view-commands.c 12.9 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"

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


53 54 55 56 57
#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); }

58 59 60 61
#define IS_ACTIVE_DISPLAY(gdisp) \
  ((gdisp) == \
   gimp_context_get_display (gimp_get_user_context ((gdisp)->gimage->gimp)))

Michael Natterer's avatar
Michael Natterer committed
62

63 64
/*  public functions  */

Michael Natterer's avatar
Michael Natterer committed
65
void
66
view_zoom_out_cmd_callback (GtkAction *action,
67
                            gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
68
{
69
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
70
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
71

72 73
  gimp_display_shell_scale (GIMP_DISPLAY_SHELL (gdisp->shell),
                            GIMP_ZOOM_OUT, 0.0);
Michael Natterer's avatar
Michael Natterer committed
74 75 76
}

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

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

87
void
88
view_zoom_fit_cmd_callback (GtkAction *action,
89 90 91 92 93 94 95 96
                            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
97
void
98 99 100
view_zoom_cmd_callback (GtkAction *action,
                        GtkAction *current,
			gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
101
{
102 103
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
104
  gint              value;
Michael Natterer's avatar
Michael Natterer committed
105
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
106

107 108
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

109
  value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
110

111 112 113 114 115 116 117 118 119 120 121 122 123
  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);
    }
124 125
}

Michael Natterer's avatar
Michael Natterer committed
126
void
127
view_dot_for_dot_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
128 129
			       gpointer   data)
{
130 131
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
132
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
133
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
134

135 136
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

137 138 139
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  if (active != shell->dot_for_dot)
140
    {
141
      gimp_display_shell_scale_set_dot_for_dot (shell, active);
142

143 144
      SET_ACTIVE (shell->menubar_manager, "view", "view-dot-for-dot",
                  shell->dot_for_dot);
145 146

      if (IS_ACTIVE_DISPLAY (gdisp))
147 148
        SET_ACTIVE (shell->popup_manager, "view", "view-dot-for-dot",
                    shell->dot_for_dot);
149
    }
Michael Natterer's avatar
Michael Natterer committed
150 151 152
}

void
153
view_info_window_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
154 155
			       gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
156 157
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
158
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
159

Michael Natterer's avatar
Michael Natterer committed
160 161
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

162
  if (GIMP_GUI_CONFIG (gdisp->gimage->gimp->config)->info_window_per_display)
