gimpprocbrowser.c 23.9 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

Daniel Egger's avatar
Daniel Egger committed
28
#include <string.h>
29
30
31
32
33
#include <gtk/gtk.h>

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

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

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

Hans Breuer's avatar
Hans Breuer committed
38
39
40
41
/* FIXME: remove usage of the 'broken' GtkText */
#define GTK_ENABLE_BROKEN
#include <gtk/gtktext.h>

42
43
44
45
46
/* configuration */

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

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* 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 */
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
  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;
  GimpPDBProcType  selected_proc_type;
  gint             selected_nparams;
  gint             selected_nreturn_vals;
  GimpParamDef    *selected_params;
  GimpParamDef    *selected_return_vals; 

  void (* apply_callback) (gchar           *proc_name,
			   gchar           *scheme_proc_name,
			   gchar           *proc_blurb,
			   gchar           *proc_help,
			   gchar           *proc_author,
			   gchar           *proc_copyright,
			   gchar           *proc_date,
			   GimpPDBProcType  proc_type,
			   gint             nparams,
			   gint             nreturn_vals,
			   GimpParamDef    *params,
			   GimpParamDef    *return_vals);
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

} 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);
Daniel Egger's avatar
Daniel Egger committed
115
static gchar * GParamType2char           (GimpPDBArgType  t);
116
117
118
119
120
121
122

GList * proc_table = NULL;

/* create the dialog box
 * console_entry != NULL => called from the script-fu-console
 */
GtkWidget *
123
124
125
126
127
128
129
130
131
132
133
134
gimp_db_browser (void (* apply_callback) (gchar           *proc_name,
					  gchar           *scheme_proc_name,
					  gchar           *proc_blurb,
					  gchar           *proc_help,
					  gchar           *proc_author,
					  gchar           *proc_copyright,
					  gchar           *proc_date,
					  GimpPDBProcType  proc_type,
					  gint             nparams,
					  gint             nreturn_vals,
					  GimpParamDef    *params,
					  GimpParamDef    *return_vals))
Elliot Lee's avatar
Elliot Lee committed
135
136
137
{
  dbbrowser_t* dbbrowser;
  
138
139
140
  GtkWidget *hbox;
  GtkWidget *searchhbox;
  GtkWidget *vbox;
Elliot Lee's avatar
Elliot Lee committed
141
  GtkWidget *label;
142

143
  dbbrowser = g_new (dbbrowser_t, 1);
Elliot Lee's avatar
Elliot Lee committed
144
145
146
147
  
  dbbrowser->apply_callback = apply_callback;
  
  /* the dialog box */
148

149
150
151
152
  if (apply_callback)
    {
      dbbrowser->dlg =
	gimp_dialog_new (_("DB Browser (init...)"), "dbbrowser",
153
			 gimp_standard_help_func, "filters/dbbrowser.html",
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
			 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",
172
			 gimp_standard_help_func, "filters/dbbrowser.html",
173
174
175
176
177
178
179
180
181
182
183
184
185
			 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
186
  gtk_signal_connect (GTK_OBJECT (dbbrowser->dlg), "destroy",
187
                      GTK_SIGNAL_FUNC (dialog_close_callback),
Elliot Lee's avatar
Elliot Lee committed
188
189
190
191
                      dbbrowser);
  
  /* hbox : left=list ; right=description */
  
192
  hbox = gtk_hbox_new (FALSE, 0);
Elliot Lee's avatar
Elliot Lee committed
193
194
195
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dbbrowser->dlg)->vbox), 
		      hbox, TRUE, TRUE, 0);
  gtk_widget_show (hbox);
196

Elliot Lee's avatar
Elliot Lee committed
197
198
  /* left = vbox : the list and the search entry */
  
199
200
  vbox = gtk_vbox_new (FALSE, 0);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 3); 
Elliot Lee's avatar
Elliot Lee committed
201
202
203
204
205
206
  gtk_box_pack_start (GTK_BOX (hbox), 
		      vbox, FALSE, TRUE, 0);
  gtk_widget_show(vbox);
  
  /* list : list in a scrolled_win */
  
207
  dbbrowser->clist = gtk_clist_new (1);
Manish Singh's avatar
Manish Singh committed
208
209
210
  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);
211
212
  gtk_clist_set_selection_mode (GTK_CLIST (dbbrowser->clist),
			        GTK_SELECTION_BROWSE);
213

214
  gtk_widget_set_usize (dbbrowser->clist, DBL_LIST_WIDTH, DBL_HEIGHT);
