gimpprocbrowser.c 23.6 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
17
18
19
 */

/* 
20
21
22
23
24
 * dbbrowser_utils.c
 * 0.08  26th sept 97  by Thomas NOEL <thomas@minet.net>
 *
 * 98/12/13  Sven Neumann <sven@gimp.org> : added help display
 */
Elliot Lee's avatar
Elliot Lee committed
25

Sven Neumann's avatar
Sven Neumann committed
26
#include "config.h"
27
28
29
30
31
32

#include <gtk/gtk.h>

#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>

Elliot Lee's avatar
Elliot Lee committed
33
#include "dbbrowser_utils.h"
34

Sven Neumann's avatar
Sven Neumann committed
35
#include "libgimp/stdplugins-intl.h"
Elliot Lee's avatar
Elliot Lee committed
36

37
38
39
40
41
/* configuration */

#define DBL_LIST_WIDTH 220
#define DBL_WIDTH DBL_LIST_WIDTH+400
#define DBL_HEIGHT 250
42

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* end of configuration */

typedef struct
{
  gchar *label;
  gchar *func;
} ListEntry_t;

typedef struct
{
  GtkWidget *dlg;

  GtkWidget *search_entry;
  GtkWidget *name_button;
  GtkWidget *blurb_button;

  GtkWidget *descr_scroll;
  GtkWidget *descr_table;

  GtkWidget *clist;
  GtkWidget *scrolled_win;

  /* the currently selected procedure */
  gchar *selected_proc_name;
  gchar *selected_scheme_proc_name;
  gchar *selected_proc_blurb;
  gchar *selected_proc_help;
  gchar *selected_proc_author;
  gchar *selected_proc_copyright;
  gchar *selected_proc_date;
  gint   selected_proc_type;
  gint   selected_nparams;
  gint   selected_nreturn_vals;
  GParamDef *selected_params;
  GParamDef *selected_return_vals; 

  void (* apply_callback) (gchar     *selected_proc_name,
			   gchar     *selected_scheme_proc_name,
			   gchar     *selected_proc_blurb,
			   gchar     *selected_proc_help,
			   gchar     *selected_proc_author,
			   gchar     *selected_proc_copyright,
			   gchar     *selected_proc_date,
			   gint       selected_proc_type,
			   gint       selected_nparams,
			   gint       selected_nreturn_vals,
			   GParamDef *selected_params,
			   GParamDef *selected_return_vals);

} dbbrowser_t;

/* local functions */

static void    dialog_apply_callback     (GtkWidget      *widget,
					  gpointer        data);
static gint    procedure_select_callback (GtkWidget      *widget,
					  gint            row,
					  gint            column,
					  GdkEventButton *bevent,
					  gpointer        data);
static void    dialog_search_callback    (GtkWidget      *widget, 
					  gpointer        data);
static void    dialog_select             (dbbrowser_t    *dbbrowser, 
					  gchar          *proc_name);
static void    dialog_close_callback     (GtkWidget      *widget, 
					  gpointer        data);
static void    convert_string            (gchar          *str);
static gchar * GParamType2char           (GParamType      t);

GList * proc_table = NULL;

/* create the dialog box
 * console_entry != NULL => called from the script-fu-console
 */
GtkWidget *
gimp_db_browser (void (* apply_callback) (gchar     *selected_proc_name,
Elliot Lee's avatar
Elliot Lee committed
119
120
121
122
123
124
					  gchar     *selected_scheme_proc_name,
					  gchar     *selected_proc_blurb,
					  gchar     *selected_proc_help,
					  gchar     *selected_proc_author,
					  gchar     *selected_proc_copyright,
					  gchar     *selected_proc_date,
125
126
127
					  gint       selected_proc_type,
					  gint       selected_nparams,
					  gint       selected_nreturn_vals,
Elliot Lee's avatar
Elliot Lee committed
128
					  GParamDef *selected_params,
129
					  GParamDef *selected_return_vals))
