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

« back to all changes in this revision

Viewing changes to app/display/gimpdisplayshell.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 program is free software; you can redistribute it and/or modify
22
22
 
23
23
#include <gtk/gtk.h>
24
24
 
 
25
#include "libgimpbase/gimpbase.h"
 
26
#include "libgimpmath/gimpmath.h"
 
27
#include "libgimpcolor/gimpcolor.h"
 
28
#include "libgimpconfig/gimpconfig.h"
25
29
#include "libgimpwidgets/gimpwidgets.h"
26
30
 
27
31
#include "display-types.h"
28
32
#include "tools/tools-types.h"
29
33
 
30
 
#include "config/gimpconfig.h"
31
 
#include "config/gimpconfig-params.h"
32
 
#include "config/gimpconfig-utils.h"
 
34
#include "config/gimpcoreconfig.h"
33
35
#include "config/gimpdisplayconfig.h"
34
36
 
35
37
#include "core/gimp.h"
36
 
#include "core/gimpbuffer.h"
 
38
#include "core/gimpchannel.h"
37
39
#include "core/gimpcontext.h"
38
 
#include "core/gimpgrid.h"
 
40
#include "core/gimpguide.h"
39
41
#include "core/gimpimage.h"
40
 
#include "core/gimpimage-guides.h"
41
42
#include "core/gimpimage-snap.h"
42
 
#include "core/gimplayer.h"
43
 
#include "core/gimplayermask.h"
44
 
#include "core/gimplist.h"
45
43
#include "core/gimpmarshal.h"
46
 
#include "core/gimppattern.h"
47
 
 
48
 
#include "vectors/gimpvectors.h"
49
 
 
50
 
#include "widgets/gimpdnd.h"
 
44
#include "core/gimpsamplepoint.h"
 
45
 
 
46
#include "widgets/gimprender.h"
51
47
#include "widgets/gimphelp-ids.h"
52
48
#include "widgets/gimpmenufactory.h"
53
49
#include "widgets/gimpuimanager.h"
54
50
#include "widgets/gimpwidgets-utils.h"
55
51
 
56
 
#ifdef __GNUC__
57
 
#warning FIXME #include "dialogs/dialogs-types.h"
58
 
#endif
59
 
#include "dialogs/dialogs-types.h"
60
 
#include "dialogs/info-window.h"
61
 
 
62
52
#include "tools/tool_manager.h"
63
53
 
64
54
#include "gimpcanvas.h"
73
63
#include "gimpdisplayshell-draw.h"
74
64
#include "gimpdisplayshell-filter.h"
75
65
#include "gimpdisplayshell-handlers.h"
76
 
#include "gimpdisplayshell-render.h"
 
66
#include "gimpdisplayshell-progress.h"
77
67
#include "gimpdisplayshell-scale.h"
78
68
#include "gimpdisplayshell-selection.h"
79
69
#include "gimpdisplayshell-title.h"
86
76
enum
87
77
{
88
78
  PROP_0,
89
 
  PROP_SCALE,
90
79
  PROP_UNIT
91
80
};
92
81
 
101
90
 
102
91
/*  local function prototypes  */
103
92
 
104
 
static void      gimp_display_shell_class_init    (GimpDisplayShellClass *klass);
105
 
static void      gimp_display_shell_init          (GimpDisplayShell      *shell);
106
 
 
107
93
static void      gimp_display_shell_finalize       (GObject          *object);
108
94
static void      gimp_display_shell_set_property   (GObject          *object,
109
95
                                                    guint             property_id,
115
101
                                                    GParamSpec       *pspec);
116
102
 
117
103
static void      gimp_display_shell_destroy        (GtkObject        *object);
 
104
 
 
105
static void      gimp_display_shell_unrealize      (GtkWidget        *widget);
118
106
static void      gimp_display_shell_screen_changed (GtkWidget        *widget,
119
107
                                                    GdkScreen        *previous);
120
108
static gboolean  gimp_display_shell_delete_event   (GtkWidget        *widget,
127
115
                                                    gint             *x,
128
116
                                                    gint             *y,
129
117
                                                    gpointer          data);
130
 
 
131
 
 
132
 
static guint  display_shell_signals[LAST_SIGNAL] = { 0 };
133
 
 
134
 
static GtkWindowClass *parent_class = NULL;
135
 
 
136
 
 
137
 
GType
138
 
gimp_display_shell_get_type (void)
139
 
{
140
 
  static GType shell_type = 0;
141
 
 
142
 
  if (! shell_type)
143
 
    {
144
 
      static const GTypeInfo shell_info =
145
 
      {
146
 
        sizeof (GimpDisplayShellClass),
147
 
        (GBaseInitFunc) NULL,
148
 
        (GBaseFinalizeFunc) NULL,
149
 
        (GClassInitFunc) gimp_display_shell_class_init,
150
 
        NULL,           /* class_finalize */
151
 
        NULL,           /* class_data     */
152
 
        sizeof (GimpDisplayShell),
153
 
        0,              /* n_preallocs    */
154
 
        (GInstanceInitFunc) gimp_display_shell_init,
155
 
      };
156
 
 
157
 
      shell_type = g_type_register_static (GTK_TYPE_WINDOW,
158
 
                                           "GimpDisplayShell",
159
 
                                           &shell_info, 0);
160
 
    }
161
 
 
162
 
  return shell_type;
163
 
}
 
118
static void      gimp_display_shell_show_tooltip   (GimpUIManager    *manager,
 
119
                                                    const gchar      *tooltip,
 
120
                                                    GimpDisplayShell *shell);
 
121
static void      gimp_display_shell_hide_tooltip   (GimpUIManager    *manager,
 
122
                                                    GimpDisplayShell *shell);
 
123
 
 
124
 
 
125
G_DEFINE_TYPE_WITH_CODE (GimpDisplayShell, gimp_display_shell, GTK_TYPE_WINDOW,
 
126
                         G_IMPLEMENT_INTERFACE (GIMP_TYPE_PROGRESS,
 
127
                                                gimp_display_shell_progress_iface_init))
 
128
 
 
129
#define parent_class gimp_display_shell_parent_class
 
130
 
 
131
static guint display_shell_signals[LAST_SIGNAL] = { 0 };
 
132
 
 
133
 
 
134
static const gchar display_rc_style[] =
 
135
  "style \"fullscreen-menubar-style\"\n"
 
136
  "{\n"
 
137
  "  GtkMenuBar::shadow-type      = none\n"
 
138
  "  GtkMenuBar::internal-padding = 0\n"
 
139
  "}\n"
 
140
  "widget \"*.gimp-menubar-fullscreen\" style \"fullscreen-menubar-style\"\n"
 
141
  "\n"
 
142
  "style \"check-button-style\"\n"
 
143
  "{\n"
 
144
  "  GtkToggleButton::child-displacement-x = 0\n"
 
145
  "  GtkToggleButton::child-displacement-y = 0\n"
 
146
  "}\n"
 
147
  "widget \"*\" style \"check-button-style\"";
164
148
 
165
149
static void
166
150
gimp_display_shell_class_init (GimpDisplayShellClass *klass)
169
153
  GtkObjectClass *gtk_object_class  = GTK_OBJECT_CLASS (klass);
170
154
  GtkWidgetClass *widget_class      = GTK_WIDGET_CLASS (klass);
171
155
 
172
 
  parent_class = g_type_class_peek_parent (klass);
173
 
 
174
156
  display_shell_signals[SCALED] =
175
157
    g_signal_new ("scaled",
176
158
                  G_TYPE_FROM_CLASS (klass),
204
186
 
205
187
  gtk_object_class->destroy    = gimp_display_shell_destroy;
206
188
 
 
189
  widget_class->unrealize      = gimp_display_shell_unrealize;
207
190
  widget_class->screen_changed = gimp_display_shell_screen_changed;
208
191
  widget_class->delete_event   = gimp_display_shell_delete_event;
209
192
  widget_class->popup_menu     = gimp_display_shell_popup_menu;
212
195
  klass->scrolled              = NULL;
213
196
  klass->reconnect             = NULL;
214
197
 
215
 
  g_object_class_install_property (object_class, PROP_SCALE,
216
 
                                   g_param_spec_double ("scale", NULL, NULL,
217
 
                                                        1.0 / 256, 256, 1.0,
218
 
                                                        G_PARAM_READWRITE));
219
 
 
220
198
  g_object_class_install_property (object_class, PROP_UNIT,
221
199
                                   gimp_param_spec_unit ("unit", NULL, NULL,
222
200
                                                         TRUE, FALSE,
223
201
                                                         GIMP_UNIT_PIXEL,
224
 
                                                         G_PARAM_READWRITE));
 
202
                                                         GIMP_PARAM_READWRITE));
 