215
216
217
  gtk_signal_connect (GTK_OBJECT (dbbrowser->clist), "select_row",
		      (GtkSignalFunc) procedure_select_callback,
		      dbbrowser);
Manish Singh's avatar
Manish Singh committed
218
219
  gtk_box_pack_start (GTK_BOX (vbox), dbbrowser->scrolled_win, TRUE, TRUE, 0);
  gtk_container_add (GTK_CONTAINER (dbbrowser->scrolled_win), dbbrowser->clist);
220
221
  gtk_widget_show (dbbrowser->clist);
  gtk_widget_show (dbbrowser->scrolled_win);
Elliot Lee's avatar
Elliot Lee committed
222
223
224

  /* search entry */

225
  searchhbox = gtk_hbox_new (FALSE, 4);
Elliot Lee's avatar
Elliot Lee committed
226
227
  gtk_box_pack_start (GTK_BOX (vbox),
		      searchhbox, FALSE, TRUE, 0);
228
  gtk_widget_show (searchhbox);
Elliot Lee's avatar
Elliot Lee committed
229

230
231
  label = gtk_label_new (_("Search:"));
  gtk_misc_set_alignment( GTK_MISC (label), 0.0, 0.5);
Elliot Lee's avatar
Elliot Lee committed
232
233
  gtk_box_pack_start (GTK_BOX (searchhbox), 
		      label, TRUE, TRUE, 0);
234
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
235

236
  dbbrowser->search_entry = gtk_entry_new ();
Elliot Lee's avatar
Elliot Lee committed
237
238
239
240
241
242
243
244
245
  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, 
246
				  GTK_POLICY_ALWAYS);
Elliot Lee's avatar
Elliot Lee committed
247
248
249
250
251
252
253
  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 */

254
  gtk_widget_show (dbbrowser->clist); 
Elliot Lee's avatar
Elliot Lee committed
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
  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) */
274
  dialog_search_callback (NULL, (gpointer) dbbrowser);
275
276

  return dbbrowser->dlg;
Elliot Lee's avatar
Elliot Lee committed
277
278
279
}

static gint
280
281
282
283
284
procedure_select_callback (GtkWidget      *widget,
			   gint            row,
			   gint            column,
			   GdkEventButton *bevent,
			   gpointer        data)
Elliot Lee's avatar
Elliot Lee committed
285
286
{
  dbbrowser_t *dbbrowser = data;
287
  gchar *func;
Elliot Lee's avatar
Elliot Lee committed
288
289

  g_return_val_if_fail (widget != NULL, FALSE);
290
  /*  g_return_val_if_fail (bevent != NULL, FALSE);  */
Elliot Lee's avatar
Elliot Lee committed
291
  g_return_val_if_fail (dbbrowser != NULL, FALSE);
292

293
  if ((func = (gchar *) (gtk_clist_get_row_data (GTK_CLIST (widget), row))))
294
    dialog_select (dbbrowser, func);
Elliot Lee's avatar
Elliot Lee committed
295
296
297
  return FALSE;
}

298
/* update the description box (right) */
Elliot Lee's avatar
Elliot Lee committed
299
300
301
302
static void 
dialog_select (dbbrowser_t *dbbrowser, 
	       gchar       *proc_name)
{
Sven Neumann's avatar
Sven Neumann committed
303
304
305
306
307
  GtkWidget *label;
  GtkWidget *old_table;
  GtkWidget *help;
  GtkWidget *text = NULL;
  GtkWidget *vscrollbar;
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
  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
324

325
326
327
328
329
330
331
332
333
334
335
336
  gimp_procedural_db_proc_info (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));
  
Elliot Lee's avatar
Elliot Lee committed
337
338
339
  /* save the "old" table */
  old_table = dbbrowser->descr_table;

340
341
342
  dbbrowser->descr_table = gtk_table_new
    (10 + dbbrowser->selected_nparams + dbbrowser->selected_nreturn_vals,
     5, FALSE);
Elliot Lee's avatar
Elliot Lee committed
343

344
  gtk_table_set_col_spacings (GTK_TABLE (dbbrowser->descr_table), 4);
Elliot Lee's avatar
Elliot Lee committed
345
346
347

  /* show the name */

348
  label = gtk_label_new (_("Name:"));
Elliot Lee's avatar
Elliot Lee committed
349
350
351
  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);
352
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
353

354
355
356
  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
357
358
  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
		    1, 4, row, row+1, GTK_FILL, GTK_FILL, 0, 0);
