gimpimagedock.c 27.4 KB
Newer Older
Michael Natterer's avatar
Michael Natterer committed
1
2
3
4
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * gimpimagedock.c
5
 * Copyright (C) 2001-2004 Michael Natterer <mitch@gimp.org>
Michael Natterer's avatar
Michael Natterer committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "config.h"

24
25
#include <string.h>

Michael Natterer's avatar
Michael Natterer committed
26
27
#include <gtk/gtk.h>

28
#include "libgimpbase/gimpbase.h"
Michael Natterer's avatar
Michael Natterer committed
29
30
#include "libgimpwidgets/gimpwidgets.h"

31
#include "widgets-types.h"
Michael Natterer's avatar
Michael Natterer committed
32

33
#include "core/gimp.h"
34
35
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
36
#include "core/gimplist.h"
37
#include "core/gimptoolinfo.h"
38

Michael Natterer's avatar
Michael Natterer committed
39
40
41
#include "gimpdialogfactory.h"
#include "gimpimagedock.h"
#include "gimpcontainermenuimpl.h"
42
#include "gimpdockable.h"
Michael Natterer's avatar
Michael Natterer committed
43
#include "gimpdockbook.h"
44
#include "gimphelp-ids.h"
45
#include "gimpmenufactory.h"
46
#include "gimpsessioninfo.h"
Michael Natterer's avatar
Michael Natterer committed
47

48
#include "gimp-intl.h"
Michael Natterer's avatar
Michael Natterer committed
49
50


51
52
#define DEFAULT_MINIMAL_WIDTH     250
#define DEFAULT_MENU_PREVIEW_SIZE GTK_ICON_SIZE_SMALL_TOOLBAR
53
54


55
56
57
static void   gimp_image_dock_class_init          (GimpImageDockClass *klass);
static void   gimp_image_dock_init                (GimpImageDock      *dock);

58
#ifdef ENABLE_GLOBAL_SHORTCUTS
59
60
61
static GObject * gimp_image_dock_constructor   (GType                  type,
                                                guint                  n_params,
                                                GObjectConstructParam *params);
62
#endif
63
64
65
66
67
68
69
static void   gimp_image_dock_destroy                 (GtkObject      *object);

static void   gimp_image_dock_style_set               (GtkWidget      *widget,
                                                       GtkStyle       *prev_style);

static void   gimp_image_dock_setup                   (GimpDock       *dock,
                                                       const GimpDock *template);
70
71
72
static void   gimp_image_dock_set_aux_info            (GimpDock       *dock,
                                                       GList          *aux_info);
static GList *gimp_image_dock_get_aux_info            (GimpDock       *dock);
73
74
75
76
77
78
79
80
81
82
83
static void   gimp_image_dock_book_added              (GimpDock       *dock,
                                                       GimpDockbook   *dockbook);
static void   gimp_image_dock_book_removed            (GimpDock       *dock,
                                                       GimpDockbook   *dockbook);

static void   gimp_image_dock_dockbook_changed        (GimpDockbook   *dockbook,
                                                       GimpDockable   *dockable,
                                                       GimpImageDock  *dock);
static void   gimp_image_dock_update_title            (GimpImageDock  *dock);

static void   gimp_image_dock_factory_display_changed (GimpContext    *context,
84
                                                       GimpObject     *display,
85
86
87
88
                                                       GimpDock       *dock);
static void   gimp_image_dock_factory_image_changed   (GimpContext    *context,
                                                       GimpImage      *gimage,
                                                       GimpDock       *dock);
89
#ifdef ENABLE_GLOBAL_SHORTCUTS
90
91
92
static void   gimp_image_dock_display_changed         (GimpContext    *context,
                                                       GimpObject     *display,
                                                       GimpDock       *dock);
93
#endif
94
95
96
97
98
static void   gimp_image_dock_image_changed           (GimpContext    *context,
                                                       GimpImage      *gimage,
                                                       GimpDock       *dock);
static void   gimp_image_dock_auto_clicked            (GtkWidget      *widget,
                                                       GimpDock       *dock);
99
#ifdef ENABLE_GLOBAL_SHORTCUTS
100
101
static void   gimp_image_dock_image_flush             (GimpImage      *gimage,
                                                       GimpDock       *dock);
102
#endif
Michael Natterer's avatar
Michael Natterer committed
103
104
105
106
107


static GimpDockClass *parent_class = NULL;