Elliot Lee's avatar
Elliot Lee committed
130
131
132
133
134
135
{
  dbbrowser_t* dbbrowser;
  
  GtkWidget *button;
  GtkWidget *hbox,*searchhbox,*vbox;
  GtkWidget *label;
136

137
  dbbrowser = g_new (dbbrowser_t, 1);
Elliot Lee's avatar
Elliot Lee committed
138
139
140
141
  
  dbbrowser->apply_callback = apply_callback;
  
  /* the dialog box */
142

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
  if (apply_callback)
    {
      dbbrowser->dlg =
	gimp_dialog_new (_("DB Browser (init...)"), "dbbrowser",
			 gimp_plugin_help_func, "filters/dbbrowser.html",
			 GTK_WIN_POS_MOUSE,
			 FALSE, TRUE, FALSE,

			 _("Search by Name"), dialog_search_callback,
			 dbbrowser, NULL, &dbbrowser->name_button, TRUE, FALSE,
			 _("Search by Blurb"), dialog_search_callback,
			 dbbrowser, NULL, &dbbrowser->blurb_button, FALSE, FALSE,
			 _("Apply"), dialog_apply_callback,
			 dbbrowser, NULL, NULL, FALSE, FALSE,
			 _("Close"), dialog_close_callback,
			 dbbrowser, NULL, NULL, FALSE, TRUE,

			 NULL);
    }
  else
    {
      dbbrowser->dlg =
	gimp_dialog_new (_("DB Browser (init...)"), "dbbrowser",
			 gimp_plugin_help_func, "filters/dbbrowser.html",
			 GTK_WIN_POS_MOUSE,
			 FALSE, TRUE, FALSE,

			 _("Search by Name"), dialog_search_callback,
			 dbbrowser, NULL, &dbbrowser->name_button, TRUE, FALSE,
			 _("Search by Blurb"), dialog_search_callback,
			 dbbrowser, NULL, &dbbrowser->blurb_button, FALSE, FALSE,
			 _("Close"), dialog_close_callback,
			 dbbrowser, NULL, NULL, FALSE, TRUE,

			 NULL);
    }

Elliot Lee's avatar
Elliot Lee committed
180
  gtk_signal_connect (GTK_OBJECT (dbbrowser->dlg), "destroy",
181
                      GTK_SIGNAL_FUNC (dialog_close_callback),
Elliot Lee's avatar
Elliot Lee committed
182
183
184
185
                      dbbrowser);
  
  /* hbox : left=list ; right=description */
  
186
  hbox = gtk_hbox_new (FALSE, 0);
Elliot Lee's avatar
Elliot Lee committed
187
188
189
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dbbrowser->dlg)->vbox), 
		      hbox, TRUE, TRUE, 0);
  gtk_widget_show (hbox);
190

Elliot Lee's avatar
Elliot Lee committed
191
192
  /* left = vbox : the list and the search entry */
  
193
194
  vbox = gtk_vbox_new (FALSE, 0);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 3); 
Elliot Lee's avatar
Elliot Lee committed
195
196
197
198
199
200
  gtk_box_pack_start (GTK_BOX (hbox), 
		      vbox, FALSE, TRUE, 0);
  gtk_widget_show(vbox);
  
  /* list : list in a scrolled_win */
  
201
  dbbrowser->clist = gtk_clist_new (1);
Manish Singh's avatar
Manish Singh committed
202
203
204
  dbbrowser->scrolled_win = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (dbbrowser->scrolled_win),
				  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
205
206
  gtk_clist_set_selection_mode (GTK_CLIST (dbbrowser->clist),
			        GTK_SELECTION_BROWSE);
207

208
  gtk_widget_set_usize (dbbrowser->clist, DBL_LIST_WIDTH, DBL_HEIGHT);
209
210
211
  gtk_signal_connect (GTK_OBJECT (dbbrowser->clist), "select_row",
		      (GtkSignalFunc) procedure_select_callback,
		      dbbrowser);
Manish Singh's avatar
Manish Singh committed
212
213
  gtk_box_pack_start (GTK_BOX (vbox), dbbrowser->scrolled_win, TRUE, TRUE, 0);
  gtk_container_add (GTK_CONTAINER (dbbrowser->scrolled_win), dbbrowser->clist);
214
215
  gtk_widget_show (dbbrowser->clist);
  gtk_widget_show (dbbrowser->scrolled_win);
Elliot Lee's avatar
Elliot Lee committed
216
217
218

  /* search entry */

219
  searchhbox = gtk_hbox_new (FALSE, 4);
