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

« back to all changes in this revision

Viewing changes to app/widgets/gimpdock.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-10-06 13:30:41 UTC
  • mto: This revision was merged to the branch mainline in revision 35.
  • Revision ID: james.westby@ubuntu.com-20081006133041-3panbkcanaymfsmp
Tags: upstream-2.6.0
ImportĀ upstreamĀ versionĀ 2.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include "gimpdockable.h"
39
39
#include "gimpdockbook.h"
40
40
#include "gimpdockseparator.h"
41
 
#include "gimpmessagebox.h"
42
 
#include "gimpmessagedialog.h"
43
41
#include "gimpwidgets-utils.h"
44
42
 
 
43
#include "gimpsessioninfo.h"    /* FIXME */
 
44
#include "core/gimpcontainer.h" /* FIXME */
 
45
#include "dialogs/dialogs.h"    /* FIXME */
 
46
 
45
47
#include "gimp-intl.h"
46
48
 
47
49
 
48
 
#define DEFAULT_DOCK_HEIGHT 300
49
 
 
 
50
#define DEFAULT_DOCK_HEIGHT     300
 
51
#define DEFAULT_DOCK_FONT_SCALE PANGO_SCALE_SMALL
50
52
 
51
53
enum
52
54
{
78
80
static void      gimp_dock_destroy           (GtkObject             *object);
79
81
 
80
82
static gboolean  gimp_dock_delete_event      (GtkWidget             *widget,
81
 
                                              GdkEventAny              *event);
82
 
static gboolean  gimp_dock_key_press_event   (GtkWidget             *widget,
83
 
                                              GdkEventKey           *kevent);
84
 
 
 
83
                                              GdkEventAny           *event);
85
84
static void      gimp_dock_style_set         (GtkWidget             *widget,
86
85
                                              GtkStyle              *prev_style);
87
86
 
91
90
                                              GimpDockbook          *dockbook);
92
91
 
93
92
 
94
 
G_DEFINE_TYPE (GimpDock, gimp_dock, GTK_TYPE_WINDOW)
 
93
G_DEFINE_TYPE (GimpDock, gimp_dock, GIMP_TYPE_WINDOW)
95
94
 
96
95
#define parent_class gimp_dock_parent_class
97
96
 
132
131
  gtk_object_class->destroy     = gimp_dock_destroy;
133
132
 
134
133
  widget_class->delete_event    = gimp_dock_delete_event;
135
 
  widget_class->key_press_event = gimp_dock_key_press_event;
136
134
  widget_class->style_set       = gimp_dock_style_set;
137
135
 
138
136
  klass->setup                  = NULL;
158
156
                                                             -1, G_MAXINT,
159
157
                                                             DEFAULT_DOCK_HEIGHT,
160
158
                                                             GIMP_PARAM_READABLE));
 
159
  gtk_widget_class_install_style_property (widget_class,
 
160
                                           g_param_spec_double ("font-scale",
 
161
                                                                NULL, NULL,
 
162
                                                                0.0,
 
163
                                                                G_MAXDOUBLE,
 
164
                                                                DEFAULT_DOCK_FONT_SCALE,
 
165
                                                                GIMP_PARAM_READABLE));
161
166
}
162
167
 