108
GType
Michael Natterer's avatar
Michael Natterer committed
109
110
gimp_image_dock_get_type (void)
{
111
  static GType dock_type = 0;
Michael Natterer's avatar
Michael Natterer committed
112
113
114

  if (! dock_type)
    {
115
      static const GTypeInfo dock_info =
Michael Natterer's avatar
Michael Natterer committed
116
      {
117
118
119
120
121
122
123
124
125
        sizeof (GimpImageDockClass),
        NULL,           /* base_init */
        NULL,           /* base_finalize */
        (GClassInitFunc) gimp_image_dock_class_init,
        NULL,           /* class_finalize */
        NULL,           /* class_data */
        sizeof (GimpImageDock),
        0,              /* n_preallocs */
        (GInstanceInitFunc) gimp_image_dock_init,
Michael Natterer's avatar
Michael Natterer committed
126
127
      };

128
129
130
      dock_type = g_type_register_static (GIMP_TYPE_DOCK,
                                          "GimpImageDock",
                                          &dock_info, 0);
Michael Natterer's avatar
Michael Natterer committed
131
132
133
134
135
136
137
138
    }

  return dock_type;
}

static void
gimp_image_dock_class_init (GimpImageDockClass *klass)
{
139
140
  GObjectClass   *object_class;
  GtkObjectClass *gtk_object_class;
141
  GtkWidgetClass *widget_class;
142
  GimpDockClass  *dock_class;
Michael Natterer's avatar
Michael Natterer committed
143

144
145
146
147
  object_class     = G_OBJECT_CLASS (klass);
  gtk_object_class = GTK_OBJECT_CLASS (klass);
  widget_class     = GTK_WIDGET_CLASS (klass);
  dock_class       = GIMP_DOCK_CLASS (klass);
Michael Natterer's avatar
Michael Natterer committed
148

149
  parent_class = g_type_class_peek_parent (klass);
Michael Natterer's avatar
Michael Natterer committed
150

151
#ifdef ENABLE_GLOBAL_SHORTCUTS
152
  object_class->constructor = gimp_image_dock_constructor;
153
#endif
154

155
  gtk_object_class->destroy = gimp_image_dock_destroy;
156

157
158
159
160
161
162
163
  widget_class->style_set   = gimp_image_dock_style_set;

  dock_class->setup         = gimp_image_dock_setup;
  dock_class->set_aux_info  = gimp_image_dock_set_aux_info;
  dock_class->get_aux_info  = gimp_image_dock_get_aux_info;
  dock_class->book_added    = gimp_image_dock_book_added;
  dock_class->book_removed  = gimp_image_dock_book_removed;
164
165
166
167
168
169
170
171

  gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_int ("minimal_width",
                                                             NULL, NULL,
                                                             0,
                                                             G_MAXINT,
                                                             DEFAULT_MINIMAL_WIDTH,
                                                             G_PARAM_READABLE));
172
  gtk_widget_class_install_style_property (widget_class,
173
174
175
176
177
                                           g_param_spec_enum ("menu_preview_size",
                                                              NULL, NULL,
                                                              GTK_TYPE_ICON_SIZE,
                                                              DEFAULT_MENU_PREVIEW_SIZE,
                                                              G_PARAM_READABLE));
Michael Natterer's avatar
Michael Natterer committed
178
179
180
181
182
}

static void
gimp_image_dock_init (GimpImageDock *dock)
{
Michael Natterer's avatar
Michael Natterer committed
183
184
  GtkWidget *hbox;

185
186
187
188
189
  dock->image_container      = NULL;
  dock->display_container    = NULL;
  dock->show_image_menu      = FALSE;
  dock->auto_follow_active   = TRUE;
  dock->update_title_idle_id = 0;
Michael Natterer's avatar
Michael Natterer committed
190
191
192

  hbox = gtk_hbox_new (FALSE, 2);
  gtk_box_pack_start (GTK_BOX (GIMP_DOCK (dock)->main_vbox), hbox,
Michael Natterer's avatar
Michael Natterer committed
193
                      FALSE, FALSE, 0);
Michael Natterer's avatar
Michael Natterer committed
194
  gtk_box_reorder_child (GTK_BOX (GIMP_DOCK (dock)->main_vbox), hbox, 0);
195
196
197

  if (dock->show_image_menu)
    gtk_widget_show (hbox);
Michael Natterer's avatar
Michael Natterer committed
198
199
200

  dock->option_menu = gtk_option_menu_new ();
  gtk_box_pack_start (GTK_BOX (hbox), dock->option_menu, TRUE, TRUE, 0);
Michael Natterer's avatar
Michael Natterer committed
201
202
  gtk_widget_show (dock->option_menu);

203
  g_signal_connect (dock->option_menu, "destroy",
204
205
206
		    G_CALLBACK (gtk_widget_destroyed),
		    &dock->option_menu);

207
208
209
  gimp_help_set_help_data (dock->option_menu, NULL,
                           GIMP_HELP_DOCK_IMAGE_MENU);

210
211
  dock->auto_button = gtk_toggle_button_new_with_label (_("Auto"));
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dock->auto_button),
Michael Natterer's avatar
Michael Natterer committed
212
				dock->auto_follow_active);