Elliot Lee's avatar
Elliot Lee committed
220
221
  gtk_box_pack_start (GTK_BOX (vbox),
		      searchhbox, FALSE, TRUE, 0);
222
  gtk_widget_show (searchhbox);
Elliot Lee's avatar
Elliot Lee committed
223

224
225
  label = gtk_label_new (_("Search:"));
  gtk_misc_set_alignment( GTK_MISC (label), 0.0, 0.5);
Elliot Lee's avatar
Elliot Lee committed
226
227
  gtk_box_pack_start (GTK_BOX (searchhbox), 
		      label, TRUE, TRUE, 0);
228
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
229

230
  dbbrowser->search_entry = gtk_entry_new ();
Elliot Lee's avatar
Elliot Lee committed
231
232
233
234
235
236
237
238
239
  gtk_box_pack_start (GTK_BOX (searchhbox), 
		      dbbrowser->search_entry, TRUE, TRUE, 0);
  gtk_widget_show(dbbrowser->search_entry);

  /* right = description */

  dbbrowser->descr_scroll = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (dbbrowser->descr_scroll),
				  GTK_POLICY_ALWAYS, 
240
				  GTK_POLICY_ALWAYS);
Elliot Lee's avatar
Elliot Lee committed
241
242
243
244
245
246
247
  gtk_box_pack_start (GTK_BOX (hbox), 
		      dbbrowser->descr_scroll, TRUE, TRUE, 0);
  gtk_widget_set_usize (dbbrowser->descr_scroll, DBL_WIDTH - DBL_LIST_WIDTH, 0);
  gtk_widget_show (dbbrowser->descr_scroll);

  /* now build the list */

248
  gtk_widget_show (dbbrowser->clist); 
Elliot Lee's avatar
Elliot Lee committed
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
  gtk_widget_show (dbbrowser->dlg);

  /* initialize the "return" value (for "apply") */

  dbbrowser->descr_table = NULL;
  dbbrowser->selected_proc_name = NULL;
  dbbrowser->selected_scheme_proc_name = NULL;
  dbbrowser->selected_proc_blurb = NULL;
  dbbrowser->selected_proc_help = NULL;
  dbbrowser->selected_proc_author = NULL;
  dbbrowser->selected_proc_copyright = NULL;
  dbbrowser->selected_proc_date = NULL;
  dbbrowser->selected_proc_type = 0;
  dbbrowser->selected_nparams = 0;
  dbbrowser->selected_nreturn_vals = 0;
  dbbrowser->selected_params = NULL;
  dbbrowser->selected_return_vals = NULL;

  /* first search (all procedures) */
268
  dialog_search_callback (NULL, (gpointer) dbbrowser);
269
270

  return dbbrowser->dlg;
Elliot Lee's avatar
Elliot Lee committed
271
272
273
}

static gint
274
275
276
277
278
procedure_select_callback (GtkWidget      *widget,
			   gint            row,
			   gint            column,
			   GdkEventButton *bevent,
			   gpointer        data)
Elliot Lee's avatar
Elliot Lee committed
279
280
{
  dbbrowser_t *dbbrowser = data;
281
  gchar *func;
Elliot Lee's avatar
Elliot Lee committed
282
283

  g_return_val_if_fail (widget != NULL, FALSE);
284
  /*  g_return_val_if_fail (bevent != NULL, FALSE);  */
Elliot Lee's avatar
Elliot Lee committed
285
  g_return_val_if_fail (dbbrowser != NULL, FALSE);
286

287
  if ((func = (gchar *) (gtk_clist_get_row_data (GTK_CLIST (widget), row))))
288
    dialog_select (dbbrowser, func);
Elliot Lee's avatar
Elliot Lee committed
289
290
291
  return FALSE;
}