163
168
static void
164
169
gimp_dock_init (GimpDock *dock)
165
170
{
166
 
  GtkWidget *separator;
 
171
  static gint  dock_ID = 1;
 
172
  GtkWidget   *separator;
 
173
  gchar       *name;
167
174
 
168
175
  dock->context        = NULL;
169
176
  dock->dialog_factory = NULL;
170
177
  dock->dockbooks      = NULL;
 
178
  dock->ID             = dock_ID++;
 
179
 
 
180
  name = g_strdup_printf ("gimp-dock-%d", dock->ID);
 
181
  gtk_widget_set_name (GTK_WIDGET (dock), name);
 
182
  g_free (name);
171
183
 
172
184
  gtk_window_set_role (GTK_WINDOW (dock), "gimp-dock");
173
185
  gtk_window_set_resizable (GTK_WINDOW (dock), TRUE);
 
186
  gtk_window_set_focus_on_map (GTK_WINDOW (dock), FALSE);
174
187
 
175
188
  dock->main_vbox = gtk_vbox_new (FALSE, 0);
176
189
  gtk_container_add (GTK_CONTAINER (dock), dock->main_vbox);
219
232
  switch (property_id)
220
233
    {
221
234
    case PROP_CONTEXT:
222
 
      dock->context = GIMP_CONTEXT (g_value_dup_object (value));
 
235
      dock->context = g_value_dup_object (value);
223
236
      break;
 
237
 
224
238
    case PROP_DIALOG_FACTORY:
225
239
      dock->dialog_factory = g_value_get_object (value);
226
240
      break;
 
241
 
227
242
    default:
228
243
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
229
244
      break;
243
258
    case PROP_CONTEXT:
244
259
      g_value_set_object (value, dock->context);
245
260
      break;
 
261
 
246
262
    case PROP_DIALOG_FACTORY:
247
263
      g_value_set_object (value, dock->dialog_factory);
248
264
      break;
 
265
 
249
266
    default:
250
267
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
251
268
      break;
273
290
gimp_dock_delete_event (GtkWidget   *widget,
274
291
                        GdkEventAny *event)
275
292
{
276
 
  GimpDock *dock   = GIMP_DOCK (widget);
277
 
  gboolean  retval = FALSE;
 
293
  GimpDock *dock = GIMP_DOCK (widget);
278
294
  GList    *list;
279
295
  gint      n;
280
296
 
283
299
 
284
300
  if (n > 1)
285
301
    {
286
 
      GtkWidget *dialog =
287
 
        gimp_message_dialog_new (_("Close all Tabs?"),
288
 
                                 GIMP_STOCK_WARNING,
289
 
                                 widget, GTK_DIALOG_MODAL,
290
 
                                 NULL, NULL,
291
 
 
292
 
                                 GTK_STOCK_CANCEL,    GTK_RESPONSE_CANCEL,
293
 
                                 _("Close all Tabs"), GTK_RESPONSE_OK,
294
 
 
295
 
                                 NULL);
296
 
 
297
 
      gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
298
 
                                               GTK_RESPONSE_OK,
299
 
                                               GTK_RESPONSE_CANCEL,
300
 
                                               -1);
301
 
 
302
 
      gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
303
 
                                         _("Close all tabs?"));
304
 
 
305
 
      gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
306
 
                                 ngettext ("This window has %d tab open. "
307
 
                                           "Closing the window will also close "
308
 
                                           "all its tabs.",
309
 
                                           "This window has %d tabs open. "
310
 
                                           "Closing the window will also close "
311
 
                                           "all its tabs.", n), n);
312
 
 
313
 
      retval = (gimp_dialog_run (GIMP_DIALOG (dialog)) != GTK_RESPONSE_OK);
314
 
 
315
 
      gtk_widget_destroy (dialog);
 
302
      GimpSessionInfo *info = gimp_session_info_new ();
 
303
 
 
304
      gimp_object_set_name (GIMP_OBJECT (info),
 
305
                            gtk_window_get_title (GTK_WINDOW (widget)));
 
306
 
 
307
      info->widget = widget;
 
308
      gimp_session_info_get_info (info);
 
309
      info->widget = NULL;
 
310
 
 
311
      gimp_container_add (global_recent_docks, GIMP_OBJECT (info));
 
312
      g_object_unref (info);
316
313
    }
317
314
 
318
 
  return retval;
319
 
}
320
 
 
321
 
static gboolean
322
 
gimp_dock_key_press_event (GtkWidget   *widget,
323
 
                           GdkEventKey *event)
324
 
{
325
 
  GtkWindow *window  = GTK_WINDOW (widget);
326
 
  GtkWidget *focus   = gtk_window_get_focus (window);
327
 
  gboolean   handled = FALSE;
328
 
 
329
 
  /* we're overriding the GtkWindow implementation here to give
330
 
   * the focus widget precedence over unmodified accelerators
331
 
   * before the accelerator activation scheme.
332
 
   */
333
 
 
334
 
  /* text widgets get all key events first */
335
 
  if (G_UNLIKELY (GTK_IS_EDITABLE (focus) || GTK_IS_TEXT_VIEW (focus)))
336
 
    handled = gtk_window_propagate_key_event (window, event);
337
 
 
338
 
  /* invoke control/alt accelerators */
339
 
  if (! handled && event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))
340
 
    handled = gtk_window_activate_key (window, event);
341
 
 
342
 
  /* invoke focus widget handlers */
343
 
  if (! handled)
344
 
    handled = gtk_window_propagate_key_event (window, event);
