gimpdisplayshell-appearance.c 17.2 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7 8 9 10 11 12 13 14
 * (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
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19
 */

#include "config.h"

20
#include <gegl.h>
21 22 23 24 25 26 27
#include <gtk/gtk.h>

#include "libgimpcolor/gimpcolor.h"
#include "libgimpwidgets/gimpwidgets.h"

#include "display-types.h"

28 29
#include "config/gimpdisplayoptions.h"

30 31
#include "core/gimp.h"
#include "core/gimpcontext.h"
32 33
#include "core/gimpimage.h"

34
#include "widgets/gimpactiongroup.h"
35
#include "widgets/gimprender.h"
36
#include "widgets/gimpuimanager.h"
37
#include "widgets/gimpwidgets-utils.h"
38

39
#include "gimpcanvas.h"
40
#include "gimpcanvasitem.h"
41
#include "gimpdisplay.h"
42 43
#include "gimpdisplayshell.h"
#include "gimpdisplayshell-appearance.h"
44
#include "gimpdisplayshell-expose.h"
45
#include "gimpdisplayshell-selection.h"
46
#include "gimpimagewindow.h"
47
#include "gimpstatusbar.h"
48 49


50
/*  local function prototypes  */
51

52
static GimpDisplayOptions *
53
              appearance_get_options       (GimpDisplayShell       *shell);
54 55 56 57 58 59
static void   appearance_set_action_active (GimpDisplayShell       *shell,
                                            const gchar            *action,
                                            gboolean                active);
static void   appearance_set_action_color  (GimpDisplayShell       *shell,
                                            const gchar            *action,
                                            const GimpRGB          *color);
60

61

62
/*  public functions  */
63

64 65 66 67
void
gimp_display_shell_appearance_update (GimpDisplayShell *shell)
{
  GimpDisplayOptions *options;
68
  GimpImageWindow    *window;
69 70 71

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

72 73
  options = appearance_get_options (shell);
  window  = gimp_display_shell_get_window (shell);
74

75
  if (window)
76 77 78 79 80 81 82 83
    {
      gboolean fullscreen = gimp_image_window_get_fullscreen (window);

      appearance_set_action_active (shell, "view-fullscreen", fullscreen);

      gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (shell->statusbar),
                                         ! fullscreen);
    }
84 85 86

  gimp_display_shell_set_show_menubar       (shell,
                                             options->show_menubar);
87 88 89
  gimp_display_shell_set_show_statusbar     (shell,
                                             options->show_statusbar);

90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
  gimp_display_shell_set_show_rulers        (shell,
                                             options->show_rulers);
  gimp_display_shell_set_show_scrollbars    (shell,
                                             options->show_scrollbars);
  gimp_display_shell_set_show_selection     (shell,
                                             options->show_selection);
  gimp_display_shell_set_show_layer         (shell,
                                             options->show_layer_boundary);
  gimp_display_shell_set_show_guides        (shell,
                                             options->show_guides);
  gimp_display_shell_set_show_grid          (shell,
                                             options->show_grid);
  gimp_display_shell_set_show_sample_points (shell,
                                             options->show_sample_points);
  gimp_display_shell_set_padding            (shell,
                                             options->padding_mode,
                                             &options->padding_color);
}

109
void
110 111
gimp_display_shell_set_show_menubar (GimpDisplayShell *shell,
                                     gboolean          show)
112
{
113
  GimpDisplayOptions *options;
114
  GimpImageWindow    *window;
115 116 117

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

118 119
  options = appearance_get_options (shell);
  window  = gimp_display_shell_get_window (shell);
120

121
  g_object_set (options, "show-menubar", show, NULL);
122

123
  if (window && gimp_image_window_get_active_shell (window) == shell)
124
    {
125
      gimp_image_window_keep_canvas_pos (gimp_display_shell_get_window (shell));
126
      gimp_image_window_set_show_menubar (window, show);
127
    }
128

129
  appearance_set_action_active (shell, "view-show-menubar", show);
130 131 132
}

gboolean
133
gimp_display_shell_get_show_menubar (GimpDisplayShell *shell)
134 135 136
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

137
  return appearance_get_options (shell)->show_menubar;
138 139
}

