~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/common/uniteditor.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * This is a plug-in for the GIMP.
24
24
 
25
25
#include <string.h>
26
26
 
27
 
#include <gtk/gtk.h>
28
 
 
29
27
#include <libgimp/gimp.h>
30
28
#include <libgimp/gimpui.h>
31
29
 
32
30
#include "libgimp/stdplugins-intl.h"
33
31
 
34
32
 
 
33
#define PLUG_IN_PROC     "plug-in-unit-editor"
 
34
#define PLUG_IN_BINARY   "uniteditor"
35
35
#define RESPONSE_REFRESH 1
36
36
 
37
37
enum
81
81
static void     unit_list_init         (GtkTreeView           *tv);
82
82
 
83
83
 
84
 
GimpPlugInInfo PLUG_IN_INFO =
 
84
const GimpPlugInInfo PLUG_IN_INFO =
85
85
{
86
86
  NULL,  /* init_proc  */
87
87
  NULL,  /* quit_proc  */
117
117
  },
118
118
 
119
119
  { "unit-editor-new", GTK_STOCK_NEW,
120
 
    NULL, NULL,
121
 
    N_("Create a new unit from scratch."),
 
120
    NULL, "<control>N",
 
121
    N_("Create a new unit from scratch"),
122
122
    G_CALLBACK (new_callback)
123
123
  },
124
124
 
125
125
  { "unit-editor-duplicate", GIMP_STOCK_DUPLICATE,
126
 
    NULL, NULL,
127
 
    N_("Create a new unit with the currently "
128
 
       "selected unit as template."),
 
126
    NULL,  "<control>D",
 
127
    N_("Create a new unit using the currently selected unit as template"),
129
128
    G_CALLBACK (duplicate_callback)
130
129
  }
