gimpprocbrowser.c 22.2 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
/* end of configuration */

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

typedef struct
{
  GtkWidget *dlg;

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

Michael Natterer's avatar
Michael Natterer committed
64
  GtkWidget *descr_vbox;
65
66
67
68
69
70
  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 *
Michael Natterer's avatar
Michael Natterer committed
123
gimp_db_browser (GimpDBBrowserApplyCallback apply_callback)
Elliot Lee's avatar
Elliot Lee committed
124
125
126
{
  dbbrowser_t* dbbrowser;
  
127
128
129
  GtkWidget *hbox;
  GtkWidget *searchhbox;
  GtkWidget *vbox;
Elliot Lee's avatar
Elliot Lee committed
130
  GtkWidget *label;
Michael Natterer's avatar
Michael Natterer committed
131
  GtkWidget *scrolled_window;
132

133
  dbbrowser = g_new (dbbrowser_t, 1);
Elliot Lee's avatar
Elliot Lee committed
134
135
136
137
  
  dbbrowser->apply_callback = apply_callback;
  
  /* the dialog box */
138

139
140
141
142
  if (apply_callback)
    {
      dbbrowser->dlg =
	gimp_dialog_new (_("DB Browser (init...)"), "dbbrowser",
143
			 gimp_standard_help_func, "filters/dbbrowser.html",
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
			 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",
162
			 gimp_standard_help_func, "filters/dbbrowser.html",
163
164
165
166
167
168
169
170
171
172
173
174
175
			 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
176
  gtk_signal_connect (GTK_OBJECT (dbbrowser->dlg), "destroy",
177
                      GTK_SIGNAL_FUNC (dialog_close_callback),
Elliot Lee's avatar
Elliot Lee committed
178
179
180
                      dbbrowser);
  
  /* hbox : left=list ; right=description */
Michael Natterer's avatar
Michael Natterer committed
181
182
183

  hbox = gtk_hbox_new (FALSE, 4);
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
Elliot Lee's avatar
Elliot Lee committed
184
185
186
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dbbrowser->dlg)->vbox), 
		      hbox, TRUE, TRUE, 0);
  gtk_widget_show (hbox);
187

Elliot Lee's avatar
Elliot Lee committed
188
189
  /* left = vbox : the list and the search entry */
  
Michael Natterer's avatar
Michael Natterer committed
190
191
192
193
  vbox = gtk_vbox_new (FALSE, 4);
  gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
  gtk_widget_show (vbox);

Elliot Lee's avatar
Elliot Lee committed
194
195
  /* list : list in a scrolled_win */
  
Manish Singh's avatar
Manish Singh committed
196
197
  dbbrowser->scrolled_win = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (dbbrowser->scrolled_win),
Michael Natterer's avatar
Michael Natterer committed
198
199
200
201
				  GTK_POLICY_AUTOMATIC,
				  GTK_POLICY_ALWAYS);
  gtk_box_pack_start (GTK_BOX (vbox), dbbrowser->scrolled_win, TRUE, TRUE, 0);
  gtk_widget_show (dbbrowser->scrolled_win);
202

Michael Natterer's avatar
Michael Natterer committed
203
  dbbrowser->clist = gtk_clist_new (1);
204
  gtk_widget_set_usize (dbbrowser->clist, DBL_LIST_WIDTH, DBL_HEIGHT);
Michael Natterer's avatar
Michael Natterer committed
205
206
  gtk_clist_set_selection_mode (GTK_CLIST (dbbrowser->clist),
			        GTK_SELECTION_BROWSE);
Manish Singh's avatar
Manish Singh committed
207
  gtk_container_add (GTK_CONTAINER (dbbrowser->scrolled_win), dbbrowser->clist);
208
  gtk_widget_show (dbbrowser->clist);
Michael Natterer's avatar
Michael Natterer committed
209
210
211
212

  g_signal_connect (G_OBJECT (dbbrowser->clist), "select_row",
		    G_CALLBACK (procedure_select_callback),
		    dbbrowser);
