view-commands.c 19.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"
35
#include "display/gimpdisplayoptions.h"
Michael Natterer's avatar
Michael Natterer committed
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"
41

42
#include "widgets/gimpactiongroup.h"
43
#include "widgets/gimpdock.h"
44
#include "widgets/gimpdialogfactory.h"
45
#include "widgets/gimpuimanager.h"
46

47 48 49 50
#include "dialogs/color-dialog.h"
#include "dialogs/dialogs.h"
#include "dialogs/info-dialog.h"
#include "dialogs/info-window.h"
Michael Natterer's avatar
Michael Natterer committed
51

52
#include "actions.h"
Michael Natterer's avatar
Michael Natterer committed
53 54
#include "view-commands.h"

55
#include "gimp-intl.h"
Michael Natterer's avatar
Michael Natterer committed
56

57 58

#define SET_ACTIVE(manager,action_name,active) \
59
  { GimpActionGroup *group = \
60
      gimp_ui_manager_get_action_group (manager, "view"); \
61 62
    gimp_action_group_set_action_active (group, action_name, active); }

63 64 65 66
#define IS_ACTIVE_DISPLAY(gdisp) \
  ((gdisp) == \
   gimp_context_get_display (gimp_get_user_context ((gdisp)->gimage->gimp)))

Michael Natterer's avatar
Michael Natterer committed
67

68 69
/*  public functions  */