213
214
  gtk_box_pack_start (GTK_BOX (hbox), dock->auto_button, FALSE, FALSE, 0);
  gtk_widget_show (dock->auto_button);
Michael Natterer's avatar
Michael Natterer committed
215

216
  g_signal_connect (dock->auto_button, "clicked",
217
218
		    G_CALLBACK (gimp_image_dock_auto_clicked),
		    dock);
219

220
221
222
  gimp_help_set_help_data (dock->auto_button,
                           _("When enabled the dialog automatically "
                             "follows the image you are working on."),
223
                           GIMP_HELP_DOCK_AUTO_BUTTON);
Michael Natterer's avatar
Michael Natterer committed
224
225
}

226
#ifdef ENABLE_GLOBAL_SHORTCUTS
227
228
229
230
static GObject *
gimp_image_dock_constructor (GType                  type,
                             guint                  n_params,
                             GObjectConstructParam *params)
Michael Natterer's avatar
Michael Natterer committed
231
{
232
233
234
235
  GObject         *object;
  GimpImageDock   *dock;
  GimpMenuFactory *menu_factory;
  GtkItemFactory  *item_factory;
236
  GList           *list;
237
238

  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
Michael Natterer's avatar
Michael Natterer committed
239
240
241

  dock = GIMP_IMAGE_DOCK (object);

242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
  menu_factory = GIMP_DOCK (object)->dialog_factory->menu_factory;

  dock->item_factory = gimp_menu_factory_menu_new (menu_factory, "<Image>",
                                                   GTK_TYPE_MENU,
                                                   object, FALSE);

  item_factory = GTK_ITEM_FACTORY (dock->item_factory);

#define DESTROY(menu) gtk_item_factory_delete_item (item_factory, menu)

  DESTROY ("/View/New View");
  DESTROY ("/View/Dot for Dot");
  DESTROY ("/View/Zoom/Zoom Out");
  DESTROY ("/View/Zoom/Zoom In");
  DESTROY ("/View/Zoom/Zoom to Fit Window");
  DESTROY ("/View/Zoom/16:1");
  DESTROY ("/View/Zoom/8:1");
  DESTROY ("/View/Zoom/4:1");
  DESTROY ("/View/Zoom/2:1");
  DESTROY ("/View/Zoom/1:1");
  DESTROY ("/View/Zoom/1:2");
  DESTROY ("/View/Zoom/1:4");
  DESTROY ("/View/Zoom/1:8");
  DESTROY ("/View/Zoom/1:16");
  DESTROY ("/View/Zoom/Other...");
  DESTROY ("/View/Info Window");
  DESTROY ("/View/Navigation Window");
  DESTROY ("/View/Display Filters...");
  DESTROY ("/View/Show Selection");
  DESTROY ("/View/Show Layer Boundary");
  DESTROY ("/View/Show Menubar");
  DESTROY ("/View/Show Rulers");
  DESTROY ("/View/Show Scrollbars");
  DESTROY ("/View/Show Statusbar");
  DESTROY ("/View/Shrink Wrap");
  DESTROY ("/View/Fullscreen");

  DESTROY ("/Layer/Stack/Select Previous Layer");
  DESTROY ("/Layer/Stack/Select Next Layer");
  DESTROY ("/Layer/Stack/Select Top Layer");
  DESTROY ("/Layer/Stack/Select Bottom Layer");
  DESTROY ("/Layer/Stack/Raise Layer");
  DESTROY ("/Layer/Stack/Lower Layer");
  DESTROY ("/Layer/Stack/Layer to Top");
  DESTROY ("/Layer/Stack/Layer to Bottom");

288
289
290
  DESTROY ("/Select/By Color");
  DESTROY ("/Select/Toggle QuickMask");

291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
  DESTROY ("/Tools/Toolbox");
  DESTROY ("/Tools/Default Colors");
  DESTROY ("/Tools/Swap Colors");

  for (list = GIMP_LIST (GIMP_DOCK (dock)->context->gimp->tool_info_list)->list;
       list;
       list = g_list_next (list))
    {
      GimpToolInfo *tool_info = list->data;
      gchar        *menu_path;

      menu_path = gimp_strip_uline (tool_info->menu_path);
      DESTROY (menu_path);
      g_free (menu_path);
    }

307
308
309
310
311
312
313
#undef DESTROY

  gtk_window_add_accel_group (GTK_WINDOW (object),
                              GTK_ITEM_FACTORY (dock->item_factory)->accel_group);

  return object;
}
314
#endif   /* ENABLE_GLOBAL_SHORTCUTS */
315
316
317
318
319
320

