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

25
#include "gui-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/gimpdialogfactory.h"
41
#include "widgets/gimpitemfactory.h"
42 43

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


Michael Natterer's avatar
Michael Natterer committed
49
#define return_if_no_display(gdisp, data) \
50 51 52 53 54 55
  if (GIMP_IS_DISPLAY (data)) \
    gdisp = data; \
  else if (GIMP_IS_GIMP (data)) \
    gdisp = gimp_context_get_display (gimp_get_user_context (GIMP (data))); \
  else \
    gdisp = NULL; \
Michael Natterer's avatar
Michael Natterer committed
56 57
  if (! gdisp) \
    return
Michael Natterer's avatar
Michael Natterer committed
58

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

Michael Natterer's avatar
Michael Natterer committed
63 64

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

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

void
75 76
view_zoom_in_cmd_callback (GtkWidget *widget,
                           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
  gimp_display_shell_scale (GIMP_DISPLAY_SHELL (gdisp->shell), GIMP_ZOOM_IN);
Michael Natterer's avatar
Michael Natterer committed
82 83
}

84 85 86 87 88 89 90 91 92 93
void
view_zoom_fit_cmd_callback (GtkWidget *widget,
                            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
94 95 96 97 98
void
view_zoom_cmd_callback (GtkWidget *widget,
			gpointer   data,
			guint      action)
{
99 100 101 102
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  guchar            scalesrc;
  guchar            scaledest;
Michael Natterer's avatar
Michael Natterer committed
103
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
104

105 106 107 108 109 110 111 112 113 114
  if (! GTK_CHECK_MENU_ITEM (widget)->active)
    return;

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  scalesrc  = CLAMP (action % 100, 1, 0xFF);
  scaledest = CLAMP (action / 100, 1, 0xFF);

  if (scalesrc != SCALESRC (shell) || scaledest != SCALEDEST (shell))
    gimp_display_shell_scale (shell, action);
Michael Natterer's avatar
Michael Natterer committed
115 116
}

117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
void
view_zoom_other_cmd_callback (GtkWidget *widget,
                              gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  return_if_no_display (gdisp, data);

  if (! GTK_CHECK_MENU_ITEM (widget)->active)
    return;

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  /*  check if we are activated by the user or from image_menu_set_zoom()  */
  if (shell->scale != shell->other_scale)
    gimp_display_shell_scale_dialog (shell);
}

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

143 144 145 146 147 148 149 150 151 152
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  if (shell->dot_for_dot != GTK_CHECK_MENU_ITEM (widget)->active)
    {
      gimp_display_shell_scale_set_dot_for_dot (shell,
                                                GTK_CHECK_MENU_ITEM (widget)->active);

      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->menubar_factory),
                                    "/View/Dot for Dot",
                                    shell->dot_for_dot);
153 154 155 156 157

      if (IS_ACTIVE_DISPLAY (gdisp))
        gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->popup_factory),
                                      "/View/Dot for Dot",
                                      shell->dot_for_dot);
158
    }
Michael Natterer's avatar
Michael Natterer committed
159 160 161 162 163 164
}

void
view_info_window_cmd_callback (GtkWidget *widget,
			       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

Michael Natterer's avatar
Michael Natterer committed
176
      info_dialog_popup (shell->info_dialog);
Michael Natterer's avatar
Michael Natterer committed
177 178 179
    }
  else
    {
Michael Natterer's avatar
Michael Natterer committed
180
      info_window_follow_auto (gdisp->gimage->gimp);
Michael Natterer's avatar
Michael Natterer committed
181 182 183 184
    }
}

void
185 186
view_navigation_window_cmd_callback (GtkWidget *widget,
                                     gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
187
{
Michael Natterer's avatar
Michael Natterer committed
188 189
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
190
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
191

Michael Natterer's avatar
Michael Natterer committed
192 193
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

Michael Natterer's avatar
Michael Natterer committed
194
  gimp_dialog_factory_dialog_raise (global_dock_factory,
195
                                    gtk_widget_get_screen (widget),
Michael Natterer's avatar
Michael Natterer committed
196
                                    "gimp-navigation-view", -1);
Michael Natterer's avatar
Michael Natterer committed
197 198
}

199 200 201 202 203 204 205 206 207 208
void
view_display_filters_cmd_callback (GtkWidget *widget,
                                   gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

209 210 211 212 213 214 215 216 217 218
  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));
219 220
}

Michael Natterer's avatar
Michael Natterer committed
221 222 223 224
void
view_toggle_selection_cmd_callback (GtkWidget *widget,
				    gpointer   data)
{
225 226
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
227
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
228

229 230
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

231 232
  gimp_display_shell_set_show_selection (shell,
                                         GTK_CHECK_MENU_ITEM (widget)->active);
Michael Natterer's avatar
Michael Natterer committed
233 234 235 236 237 238 239 240 241 242 243 244
}

void
view_toggle_layer_boundary_cmd_callback (GtkWidget *widget,
                                         gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

245 246
  gimp_display_shell_set_show_layer (shell,
                                     GTK_CHECK_MENU_ITEM (widget)->active);
Michael Natterer's avatar
Michael Natterer committed
247 248
}