359
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
360
361
362
363
  row++;

  /* show the description */

364
  label = gtk_label_new (_("Blurb:"));
Elliot Lee's avatar
Elliot Lee committed
365
366
367
  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);
368
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
369

370
  label = gtk_label_new (dbbrowser->selected_proc_blurb);
Elliot Lee's avatar
Elliot Lee committed
371
372
373
  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);
374
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
375
376
  row++;

377
  label = gtk_hseparator_new (); /* ok, not really a label ... :) */
Elliot Lee's avatar
Elliot Lee committed
378
379
  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
		    0, 4, row, row+1, GTK_FILL, GTK_FILL, 3, 6);
380
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
381
382
383
384
385
  row++;

  /* in parameters */
  if (dbbrowser->selected_nparams) 
    {
386
      label = gtk_label_new (_("In:"));
Elliot Lee's avatar
Elliot Lee committed
387
388
      gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
      gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
389
390
391
392
			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
393
394
	{
	  /* name */
395
	  label = gtk_label_new ((dbbrowser->selected_params[i]).name);
Elliot Lee's avatar
Elliot Lee committed
396
397
398
	  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);
399
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
400
401

	  /* type */
402
	  label = gtk_label_new (GParamType2char ((dbbrowser->selected_params[i]).type));
Elliot Lee's avatar
Elliot Lee committed
403
404
405
	  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);
406
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
407
408

	  /* description */
409
	  label = gtk_label_new ((dbbrowser->selected_params[i]).description);
Elliot Lee's avatar
Elliot Lee committed
410
411
412
	  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);
413
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
414
415
416
417
	  
	  row++;
	}
    }
418

Elliot Lee's avatar
Elliot Lee committed
419
  if ((dbbrowser->selected_nparams) && 
420
421
422
423
424
425
426
427
428
      (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
429
430
431
432

  /* out parameters */
  if (dbbrowser->selected_nreturn_vals)
    {
433
      label = gtk_label_new (_("Out:"));
Elliot Lee's avatar
Elliot Lee committed
434
435
436
437
      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);
438
439
      gtk_widget_show (label);
      for (i = 0; i < dbbrowser->selected_nreturn_vals; i++) 
Elliot Lee's avatar
Elliot Lee committed
440
441
	{
	  /* name */
442
	  label = gtk_label_new ((dbbrowser->selected_return_vals[i]).name);
Elliot Lee's avatar
Elliot Lee committed
443
444
445
446
	  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);
447
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
448
449

	  /* type */
450
	  label = gtk_label_new (GParamType2char((dbbrowser->selected_return_vals[i]).type));
Elliot Lee's avatar
Elliot Lee committed
451
452
453
454
	  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);
455
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
456
457

	  /* description */
458
	  label = gtk_label_new ((dbbrowser->selected_return_vals[i]).description);
Elliot Lee's avatar
Elliot Lee committed
459
460
461
462
	  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);
463
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
464
465
466
467
468
	  row++;
	}
    }

  if ((dbbrowser->selected_nparams) || 
469
470
471
472
473
474
475
      (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
476
477
478
    row++;
  }

Sven Neumann's avatar
Sven Neumann committed
479
  /* show the help */
480
481
  if ((dbbrowser->selected_proc_help) &&
      (strlen (dbbrowser->selected_proc_help) > 1))
Sven Neumann's avatar
Sven Neumann committed
482
    {
483
      label = gtk_label_new (_("Help:"));
Sven Neumann's avatar
Sven Neumann committed
484
485
486
487
      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);
488
489
      gtk_widget_show (label);

Sven Neumann's avatar
Sven Neumann committed
490
491
492
493
494
495
496
497
498
499
      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);
500
      gtk_text_set_word_wrap (GTK_TEXT (text), TRUE);
Sven Neumann's avatar
Sven Neumann committed
501
502
503
504
505
506
507
508
509
510
      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);
511
512

      label = gtk_hseparator_new (); /* ok, not really a label ... :) */
Sven Neumann's avatar
Sven Neumann committed
513
514
      gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
			0, 4, row, row+1, GTK_FILL, GTK_FILL, 3, 6);
515
      gtk_widget_show (label);
Sven Neumann's avatar
Sven Neumann committed
516
517
518
519
520
      row++;
    }

  /* show the author & the copyright */

521
  label = gtk_label_new (_("Author:"));
Elliot Lee's avatar
Elliot Lee committed
522
523
524
525
  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);