static void
gimp_image_dock_destroy (GtkObject *object)
{
  GimpImageDock *dock = GIMP_IMAGE_DOCK (object);

321
322
323
324
325
326
  if (dock->update_title_idle_id)
    {
      g_source_remove (dock->update_title_idle_id);
      dock->update_title_idle_id = 0;
    }

327
#ifdef ENABLE_GLOBAL_SHORTCUTS
328
329
330
331
332
333
334
335
336
337
338
339
  if (dock->image_flush_handler_id)
    {
      gimp_container_remove_handler (dock->image_container,
                                     dock->image_flush_handler_id);
      dock->image_flush_handler_id = 0;
    }

  if (dock->item_factory)
    {
      g_object_unref (dock->item_factory);
      dock->item_factory = NULL;
    }
340
#endif
341

Michael Natterer's avatar
Michael Natterer committed
342
343
344
  /*  remove the image menu and the auto button manually here because
   *  of weird cross-connections with GimpDock's context
   */
345
346
347
348
349
350
351
  if (GIMP_DOCK (dock)->main_vbox &&
      dock->option_menu           &&
      dock->option_menu->parent)
    {
      gtk_container_remove (GTK_CONTAINER (GIMP_DOCK (dock)->main_vbox),
			    dock->option_menu->parent);
    }
Michael Natterer's avatar
Michael Natterer committed
352

353
  GTK_OBJECT_CLASS (parent_class)->destroy (object);
Michael Natterer's avatar
Michael Natterer committed
354
355
}

356
357
358
359
static void
gimp_image_dock_style_set (GtkWidget *widget,
                           GtkStyle  *prev_style)
{
360
361
  GimpImageDock *image_dock;
  gint           minimal_width;
362
  GtkIconSize    menu_preview_size;
363
  GdkScreen     *screen;
364
365
  gint           menu_preview_width  = 18;
  gint           menu_preview_height = 18;
366
367
368
369
370
  gint           focus_line_width;
  gint           focus_padding;
  gint           ythickness;

  image_dock = GIMP_IMAGE_DOCK (widget);
371
372
373
374
375

  if (GTK_WIDGET_CLASS (parent_class)->style_set)
    GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);

  gtk_widget_style_get (widget,
376
377
                        "minimal_width",     &minimal_width,
                        "menu_preview_size", &menu_preview_size,
378
379
			NULL);

380
381
382
383
384
  screen = gtk_widget_get_screen (image_dock->menu);
  gtk_icon_size_lookup_for_settings (gtk_settings_get_for_screen (screen),
                                     menu_preview_size,
                                     &menu_preview_width,
                                     &menu_preview_height);
385

386
387
388
389
390
391
392
  gtk_widget_style_get (image_dock->auto_button,
                        "focus_line_width", &focus_line_width,
                        "focus_padding",    &focus_padding,
			NULL);

  ythickness = image_dock->auto_button->style->ythickness;

393
  gtk_widget_set_size_request (widget, minimal_width, -1);
394
395

  gimp_container_menu_set_preview_size (GIMP_CONTAINER_MENU (image_dock->menu),
396
                                        menu_preview_height, 1);
397
398
399
400
401
402
403

  gtk_widget_set_size_request (image_dock->auto_button, -1,
                               menu_preview_height +
                               2 * (1 /* CHILD_SPACING */ +
                                    ythickness            +
                                    focus_padding         +
                                    focus_line_width));
