~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to app/display/gimpdisplayshell-appearance.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The GIMP -- an image manipulation program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 */
 
18
 
 
19
#include "config.h"
 
20
 
 
21
#include <gtk/gtk.h>
 
22
 
 
23
#include "libgimpcolor/gimpcolor.h"
 
24
#include "libgimpwidgets/gimpwidgets.h"
 
25
 
 
26
#include "display-types.h"
 
27
 
 
28
#include "core/gimp.h"
 
29
#include "core/gimpcontext.h"
 
30
#include "core/gimpimage.h"
 
31
 
 
32
#include "widgets/gimpactiongroup.h"
 
33
#include "widgets/gimpuimanager.h"
 
34
#include "widgets/gimpwidgets-utils.h"
 
35
 
 
36
#include "gimpcanvas.h"
 
37
#include "gimpdisplay.h"
 
38
#include "gimpdisplayoptions.h"
 
39
#include "gimpdisplayshell.h"
 
40
#include "gimpdisplayshell-appearance.h"
 
41
#include "gimpdisplayshell-callbacks.h"
 
42
#include "gimpdisplayshell-selection.h"
 
43
#include "gimpdisplayshell-render.h"
 
44
 
 
45
 
 
46
#define GET_OPTIONS(shell) \
 
47
  (gimp_display_shell_get_fullscreen (shell) ? \
 
48
   shell->fullscreen_options : shell->options)
 
49
 
 
50
#define SET_ACTIVE(manager,action_name,active) \
 
51
  { GimpActionGroup *group = \
 
52
      gimp_ui_manager_get_action_group (manager, "view"); \
 
53
    gimp_action_group_set_action_active (group, action_name, active); }
 
54
 
 
55
#define SET_COLOR(manager,action_name,color) \
 
56
  { GimpActionGroup *group = \
 
57
      gimp_ui_manager_get_action_group (manager, "view"); \
 
58
    gimp_action_group_set_action_color (group, action_name, color, FALSE); }
 
59
 
 
60
#define IS_ACTIVE_DISPLAY(shell) \
 
61
  ((shell)->gdisp == \
 
62
   gimp_context_get_display (gimp_get_user_context \
 
63
                             ((shell)->gdisp->gimage->gimp)))
 
64
 
 
65
 
 
66
void
 
67
gimp_display_shell_set_fullscreen (GimpDisplayShell *shell,
 
68
                                   gboolean          fullscreen)
 
69
{
 
70
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
71
 
 
72
  if (fullscreen != gimp_display_shell_get_fullscreen (shell))
 
73
    {
 
74
      if (fullscreen)
 
75
        gtk_window_fullscreen (GTK_WINDOW (shell));
 
76
      else
 
77
        gtk_window_unfullscreen (GTK_WINDOW (shell));
 
78
    }
 
79
}
 
80
 
 
81
gboolean
 
82
gimp_display_shell_get_fullscreen (GimpDisplayShell *shell)
 
83
{
 
84
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
 
85
 
 
86
  return (shell->window_state & GDK_WINDOW_STATE_FULLSCREEN) != 0;
 
87
}
 
88
 
 
89
void
 
90
gimp_display_shell_set_show_menubar (GimpDisplayShell *shell,
 
91
                                     gboolean          show)
 
92
{
 
93
  GimpDisplayOptions *options;
 
94
  GtkContainer       *vbox;
 
95
 
 
96
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
97
 
 
98
  options = GET_OPTIONS (shell);
 
99
 
 
100
  g_object_set (options, "show-menubar", show, NULL);
 
101
 
 
102
  vbox = GTK_CONTAINER (shell->qmask_button->parent->parent);
 
103
 
 
104
  if (shell->menubar)
 
105
    {
 
106
      if (show)
 
107
        gtk_widget_show (shell->menubar);
 
108
      else
 
109
        gtk_widget_hide (shell->menubar);
 
110
    }
 
111
 
 
112
  if (options->show_menubar || options->show_statusbar)
 
113
    gtk_container_set_border_width (vbox, 2);
 
114
  else
 
115
    gtk_container_set_border_width (vbox, 0);
 
116
 
 
117
  SET_ACTIVE (shell->menubar_manager, "view-show-menubar", show);
 
118
 
 
119
  if (IS_ACTIVE_DISPLAY (shell))
 
120
    SET_ACTIVE (shell->popup_manager, "view-show-menubar", show);
 
121
}
 
