gimpprocview.c 10.4 KB
Newer Older
1 2
/* LIBGIMP - The GIMP Library
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
Elliot Lee's avatar
Elliot Lee committed
3
 *
4
 * gimpprocview.c
Elliot Lee's avatar
Elliot Lee committed
5
 *
6
 * This library is free software: you can redistribute it and/or
7 8
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
9
 * version 3 of the License, or (at your option) any later version.
10 11
 *
 * This library is distributed in the hope that it will be useful,
Elliot Lee's avatar
Elliot Lee committed
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
Elliot Lee's avatar
Elliot Lee committed
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17 18
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
Elliot Lee's avatar
Elliot Lee committed
19 20
 */

21
/*
22 23 24 25 26
 * 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
27

Sven Neumann's avatar
Sven Neumann committed
28
#include "config.h"
29

Daniel Egger's avatar
Daniel Egger committed
30
#include <string.h>
31

32
#include <gegl.h>
33 34
#include <gtk/gtk.h>

35
#include "libgimpwidgets/gimpwidgets.h"
36

37 38 39
#include "gimp.h"

#include "gimpuitypes.h"
40
#include "gimpprocview.h"
41

42
#include "libgimp-intl.h"
Elliot Lee's avatar
Elliot Lee committed
43

44

45 46 47 48 49 50 51 52 53 54
/**
 * SECTION: gimpprocview
 * @title: GimpProcView
 * @short_description: A widget showing information about a PDB procedure.
 *
 * A widget showing information about a PDB procedure, mainly for the
 * procedure and plug-in browsers.
 **/


55
/*  local function prototypes  */
56

57 58 59 60 61
static GtkWidget * gimp_proc_view_create_params (const GimpParamDef *params,
                                                 gint                n_params,
                                                 GtkSizeGroup       *name_group,
                                                 GtkSizeGroup       *type_group,
                                                 GtkSizeGroup       *desc_group);
62

63

64 65
/*  public functions  */

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83

/**
 * gimp_proc_view_new:
 * @name:
 * @menu_path:
 * @blurb:
 * @help:
 * @author:
 * @copyright:
 * @date:
 * @type:
 * @n_params:
 * @n_return_vals:
 * @params:
 * @return_vals:
 *
 * Return value: a new widget providing a view on a GIMP procedure
 *
84
 * Since: 2.4
85
 **/
86
GtkWidget *
87 88 89 90 91 92 93 94 95 96 97 98
gimp_proc_view_new (const gchar        *name,
                    const gchar        *menu_path,
                    const gchar        *blurb,
                    const gchar        *help,
                    const gchar        *author,
                    const gchar        *copyright,
                    const gchar        *date,
                    GimpPDBProcType     type,
                    gint                n_params,
                    gint                n_return_vals,
                    const GimpParamDef *params,
                    const GimpParamDef *return_vals)
Elliot Lee's avatar
Elliot Lee committed
99
{
100 101 102
  GtkWidget    *main_vbox;
  GtkWidget    *frame;
  GtkWidget    *vbox;
103
  GtkWidget    *grid;
104 105 106 107
  GtkWidget    *label;
  GtkSizeGroup *name_group;
  GtkSizeGroup *type_group;
  GtkSizeGroup *desc_group;
108
  const gchar  *type_str;
109 110 111 112 113 114 115 116 117 118
  gint          row;

  if (blurb     && strlen (blurb) < 2)     blurb     = NULL;
  if (help      && strlen (help) < 2)      help      = NULL;
  if (author    && strlen (author) < 2)    author    = NULL;
  if (date      && strlen (date) < 2)      date      = NULL;
  if (copyright && strlen (copyright) < 2) copyright = NULL;

  if (blurb && help && ! strcmp (blurb, help))
    help = NULL;
119

120
  main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
121

122
  /* show the name */
123

124 125 126 127 128
  frame = gimp_frame_new (name);
  label = gtk_frame_get_label_widget (GTK_FRAME (frame));
  gtk_label_set_selectable (GTK_LABEL (label), TRUE);
  gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);
129

130
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
131
  gtk_container_add (GTK_CONTAINER (frame), vbox);