404
405
}

406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
static void
gimp_image_dock_setup (GimpDock       *dock,
                       const GimpDock *template)
{
  if (GIMP_IS_IMAGE_DOCK (template))
    {
      gboolean auto_follow_active;
      gboolean show_image_menu;

      auto_follow_active = GIMP_IMAGE_DOCK (template)->auto_follow_active;
      show_image_menu    = GIMP_IMAGE_DOCK (template)->show_image_menu;

      gimp_image_dock_set_auto_follow_active (GIMP_IMAGE_DOCK (dock),
                                              auto_follow_active);
      gimp_image_dock_set_show_image_menu (GIMP_IMAGE_DOCK (dock),
                                           show_image_menu);
    }
}

425
426
427
#define AUX_INFO_SHOW_IMAGE_MENU     "show-image-menu"
#define AUX_INFO_FOLLOW_ACTIVE_IMAGE "follow-active-image"

428
429
430
431
static void
gimp_image_dock_set_aux_info (GimpDock *dock,
                              GList    *aux_info)
{
432
  GimpImageDock *image_dock  = GIMP_IMAGE_DOCK (dock);
433
  GList         *list;
434
435
436
  gboolean       menu_shown  = image_dock->show_image_menu;
  gboolean       auto_follow = image_dock->auto_follow_active;

437
  for (list = aux_info; list; list = g_list_next (list))
438
    {
439
440
      GimpSessionInfoAux *aux = list->data;

441
      if (! strcmp (aux->name, AUX_INFO_SHOW_IMAGE_MENU))
442
443
444
        {
          menu_shown = ! g_ascii_strcasecmp (aux->value, "true");
        }
445
      else if (! strcmp (aux->name, AUX_INFO_FOLLOW_ACTIVE_IMAGE))
446
447
448
        {
          auto_follow = ! g_ascii_strcasecmp (aux->value, "true");
        }
449
450
451
452
453
454
455
456
457
458
459
460
    }

  if (menu_shown != image_dock->show_image_menu)
    gimp_image_dock_set_show_image_menu (image_dock, menu_shown);

  if (auto_follow != image_dock->auto_follow_active)
    gimp_image_dock_set_auto_follow_active (image_dock, auto_follow);
}

static GList *
gimp_image_dock_get_aux_info (GimpDock *dock)
{
461
462
463
464
  GimpImageDock      *image_dock = GIMP_IMAGE_DOCK (dock);
  GList              *aux_info   = NULL;
  GimpSessionInfoAux *aux;

465
  aux = gimp_session_info_aux_new (AUX_INFO_SHOW_IMAGE_MENU,
466
467
                                   image_dock->show_image_menu ?
                                   "true" : "false");
468
  aux_info = g_list_append (aux_info, aux);
469

470
  aux = gimp_session_info_aux_new (AUX_INFO_FOLLOW_ACTIVE_IMAGE,
471
472
                                   image_dock->auto_follow_active ?
                                   "true" : "false");
473
  aux_info = g_list_append (aux_info, aux);
474

475
  return aux_info;
476
477
}

478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
static void
gimp_image_dock_book_added (GimpDock     *dock,
                            GimpDockbook *dockbook)
{
  g_signal_connect (dockbook, "dockable_added",
                    G_CALLBACK (gimp_image_dock_dockbook_changed),
                    dock);
  g_signal_connect (dockbook, "dockable_removed",
                    G_CALLBACK (gimp_image_dock_dockbook_changed),
                    dock);
  g_signal_connect (dockbook, "dockable_reordered",
                    G_CALLBACK (gimp_image_dock_dockbook_changed),
                    dock);

  gimp_image_dock_update_title (GIMP_IMAGE_DOCK (dock));

  GIMP_DOCK_CLASS (parent_class)->book_added (dock, dockbook);
}

static void
gimp_image_dock_book_removed (GimpDock     *dock,
                              GimpDockbook *dockbook)
{
  g_signal_handlers_disconnect_by_func (dockbook,
                                        gimp_image_dock_dockbook_changed,
                                        dock);

  gimp_image_dock_update_title (GIMP_IMAGE_DOCK (dock));

507
  GIMP_DOCK_CLASS (parent_class)->book_removed (dock, dockbook);
508
509
}

