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

« back to all changes in this revision

Viewing changes to app/widgets/gimpeditor.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
 * gimpeditor.c
30
30
#include "gimpdocked.h"
31
31
#include "gimpeditor.h"
32
32
#include "gimpdnd.h"
33
 
#include "gimpenumwidgets.h"
34
33
#include "gimpmenufactory.h"
35
34
#include "gimpuimanager.h"
36
35
#include "gimpwidgets-utils.h"
37
36
 
 
37
#include "gimp-intl.h"
 
38
 
38
39
 
39
40
#define DEFAULT_CONTENT_SPACING  2
40
41
#define DEFAULT_BUTTON_SPACING   2
47
48
  PROP_MENU_FACTORY,
48
49
  PROP_MENU_IDENTIFIER,
49
50
  PROP_UI_PATH,
50
 
  PROP_POPUP_DATA
 
51
  PROP_POPUP_DATA,
 
52
  PROP_SHOW_NAME,
 
53
  PROP_NAME
51
54
};
52
55
 
53
56
 
54
 
static void        gimp_editor_class_init        (GimpEditorClass *klass);
55
 
static void        gimp_editor_init              (GimpEditor      *editor);
56
 
static void        gimp_editor_docked_iface_init (GimpDockedInterface *docked_iface);
 
57
static void        gimp_editor_docked_iface_init (GimpDockedInterface *iface);
57
58
 
58
59
static GObject   * gimp_editor_constructor       (GType            type,
59
60
                                                  guint            n_params,
70
71
static void        gimp_editor_style_set         (GtkWidget       *widget,
71
72
                                                  GtkStyle        *prev_style);
72
73
 
73
 
static GimpUIManager * gimp_editor_get_menu      (GimpDocked      *docked,
74
 
                                                  const gchar    **ui_path,
75
 
                                                  gpointer        *popup_data);
76
 
 
77
 
static GtkIconSize gimp_editor_ensure_button_box (GimpEditor      *editor);
78
 
 
79
 
 
80
 
static GtkVBoxClass *parent_class = NULL;
81
 
 
82
 
 
83
 
GType
84
 
gimp_editor_get_type (void)
85
 
{
86
 
  static GType type = 0;
87
 
 
88
 
  if (! type)
89
 
    {
90
 
      static const GTypeInfo info =
91
 
      {
92
 
        sizeof (GimpEditorClass),
93
 
        NULL,           /* base_init */
94
 
        NULL,           /* base_finalize */
95
 
        (GClassInitFunc) gimp_editor_class_init,
96
 
        NULL,           /* class_finalize */
97
 
        NULL,           /* class_data */
98
 
        sizeof (GimpEditor),
99
 
        0,              /* n_preallocs */
100
 
        (GInstanceInitFunc) gimp_editor_init,
101
 
      };
102
 
      static const GInterfaceInfo docked_iface_info =
103
 
      {
104
 
        (GInterfaceInitFunc) gimp_editor_docked_iface_init,
105
 
        NULL,           /* iface_finalize */
106
 
        NULL            /* iface_data     */
107
 
      };
108
 
 
109
 
      type = g_type_register_static (GTK_TYPE_VBOX,
110
 
                                     "GimpEditor",
111
 
                                     &info, 0);
112
 
 
113
 
      g_type_add_interface_static (type, GIMP_TYPE_DOCKED,
114
 
                                   &docked_iface_info);
115
 
    }
116
 
 
117
 
  return type;
118
 
}
 
74
static GimpUIManager * gimp_editor_get_menu        (GimpDocked      *docked,
 
75
                                                    const gchar    **ui_path,
 
76
                                                    gpointer        *popup_data);
 
77
static gboolean    gimp_editor_has_button_bar      (GimpDocked      *docked);
 
78
static void        gimp_editor_set_show_button_bar (GimpDocked      *docked,
 
79
                                                    gboolean         show);
 
80
static gboolean    gimp_editor_get_show_button_bar (GimpDocked      *docked);
 
81
 
 
82
static GtkIconSize gimp_editor_ensure_button_box   (GimpEditor      *editor);
 
83
 
 
84
 
 
85
G_DEFINE_TYPE_WITH_CODE (GimpEditor, gimp_editor, GTK_TYPE_VBOX,
 
86
                         G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,
 
87
                                                gimp_editor_docked_iface_init))
 
