view-commands.c 22.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"
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/gimpcolordialog.h"
44
#include "widgets/gimpdock.h"
45
#include "widgets/gimpdialogfactory.h"
46
#include "widgets/gimpuimanager.h"
47

48 49 50
#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 70 71 72 73
/*  local function prototypes  */

static void   view_padding_color_dialog_update    (GimpColorDialog      *dialog,
                                                   const GimpRGB        *color,
                                                   GimpColorDialogState  state,
                                                   GimpDisplayShell     *shell);
74
static void   view_change_screen_confirm_callback (GtkWidget            *dialog,
75 76
                                                   gint                  value,
                                                   gpointer              data);
77
static void   view_change_screen_destroy_callback (GtkWidget            *dialog,
78 79 80
                                                   GtkWidget            *shell);


81 82
/*  public functions  */

83 84
void
view_new_view_cmd_callback (GtkAction *action,
85
                            gpointer   data)
86
{
87 88
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
89 90
  return_if_no_display (gdisp, data);

91 92 93 94 95
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  gimp_create_display (gdisp->gimage->gimp,
                       gdisp->gimage,
                       shell->unit, shell->scale);
96 97 98 99 100 101 102 103 104 105 106 107
}

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
108
void
109 110
view_zoom_fit_in_cmd_callback (GtkAction *action,
                               gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
111
{
112
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
113
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
114

115
  gimp_display_shell_scale_fit_in (GIMP_DISPLAY_SHELL (gdisp->shell));
Michael Natterer's avatar
Michael Natterer committed
116 117 118
}

void
119 120
view_zoom_fit_to_cmd_callback (GtkAction *action,
                               gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
121
{
122
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
123
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
124

125
  gimp_display_shell_scale_fit_to (GIMP_DISPLAY_SHELL (gdisp->shell));
Michael Natterer's avatar
Michael Natterer committed
126 127
}

128
void
129 130 131
view_zoom_cmd_callback (GtkAction *action,
                        gint       value,
                        gpointer   data)
132
{
133 134 135
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  gdouble           scale;
136 137
  return_if_no_display (gdisp, data);

138
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);
139

140
  scale = shell->scale;
141

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
  switch ((GimpActionSelectType) value)
    {
    case GIMP_ACTION_SELECT_FIRST:
      gimp_display_shell_scale (shell, GIMP_ZOOM_TO, 1.0 / 256.0);
      break;

    case GIMP_ACTION_SELECT_LAST:
      gimp_display_shell_scale (shell, GIMP_ZOOM_TO, 256.0);
      break;

    case GIMP_ACTION_SELECT_PREVIOUS:
      gimp_display_shell_scale (shell, GIMP_ZOOM_OUT, 0.0);
      break;

    case GIMP_ACTION_SELECT_NEXT:
      gimp_display_shell_scale (shell, GIMP_ZOOM_IN, 0.0);
      break;

    case GIMP_ACTION_SELECT_SKIP_PREVIOUS:
      scale = gimp_display_shell_scale_zoom_step (GIMP_ZOOM_OUT, scale);
      scale = gimp_display_shell_scale_zoom_step (GIMP_ZOOM_OUT, scale);
      scale = gimp_display_shell_scale_zoom_step (GIMP_ZOOM_OUT, scale);
      gimp_display_shell_scale (shell, GIMP_ZOOM_TO, scale);
      break;

    case GIMP_ACTION_SELECT_SKIP_NEXT:
      scale = gimp_display_shell_scale_zoom_step (GIMP_ZOOM_IN, scale);
      scale = gimp_display_shell_scale_zoom_step (GIMP_ZOOM_IN, scale);
      scale = gimp_display_shell_scale_zoom_step (GIMP_ZOOM_IN, scale);
      gimp_display_shell_scale (shell, GIMP_ZOOM_TO, scale);
      break;

    default:
      scale = action_select_value ((GimpActionSelectType) value,
                                   scale,
177
                                   0.0, 512.0,
178 179 180
                                   1.0, 16.0,
                                   FALSE);

181 182 183
      /* min = 1.0 / 256,  max = 256.0                */
      /* scale = min *  (max / min)**(i/n), i = 0..n  */
      scale = pow (65536.0, scale / 512.0) / 256.0;
184 185 186 187

      gimp_display_shell_scale (shell, GIMP_ZOOM_TO, scale);
      break;
    }
188 189
}

Michael Natterer's avatar
Michael Natterer committed
190
void
191 192 193
view_zoom_explicit_cmd_callback (GtkAction *action,
                                 GtkAction *current,
                                 gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
194
{
195 196
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
197
  gint              value;
Michael Natterer's avatar
Michael Natterer committed
198
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
199

200 201
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

202
  value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
203

204
  if (value != 0 /* not Other... */)
205 206 207 208
    {
      if (fabs (value - shell->scale) > 0.0001)
        gimp_display_shell_scale (shell, GIMP_ZOOM_TO, (gdouble) value / 10000);
    }
209 210
}

211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
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
231
void
232
view_dot_for_dot_cmd_callback (GtkAction *action,
233
                               gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
234
{
235 236
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
237
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
238
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
239

240 241
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

242 243 244
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  if (active != shell->dot_for_dot)
245
    {
246
      gimp_display_shell_scale_set_dot_for_dot (shell, active);
247

248
      SET_ACTIVE (shell->menubar_manager, "view-dot-for-dot",
249
                  shell->dot_for_dot);
250 251

      if (IS_ACTIVE_DISPLAY (gdisp))
252
        SET_ACTIVE (shell->popup_manager, "view-dot-for-dot",
253
                    shell->dot_for_dot);
254
    }
Michael Natterer's avatar
Michael Natterer committed
255 256
}

257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
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
303
void
304
view_info_window_cmd_callback (GtkAction *action,
305
                               gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
306
{
Michael Natterer's avatar
Michael Natterer committed
307 308
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
309
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
310

Michael Natterer's avatar
Michael Natterer committed
311 312
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

313
  if (GIMP_GUI_CONFIG (gdisp->gimage->gimp->config)->info_window_per_display)
Michael Natterer's avatar
Michael Natterer committed
314
    {
Michael Natterer's avatar
Michael Natterer committed
315
      if (! shell->info_dialog)
316
        shell->info_dialog = info_window_create (gdisp);
Michael Natterer's avatar
Michael Natterer committed
317

Sven Neumann's avatar
Sven Neumann committed
318 319 320 321 322
      /* 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);

323
      info_dialog_present (shell->info_dialog);
Michael Natterer's avatar
Michael Natterer committed
324 325 326
    }
  else
    {
Michael Natterer's avatar
Michael Natterer committed
327
      info_window_follow_auto (gdisp->gimage->gimp);
Michael Natterer's avatar
Michael Natterer committed
328 329 330 331
    }
}

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

Michael Natterer's avatar
Michael Natterer committed
339 340
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

Michael Natterer's avatar
Michael Natterer committed
341
  gimp_dialog_factory_dialog_raise (global_dock_factory,
342
                                    gtk_widget_get_screen (gdisp->shell),
Michael Natterer's avatar
Michael Natterer committed
343
                                    "gimp-navigation-view", -1);
Michael Natterer's avatar
Michael Natterer committed
344 345
}

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

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

356 357 358 359 360 361 362 363 364 365
  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));
366 367
}

Michael Natterer's avatar
Michael Natterer committed
368
void
369
view_toggle_selection_cmd_callback (GtkAction *action,
370
                                    gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
371
{
372 373
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
374
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
375
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
376

377 378
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

379 380 381
  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
382 383 384
}

void
385
view_toggle_layer_boundary_cmd_callback (GtkAction *action,
Michael Natterer's avatar
Michael Natterer committed
386 387 388 389
                                         gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
390
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
391 392 393 394
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

395 396 397
  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
398 399
}

400
void
401
view_toggle_menubar_cmd_callback (GtkAction *action,
402 403 404 405
                                  gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
406
  gboolean          active;
407 408 409 410
  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_show_menubar (shell, active);
414 415
}

Michael Natterer's avatar
Michael Natterer committed
416
void
417
view_toggle_rulers_cmd_callback (GtkAction *action,
418
                                 gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
419
{
420 421
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
422
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
423
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
424

Michael Natterer's avatar
Michael Natterer committed
425 426
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

427 428 429
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_show_rulers (shell, active);
430
}
431

432
void
433
view_toggle_scrollbars_cmd_callback (GtkAction *action,
434 435 436 437
                                     gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
438
  gboolean          active;
439
  return_if_no_display (gdisp, data);
440

441 442
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

443 444 445
  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
446 447 448
}

void
449
view_toggle_statusbar_cmd_callback (GtkAction *action,
450
                                    gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
451
{
Michael Natterer's avatar
Michael Natterer committed
452 453
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
454
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
455
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
456

Michael Natterer's avatar
Michael Natterer committed
457 458
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

459 460 461
  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
462 463 464
}

void
465
view_toggle_guides_cmd_callback (GtkAction *action,
466
                                 gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
467
{
468 469
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
470
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
471
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
472

473 474
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

475 476 477
  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
478 479 480
}

void
481
view_snap_to_guides_cmd_callback (GtkAction *action,
482
                                  gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
483
{
484 485
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
486
  gboolean          active;
Michael Natterer's avatar
Michael Natterer committed
487
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
488

489
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);
490

491
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
492

493
  gimp_display_shell_set_snap_to_guides (shell, active);
Michael Natterer's avatar
Michael Natterer committed
494 495
}

496 497

void
498
view_toggle_grid_cmd_callback (GtkAction *action,
499 500 501 502
                               gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
503
  gboolean          active;
504 505 506 507
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

508
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
509

510
  gimp_display_shell_set_show_grid (shell, active);
511 512 513
}

void
514
view_snap_to_grid_cmd_callback (GtkAction *action,
515 516 517 518
                                gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
519
  gboolean          active;
520 521 522 523
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

524
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
525

526
  gimp_display_shell_set_snap_to_grid (shell, active);
527 528
}

529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
void
view_snap_to_canvas_cmd_callback (GtkAction *action,
                                  gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  gboolean          active;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_snap_to_canvas (shell, active);
}

void
view_snap_to_vectors_cmd_callback (GtkAction *action,
                                   gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  gboolean          active;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_snap_to_vectors (shell, active);
}

561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585
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:
586
      g_object_set_data (G_OBJECT (shell), "padding-color-dialog", NULL);
587 588 589 590 591 592 593 594 595

      options->padding_mode_set = TRUE;

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

    case GIMP_CANVAS_PADDING_MODE_CUSTOM:
      {
596
        GtkWidget *color_dialog;
597

598
        color_dialog = g_object_get_data (G_OBJECT (shell),
599
                                          "padding-color-dialog");
600

601
        if (! color_dialog)
602
          {
603 604 605 606 607 608 609 610 611 612 613 614 615
            color_dialog = gimp_color_dialog_new (GIMP_VIEWABLE (gdisp->gimage),
                                                  _("Set Canvas Padding Color"),
                                                  GTK_STOCK_SELECT_COLOR,
                                                  _("Set Custom Canvas Padding Color"),
                                                  gdisp->shell,
                                                  NULL, NULL,
                                                  &options->padding_color,
                                                  FALSE, FALSE);

            g_signal_connect (color_dialog, "update",
                              G_CALLBACK (view_padding_color_dialog_update),
                              gdisp->shell);

616 617
            g_object_set_data_full (G_OBJECT (shell), "padding-color-dialog",
                                    color_dialog,
618
                                    (GDestroyNotify) gtk_widget_destroy);
619 620
          }

621
        gtk_window_present (GTK_WINDOW (color_dialog));
622 623 624 625
      }
      break;

    case GIMP_CANVAS_PADDING_MODE_RESET:
626
      g_object_set_data (G_OBJECT (shell), "padding-color-dialog", NULL);
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648

      {
        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
649
void
650
view_shrink_wrap_cmd_callback (GtkAction *action,
651
                               gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
652
{
653
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
654
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
655

Michael Natterer's avatar
Michael Natterer committed
656
  gimp_display_shell_scale_shrink_wrap (GIMP_DISPLAY_SHELL (gdisp->shell));
Michael Natterer's avatar
Michael Natterer committed
657
}
658 659

void
660
view_fullscreen_cmd_callback (GtkAction *action,
661
                              gpointer   data)
662 663 664
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
665
  gboolean          active;
666 667 668 669
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

670 671 672
  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

  gimp_display_shell_set_fullscreen (shell, active);
673 674 675
}

void
676
view_change_screen_cmd_callback (GtkAction *action,
677 678 679 680 681 682 683
                                 gpointer   data)
{
  GimpDisplay *gdisp;
  GdkScreen   *screen;
  GdkDisplay  *display;
  gint         cur_screen;
  gint         num_screens;
684
  GtkWidget   *dialog;
685 686
  return_if_no_display (gdisp, data);

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

690
  if (dialog)
691
    {
692
      gtk_window_present (GTK_WINDOW (dialog));
693 694 695 696 697 698 699 700 701
      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);

702 703
  dialog = gimp_query_int_box ("Move Display to Screen",
                               gdisp->shell,
704
                               NULL, NULL,
705 706 707 708 709
                               "Enter destination screen",
                               cur_screen, 0, num_screens - 1,
                               G_OBJECT (gdisp->shell), "destroy",
                               view_change_screen_confirm_callback,
                               gdisp->shell);
710

711 712
  g_object_set_data (G_OBJECT (gdisp->shell), "gimp-change-screen-dialog",
                     dialog);
713

714
  g_signal_connect (dialog, "destroy",
715 716 717
                    G_CALLBACK (view_change_screen_destroy_callback),
                    gdisp->shell);

718
  gtk_widget_show (dialog);
719
}
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758


/*  private functions  */

static void
view_padding_color_dialog_update (GimpColorDialog      *dialog,
                                  const GimpRGB        *color,
                                  GimpColorDialogState  state,
                                  GimpDisplayShell     *shell)
{
  GimpDisplayOptions *options;
  gboolean            fullscreen;

  fullscreen = gimp_display_shell_get_fullscreen (shell);

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

  switch (state)
    {
    case GIMP_COLOR_DIALOG_OK:
      options->padding_mode_set = TRUE;

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

    case GIMP_COLOR_DIALOG_CANCEL:
      g_object_set_data (G_OBJECT (shell), "padding-color-dialog", NULL);
      break;

    default:
      break;
    }
}

static void
759
view_change_screen_confirm_callback (GtkWidget *dialog,
760 761 762 763 764 765 766 767 768 769 770 771 772
                                     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
773
view_change_screen_destroy_callback (GtkWidget *dialog,
774 775 776 777
                                     GtkWidget *shell)
{
  g_object_set_data (G_OBJECT (shell), "gimp-change-screen-dialog", NULL);
}