Elliot Lee's avatar
Elliot Lee committed
213
214
215

  /* search entry */

216
  searchhbox = gtk_hbox_new (FALSE, 4);
Michael Natterer's avatar
Michael Natterer committed
217
  gtk_box_pack_start (GTK_BOX (vbox), searchhbox, FALSE, FALSE, 0);
218
  gtk_widget_show (searchhbox);
Elliot Lee's avatar
Elliot Lee committed
219

220
  label = gtk_label_new (_("Search:"));
Michael Natterer's avatar
Michael Natterer committed
221
222
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_box_pack_start (GTK_BOX (searchhbox), label, FALSE, FALSE, 0);
223
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
224

225
  dbbrowser->search_entry = gtk_entry_new ();
Michael Natterer's avatar
Michael Natterer committed
226
227
228
  gtk_box_pack_start (GTK_BOX (searchhbox), dbbrowser->search_entry,
		      TRUE, TRUE, 0);
  gtk_widget_show (dbbrowser->search_entry);
Elliot Lee's avatar
Elliot Lee committed
229
230
231

  /* right = description */

Michael Natterer's avatar
Michael Natterer committed
232
233
234
235
  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_set_usize (scrolled_window, DBL_WIDTH - DBL_LIST_WIDTH, 0);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
				  GTK_POLICY_AUTOMATIC, 
236
				  GTK_POLICY_ALWAYS);
Michael Natterer's avatar
Michael Natterer committed
237
238
239
240
241
242
243
244
  gtk_box_pack_start (GTK_BOX (hbox), scrolled_window, TRUE, TRUE, 0);
  gtk_widget_show (scrolled_window);

  dbbrowser->descr_vbox = gtk_vbox_new (FALSE, 0);
  gtk_container_set_border_width (GTK_CONTAINER (dbbrowser->descr_vbox), 4);
  gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window),
					 dbbrowser->descr_vbox);
  gtk_widget_show (dbbrowser->descr_vbox);
Elliot Lee's avatar
Elliot Lee committed
245
246
247
248
249
250
251

  /* now build the list */

  gtk_widget_show (dbbrowser->dlg);

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

Michael Natterer's avatar
Michael Natterer committed
252
253
  dbbrowser->descr_table               = NULL;
  dbbrowser->selected_proc_name        = NULL;
Elliot Lee's avatar
Elliot Lee committed
254
  dbbrowser->selected_scheme_proc_name = NULL;
Michael Natterer's avatar
Michael Natterer committed
255
256
257
258
259
260
261
262
263
264
  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;
Elliot Lee's avatar
Elliot Lee committed
265
266

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

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

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

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

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

291
/* update the description box (right) */
Elliot Lee's avatar
Elliot Lee committed
292
293
294
295
static void 
dialog_select (dbbrowser_t *dbbrowser, 
	       gchar       *proc_name)
{
Michael Natterer's avatar
Michael Natterer committed
296
297
298
299
300
301
302
303
304
  GtkWidget     *old_table;
  GtkWidget     *label;
  GtkWidget     *entry;
  GtkWidget     *sep;
  GtkWidget     *scrolled_window;
  GtkWidget     *text_view;
  GtkTextBuffer *text_buffer = NULL;
  gint           i;
  gint           row = 0;
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319

  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
320

321
322
323
324
325
326
327
328
329
330
331
  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));
Michael Natterer's avatar
Michael Natterer committed
332

Elliot Lee's avatar
Elliot Lee committed
333
334
335
  /* save the "old" table */
  old_table = dbbrowser->descr_table;

Michael Natterer's avatar
Michael Natterer committed
336
337
338
339
  dbbrowser->descr_table = gtk_table_new (10 +
					  dbbrowser->selected_nparams +
					  dbbrowser->selected_nreturn_vals,
					  5, FALSE);
Elliot Lee's avatar
Elliot Lee committed
340

Michael Natterer's avatar
Michael Natterer committed
341
342
  gtk_table_set_col_spacings (GTK_TABLE (dbbrowser->descr_table), 6);
  gtk_table_set_row_spacing (GTK_TABLE (dbbrowser->descr_table), 0, 2);