Michael Natterer's avatar
Michael Natterer committed
510
GtkWidget *
511
gimp_image_dock_new (GimpDialogFactory *dialog_factory,
512
513
		     GimpContainer     *image_container,
                     GimpContainer     *display_container)
Michael Natterer's avatar
Michael Natterer committed
514
515
{
  GimpImageDock *image_dock;
516
  GimpContext   *context;
517
  GdkScreen     *screen;
518
519
  gint           menu_preview_width;
  gint           menu_preview_height;
520

521
  g_return_val_if_fail (GIMP_IS_DIALOG_FACTORY (dialog_factory), NULL);
Michael Natterer's avatar
Michael Natterer committed
522
  g_return_val_if_fail (GIMP_IS_CONTAINER (image_container), NULL);
523
  g_return_val_if_fail (GIMP_IS_CONTAINER (display_container), NULL);
Michael Natterer's avatar
Michael Natterer committed
524

525
526
527
  context = gimp_context_new (dialog_factory->context->gimp,
                              "Dock Context", NULL);

Sven Neumann's avatar
Sven Neumann committed
528
529
530
531
532
533
534
  image_dock = g_object_new (GIMP_TYPE_IMAGE_DOCK,
                             "context",        context,
                             "dialog-factory", dialog_factory,
                             NULL);

  image_dock->image_container   = image_container;
  image_dock->display_container = display_container;
Michael Natterer's avatar
Michael Natterer committed
535

536
#ifdef ENABLE_GLOBAL_SHORTCUTS
537
538
539
540
  image_dock->image_flush_handler_id =
    gimp_container_add_handler (image_container, "flush",
                                G_CALLBACK (gimp_image_dock_image_flush),
                                image_dock);
541
#endif
542

543
544
545
  gimp_help_connect (GTK_WIDGET (image_dock), gimp_standard_help_func,
                     GIMP_HELP_DOCK, NULL);

546
  gimp_context_define_properties (context,
547
548
549
550
				  GIMP_CONTEXT_ALL_PROPS_MASK &
				  ~(GIMP_CONTEXT_IMAGE_MASK |
				    GIMP_CONTEXT_DISPLAY_MASK),
				  FALSE);
551
  gimp_context_set_parent (context, dialog_factory->context);
Michael Natterer's avatar
Michael Natterer committed
552

553
  if (image_dock->auto_follow_active)
554
555
556
557
558
559
560
561
    {
      if (gimp_context_get_display (dialog_factory->context))
        gimp_context_copy_property (dialog_factory->context, context,
                                    GIMP_CONTEXT_PROP_DISPLAY);
      else
        gimp_context_copy_property (dialog_factory->context, context,
                                    GIMP_CONTEXT_PROP_IMAGE);
    }
562

563
  g_signal_connect_object (dialog_factory->context, "display_changed",
Michael Natterer's avatar
Michael Natterer committed
564
			   G_CALLBACK (gimp_image_dock_factory_display_changed),
565
			   image_dock,
Michael Natterer's avatar
Michael Natterer committed
566
			   0);
567
  g_signal_connect_object (dialog_factory->context, "image_changed",
568
			   G_CALLBACK (gimp_image_dock_factory_image_changed),
569
			   image_dock,
570
			   0);
Michael Natterer's avatar
Michael Natterer committed
571

572
#ifdef ENABLE_GLOBAL_SHORTCUTS
573
574
575
576
  g_signal_connect_object (context, "display_changed",
			   G_CALLBACK (gimp_image_dock_display_changed),
			   image_dock,
			   0);
577
#endif
578
  g_signal_connect_object (context, "image_changed",
579
			   G_CALLBACK (gimp_image_dock_image_changed),
580
			   image_dock,
581
			   0);
Michael Natterer's avatar
Michael Natterer committed
582

583
584
585
586
587
  screen = gtk_widget_get_screen (GTK_WIDGET (image_dock));
  gtk_icon_size_lookup_for_settings (gtk_settings_get_for_screen (screen),
                                     DEFAULT_MENU_PREVIEW_SIZE,
                                     &menu_preview_width,
                                     &menu_preview_height);
588

589
  image_dock->menu = gimp_container_menu_new (image_container, context,
590
                                              menu_preview_height, 1);
Michael Natterer's avatar
Michael Natterer committed
591
592
593
594
  gtk_option_menu_set_menu (GTK_OPTION_MENU (image_dock->option_menu),
			    image_dock->menu);
  gtk_widget_show (image_dock->menu);

595
  g_object_unref (context);
596

Michael Natterer's avatar
Michael Natterer committed
597
598
  return GTK_WIDGET (image_dock);
}
Michael Natterer's avatar
Michael Natterer committed
599