132 133
  gtk_widget_show (vbox);

134 135 136 137 138
  if (! gimp_enum_get_value (GIMP_TYPE_PDB_PROC_TYPE, type,
                             NULL, NULL, &type_str, NULL))
    type_str = "UNKNOWN";

  label = gtk_label_new (type_str);
139 140 141
  gimp_label_set_attributes (GTK_LABEL (label),
                             PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
                             -1);
142
  gtk_label_set_xalign (GTK_LABEL (label), 0.0);
143
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
144
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
145

146
  if (menu_path)
147
    {
148
      label = gtk_label_new_with_mnemonic (menu_path);
Sven Neumann's avatar
Sven Neumann committed
149
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
150
      gtk_label_set_xalign (GTK_LABEL (label), 0.0);
151 152 153
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
      gtk_widget_show (label);
154
    }
Elliot Lee's avatar
Elliot Lee committed
155

156
  if (blurb)
Elliot Lee's avatar
Elliot Lee committed
157
    {
158
      label = gtk_label_new (blurb);
159
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
160
      gtk_label_set_xalign (GTK_LABEL (label), 0.0);
161 162
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
163
      gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
164
    }
165

166 167 168 169 170 171
  name_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
  type_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
  desc_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);

  /* in parameters */
  if (n_params)
172
    {
173 174 175 176
      frame = gimp_frame_new (_("Parameters"));
      gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
      gtk_widget_show (frame);

177 178 179 180
      grid = gimp_proc_view_create_params (params, n_params,
                                           name_group, type_group, desc_group);
      gtk_container_add (GTK_CONTAINER (frame), grid);
      gtk_widget_show (grid);
181
    }
Elliot Lee's avatar
Elliot Lee committed
182 183

  /* out parameters */
184
  if (n_return_vals)
Elliot Lee's avatar
Elliot Lee committed
185
    {
186 187 188 189
      frame = gimp_frame_new (_("Return Values"));
      gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
      gtk_widget_show (frame);

190 191 192 193
      grid = gimp_proc_view_create_params (return_vals, n_return_vals,
                                           name_group, type_group, desc_group);
      gtk_container_add (GTK_CONTAINER (frame), grid);
      gtk_widget_show (grid);
Elliot Lee's avatar
Elliot Lee committed
194 195
    }

196 197 198
  if (! help && ! author && ! date && ! copyright)
    return main_vbox;

199 200 201 202
  frame = gimp_frame_new (_("Additional Information"));
  gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);

203
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
204 205
  gtk_container_add (GTK_CONTAINER (frame), vbox);
  gtk_widget_show (vbox);
Elliot Lee's avatar
Elliot Lee committed
206

Sven Neumann's avatar
Sven Neumann committed
207
  /* show the help */
208
  if (help)
Sven Neumann's avatar
Sven Neumann committed
209
    {
210
      label = gtk_label_new (help);
211
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
212
      gtk_label_set_xalign (GTK_LABEL (label), 0.0);
213
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
214 215
      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
      gtk_widget_show (label);
Sven Neumann's avatar
Sven Neumann committed
216 217 218 219
    }

  /* show the author & the copyright */

220 221 222
  if (! author && ! date && ! copyright)
    return main_vbox;

223 224 225 226 227
  grid = gtk_grid_new ();
  gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
  gtk_grid_set_row_spacing (GTK_GRID (grid), 4);
  gtk_box_pack_start (GTK_BOX (vbox), grid, FALSE, FALSE, 0);
  gtk_widget_show (grid);
228

229
  row = 0;
230

231 232 233
  if (author)
    {
      label = gtk_label_new (author);
234
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
235 236
      gtk_label_set_xalign (GTK_LABEL (label), 0.0);
      gtk_label_set_yalign (GTK_LABEL (label), 0.0);
237
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
Elliot Lee's avatar
Elliot Lee committed
238

239 240 241
      gimp_grid_attach_aligned (GTK_GRID (grid), 0, row++,
                                _("Author:"), 0.0, 0.0,
                                label, 3);
242
    }
Elliot Lee's avatar
Elliot Lee committed
243