131
130
};
137
136
static void
138
137
query (void)
139
138
{
140
 
  static GimpParamDef args[] =
 
139
  static const GimpParamDef args[] =
141
140
  {
142
 
    { GIMP_PDB_INT32, "run_mode", "Interactive" }
 
141
    { GIMP_PDB_INT32, "run-mode", "Interactive" }
143
142
  };
144
143
 
145
 
  gimp_install_procedure ("plug_in_unit_editor",
146
 
                          "The GIMP unit editor (runs in interactive mode only)",
147
 
                          "The GIMP unit editor (runs in interactive mode only)",
 
144
  gimp_install_procedure (PLUG_IN_PROC,
 
145
                          N_("Create or alter units used in GIMP"),
 
146
                          "The GIMP unit editor",
148
147
                          "Michael Natterer <mitch@gimp.org>",
149
148
                          "Michael Natterer <mitch@gimp.org>",
150
149
                          "2000",
154
153
                          G_N_ELEMENTS (args), 0,
155
154
                          args, NULL);
156
155
 
157
 
  gimp_plugin_menu_register ("plug_in_unit_editor",
158
 
                             "<Toolbox>/Xtns/Extensions");
159
 
  gimp_plugin_icon_register ("plug_in_unit_editor",
160
 
                             GIMP_ICON_TYPE_STOCK_ID, GIMP_STOCK_TOOL_MEASURE);
 
156
  gimp_plugin_menu_register (PLUG_IN_PROC, "<Toolbox>/Xtns/Extensions");
 
157
  gimp_plugin_icon_register (PLUG_IN_PROC, GIMP_ICON_TYPE_STOCK_ID,
 
158
                             (const guint8 *) GIMP_STOCK_TOOL_MEASURE);
161
159
}
162
160
 
163
161
static void
180
178
  values[0].type          = GIMP_PDB_STATUS;
181
179
  values[0].data.d_status = GIMP_PDB_CALLING_ERROR;
182
180
 
183
 
  if (strcmp (name, "plug_in_unit_editor") == 0)
 
181
  if (strcmp (name, PLUG_IN_PROC) == 0)
184
182
    {
185
183
      values[0].data.d_status = GIMP_PDB_SUCCESS;
186
184
 
207
205
 
208
206
  GimpUnit   unit = GIMP_UNIT_PIXEL;
209
207
 
210
 
  dialog = gimp_dialog_new (_("New Unit"), "uniteditor",
 
208
  dialog = gimp_dialog_new (_("Add a New Unit"), PLUG_IN_BINARY,
211
209
                            main_dialog, GTK_DIALOG_MODAL,
212
 
                            gimp_standard_help_func, "plug-in-unit-editor",
 
210
                            gimp_standard_help_func, PLUG_IN_PROC,
213
211
 
214
212
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
215
 
                            GTK_STOCK_OK,     GTK_RESPONSE_OK,
 
213
                            GTK_STOCK_ADD,    GTK_RESPONSE_OK,
216
214
 
217
215
                            NULL);
218
216
 
 
217
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
 
218
                                           GTK_RESPONSE_OK,
 
219
                                           GTK_RESPONSE_CANCEL,
 
220
                                           -1);
 
221
 
219
222
  table = gtk_table_new (7, 2, FALSE);
220
223
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
221
224
  gtk_table_set_row_spacings (GTK_TABLE (table), 6);
321
324
        break;
322
325
 
323
326
      identifier   = g_strdup (gtk_entry_get_text (GTK_ENTRY (identifier_entry)));
324
 
      factor       = GTK_ADJUSTMENT (factor_adj)->value;
325
 
      digits       = ROUND (GTK_ADJUSTMENT (digits_adj)->value);
 
327
      factor       = gtk_adjustment_get_value (GTK_ADJUSTMENT (factor_adj));
 
328
      digits       = gtk_adjustment_get_value (GTK_ADJUSTMENT (digits_adj));
326
329
      symbol       = g_strdup (gtk_entry_get_text (GTK_ENTRY (symbol_entry)));
327
330
      abbreviation = g_strdup (gtk_entry_get_text (GTK_ENTRY (abbreviation_entry)));
328
331
      singular     = g_strdup (gtk_entry_get_text (GTK_ENTRY (singular_entry)));
334
337
      singular     = g_strstrip (singular);
335
338
      plural       = g_strstrip (plural);
336
339
 
337
 
      if (factor < GIMP_MIN_RESOLUTION)
338
 
        {
339
 
          g_message (_("Unit factor must not be 0."));
340
 
          continue;
341
 
        }
342
 
 
343
340
      if (!strlen (identifier) |
344
341
          !strlen (symbol) |
345
342
          !strlen (abbreviation) |
346
343
          !strlen (singular) |
347
344
          !strlen (plural))
348
345
        {
349
 
          g_message (_("All text fields must contain a value."));
 
346
          GtkWidget *msg = gtk_message_dialog_new (GTK_WINDOW (dialog), 0,
 
347
                                                   GTK_MESSAGE_ERROR,
 
348
                                                   GTK_BUTTONS_OK,
 
349
                                                   _("Incomplete input"));
 
350
 
 
351
          gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (msg),
 
352
                                                    _("Please fill in all text fields."));
 
353
          gtk_dialog_run (GTK_DIALOG (msg));
 
354
          gtk_widget_destroy (msg);
 
355
 
350
356
          continue;
351
357
        }
352
358
 
353
 
      unit = gimp_unit_new (identifier, factor, digits,
354
 
                            symbol, abbreviation,
355
 
                            singular, plural);
 
359
      unit = gimp_unit_new (identifier,
 
360
                            factor, digits,
 
361
                            symbol, abbreviation, singular, plural);
356
362
 
357
363
      g_free (identifier);
358
364
      g_free (symbol);
371
377
static void
372
378
unit_editor_dialog (void)
373
379
{
374
 
  GtkWidget         *main_dialog;
 
380
  GtkWidget         *dialog;
375
381
  GtkWidget         *scrolled_win;
376
382
  GtkUIManager      *ui_manager;
377
383
  GtkActionGroup    *group;
382
388
  GtkCellRenderer   *rend;
383
389
  gint               i;
384
390
 
385
 
  gimp_ui_init ("uniteditor", FALSE);
 
391
  gimp_ui_init (PLUG_IN_BINARY, FALSE);
386
392
 
387
393
  list_store = gtk_list_store_new (NUM_COLUMNS,
388
394
                                   G_TYPE_BOOLEAN,   /*  SAVE          */
400
406
  tv = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
401
407
  g_object_unref (list_store);
402
408
 
403
 
  main_dialog = gimp_dialog_new (_("Unit Editor"), "uniteditor",
404
 
                                 NULL, 0,
405
 
                                 gimp_standard_help_func, "plug-in-unit-editor",
406
 
 
407
 
                                 GTK_STOCK_REFRESH, RESPONSE_REFRESH,
408
 
                                 GTK_STOCK_CLOSE,   GTK_RESPONSE_CLOSE,
409
 
 
410
 
                                 NULL);
411
 
 
412
 
  gtk_dialog_set_default_response (GTK_DIALOG (main_dialog),
413
 
                                   GTK_RESPONSE_CLOSE);
414
 
 
415
 
  g_signal_connect (main_dialog, "response",
 
409
  dialog = gimp_dialog_new (_("Unit Editor"), PLUG_IN_BINARY,
 
410
                            NULL, 0,
 
411
                            gimp_standard_help_func, PLUG_IN_PROC,
 
412
 
 
413
                            GTK_STOCK_REFRESH, RESPONSE_REFRESH,
 
414
                            GTK_STOCK_CLOSE,   GTK_RESPONSE_CLOSE,
 
415
 
 
416
                            NULL);
 
417
 
 
418
  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
 
419
 
 
420
  g_signal_connect (dialog, "response",
416
421
                    G_CALLBACK (unit_editor_response),
417
422
                    tv);
418
 
  g_signal_connect (main_dialog, "destroy",
 
423
  g_signal_connect (dialog, "destroy",
419
424
                    G_CALLBACK (gtk_main_quit),
420
425
                    NULL);
421
426
 
423
428
  ui_manager = gtk_ui_manager_new ();
424
429
 
425
430
  group = gtk_action_group_new ("unit-editor");
 
431
 
426
432
  gtk_action_group_set_translation_domain (group, NULL);
427
433
  gtk_action_group_add_actions (group, actions, G_N_ELEMENTS (actions), tv);
428
434
 
 
435
  gtk_window_add_accel_group (GTK_WINDOW (dialog),
 
436
                              gtk_ui_manager_get_accel_group (ui_manager));
 
437
  gtk_accel_group_lock (gtk_ui_manager_get_accel_group (ui_manager));
 
438
 
429
439
  gtk_ui_manager_insert_action_group (ui_manager, group, -1);
430
440
  g_object_unref (group);
431
441
 
440
450
     -1, NULL);
441
451
 
442
452
  toolbar = gtk_ui_manager_get_widget (ui_manager, "/unit-editor-toolbar");
443
 
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (main_dialog)->vbox), toolbar,
 
453
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), toolbar,
444
454
                      FALSE, FALSE, 0);
445
455
  gtk_widget_show (toolbar);
446
456
 
451
461
                                  GTK_POLICY_NEVER,
452
462
                                  GTK_POLICY_ALWAYS);