292
/* update the description box (right) */
Elliot Lee's avatar
Elliot Lee committed
293
294
295
296
static void 
dialog_select (dbbrowser_t *dbbrowser, 
	       gchar       *proc_name)
{
Sven Neumann's avatar
Sven Neumann committed
297
298
299
300
301
  GtkWidget *label;
  GtkWidget *old_table;
  GtkWidget *help;
  GtkWidget *text = NULL;
  GtkWidget *vscrollbar;
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
  gint i, row = 0;

  g_free (dbbrowser->selected_proc_name);
  dbbrowser->selected_proc_name = g_strdup (proc_name);

  g_free (dbbrowser->selected_scheme_proc_name);
  dbbrowser->selected_scheme_proc_name = g_strdup (proc_name);
  convert_string (dbbrowser->selected_scheme_proc_name);

  g_free (dbbrowser->selected_proc_blurb);
  g_free (dbbrowser->selected_proc_help);
  g_free (dbbrowser->selected_proc_author);
  g_free (dbbrowser->selected_proc_copyright);
  g_free (dbbrowser->selected_proc_date);
  g_free (dbbrowser->selected_params);
  g_free (dbbrowser->selected_return_vals);
Elliot Lee's avatar
Elliot Lee committed
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333

  gimp_query_procedure (proc_name, 
			&(dbbrowser->selected_proc_blurb), 
			&(dbbrowser->selected_proc_help), 
			&(dbbrowser->selected_proc_author),
			&(dbbrowser->selected_proc_copyright), 
			&(dbbrowser->selected_proc_date), 
			&(dbbrowser->selected_proc_type), 
			&(dbbrowser->selected_nparams),
			&(dbbrowser->selected_nreturn_vals), 
			&(dbbrowser->selected_params), 
			&(dbbrowser->selected_return_vals));

  /* save the "old" table */
  old_table = dbbrowser->descr_table;

334
335
336
  dbbrowser->descr_table = gtk_table_new
    (10 + dbbrowser->selected_nparams + dbbrowser->selected_nreturn_vals,
     5, FALSE);
Elliot Lee's avatar
Elliot Lee committed
337

338
  gtk_table_set_col_spacings (GTK_TABLE (dbbrowser->descr_table), 4);
Elliot Lee's avatar
Elliot Lee committed
339
340
341

  /* show the name */

342
  label = gtk_label_new (_("Name:"));
Elliot Lee's avatar
Elliot Lee committed
343
344
345
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
		    0, 1, row, row+1, GTK_FILL, GTK_FILL, 3, 6);
346
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
347

348
349
350
  label = gtk_entry_new ();
  gtk_entry_set_text (GTK_ENTRY (label), dbbrowser->selected_scheme_proc_name);
  gtk_entry_set_editable (GTK_ENTRY (label), FALSE);
Elliot Lee's avatar
Elliot Lee committed
351
352
  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
		    1, 4, row, row+1, GTK_FILL, GTK_FILL, 0, 0);
353
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
354
355
356
357
  row++;

  /* show the description */

358
  label = gtk_label_new (_("Blurb:"));
Elliot Lee's avatar
Elliot Lee committed
359
360
361
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
		    0, 1, row, row+1, GTK_FILL, GTK_FILL, 3, 0);
362
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
363

364
  label = gtk_label_new (dbbrowser->selected_proc_blurb);
Elliot Lee's avatar
Elliot Lee committed
365
366
367
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
		    1, 4, row, row+1, GTK_FILL, GTK_FILL, 0, 0);
368
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
369
370
  row++;

371
  label = gtk_hseparator_new (); /* ok, not really a label ... :) */
Elliot Lee's avatar
Elliot Lee committed
372
373
  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
		    0, 4, row, row+1, GTK_FILL, GTK_FILL, 3, 6);
374
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
375
376
377
378
379
  row++;

  /* in parameters */
  if (dbbrowser->selected_nparams) 
    {
380
      label = gtk_label_new (_("In:"));
Elliot Lee's avatar
Elliot Lee committed
381
382
      gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
      gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
383
384
385
386
			0, 1, row, row+(dbbrowser->selected_nparams), 
			GTK_FILL, GTK_FILL, 3, 0);
      gtk_widget_show (label);
      for (i = 0; i < dbbrowser->selected_nparams; i++) 
Elliot Lee's avatar
Elliot Lee committed
387
388
	{
	  /* name */
389
	  label = gtk_label_new ((dbbrowser->selected_params[i]).name);
Elliot Lee's avatar
Elliot Lee committed
390
391
392
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); 
	  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
			    1, 2, row, row+1, GTK_FILL, GTK_FILL, 0, 0);
393
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
394
395

	  /* type */
396
	  label = gtk_label_new (GParamType2char ((dbbrowser->selected_params[i]).type));