526
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
527

528
  label = gtk_label_new (dbbrowser->selected_proc_author);
Elliot Lee's avatar
Elliot Lee committed
529
530
531
532
  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);
533
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
534
  row++;
535
536

  label = gtk_label_new (_("Date:"));
Elliot Lee's avatar
Elliot Lee committed
537
538
539
540
  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);
541
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
542

543
  label = gtk_label_new (dbbrowser->selected_proc_date);
Elliot Lee's avatar
Elliot Lee committed
544
545
546
547
  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);
548
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
549
550
  row++;

551
  label = gtk_label_new (_("Copyright:"));
Elliot Lee's avatar
Elliot Lee committed
552
553
554
555
  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);
556
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
557

558
  label = gtk_label_new (dbbrowser->selected_proc_copyright);
Elliot Lee's avatar
Elliot Lee committed
559
560
561
562
  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);
563
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
564
565
  row++;

Manish Singh's avatar
Manish Singh committed
566
  if (old_table)
567
    gtk_widget_destroy (old_table);
Elliot Lee's avatar
Elliot Lee committed
568

Manish Singh's avatar
Manish Singh committed
569
570
  gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (dbbrowser->descr_scroll), 
					 dbbrowser->descr_table);
Sven Neumann's avatar
Sven Neumann committed
571
572
573
574
575
576
577
578
579
580

  /* 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));
    }
581
  gtk_widget_show (dbbrowser->descr_table);
Elliot Lee's avatar
Elliot Lee committed
582
583
}

584
/* end of the dialog */
Elliot Lee's avatar
Elliot Lee committed
585
586
587
588
589
static void
dialog_close_callback (GtkWidget *widget, 
		       gpointer   data)
{
  dbbrowser_t* dbbrowser = data;
590

591
592
593
594
595
596
597
598
599
600
601
602
  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
603
}
Elliot Lee's avatar
Elliot Lee committed
604

605
/* end of the dialog */
Elliot Lee's avatar
Elliot Lee committed
606
607
608
609
610
611
static void 
dialog_apply_callback (GtkWidget *widget, 
		       gpointer   data)
{
  dbbrowser_t* dbbrowser = data;

612
  (dbbrowser->apply_callback) (dbbrowser->selected_proc_name,
Elliot Lee's avatar
Elliot Lee committed
613
614
615
616
617
618
619
620
621
622
			       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,
623
			       dbbrowser->selected_return_vals);
Elliot Lee's avatar
Elliot Lee committed
624
625
}

626
/* search in the whole db */
Elliot Lee's avatar
Elliot Lee committed
627
628
629
630
static void 
dialog_search_callback (GtkWidget *widget, 
			gpointer   data)
{
631
632
633
  gchar **proc_list;
  gint num_procs;
  gint i, j;
Elliot Lee's avatar
Elliot Lee committed
634
  dbbrowser_t* dbbrowser = data;
635
636
  gchar *func_name, *label, *query_text;
  GString *query;
Elliot Lee's avatar
Elliot Lee committed
637

638
639
  gtk_clist_freeze (GTK_CLIST (dbbrowser->clist));
  gtk_clist_clear (GTK_CLIST (dbbrowser->clist));
Elliot Lee's avatar
Elliot Lee committed
640
641
642

  /* search */

643
  if (widget == (dbbrowser->name_button))
Elliot Lee's avatar
Elliot Lee committed
644
645
    {
      gtk_window_set_title (GTK_WINDOW (dbbrowser->dlg), 
Sven Neumann's avatar
Sven Neumann committed
646
			    _("DB Browser (by name - please wait)"));
647
648

      query = g_string_new ("");
649
      query_text = gtk_entry_get_text (GTK_ENTRY (dbbrowser->search_entry));
650
651
652
653
654
655
656
657
658
659
660

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

	  query_text++;
	}

Daniel Egger's avatar
Daniel Egger committed
661
662
663
      gimp_procedural_db_query (query->str,
			        ".*", ".*", ".*", ".*", ".*", ".*", 
			        &num_procs, &proc_list);
664
665

      g_string_free (query, TRUE);
Elliot Lee's avatar
Elliot Lee committed
666
    }
667
  else if (widget == (dbbrowser->blurb_button))
