view-commands.c 13.1 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  */

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
void
view_new_view_cmd_callback (GtkAction *action,
			    gpointer   data)
{
  GimpDisplay *gdisp;
  return_if_no_display (gdisp, data);

  gimp_create_display (gdisp->gimage->gimp, gdisp->gimage,
                       GIMP_DISPLAY_SHELL (gdisp->shell)->scale);
}

void
view_close_view_cmd_callback (GtkAction *action,
                              gpointer   data)
{
  GimpDisplay *gdisp;
  return_if_no_display (gdisp, data);

  gimp_display_shell_close (GIMP_DISPLAY_SHELL (gdisp->shell), FALSE);
}

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

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

void
98
view_zoom_in_cmd_callback (GtkAction *action,
99
                           gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
100
{
101
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
102
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
103

104 105
  gimp_display_shell_scale (GIMP_DISPLAY_SHELL (gdisp->shell),
                            GIMP_ZOOM_IN, 0.0);
Michael Natterer's avatar
Michael Natterer committed
106 107
}

108
void
109
view_zoom_fit_cmd_callback (GtkAction *action,
110 111 112 113 114 115 116 117
                            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
118
void
119 120 121
view_zoom_cmd_callback (GtkAction *action,
                        GtkAction *current,
			gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
122
{
123 124
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
125
  gint              value;
Michael Natterer's avatar
Michael Natterer committed
126
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
127

128 129
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

130
  value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
131

132 133 134 135 136 137 138 139 140 141 142 143 144
  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);
    }
145 146
}

Michael Natterer's avatar
Michael Natterer committed
147
void
148
view_dot_for_dot_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
149 150
			       gpointer   data)
{
151 152
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
153
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
154
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
155

156 157
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

158 159 160
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  if (active != shell->dot_for_dot)
161
    {
162
      gimp_display_shell_scale_set_dot_for_dot (shell, active);
163

164 165
      SET_ACTIVE (shell->menubar_manager, "view", "view-dot-for-dot",
                  shell->dot_for_dot);
166 167

      if (IS_ACTIVE_DISPLAY (gdisp))
168 169
        SET_ACTIVE (shell->popup_manager, "view", "view-dot-for-dot",
                    shell->dot_for_dot);
170
    }
Michael Natterer's avatar
Michael Natterer committed
171 172 173
}

void
174
view_info_window_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
175 176
			       gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
177 178
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
179
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
180

Michael Natterer's avatar
Michael Natterer committed
181 182
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

183
  if (GIMP_GUI_CONFIG (gdisp->gimage->gimp->config)->info_window_per_display)
Michael Natterer's avatar
Michael Natterer committed
184
    {
Michael Natterer's avatar
Michael Natterer committed
185 186
      if (! shell->info_dialog)
	shell->info_dialog = info_window_create (gdisp);
Michael Natterer's avatar
Michael Natterer committed
187

Sven Neumann's avatar
Sven Neumann committed
188 189 190 191 192
      /* 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);

193
      info_dialog_present (shell->info_dialog);
Michael Natterer's avatar
Michael Natterer committed
194 195 196
    }
  else
    {
Michael Natterer's avatar
Michael Natterer committed
197
      info_window_follow_auto (gdisp->gimage->gimp);
Michael Natterer's avatar
Michael Natterer committed
198 199 200 201
    }
}

void
202
view_navigation_window_cmd_callback (GtkAction *action,
203
                                     gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
204
{
Michael Natterer's avatar
Michael Natterer committed
205 206
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
207
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
208

Michael Natterer's avatar
Michael Natterer committed
209 210
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

Michael Natterer's avatar
Michael Natterer committed
211
  gimp_dialog_factory_dialog_raise (global_dock_factory,
212
                                    gtk_widget_get_screen (gdisp->shell),
Michael Natterer's avatar
Michael Natterer committed
213
                                    "gimp-navigation-view", -1);
Michael Natterer's avatar
Michael Natterer committed
214 215
}

216
void
217
view_display_filters_cmd_callback (GtkAction *action,
218 219 220 221 222 223 224 225
                                   gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

226 227 228 229 230 231 232 233 234 235
  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));
236 237
}

Michael Natterer's avatar
Michael Natterer committed
238
void
239
view_toggle_selection_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
240 241
				    gpointer   data)
{
242 243
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
244
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
245
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
246

247 248
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

249 250 251
  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
252 253 254
}

void
255
view_toggle_layer_boundary_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
256 257 258 259
                                         gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
260
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
261 262 263 264
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

265 266 267
  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
268 269
}

270
void
271
view_toggle_menubar_cmd_callback (GtkAction *action,
272 273 274 275
                                  gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
276
  gboolean          active;
277 278 279 280
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

281 282 283
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_show_menubar (shell, active);
284 285
}

Michael Natterer's avatar
Michael Natterer committed
286
void
287
view_toggle_rulers_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
288 289
				 gpointer   data)
{
290 291
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
292
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
293
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
294

Michael Natterer's avatar
Michael Natterer committed
295 296
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

297 298 299
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_show_rulers (shell, active);
300
}
301

302
void
303
view_toggle_scrollbars_cmd_callback (GtkAction *action,
304 305 306 307
                                     gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
308
  gboolean          active;
309
  return_if_no_display (gdisp, data);
310

311 312
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

313 314 315
  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
316 317 318
}

void
319
view_toggle_statusbar_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
320 321
				    gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
322 323
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
324
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
325
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
326

Michael Natterer's avatar
Michael Natterer committed
327 328
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

329 330 331
  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
332 333 334
}

void
335
view_toggle_guides_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
336 337
				 gpointer   data)
{
338 339
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
340
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
341
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
342

343 344
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

345 346 347
  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
348 349 350
}

void
351
view_snap_to_guides_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
352 353
				  gpointer   data)
{
354 355
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
356
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
357
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
358

359
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);
360

361
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
362

363
  gimp_display_shell_set_snap_to_guides (shell, active);
Michael Natterer's avatar
Michael Natterer committed
364 365
}

366 367

void
368
view_toggle_grid_cmd_callback (GtkAction *action,
369 370 371 372
                               gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
373
  gboolean          active;
374 375 376 377
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

378
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
379

380
  gimp_display_shell_set_show_grid (shell, active);
381 382 383
}

void
384
view_snap_to_grid_cmd_callback (GtkAction *action,
385 386 387 388
                                gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
389
  gboolean          active;
390 391 392 393
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

394
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
395

396
  gimp_display_shell_set_snap_to_grid (shell, active);
397 398
}

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

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

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

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

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

  gimp_display_shell_set_fullscreen (shell, active);
424 425 426

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

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

      if (IS_ACTIVE_DISPLAY (gdisp))
433 434
        SET_ACTIVE (shell->popup_manager, "view", "view-fullscreen",
                    fullscreen);
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
    }
}

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
460
view_change_screen_cmd_callback (GtkAction *action,
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 488
                                 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,
489
                             "Enter destination screen",
490 491 492 493 494 495 496 497 498 499 500 501 502
                             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);
}