140 141 142 143 144 145 146 147
void
gimp_display_shell_set_show_statusbar (GimpDisplayShell *shell,
                                       gboolean          show)
{
  GimpDisplayOptions *options;

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

148
  options = appearance_get_options (shell);
149 150 151

  g_object_set (options, "show-statusbar", show, NULL);

152
  gimp_image_window_keep_canvas_pos (gimp_display_shell_get_window (shell));
153
  gimp_statusbar_set_visible (GIMP_STATUSBAR (shell->statusbar), show);
154 155 156 157 158

  appearance_set_action_active (shell, "view-show-statusbar", show);
}

gboolean
159
gimp_display_shell_get_show_statusbar (GimpDisplayShell *shell)
160 161 162 163 164 165
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

  return appearance_get_options (shell)->show_statusbar;
}

166
void
167 168
gimp_display_shell_set_show_rulers (GimpDisplayShell *shell,
                                    gboolean          show)
169
{
170
  GimpDisplayOptions *options;
171 172 173

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

174
  options = appearance_get_options (shell);
175 176

  g_object_set (options, "show-rulers", show, NULL);
177

178
  gimp_image_window_keep_canvas_pos (gimp_display_shell_get_window (shell));
179 180 181
  gtk_widget_set_visible (shell->origin, show);
  gtk_widget_set_visible (shell->hrule, show);
  gtk_widget_set_visible (shell->vrule, show);
182

183
  appearance_set_action_active (shell, "view-show-rulers", show);
184 185 186
}

gboolean
187
gimp_display_shell_get_show_rulers (GimpDisplayShell *shell)
188 189 190
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

191
  return appearance_get_options (shell)->show_rulers;
192 193
}

194
void
195 196
gimp_display_shell_set_show_scrollbars (GimpDisplayShell *shell,
                                        gboolean          show)
197
{
198
  GimpDisplayOptions *options;
199 200 201

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

202
  options = appearance_get_options (shell);
203

204
  g_object_set (options, "show-scrollbars", show, NULL);
205

206
  gimp_image_window_keep_canvas_pos (gimp_display_shell_get_window (shell));
207 208 209 210 211 212
  gtk_widget_set_visible (shell->nav_ebox, show);
  gtk_widget_set_visible (shell->hsb, show);
  gtk_widget_set_visible (shell->vsb, show);
  gtk_widget_set_visible (shell->quick_mask_button, show);
  gtk_widget_set_visible (shell->zoom_button, show);

213
  appearance_set_action_active (shell, "view-show-scrollbars", show);
214 215 216
}

gboolean
217
gimp_display_shell_get_show_scrollbars (GimpDisplayShell *shell)
218 219 220
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

221
  return appearance_get_options (shell)->show_scrollbars;
222 223
}

224
void
225 226
gimp_display_shell_set_show_selection (GimpDisplayShell *shell,
                                       gboolean          show)
227
{
228
  GimpDisplayOptions *options;
229 230 231

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

232
  options = appearance_get_options (shell);
233

234
  g_object_set (options, "show-selection", show, NULL);
235

Sven Neumann's avatar
Sven Neumann committed
236
  gimp_display_shell_selection_set_hidden (shell, ! show);
237

238
  appearance_set_action_active (shell, "view-show-selection", show);
239 240 241
}

gboolean
242
gimp_display_shell_get_show_selection (GimpDisplayShell *shell)
243 244 245
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

246
  return appearance_get_options (shell)->show_selection;
247 248
}

249
void
250 251
gimp_display_shell_set_show_layer (GimpDisplayShell *shell,
                                   gboolean          show)
252
{
253
  GimpDisplayOptions *options;
254 255 256

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

257
  options = appearance_get_options (shell);
258

259
  g_object_set (options, "show-layer-boundary", show, NULL);
260

261
  gimp_display_shell_selection_set_layer_hidden (shell, ! show);
262

263
  appearance_set_action_active (shell, "view-show-layer-boundary", show);
264 265 266
}

gboolean
267
gimp_display_shell_get_show_layer (GimpDisplayShell *shell)
268 269 270
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

271
  return appearance_get_options (shell)->show_layer_boundary;
272 273
}

274 275 276 277 278 279 280 281 282 283
void
gimp_display_shell_set_show_transform (GimpDisplayShell *shell,
                                       gboolean          show)
{
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

  shell->show_transform_preview = show;
}

gboolean
284
gimp_display_shell_get_show_transform (GimpDisplayShell *shell)
285 286 287 288 289 290
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

  return shell->show_transform_preview;
}

291
void
292 293
gimp_display_shell_set_show_guides (GimpDisplayShell *shell,
                                    gboolean          show)