345
 
 
346
 
  /* invoke non-(control/alt) accelerators */
347
 
  if (! handled && ! (event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK)))
348
 
    handled = gtk_window_activate_key (window, event);
349
 
 
350
 
  /* chain up, bypassing gtk_window_key_press(), to invoke binding set */
351
 
  if (! handled)
352
 
    handled = GTK_WIDGET_CLASS (g_type_class_peek (g_type_parent (GTK_TYPE_WINDOW)))->key_press_event (widget, event);
353
 
 
354
 
  return handled;
 
315
  return FALSE;
355
316
}
356
317
 
357
318
static void
358
319
gimp_dock_style_set (GtkWidget *widget,
359
320
                     GtkStyle  *prev_style)
360
321
{
361
 
  gint default_height;
362
 
 
363
 
  if (GTK_WIDGET_CLASS (parent_class)->style_set)
364
 
    GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
365
 
 
366
 
  gtk_widget_style_get (widget, "default-height", &default_height, NULL);
 
322
  gint    default_height;
 
323
  gdouble font_scale;
 
324
 
 
325
  GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
 
326
 
 
327
  gtk_widget_style_get (widget,
 
328
                        "default-height", &default_height,
 
329
                        "font-scale",     &font_scale,
 
330
                        NULL);
367
331
 
368
332
  gtk_window_set_default_size (GTK_WINDOW (widget), -1, default_height);
 
333
 
 
334
  if (font_scale != 1.0)
 
335
    {
 
336
      PangoContext         *context;
 
337
      PangoFontDescription *font_desc;
 
338
      gint                  font_size;
 
339
      gchar                *font_str;
 
340
      gchar                *rc_string;
 
341
 
 
342
      context = gtk_widget_get_pango_context (widget);
 
343
      font_desc = pango_context_get_font_description (context);
 
344
      font_desc = pango_font_description_copy (font_desc);
 
345
 
 
346
      font_size = pango_font_description_get_size (font_desc);
 
347
      font_size = font_scale * font_size;
 
348
      pango_font_description_set_size (font_desc, font_size);
 
349
 
 
350
      font_str = pango_font_description_to_string (font_desc);
 
351
      pango_font_description_free (font_desc);
 
352
 
 
353
      rc_string =
 
354
        g_strdup_printf ("style \"gimp-dock-style\""
 
355
                         "{"
 
356
                         "  font_name = \"%s\""
 
357
                         "}"
 
358
                         "widget \"gimp-dock-%d.*\" style \"gimp-dock-style\"",
 
359
                         font_str,
 
360
                         GIMP_DOCK (widget)->ID);
 
361
      g_free (font_str);
 
362
 
 
363
      gtk_rc_parse_string (rc_string);
 
364
      g_free (rc_string);
 
365
 
 
366
      if (gtk_bin_get_child (GTK_BIN (widget)))
 
367
        gtk_widget_reset_rc_styles (gtk_bin_get_child (GTK_BIN (widget)));
 
368
    }
369
369
}
370
370
 
371
371
static void
487
487
      else
488
488
        old_book = g_list_nth_data (dock->dockbooks, index - 1);
489
489
 
490
 
      parent = old_book->parent;
 
490
      parent = gtk_widget_get_parent (old_book);
491
491
 
492
492
      if ((old_length > 1) && (index > 0))
493
493
        {
494
494
          GtkWidget *grandparent;
495
495
 
496
 
          grandparent = parent->parent;
 
496
          grandparent = gtk_widget_get_parent (parent);
497
497
 
498
498
          old_book = parent;
499
499
          parent   = grandparent;
575
575
      GtkWidget *parent;
576
576
      GtkWidget *grandparent;
577
577
 
578
 
      parent      = GTK_WIDGET (dockbook)->parent;
579
 
      grandparent = parent->parent;
 
578
      parent      = gtk_widget_get_parent (GTK_WIDGET (dockbook));
 
579
      grandparent = gtk_widget_get_parent (parent);
580
580
 
581
581
      if (index == 0)
582
 
        other_book = GTK_PANED (parent)->child2;
 
582
        other_book = gtk_paned_get_child2 (GTK_PANED (parent));
583
583
      else
584
 
        other_book = GTK_PANED (parent)->child1;
 
584
        other_book = gtk_paned_get_child1 (GTK_PANED (parent));
585
585
 
586
586
      g_object_ref (other_book);
587
587