Elliot Lee's avatar
Elliot Lee committed
397
398
399
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
	  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
			    2, 3, row, row+1, GTK_FILL, GTK_FILL, 0, 0);
400
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
401
402

	  /* description */
403
	  label = gtk_label_new ((dbbrowser->selected_params[i]).description);
Elliot Lee's avatar
Elliot Lee committed
404
405
406
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
	  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
			    3, 4, row, row+1, GTK_FILL, GTK_FILL, 0, 0);
407
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
408
409
410
411
	  
	  row++;
	}
    }
412

Elliot Lee's avatar
Elliot Lee committed
413
  if ((dbbrowser->selected_nparams) && 
414
415
416
417
418
419
420
421
422
      (dbbrowser->selected_nreturn_vals))
    {
      label = gtk_hseparator_new (); /* ok, not really a label ... :) */
      gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
			0, 4, row, row+1,
			GTK_FILL, GTK_FILL, 3, 6);
      gtk_widget_show (label);
      row++;
    }
Elliot Lee's avatar
Elliot Lee committed
423
424
425
426

  /* out parameters */
  if (dbbrowser->selected_nreturn_vals)
    {
427
      label = gtk_label_new (_("Out:"));
Elliot Lee's avatar
Elliot Lee committed
428
429
430
431
      gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
      gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
			0, 1, row, row+(dbbrowser->selected_nreturn_vals), 
			GTK_FILL, GTK_FILL, 3, 0);
432
433
      gtk_widget_show (label);
      for (i = 0; i < dbbrowser->selected_nreturn_vals; i++) 
Elliot Lee's avatar
Elliot Lee committed
434
435
	{
	  /* name */
436
	  label = gtk_label_new ((dbbrowser->selected_return_vals[i]).name);
Elliot Lee's avatar
Elliot Lee committed
437
438
439
440
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); 
	  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
			    1, 2, row, row+1, 
			    GTK_FILL, GTK_FILL, 0, 0);
441
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
442
443

	  /* type */
444
	  label = gtk_label_new (GParamType2char((dbbrowser->selected_return_vals[i]).type));
Elliot Lee's avatar
Elliot Lee committed
445
446
447
448
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
	  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
			    2, 3, row, row+1, 
			    GTK_FILL, GTK_FILL, 0, 0);
449
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
450
451

	  /* description */
452
	  label = gtk_label_new ((dbbrowser->selected_return_vals[i]).description);
Elliot Lee's avatar
Elliot Lee committed
453
454
455
456
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); 
	  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
			    3, 4, row, row+1, 
			    GTK_FILL, GTK_FILL, 0, 0);
457
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
458
459
460
461
462
	  row++;
	}
    }

  if ((dbbrowser->selected_nparams) || 
463
464
465
466
467
468
469
      (dbbrowser->selected_nreturn_vals))
    {
      label = gtk_hseparator_new (); /* ok, not really a label ... :) */
      gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
			0, 4, row, row+1,
			GTK_FILL, GTK_FILL, 3, 6);
      gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
470
471
472
    row++;
  }

Sven Neumann's avatar
Sven Neumann committed
473
  /* show the help */
474
475
  if ((dbbrowser->selected_proc_help) &&
      (strlen (dbbrowser->selected_proc_help) > 1))
Sven Neumann's avatar
Sven Neumann committed
476
    {
477
      label = gtk_label_new (_("Help:"));
Sven Neumann's avatar
Sven Neumann committed
478
479
480
481
      gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
      gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
			0, 1, row, row+1, 
			GTK_FILL, GTK_FILL, 3, 0);
482
483
      gtk_widget_show (label);

Sven Neumann's avatar
Sven Neumann committed
484
485
486
487
488
489
490
491
492
493
      help = gtk_table_new (2, 2, FALSE);
      gtk_table_set_row_spacing (GTK_TABLE (help), 0, 2);
      gtk_table_set_col_spacing (GTK_TABLE (help), 0, 2);
      gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), help,
			1, 4, row, row+1, GTK_FILL, GTK_FILL, 3, 0);
      gtk_widget_show (help);
      row++;
      
      text = gtk_text_new (NULL, NULL);
      gtk_text_set_editable (GTK_TEXT (text), FALSE);
494
      gtk_text_set_word_wrap (GTK_TEXT (text), TRUE);