88
 
 
89
#define parent_class gimp_editor_parent_class
 
90
 
119
91
 
120
92
static void
121
93
gimp_editor_class_init (GimpEditorClass *klass)
124
96
  GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
125
97
  GtkWidgetClass *widget_class     = GTK_WIDGET_CLASS (klass);
126
98
 
127
 
  parent_class = g_type_class_peek_parent (klass);
128
 
 
129
99
  object_class->constructor  = gimp_editor_constructor;
130
100
  object_class->set_property = gimp_editor_set_property;
131
101
  object_class->get_property = gimp_editor_get_property;
138
108
                                   g_param_spec_object ("menu-factory",
139
109
                                                        NULL, NULL,
140
110
                                                        GIMP_TYPE_MENU_FACTORY,
141
 
                                                        G_PARAM_READWRITE |
 
111
                                                        GIMP_PARAM_READWRITE |
142
112
                                                        G_PARAM_CONSTRUCT_ONLY));
143
113
 
144
114
  g_object_class_install_property (object_class, PROP_MENU_IDENTIFIER,
145
115
                                   g_param_spec_string ("menu-identifier",
146
116
                                                        NULL, NULL,
147
117
                                                        NULL,
148
 
                                                        G_PARAM_READWRITE |
 
118
                                                        GIMP_PARAM_READWRITE |
149
119
                                                        G_PARAM_CONSTRUCT_ONLY));
150
120
 
151
121
  g_object_class_install_property (object_class, PROP_UI_PATH,
152
122
                                   g_param_spec_string ("ui-path",
153
123
                                                        NULL, NULL,
154
124
                                                        NULL,
155
 
                                                        G_PARAM_READWRITE |
 
125
                                                        GIMP_PARAM_READWRITE |
156
126
                                                        G_PARAM_CONSTRUCT_ONLY));
157
127
 
158
128
  g_object_class_install_property (object_class, PROP_POPUP_DATA,
159
129
                                   g_param_spec_pointer ("popup-data",
160
130
                                                         NULL, NULL,
161
 
                                                         G_PARAM_READWRITE |
 
131
                                                         GIMP_PARAM_READWRITE |
162
132
                                                         G_PARAM_CONSTRUCT_ONLY));
163
133
 
 
134
  g_object_class_install_property (object_class, PROP_SHOW_NAME,
 
135
                                   g_param_spec_boolean ("show-name",
 
136
                                                         NULL, NULL,
 
137
                                                         FALSE,
 
138
                                                         GIMP_PARAM_READWRITE));
 
139
 
 
140
  g_object_class_install_property (object_class, PROP_NAME,
 
141
                                   g_param_spec_string ("name",
 
142
                                                        NULL, NULL,
 
143
                                                        NULL,
 
144
                                                        GIMP_PARAM_WRITABLE |
 
145
                                                        G_PARAM_CONSTRUCT));
 
146
 
164
147
  gtk_widget_class_install_style_property (widget_class,
165
 
                                           g_param_spec_int ("content_spacing",
 
148
                                           g_param_spec_int ("content-spacing",
166
149
                                                             NULL, NULL,
167
150
                                                             0,
168
151
                                                             G_MAXINT,
169
152
                                                             DEFAULT_CONTENT_SPACING,
170
 
                                                             G_PARAM_READABLE));
 
153
                                                             GIMP_PARAM_READABLE));
171
154
 