122
 
 
123
gboolean
 
124
gimp_display_shell_get_show_menubar (GimpDisplayShell *shell)
 
125
{
 
126
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
 
127
 
 
128
  return GET_OPTIONS (shell)->show_menubar;
 
129
}
 
130
 
 
131
void
 
132
gimp_display_shell_set_show_rulers (GimpDisplayShell *shell,
 
133
                                    gboolean          show)
 
134
{
 
135
  GimpDisplayOptions *options;
 
136
  GtkTable           *table;
 
137
 
 
138
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
139
 
 
140
  options = GET_OPTIONS (shell);
 
141
 
 
142
  g_object_set (options, "show-rulers", show, NULL);
 
143
 
 
144
  table = GTK_TABLE (GTK_WIDGET (shell->canvas)->parent);
 
145
 
 
146
  if (show)
 
147
    {
 
148
      gtk_widget_show (shell->origin_button);
 
149
      gtk_widget_show (shell->hrule);
 
150
      gtk_widget_show (shell->vrule);
 
151
 
 
152
      gtk_table_set_col_spacing (table, 0, 1);
 
153
      gtk_table_set_row_spacing (table, 0, 1);
 
154
    }
 
155
  else
 
156
    {
 
157
      gtk_widget_hide (shell->origin_button);
 
158
      gtk_widget_hide (shell->hrule);
 
159
      gtk_widget_hide (shell->vrule);
 
160
 
 
161
      gtk_table_set_col_spacing (table, 0, 0);
 
162
      gtk_table_set_row_spacing (table, 0, 0);
 
163
    }
 
164
 
 
165
  SET_ACTIVE (shell->menubar_manager, "view-show-rulers", show);
 
166
 
 
167
  if (IS_ACTIVE_DISPLAY (shell))
 
168
    SET_ACTIVE (shell->popup_manager, "view-show-rulers", show);
 
169
}
 
170
 
 
171
gboolean
 
172
gimp_display_shell_get_show_rulers (GimpDisplayShell *shell)
 
173
{
 
174
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
 
175
 
 
176
  return GET_OPTIONS (shell)->show_rulers;
 
177
}
 
178
 
 
179
void
 
180
gimp_display_shell_set_show_scrollbars (GimpDisplayShell *shell,
 
181
                                        gboolean          show)
 
182
{
 
183
  GimpDisplayOptions *options;
 
184
  GtkBox             *hbox;
 
185
  GtkBox             *vbox;
 
186
 
 
187
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
188
 
 
189
  options = GET_OPTIONS (shell);
 
190
 
 
191
  g_object_set (options, "show-scrollbars", show, NULL);
 
192
 
 
193
  hbox = GTK_BOX (shell->vsb->parent->parent);
 
194
  vbox = GTK_BOX (shell->hsb->parent->parent);
 
195
 
 
196
  if (show)
 
197
    {
 
198
      gtk_widget_show (shell->nav_ebox);
 
199
      gtk_widget_show (shell->hsb);
 
200
      gtk_widget_show (shell->vsb);
 
201
      gtk_widget_show (shell->qmask_button);
 
202
      gtk_widget_show (shell->zoom_button);
 
203
 
 
204
      gtk_box_set_spacing (hbox, 1);
 
205
      gtk_box_set_spacing (vbox, 1);
 
206
    }
 
207
  else
 
208
    {
 
209
      gtk_widget_hide (shell->nav_ebox);
 
210
      gtk_widget_hide (shell->hsb);
 
211
      gtk_widget_hide (shell->vsb);
 
212
      gtk_widget_hide (shell->qmask_button);
 
213
      gtk_widget_hide (shell->zoom_button);
 
214
 
 
215
      gtk_box_set_spacing (hbox, 0);
 
216
      gtk_box_set_spacing (vbox, 0);
 
217
    }
 
218
 
 
219
  SET_ACTIVE (shell->menubar_manager, "view-show-scrollbars", show);
 
220
 
 
221
  if (IS_ACTIVE_DISPLAY (shell))
 
222
    SET_ACTIVE (shell->popup_manager, "view-show-scrollbars", show);
 
223
}
 