Sven Neumann's avatar
Sven Neumann committed
495
496
497
498
499
500
501
502
503
504
      gtk_widget_set_usize (text, -1, 60);
      gtk_table_attach (GTK_TABLE (help), text, 0, 1, 0, 1,
			GTK_EXPAND | GTK_SHRINK | GTK_FILL,
			GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
      gtk_widget_show (text);
      
      vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
      gtk_table_attach (GTK_TABLE (help), vscrollbar, 1, 2, 0, 1,
			GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
      gtk_widget_show (vscrollbar);
505
506

      label = gtk_hseparator_new (); /* ok, not really a label ... :) */
Sven Neumann's avatar
Sven Neumann committed
507
508
      gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
			0, 4, row, row+1, GTK_FILL, GTK_FILL, 3, 6);
509
      gtk_widget_show (label);
Sven Neumann's avatar
Sven Neumann committed
510
511
512
513
514
      row++;
    }

  /* show the author & the copyright */

515
  label = gtk_label_new (_("Author:"));
Elliot Lee's avatar
Elliot Lee committed
516
517
518
519
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
		    0, 1, row, row+1, 
		    GTK_FILL, GTK_FILL, 3, 0);
520
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
521

522
  label = gtk_label_new (dbbrowser->selected_proc_author);
Elliot Lee's avatar
Elliot Lee committed
523
524
525
526
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
		    1, 4,  row, row+1,
		    GTK_FILL, GTK_FILL, 0, 0);
527
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
528
  row++;
529
530

  label = gtk_label_new (_("Date:"));
Elliot Lee's avatar
Elliot Lee committed
531
532
533
534
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
		    0, 1, row, row+1, 
		    GTK_FILL, GTK_FILL, 3, 0);
535
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
536

537
  label = gtk_label_new (dbbrowser->selected_proc_date);
Elliot Lee's avatar
Elliot Lee committed
538
539
540
541
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
		    1, 4,  row, row+1,
		    GTK_FILL, GTK_FILL, 0, 0);
542
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
543
544
  row++;

545
  label = gtk_label_new (_("Copyright:"));
Elliot Lee's avatar
Elliot Lee committed
546
547
548
549
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
		    0, 1, row, row+1, 
		    GTK_FILL, GTK_FILL, 3, 0);
550
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
551

552
  label = gtk_label_new (dbbrowser->selected_proc_copyright);
Elliot Lee's avatar
Elliot Lee committed
553
554
555
556
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
		    1, 4,  row, row+1,
		    GTK_FILL, GTK_FILL, 0, 0);
557
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
558
559
  row++;

Manish Singh's avatar
Manish Singh committed
560
  if (old_table)
561
    gtk_widget_destroy (old_table);
Elliot Lee's avatar
Elliot Lee committed
562

Manish Singh's avatar
Manish Singh committed
563
564
  gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (dbbrowser->descr_scroll), 
					 dbbrowser->descr_table);
Sven Neumann's avatar
Sven Neumann committed
565
566
567
568
569
570
571
572
573
574

  /* now after the table is added to a window add the text */
  if (text != NULL)
    {
      gtk_widget_realize (text);
      gtk_text_freeze (GTK_TEXT (text));
      gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,
		       dbbrowser->selected_proc_help, -1);
      gtk_text_thaw (GTK_TEXT (text));
    }
575
  gtk_widget_show (dbbrowser->descr_table);
Elliot Lee's avatar
Elliot Lee committed
576
577
}

578
/* end of the dialog */
Elliot Lee's avatar
Elliot Lee committed
579
580
581
582
583
static void
dialog_close_callback (GtkWidget *widget, 
		       gpointer   data)
{
  dbbrowser_t* dbbrowser = data;
584

585
586
587
588
589
590
591
592
593
594
595
596
  if (dbbrowser->apply_callback)
    {
      /* we are called by another application : just kill the dialog box */
      gtk_widget_hide (dbbrowser->dlg);
      gtk_widget_destroy (dbbrowser->dlg);
    }
  else
    {
      /* we are in the plug_in : kill the gtk application */
      gtk_widget_destroy (dbbrowser->dlg);
      gtk_main_quit ();
    }
Manish Singh's avatar
Manish Singh committed
597
}
Elliot Lee's avatar
Elliot Lee committed
598