244 245 246
  if (date)
    {
      label = gtk_label_new (date);
247
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
248 249
      gtk_label_set_xalign (GTK_LABEL (label), 0.0);
      gtk_label_set_yalign (GTK_LABEL (label), 0.0);
250
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
Elliot Lee's avatar
Elliot Lee committed
251

252 253 254
      gimp_grid_attach_aligned (GTK_GRID (grid), 0, row++,
                                _("Date:"), 0.0, 0.0,
                                label, 3);
255
    }
Elliot Lee's avatar
Elliot Lee committed
256

257 258 259
  if (copyright)
    {
      label = gtk_label_new (copyright);
260
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
261 262
      gtk_label_set_xalign (GTK_LABEL (label), 0.0);
      gtk_label_set_yalign (GTK_LABEL (label), 0.0);
263 264
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);

265 266 267
      gimp_grid_attach_aligned (GTK_GRID (grid), 0, row++,
                                _("Copyright:"), 0.0, 0.0,
                                label, 3);
268
    }
Elliot Lee's avatar
Elliot Lee committed
269

270
  return main_vbox;
271 272
}

Sven Neumann's avatar
Sven Neumann committed
273

274
/*  private functions  */
Elliot Lee's avatar
Elliot Lee committed
275

276
static GtkWidget *
277 278 279 280 281
gimp_proc_view_create_params (const GimpParamDef *params,
                              gint                n_params,
                              GtkSizeGroup       *name_group,
                              GtkSizeGroup       *type_group,
                              GtkSizeGroup       *desc_group)
Elliot Lee's avatar
Elliot Lee committed
282
{
283
  GtkWidget *grid;
284
  gint       i;
Elliot Lee's avatar
Elliot Lee committed
285

286 287 288
  grid = gtk_grid_new ();
  gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
  gtk_grid_set_row_spacing (GTK_GRID (grid), 4);
Elliot Lee's avatar
Elliot Lee committed
289

290
  for (i = 0; i < n_params; i++)
Elliot Lee's avatar
Elliot Lee committed
291
    {
292 293 294 295
      GtkWidget   *label;
      const gchar *type;
      gchar       *upper;

296 297
      /* name */
      label = gtk_label_new (params[i].name);
298 299
      gtk_label_set_xalign (GTK_LABEL (label), 0.0);
      gtk_label_set_yalign (GTK_LABEL (label), 0.0);
300
      gtk_size_group_add_widget (name_group, label);
301
      gtk_grid_attach (GTK_GRID (grid), label, 0, i, 1, 1);
302
      gtk_widget_show (label);
303

304
      /* type */
305 306 307 308 309 310 311 312 313
      if (! gimp_enum_get_value (GIMP_TYPE_PDB_ARG_TYPE, params[i].type,
                                 NULL, &type, NULL, NULL))
        upper = g_strdup ("UNKNOWN");
      else
        upper = g_ascii_strup (type, -1);

      label = gtk_label_new (upper);
      g_free (upper);

314
      gimp_label_set_attributes (GTK_LABEL (label),
315 316
                                 PANGO_ATTR_FAMILY, "monospace",
                                 PANGO_ATTR_STYLE,  PANGO_STYLE_ITALIC,
317
                                 -1);
318 319
      gtk_label_set_xalign (GTK_LABEL (label), 0.0);
      gtk_label_set_yalign (GTK_LABEL (label), 0.0);
320
      gtk_size_group_add_widget (type_group, label);
321
      gtk_grid_attach (GTK_GRID (grid), label, 1, i, 1, 1);
322 323 324 325
      gtk_widget_show (label);

      /* description */
      label = gtk_label_new (params[i].description);
326
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
327 328
      gtk_label_set_xalign (GTK_LABEL (label), 0.0);
      gtk_label_set_yalign (GTK_LABEL (label), 0.0);
329 330
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
      gtk_size_group_add_widget (desc_group, label);
331
      gtk_grid_attach (GTK_GRID (grid), label, 2, i, 1, 1);
332
      gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
333
    }
334

335
  return grid;
Elliot Lee's avatar
Elliot Lee committed
336
}