172
155
  gtk_widget_class_install_style_property (widget_class,
173
 
                                           g_param_spec_int ("button_spacing",
 
156
                                           g_param_spec_int ("button-spacing",
174
157
                                                             NULL, NULL,
175
158
                                                             0,
176
159
                                                             G_MAXINT,
177
160
                                                             DEFAULT_BUTTON_SPACING,
178
 
                                                             G_PARAM_READABLE));
 
161
                                                             GIMP_PARAM_READABLE));
179
162
 
180
163
  gtk_widget_class_install_style_property (widget_class,
181
 
                                           g_param_spec_enum ("button_icon_size",
 
164
                                           g_param_spec_enum ("button-icon-size",
182
165
                                                              NULL, NULL,
183
166
                                                              GTK_TYPE_ICON_SIZE,
184
167
                                                              DEFAULT_BUTTON_ICON_SIZE,
185
 
                                                              G_PARAM_READABLE));
 
168
                                                              GIMP_PARAM_READABLE));
186
169
}
187
170
 
188
171
static void
194
177
  editor->ui_path         = NULL;
195
178
  editor->popup_data      = editor;
196
179
  editor->button_box      = NULL;
 
180
  editor->show_button_bar = TRUE;
 
181
 
 
182
  editor->name_label = g_object_new (GTK_TYPE_LABEL,
 
183
                                     "xalign",    0.0,
 
184
                                     "yalign",    0.5,
 
185
                                     "ellipsize", PANGO_ELLIPSIZE_END,
 
186
                                     NULL);
 
187
  gimp_label_set_attributes (GTK_LABEL (editor->name_label),
 
188
                             PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
 
189
                             -1);
 
190
  gtk_box_pack_start (GTK_BOX (editor), editor->name_label, FALSE, FALSE, 0);
197
191
}
198
192
 
199
193
static void
200
 
gimp_editor_docked_iface_init (GimpDockedInterface *docked_iface)
 
194
gimp_editor_docked_iface_init (GimpDockedInterface *iface)
201
195
{
202
 
  docked_iface->get_menu = gimp_editor_get_menu;
 
196
  iface->get_menu            = gimp_editor_get_menu;
 
197
  iface->has_button_bar      = gimp_editor_has_button_bar;
 
198
  iface->set_show_button_bar = gimp_editor_set_show_button_bar;
 
199
  iface->get_show_button_bar = gimp_editor_get_show_button_bar;
203
200
}
204
201
 
205
202
static GObject *
251
248
    case PROP_POPUP_DATA:
252
249
      editor->popup_data = g_value_get_pointer (value);
253
250
      break;
 
251
    case PROP_SHOW_NAME:
 
252
      g_object_set_property (G_OBJECT (editor->name_label), "visible", value);
 
253
      break;
 
254
    case PROP_NAME:
 
255
      gimp_editor_set_name (editor, g_value_get_string (value));
 
256
      break;
254
257
    default:
255
258
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
256
259
      break;
279
282
    case PROP_POPUP_DATA:
280
283
      g_value_set_pointer (value, editor->popup_data);
281
284
      break;
 
285
    case PROP_SHOW_NAME:
 
286
      g_object_get_property (G_OBJECT (editor->name_label), "visible", value);
 
287
      break;
282
288
    default:
283
289
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
284
290
      break;
327
333
  if (GTK_WIDGET_CLASS (parent_class)->style_set)
328
334
    GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
329
335
 
330
 
  gtk_widget_style_get (widget, "content_spacing",  &content_spacing, NULL);
 
336
  gtk_widget_style_get (widget, "content-spacing",  &content_spacing, NULL);
331
337
 
332
338
  gtk_box_set_spacing (GTK_BOX (widget), content_spacing);
333
339
 
348
354
  return editor->ui_manager;
349
355
}
350
356
 
 
357
 
 
358
static gboolean
 
359
gimp_editor_has_button_bar (GimpDocked *docked)
 