599
/* end of the dialog */
Elliot Lee's avatar
Elliot Lee committed
600
601
602
603
604
605
static void 
dialog_apply_callback (GtkWidget *widget, 
		       gpointer   data)
{
  dbbrowser_t* dbbrowser = data;

606
  (dbbrowser->apply_callback) (dbbrowser->selected_proc_name,
Elliot Lee's avatar
Elliot Lee committed
607
608
609
610
611
612
613
614
615
616
			       dbbrowser->selected_scheme_proc_name,
			       dbbrowser->selected_proc_blurb,
			       dbbrowser->selected_proc_help,
			       dbbrowser->selected_proc_author,
			       dbbrowser->selected_proc_copyright,
			       dbbrowser->selected_proc_date,
			       dbbrowser->selected_proc_type,
			       dbbrowser->selected_nparams,
			       dbbrowser->selected_nreturn_vals,
			       dbbrowser->selected_params,
617
			       dbbrowser->selected_return_vals);
Elliot Lee's avatar
Elliot Lee committed
618
619
}

620
/* search in the whole db */
Elliot Lee's avatar
Elliot Lee committed
621
622
623
624
static void 
dialog_search_callback (GtkWidget *widget, 
			gpointer   data)
{
625
626
627
  gchar **proc_list;
  gint num_procs;
  gint i, j;
Elliot Lee's avatar
Elliot Lee committed
628
  dbbrowser_t* dbbrowser = data;
629
630
  gchar *func_name, *label, *query_text;
  GString *query;
Elliot Lee's avatar
Elliot Lee committed
631

632
633
  gtk_clist_freeze (GTK_CLIST (dbbrowser->clist));
  gtk_clist_clear (GTK_CLIST (dbbrowser->clist));
Elliot Lee's avatar
Elliot Lee committed
634
635
636

  /* search */

637
  if (widget == (dbbrowser->name_button))
Elliot Lee's avatar
Elliot Lee committed
638
639
    {
      gtk_window_set_title (GTK_WINDOW (dbbrowser->dlg), 
Sven Neumann's avatar
Sven Neumann committed
640
			    _("DB Browser (by name - please wait)"));
641
642

      query = g_string_new ("");
643
      query_text = gtk_entry_get_text (GTK_ENTRY (dbbrowser->search_entry));
644
645
646
647
648
649
650
651
652
653
654
655

      while (*query_text)
	{
	  if ((*query_text == '_') || (*query_text == '-'))
	    g_string_append (query, "[-_]");
	  else
	    g_string_append_c (query, *query_text);

	  query_text++;
	}

      gimp_query_database (query->str,
Elliot Lee's avatar
Elliot Lee committed
656
657
			   ".*", ".*", ".*", ".*", ".*", ".*", 
			   &num_procs, &proc_list);
658
659

      g_string_free (query, TRUE);
Elliot Lee's avatar
Elliot Lee committed
660
    }
661
  else if (widget == (dbbrowser->blurb_button))
Elliot Lee's avatar
Elliot Lee committed
662
663
    {
      gtk_window_set_title (GTK_WINDOW (dbbrowser->dlg), 
Sven Neumann's avatar
Sven Neumann committed
664
			    _("DB Browser (by blurb - please wait)"));
Elliot Lee's avatar
Elliot Lee committed
665
666
667
668
669
      gimp_query_database (".*", 
			   gtk_entry_get_text( GTK_ENTRY(dbbrowser->search_entry) ),
			   ".*", ".*", ".*", ".*", ".*",
			   &num_procs, &proc_list);
    }
670
671
  else
    {
Elliot Lee's avatar
Elliot Lee committed
672
      gtk_window_set_title (GTK_WINDOW (dbbrowser->dlg), 
Sven Neumann's avatar
Sven Neumann committed
673
			    _("DB Browser (please wait)"));
Elliot Lee's avatar
Elliot Lee committed
674
675
      gimp_query_database (".*", ".*", ".*", ".*", ".*", ".*", ".*", 
			   &num_procs, &proc_list);
676
    }
Elliot Lee's avatar
Elliot Lee committed
677

678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
  for (i = 0; i < num_procs; i++)
    {
      j = 0;
      while ((j < i) &&
	     (strcmp (gtk_clist_get_row_data (GTK_CLIST (dbbrowser->clist), j),
		      proc_list[i]) < 0))
	j++;

      label = g_strdup (proc_list[i]);
      convert_string (label);
      gtk_clist_insert (GTK_CLIST (GTK_CLIST(dbbrowser->clist)), j,
			&label);
      func_name = g_strdup (proc_list[i]);

      gtk_clist_set_row_data_full (GTK_CLIST (dbbrowser->clist), j,
				   func_name, g_free);
    }
695

696
697
698
699
700
701
  if (num_procs > 0)
    {
      dialog_select (dbbrowser,
		     gtk_clist_get_row_data (GTK_CLIST (dbbrowser->clist), 0));
      gtk_clist_select_row (GTK_CLIST (dbbrowser->clist), 0, 0);
    }
702
703

  /*
Elliot Lee's avatar
Elliot Lee committed
704
705
706
707
708
709
710
711
712
713
714
715
716
717
  if (num_procs != 0) {
    gchar *insert_name, *label_name;
    int i,j,savej;
    
    for (i = 0; i < num_procs ; i++) {

      insert_name=g_strdup(proc_list[0]); savej=0;
      for (j = 0; j < num_procs ; j++) {
	if (strcmp(proc_list[j],insert_name)<0) {
	  g_free(insert_name);
	  insert_name=g_strdup(proc_list[j]);
	  savej=j;
	}
      }
718
  
Elliot Lee's avatar
Elliot Lee committed
719
720
721
722
      proc_list[savej][0]='\255';

      label_name = g_strdup( insert_name );
      convert_string( label_name );
723
      gtk_clist_append (GTK_CLIST (dbbrowser->clist), &label_name);
Elliot Lee's avatar
Elliot Lee committed
724
725
726
727
728
729

      if (i==0) dialog_select( dbbrowser , insert_name );

      g_free(label_name);
    }
  }
730
  */
Elliot Lee's avatar
Elliot Lee committed
731
  
732
733
734
735
  if (dbbrowser->clist)
    {
      ;
    }
Elliot Lee's avatar
Elliot Lee committed
736
  
737
  g_free (proc_list);
Elliot Lee's avatar
Elliot Lee committed
738

Sven Neumann's avatar
Sven Neumann committed
739
  gtk_window_set_title (GTK_WINDOW (dbbrowser->dlg), _("DB Browser"));
740
  gtk_clist_thaw (GTK_CLIST (dbbrowser->clist));
Elliot Lee's avatar
Elliot Lee committed
741
742
743
744
745
746

}