224
 
 
225
gboolean
 
226
gimp_display_shell_get_show_scrollbars (GimpDisplayShell *shell)
 
227
{
 
228
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
 
229
 
 
230
  return GET_OPTIONS (shell)->show_scrollbars;
 
231
}
 
232
 
 
233
void
 
234
gimp_display_shell_set_show_statusbar (GimpDisplayShell *shell,
 
235
                                       gboolean          show)
 
236
{
 
237
  GimpDisplayOptions *options;
 
238
  GtkContainer       *vbox;
 
239
 
 
240
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
241
 
 
242
  options = GET_OPTIONS (shell);
 
243
 
 
244
  g_object_set (options, "show-statusbar", show, NULL);
 
245
 
 
246
  vbox = GTK_CONTAINER (shell->qmask_button->parent->parent);
 
247
 
 
248
  if (show)
 
249
    gtk_widget_show (shell->statusbar);
 
250
  else
 
251
    gtk_widget_hide (shell->statusbar);
 
252
 
 
253
  if (options->show_menubar || options->show_statusbar)
 
254
    gtk_container_set_border_width (vbox, 2);
 
255
  else
 
256
    gtk_container_set_border_width (vbox, 0);
 
257
 
 
258
  SET_ACTIVE (shell->menubar_manager, "view-show-statusbar", show);
 
259
 
 
260
  if (IS_ACTIVE_DISPLAY (shell))
 
261
    SET_ACTIVE (shell->popup_manager, "view-show-statusbar", show);
 
262
}
 
263
 
 
264
gboolean
 
265
gimp_display_shell_get_show_statusbar (GimpDisplayShell *shell)
 
266
{
 
267
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
 
268
 
 
269
  return GET_OPTIONS (shell)->show_statusbar;
 
270
}
 
271
 
 
272
void
 
273
gimp_display_shell_set_show_selection (GimpDisplayShell *shell,
 
274
                                       gboolean          show)
 
275
{
 
276
  GimpDisplayOptions *options;
 
277
 
 
278
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
279
 
 
280
  options = GET_OPTIONS (shell);
 
281
 
 
282
  g_object_set (options, "show-selection", show, NULL);
 
283
 
 
284
  if (shell->select)
 
285
    gimp_display_shell_selection_set_hidden (shell->select, ! show);
 
286
 
 
287
  SET_ACTIVE (shell->menubar_manager, "view-show-selection", show);
 
288
 
 
289
  if (IS_ACTIVE_DISPLAY (shell))
 
290
    SET_ACTIVE (shell->popup_manager, "view-show-selection", show);
 
291
}
 
292
 
 
293
gboolean
 
294
gimp_display_shell_get_show_selection (GimpDisplayShell *shell)
 
295
{
 
296
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
 
297
 
 
298
  return GET_OPTIONS (shell)->show_selection;
 
299
}
 
300
 
 
301
void
 
302
gimp_display_shell_set_show_layer (GimpDisplayShell *shell,
 
303
                                   gboolean          show)
 
304
{
 
305
  GimpDisplayOptions *options;
 
306
 
 
307
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
308
 
 
309
  options = GET_OPTIONS (shell);
 
310
 
 
311
  g_object_set (options, "show-layer-boundary", show, NULL);
 
312
 
 
313
  if (shell->select)
 
314
    gimp_display_shell_selection_layer_set_hidden (shell->select, ! show);
 
315
 
 
316
  SET_ACTIVE (shell->menubar_manager, "view-show-layer-boundary", show);
 
317
 
 
318
  if (IS_ACTIVE_DISPLAY (shell))
 
319
    SET_ACTIVE (shell->popup_manager, "view-show-layer-boundary", show);
 
320
}
 