600
601
602
603
604
605
606
607
608
609
void
gimp_image_dock_set_auto_follow_active (GimpImageDock *image_dock,
					gboolean       auto_follow_active)
{
  g_return_if_fail (GIMP_IS_IMAGE_DOCK (image_dock));

  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (image_dock->auto_button),
				auto_follow_active ? TRUE : FALSE);
}

Michael Natterer's avatar
Michael Natterer committed
610
611
612
613
614
615
616
void
gimp_image_dock_set_show_image_menu (GimpImageDock *image_dock,
				     gboolean       show)
{
  g_return_if_fail (GIMP_IS_IMAGE_DOCK (image_dock));

  if (show)
617
    gtk_widget_show (image_dock->option_menu->parent);
Michael Natterer's avatar
Michael Natterer committed
618
  else
619
    gtk_widget_hide (image_dock->option_menu->parent);
620
621

  image_dock->show_image_menu = show ? TRUE : FALSE;
Michael Natterer's avatar
Michael Natterer committed
622
623
}

624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
static void
gimp_image_dock_dockbook_changed (GimpDockbook  *dockbook,
                                  GimpDockable  *dockable,
                                  GimpImageDock *dock)
{
  gimp_image_dock_update_title (dock);
}

static gboolean
gimp_image_dock_update_title_idle (GimpImageDock *image_dock)
{
  GString *title;
  GList   *list;

  title = g_string_new (NULL);

  for (list = GIMP_DOCK (image_dock)->dockbooks;
       list;
       list = g_list_next (list))
    {
      GimpDockbook *dockbook = list->data;
      GList        *children;
      GList        *child;

      children = gtk_container_get_children (GTK_CONTAINER (dockbook));

      for (child = children; child; child = g_list_next (child))
        {
          GimpDockable *dockable = child->data;

654
          g_string_append (title, dockable->name);
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685

          if (g_list_next (child))
            g_string_append (title, ", ");
        }

      g_list_free (children);

      if (g_list_next (list))
        g_string_append (title, " | ");
    }

  gtk_window_set_title (GTK_WINDOW (image_dock), title->str);

  g_string_free (title, TRUE);

  image_dock->update_title_idle_id = 0;

  return FALSE;
}

static void
gimp_image_dock_update_title (GimpImageDock *image_dock)
{
  if (image_dock->update_title_idle_id)
    g_source_remove (image_dock->update_title_idle_id);

  image_dock->update_title_idle_id =
    g_idle_add ((GSourceFunc) gimp_image_dock_update_title_idle,
                image_dock);
}

Michael Natterer's avatar
Michael Natterer committed
686
687
static void
gimp_image_dock_factory_display_changed (GimpContext *context,
688
                                         GimpObject  *display,
Michael Natterer's avatar
Michael Natterer committed
689
690
                                         GimpDock    *dock)
{
691
  GimpImageDock *image_dock = GIMP_IMAGE_DOCK (dock);
Michael Natterer's avatar
Michael Natterer committed
692

693
694
  if (display && image_dock->auto_follow_active)
    gimp_context_set_display (dock->context, display);
Michael Natterer's avatar
Michael Natterer committed
695
696
}

Michael Natterer's avatar
Michael Natterer committed
697
698
699
700
701
static void
gimp_image_dock_factory_image_changed (GimpContext *context,
				       GimpImage   *gimage,
				       GimpDock    *dock)
{
702
  GimpImageDock *image_dock = GIMP_IMAGE_DOCK (dock);
Michael Natterer's avatar
Michael Natterer committed
703

704
  /*  won't do anything if we already set the display above  */
Michael Natterer's avatar
Michael Natterer committed
705
  if (gimage && image_dock->auto_follow_active)
706
    gimp_context_set_image (dock->context, gimage);
Michael Natterer's avatar
Michael Natterer committed
707
708
}

709
#ifdef ENABLE_GLOBAL_SHORTCUTS
710
711
712
713
714
715
716
717
718
static void
gimp_image_dock_display_changed (GimpContext *context,
                                 GimpObject  *display,
                                 GimpDock    *dock)
{
  GimpImageDock *image_dock = GIMP_IMAGE_DOCK (dock);

  gimp_item_factory_update (image_dock->item_factory, display);
}
719
#endif
720