/* utils ... */

static void 
747
convert_string (gchar *str)
Elliot Lee's avatar
Elliot Lee committed
748
749
750
751
752
753
754
755
{
  while (*str)
    {
      if (*str == '_') *str = '-';
      str++;
    }
}

756
757
static gchar * 
GParamType2char (GParamType t)
Elliot Lee's avatar
Elliot Lee committed
758
{
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
  switch (t)
    {
    case PARAM_INT32: return "INT32";
    case PARAM_INT16: return "INT16";
    case PARAM_INT8: return "INT8";
    case PARAM_FLOAT: return "FLOAT";
    case PARAM_STRING: return "STRING";
    case PARAM_INT32ARRAY: return "INT32ARRAY";
    case PARAM_INT16ARRAY: return "INT16ARRAY";
    case PARAM_INT8ARRAY: return "INT8ARRAY";
    case PARAM_FLOATARRAY: return "FLOATARRAY";
    case PARAM_STRINGARRAY: return "STRINGARRAY";
    case PARAM_COLOR: return "COLOR";
    case PARAM_REGION: return "REGION";
    case PARAM_DISPLAY: return "DISPLAY";
    case PARAM_IMAGE: return "IMAGE";
    case PARAM_LAYER: return "LAYER";
    case PARAM_CHANNEL: return "CHANNEL";
    case PARAM_DRAWABLE: return "DRAWABLE";
    case PARAM_SELECTION: return "SELECTION";
    case PARAM_BOUNDARY: return "BOUNDARY";
    case PARAM_PATH: return "PATH";
    case PARAM_PARASITE: return "PARASITE";
    case PARAM_STATUS: return "STATUS";
    case PARAM_END: return "END";
    default: return "UNKNOWN?";
    }
Elliot Lee's avatar
Elliot Lee committed
786
}