1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
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.
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.
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.
23
#include "libgimpwidgets/gimpwidgets.h"
25
#include "actions-types.h"
27
#include "config/gimpguiconfig.h"
29
#include "core/gimp.h"
30
#include "core/gimpcontext.h"
31
#include "core/gimpimage.h"
33
#include "display/gimpdisplay.h"
34
#include "display/gimpdisplay-foreach.h"
35
#include "display/gimpdisplayoptions.h"
36
#include "display/gimpdisplayshell.h"
37
#include "display/gimpdisplayshell-appearance.h"
38
#include "display/gimpdisplayshell-close.h"
39
#include "display/gimpdisplayshell-filter-dialog.h"
40
#include "display/gimpdisplayshell-scale.h"
42
#include "widgets/gimpactiongroup.h"
43
#include "widgets/gimpcolordialog.h"
44
#include "widgets/gimpdock.h"
45
#include "widgets/gimpdialogfactory.h"
46
#include "widgets/gimpuimanager.h"
48
#include "dialogs/dialogs.h"
49
#include "dialogs/info-dialog.h"
50
#include "dialogs/info-window.h"
53
#include "view-commands.h"
55
#include "gimp-intl.h"
58
#define SET_ACTIVE(manager,action_name,active) \
59
{ GimpActionGroup *group = \
60
gimp_ui_manager_get_action_group (manager, "view"); \
61
gimp_action_group_set_action_active (group, action_name, active); }
63
#define IS_ACTIVE_DISPLAY(gdisp) \
65
gimp_context_get_display (gimp_get_user_context ((gdisp)->gimage->gimp)))
68
/* local function prototypes */
70
static void view_padding_color_dialog_update (GimpColorDialog *dialog,
72
GimpColorDialogState state,
73
GimpDisplayShell *shell);
74
static void view_change_screen_confirm_callback (GtkWidget *dialog,
77
static void view_change_screen_destroy_callback (GtkWidget *dialog,
81
/* public functions */
84
view_new_view_cmd_callback (GtkAction *action,
88
GimpDisplayShell *shell;
89
return_if_no_display (gdisp, data);
91
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
93
gimp_create_display (gdisp->gimage->gimp,
95
shell->unit, shell->scale);
99
view_close_view_cmd_callback (GtkAction *action,
103
return_if_no_display (gdisp, data);
105
gimp_display_shell_close (GIMP_DISPLAY_SHELL (gdisp->shell), FALSE);
109
view_zoom_fit_in_cmd_callback (GtkAction *action,
113
return_if_no_display (gdisp, data);
115
gimp_display_shell_scale_fit_in (GIMP_DISPLAY_SHELL (gdisp->shell));
119
view_zoom_fit_to_cmd_callback (GtkAction *action,
123
return_if_no_display (gdisp, data);
125
gimp_display_shell_scale_fit_to (GIMP_DISPLAY_SHELL (gdisp->shell));
129
view_zoom_cmd_callback (GtkAction *action,
134
GimpDisplayShell *shell;
136
return_if_no_display (gdisp, data);
138
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
140
scale = shell->scale;
142
switch ((GimpActionSelectType) value)
144
case GIMP_ACTION_SELECT_FIRST:
145
gimp_display_shell_scale (shell, GIMP_ZOOM_TO, 1.0 / 256.0);
148
case GIMP_ACTION_SELECT_LAST:
149
gimp_display_shell_scale (shell, GIMP_ZOOM_TO, 256.0);
152
case GIMP_ACTION_SELECT_PREVIOUS:
153
gimp_display_shell_scale (shell, GIMP_ZOOM_OUT, 0.0);
156
case GIMP_ACTION_SELECT_NEXT:
157
gimp_display_shell_scale (shell, GIMP_ZOOM_IN, 0.0);
160
case GIMP_ACTION_SELECT_SKIP_PREVIOUS:
161
scale = gimp_display_shell_scale_zoom_step (GIMP_ZOOM_OUT, scale);
162
scale = gimp_display_shell_scale_zoom_step (GIMP_ZOOM_OUT, scale);
163
scale = gimp_display_shell_scale_zoom_step (GIMP_ZOOM_OUT, scale);
164
gimp_display_shell_scale (shell, GIMP_ZOOM_TO, scale);
167
case GIMP_ACTION_SELECT_SKIP_NEXT:
168
scale = gimp_display_shell_scale_zoom_step (GIMP_ZOOM_IN, scale);
169
scale = gimp_display_shell_scale_zoom_step (GIMP_ZOOM_IN, scale);
170
scale = gimp_display_shell_scale_zoom_step (GIMP_ZOOM_IN, scale);
171
gimp_display_shell_scale (shell, GIMP_ZOOM_TO, scale);
175
scale = action_select_value ((GimpActionSelectType) value,
181
/* min = 1.0 / 256, max = 256.0 */
182
/* scale = min * (max / min)**(i/n), i = 0..n */
183
scale = pow (65536.0, scale / 512.0) / 256.0;
185
gimp_display_shell_scale (shell, GIMP_ZOOM_TO, scale);
191
view_zoom_explicit_cmd_callback (GtkAction *action,
196
GimpDisplayShell *shell;
198
return_if_no_display (gdisp, data);
200
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
202
value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
204
if (value != 0 /* not Other... */)
206
if (fabs (value - shell->scale) > 0.0001)
207
gimp_display_shell_scale (shell, GIMP_ZOOM_TO, (gdouble) value / 10000);
212
view_zoom_other_cmd_callback (GtkAction *action,
216
GimpDisplayShell *shell;
217
return_if_no_display (gdisp, data);
219
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
221
/* check if we are activated by the user or from
222
* view_actions_set_zoom()
224
if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) &&
225
shell->scale != shell->other_scale)
227
gimp_display_shell_scale_dialog (shell);
232
view_dot_for_dot_cmd_callback (GtkAction *action,
236
GimpDisplayShell *shell;
238
return_if_no_display (gdisp, data);
240
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
242
active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
244
if (active != shell->dot_for_dot)
246
gimp_display_shell_scale_set_dot_for_dot (shell, active);
248
SET_ACTIVE (shell->menubar_manager, "view-dot-for-dot",
251
if (IS_ACTIVE_DISPLAY (gdisp))
252
SET_ACTIVE (shell->popup_manager, "view-dot-for-dot",
258
view_scroll_horizontal_cmd_callback (GtkAction *action,
263
GimpDisplayShell *shell;
265
return_if_no_display (gdisp, data);
267
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
269
offset = action_select_value ((GimpActionSelectType) value,
270
shell->hsbdata->value,
271
shell->hsbdata->lower,
272
shell->hsbdata->upper -
273
shell->hsbdata->page_size,
274
shell->hsbdata->step_increment,
275
shell->hsbdata->page_increment,
277
gtk_adjustment_set_value (shell->hsbdata, offset);
281
view_scroll_vertical_cmd_callback (GtkAction *action,
286
GimpDisplayShell *shell;
288
return_if_no_display (gdisp, data);
290
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
292
offset = action_select_value ((GimpActionSelectType) value,
293
shell->vsbdata->value,
294
shell->vsbdata->lower,
295
shell->vsbdata->upper -
296
shell->vsbdata->page_size,
297
shell->vsbdata->step_increment,
298
shell->vsbdata->page_increment,
300
gtk_adjustment_set_value (shell->vsbdata, offset);
304
view_info_window_cmd_callback (GtkAction *action,
308
GimpDisplayShell *shell;
309
return_if_no_display (gdisp, data);
311
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
313
if (GIMP_GUI_CONFIG (gdisp->gimage->gimp->config)->info_window_per_display)
315
if (! shell->info_dialog)
316
shell->info_dialog = info_window_create (gdisp);
318
/* To update the fields of the info window for the first time. *
319
* It's no use updating it in info_window_create() because the *
320
* pointer of the info window is not present in the shell yet. */
321
info_window_update (gdisp);
323
info_dialog_present (shell->info_dialog);
327
info_window_follow_auto (gdisp->gimage->gimp);
332
view_navigation_window_cmd_callback (GtkAction *action,
336
GimpDisplayShell *shell;
337
return_if_no_display (gdisp, data);
339
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
341
gimp_dialog_factory_dialog_raise (global_dock_factory,
342
gtk_widget_get_screen (gdisp->shell),
343
"gimp-navigation-view", -1);
347
view_display_filters_cmd_callback (GtkAction *action,
351
GimpDisplayShell *shell;
352
return_if_no_display (gdisp, data);
354
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
356
if (! shell->filters_dialog)
358
shell->filters_dialog = gimp_display_shell_filter_dialog_new (shell);
360
g_signal_connect (shell->filters_dialog, "destroy",
361
G_CALLBACK (gtk_widget_destroyed),
362
&shell->filters_dialog);
365
gtk_window_present (GTK_WINDOW (shell->filters_dialog));
369
view_toggle_selection_cmd_callback (GtkAction *action,
373
GimpDisplayShell *shell;
375
return_if_no_display (gdisp, data);
377
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
379
active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
381
gimp_display_shell_set_show_selection (shell, active);
385
view_toggle_layer_boundary_cmd_callback (GtkAction *action,
389
GimpDisplayShell *shell;
391
return_if_no_display (gdisp, data);
393
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
395
active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
397
gimp_display_shell_set_show_layer (shell, active);
401
view_toggle_menubar_cmd_callback (GtkAction *action,
405
GimpDisplayShell *shell;
407
return_if_no_display (gdisp, data);
409
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
411
active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
413
gimp_display_shell_set_show_menubar (shell, active);
417
view_toggle_rulers_cmd_callback (GtkAction *action,
421
GimpDisplayShell *shell;
423
return_if_no_display (gdisp, data);
425
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
427
active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
429
gimp_display_shell_set_show_rulers (shell, active);
433
view_toggle_scrollbars_cmd_callback (GtkAction *action,
437
GimpDisplayShell *shell;
439
return_if_no_display (gdisp, data);
441
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
443
active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
445
gimp_display_shell_set_show_scrollbars (shell, active);
449
view_toggle_statusbar_cmd_callback (GtkAction *action,
453
GimpDisplayShell *shell;
455
return_if_no_display (gdisp, data);
457
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
459
active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
461
gimp_display_shell_set_show_statusbar (shell, active);
465
view_toggle_guides_cmd_callback (GtkAction *action,
469
GimpDisplayShell *shell;
471
return_if_no_display (gdisp, data);
473
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
475
active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
477
gimp_display_shell_set_show_guides (shell, active);
481
view_snap_to_guides_cmd_callback (GtkAction *action,
485
GimpDisplayShell *shell;
487
return_if_no_display (gdisp, data);
489
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
491
active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
493
gimp_display_shell_set_snap_to_guides (shell, active);
498
view_toggle_grid_cmd_callback (GtkAction *action,
502
GimpDisplayShell *shell;
504
return_if_no_display (gdisp, data);
506
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
508
active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
510
gimp_display_shell_set_show_grid (shell, active);
514
view_snap_to_grid_cmd_callback (GtkAction *action,
518
GimpDisplayShell *shell;
520
return_if_no_display (gdisp, data);
522
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
524
active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
526
gimp_display_shell_set_snap_to_grid (shell, active);
530
view_padding_color_cmd_callback (GtkAction *action,
535
GimpDisplayShell *shell;
536
GimpDisplayOptions *options;
538
return_if_no_display (gdisp, data);
540
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
542
fullscreen = gimp_display_shell_get_fullscreen (shell);
545
options = shell->fullscreen_options;
547
options = shell->options;
549
switch ((GimpCanvasPaddingMode) value)
551
case GIMP_CANVAS_PADDING_MODE_DEFAULT:
552
case GIMP_CANVAS_PADDING_MODE_LIGHT_CHECK:
553
case GIMP_CANVAS_PADDING_MODE_DARK_CHECK:
554
g_object_set_data (G_OBJECT (shell), "padding-color-dialog", NULL);
556
options->padding_mode_set = TRUE;
558
gimp_display_shell_set_padding (shell, (GimpCanvasPaddingMode) value,
559
&options->padding_color);
562
case GIMP_CANVAS_PADDING_MODE_CUSTOM:
564
GtkWidget *color_dialog;
566
color_dialog = g_object_get_data (G_OBJECT (shell),
567
"padding-color-dialog");
571
color_dialog = gimp_color_dialog_new (GIMP_VIEWABLE (gdisp->gimage),
572
_("Set Canvas Padding Color"),
573
GTK_STOCK_SELECT_COLOR,
574
_("Set Custom Canvas Padding Color"),
577
&options->padding_color,
580
g_signal_connect (color_dialog, "update",
581
G_CALLBACK (view_padding_color_dialog_update),
584
g_object_set_data_full (G_OBJECT (shell), "padding-color-dialog",
586
(GDestroyNotify) gtk_widget_destroy);
589
gtk_window_present (GTK_WINDOW (color_dialog));
593
case GIMP_CANVAS_PADDING_MODE_RESET:
594
g_object_set_data (G_OBJECT (shell), "padding-color-dialog", NULL);
597
GimpDisplayConfig *config;
598
GimpDisplayOptions *default_options;
600
config = GIMP_DISPLAY_CONFIG (gdisp->gimage->gimp->config);
602
options->padding_mode_set = FALSE;
605
default_options = config->default_fullscreen_view;
607
default_options = config->default_view;
609
gimp_display_shell_set_padding (shell,
610
default_options->padding_mode,
611
&default_options->padding_color);
618
view_shrink_wrap_cmd_callback (GtkAction *action,
622
return_if_no_display (gdisp, data);
624
gimp_display_shell_scale_shrink_wrap (GIMP_DISPLAY_SHELL (gdisp->shell));
628
view_fullscreen_cmd_callback (GtkAction *action,
632
GimpDisplayShell *shell;
634
return_if_no_display (gdisp, data);
636
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
638
active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
640
gimp_display_shell_set_fullscreen (shell, active);
644
view_change_screen_cmd_callback (GtkAction *action,
653
return_if_no_display (gdisp, data);
655
dialog = g_object_get_data (G_OBJECT (gdisp->shell),
656
"gimp-change-screen-dialog");
660
gtk_window_present (GTK_WINDOW (dialog));
664
screen = gtk_widget_get_screen (gdisp->shell);
665
display = gtk_widget_get_display (gdisp->shell);
667
cur_screen = gdk_screen_get_number (screen);
668
num_screens = gdk_display_get_n_screens (display);
670
dialog = gimp_query_int_box ("Move Display to Screen",
673
"Enter destination screen",
674
cur_screen, 0, num_screens - 1,
675
G_OBJECT (gdisp->shell), "destroy",
676
view_change_screen_confirm_callback,
679
g_object_set_data (G_OBJECT (gdisp->shell), "gimp-change-screen-dialog",
682
g_signal_connect (dialog, "destroy",
683
G_CALLBACK (view_change_screen_destroy_callback),
686
gtk_widget_show (dialog);
690
/* private functions */
693
view_padding_color_dialog_update (GimpColorDialog *dialog,
694
const GimpRGB *color,
695
GimpColorDialogState state,
696
GimpDisplayShell *shell)
698
GimpDisplayOptions *options;
701
fullscreen = gimp_display_shell_get_fullscreen (shell);
704
options = shell->fullscreen_options;
706
options = shell->options;
710
case GIMP_COLOR_DIALOG_OK:
711
options->padding_mode_set = TRUE;
713
gimp_display_shell_set_padding (shell, GIMP_CANVAS_PADDING_MODE_CUSTOM,
717
case GIMP_COLOR_DIALOG_CANCEL:
718
g_object_set_data (G_OBJECT (shell), "padding-color-dialog", NULL);
727
view_change_screen_confirm_callback (GtkWidget *dialog,
733
screen = gdk_display_get_screen (gtk_widget_get_display (GTK_WIDGET (data)),
737
gtk_window_set_screen (GTK_WINDOW (data), screen);
741
view_change_screen_destroy_callback (GtkWidget *dialog,
744
g_object_set_data (G_OBJECT (shell), "gimp-change-screen-dialog", NULL);