203
 
 
204
  gtk_rc_parse_string (display_rc_style);
225
205
}
226
206
 
227
207
static void
228
208
gimp_display_shell_init (GimpDisplayShell *shell)
229
209
{
230
 
  shell->gdisp                  = NULL;
 
210
  shell->display                = NULL;
231
211
 
232
212
  shell->menubar_manager        = NULL;
233
213
  shell->popup_manager          = NULL;
234
214
 
235
215
  shell->unit                   = GIMP_UNIT_PIXEL;
236
216
 
237
 
  shell->scale                  = 1.0;
 
217
  shell->zoom                   = gimp_zoom_model_new ();
238
218
  shell->other_scale            = 0.0;
239
219
  shell->dot_for_dot            = TRUE;
240
220
 
241
221
  shell->offset_x               = 0;
242
222
  shell->offset_y               = 0;
 
223
  shell->scale_x                = 1.0;
 
224
  shell->scale_y                = 1.0;
 
225
 
 
226
  shell->last_scale             = 0.0;
 
227
  shell->last_scale_time        = 0;
 
228
  shell->last_offset_x          = 0;
 
229
  shell->last_offset_y          = 0;
243
230
 
244
231
  shell->disp_width             = 0;
245
232
  shell->disp_height            = 0;
249
236
  shell->proximity              = FALSE;
250
237
  shell->snap_to_guides         = TRUE;
251
238
  shell->snap_to_grid           = FALSE;
 
239
  shell->snap_to_canvas         = FALSE;
 
240
  shell->snap_to_vectors        = FALSE;
252
241
 
253
 
  shell->select                 = NULL;
 
242
  shell->selection              = NULL;
254
243
 
255
244
  shell->canvas                 = NULL;
256
245
  shell->grid_gc                = NULL;
 
246
  shell->pen_gc                 = NULL;
257
247
 
258
248
  shell->hsbdata                = NULL;
259
249
  shell->vsbdata                = NULL;
263
253
  shell->hrule                  = NULL;
264
254
  shell->vrule                  = NULL;
265
255
 
266
 
  shell->origin_button          = NULL;
267
 
  shell->qmask_button           = NULL;
 
256
  shell->origin                 = NULL;
 
257
  shell->quick_mask_button      = NULL;
268
258
  shell->zoom_button            = NULL;
269
259
  shell->nav_ebox               = NULL;
270
260
 
271
261
  shell->menubar                = NULL;
272
262
  shell->statusbar              = NULL;
273
263
 
274
 
  shell->render_buf             = g_malloc (GIMP_DISPLAY_SHELL_RENDER_BUF_WIDTH  *
275
 
                                           GIMP_DISPLAY_SHELL_RENDER_BUF_HEIGHT *
276
 
                                           3);
 
264
  shell->render_buf             = g_new (guchar,
 
265
                                         GIMP_RENDER_BUF_WIDTH  *
 
266
                                         GIMP_RENDER_BUF_HEIGHT * 3);
277
267
 
278
268
  shell->title_idle_id          = 0;
279
269
 
294
284
  shell->cursor_y               = 0;
295
285
 
296
286
  shell->close_dialog           = NULL;
297
 
  shell->info_dialog            = NULL;
298
287
  shell->scale_dialog           = NULL;
299
288
  shell->nav_popup              = NULL;
300
289
  shell->grid_dialog            = NULL;
314
303
 
315
304
  shell->space_pressed          = FALSE;
316
305
  shell->space_release_pending  = FALSE;
 
306
  shell->space_shaded_tool      = NULL;
 
307
 
317
308
  shell->scrolling              = FALSE;
318
309
  shell->scroll_start_x         = 0;
319
310
  shell->scroll_start_y         = 0;
320
311
  shell->button_press_before_focus = FALSE;
321
312
 
322
313
  shell->highlight              = NULL;
 
314
  shell->mask                   = NULL;
323
315
 
324
316
  gtk_window_set_role (GTK_WINDOW (shell), "gimp-image-window");
325
317
  gtk_window_set_resizable (GTK_WINDOW (shell), TRUE);
330
322
                                              GDK_KEY_PRESS_MASK           |
331
323
                                              GDK_KEY_RELEASE_MASK         |
332
324
                                              GDK_FOCUS_CHANGE_MASK        |
 
325
                                              GDK_VISIBILITY_NOTIFY_MASK   |
333
326
                                              GDK_SCROLL_MASK));
334
327
 
 
328
  /*  zoom model callback  */
 
329
  g_signal_connect_swapped (shell->zoom, "zoomed",
 
330
                            G_CALLBACK (gimp_display_shell_scale_changed),
 
331
                            shell);
 
332
 
335
333
  /*  active display callback  */
336
 
  g_signal_connect (shell, "button_press_event",
337
 
                    G_CALLBACK (gimp_display_shell_events),
338
 
                    shell);
339
 
  g_signal_connect (shell, "button_release_event",
340
 
                    G_CALLBACK (gimp_display_shell_events),
341
 
                    shell);
342
 
  g_signal_connect (shell, "key_press_event",
343
 
                    G_CALLBACK (gimp_display_shell_events),
344
 
                    shell);
345
 
  g_signal_connect (shell, "window_state_event",
 
334
  g_signal_connect (shell, "button-press-event",
 
335
                    G_CALLBACK (gimp_display_shell_events),
 
336
                    shell);
 
337
  g_signal_connect (shell, "button-release-event",
 
338
                    G_CALLBACK (gimp_display_shell_events),
 
339
                    shell);
 
340
  g_signal_connect (shell, "key-press-event",
 
341
                    G_CALLBACK (gimp_display_shell_events),
 
342
                    shell);
 
343
  g_signal_connect (shell, "window-state-event",
346
344
                    G_CALLBACK (gimp_display_shell_events),
347
345
                    shell);
348
346
 
349
 
  /*  dnd stuff  */
350
 
  gimp_dnd_uri_list_dest_add (GTK_WIDGET (shell),
351
 
                              gimp_display_shell_drop_uri_list,
352
 
                              shell);
353
 
  gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_LAYER,
354
 
                              gimp_display_shell_drop_drawable,
355
 
                              shell);
356
 
  gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_LAYER_MASK,
357
 
                              gimp_display_shell_drop_drawable,
358
 
                              shell);
359
 
  gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_CHANNEL,
360
 
                              gimp_display_shell_drop_drawable,
361
 
                              shell);
362
 
  gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_VECTORS,
363
 
                              gimp_display_shell_drop_vectors,
364
 
                              shell);
365
 
  gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_PATTERN,
366
 
                              gimp_display_shell_drop_pattern,
367
 
                              shell);
368
 
  gimp_dnd_viewable_dest_add (GTK_WIDGET (shell), GIMP_TYPE_BUFFER,
369
 
                              gimp_display_shell_drop_buffer,
370
 
                              shell);
371
 
  gimp_dnd_color_dest_add    (GTK_WIDGET (shell),
372
 
                              gimp_display_shell_drop_color,
373
 
                              shell);
374
 
  gimp_dnd_svg_dest_add      (GTK_WIDGET (shell),
375
 
                              gimp_display_shell_drop_svg,
376
 
                              shell);
 
347
  gimp_display_shell_dnd_init (shell);
377
348
 
378
349
  gimp_help_connect (GTK_WIDGET (shell), gimp_standard_help_func,
379
350
                     GIMP_HELP_IMAGE_WINDOW, NULL);
384
355
{
385
356
  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (object);
386
357
 
 
358
  g_object_unref (shell->zoom);
 
359
 
387
360
  if (shell->options)
388
361
    g_object_unref (shell->options);
389
362
 
394
367
}
395
368
 
396
369
static void
 
370
gimp_display_shell_set_property (GObject      *object,
 
371
                                 guint         property_id,
 
372
                                 const GValue *value,
 
373
                                 GParamSpec   *pspec)
 
374
{
 
375
  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (object);
 
376
 
 
377
  switch (property_id)
 
378
    {
 
379
    case PROP_UNIT:
 
380
      gimp_display_shell_set_unit (shell, g_value_get_int (value));
 
381
      break;
 
382
 
 
383
    default:
 
384
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
385
      break;
 
386
    }
 
387
}
 
388
 
 
389
static void
 
390
gimp_display_shell_get_property (GObject    *object,
 
391
                                 guint       property_id,
 
392
                                 GValue     *value,
 
393
                                 GParamSpec *pspec)
 
394
{
 
395
  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (object);
 
396
 
 
397
  switch (property_id)
 
398
    {
 
399
    case PROP_UNIT:
 
400
      g_value_set_int (value, shell->unit);
 
401
      break;
 
402
 
 
403
    default:
 
404
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
405
      break;
 
406
    }
 
407
}
 