Elliot Lee's avatar
Elliot Lee committed
343
344
345

  /* show the name */

Michael Natterer's avatar
Michael Natterer committed
346
347
348
  entry = gtk_entry_new ();
  gtk_entry_set_text (GTK_ENTRY (entry), dbbrowser->selected_scheme_proc_name);
  gtk_entry_set_editable (GTK_ENTRY (entry), FALSE);
Elliot Lee's avatar
Elliot Lee committed
349

Michael Natterer's avatar
Michael Natterer committed
350
351
352
  gimp_table_attach_aligned (GTK_TABLE (dbbrowser->descr_table), 0, row++,
			     _("Name:"), 1.0, 0.5,
			     entry, 3, FALSE);
Elliot Lee's avatar
Elliot Lee committed
353
354
355

  /* show the description */

356
  label = gtk_label_new (dbbrowser->selected_proc_blurb);
Elliot Lee's avatar
Elliot Lee committed
357
358
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);

Michael Natterer's avatar
Michael Natterer committed
359
360
361
362
363
364
365
366
  gimp_table_attach_aligned (GTK_TABLE (dbbrowser->descr_table), 0, row++,
			     _("Blurb:"), 1.0, 0.5,
			     label, 3, FALSE);

  sep = gtk_hseparator_new ();
  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), sep,
		    0, 4, row, row+1, GTK_FILL, GTK_FILL, 0, 6);
  gtk_widget_show (sep);
Elliot Lee's avatar
Elliot Lee committed
367
368
369
370
371
  row++;

  /* in parameters */
  if (dbbrowser->selected_nparams) 
    {
372
      label = gtk_label_new (_("In:"));
Elliot Lee's avatar
Elliot Lee committed
373
374
      gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
      gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
Michael Natterer's avatar
Michael Natterer committed
375
376
			0, 1, row, row + (dbbrowser->selected_nparams), 
			GTK_FILL, GTK_FILL, 0, 0);
377
      gtk_widget_show (label);
Michael Natterer's avatar
Michael Natterer committed
378

379
      for (i = 0; i < dbbrowser->selected_nparams; i++) 
Elliot Lee's avatar
Elliot Lee committed
380
381
	{
	  /* name */
382
	  label = gtk_label_new ((dbbrowser->selected_params[i]).name);
Elliot Lee's avatar
Elliot Lee committed
383
384
385
	  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);
386
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
387
388

	  /* type */
389
	  label = gtk_label_new (GParamType2char ((dbbrowser->selected_params[i]).type));
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,
			    2, 3, row, row+1, GTK_FILL, GTK_FILL, 0, 0);
393
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
394
395

	  /* description */
396
	  label = gtk_label_new ((dbbrowser->selected_params[i]).description);
Elliot Lee's avatar
Elliot Lee committed
397
398
399
	  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);
400
	  gtk_widget_show (label);
Michael Natterer's avatar
Michael Natterer committed
401

Elliot Lee's avatar
Elliot Lee committed
402
403
404
	  row++;
	}
    }
405

Elliot Lee's avatar
Elliot Lee committed
406
  if ((dbbrowser->selected_nparams) && 
407
408
      (dbbrowser->selected_nreturn_vals))
    {
Michael Natterer's avatar
Michael Natterer committed
409
410
411
412
      sep = gtk_hseparator_new ();
      gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), sep,
			0, 4, row, row+1, GTK_FILL, GTK_FILL, 0, 6);
      gtk_widget_show (sep);
413
414
      row++;
    }
Elliot Lee's avatar
Elliot Lee committed
415
416
417
418

  /* out parameters */
  if (dbbrowser->selected_nreturn_vals)
    {
419
      label = gtk_label_new (_("Out:"));
Elliot Lee's avatar
Elliot Lee committed
420
421
      gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
      gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
Michael Natterer's avatar
Michael Natterer committed
422
423
			0, 1, row, row + (dbbrowser->selected_nreturn_vals), 
			GTK_FILL, GTK_FILL, 0, 0);
