gimpprocview.c 9.86 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 7 8 9 10 11
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * 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 17 18 19
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
20 21
 */

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

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

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

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
/*  local function prototypes  */
46

47 48 49 50 51
static GtkWidget * gimp_proc_view_create_params (GimpParamDef *params,
                                                 gint          n_params,
                                                 GtkSizeGroup *name_group,
                                                 GtkSizeGroup *type_group,
                                                 GtkSizeGroup *desc_group);
52

53

54 55
/*  public functions  */

56
GtkWidget *
57 58 59 60 61 62 63 64 65 66 67 68
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,
                    GimpParamDef    *params,
                    GimpParamDef    *return_vals)
Elliot Lee's avatar
Elliot Lee committed
69
{
70 71 72 73 74 75 76 77
  GtkWidget    *main_vbox;
  GtkWidget    *frame;
  GtkWidget    *vbox;
  GtkWidget    *table;
  GtkWidget    *label;
  GtkSizeGroup *name_group;
  GtkSizeGroup *type_group;
  GtkSizeGroup *desc_group;
78
  const gchar  *type_str;
79 80 81 82 83 84 85 86 87 88
  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;
89

90
  main_vbox = gtk_vbox_new (FALSE, 12);
91

92
  /* show the name */
93

94 95 96 97 98
  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);
99

100 101
  vbox = gtk_vbox_new (FALSE, 8);
  gtk_container_add (GTK_CONTAINER (frame), vbox);
102 103
  gtk_widget_show (vbox);

104 105 106 107 108
  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);
109 110 111 112 113
  gimp_label_set_attributes (GTK_LABEL (label),
                             PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
                             -1);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
114
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
115

116
  if (menu_path)
117
    {
118
      label = gtk_label_new_with_mnemonic (menu_path);
Sven Neumann's avatar
Sven Neumann committed
119
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
120 121 122 123
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
      gtk_widget_show (label);
124
    }
Elliot Lee's avatar
Elliot Lee committed
125

126
  if (blurb)
Elliot Lee's avatar
Elliot Lee committed
127
    {
128
      label = gtk_label_new (blurb);
129
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
130
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
131 132
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
133
      gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
134
    }
135

136 137 138 139 140 141
  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)
142
    {
143 144 145 146 147 148 149 150
      frame = gimp_frame_new (_("Parameters"));
      gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
      gtk_widget_show (frame);

      table = gimp_proc_view_create_params (params, n_params,
                                            name_group, type_group, desc_group);
      gtk_container_add (GTK_CONTAINER (frame), table);
      gtk_widget_show (table);
151
    }
Elliot Lee's avatar
Elliot Lee committed
152 153

  /* out parameters */
154
  if (n_return_vals)
Elliot Lee's avatar
Elliot Lee committed
155
    {
156 157 158 159 160 161 162 163
      frame = gimp_frame_new (_("Return Values"));
      gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
      gtk_widget_show (frame);

      table = gimp_proc_view_create_params (return_vals, n_return_vals,
                                            name_group, type_group, desc_group);
      gtk_container_add (GTK_CONTAINER (frame), table);
      gtk_widget_show (table);
Elliot Lee's avatar
Elliot Lee committed
164 165
    }

166 167 168
  if (! help && ! author && ! date && ! copyright)
    return main_vbox;

169 170 171 172 173 174 175
  frame = gimp_frame_new (_("Additional Information"));
  gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);

  vbox = gtk_vbox_new (FALSE, 8);
  gtk_container_add (GTK_CONTAINER (frame), vbox);
  gtk_widget_show (vbox);
Elliot Lee's avatar
Elliot Lee committed
176

Sven Neumann's avatar
Sven Neumann committed
177
  /* show the help */
178
  if (help)
Sven Neumann's avatar
Sven Neumann committed
179
    {
180
      label = gtk_label_new (help);
181
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
182
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
183
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
184 185
      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
      gtk_widget_show (label);
Sven Neumann's avatar
Sven Neumann committed
186 187 188 189
    }

  /* show the author & the copyright */