294
{
295
  GimpDisplayOptions *options;
296 297 298

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

299
  options = appearance_get_options (shell);
300

301
  g_object_set (options, "show-guides", show, NULL);
302

303
  gimp_canvas_item_set_visible (shell->guides, show);
304

305
  appearance_set_action_active (shell, "view-show-guides", show);
306 307 308
}

gboolean
309
gimp_display_shell_get_show_guides (GimpDisplayShell *shell)
310 311 312
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

313
  return appearance_get_options (shell)->show_guides;
314 315 316
}

void
317 318
gimp_display_shell_set_show_grid (GimpDisplayShell *shell,
                                  gboolean          show)
319
{
320
  GimpDisplayOptions *options;
321 322 323

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

324
  options = appearance_get_options (shell);
325

326
  g_object_set (options, "show-grid", show, NULL);
327

328
  gimp_canvas_item_set_visible (shell->grid, show);
329

330
  appearance_set_action_active (shell, "view-show-grid", show);
331 332 333
}

gboolean
334
gimp_display_shell_get_show_grid (GimpDisplayShell *shell)
335 336 337
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

338
  return appearance_get_options (shell)->show_grid;
339 340
}

341 342 343 344 345 346 347 348
void
gimp_display_shell_set_show_sample_points (GimpDisplayShell *shell,
                                           gboolean          show)
{
  GimpDisplayOptions *options;

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

349
  options = appearance_get_options (shell);
350 351 352

  g_object_set (options, "show-sample-points", show, NULL);

353
  gimp_canvas_item_set_visible (shell->sample_points, show);
354

355
  appearance_set_action_active (shell, "view-show-sample-points", show);
356 357 358
}

gboolean
359
gimp_display_shell_get_show_sample_points (GimpDisplayShell *shell)
360 361 362
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

363
  return appearance_get_options (shell)->show_sample_points;
364 365
}

366 367 368 369 370 371 372 373 374 375
void
gimp_display_shell_set_snap_to_grid (GimpDisplayShell *shell,
                                     gboolean          snap)
{
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

  if (snap != shell->snap_to_grid)
    {
      shell->snap_to_grid = snap ? TRUE : FALSE;

376
      appearance_set_action_active (shell, "view-snap-to-grid", snap);
377 378 379 380
    }
}

gboolean
381
gimp_display_shell_get_snap_to_grid (GimpDisplayShell *shell)
382 383 384 385 386 387
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

  return shell->snap_to_grid;
}

388 389 390 391 392 393 394 395 396 397
void
gimp_display_shell_set_snap_to_guides (GimpDisplayShell *shell,
                                       gboolean          snap)
{
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

  if (snap != shell->snap_to_guides)
    {
      shell->snap_to_guides = snap ? TRUE : FALSE;

398
      appearance_set_action_active (shell, "view-snap-to-guides", snap);
399 400 401 402
    }
}

gboolean
403
gimp_display_shell_get_snap_to_guides (GimpDisplayShell *shell)
404 405 406 407 408 409
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

  return shell->snap_to_guides;
}

410 411 412 413 414 415 416 417 418 419
void
gimp_display_shell_set_snap_to_canvas (GimpDisplayShell *shell,
                                       gboolean          snap)
{
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

  if (snap != shell->snap_to_canvas)
    {
      shell->snap_to_canvas = snap ? TRUE : FALSE;

420
      appearance_set_action_active (shell, "view-snap-to-canvas", snap);
421 422 423 424
    }
}

gboolean
425
gimp_display_shell_get_snap_to_canvas (GimpDisplayShell *shell)
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

  return shell->snap_to_canvas;
}

void
gimp_display_shell_set_snap_to_vectors (GimpDisplayShell *shell,
                                        gboolean          snap)
{
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

  if (snap != shell->snap_to_vectors)
    {
      shell->snap_to_vectors = snap ? TRUE : FALSE;

442
      appearance_set_action_active (shell, "view-snap-to-vectors", snap);
443 444 445 446
    }
}

gboolean
447
gimp_display_shell_get_snap_to_vectors (GimpDisplayShell *shell)
448 449 450 451 452 453
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

  return shell->snap_to_vectors;
}

454
void
455 456 457
gimp_display_shell_set_padding (GimpDisplayShell      *shell,
                                GimpCanvasPaddingMode  padding_mode,
                                const GimpRGB         *padding_color)