Michael Natterer's avatar
Michael Natterer committed
163
    {
Michael Natterer's avatar
Michael Natterer committed
164 165
      if (! shell->info_dialog)
	shell->info_dialog = info_window_create (gdisp);
Michael Natterer's avatar
Michael Natterer committed
166

Sven Neumann's avatar
Sven Neumann committed
167 168 169 170 171
      /* 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);

172
      info_dialog_present (shell->info_dialog);
Michael Natterer's avatar
Michael Natterer committed
173 174 175
    }
  else
    {
Michael Natterer's avatar
Michael Natterer committed
176
      info_window_follow_auto (gdisp->gimage->gimp);
Michael Natterer's avatar
Michael Natterer committed
177 178 179 180
    }
}

void
181
view_navigation_window_cmd_callback (GtkAction *action,
182
                                     gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
183
{
Michael Natterer's avatar
Michael Natterer committed
184 185
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
186
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
187

Michael Natterer's avatar
Michael Natterer committed
188 189
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

Michael Natterer's avatar
Michael Natterer committed
190
  gimp_dialog_factory_dialog_raise (global_dock_factory,
191
                                    gtk_widget_get_screen (gdisp->shell),
Michael Natterer's avatar
Michael Natterer committed
192
                                    "gimp-navigation-view", -1);
Michael Natterer's avatar
Michael Natterer committed
193 194
}

195
void
196
view_display_filters_cmd_callback (GtkAction *action,
197 198 199 200 201 202 203 204
                                   gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

205 206 207 208 209 210 211 212 213 214
  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));
215 216
}

Michael Natterer's avatar
Michael Natterer committed
217
void
218
view_toggle_selection_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
219 220
				    gpointer   data)
{
221 222
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
223
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
224
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
225

226 227
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

228 229 230
  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
231 232 233
}

void
234
view_toggle_layer_boundary_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
235 236 237 238
                                         gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
239
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
240 241 242 243
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

244 245 246
  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
247 248
}

249
void
250
view_toggle_menubar_cmd_callback (GtkAction *action,
251 252 253 254
                                  gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
255
  gboolean          active;
256 257 258 259
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

260 261 262
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_show_menubar (shell, active);
263 264
}

Michael Natterer's avatar
Michael Natterer committed
265
void
266
view_toggle_rulers_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
267 268
				 gpointer   data)
{
269 270
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
271
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
272
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
273

Michael Natterer's avatar
Michael Natterer committed
274 275
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

276 277 278
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_show_rulers (shell, active);
279
}
280

281
void
282
view_toggle_scrollbars_cmd_callback (GtkAction *action,
283 284 285 286
                                     gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
287
  gboolean          active;
288
  return_if_no_display (gdisp, data);
289

290 291
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

292 293 294
  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
295 296 297
}

void
298
view_toggle_statusbar_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
299 300
				    gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
301 302
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
303
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
304
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
305

Michael Natterer's avatar
Michael Natterer committed
306 307
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

308 309 310
  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
311 312 313
}

void
314
view_toggle_guides_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
315 316
				 gpointer   data)
{
317 318
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
319
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
320
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
321

322 323
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

324 325 326
  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
327 328 329
}

void
330
view_snap_to_guides_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
331 332
				  gpointer   data)
{
333 334
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
335
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
336
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
337

338
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);
339

340
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
341

342
  gimp_display_shell_set_snap_to_guides (shell, active);
Michael Natterer's avatar
Michael Natterer committed
343 344
}

345 346

void
347
view_toggle_grid_cmd_callback (GtkAction *action,
348 349 350 351
                               gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
352
  gboolean          active;
353 354 355 356
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

357
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
358

359
  gimp_display_shell_set_show_grid (shell, active);
360 361 362
}

void
363
view_snap_to_grid_cmd_callback (GtkAction *action,
364 365 366 367
                                gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
368
  gboolean          active;
369 370 371 372
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

373
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
374

375
  gimp_display_shell_set_snap_to_grid (shell, active);
376 377
}

Michael Natterer's avatar
Michael Natterer committed
378
void
379
view_new_view_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
380 381
			    gpointer   data)
{
382
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
383
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
384

385 386
  gimp_create_display (gdisp->gimage->gimp, gdisp->gimage,
                       GIMP_DISPLAY_SHELL (gdisp->shell)->scale);
Michael Natterer's avatar
Michael Natterer committed
387 388 389
}

void
390
view_shrink_wrap_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
391 392
			       gpointer   data)
{
393
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
394
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
395

Michael Natterer's avatar
Michael Natterer committed
396
  gimp_display_shell_scale_shrink_wrap (GIMP_DISPLAY_SHELL (gdisp->shell));
Michael Natterer's avatar
Michael Natterer committed
397
}
398 399

void
400
view_fullscreen_cmd_callback (GtkAction *action,
401 402 403 404
			      gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
405
  gboolean          active;
406 407 408 409 410
  gboolean          fullscreen;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

411 412 413
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_fullscreen (shell, active);
414 415 416

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

417
  if (active != fullscreen)
418
    {
419 420
      SET_ACTIVE (shell->menubar_manager, "view", "view-fullscreen",
                  fullscreen);
421 422

      if (IS_ACTIVE_DISPLAY (gdisp))
423 424
        SET_ACTIVE (shell->popup_manager, "view", "view-fullscreen",
                    fullscreen);
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
    }
}

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
450
view_change_screen_cmd_callback (GtkAction *action,
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
                                 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,
479
                             "Enter destination screen",
480 481 482 483 484 485 486 487 488 489 490 491 492
                             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);
}