249 250 251 252 253 254 255 256 257 258
void
view_toggle_menubar_cmd_callback (GtkWidget *widget,
                                  gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

259 260
  gimp_display_shell_set_show_menubar (shell,
                                       GTK_CHECK_MENU_ITEM (widget)->active);
261 262
}

Michael Natterer's avatar
Michael Natterer committed
263 264 265 266
void
view_toggle_rulers_cmd_callback (GtkWidget *widget,
				 gpointer   data)
{
267 268
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
269
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
270

Michael Natterer's avatar
Michael Natterer committed
271 272
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

273 274 275
  gimp_display_shell_set_show_rulers (shell,
                                      GTK_CHECK_MENU_ITEM (widget)->active);
}
276

277 278 279 280 281 282 283
void
view_toggle_scrollbars_cmd_callback (GtkWidget *widget,
                                     gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  return_if_no_display (gdisp, data);
284

285 286 287 288
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  gimp_display_shell_set_show_scrollbars (shell,
                                          GTK_CHECK_MENU_ITEM (widget)->active);
Michael Natterer's avatar
Michael Natterer committed
289 290 291 292 293 294
}

void
view_toggle_statusbar_cmd_callback (GtkWidget *widget,
				    gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
295 296
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
297
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
298

Michael Natterer's avatar
Michael Natterer committed
299 300
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

301 302
  gimp_display_shell_set_show_statusbar (shell,
                                         GTK_CHECK_MENU_ITEM (widget)->active);
Michael Natterer's avatar
Michael Natterer committed
303 304 305 306 307 308
}

void
view_toggle_guides_cmd_callback (GtkWidget *widget,
				 gpointer   data)
{
309 310
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
311
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
312

313 314 315 316
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  gimp_display_shell_set_show_guides (shell,
                                      GTK_CHECK_MENU_ITEM (widget)->active);
Michael Natterer's avatar
Michael Natterer committed
317 318 319 320 321 322
}

void
view_snap_to_guides_cmd_callback (GtkWidget *widget,
				  gpointer   data)
{
323 324
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
325
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
326

327
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);
328

329
  if (shell->snap_to_guides != GTK_CHECK_MENU_ITEM (widget)->active)
330
    {
331
      shell->snap_to_guides = GTK_CHECK_MENU_ITEM (widget)->active;
332 333 334

      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->menubar_factory),
                                    "/View/Snap to Guides",
335
                                    shell->snap_to_guides);
336 337 338 339 340

      if (IS_ACTIVE_DISPLAY (gdisp))
        gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->popup_factory),
                                      "/View/Snap to Guides",
                                      shell->snap_to_guides);
341
    }
Michael Natterer's avatar
Michael Natterer committed
342 343
}

344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376

void
view_toggle_grid_cmd_callback (GtkWidget *widget,
                               gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  gimp_display_shell_set_show_grid (shell,
                                    GTK_CHECK_MENU_ITEM (widget)->active);

}

void
view_snap_to_grid_cmd_callback (GtkWidget *widget,
                                gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  if (shell->snap_to_grid != GTK_CHECK_MENU_ITEM (widget)->active)
    {
      shell->snap_to_grid = GTK_CHECK_MENU_ITEM (widget)->active;

      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->menubar_factory),
                                    "/View/Snap to Grid",
                                    shell->snap_to_grid);
377 378 379 380 381

      if (IS_ACTIVE_DISPLAY (gdisp))
        gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->popup_factory),
                                      "/View/Snap to Grid",
                                      shell->snap_to_grid);
382 383 384
    }
}

Michael Natterer's avatar
Michael Natterer committed
385 386 387 388
void
view_new_view_cmd_callback (GtkWidget *widget,
			    gpointer   data)
{
389
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
390
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
391

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

void
view_shrink_wrap_cmd_callback (GtkWidget *widget,
			       gpointer   data)
{
400
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
401
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
402

Michael Natterer's avatar
Michael Natterer committed
403
  gimp_display_shell_scale_shrink_wrap (GIMP_DISPLAY_SHELL (gdisp->shell));
Michael Natterer's avatar
Michael Natterer committed
404
}
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426

void
view_fullscreen_cmd_callback (GtkWidget *widget,
			      gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  gboolean          fullscreen;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  gimp_display_shell_set_fullscreen (shell,
                                     GTK_CHECK_MENU_ITEM (widget)->active);

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

  if (fullscreen != GTK_CHECK_MENU_ITEM (widget)->active)
    {
      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->menubar_factory),
                                    "/View/Fullscreen",
                                    fullscreen);
427 428 429 430 431

      if (IS_ACTIVE_DISPLAY (gdisp))
        gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->popup_factory),
                                      "/View/Fullscreen",
                                      fullscreen);
432 433 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 459 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
    }
}

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
view_change_screen_cmd_callback (GtkWidget *widget,
                                 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,
486
                             "Enter destination screen",
487 488 489 490 491 492 493 494 495 496 497 498 499
                             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);
}