458
{
459
  GimpDisplayOptions *options;
460
  GimpRGB             color;
461 462 463 464

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
  g_return_if_fail (padding_color != NULL);

465
  options = appearance_get_options (shell);
466
  color   = *padding_color;
467

468
  switch (padding_mode)
469
    {
470
    case GIMP_CANVAS_PADDING_MODE_DEFAULT:
471 472
      if (shell->canvas)
        {
473 474
          GtkStyle *style;

475
          gtk_widget_ensure_style (shell->canvas);
476 477 478 479

          style = gtk_widget_get_style (shell->canvas);

          gimp_rgb_set_gdk_color (&color, style->bg + GTK_STATE_NORMAL);
480 481 482
        }
      break;

483
    case GIMP_CANVAS_PADDING_MODE_LIGHT_CHECK:
484
      color = *gimp_render_light_check_color ();
485 486
      break;

487
    case GIMP_CANVAS_PADDING_MODE_DARK_CHECK:
488
      color = *gimp_render_dark_check_color ();
489 490
      break;

491
    case GIMP_CANVAS_PADDING_MODE_CUSTOM:
492
    case GIMP_CANVAS_PADDING_MODE_RESET:
493 494 495
      break;
    }

496 497 498 499 500
  g_object_set (options,
                "padding-mode",  padding_mode,
                "padding-color", &color,
                NULL);

501
  gimp_canvas_set_bg_color (GIMP_CANVAS (shell->canvas), &color);
502

503 504
  appearance_set_action_color (shell, "view-padding-color-menu",
                               &options->padding_color);
505 506 507 508 509

  gimp_display_shell_expose_full (shell);
}

void
510
gimp_display_shell_get_padding (GimpDisplayShell       *shell,
511 512
                                GimpCanvasPaddingMode  *padding_mode,
                                GimpRGB                *padding_color)
513
{
514
  GimpDisplayOptions *options;
515 516 517

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

518
  options = appearance_get_options (shell);
519 520

  if (padding_mode)
521
    *padding_mode = options->padding_mode;
522 523

  if (padding_color)
524
    *padding_color = options->padding_color;
525
}
526 527 528 529 530


/*  private functions  */

static GimpDisplayOptions *
531
appearance_get_options (GimpDisplayShell *shell)
532
{
533
  if (gimp_display_get_image (shell->display))
534
    {
535
      GimpImageWindow *window = gimp_display_shell_get_window (shell);
536

537
      if (window && gimp_image_window_get_fullscreen (window))
538 539 540 541 542 543 544 545 546 547 548 549 550
        return shell->fullscreen_options;
      else
        return shell->options;
    }

  return shell->no_image_options;
}

static void
appearance_set_action_active (GimpDisplayShell *shell,
                              const gchar      *action,
                              gboolean          active)
{
551
  GimpImageWindow *window = gimp_display_shell_get_window (shell);
552 553
  GimpContext     *context;

554
  if (window && gimp_image_window_get_active_shell (window) == shell)
555
    {
556
      GimpUIManager   *manager = gimp_image_window_get_ui_manager (window);
557 558
      GimpActionGroup *action_group;

559
      action_group = gimp_ui_manager_get_action_group (manager, "view");
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583

      if (action_group)
        gimp_action_group_set_action_active (action_group, action, active);
    }

  context = gimp_get_user_context (shell->display->gimp);

  if (shell->display == gimp_context_get_display (context))
    {
      GimpActionGroup *action_group;

      action_group = gimp_ui_manager_get_action_group (shell->popup_manager,
                                                       "view");

      if (action_group)
        gimp_action_group_set_action_active (action_group, action, active);
    }
}

static void
appearance_set_action_color (GimpDisplayShell *shell,
                             const gchar      *action,
                             const GimpRGB    *color)
{
584
  GimpImageWindow *window = gimp_display_shell_get_window (shell);
585 586
  GimpContext     *context;

587
  if (window && gimp_image_window_get_active_shell (window) == shell)
588
    {
589
      GimpUIManager   *manager = gimp_image_window_get_ui_manager (window);
590 591
      GimpActionGroup *action_group;

592
      action_group = gimp_ui_manager_get_action_group (manager, "view");
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610

      if (action_group)
        gimp_action_group_set_action_color (action_group, action, color, FALSE);
    }

  context = gimp_get_user_context (shell->display->gimp);

  if (shell->display == gimp_context_get_display (context))
    {
      GimpActionGroup *action_group;

      action_group = gimp_ui_manager_get_action_group (shell->popup_manager,
                                                       "view");

      if (action_group)
        gimp_action_group_set_action_color (action_group, action, color, FALSE);
    }
}