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

#include "config.h"

#include <gtk/gtk.h>

#include "libgimpwidgets/gimpwidgets.h"

Michael Natterer's avatar
Michael Natterer committed
25
#include "actions-types.h"
Michael Natterer's avatar
Michael Natterer committed
26

27 28
#include "config/gimpguiconfig.h"

29 30
#include "core/gimp.h"
#include "core/gimpcontext.h"
Michael Natterer's avatar
Michael Natterer committed
31 32
#include "core/gimpimage.h"

33
#include "display/gimpdisplay.h"
34
#include "display/gimpdisplay-foreach.h"
Michael Natterer's avatar
Michael Natterer committed
35
#include "display/gimpdisplayshell.h"
36
#include "display/gimpdisplayshell-appearance.h"
37
#include "display/gimpdisplayshell-filter-dialog.h"
38
#include "display/gimpdisplayshell-scale.h"
39

40
#include "widgets/gimpactiongroup.h"
41
#include "widgets/gimpdock.h"
42
#include "widgets/gimpdialogfactory.h"
43
#include "widgets/gimpuimanager.h"
44

Michael Natterer's avatar
Michael Natterer committed
45 46 47 48
#include "gui/dialogs.h"
#include "gui/info-dialog.h"
#include "gui/info-window.h"

Michael Natterer's avatar
Michael Natterer committed
49 50 51
#include "view-commands.h"


Michael Natterer's avatar
Michael Natterer committed
52
#define return_if_no_display(gdisp, data) \
53 54 55 56
  if (GIMP_IS_DISPLAY (data)) \
    gdisp = data; \
  else if (GIMP_IS_GIMP (data)) \
    gdisp = gimp_context_get_display (gimp_get_user_context (GIMP (data))); \
57 58
  else if (GIMP_IS_DOCK (data)) \
    gdisp = gimp_context_get_display (((GimpDock *) data)->context); \
59 60
  else \
    gdisp = NULL; \
Michael Natterer's avatar
Michael Natterer committed
61 62
  if (! gdisp) \
    return
Michael Natterer's avatar
Michael Natterer committed
63

64 65 66 67 68
#define SET_ACTIVE(manager,group_name,action_name,active) \
  { GimpActionGroup *group = \
      gimp_ui_manager_get_action_group (manager, group_name); \
    gimp_action_group_set_action_active (group, action_name, active); }

69 70 71 72
#define IS_ACTIVE_DISPLAY(gdisp) \
  ((gdisp) == \
   gimp_context_get_display (gimp_get_user_context ((gdisp)->gimage->gimp)))

Michael Natterer's avatar
Michael Natterer committed
73 74