321
 
 
322
gboolean
 
323
gimp_display_shell_get_show_layer (GimpDisplayShell *shell)
 
324
{
 
325
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
 
326
 
 
327
  return GET_OPTIONS (shell)->show_layer_boundary;
 
328
}
 
329
 
 
330
void
 
331
gimp_display_shell_set_show_transform (GimpDisplayShell *shell,
 
332
                                       gboolean          show)
 
333
{
 
334
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
335
 
 
336
  shell->show_transform_preview = show;
 
337
}
 
338
 
 
339
gboolean
 
340
gimp_display_shell_get_show_transform (GimpDisplayShell *shell)
 
341
{
 
342
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
 
343
 
 
344
  return shell->show_transform_preview;
 
345
}
 
346
 
 
347
void
 
348
gimp_display_shell_set_show_grid (GimpDisplayShell *shell,
 
349
                                  gboolean          show)
 
350
{
 
351
  GimpDisplayOptions *options;
 
352
 
 
353
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
354
 
 
355
  options = GET_OPTIONS (shell);
 
356
 
 
357
  g_object_set (options, "show-grid", show, NULL);
 
358
 
 
359
  if (shell->gdisp->gimage->grid)
 
360
    gimp_display_shell_expose_full (shell);
 
361
 
 
362
  SET_ACTIVE (shell->menubar_manager, "view-show-grid", show);
 
363
 
 
364
  if (IS_ACTIVE_DISPLAY (shell))
 
365
    SET_ACTIVE (shell->popup_manager, "view-show-grid", show);
 
366
}
 
367
 
 
368
gboolean
 
369
gimp_display_shell_get_show_grid (GimpDisplayShell *shell)
 
370
{
 
371
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
 
372
 
 
373
  return GET_OPTIONS (shell)->show_grid;
 
374
}
 
375
 
 
376
void
 
377
gimp_display_shell_set_snap_to_grid (GimpDisplayShell *shell,
 
378
                                     gboolean          snap)
 
379
{
 
380
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
381
 
 
382
  if (snap != shell->snap_to_grid)
 
383
    {
 
384
      shell->snap_to_grid = snap ? TRUE : FALSE;
 
385
 
 
386
      SET_ACTIVE (shell->menubar_manager, "view-snap-to-grid", snap);
 
387
 
 
388
      if (IS_ACTIVE_DISPLAY (shell))
 
389
        SET_ACTIVE (shell->popup_manager, "view-snap-to-grid", snap);
 
390
    }
 
391
}
 
392
 
 
393
gboolean
 
394
gimp_display_shell_get_snap_to_grid (GimpDisplayShell *shell)
 
395
{
 
396
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
 
397
 
 
398
  return shell->snap_to_grid;
 
399
}
 
400
 
 
401
void
 
402
gimp_display_shell_set_show_guides (GimpDisplayShell *shell,
 
403
                                    gboolean          show)
 
404
{
 
405
  GimpDisplayOptions *options;
 
406
 
 
407
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
408
 
 
409
  options = GET_OPTIONS (shell);
 
410
 
 
411
  g_object_set (options, "show-guides", show, NULL);
 
412
 
 
413
  if (shell->gdisp->gimage->guides)
 
414
    gimp_display_shell_expose_full (shell);
 
415
 
 
416
  SET_ACTIVE (shell->menubar_manager, "view-show-guides", show);
 
417
 
 
418
  if (IS_ACTIVE_DISPLAY (shell))
 
419
    SET_ACTIVE (shell->popup_manager, "view-show-guides", show);
 
420
}
 
421
 
 
422
gboolean
 
423
gimp_display_shell_get_show_guides (GimpDisplayShell *shell)
 
424
{
 
425
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
 
426
 
 
427
  return GET_OPTIONS (shell)->show_guides;
 
428
}
 
429
 
 
430
void
 