70 71 72 73
void
view_new_view_cmd_callback (GtkAction *action,
			    gpointer   data)
{
74 75
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
76 77
  return_if_no_display (gdisp, data);

78 79 80 81 82
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  gimp_create_display (gdisp->gimage->gimp,
                       gdisp->gimage,
                       shell->unit, shell->scale);
83 84 85 86 87 88 89 90 91 92 93 94
}

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
95
void
96
view_zoom_out_cmd_callback (GtkAction *action,
97
                            gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
98
{
99
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
100
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
101

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

void
107
view_zoom_in_cmd_callback (GtkAction *action,
108
                           gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
109
{
110
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
111
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
112

113 114
  gimp_display_shell_scale (GIMP_DISPLAY_SHELL (gdisp->shell),
                            GIMP_ZOOM_IN, 0.0);
Michael Natterer's avatar
Michael Natterer committed
115 116
}

117
void
118 119 120 121 122 123 124 125 126 127 128 129
view_zoom_fit_in_cmd_callback (GtkAction *action,
                               gpointer   data)
{
  GimpDisplay *gdisp;
  return_if_no_display (gdisp, data);

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

void
view_zoom_fit_to_cmd_callback (GtkAction *action,
                               gpointer   data)
130 131 132 133
{
  GimpDisplay *gdisp;
  return_if_no_display (gdisp, data);

134
  gimp_display_shell_scale_fit_to (GIMP_DISPLAY_SHELL (gdisp->shell));
135 136
}

Michael Natterer's avatar
Michael Natterer committed
137
void
138 139 140
view_zoom_cmd_callback (GtkAction *action,
                        GtkAction *current,
			gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
141
{
142 143
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
144
  gint              value;
Michael Natterer's avatar
Michael Natterer committed
145
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
146

147 148
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

149
  value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
150

151
  if (value != 0 /* not Other... */)
152 153 154 155
    {
      if (fabs (value - shell->scale) > 0.0001)
        gimp_display_shell_scale (shell, GIMP_ZOOM_TO, (gdouble) value / 10000);
    }
156 157
}

158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
void
view_zoom_other_cmd_callback (GtkAction *action,
                              gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  /* check if we are activated by the user or from
   * view_actions_set_zoom()
   */
  if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) &&
      shell->scale != shell->other_scale)
    {
      gimp_display_shell_scale_dialog (shell);
    }
}

Michael Natterer's avatar
Michael Natterer committed
178
void
179
view_dot_for_dot_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
180 181
			       gpointer   data)
{
182 183
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
184
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
185
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
186

187 188
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

189 190 191
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  if (active != shell->dot_for_dot)
192
    {
193
      gimp_display_shell_scale_set_dot_for_dot (shell, active);
194

195
      SET_ACTIVE (shell->menubar_manager, "view-dot-for-dot",
196
                  shell->dot_for_dot);
197 198

      if (IS_ACTIVE_DISPLAY (gdisp))
199
        SET_ACTIVE (shell->popup_manager, "view-dot-for-dot",
200
                    shell->dot_for_dot);
201
    }
Michael Natterer's avatar
Michael Natterer committed
202 203
}

204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
void
view_scroll_horizontal_cmd_callback (GtkAction *action,
                                     gint       value,
                                     gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  gdouble           offset;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  offset = action_select_value ((GimpActionSelectType) value,
                                shell->hsbdata->value,
                                shell->hsbdata->lower,
                                shell->hsbdata->upper -
                                shell->hsbdata->page_size,
                                shell->hsbdata->step_increment,
                                shell->hsbdata->page_increment,
                                FALSE);
  gtk_adjustment_set_value (shell->hsbdata, offset);
}

void
view_scroll_vertical_cmd_callback (GtkAction *action,
                                   gint       value,
                                   gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  gdouble           offset;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  offset = action_select_value ((GimpActionSelectType) value,
                                shell->vsbdata->value,
                                shell->vsbdata->lower,
                                shell->vsbdata->upper -
                                shell->vsbdata->page_size,
                                shell->vsbdata->step_increment,
                                shell->vsbdata->page_increment,
                                FALSE);
  gtk_adjustment_set_value (shell->vsbdata, offset);
}

Michael Natterer's avatar
Michael Natterer committed
250
void
251
view_info_window_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
252 253
			       gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
254 255
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
256
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
257

Michael Natterer's avatar
Michael Natterer committed
258 259
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

260
  if (GIMP_GUI_CONFIG (gdisp->gimage->gimp->config)->info_window_per_display)
Michael Natterer's avatar
Michael Natterer committed
261
    {
Michael Natterer's avatar
Michael Natterer committed
262 263
      if (! shell->info_dialog)
	shell->info_dialog = info_window_create (gdisp);
Michael Natterer's avatar
Michael Natterer committed
264

Sven Neumann's avatar
Sven Neumann committed
265 266 267 268 269
      /* 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);

270
      info_dialog_present (shell->info_dialog);
Michael Natterer's avatar
Michael Natterer committed
271 272 273
    }
  else
    {
Michael Natterer's avatar
Michael Natterer committed
274
      info_window_follow_auto (gdisp->gimage->gimp);
Michael Natterer's avatar
Michael Natterer committed
275 276 277 278
    }
}

void
279
view_navigation_window_cmd_callback (GtkAction *action,
280
                                     gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
281
{
Michael Natterer's avatar
Michael Natterer committed
282 283
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
284
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
285

Michael Natterer's avatar
Michael Natterer committed
286 287
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

Michael Natterer's avatar
Michael Natterer committed
288
  gimp_dialog_factory_dialog_raise (global_dock_factory,
289
                                    gtk_widget_get_screen (gdisp->shell),
Michael Natterer's avatar
Michael Natterer committed
290
                                    "gimp-navigation-view", -1);
Michael Natterer's avatar
Michael Natterer committed
291 292
}

293
void
294
view_display_filters_cmd_callback (GtkAction *action,
295 296 297 298 299 300 301 302
                                   gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

303 304 305 306 307 308 309 310 311 312
  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));
313 314
}

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

324 325
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

326 327 328
  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
329 330 331
}

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

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

342 343 344
  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
345 346
}

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

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

358 359 360
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_show_menubar (shell, active);
361 362
}

Michael Natterer's avatar
Michael Natterer committed
363
void
364
view_toggle_rulers_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
365 366
				 gpointer   data)
{
367 368
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
369
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
370
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
371

Michael Natterer's avatar
Michael Natterer committed
372 373
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

374 375 376
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_show_rulers (shell, active);
377
}
378

379
void
380
view_toggle_scrollbars_cmd_callback (GtkAction *action,
381 382 383 384
                                     gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
385
  gboolean          active;
386
  return_if_no_display (gdisp, data);
387

388 389
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

390 391 392
  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
393 394 395
}

void
396
view_toggle_statusbar_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
397 398
				    gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
399 400
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
401
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
402
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
403

Michael Natterer's avatar
Michael Natterer committed
404 405
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

406 407 408
  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
409 410 411
}

void
412
view_toggle_guides_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
413 414
				 gpointer   data)
{
415 416
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
417
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
418
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
419

420 421
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

422 423 424
  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
425 426 427
}

void
428
view_snap_to_guides_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
429 430
				  gpointer   data)
{
431 432
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
433
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
434
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
435

436
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);
437

438
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
439

440
  gimp_display_shell_set_snap_to_guides (shell, active);
Michael Natterer's avatar
Michael Natterer committed
441 442
}

443 444

void
445
view_toggle_grid_cmd_callback (GtkAction *action,
446 447 448 449
                               gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
450
  gboolean          active;
451 452 453 454
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

455
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
456

457
  gimp_display_shell_set_show_grid (shell, active);
458 459 460
}

void
461
view_snap_to_grid_cmd_callback (GtkAction *action,
462 463 464 465
                                gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
466
  gboolean          active;
467 468 469 470
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

471
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
472

473
  gimp_display_shell_set_snap_to_grid (shell, active);
474 475
}

476
static void
477 478 479 480
view_padding_color_callback (ColorDialog      *cnb,
                             const GimpRGB    *color,
                             ColorDialogState  state,
                             gpointer          data)
481 482 483 484 485 486 487 488 489 490 491 492 493 494
{
  GimpDisplayShell   *shell = GIMP_DISPLAY_SHELL (data);
  GimpDisplayOptions *options;
  gboolean            fullscreen;

  fullscreen = gimp_display_shell_get_fullscreen (shell);

  if (fullscreen)
    options = shell->fullscreen_options;
  else
    options = shell->options;

  switch (state)
    {
495
    case COLOR_DIALOG_OK:
496 497 498 499 500 501
      options->padding_mode_set = TRUE;

      gimp_display_shell_set_padding (shell, GIMP_CANVAS_PADDING_MODE_CUSTOM,
                                      color);
      /* fallthru */

502 503
    case COLOR_DIALOG_CANCEL:
      g_object_set_data (G_OBJECT (shell), "padding-color-dialog", NULL);
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
      break;

    default:
      break;
    }
}

void
view_padding_color_cmd_callback (GtkAction *action,
                                 gint       value,
                                 gpointer   data)
{
  GimpDisplay        *gdisp;
  GimpDisplayShell   *shell;
  GimpDisplayOptions *options;
  gboolean            fullscreen;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  fullscreen = gimp_display_shell_get_fullscreen (shell);

  if (fullscreen)
    options = shell->fullscreen_options;
  else
    options = shell->options;

  switch ((GimpCanvasPaddingMode) value)
    {
    case GIMP_CANVAS_PADDING_MODE_DEFAULT:
    case GIMP_CANVAS_PADDING_MODE_LIGHT_CHECK:
    case GIMP_CANVAS_PADDING_MODE_DARK_CHECK:
536
      g_object_set_data (G_OBJECT (shell), "padding-color-dialog", NULL);
537 538 539 540 541 542 543 544 545

      options->padding_mode_set = TRUE;

      gimp_display_shell_set_padding (shell, (GimpCanvasPaddingMode) value,
                                      &options->padding_color);
      break;

    case GIMP_CANVAS_PADDING_MODE_CUSTOM:
      {
546
        ColorDialog *color_dialog;
547

548 549
        color_dialog = g_object_get_data (G_OBJECT (shell),
                                            "padding-color-dialog");
550

551
        if (! color_dialog)
552
          {
553 554 555 556 557 558 559 560 561 562 563 564 565
            color_dialog = color_dialog_new (GIMP_VIEWABLE (gdisp->gimage),
                                             _("Set Canvas Padding Color"),
                                             GTK_STOCK_SELECT_COLOR,
                                             NULL,
                                             gdisp->shell,
                                             NULL, NULL,
                                             &options->padding_color,
                                             view_padding_color_callback,
                                             shell,
                                             FALSE, FALSE);
            g_object_set_data_full (G_OBJECT (shell), "padding-color-dialog",
                                    color_dialog,
                                    (GDestroyNotify) color_dialog_free);
566 567
          }

568
        color_dialog_show (color_dialog);
569 570 571 572
      }
      break;

    case GIMP_CANVAS_PADDING_MODE_RESET:
573
      g_object_set_data (G_OBJECT (shell), "padding-color-dialog", NULL);
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595

      {
        GimpDisplayConfig  *config;
        GimpDisplayOptions *default_options;

        config = GIMP_DISPLAY_CONFIG (gdisp->gimage->gimp->config);

        options->padding_mode_set = FALSE;

        if (fullscreen)
          default_options = config->default_fullscreen_view;
        else
          default_options = config->default_view;

        gimp_display_shell_set_padding (shell,
                                        default_options->padding_mode,
                                        &default_options->padding_color);
      }
      break;
    }
}

Michael Natterer's avatar
Michael Natterer committed
596
void
597
view_shrink_wrap_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
598 599
			       gpointer   data)
{
600
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
601
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
602

Michael Natterer's avatar
Michael Natterer committed
603
  gimp_display_shell_scale_shrink_wrap (GIMP_DISPLAY_SHELL (gdisp->shell));
Michael Natterer's avatar
Michael Natterer committed
604
}
605 606

void
607
view_fullscreen_cmd_callback (GtkAction *action,
608 609 610 611
			      gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
612
  gboolean          active;
613 614 615 616 617
  gboolean          fullscreen;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

618 619 620
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_fullscreen (shell, active);
621 622 623

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

624
  if (active != fullscreen)
625
    {
626
      SET_ACTIVE (shell->menubar_manager, "view-fullscreen",
627
                  fullscreen);
628 629

      if (IS_ACTIVE_DISPLAY (gdisp))
630
        SET_ACTIVE (shell->popup_manager, "view-fullscreen",
631
                    fullscreen);
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
    }
}

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
657
view_change_screen_cmd_callback (GtkAction *action,
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685
                                 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,
686
                             "Enter destination screen",
687 688 689 690 691 692 693 694 695 696 697 698 699
                             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);
}