424
      gtk_widget_show (label);
Michael Natterer's avatar
Michael Natterer committed
425

426
      for (i = 0; i < dbbrowser->selected_nreturn_vals; i++) 
Elliot Lee's avatar
Elliot Lee committed
427
428
	{
	  /* name */
429
	  label = gtk_label_new ((dbbrowser->selected_return_vals[i]).name);
Elliot Lee's avatar
Elliot Lee committed
430
431
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); 
	  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
Michael Natterer's avatar
Michael Natterer committed
432
			    1, 2, row, row+1, GTK_FILL, GTK_FILL, 0, 0);
433
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
434
435

	  /* type */
Michael Natterer's avatar
Michael Natterer committed
436
	  label = gtk_label_new (GParamType2char (dbbrowser->selected_return_vals[i].type));
Elliot Lee's avatar
Elliot Lee committed
437
438
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
	  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
Michael Natterer's avatar
Michael Natterer committed
439
			    2, 3, row, row+1, GTK_FILL, GTK_FILL, 0, 0);
440
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
441
442

	  /* description */
Michael Natterer's avatar
Michael Natterer committed
443
	  label = gtk_label_new (dbbrowser->selected_return_vals[i].description);
Elliot Lee's avatar
Elliot Lee committed
444
445
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); 
	  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
Michael Natterer's avatar
Michael Natterer committed
446
			    3, 4, row, row+1, GTK_FILL, GTK_FILL, 0, 0);
447
	  gtk_widget_show (label);
Michael Natterer's avatar
Michael Natterer committed
448

Elliot Lee's avatar
Elliot Lee committed
449
450
451
452
	  row++;
	}
    }

Michael Natterer's avatar
Michael Natterer committed
453
454
  if (dbbrowser->selected_nparams || 
      dbbrowser->selected_nreturn_vals)
455
    {
Michael Natterer's avatar
Michael Natterer committed
456
457
458
459
460
461
      sep = gtk_hseparator_new ();
      gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), sep,
			0, 4, row, row+1, GTK_FILL, GTK_FILL, 0, 6);
      gtk_widget_show (sep);
      row++;
    }
Elliot Lee's avatar
Elliot Lee committed
462

Sven Neumann's avatar
Sven Neumann committed
463
  /* show the help */
Michael Natterer's avatar
Michael Natterer committed
464
  if (dbbrowser->selected_proc_help &&
465
      (strlen (dbbrowser->selected_proc_help) > 1))
Sven Neumann's avatar
Sven Neumann committed
466
    {
Michael Natterer's avatar
Michael Natterer committed
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
      scrolled_window = gtk_scrolled_window_new (NULL, NULL);
      gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
				      GTK_POLICY_AUTOMATIC,
				      GTK_POLICY_AUTOMATIC);

      gimp_table_attach_aligned (GTK_TABLE (dbbrowser->descr_table), 0, row++,
				 _("Help:"), 1.0, 0.5,
				 scrolled_window, 3, FALSE);

      text_buffer = gtk_text_buffer_new (NULL);
      text_view = gtk_text_view_new_with_buffer (text_buffer);
      g_object_unref (G_OBJECT (text_buffer));

      gtk_text_buffer_set_text (text_buffer, dbbrowser->selected_proc_help, -1);

      gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE);
      gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD);
      gtk_widget_set_usize (text_view, -1, 60);
      gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);
      gtk_widget_show (text_view);

      sep = gtk_hseparator_new ();
      gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), sep,
			0, 4, row, row+1, GTK_FILL, GTK_FILL, 0, 6);
      gtk_widget_show (sep);
492

Sven Neumann's avatar
Sven Neumann committed
493
494
495
496
497
      row++;
    }

  /* show the author & the copyright */

498
  label = gtk_label_new (dbbrowser->selected_proc_author);
Elliot Lee's avatar
Elliot Lee committed
499
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
500