431
gimp_display_shell_set_snap_to_guides (GimpDisplayShell *shell,
 
432
                                       gboolean          snap)
 
433
{
 
434
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
435
 
 
436
  if (snap != shell->snap_to_guides)
 
437
    {
 
438
      shell->snap_to_guides = snap ? TRUE : FALSE;
 
439
 
 
440
      SET_ACTIVE (shell->menubar_manager, "view-snap-to-guides", snap);
 
441
 
 
442
      if (IS_ACTIVE_DISPLAY (shell))
 
443
        SET_ACTIVE (shell->popup_manager, "view-snap-to-guides", snap);
 
444
    }
 
445
}
 
446
 
 
447
gboolean
 
448
gimp_display_shell_get_snap_to_guides (GimpDisplayShell *shell)
 
449
{
 
450
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
 
451
 
 
452
  return shell->snap_to_guides;
 
453
}
 
454
 
 
455
void
 
456
gimp_display_shell_set_padding (GimpDisplayShell      *shell,
 
457
                                GimpCanvasPaddingMode  padding_mode,
 
458
                                const GimpRGB         *padding_color)
 
459
{
 
460
  GimpDisplayOptions *options;
 
461
  GimpRGB             color;
 
462
 
 
463
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
464
  g_return_if_fail (padding_color != NULL);
 
465
 
 
466
  options = GET_OPTIONS (shell);
 
467
  color   = *padding_color;
 
468
 
 
469
  switch (padding_mode)
 
470
    {
 
471
    case GIMP_CANVAS_PADDING_MODE_DEFAULT:
 
472
      if (shell->canvas)
 
473
        {
 
474
          gtk_widget_ensure_style (shell->canvas);
 
475
          gimp_rgb_set_gdk_color (&color,
 
476
                                  shell->canvas->style->bg + GTK_STATE_NORMAL);
 
477
        }
 
478
      break;
 
479
 
 
480
    case GIMP_CANVAS_PADDING_MODE_LIGHT_CHECK:
 
481
      gimp_rgb_set_uchar (&color,
 
482
                          render_blend_light_check[0],
 
483
                          render_blend_light_check[1],
 
484
                          render_blend_light_check[2]);
 
485
      break;
 
486
 
 
487
    case GIMP_CANVAS_PADDING_MODE_DARK_CHECK:
 
488
      gimp_rgb_set_uchar (&color,
 
489
                          render_blend_dark_check[0],
 
490
                          render_blend_dark_check[1],
 
491
                          render_blend_dark_check[2]);
 
492
      break;
 
493
 
 
494
    case GIMP_CANVAS_PADDING_MODE_CUSTOM:
 
495
    case GIMP_CANVAS_PADDING_MODE_RESET:
 
496
      break;
 
497
    }
 
498
 
 
499
  g_object_set (options,
 
500
                "padding-mode",  padding_mode,
 
501
                "padding-color", &color,
 
502
                NULL);
 
503
 
 
504
  gimp_canvas_set_bg_color (GIMP_CANVAS (shell->canvas), &color);
 
505
 
 
506
  SET_COLOR (shell->menubar_manager, "view-padding-color-menu",
 
507
             &options->padding_color);
 
508
 
 
509
  if (IS_ACTIVE_DISPLAY (shell))
 
510
    SET_COLOR (shell->popup_manager, "view-padding-color-menu",
 
511
               &options->padding_color);
 
512
 
 
513
  gimp_display_shell_expose_full (shell);
 
514
}
 
515
 
 
516
void
 
517
gimp_display_shell_get_padding (GimpDisplayShell      *shell,
 
518
                                GimpCanvasPaddingMode *padding_mode,
 
519
                                GimpRGB               *padding_color)
 
520
{
 
521
  GimpDisplayOptions *options;
 
522
 
 
523
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
524
 
 
525
  options = GET_OPTIONS (shell);
 
526
 
 
527
  if (padding_mode)
 
528
    *padding_mode = options->padding_mode;
 
529
 
 
530
  if (padding_color)
 
531
    *padding_color = options->padding_color;
 
532
}