408
 
 
409
static void
397
410
gimp_display_shell_destroy (GtkObject *object)
398
411
{
399
412
  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (object);
400
413
 
401
 
  if (shell->gdisp)
 
414
  if (shell->display)
402
415
    gimp_display_shell_disconnect (shell);
403
416
 
404
417
  if (shell->menubar_manager)
409
422
 
410
423
  shell->popup_manager = NULL;
411
424
 
412
 
  if (shell->select)
413
 
    {
414
 
      gimp_display_shell_selection_free (shell->select);
415
 
      shell->select = NULL;
416
 
    }
 
425
  gimp_display_shell_selection_free (shell);
417
426
 
418
427
  if (shell->filter_stack)
419
428
    gimp_display_shell_filter_set (shell, NULL);
436
445
      shell->highlight = NULL;
437
446
    }
438
447
 
 
448
  if (shell->mask)
 
449
    {
 
450
      g_object_unref (shell->mask);
 
451
      shell->mask = NULL;
 
452
    }
 
453
 
439
454
  if (shell->title_idle_id)
440
455
    {
441
456
      g_source_remove (shell->title_idle_id);
442
457
      shell->title_idle_id = 0;
443
458
    }
444
459
 
445
 
  if (shell->info_dialog)
446
 
    {
447
 
      info_window_free (shell->info_dialog);
448
 
      shell->info_dialog = NULL;
449
 
    }
450
 
 
451
460
  if (shell->nav_popup)
452
461
    {
453
462
      gtk_widget_destroy (shell->nav_popup);
460
469
      shell->grid_dialog = NULL;
461
470
    }
462
471
 
463
 
  shell->gdisp = NULL;
 
472
  shell->display = NULL;
464
473
 
465
474
  GTK_OBJECT_CLASS (parent_class)->destroy (object);
466
475
}
467
476
 
468
477
static void
469
 
gimp_display_shell_set_property (GObject      *object,
470
 
                                 guint         property_id,
471
 
                                 const GValue *value,
472
 
                                 GParamSpec   *pspec)
473
 
{
474
 
  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (object);
475
 
 
476
 
  switch (property_id)
477
 
    {
478
 
    case PROP_SCALE:
479
 
      gimp_display_shell_scale (shell,
480
 
                                GIMP_ZOOM_TO, g_value_get_double (value));
481
 
      break;
482
 
    case PROP_UNIT:
483
 
      gimp_display_shell_set_unit (shell, g_value_get_int (value));
484
 
      break;
485
 
    default:
486
 
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
487
 
      break;
488
 
    }
489
 
}
490
 
 
491
 
static void
492
 
gimp_display_shell_get_property (GObject    *object,
493
 
                                 guint       property_id,
494
 
                                 GValue     *value,
495
 
                                 GParamSpec *pspec)
496
 