453
463
  gtk_container_set_border_width (GTK_CONTAINER (scrolled_win), 12);
454
 
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (main_dialog)->vbox),
 
464
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
455
465
                     scrolled_win);
456
466
  gtk_widget_show (scrolled_win);
457
467
 
491
501
 
492
502
      gtk_tree_view_append_column (GTK_TREE_VIEW (tv), col);
493
503
 
494
 
      gimp_help_set_help_data (col->button,
495
 
                               gettext (columns[i].help), NULL);
 
504
      gimp_help_set_help_data (col->button, gettext (columns[i].help), NULL);
496
505
    }
497
506
 
498
507
  unit_list_init (GTK_TREE_VIEW (tv));
499
508
 
500
 
  gtk_widget_show (main_dialog);
 
509
  gtk_widget_show (dialog);
501
510
 
502
511
  gtk_main ();
503
512
}
606
615
  GimpUnit     unit;
607
616
 
608
617
  path = gtk_tree_path_new_from_string (path_string);
 
618
 
609
619
  if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (list_store), &iter, path))
610
620
    {
611
621
      g_warning ("%s: bad tree path?", G_STRLOC);
648
658
 
649
659
  for (unit = GIMP_UNIT_INCH; unit < num_units; unit++)
650
660
    {
651
 
      gboolean user_unit;
652
 
 
653
 
      user_unit = (unit >= gimp_unit_get_number_of_built_in_units ());
 
661
      gboolean user_unit = (unit >= gimp_unit_get_number_of_built_in_units ());
654
662
 
655
663
      gtk_list_store_append (list_store, &iter);
656
664
      gtk_list_store_set (list_store, &iter,