Elliot Lee's avatar
Elliot Lee committed
668
669
    {
      gtk_window_set_title (GTK_WINDOW (dbbrowser->dlg), 
Sven Neumann's avatar
Sven Neumann committed
670
			    _("DB Browser (by blurb - please wait)"));
Daniel Egger's avatar
Daniel Egger committed
671
672
673
674
675
      gimp_procedural_db_query (".*", 
			        gtk_entry_get_text(
				  GTK_ENTRY(dbbrowser->search_entry) ),
			        ".*", ".*", ".*", ".*", ".*",
			        &num_procs, &proc_list);
Elliot Lee's avatar
Elliot Lee committed
676
    }
677
678
  else
    {
Elliot Lee's avatar
Elliot Lee committed
679
      gtk_window_set_title (GTK_WINDOW (dbbrowser->dlg), 
Sven Neumann's avatar
Sven Neumann committed
680
			    _("DB Browser (please wait)"));
Daniel Egger's avatar
Daniel Egger committed
681
682
      gimp_procedural_db_query (".*", ".*", ".*", ".*", ".*", ".*", ".*", 
			        &num_procs, &proc_list);
683
    }
Elliot Lee's avatar
Elliot Lee committed
684

685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
  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);
    }
702

703
704
705
706
707
708
  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);
    }
709
710

  /*
Elliot Lee's avatar
Elliot Lee committed
711
712
713
714
715
716
717
718
719
720
721
722
723
724
  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;
	}
      }
725
  
Elliot Lee's avatar
Elliot Lee committed
726
727
728
729
      proc_list[savej][0]='\255';

      label_name = g_strdup( insert_name );
      convert_string( label_name );
730
      gtk_clist_append (GTK_CLIST (dbbrowser->clist), &label_name);
Elliot Lee's avatar
Elliot Lee committed
731
732
733
734
735
736

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

      g_free(label_name);
    }
  }
737
  */
Elliot Lee's avatar
Elliot Lee committed
738
  
739
740
741
742
  if (dbbrowser->clist)
    {
      ;
    }
Elliot Lee's avatar
Elliot Lee committed
743
  
744
  g_free (proc_list);
Elliot Lee's avatar
Elliot Lee committed
745

Sven Neumann's avatar
Sven Neumann committed
746
  gtk_window_set_title (GTK_WINDOW (dbbrowser->dlg), _("DB Browser"));
747
  gtk_clist_thaw (GTK_CLIST (dbbrowser->clist));
Elliot Lee's avatar
Elliot Lee committed
748
749
750
751
752
753

}

/* utils ... */

static void 
754
convert_string (gchar *str)
Elliot Lee's avatar
Elliot Lee committed
755
756
757
758
759
760
761
762
{
  while (*str)
    {
      if (*str == '_') *str = '-';
      str++;
    }
}

763
static gchar * 
Daniel Egger's avatar
Daniel Egger committed
764
GParamType2char (GimpPDBArgType t)
Elliot Lee's avatar
Elliot Lee committed
765
{
766
767
  switch (t)
    {
Daniel Egger's avatar
Daniel Egger committed
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
    case GIMP_PDB_INT32: return "INT32";
    case GIMP_PDB_INT16: return "INT16";
    case GIMP_PDB_INT8: return "INT8";
    case GIMP_PDB_FLOAT: return "FLOAT";
    case GIMP_PDB_STRING: return "STRING";
    case GIMP_PDB_INT32ARRAY: return "INT32ARRAY";
    case GIMP_PDB_INT16ARRAY: return "INT16ARRAY";
    case GIMP_PDB_INT8ARRAY: return "INT8ARRAY";
    case GIMP_PDB_FLOATARRAY: return "FLOATARRAY";
    case GIMP_PDB_STRINGARRAY: return "STRINGARRAY";
    case GIMP_PDB_COLOR: return "COLOR";
    case GIMP_PDB_REGION: return "REGION";
    case GIMP_PDB_DISPLAY: return "DISPLAY";
    case GIMP_PDB_IMAGE: return "IMAGE";
    case GIMP_PDB_LAYER: return "LAYER";
    case GIMP_PDB_CHANNEL: return "CHANNEL";
    case GIMP_PDB_DRAWABLE: return "DRAWABLE";
    case GIMP_PDB_SELECTION: return "SELECTION";
    case GIMP_PDB_BOUNDARY: return "BOUNDARY";
    case GIMP_PDB_PATH: return "PATH";
    case GIMP_PDB_PARASITE: return "PARASITE";
    case GIMP_PDB_STATUS: return "STATUS";
    case GIMP_PDB_END: return "END";
791
792
    default: return "UNKNOWN?";
    }
Elliot Lee's avatar
Elliot Lee committed
793
}