360
{
 
361
  GimpEditor *editor = GIMP_EDITOR (docked);
 
362
 
 
363
  return editor->button_box != NULL;
 
364
}
 
365
 
 
366
static void
 
367
gimp_editor_set_show_button_bar (GimpDocked *docked,
 
368
                                 gboolean    show)
 
369
{
 
370
  GimpEditor *editor = GIMP_EDITOR (docked);
 
371
 
 
372
  if (show != editor->show_button_bar)
 
373
    {
 
374
      editor->show_button_bar = show;
 
375
 
 
376
      if (editor->button_box)
 
377
        {
 
378
          if (show)
 
379
            gtk_widget_show (editor->button_box);
 
380
          else
 
381
            gtk_widget_hide (editor->button_box);
 
382
        }
 
383
    }
 
384
}
 
385
 
 
386
static gboolean
 
387
gimp_editor_get_show_button_bar (GimpDocked *docked)
 
388
{
 
389
  GimpEditor *editor = GIMP_EDITOR (docked);
 
390
 
 
391
  return editor->show_button_bar;
 
392
}
 
393
 
351
394
GtkWidget *
352
395
gimp_editor_new (void)
353
396
{
354
 
  GimpEditor *editor;
355
 
 
356
 
  editor = g_object_new (GIMP_TYPE_EDITOR, NULL);
357
 
 
358
 
  return GTK_WIDGET (editor);
 
397
  return g_object_new (GIMP_TYPE_EDITOR, NULL);
359
398
}
360
399
 
361
400
void
429
468
 
430
469
  button_icon_size = gimp_editor_ensure_button_box (editor);
431
470
 
432
 
  button = gimp_button_new ();
 
471
  button = g_object_new (GIMP_TYPE_BUTTON,
 
472
                         "use-stock", TRUE,
 
473
                         NULL);
433
474
  gtk_box_pack_start (GTK_BOX (editor->button_box), button, TRUE, TRUE, 0);
434
475
  gtk_widget_show (button);
435
476
 
438
479
 
439
480
  if (callback)
440
481
    g_signal_connect (button, "clicked",
441
 
                      callback,
442
 
                      callback_data);
 
482
                      callback,
 
483
                      callback_data);
443
484
 
444
485
  if (extended_callback)
445
 
    g_signal_connect (button, "extended_clicked",
446
 
                      extended_callback,
447
 
                      callback_data);
 
486
    g_signal_connect (button, "extended-clicked",
 
487
                      extended_callback,
 
488
                      callback_data);
448
489
 
449
490
  image = gtk_image_new_from_stock (stock_id, button_icon_size);
450
491
  gtk_container_add (GTK_CONTAINER (button), image);
493
534
 
494
535
  g_list_free (children);
495
536
 
496
 
  gtk_object_sink (GTK_OBJECT (hbox));
 
537
  g_object_ref_sink (hbox);
 
538
  g_object_unref (hbox);
497
539
 
498
540
  return first_button;
499
541
}
577
619
      button = gimp_button_new ();
578
620
    }
579
621
 
580
 
  gtk_action_connect_proxy (action, button);
581
 
  gtk_box_pack_start (GTK_BOX (editor->button_box), button, TRUE, TRUE, 0);
582
 
  gtk_widget_show (button);
583
 
 
584
622
  g_object_get (action,
585
623
                "stock-id", &stock_id,
586
624
                "tooltip",  &tooltip,
587
625
                NULL);
588
626
 
589
 
  help_id = g_object_get_qdata (G_OBJECT (action), GIMP_HELP_ID);
590
 
 
591
627
  old_child = gtk_bin_get_child (GTK_BIN (button));
592
628
 
593
629
  if (old_child)
599
635
 
600
636
  g_free (stock_id);
601
637
 
 
638
  gtk_action_connect_proxy (action, button);
 