Michael Natterer's avatar
Michael Natterer committed
721
722
723
724
725
static void
gimp_image_dock_image_changed (GimpContext *context,
			       GimpImage   *gimage,
			       GimpDock    *dock)
{
726
  GimpImageDock *image_dock = GIMP_IMAGE_DOCK (dock);
Michael Natterer's avatar
Michael Natterer committed
727

728
729
  if (gimage == NULL &&
      gimp_container_num_children (image_dock->image_container) > 0)
Michael Natterer's avatar
Michael Natterer committed
730
731
732
    {
      gimage = GIMP_IMAGE (gimp_container_get_child_by_index (image_dock->image_container, 0));

733
734
735
736
737
      if (gimage)
	{
	  /*  this invokes this function recursively but we don't enter
	   *  the if() branch the second time
	   */
738
	  gimp_context_set_image (context, gimage);
739
740
741
742

	  /*  stop the emission of the original signal (the emission of
	   *  the recursive signal is finished)
	   */
743
	  g_signal_stop_emission_by_name (context, "image_changed");
744
	}
Michael Natterer's avatar
Michael Natterer committed
745
    }
746
747
  else if (gimage != NULL &&
           gimp_container_num_children (image_dock->display_container) > 0)
748
749
    {
      GimpObject *gdisp;
750
      GimpImage  *gdisp_gimage;
751
752
753
754
755
756
757
758
      gboolean    find_display = TRUE;

      gdisp = gimp_context_get_display (context);

      if (gdisp)
        {
          g_object_get (gdisp, "image", &gdisp_gimage, NULL);

759
760
761
762
763
764
765
          if (gdisp_gimage)
            {
              g_object_unref (gdisp_gimage);

              if (gdisp_gimage == gimage)
                find_display = FALSE;
            }
766
767
768
769
770
771
772
773
774
775
776
777
778
779
        }

      if (find_display)
        {
          GList *list;

          for (list = GIMP_LIST (image_dock->display_container)->list;
               list;
               list = g_list_next (list))
            {
              gdisp = GIMP_OBJECT (list->data);

              g_object_get (gdisp, "image", &gdisp_gimage, NULL);

780
              if (gdisp_gimage)
781
                {
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
                  g_object_unref (gdisp_gimage);

                  if (gdisp_gimage == gimage)
                    {
                      /*  this invokes this function recursively but we
                       *  don't enter the if(find_display) branch the
                       *  second time
                       */
                      gimp_context_set_display (context, gdisp);

                      /*  don't stop signal emission here because the
                       *  context's image was not changed by the
                       *  recursive call
                       */
                      break;
                    }
798
799
800
801
                }
            }
        }
    }
Michael Natterer's avatar
Michael Natterer committed
802
803
804
805
806
807
}

static void
gimp_image_dock_auto_clicked (GtkWidget *widget,
			      GimpDock  *dock)
{
808
  GimpImageDock *image_dock = GIMP_IMAGE_DOCK (dock);
Michael Natterer's avatar
Michael Natterer committed
809
810
811
812
813

  gimp_toggle_button_update (widget, &image_dock->auto_follow_active);

  if (image_dock->auto_follow_active)
    {
814
      if (gimp_context_get_display (dock->dialog_factory->context))
815
816
        gimp_context_copy_property (dock->dialog_factory->context,
                                    dock->context,
817
                                    GIMP_CONTEXT_PROP_DISPLAY);
Michael Natterer's avatar
Michael Natterer committed
818
      else
819
820
        gimp_context_copy_property (dock->dialog_factory->context,
                                    dock->context,
821
                                    GIMP_CONTEXT_PROP_IMAGE);
Michael Natterer's avatar
Michael Natterer committed
822
823
    }
}
824

825
#ifdef ENABLE_GLOBAL_SHORTCUTS
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
static void
gimp_image_dock_image_flush (GimpImage *gimage,
                             GimpDock  *dock)
{
  GimpImageDock *image_dock = GIMP_IMAGE_DOCK (dock);
  GimpImage     *dock_image;

  dock_image = gimp_context_get_image (dock->context);

  if (dock_image == gimage)
    {
      GimpObject *display = gimp_context_get_display (dock->context);

      if (display)
        gimp_item_factory_update (image_dock->item_factory, display);
    }
}
843
#endif