void
75
view_zoom_out_cmd_callback (GtkAction *action,
76
                            gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
77
{
78
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
79
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
80

81 82
  gimp_display_shell_scale (GIMP_DISPLAY_SHELL (gdisp->shell),
                            GIMP_ZOOM_OUT, 0.0);
Michael Natterer's avatar
Michael Natterer committed
83 84 85
}

void
86
view_zoom_in_cmd_callback (GtkAction *action,
87
                           gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
88
{
89
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
90
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
91

92 93
  gimp_display_shell_scale (GIMP_DISPLAY_SHELL (gdisp->shell),
                            GIMP_ZOOM_IN, 0.0);
Michael Natterer's avatar
Michael Natterer committed
94 95
}

96
void
97
view_zoom_fit_cmd_callback (GtkAction *action,
98 99 100 101 102 103 104 105
                            gpointer   data)
{
  GimpDisplay *gdisp;
  return_if_no_display (gdisp, data);

  gimp_display_shell_scale_fit (GIMP_DISPLAY_SHELL (gdisp->shell));
}

Michael Natterer's avatar
Michael Natterer committed
106
void
107 108 109
view_zoom_cmd_callback (GtkAction *action,
                        GtkAction *current,
			gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
110
{
111 112
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
113
  gint              value;
Michael Natterer's avatar
Michael Natterer committed
114
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
115

116 117
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

118
  value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
119

120 121 122 123 124 125 126 127 128 129 130 131 132
  if (value == 0 /* Other... */)
    {
      /* check if we are activated by the user
       * or from view_actions_set_zoom()
       */
      if (shell->scale != shell->other_scale)
        gimp_display_shell_scale_dialog (shell);
    }
  else
    {
      if (fabs (value - shell->scale) > 0.0001)
        gimp_display_shell_scale (shell, GIMP_ZOOM_TO, (gdouble) value / 10000);
    }
133 134
}

Michael Natterer's avatar
Michael Natterer committed
135
void
136
view_dot_for_dot_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
137 138
			       gpointer   data)
{
139 140
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
141
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
142
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
143

144 145
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

146 147 148
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  if (active != shell->dot_for_dot)
149
    {
150
      gimp_display_shell_scale_set_dot_for_dot (shell, active);
151

152 153
      SET_ACTIVE (shell->menubar_manager, "view", "view-dot-for-dot",
                  shell->dot_for_dot);
154 155

      if (IS_ACTIVE_DISPLAY (gdisp))
156 157
        SET_ACTIVE (shell->popup_manager, "view", "view-dot-for-dot",
                    shell->dot_for_dot);
158
    }
Michael Natterer's avatar
Michael Natterer committed
159 160 161
}

void
162
view_info_window_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
163 164
			       gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
165 166
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
167
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
168

Michael Natterer's avatar
Michael Natterer committed
169 170
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

171
  if (GIMP_GUI_CONFIG (gdisp->gimage->gimp->config)->info_window_per_display)
Michael Natterer's avatar
Michael Natterer committed
172
    {
Michael Natterer's avatar
Michael Natterer committed
173 174
      if (! shell->info_dialog)
	shell->info_dialog = info_window_create (gdisp);
Michael Natterer's avatar
Michael Natterer committed
175

Sven Neumann's avatar
Sven Neumann committed
176 177 178 179 180
      /* To update the fields of the info window for the first time. *
       * It's no use updating it in info_window_create() because the *
       * pointer of the info window is not present in the shell yet. */
      info_window_update (gdisp);

181
      info_dialog_present (shell->info_dialog);
Michael Natterer's avatar
Michael Natterer committed
182 183 184
    }
  else
    {
Michael Natterer's avatar
Michael Natterer committed
185
      info_window_follow_auto (gdisp->gimage->gimp);
Michael Natterer's avatar
Michael Natterer committed
186 187 188 189
    }
}

void
190
view_navigation_window_cmd_callback (GtkAction *action,
191
                                     gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
192
{
Michael Natterer's avatar
Michael Natterer committed
193 194
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
195
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
196

Michael Natterer's avatar
Michael Natterer committed
197 198
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

Michael Natterer's avatar
Michael Natterer committed
199
  gimp_dialog_factory_dialog_raise (global_dock_factory,
200
                                    gtk_widget_get_screen (gdisp->shell),
Michael Natterer's avatar
Michael Natterer committed
201
                                    "gimp-navigation-view", -1);
Michael Natterer's avatar
Michael Natterer committed
202 203
}

204
void
205
view_display_filters_cmd_callback (GtkAction *action,
206 207 208 209 210 211 212 213
                                   gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

214 215 216 217 218 219 220 221 222 223
  if (! shell->filters_dialog)
    {
      shell->filters_dialog = gimp_display_shell_filter_dialog_new (shell);

      g_signal_connect (shell->filters_dialog, "destroy",
                        G_CALLBACK (gtk_widget_destroyed),
                        &shell->filters_dialog);
    }

  gtk_window_present (GTK_WINDOW (shell->filters_dialog));
224 225
}

Michael Natterer's avatar
Michael Natterer committed
226
void
227
view_toggle_selection_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
228 229
				    gpointer   data)
{
230 231
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
232
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
233
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
234

235 236
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

237 238 239
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_show_selection (shell, active);
Michael Natterer's avatar
Michael Natterer committed
240 241 242
}

void
243
view_toggle_layer_boundary_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
244 245 246 247
                                         gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
248
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
249 250 251 252
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

253 254 255
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_show_layer (shell, active);
Michael Natterer's avatar
Michael Natterer committed
256 257
}

258
void
259
view_toggle_menubar_cmd_callback (GtkAction *action,
260 261 262 263
                                  gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
264
  gboolean          active;
265 266 267 268
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

269 270 271
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_show_menubar (shell, active);
272 273
}

Michael Natterer's avatar
Michael Natterer committed
274
void
275
view_toggle_rulers_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
276 277
				 gpointer   data)
{
278 279
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
280
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
281
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
282

Michael Natterer's avatar
Michael Natterer committed
283 284
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

285 286 287
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_show_rulers (shell, active);
288
}
289

290
void
291
view_toggle_scrollbars_cmd_callback (GtkAction *action,
292 293 294 295
                                     gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
296
  gboolean          active;
297
  return_if_no_display (gdisp, data);
298

299 300
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

301 302 303
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_show_scrollbars (shell, active);
Michael Natterer's avatar
Michael Natterer committed
304 305 306
}

void
307
view_toggle_statusbar_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
308 309
				    gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
310 311
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
312
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
313
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
314

Michael Natterer's avatar
Michael Natterer committed
315 316
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

317 318 319
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_show_statusbar (shell, active);
Michael Natterer's avatar
Michael Natterer committed
320 321 322
}