{
497
 
  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (object);
498
 
 
499
 
  switch (property_id)
500
 
    {
501
 
    case PROP_SCALE:
502
 
      g_value_set_double (value, shell->scale);
503
 
      break;
504
 
    case PROP_UNIT:
505
 
      g_value_set_int (value, shell->unit);
506
 
      break;
507
 
    default:
508
 
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
509
 
      break;
510
 
    }
 
478
gimp_display_shell_unrealize (GtkWidget *widget)
 
479
{
 
480
  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (widget);
 
481
 
 
482
  if (shell->grid_gc)
 
483
    {
 
484
      g_object_unref (shell->grid_gc);
 
485
      shell->grid_gc = NULL;
 
486
    }
 
487
 
 
488
  if (shell->pen_gc)
 
489
    {
 
490
      g_object_unref (shell->pen_gc);
 
491
      shell->pen_gc = NULL;
 
492
    }
 
493
 
 
494
  if (shell->nav_popup)
 
495
    gtk_widget_unrealize (shell->nav_popup);
 
496
 
 
497
  GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
511
498
}
512
499
 
513
500
static void
520
507
  if (GTK_WIDGET_CLASS (parent_class)->screen_changed)
521
508
    GTK_WIDGET_CLASS (parent_class)->screen_changed (widget, previous);
522
509
 
523
 
  config = GIMP_DISPLAY_CONFIG (shell->gdisp->gimage->gimp->config);
 
510
  config = GIMP_DISPLAY_CONFIG (shell->display->image->gimp->config);
524
511
 
525
512
  if (GIMP_DISPLAY_CONFIG (config)->monitor_res_from_gdk)
526
513
    {
551
538
{
552
539
  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (widget);
553
540
 
554
 
  gimp_context_set_display (gimp_get_user_context (shell->gdisp->gimage->gimp),
555
 
                            shell->gdisp);
 
541
  gimp_context_set_display (gimp_get_user_context (shell->display->image->gimp),
 
542
                            shell->display);
556
543
 
557
544
  gimp_ui_manager_ui_popup (shell->popup_manager, "/dummy-menubar/image-popup",
558
545
                            GTK_WIDGET (shell),
559
546
                            gimp_display_shell_menu_position,
560
 
                            shell->origin_button,
 
547
                            shell->origin,
561
548
                            NULL, NULL);
562
549
 
563
550
  return TRUE;
568
555
{
569
556
  GimpContext *user_context;
570
557
 
571
 
  if (! shell->gdisp)
 
558
  if (! shell->display)
572
559
    return;
573
560
 
574
561
  gimp_display_shell_title_update (shell);
575
562
 
576
563
  /* update the <Image>/View/Zoom menu */
577
 
  gimp_ui_manager_update (shell->menubar_manager, shell->gdisp);
578
 
 
579
 
  user_context = gimp_get_user_context (shell->gdisp->gimage->gimp);
580
 
 
581
 
  if (shell->gdisp == gimp_context_get_display (user_context))
582
 
    gimp_ui_manager_update (shell->popup_manager, shell->gdisp);
 
564
  gimp_ui_manager_update (shell->menubar_manager, shell->display);
 
565
 
 
566
  user_context = gimp_get_user_context (shell->display->image->gimp);
 
567
 
 
568
  if (shell->display == gimp_context_get_display (user_context))
 
569
    gimp_ui_manager_update (shell->popup_manager, shell->display);
583
570
}
584
571
 
585
572
static void
591
578
  gimp_button_menu_position (GTK_WIDGET (data), menu, GTK_POS_RIGHT, x, y);
592
579
}
593
580
 
 
581
static void
 
582
gimp_display_shell_show_tooltip (GimpUIManager    *manager,
 
583
                                 const gchar      *tooltip,
 
584
                                 GimpDisplayShell *shell)
 
585
{
 
586
  gimp_statusbar_push (GIMP_STATUSBAR (shell->statusbar), "menu-tooltip",
 
587
                       tooltip);
 
588
}
 
589
 
 
590
static void
 
591
gimp_display_shell_hide_tooltip (GimpUIManager    *manager,
 
592
                                 GimpDisplayShell *shell)
 
593
{
 
594
  gimp_statusbar_pop (GIMP_STATUSBAR (shell->statusbar), "menu-tooltip");
 
595
}
 
596
 
594
597
 
595
598
/*  public functions  */
596
599
 
597
600
GtkWidget *
598
 
gimp_display_shell_new (GimpDisplay     *gdisp,
 
601
gimp_display_shell_new (GimpDisplay     *display,
599
602
                        GimpUnit         unit,
600
603
                        gdouble          scale,
601
604
                        GimpMenuFactory *menu_factory,
603
606
{
604
607
  GimpDisplayShell  *shell;
605
608
  GimpDisplayConfig *display_config;
 
609
  GimpColorConfig   *color_config;
606
610
  GtkWidget         *main_vbox;
607
611
  GtkWidget         *disp_vbox;
608
612
  GtkWidget         *upper_hbox;
611
615
  GtkWidget         *inner_table;
612
616
  GtkWidget         *image;
613
617
  GdkScreen         *screen;
 
618
  GtkAction         *action;
614
619
  gint               image_width, image_height;
615
620
  gint               n_width, n_height;
616
621
  gint               s_width, s_height;
617
622
  gdouble            new_scale;
618
623
 
619
 
  g_return_val_if_fail (GIMP_IS_DISPLAY (gdisp), NULL);
 
624
  g_return_val_if_fail (GIMP_IS_DISPLAY (display), NULL);
620
625
  g_return_val_if_fail (GIMP_IS_MENU_FACTORY (menu_factory), NULL);
621
626
  g_return_val_if_fail (GIMP_IS_UI_MANAGER (popup_manager), NULL);
622
627
 
623
628
  /*  the toplevel shell */
624
629
  shell = g_object_new (GIMP_TYPE_DISPLAY_SHELL,
625
 
                        "unit",  unit,
626
 
                        "scale", scale,
 
630
                     /* "gravity", GDK_GRAVITY_CENTER, */
 
631
                        "unit",    unit,
627
632
                        NULL);
628
633
 
629
 
  shell->gdisp = gdisp;
630
 
 
631
 
  image_width  = gdisp->gimage->width;
632
 
  image_height = gdisp->gimage->height;
633
 
 
634
 
  display_config = GIMP_DISPLAY_CONFIG (gdisp->gimage->gimp->config);
 
634
  shell->display = display;
 
635
 
 
636
  image_width  = display->image->width;
 
637
  image_height = display->image->height;
 
638
 
 
639
  display_config = GIMP_DISPLAY_CONFIG (display->image->gimp->config);
635
640
 
636
641
  shell->dot_for_dot = display_config->default_dot_for_dot;
637
642
 
638
 
  gimp_config_sync (GIMP_CONFIG (display_config->default_view),
639
 
                    GIMP_CONFIG (shell->options), 0);
640
 
  gimp_config_sync (GIMP_CONFIG (display_config->default_fullscreen_view),
641
 
                    GIMP_CONFIG (shell->fullscreen_options), 0);
 
643
  gimp_config_sync (G_OBJECT (display_config->default_view),
 
644
                    G_OBJECT (shell->options), 0);
 
645
  gimp_config_sync (G_OBJECT (display_config->default_fullscreen_view),
 
646
                    G_OBJECT (shell->fullscreen_options), 0);
 
647
 
 
648
  gimp_zoom_model_zoom (shell->zoom, GIMP_ZOOM_TO, scale);
642
649
 
643
650
  /* adjust the initial scale -- so that window fits on screen the 75%
644
651
   * value is the same as in gimp_display_shell_shrink_wrap. It
668
675
      /*  Limit to the size of the screen...  */
669
676
      if (n_width > s_width || n_height > s_height)
670
677
        {
671
 
          new_scale = shell->scale * MIN (((gdouble) s_height) / n_height,
672
 
                                          ((gdouble) s_width) / n_width);
673
 
 
674
 
          new_scale = gimp_display_shell_scale_zoom_step (GIMP_ZOOM_OUT,
675
 
                                                          new_scale);
676
 
 
677
 
          /* since zooming out might skip a zoom step we zoom in again
678
 
           * and test if we are small enough. */
679
 
          shell->scale = gimp_display_shell_scale_zoom_step (GIMP_ZOOM_IN,
680
 
                                                             new_scale);
 
678
          gdouble current = gimp_zoom_model_get_factor (shell->zoom);
 
679
 
 
680
          new_scale = current * MIN (((gdouble) s_height) / n_height,
 
681
                                     ((gdouble) s_width) / n_width);
 
682
 
 
683
          new_scale = gimp_zoom_model_zoom_step (GIMP_ZOOM_OUT, new_scale);
 
684
 
 
685
          /* Since zooming out might skip a zoom step we zoom in again
 
686
           * and test if we are small enough.
 
687
           */
 
688
          gimp_zoom_model_zoom (shell->zoom, GIMP_ZOOM_TO,
 
689
                                gimp_zoom_model_zoom_step (GIMP_ZOOM_IN,
 
690
                                                           new_scale));
681
691
 
682
692
          if (SCALEX (shell, image_width) > s_width ||
683
693
              SCALEY (shell, image_height) > s_height)
684
 
            shell->scale = new_scale;
 
694
            gimp_zoom_model_zoom (shell->zoom, GIMP_ZOOM_TO, new_scale);
685
695
 
686
696
          n_width  = SCALEX (shell, image_width);
687
697
          n_height = SCALEY (shell, image_height);
701
711
 
702
712
  shell->menubar_manager = gimp_menu_factory_manager_new (menu_factory,
703
713
                                                          "<Image>",
704
 
                                                          gdisp,
 
714
                                                          display,
705
715
                                                          FALSE);
706
716
 
707
717
  shell->popup_manager = popup_manager;
709
719
  gtk_window_add_accel_group (GTK_WINDOW (shell),
710
720
                              gtk_ui_manager_get_accel_group (GTK_UI_MANAGER (shell->menubar_manager)));
711
721
 
 
722
  g_signal_connect (shell->menubar_manager, "show-tooltip",
 
723
                    G_CALLBACK (gimp_display_shell_show_tooltip),
 
724
                    shell);
 
725
  g_signal_connect (shell->menubar_manager, "hide-tooltip",
 
726
                    G_CALLBACK (gimp_display_shell_hide_tooltip),
 
727
                    shell);
 
728
 
712
729
  /*  GtkTable widgets are not able to shrink a row/column correctly if
713
730
   *  widgets are attached with GTK_EXPAND even if those widgets have
714
731
   *  other rows/columns in their rowspan/colspan where they could
739
756
   *     |      |
740
757
   *     |      +-- lower_hbox
741
758
   *     |             |
742
 
   *     |             +-- qmask
 
759
   *     |             +-- quick_mask
743
760
   *     |             +-- hscrollbar
744
761
   *     |             +-- navbutton
745
762
   *     |
750
767
 
751
768
  /*  the vbox containing all widgets  */
752
769
 
753
 
  main_vbox = gtk_vbox_new (FALSE, 0);
 
770
  main_vbox = gtk_vbox_new (FALSE, 1);
754
771
  gtk_container_add (GTK_CONTAINER (shell), main_vbox);
755
772
 
756
 
  shell->menubar = gimp_ui_manager_ui_get (shell->menubar_manager,
757
 
                                           "/image-menubar");
 
773
  shell->menubar =
 
774
    gtk_ui_manager_get_widget (GTK_UI_MANAGER (shell->menubar_manager),
 
775
                               "/image-menubar");
758
776
 
759
777
  if (shell->menubar)
760
778
    {
773
791
                        NULL);
774
792
 
775
793
      /*  active display callback  */
776
 
      g_signal_connect (shell->menubar, "button_press_event",
777
 
                        G_CALLBACK (gimp_display_shell_events),
778
 
                        shell);
779
 
      g_signal_connect (shell->menubar, "button_release_event",
780
 
                        G_CALLBACK (gimp_display_shell_events),
781
 
                        shell);
782
 
      g_signal_connect (shell->menubar, "key_press_event",
 
794
      g_signal_connect (shell->menubar, "button-press-event",
 
795
                        G_CALLBACK (gimp_display_shell_events),
 
796
                        shell);
 
797
      g_signal_connect (shell->menubar, "button-release-event",
 
798
                        G_CALLBACK (gimp_display_shell_events),
 
799
                        shell);
 
800
      g_signal_connect (shell->menubar, "key-press-event",
783
801
                        G_CALLBACK (gimp_display_shell_events),
784
802
                        shell);
785
803
    }
786
804
 
787
805
  /*  another vbox for everything except the statusbar  */
788
806
  disp_vbox = gtk_vbox_new (FALSE, 1);
789
 
  gtk_container_set_border_width (GTK_CONTAINER (disp_vbox), 2);
790
807
  gtk_box_pack_start (GTK_BOX (main_vbox), disp_vbox, TRUE, TRUE, 0);
791
808
  gtk_widget_show (disp_vbox);
792
809
 
807
824
  gtk_box_pack_start (GTK_BOX (upper_hbox), right_vbox, FALSE, FALSE, 0);
808
825
  gtk_widget_show (right_vbox);
809
826
 
810
 
  /*  the hbox containing qmask button, vertical scrollbar and nav button  */
 
827
  /*  the hbox containing the quickmask button, vertical scrollbar and
 
828
      the navigation button  */
811
829
  lower_hbox = gtk_hbox_new (FALSE, 1);
812
830
  gtk_box_pack_start (GTK_BOX (disp_vbox), lower_hbox, FALSE, FALSE, 0);
813
831
  gtk_widget_show (lower_hbox);
814
832
 
815
 
 /*  create the scrollbars  *************************************************/
 
833
  /*  create the scrollbars  *************************************************/
816
834
 
817
835
  /*  the horizontal scrollbar  */
818
 
  shell->hsbdata =
819
 
    GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, image_width, 1, 1, image_width));
 
836
  shell->hsbdata = GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, image_width,
 
837
                                                       1, 1, image_width));
820
838
  shell->hsb = gtk_hscrollbar_new (shell->hsbdata);
821
839
  GTK_WIDGET_UNSET_FLAGS (shell->hsb, GTK_CAN_FOCUS);
822
840
 
823
841
  /*  the vertical scrollbar  */
824
 
  shell->vsbdata =
825
 
    GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, image_height, 1, 1, image_height));
 