190 191 192 193 194
  if (! author && ! date && ! copyright)
    return main_vbox;

  table = gtk_table_new ((author != 0) + (date != 0) + (copyright != 0), 2,
                         FALSE);
195 196 197 198 199
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
  gtk_table_set_row_spacings (GTK_TABLE (table), 4);
  gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
  gtk_widget_show (table);

200
  row = 0;
201

202 203 204
  if (author)
    {
      label = gtk_label_new (author);
205
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
206 207
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
Elliot Lee's avatar
Elliot Lee committed
208

209 210 211 212
      gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
                                 _("Author:"), 0.0, 0.0,
                                 label, 3, FALSE);
    }
Elliot Lee's avatar
Elliot Lee committed
213

214 215 216
  if (date)
    {
      label = gtk_label_new (date);
217
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
218 219
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
Elliot Lee's avatar
Elliot Lee committed
220

221 222 223 224
      gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
                                 _("Date:"), 0.0, 0.0,
                                 label, 3, FALSE);
    }
Elliot Lee's avatar
Elliot Lee committed
225

226 227 228
  if (copyright)
    {
      label = gtk_label_new (copyright);
229
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
230 231 232 233 234 235 236
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);

      gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
                                 _("Copyright:"), 0.0, 0.0,
                                 label, 3, FALSE);
    }
Elliot Lee's avatar
Elliot Lee committed
237

238
  return main_vbox;
239 240
}

Sven Neumann's avatar
Sven Neumann committed
241

242
/*  private functions  */
Elliot Lee's avatar
Elliot Lee committed
243

244 245 246 247 248 249
static GtkWidget *
gimp_proc_view_create_params (GimpParamDef *params,
                              gint          n_params,
                              GtkSizeGroup *name_group,
                              GtkSizeGroup *type_group,
                              GtkSizeGroup *desc_group)
Elliot Lee's avatar
Elliot Lee committed
250
{
251 252
  GtkWidget *table;
  gint       i;
Elliot Lee's avatar
Elliot Lee committed
253

254 255 256
  table = gtk_table_new (n_params, 3, FALSE);
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
  gtk_table_set_row_spacings (GTK_TABLE (table), 4);
Elliot Lee's avatar
Elliot Lee committed
257

258
  for (i = 0; i < n_params; i++)
Elliot Lee's avatar
Elliot Lee committed
259
    {
260 261 262 263
      GtkWidget   *label;
      const gchar *type;
      gchar       *upper;

264 265 266 267 268 269 270
      /* name */
      label = gtk_label_new (params[i].name);
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
      gtk_size_group_add_widget (name_group, label);
      gtk_table_attach (GTK_TABLE (table), label,
                        0, 1, i, i + 1, GTK_FILL, GTK_FILL, 0, 0);
      gtk_widget_show (label);
271

272
      /* type */
273 274 275 276 277 278 279 280 281
      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);

282
      gimp_label_set_attributes (GTK_LABEL (label),
283 284
                                 PANGO_ATTR_FAMILY, "monospace",
                                 PANGO_ATTR_STYLE,  PANGO_STYLE_ITALIC,
285 286 287 288 289 290 291 292 293
                                 -1);
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
      gtk_size_group_add_widget (type_group, label);
      gtk_table_attach (GTK_TABLE (table), label,
                        1, 2, i, i + 1, GTK_FILL, GTK_FILL, 0, 0);
      gtk_widget_show (label);

      /* description */
      label = gtk_label_new (params[i].description);
294
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
295 296 297 298
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
      gtk_size_group_add_widget (desc_group, label);
      gtk_table_attach (GTK_TABLE (table), label,
299
                        2, 3, i, i + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
300
      gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
301
    }
302 303

  return table;
Elliot Lee's avatar
Elliot Lee committed
304
}