639
  gtk_box_pack_start (GTK_BOX (editor->button_box), button, TRUE, TRUE, 0);
 
640
  gtk_widget_show (button);
 
641
 
602
642
  va_start (args, action_name);
603
643
 
604
644
  action_name = va_arg (args, const gchar *);
629
669
 
630
670
              if (ext_tooltip)
631
671
                {
632
 
                  gchar *tmp = g_strconcat (tooltip, "\n",
 
672
                  gchar *tmp = g_strconcat (tooltip, "\n(",
633
673
                                            gimp_get_mod_string (mod_mask),
634
 
                                            "  ", ext_tooltip, NULL);
 
674
                                            ")  ", ext_tooltip, NULL);
635
675
 
636
676
                  g_free (ext_tooltip);
637
677
                  g_free (tooltip);
650
690
      g_object_set_data_full (G_OBJECT (button), "extended-actions", extended,
651
691
                              (GDestroyNotify) gimp_editor_button_extended_actions_free);
652
692
 
653
 
      g_signal_connect (button, "extended_clicked",
 
693
      g_signal_connect (button, "extended-clicked",
654
694
                        G_CALLBACK (gimp_editor_button_extended_clicked),
655
695
                        NULL);
656
696
    }
657
697
 
 
698
  help_id = g_object_get_qdata (G_OBJECT (action), GIMP_HELP_ID);
 
699
 
658
700
  if (tooltip || help_id)
659
701
    gimp_help_set_help_data (button, tooltip, help_id);
660
702
 
664
706
}
665
707
 
666
708
void
 
709
gimp_editor_set_show_name (GimpEditor *editor,
 
710
                           gboolean    show)
 
711
{
 
712
  g_return_if_fail (GIMP_IS_EDITOR (editor));
 
713
 
 
714
  g_object_set (editor, "show-name", show, NULL);
 
715
}
 
716
 
 
717
void
 
718
gimp_editor_set_name (GimpEditor  *editor,
 
719
                      const gchar *name)
 
720
{
 
721
  g_return_if_fail (GIMP_IS_EDITOR (editor));
 
722
 
 
723
  gtk_label_set_text (GTK_LABEL (editor->name_label),
 
724
                      name ? name : _("(None)"));
 
725
}
 
726
 
 
727
void
667
728
gimp_editor_set_box_style (GimpEditor *editor,
668
729
                           GtkBox     *box)
669
730
{
676
737
  g_return_if_fail (GTK_IS_BOX (box));
677
738
 
678
739
  gtk_widget_style_get (GTK_WIDGET (editor),
679
 
                        "button_icon_size", &button_icon_size,
680
 
                        "button_spacing",   &button_spacing,
681
 
                        NULL);
 
740
                        "button-icon-size", &button_icon_size,
 
741
                        "button-spacing",   &button_spacing,
 
742
                        NULL);
682
743
 
683
744
  gtk_box_set_spacing (box, button_spacing);
684
745
 
716
777
  gint         button_spacing;
717
778
 
718
779
  gtk_widget_style_get (GTK_WIDGET (editor),
719
 
                        "button_icon_size", &button_icon_size,
720
 
                        "button_spacing",   &button_spacing,
 
780
                        "button-icon-size", &button_icon_size,
 
781
                        "button-spacing",   &button_spacing,
721
782
                        NULL);
722
783
 
723
784
  if (! editor->button_box)
725
786
      editor->button_box = gtk_hbox_new (TRUE, button_spacing);
726
787
      gtk_box_pack_end (GTK_BOX (editor), editor->button_box, FALSE, FALSE, 0);
727
788
      gtk_box_reorder_child (GTK_BOX (editor), editor->button_box, 0);
728
 
      gtk_widget_show (editor->button_box);
 
789
 
 
790
      if (editor->show_button_bar)
 
791
        gtk_widget_show (editor->button_box);
729
792
    }
730
793
 
731
794
  return button_icon_size;