842
  shell->vsbdata = GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, image_height,
 
843
                                                       1, 1, image_height));
826
844
  shell->vsb = gtk_vscrollbar_new (shell->vsbdata);
827
845
  GTK_WIDGET_UNSET_FLAGS (shell->vsb, GTK_CAN_FOCUS);
828
846
 
829
847
  /*  create the contents of the inner_table  ********************************/
830
848
 
831
849
  /*  the menu popup button  */
832
 
  shell->origin_button = gtk_button_new ();
833
 
  GTK_WIDGET_UNSET_FLAGS (shell->origin_button, GTK_CAN_FOCUS);
 
850
  shell->origin = gtk_event_box_new ();
834
851
 
835
852
  image = gtk_image_new_from_stock (GIMP_STOCK_MENU_RIGHT, GTK_ICON_SIZE_MENU);
836
 
  gtk_container_add (GTK_CONTAINER (shell->origin_button), image);
 
853
  gtk_container_add (GTK_CONTAINER (shell->origin), image);
837
854
  gtk_widget_show (image);
838
855
 
839
 
  g_signal_connect (shell->origin_button, "button_press_event",
 
856
  g_signal_connect (shell->origin, "button-press-event",
840
857
                    G_CALLBACK (gimp_display_shell_origin_button_press),
841
858
                    shell);
842
859
 
843
 
  gimp_help_set_help_data (shell->origin_button, NULL,
844
 
                           GIMP_HELP_IMAGE_WINDOW_ORIGIN_BUTTON);
845
 
 
846
 
  shell->canvas = gimp_canvas_new ();
847
 
 
848
 
  shell->select = gimp_display_shell_selection_new (shell);
 
860
  gimp_help_set_help_data (shell->origin,
 
861
                           _("Access the image menu"),
 
862
                           GIMP_HELP_IMAGE_WINDOW_ORIGIN);
 
863
 
 
864
  shell->canvas = gimp_canvas_new (shell->display->image->gimp);
 
865
 
 
866
  gimp_display_shell_selection_init (shell);
849
867
 
850
868
  /*  the horizontal ruler  */
851
869
  shell->hrule = gtk_hruler_new ();
852
870
  gtk_widget_set_events (GTK_WIDGET (shell->hrule),
853
871
                         GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
854
872
 
855
 
  g_signal_connect_swapped (shell->canvas, "motion_notify_event",
 
873
  g_signal_connect_swapped (shell->canvas, "motion-notify-event",
856
874
                            G_CALLBACK (GTK_WIDGET_GET_CLASS (shell->hrule)->motion_notify_event),
857
875
                            shell->hrule);
858
 
  g_signal_connect (shell->hrule, "button_press_event",
 
876
  g_signal_connect (shell->hrule, "button-press-event",
859
877
                    G_CALLBACK (gimp_display_shell_hruler_button_press),
860
878
                    shell);
861
879
 
866
884
  gtk_widget_set_events (GTK_WIDGET (shell->vrule),
867
885
                         GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
868
886
 
869
 
  g_signal_connect_swapped (shell->canvas, "motion_notify_event",
 
887
  g_signal_connect_swapped (shell->canvas, "motion-notify-event",
870
888
                            G_CALLBACK (GTK_WIDGET_GET_CLASS (shell->vrule)->motion_notify_event),
871
889
                            shell->vrule);
872
 
  g_signal_connect (shell->vrule, "button_press_event",
 
890
  g_signal_connect (shell->vrule, "button-press-event",
873
891
                    G_CALLBACK (gimp_display_shell_vruler_button_press),
874
892
                    shell);
875
893
 
876
894
  gimp_help_set_help_data (shell->vrule, NULL, GIMP_HELP_IMAGE_WINDOW_RULER);
877
895
 
878
 
  /* Workaround for GTK+ Wintab bug on Windows when creating guides by
879
 
   * dragging from the rulers. See bug #168516. */
 
896
  /*  Workaround for GTK+ Wintab bug on Windows when creating guides by
 
897
   *  dragging from the rulers. See bug #168516.
 
898
   */
880
899
  gtk_widget_set_extension_events (shell->hrule, GDK_EXTENSION_EVENTS_ALL);
881
900
  gtk_widget_set_extension_events (shell->vrule, GDK_EXTENSION_EVENTS_ALL);
882
 
  
 
901
 
883
902
  /*  the canvas  */
884
903
  gtk_widget_set_size_request (shell->canvas, n_width, n_height);
885
904
  gtk_widget_set_events (shell->canvas, GIMP_DISPLAY_SHELL_CANVAS_EVENT_MASK);
889
908
  g_signal_connect (shell->canvas, "realize",
890
909
                    G_CALLBACK (gimp_display_shell_canvas_realize),
891
910
                    shell);
892
 
  g_signal_connect (shell->canvas, "size_allocate",
 
911
  g_signal_connect (shell->canvas, "size-allocate",
893
912
                    G_CALLBACK (gimp_display_shell_canvas_size_allocate),
894
913
                    shell);
895
 
  g_signal_connect (shell->canvas, "expose_event",
 
914
  g_signal_connect (shell->canvas, "expose-event",
896
915
                    G_CALLBACK (gimp_display_shell_canvas_expose),
897
916
                    shell);
898
917
 
899
 
  g_signal_connect (shell->canvas, "enter_notify_event",
900
 
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
901
 
                    shell);
902
 
  g_signal_connect (shell->canvas, "leave_notify_event",
903
 
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
904
 
                    shell);
905
 
  g_signal_connect (shell->canvas, "proximity_in_event",
906
 
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
907
 
                    shell);
908
 
  g_signal_connect (shell->canvas, "proximity_out_event",
909
 
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
910
 
                    shell);
911
 
  g_signal_connect (shell->canvas, "focus_in_event",
912
 
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
913
 
                    shell);
914
 
  g_signal_connect (shell->canvas, "focus_out_event",
915
 
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
916
 
                    shell);
917
 
  g_signal_connect (shell->canvas, "button_press_event",
918
 
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
919
 
                    shell);
920
 
  g_signal_connect (shell->canvas, "button_release_event",
921
 
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
922
 
                    shell);
923
 
  g_signal_connect (shell->canvas, "scroll_event",
924
 
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
925
 
                    shell);
926
 
  g_signal_connect (shell->canvas, "motion_notify_event",
927
 
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
928
 
                    shell);
929
 
  g_signal_connect (shell->canvas, "key_press_event",
930
 
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
931
 
                    shell);
932
 
  g_signal_connect (shell->canvas, "key_release_event",
 
918
  g_signal_connect (shell->canvas, "enter-notify-event",
 
919
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
 
920
                    shell);
 
921
  g_signal_connect (shell->canvas, "leave-notify-event",
 
922
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
 
923
                    shell);
 
924
  g_signal_connect (shell->canvas, "proximity-in-event",
 
925
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
 
926
                    shell);
 
927
  g_signal_connect (shell->canvas, "proximity-out-event",
 
928
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
 
929
                    shell);
 
930
  g_signal_connect (shell->canvas, "focus-in-event",
 
931
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
 
932
                    shell);
 
933
  g_signal_connect (shell->canvas, "focus-out-event",
 
934
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
 
935
                    shell);
 
936
  g_signal_connect (shell->canvas, "button-press-event",
 
937
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
 
938
                    shell);
 
939
  g_signal_connect (shell->canvas, "button-release-event",
 
940
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
 
941
                    shell);
 
942
  g_signal_connect (shell->canvas, "scroll-event",
 
943
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
 
944
                    shell);
 
945
  g_signal_connect (shell->canvas, "motion-notify-event",
 
946
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
 
947
                    shell);
 
948
  g_signal_connect (shell->canvas, "key-press-event",
 
949
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
 
950
                    shell);
 
951
  g_signal_connect (shell->canvas, "key-release-event",
933
952
                    G_CALLBACK (gimp_display_shell_canvas_tool_events),
934
953
                    shell);
935
954
 
936
955
  /*  create the contents of the right_vbox  *********************************/
937
 
  shell->zoom_button = gtk_check_button_new ();
938
 
  gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (shell->zoom_button), FALSE);
939
 
  gtk_widget_set_size_request (GTK_WIDGET (shell->zoom_button), 16, 16);
 
956
  shell->zoom_button = g_object_new (GTK_TYPE_CHECK_BUTTON,
 
957
                                     "draw-indicator", FALSE,
 
958
                                     "relief",         GTK_RELIEF_NONE,
 
959
                                     "width-request",  18,
 
960
                                     "height-request", 18,
 
961
                                     NULL);
940
962
  GTK_WIDGET_UNSET_FLAGS (shell->zoom_button, GTK_CAN_FOCUS);
941
963
 
942
964
  image = gtk_image_new_from_stock (GIMP_STOCK_ZOOM_FOLLOW_WINDOW,
954
976
 
955
977
  /*  create the contents of the lower_hbox  *********************************/
956
978
 
957
 
  /*  the qmask button  */
958
 
  shell->qmask_button = gtk_check_button_new ();
959
 
  gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (shell->qmask_button), FALSE);
960
 
  gtk_widget_set_size_request (GTK_WIDGET (shell->qmask_button), 16, 16);
961
 
  GTK_WIDGET_UNSET_FLAGS (shell->qmask_button, GTK_CAN_FOCUS);
 
979
  /*  the quick mask button  */
 
980
  shell->quick_mask_button = g_object_new (GTK_TYPE_CHECK_BUTTON,
 
981
                                           "draw-indicator", FALSE,
 
982
                                           "relief",         GTK_RELIEF_NONE,
 
983
                                           "width-request",  18,
 
984
                                           "height-request", 18,
 
985
                                           NULL);
 
986
  GTK_WIDGET_UNSET_FLAGS (shell->quick_mask_button, GTK_CAN_FOCUS);
962
987
 
963
 
  image = gtk_image_new_from_stock (GIMP_STOCK_QMASK_OFF, GTK_ICON_SIZE_MENU);
964
 
  gtk_container_add (GTK_CONTAINER (shell->qmask_button), image);
 
988
  image = gtk_image_new_from_stock (GIMP_STOCK_QUICK_MASK_OFF,
 
989
                                    GTK_ICON_SIZE_MENU);
 
990
  gtk_container_add (GTK_CONTAINER (shell->quick_mask_button), image);
965
991
  gtk_widget_show (image);
966
992
 
967
 
  gimp_help_set_help_data (shell->qmask_button,
968
 
                           _("Toggle Quick Mask"),
969
 
                           GIMP_HELP_IMAGE_WINDOW_QMASK_BUTTON);
 
993
  action = gimp_ui_manager_find_action (shell->menubar_manager,
 
994
                                        "quick-mask", "quick-mask-toggle");
 
995
  if (action)
 
996
    gimp_widget_set_accel_help (shell->quick_mask_button, action);
 
997
  else
 
998
    gimp_help_set_help_data (shell->quick_mask_button,
 
999
                             _("Toggle Quick Mask"),
 
1000
                             GIMP_HELP_IMAGE_WINDOW_QUICK_MASK_BUTTON);
970
1001
 
971
 
  g_signal_connect (shell->qmask_button, "toggled",
972
 
                    G_CALLBACK (gimp_display_shell_qmask_toggled),
 
1002
  g_signal_connect (shell->quick_mask_button, "toggled",
 
1003
                    G_CALLBACK (gimp_display_shell_quick_mask_toggled),
973
1004
                    shell);
974
 
  g_signal_connect (shell->qmask_button, "button_press_event",
975
 
                    G_CALLBACK (gimp_display_shell_qmask_button_press),
 
1005
  g_signal_connect (shell->quick_mask_button, "button-press-event",
 
1006
                    G_CALLBACK (gimp_display_shell_quick_mask_button_press),
976
1007
                    shell);
977
1008
 
978
1009
  /*  the navigation window button  */
979
1010
  shell->nav_ebox = gtk_event_box_new ();
980
 
 
981
1011
  image = gtk_image_new_from_stock (GIMP_STOCK_NAVIGATION, GTK_ICON_SIZE_MENU);
982
1012
  gtk_container_add (GTK_CONTAINER (shell->nav_ebox), image);
983
1013
  gtk_widget_show (image);
984
1014
 
985
 
  g_signal_connect (shell->nav_ebox, "button_press_event",
 
1015
  g_signal_connect (shell->nav_ebox, "button-press-event",
986
1016
                    G_CALLBACK (gimp_display_shell_nav_button_press),
987
1017
                    shell);
988
1018
 
989
 
  gimp_help_set_help_data (shell->nav_ebox, NULL,
 
1019
  gimp_help_set_help_data (shell->nav_ebox,
 
1020
                           _("Navigate the image display"),
990
1021
                           GIMP_HELP_IMAGE_WINDOW_NAV_BUTTON);
991
1022
 
992
1023
  /*  create the contents of the status area *********************************/
999
1030
  /*  pack all the widgets  **************************************************/
1000
1031
 
1001
1032
  /*  fill the inner_table  */
1002
 
  gtk_table_attach (GTK_TABLE (inner_table), shell->origin_button, 0, 1, 0, 1,
 
1033
  gtk_table_attach (GTK_TABLE (inner_table), shell->origin, 0, 1, 0, 1,
1003
1034
                    GTK_FILL, GTK_FILL, 0, 0);
1004
1035
  gtk_table_attach (GTK_TABLE (inner_table), shell->hrule, 1, 2, 0, 1,
1005
1036
                    GTK_EXPAND | GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
1014
1045
  gtk_box_pack_start (GTK_BOX (right_vbox), shell->vsb, TRUE, TRUE, 0);
1015
1046
 
1016
1047
  /*  fill the lower_hbox  */
1017
 
  gtk_box_pack_start (GTK_BOX (lower_hbox), shell->qmask_button, FALSE, FALSE, 0);
 
1048
  gtk_box_pack_start (GTK_BOX (lower_hbox), shell->quick_mask_button, FALSE, FALSE, 0);
1018
1049
  gtk_box_pack_start (GTK_BOX (lower_hbox), shell->hsb, TRUE, TRUE, 0);
1019
1050
  gtk_box_pack_start (GTK_BOX (lower_hbox), shell->nav_ebox, FALSE, FALSE, 0);
1020
1051
 
1024
1055
 
1025
1056
  if (shell->options->show_rulers)
1026
1057
    {
1027
 
      gtk_widget_show (shell->origin_button);
 
1058
      gtk_widget_show (shell->origin);
1028
1059
      gtk_widget_show (shell->hrule);
1029
1060
      gtk_widget_show (shell->vrule);
1030
1061
    }
1036
1067
      gtk_widget_show (shell->vsb);
1037
1068
      gtk_widget_show (shell->hsb);
1038
1069
      gtk_widget_show (shell->zoom_button);
1039
 
      gtk_widget_show (shell->qmask_button);
 
1070
      gtk_widget_show (shell->quick_mask_button);
1040
1071
      gtk_widget_show (shell->nav_ebox);
1041
1072
    }
1042
1073
 
1045
1076
 
1046
1077
  gtk_widget_show (main_vbox);
1047
1078
 
 
1079
  color_config = display->image->gimp->config->color_management;
 
1080
  gimp_display_shell_filter_set (shell,
 
1081
                                 gimp_display_shell_filter_new (color_config));
 
1082
 
1048
1083
  gimp_display_shell_connect (shell);
1049
1084
 
1050
1085
  gimp_display_shell_title_init (shell);
1056
1091
gimp_display_shell_reconnect (GimpDisplayShell *shell)
1057
1092
{
1058
1093
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
1059
 
  g_return_if_fail (GIMP_IS_DISPLAY (shell->gdisp));
1060
 
  g_return_if_fail (GIMP_IS_IMAGE (shell->gdisp->gimage));
 
1094
  g_return_if_fail (GIMP_IS_DISPLAY (shell->display));
 
1095
  g_return_if_fail (GIMP_IS_IMAGE (shell->display->image));
1061
1096
 
1062
1097
  gimp_display_shell_connect (shell);
1063
1098
 
1068
1103
  gimp_display_shell_scaled (shell);
1069
1104
}
1070
1105
 
 
1106
/*
 
1107
 * We used to calculate the scale factor in the SCALEFACTOR_X() and
 
1108
 * SCALEFACTOR_Y() macros. But since these are rather frequently
 
1109
 * called and the values rarely change, we now store them in the
 
1110
 * shell and call this function whenever they need to be recalculated.
 
1111
 */
 
1112
void
 
1113
gimp_display_shell_scale_changed (GimpDisplayShell *shell)
 
1114
{
 
1115
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
1116
 
 
1117
  shell->scale_x = (gimp_zoom_model_get_factor (shell->zoom)
 
1118
                    * SCREEN_XRES (shell)
 
1119
                    / shell->display->image->xresolution);
 
1120
 
 
1121
  shell->scale_y = (gimp_zoom_model_get_factor (shell->zoom)
 
1122
                    * SCREEN_YRES (shell)
 
1123
                    / shell->display->image->yresolution);
 
1124
}
 
1125
 
1071
1126
void
1072
1127
gimp_display_shell_scaled (GimpDisplayShell *shell)
1073
1128
{
1101
1156
    }
1102
1157
}
1103
1158
 
 
1159
GimpUnit
 
1160
gimp_display_shell_get_unit (GimpDisplayShell *shell)
 
1161
{
 
1162
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), GIMP_UNIT_PIXEL);
 
1163
 
 
1164
  return shell->unit;
 
1165
}
 
1166
 
1104
1167
gboolean
1105
1168
gimp_display_shell_snap_coords (GimpDisplayShell *shell,
1106
1169
                                GimpCoords       *coords,
1110
1173
                                gint              snap_width,
1111
1174
                                gint              snap_height)
1112
1175
{
1113
 
  gboolean snap_to_guides = FALSE;
1114
 
  gboolean snap_to_grid   = FALSE;
1115
 
  gboolean snapped        = FALSE;
 
1176
  gboolean snap_to_guides  = FALSE;
 
1177
  gboolean snap_to_grid    = FALSE;
 
1178
  gboolean snap_to_canvas  = FALSE;
 
1179
  gboolean snap_to_vectors = FALSE;
 
1180
  gboolean snapped         = FALSE;
1116
1181
 
1117
1182
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
1118
1183
  g_return_val_if_fail (coords != NULL, FALSE);
1120
1185
 
1121
1186
  *snapped_coords = *coords;
1122
1187
 
1123
 
  if (shell->snap_to_guides &&
1124
 
      shell->gdisp->gimage->guides)
 
1188
  if (gimp_display_shell_get_snap_to_guides (shell) &&
 
1189
      shell->display->image->guides)
1125
1190
    {
1126
1191
      snap_to_guides = TRUE;
1127
1192
    }
1128
1193
 
1129
1194
  if (gimp_display_shell_get_snap_to_grid (shell) &&
1130
 
      shell->gdisp->gimage->grid)
 
1195
      shell->display->image->grid)
1131
1196
    {
1132
1197
      snap_to_grid = TRUE;
1133
1198
    }
1134
1199
 
1135
 
  if (snap_to_guides || snap_to_grid)
 
1200
  snap_to_canvas = gimp_display_shell_get_snap_to_canvas (shell);
 
1201
 
 
1202
  if (gimp_display_shell_get_snap_to_vectors (shell) &&
 
1203
      gimp_image_get_active_vectors (shell->display->image))
 
1204
    {
 
1205
      snap_to_vectors = TRUE;
 
1206
    }
 
1207
 
 
1208
  if (snap_to_guides || snap_to_grid || snap_to_canvas || snap_to_vectors)
1136
1209
    {
1137
1210
      gdouble tx, ty;
1138
1211
      gint    snap_distance;
1139
1212
 
1140
1213
      snap_distance =
1141
 
        GIMP_DISPLAY_CONFIG (shell->gdisp->gimage->gimp->config)->snap_distance;
 
1214
        GIMP_DISPLAY_CONFIG (shell->display->image->gimp->config)->snap_distance;
1142
1215
 
1143
1216
      if (snap_width > 0 && snap_height > 0)
1144
1217
        {
1145
 
          snapped = gimp_image_snap_rectangle (shell->gdisp->gimage,
 
1218
          snapped = gimp_image_snap_rectangle (shell->display->image,
1146
1219
                                               coords->x + snap_offset_x,
1147
1220
                                               coords->y + snap_offset_y,
1148
1221
                                               coords->x + snap_offset_x +
1154
1227
                                               FUNSCALEX (shell, snap_distance),
1155
1228
                                               FUNSCALEY (shell, snap_distance),
1156
1229
                                               snap_to_guides,
1157
 
                                               snap_to_grid);
 
1230
                                               snap_to_grid,
 
1231
                                               snap_to_canvas,
 
1232
                                               snap_to_vectors);
1158
1233
        }
1159
1234
      else
1160
1235
        {
1161
 
          snapped = gimp_image_snap_point (shell->gdisp->gimage,
 
1236
          snapped = gimp_image_snap_point (shell->display->image,
1162
1237
                                           coords->x + snap_offset_x,
1163
1238
                                           coords->y + snap_offset_y,
1164
1239
                                           &tx,
1166
1241
                                           FUNSCALEX (shell, snap_distance),
1167
1242
                                           FUNSCALEY (shell, snap_distance),
1168
1243
                                           snap_to_guides,
1169
 
                                           snap_to_grid);
 
1244
                                           snap_to_grid,
 
1245
                                           snap_to_canvas,
 
1246
                                           snap_to_vectors);
1170
1247
        }
1171
1248
 
1172
1249
      if (snapped)
1187
1264
                                gint             *y2)
1188
1265
{
1189
1266
  GimpLayer *layer;
1190
 
  gint       off_x;
1191
 
  gint       off_y;
1192
1267
 
1193
1268
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
1194
1269
  g_return_val_if_fail (x1 != NULL, FALSE);
1197
1272
  g_return_val_if_fail (y2 != NULL, FALSE);
1198
1273
 
1199
1274
  /*  If there is a floating selection, handle things differently  */
1200
 
  if ((layer = gimp_image_floating_sel (shell->gdisp->gimage)))
 
1275
  if ((layer = gimp_image_floating_sel (shell->display->image)))
1201
1276
    {
 
1277
      gint off_x;
 
1278
      gint off_y;
 
1279
 
1202
1280
      gimp_item_offsets (GIMP_ITEM (layer), &off_x, &off_y);
1203
1281
 
1204
 
      if (! gimp_channel_bounds (gimp_image_get_mask (shell->gdisp->gimage),
 
1282
      if (! gimp_channel_bounds (gimp_image_get_mask (shell->display->image),
1205
1283
                                 x1, y1, x2, y2))
1206
1284
        {
1207
1285
          *x1 = off_x;
1217
1295
          *y2 = MAX (off_y + gimp_item_height (GIMP_ITEM (layer)), *y2);
1218
1296
        }
1219
1297
    }
1220
 
  else if (! gimp_channel_bounds (gimp_image_get_mask (shell->gdisp->gimage),
 
1298
  else if (! gimp_channel_bounds (gimp_image_get_mask (shell->display->image),
1221
1299
                                  x1, y1, x2, y2))
1222
1300
    {
1223
1301
      return FALSE;
1251
1329
gimp_display_shell_expose_guide (GimpDisplayShell *shell,
1252
1330
                                 GimpGuide        *guide)
1253
1331
{
1254
 
  gint x;
1255
 
  gint y;
 
1332
  gint position;
 
1333
  gint x, y;
1256
1334
 
1257
1335
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
1258
 
  g_return_if_fail (guide != NULL);
1259
 
 
1260
 
  if (guide->position < 0)
 
1336
  g_return_if_fail (GIMP_IS_GUIDE (guide));
 
1337
 
 
1338
  position = gimp_guide_get_position (guide);
 
1339
 
 
1340
  if (position < 0)
1261
1341
    return;
1262
1342
 
1263
1343
  gimp_display_shell_transform_xy (shell,
1264
 
                                   guide->position,
1265
 
                                   guide->position,
 
1344
                                   position, position,
1266
1345
                                   &x, &y,
1267
1346
                                   FALSE);
1268
1347
 
1269
 
  switch (guide->orientation)
 
1348
  switch (gimp_guide_get_orientation (guide))
1270
1349
    {
1271
1350
    case GIMP_ORIENTATION_HORIZONTAL:
1272
1351
      gimp_display_shell_expose_area (shell, 0, y, shell->disp_width, 1);
1282
1361
}
1283
1362
 
1284
1363
void
 
1364
gimp_display_shell_expose_sample_point (GimpDisplayShell *shell,
 
1365
                                        GimpSamplePoint  *sample_point)
 
1366
{
 
1367
  gdouble x, y;
 
1368
  gint    x1, y1, x2, y2;
 
1369
 
 
1370
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
1371
  g_return_if_fail (sample_point != NULL);
 
1372
 
 
1373
  if (sample_point->x < 0)
 
1374
    return;
 
1375
 
 
1376
  gimp_display_shell_transform_xy_f (shell,
 
1377
                                     sample_point->x + 0.5,
 
1378
                                     sample_point->y + 0.5,
 
1379
                                     &x, &y,
 
1380
                                     FALSE);
 
1381
 
 
1382
  x1 = MAX (0, floor (x - GIMP_SAMPLE_POINT_DRAW_SIZE));
 
1383
  y1 = MAX (0, floor (y - GIMP_SAMPLE_POINT_DRAW_SIZE));
 
1384
  x2 = MIN (shell->disp_width,  ceil (x + GIMP_SAMPLE_POINT_DRAW_SIZE));
 
1385
  y2 = MIN (shell->disp_height, ceil (y + GIMP_SAMPLE_POINT_DRAW_SIZE));
 
1386
 
 
1387
  /* HACK: add 3 instead of 1 so the number gets cleared too */
 
1388
  gimp_display_shell_expose_area (shell, x1, y1, x2 - x1 + 3, y2 - y1 + 3);
 
1389
}
 
1390
 
 
1391
void
1285
1392
gimp_display_shell_expose_full (GimpDisplayShell *shell)
1286
1393
{
1287
1394
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
1295
1402
{
1296
1403
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
1297
1404
 
1298
 
  if (! shell->select)
1299
 
    {
1300
 
      g_warning ("%s: called unrealized", G_STRFUNC);
1301
 
      return;
1302
 
    }
1303
 
 
1304
1405
  gimp_display_shell_title_update (shell);
1305
1406
 
1306
1407
  if (now)
1311
1412
    {
1312
1413
      GimpContext *user_context;
1313
1414
 
1314
 
      gimp_ui_manager_update (shell->menubar_manager, shell->gdisp);
1315
 
 
1316
 
      user_context = gimp_get_user_context (shell->gdisp->gimage->gimp);
1317
 
 
1318
 
      if (shell->gdisp == gimp_context_get_display (user_context))
1319
 
        gimp_ui_manager_update (shell->popup_manager, shell->gdisp);
 
1415
      gimp_ui_manager_update (shell->menubar_manager, shell->display);
 
1416
 
 
1417
      user_context = gimp_get_user_context (shell->display->image->gimp);
 
1418
 
 
1419
      if (shell->display == gimp_context_get_display (user_context))
 
1420
        gimp_ui_manager_update (shell->popup_manager, shell->display);
1320
1421
    }
1321
1422
}
1322
1423
 
1341
1442
  if (shell->paused_count == 1)
1342
1443
    {
1343
1444
      /*  pause the currently active tool  */
1344
 
      tool_manager_control_active (shell->gdisp->gimage->gimp, PAUSE,
1345
 
                                   shell->gdisp);
 
1445
      tool_manager_control_active (shell->display->image->gimp,
 
1446
                                   GIMP_TOOL_ACTION_PAUSE,
 
1447
                                   shell->display);
1346
1448
 
1347
1449
      gimp_display_shell_draw_vectors (shell);
1348
1450
    }
1370
1472
      gimp_display_shell_draw_vectors (shell);
1371
1473
 
1372
1474
      /* start the currently active tool */
1373
 
      tool_manager_control_active (shell->gdisp->gimage->gimp, RESUME,
1374
 
                                   shell->gdisp);
 
1475
      tool_manager_control_active (shell->display->image->gimp,
 
1476
                                   GIMP_TOOL_ACTION_RESUME,
 
1477
                                   shell->display);
1375
1478
    }
1376
1479
}
1377
1480
 
1378
1481
void
1379
1482
gimp_display_shell_update_icon (GimpDisplayShell *shell)
1380
1483
{
 
1484
  GimpImage *image;
1381
1485
  GdkPixbuf *pixbuf;
1382
1486
  gint       width, height;
1383
1487
  gdouble    factor;
1384
1488
 
1385
1489
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
1386
1490
 
1387
 
  factor = ((gdouble) gimp_image_get_height (shell->gdisp->gimage) /
1388
 
            (gdouble) gimp_image_get_width (shell->gdisp->gimage));
 
1491
  image = shell->display->image;
 
1492
 
 
1493
  factor = ((gdouble) gimp_image_get_height (image) /
 
1494
            (gdouble) gimp_image_get_width  (image));
1389
1495
 
1390
1496
  if (factor >= 1)
1391
1497
    {
1398
1504
      width  = MAX (shell->icon_size, 1);
1399
1505
    }
1400
1506
 
1401
 
  pixbuf = gimp_viewable_get_pixbuf (GIMP_VIEWABLE (shell->gdisp->gimage),
 
1507
  pixbuf = gimp_viewable_get_pixbuf (GIMP_VIEWABLE (image),
 
1508
                                     gimp_get_user_context (image->gimp),
1402
1509
                                     width, height);
1403
1510
 
1404
1511
  gtk_window_set_icon (GTK_WINDOW (shell), pixbuf);
1417
1524
  gint          border_x, border_y;
1418
1525
  gboolean      resize = FALSE;
1419
1526
 
1420
 
  g_return_if_fail (GTK_WIDGET_REALIZED (shell));
 
1527
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
1528
 
 
1529
  if (! GTK_WIDGET_REALIZED (shell))
 
1530
    return;
1421
1531
 
1422
1532
  widget = GTK_WIDGET (shell);
1423
1533
  screen = gtk_widget_get_screen (widget);
1425
1535
  monitor = gdk_screen_get_monitor_at_window (screen, widget->window);
1426
1536
  gdk_screen_get_monitor_geometry (screen, monitor, &rect);
1427
1537
 
1428
 
  width  = SCALEX (shell, shell->gdisp->gimage->width);
1429
 
  height = SCALEY (shell, shell->gdisp->gimage->height);
 
1538
  width  = SCALEX (shell, shell->display->image->width);
 
1539
  height = SCALEY (shell, shell->display->image->height);
1430
1540
 
1431
1541
  disp_width  = shell->disp_width;
1432
1542
  disp_height = shell->disp_height;
1472
1582
    }
1473
1583
}
1474
1584
 
1475
 
void
1476
 
gimp_display_shell_selection_visibility (GimpDisplayShell     *shell,
1477
 
                                         GimpSelectionControl  control)
1478
 
{
1479
 
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
1480
 
 
1481
 
  if (shell->select)
1482
 
    {
1483
 
      switch (control)
1484
 
        {
1485
 
        case GIMP_SELECTION_OFF:
1486
 
          gimp_display_shell_selection_invis (shell->select);
1487
 
          break;
1488
 
        case GIMP_SELECTION_LAYER_OFF:
1489
 
          gimp_display_shell_selection_layer_invis (shell->select);
1490
 
          break;
1491
 
        case GIMP_SELECTION_ON:
1492
 
          gimp_display_shell_selection_start (shell->select, TRUE);
1493
 
          break;
1494
 
        case GIMP_SELECTION_PAUSE:
1495
 
          gimp_display_shell_selection_pause (shell->select);
1496
 
          break;
1497
 
        case GIMP_SELECTION_RESUME:
1498
 
          gimp_display_shell_selection_resume (shell->select);
1499
 
          break;
1500
 
        }
1501
 
    }
1502
 
}
1503
 
 
1504
1585
/**
1505
1586
 * gimp_display_shell_set_highlight:
1506
1587
 * @shell:     a #GimpDisplayShell
1542
1623
          gdk_region_destroy (new);
1543
1624
 
1544
1625
          for (i = 0; i < num_rects; i++)
1545
 
            gimp_display_update_area (shell->gdisp, TRUE,
 
1626
            gimp_display_update_area (shell->display, TRUE,
1546
1627
                                      rects[i].x,
1547
1628
                                      rects[i].y,
1548
1629
                                      rects[i].width,
1564
1645
      gimp_display_shell_expose_full (shell);
1565
1646
    }
1566
1647
}
 
1648
 
 
1649
/**
 
1650
 * gimp_display_shell_set_mask:
 
1651
 * @shell: a #GimpDisplayShell
 
1652
 * @mask:  a #GimpDrawable (1 byte per pixel)
 
1653
 * @color: the color to use for drawing the mask
 
1654
 *
 
1655
 * Allows to preview a selection (used by the foreground selection
 
1656
 * tool).  Pixels that are not selected (> 127) in the mask are tinted
 
1657
 * with dark blue.
 
1658
 **/
 
1659
void
 
1660
gimp_display_shell_set_mask (GimpDisplayShell *shell,
 
1661
                             GimpDrawable     *mask,
 
1662
                             GimpChannelType   color)
 
1663
{
 
1664
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
1665
  g_return_if_fail (mask == NULL ||
 
1666
                    (GIMP_IS_DRAWABLE (mask) &&
 
1667
                     gimp_drawable_bytes (mask) == 1));
 
1668
 
 
1669
  if (shell->mask == mask && shell->mask_color == color)
 
1670
    return;
 
1671
 
 
1672
  if (mask)
 
1673
    g_object_ref (mask);
 
1674
 
 
1675
  if (shell->mask)
 
1676
    g_object_unref (shell->mask);
 
1677
 
 
1678
  shell->mask = mask;
 
1679
  shell->mask_color = color;
 
1680
 
 
1681
  gimp_display_shell_expose_full (shell);
 
1682
}