Michael Natterer's avatar
Michael Natterer committed
501
502
503
504
  gtk_table_set_row_spacing (GTK_TABLE (dbbrowser->descr_table), row, 2);
  gimp_table_attach_aligned (GTK_TABLE (dbbrowser->descr_table), 0, row++,
			     _("Author:"), 1.0, 0.5,
			     label, 3, FALSE);
Elliot Lee's avatar
Elliot Lee committed
505

506
  label = gtk_label_new (dbbrowser->selected_proc_date);
Elliot Lee's avatar
Elliot Lee committed
507
508
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);

Michael Natterer's avatar
Michael Natterer committed
509
510
511
512
  gtk_table_set_row_spacing (GTK_TABLE (dbbrowser->descr_table), row, 2);
  gimp_table_attach_aligned (GTK_TABLE (dbbrowser->descr_table), 0, row++,
			     _("Date:"), 1.0, 0.5,
			     label, 3, FALSE);
Elliot Lee's avatar
Elliot Lee committed
513

514
  label = gtk_label_new (dbbrowser->selected_proc_copyright);
Elliot Lee's avatar
Elliot Lee committed
515
516
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);

Michael Natterer's avatar
Michael Natterer committed
517
518
519
520
  gtk_table_set_row_spacing (GTK_TABLE (dbbrowser->descr_table), row, 2);
  gimp_table_attach_aligned (GTK_TABLE (dbbrowser->descr_table), 0, row++,
			     _("Copyright:"), 1.0, 0.5,
			     label, 3, FALSE);
Elliot Lee's avatar
Elliot Lee committed
521

Michael Natterer's avatar
Michael Natterer committed
522
523
  if (old_table)
    gtk_container_remove (GTK_CONTAINER (dbbrowser->descr_vbox), old_table);
Sven Neumann's avatar
Sven Neumann committed
524

Michael Natterer's avatar
Michael Natterer committed
525
526
  gtk_box_pack_start (GTK_BOX (dbbrowser->descr_vbox), dbbrowser->descr_table,
		      FALSE, FALSE, 0);
527
  gtk_widget_show (dbbrowser->descr_table);
Elliot Lee's avatar
Elliot Lee committed
528
529
}

530
/* end of the dialog */
Elliot Lee's avatar
Elliot Lee committed
531
532
533
534
535
static void
dialog_close_callback (GtkWidget *widget, 
		       gpointer   data)
{
  dbbrowser_t* dbbrowser = data;
536

537
538
539
540
541
542
543
544
545
546
547
548
  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
549
}
Elliot Lee's avatar
Elliot Lee committed
550

551
/* end of the dialog */
Elliot Lee's avatar
Elliot Lee committed
552
553
554
555
556
557
static void 
dialog_apply_callback (GtkWidget *widget, 
		       gpointer   data)
{
  dbbrowser_t* dbbrowser = data;

558
  (dbbrowser->apply_callback) (dbbrowser->selected_proc_name,
Elliot Lee's avatar
Elliot Lee committed
559
560
561
562
563
564
565
566
567
568
			       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,
569
			       dbbrowser->selected_return_vals);
Elliot Lee's avatar
Elliot Lee committed
570
571
}