void
323
view_toggle_guides_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
324 325
				 gpointer   data)
{
326 327
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
328
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
329
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
330

331 332
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

333 334 335
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_show_guides (shell, active);
Michael Natterer's avatar
Michael Natterer committed
336 337 338
}

void
339
view_snap_to_guides_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
340 341
				  gpointer   data)
{
342 343
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
344
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
345
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
346

347
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);
348

349
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
350

351
  gimp_display_shell_set_snap_to_guides (shell, active);
Michael Natterer's avatar
Michael Natterer committed
352 353
}

354 355

void
356
view_toggle_grid_cmd_callback (GtkAction *action,
357 358 359 360
                               gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
361
  gboolean          active;
362 363 364 365
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

366
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
367

368
  gimp_display_shell_set_show_grid (shell, active);
369 370 371
}

void
372
view_snap_to_grid_cmd_callback (GtkAction *action,
373 374 375 376
                                gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
377
  gboolean          active;
378 379 380 381
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

382
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
383

384
  gimp_display_shell_set_snap_to_grid (shell, active);
385 386
}

Michael Natterer's avatar
Michael Natterer committed
387
void
388
view_new_view_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
389 390
			    gpointer   data)
{
391
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
392
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
393

394 395
  gimp_create_display (gdisp->gimage->gimp, gdisp->gimage,
                       GIMP_DISPLAY_SHELL (gdisp->shell)->scale);
Michael Natterer's avatar
Michael Natterer committed
396 397 398
}

void
399
view_shrink_wrap_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
400 401
			       gpointer   data)
{
402
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
403
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
404

Michael Natterer's avatar
Michael Natterer committed
405
  gimp_display_shell_scale_shrink_wrap (GIMP_DISPLAY_SHELL (gdisp->shell));
Michael Natterer's avatar
Michael Natterer committed
406
}
407 408

void
409
view_fullscreen_cmd_callback (GtkAction *action,
410 411 412 413
			      gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
414
  gboolean          active;
415 416 417 418 419
  gboolean          fullscreen;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

420 421 422
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_fullscreen (shell, active);
423 424 425

  fullscreen = (shell->window_state & GDK_WINDOW_STATE_FULLSCREEN) != 0;

426
  if (active != fullscreen)
427
    {
428 429
      SET_ACTIVE (shell->menubar_manager, "view", "view-fullscreen",
                  fullscreen);
430 431

      if (IS_ACTIVE_DISPLAY (gdisp))
432 433
        SET_ACTIVE (shell->popup_manager, "view", "view-fullscreen",
                    fullscreen);
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
    }
}

static void
view_change_screen_confirm_callback (GtkWidget *query_box,
                                     gint       value,
                                     gpointer   data)
{
  GdkScreen *screen;

  screen = gdk_display_get_screen (gtk_widget_get_display (GTK_WIDGET (data)),
                                   value);

  if (screen)
    gtk_window_set_screen (GTK_WINDOW (data), screen);
}

static void
view_change_screen_destroy_callback (GtkWidget *query_box,
                                     GtkWidget *shell)
{
  g_object_set_data (G_OBJECT (shell), "gimp-change-screen-dialog", NULL);
}

void
459
view_change_screen_cmd_callback (GtkAction *action,
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
                                 gpointer   data)
{
  GimpDisplay *gdisp;
  GdkScreen   *screen;
  GdkDisplay  *display;
  gint         cur_screen;
  gint         num_screens;
  GtkWidget   *qbox;
  return_if_no_display (gdisp, data);

  qbox = g_object_get_data (G_OBJECT (gdisp->shell),
                            "gimp-change-screen-dialog");

  if (qbox)
    {
      gtk_window_present (GTK_WINDOW (qbox));
      return;
    }

  screen  = gtk_widget_get_screen (gdisp->shell);
  display = gtk_widget_get_display (gdisp->shell);

  cur_screen  = gdk_screen_get_number (screen);
  num_screens = gdk_display_get_n_screens (display);

  qbox = gimp_query_int_box ("Move Display to Screen",
                             gdisp->shell,
                             NULL, 0,
488
                             "Enter destination screen",
489 490 491 492 493 494 495 496 497 498 499 500 501
                             cur_screen, 0, num_screens - 1,
                             G_OBJECT (gdisp->shell), "destroy",
                             view_change_screen_confirm_callback,
                             gdisp->shell);

  g_object_set_data (G_OBJECT (gdisp->shell), "gimp-change-screen-dialog", qbox);

  g_signal_connect (qbox, "destroy",
                    G_CALLBACK (view_change_screen_destroy_callback),
                    gdisp->shell);

  gtk_widget_show (qbox);
}