gimpprocbrowserdialog.c 23.7 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
/* 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 */
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
  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);
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

} 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 *
118 119 120 121 122 123 124 125 126 127 128 129
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
130 131 132
{
  dbbrowser_t* dbbrowser;
  
133 134 135
  GtkWidget *hbox;
  GtkWidget *searchhbox;
  GtkWidget *vbox;
Elliot Lee's avatar
Elliot Lee committed
136
  GtkWidget *label;
137

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

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

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

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

  /* search entry */

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

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

231
  dbbrowser->search_entry = gtk_entry_new ();
Elliot Lee's avatar
Elliot Lee committed
232 233 234 235 236 237 238 239 240
  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, 
241
				  GTK_POLICY_ALWAYS);
Elliot Lee's avatar
Elliot Lee committed
242 243 244 245 246 247 248
  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 */

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

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

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

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

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

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

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));
  
Elliot Lee's avatar
Elliot Lee committed
332 333 334
  /* save the "old" table */
  old_table = dbbrowser->descr_table;

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

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

  /* show the name */

343
  label = gtk_label_new (_("Name:"));
Elliot Lee's avatar
Elliot Lee committed
344 345 346
  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);
347
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
348

349 350 351
  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
352 353
  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), label,
		    1, 4, row, row+1, GTK_FILL, GTK_FILL, 0, 0);
354
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
355 356 357 358
  row++;

  /* show the description */

359
  label = gtk_label_new (_("Blurb:"));
Elliot Lee's avatar
Elliot Lee committed
360 361 362
  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);
363
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
364

365
  label = gtk_label_new (dbbrowser->selected_proc_blurb);
Elliot Lee's avatar
Elliot Lee committed
366 367 368
  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);
369
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
370 371
  row++;

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

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

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

	  /* description */
404
	  label = gtk_label_new ((dbbrowser->selected_params[i]).description);
Elliot Lee's avatar
Elliot Lee committed
405 406 407
	  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);
408
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
409 410 411 412
	  
	  row++;
	}
    }
413

Elliot Lee's avatar
Elliot Lee committed
414
  if ((dbbrowser->selected_nparams) && 
415 416 417 418 419 420 421 422 423
      (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
424 425 426 427

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

	  /* type */
445
	  label = gtk_label_new (GParamType2char((dbbrowser->selected_return_vals[i]).type));
Elliot Lee's avatar
Elliot Lee committed
446 447 448 449
	  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);
450
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
451 452

	  /* description */
453
	  label = gtk_label_new ((dbbrowser->selected_return_vals[i]).description);
Elliot Lee's avatar
Elliot Lee committed
454 455 456 457
	  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);
458
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
459 460 461 462 463
	  row++;
	}
    }

  if ((dbbrowser->selected_nparams) || 
464 465 466 467 468 469 470
      (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
471 472 473
    row++;
  }

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

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

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

  /* show the author & the copyright */

516
  label = gtk_label_new (_("Author:"));
Elliot Lee's avatar
Elliot Lee committed
517 518 519 520
  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);
521
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
522

523
  label = gtk_label_new (dbbrowser->selected_proc_author);
Elliot Lee's avatar
Elliot Lee committed
524 525 526 527
  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);
528
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
529
  row++;
530 531

  label = gtk_label_new (_("Date:"));
Elliot Lee's avatar
Elliot Lee committed
532 533 534 535
  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);
536
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
537

538
  label = gtk_label_new (dbbrowser->selected_proc_date);
Elliot Lee's avatar
Elliot Lee committed
539 540 541 542
  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);
543
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
544 545
  row++;

546
  label = gtk_label_new (_("Copyright:"));
Elliot Lee's avatar
Elliot Lee committed
547 548 549 550
  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);
551
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
552

553
  label = gtk_label_new (dbbrowser->selected_proc_copyright);
Elliot Lee's avatar
Elliot Lee committed
554 555 556 557
  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);
558
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
559 560
  row++;

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

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

  /* 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));
    }
576
  gtk_widget_show (dbbrowser->descr_table);
Elliot Lee's avatar
Elliot Lee committed
577 578
}

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

586 587 588 589 590 591 592 593 594 595 596 597
  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
598
}
Elliot Lee's avatar
Elliot Lee committed
599

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

607
  (dbbrowser->apply_callback) (dbbrowser->selected_proc_name,
Elliot Lee's avatar
Elliot Lee committed
608 609 610 611 612 613 614 615 616 617
			       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,
618
			       dbbrowser->selected_return_vals);
Elliot Lee's avatar
Elliot Lee committed
619 620
}

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

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

  /* search */

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

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

      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
657 658
			   ".*", ".*", ".*", ".*", ".*", ".*", 
			   &num_procs, &proc_list);
659 660

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

679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695
  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);
    }
696

697 698 699 700 701 702
  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);
    }
703 704

  /*
Elliot Lee's avatar
Elliot Lee committed
705 706 707 708 709 710 711 712 713 714 715 716 717 718
  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;
	}
      }
719
  
Elliot Lee's avatar
Elliot Lee committed
720 721 722 723
      proc_list[savej][0]='\255';

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

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

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

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

}

/* utils ... */

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

757 758
static gchar * 
GParamType2char (GParamType t)
Elliot Lee's avatar
Elliot Lee committed
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 786
  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
787
}