572
/* search in the whole db */
Elliot Lee's avatar
Elliot Lee committed
573
574
575
576
static void 
dialog_search_callback (GtkWidget *widget, 
			gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
577
578
579
580
581
582
583
584
  gchar       **proc_list;
  gint          num_procs;
  gint          i, j;
  dbbrowser_t  *dbbrowser = data;
  gchar        *func_name;
  gchar        *label;
  gchar        *query_text;
  GString      *query;
Elliot Lee's avatar
Elliot Lee committed
585

586
587
  gtk_clist_freeze (GTK_CLIST (dbbrowser->clist));
  gtk_clist_clear (GTK_CLIST (dbbrowser->clist));
Elliot Lee's avatar
Elliot Lee committed
588
589
590

  /* search */

591
  if (widget == (dbbrowser->name_button))
Elliot Lee's avatar
Elliot Lee committed
592
593
    {
      gtk_window_set_title (GTK_WINDOW (dbbrowser->dlg), 
Sven Neumann's avatar
Sven Neumann committed
594
			    _("DB Browser (by name - please wait)"));
595
596

      query = g_string_new ("");
597
      query_text = gtk_entry_get_text (GTK_ENTRY (dbbrowser->search_entry));
598
599
600
601
602
603
604
605
606
607
608

      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
609
610
611
      gimp_procedural_db_query (query->str,
			        ".*", ".*", ".*", ".*", ".*", ".*", 
			        &num_procs, &proc_list);
612
613

      g_string_free (query, TRUE);
Elliot Lee's avatar
Elliot Lee committed
614
    }
615
  else if (widget == (dbbrowser->blurb_button))
Elliot Lee's avatar
Elliot Lee committed
616
617
    {
      gtk_window_set_title (GTK_WINDOW (dbbrowser->dlg), 
Sven Neumann's avatar
Sven Neumann committed
618
			    _("DB Browser (by blurb - please wait)"));
Daniel Egger's avatar
Daniel Egger committed
619
      gimp_procedural_db_query (".*", 
Michael Natterer's avatar
Michael Natterer committed
620
621
			        gtk_entry_get_text
				(GTK_ENTRY (dbbrowser->search_entry)),
Daniel Egger's avatar
Daniel Egger committed
622
623
			        ".*", ".*", ".*", ".*", ".*",
			        &num_procs, &proc_list);
Elliot Lee's avatar
Elliot Lee committed
624
    }
625
626
  else
    {
Elliot Lee's avatar
Elliot Lee committed
627
      gtk_window_set_title (GTK_WINDOW (dbbrowser->dlg), 
Sven Neumann's avatar
Sven Neumann committed
628
			    _("DB Browser (please wait)"));
Daniel Egger's avatar
Daniel Egger committed
629
630
      gimp_procedural_db_query (".*", ".*", ".*", ".*", ".*", ".*", ".*", 
			        &num_procs, &proc_list);
631
    }
Elliot Lee's avatar
Elliot Lee committed
632

633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
  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);
    }
650

651
652
653
654
655
656
  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);
    }
657
658

  /*
Elliot Lee's avatar
Elliot Lee committed
659
660
661
662
663
664
665
666
667
668
669
670
671
672
  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;
	}
      }
673
  
Elliot Lee's avatar
Elliot Lee committed
674
675
676
677
      proc_list[savej][0]='\255';

      label_name = g_strdup( insert_name );
      convert_string( label_name );
678
      gtk_clist_append (GTK_CLIST (dbbrowser->clist), &label_name);
Elliot Lee's avatar
Elliot Lee committed
679
680
681
682
683
684

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

      g_free(label_name);
    }
  }
685
  */
Elliot Lee's avatar
Elliot Lee committed
686
  
687
688
689
690
  if (dbbrowser->clist)
    {
      ;
    }
Elliot Lee's avatar
Elliot Lee committed
691
  
692
  g_free (proc_list);
Elliot Lee's avatar
Elliot Lee committed
693

Sven Neumann's avatar
Sven Neumann committed
694
  gtk_window_set_title (GTK_WINDOW (dbbrowser->dlg), _("DB Browser"));
695
  gtk_clist_thaw (GTK_CLIST (dbbrowser->clist));
Elliot Lee's avatar
Elliot Lee committed
696
697
698
699
700
}

/* utils ... */

static void 
701
convert_string (gchar *str)
Elliot Lee's avatar
Elliot Lee committed
702
703
704
705
706
707
708
709
{
  while (*str)
    {
      if (*str == '_') *str = '-';
      str++;
    }
}

710
static gchar * 
Daniel Egger's avatar
Daniel Egger committed
711
GParamType2char (GimpPDBArgType t)
Elliot Lee's avatar
Elliot Lee committed
712
{
713
714
  switch (t)
    {
Daniel Egger's avatar
Daniel Egger committed
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
    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";
738
739
    default: return "UNKNOWN?";
    }
Elliot Lee's avatar
Elliot Lee committed
740
}