gimpdisplayshell-appearance.c 17.3 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 * 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 "libgimpcolor/gimpcolor.h"
#include "libgimpwidgets/gimpwidgets.h"

#include "display-types.h"

28 29
#include "core/gimp.h"
#include "core/gimpcontext.h"
30
#include "core/gimpimage.h"
31
#include "core/gimpimage-grid.h"
32 33
#include "core/gimpimage-guides.h"
#include "core/gimpimage-sample-points.h"
34

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

40
#include "gimpcanvas.h"
41
#include "gimpdisplay.h"
42
#include "gimpdisplayoptions.h"
43 44
#include "gimpdisplayshell.h"
#include "gimpdisplayshell-appearance.h"
45
#include "gimpdisplayshell-selection.h"
46
#include "gimpstatusbar.h"
47 48


49
#define GET_OPTIONS(shell) \
50 51 52 53
  (shell->display->image ? \
   (gimp_display_shell_get_fullscreen (shell) ? \
    shell->fullscreen_options : shell->options) : \
   shell->no_image_options)
54

55
#define SET_ACTIVE(manager,action_name,active) \
56
  { GimpActionGroup *group = \
57
      gimp_ui_manager_get_action_group (manager, "view"); \
58 59
    gimp_action_group_set_action_active (group, action_name, active); }

60 61 62 63 64
#define SET_COLOR(manager,action_name,color) \
  { GimpActionGroup *group = \
      gimp_ui_manager_get_action_group (manager, "view"); \
    gimp_action_group_set_action_color (group, action_name, color, FALSE); }

65
#define IS_ACTIVE_DISPLAY(shell) \
66
  ((shell)->display == \
67
   gimp_context_get_display (gimp_get_user_context \
68
                             ((shell)->display->gimp)))
69 70


71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
void
gimp_display_shell_appearance_update (GimpDisplayShell *shell)
{
  GimpDisplayOptions *options;

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

  options = GET_OPTIONS (shell);

  gtk_widget_set_name (GTK_WIDGET (shell->menubar),
                       gimp_display_shell_get_fullscreen (shell) ?
                       "gimp-menubar-fullscreen" : NULL);

  gimp_display_shell_set_show_menubar       (shell,
                                             options->show_menubar);
  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_statusbar     (shell,
                                             options->show_statusbar);
  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);
}

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
void
gimp_display_shell_set_fullscreen (GimpDisplayShell *shell,
                                   gboolean          fullscreen)
{
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

  if (fullscreen != gimp_display_shell_get_fullscreen (shell))
    {
      if (fullscreen)
        gtk_window_fullscreen (GTK_WINDOW (shell));
      else
        gtk_window_unfullscreen (GTK_WINDOW (shell));
    }
}

gboolean
gimp_display_shell_get_fullscreen (GimpDisplayShell *shell)
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

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

130
void
131 132
gimp_display_shell_set_show_menubar (GimpDisplayShell *shell,
                                     gboolean          show)
133
{
134
  GimpDisplayOptions *options;
135 136 137

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

138
  options = GET_OPTIONS (shell);
139

140
  g_object_set (options, "show-menubar", show, NULL);
141

142 143 144 145 146 147 148
  if (shell->menubar)
    {
      if (show)
        gtk_widget_show (shell->menubar);
      else
        gtk_widget_hide (shell->menubar);
    }
149

150
  SET_ACTIVE (shell->menubar_manager, "view-show-menubar", show);
151 152

  if (IS_ACTIVE_DISPLAY (shell))
153
    SET_ACTIVE (shell->popup_manager, "view-show-menubar", show);
154 155 156
}

gboolean
157
gimp_display_shell_get_show_menubar (GimpDisplayShell *shell)
158 159 160
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

161
  return GET_OPTIONS (shell)->show_menubar;
162 163 164
}

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

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

173 174 175
  options = GET_OPTIONS (shell);

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

177
  table = GTK_TABLE (GTK_WIDGET (shell->canvas)->parent);
178 179

  if (show)
180
    {
181
      gtk_widget_show (shell->origin);
182 183
      gtk_widget_show (shell->hrule);
      gtk_widget_show (shell->vrule);
184

185 186 187 188 189
      gtk_table_set_col_spacing (table, 0, 1);
      gtk_table_set_row_spacing (table, 0, 1);
    }
  else
    {
190
      gtk_widget_hide (shell->origin);
191 192
      gtk_widget_hide (shell->hrule);
      gtk_widget_hide (shell->vrule);
193

194 195
      gtk_table_set_col_spacing (table, 0, 0);
      gtk_table_set_row_spacing (table, 0, 0);
196
    }
197

198
  SET_ACTIVE (shell->menubar_manager, "view-show-rulers", show);
199 200

  if (IS_ACTIVE_DISPLAY (shell))
201
    SET_ACTIVE (shell->popup_manager, "view-show-rulers", show);
202 203 204
}

gboolean
205
gimp_display_shell_get_show_rulers (GimpDisplayShell *shell)
206 207 208
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

209
  return GET_OPTIONS (shell)->show_rulers;
210 211
}

212
void
213 214
gimp_display_shell_set_show_scrollbars (GimpDisplayShell *shell,
                                        gboolean          show)
215
{
216 217 218
  GimpDisplayOptions *options;
  GtkBox             *hbox;
  GtkBox             *vbox;
219 220 221

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

222
  options = GET_OPTIONS (shell);
223

224
  g_object_set (options, "show-scrollbars", show, NULL);
225

226 227
  hbox = GTK_BOX (shell->vsb->parent->parent);
  vbox = GTK_BOX (shell->hsb->parent->parent);
228

229 230 231 232 233
  if (show)
    {
      gtk_widget_show (shell->nav_ebox);
      gtk_widget_show (shell->hsb);
      gtk_widget_show (shell->vsb);
234
      gtk_widget_show (shell->quick_mask_button);
235
      gtk_widget_show (shell->zoom_button);
236 237 238

      gtk_box_set_spacing (hbox, 1);
      gtk_box_set_spacing (vbox, 1);
239
    }
240 241 242 243 244
  else
    {
      gtk_widget_hide (shell->nav_ebox);
      gtk_widget_hide (shell->hsb);
      gtk_widget_hide (shell->vsb);
245
      gtk_widget_hide (shell->quick_mask_button);
246
      gtk_widget_hide (shell->zoom_button);
247 248 249 250 251

      gtk_box_set_spacing (hbox, 0);
      gtk_box_set_spacing (vbox, 0);
    }

252
  SET_ACTIVE (shell->menubar_manager, "view-show-scrollbars", show);
253 254

  if (IS_ACTIVE_DISPLAY (shell))
255
    SET_ACTIVE (shell->popup_manager, "view-show-scrollbars", show);
256 257 258
}

gboolean
259
gimp_display_shell_get_show_scrollbars (GimpDisplayShell *shell)
260 261 262
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

263
  return GET_OPTIONS (shell)->show_scrollbars;
264 265 266
}

void
267 268
gimp_display_shell_set_show_statusbar (GimpDisplayShell *shell,
                                       gboolean          show)
269
{
270 271
  GimpDisplayOptions *options;

272 273
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

274
  options = GET_OPTIONS (shell);
275

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

278
  gimp_statusbar_set_visible (GIMP_STATUSBAR (shell->statusbar), show);
279

280
  SET_ACTIVE (shell->menubar_manager, "view-show-statusbar", show);
281 282

  if (IS_ACTIVE_DISPLAY (shell))
283
    SET_ACTIVE (shell->popup_manager, "view-show-statusbar", show);
284 285 286
}

gboolean
287
gimp_display_shell_get_show_statusbar (GimpDisplayShell *shell)
288 289 290
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

291
  return GET_OPTIONS (shell)->show_statusbar;
292 293
}

294
void
295 296
gimp_display_shell_set_show_selection (GimpDisplayShell *shell,
                                       gboolean          show)
297
{
298
  GimpDisplayOptions *options;
299 300 301

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

302
  options = GET_OPTIONS (shell);
303

304
  g_object_set (options, "show-selection", show, NULL);
305

Sven Neumann's avatar
Sven Neumann committed
306
  gimp_display_shell_selection_set_hidden (shell, ! show);
307

308
  SET_ACTIVE (shell->menubar_manager, "view-show-selection", show);
309 310

  if (IS_ACTIVE_DISPLAY (shell))
311
    SET_ACTIVE (shell->popup_manager, "view-show-selection", show);
312 313 314
}

gboolean
315
gimp_display_shell_get_show_selection (GimpDisplayShell *shell)
316 317 318
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

319
  return GET_OPTIONS (shell)->show_selection;
320 321
}

322
void
323 324
gimp_display_shell_set_show_layer (GimpDisplayShell *shell,
                                   gboolean          show)
325
{
326
  GimpDisplayOptions *options;
327 328 329

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

330
  options = GET_OPTIONS (shell);
331

332
  g_object_set (options, "show-layer-boundary", show, NULL);
333

Sven Neumann's avatar
Sven Neumann committed
334
  gimp_display_shell_selection_layer_set_hidden (shell, ! show);
335

336
  SET_ACTIVE (shell->menubar_manager, "view-show-layer-boundary", show);
337 338

  if (IS_ACTIVE_DISPLAY (shell))
339
    SET_ACTIVE (shell->popup_manager, "view-show-layer-boundary", show);
340 341 342
}

gboolean
343
gimp_display_shell_get_show_layer (GimpDisplayShell *shell)
344 345 346
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

347
  return GET_OPTIONS (shell)->show_layer_boundary;
348 349
}

350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
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
gimp_display_shell_get_show_transform (GimpDisplayShell *shell)
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

  return shell->show_transform_preview;
}

367
void
368 369
gimp_display_shell_set_show_guides (GimpDisplayShell *shell,
                                    gboolean          show)
370
{
371
  GimpDisplayOptions *options;
372 373 374

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

375
  options = GET_OPTIONS (shell);
376

377
  g_object_set (options, "show-guides", show, NULL);
378

379 380 381 382 383
  if (shell->display->image &&
      gimp_image_get_guides (shell->display->image))
    {
      gimp_display_shell_expose_full (shell);
    }
384

385
  SET_ACTIVE (shell->menubar_manager, "view-show-guides", show);
386 387

  if (IS_ACTIVE_DISPLAY (shell))
388
    SET_ACTIVE (shell->popup_manager, "view-show-guides", show);
389 390 391
}

gboolean
392
gimp_display_shell_get_show_guides (GimpDisplayShell *shell)
393 394 395
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

396
  return GET_OPTIONS (shell)->show_guides;
397 398 399
}

void
400 401
gimp_display_shell_set_show_grid (GimpDisplayShell *shell,
                                  gboolean          show)
402
{
403
  GimpDisplayOptions *options;
404 405 406

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

407
  options = GET_OPTIONS (shell);
408

409
  g_object_set (options, "show-grid", show, NULL);
410

411 412 413 414 415
  if (shell->display->image &&
      gimp_image_get_grid (shell->display->image))
    {
      gimp_display_shell_expose_full (shell);
    }
416

417
  SET_ACTIVE (shell->menubar_manager, "view-show-grid", show);
418 419

  if (IS_ACTIVE_DISPLAY (shell))
420
    SET_ACTIVE (shell->popup_manager, "view-show-grid", show);
421 422 423
}

gboolean
424
gimp_display_shell_get_show_grid (GimpDisplayShell *shell)
425 426 427
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

428
  return GET_OPTIONS (shell)->show_grid;
429 430
}

431 432 433 434 435 436 437 438 439 440 441 442
void
gimp_display_shell_set_show_sample_points (GimpDisplayShell *shell,
                                           gboolean          show)
{
  GimpDisplayOptions *options;

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

  options = GET_OPTIONS (shell);

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

443 444 445 446 447
  if (shell->display->image &&
      gimp_image_get_sample_points (shell->display->image))
    {
      gimp_display_shell_expose_full (shell);
    }
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462

  SET_ACTIVE (shell->menubar_manager, "view-show-sample-points", show);

  if (IS_ACTIVE_DISPLAY (shell))
    SET_ACTIVE (shell->popup_manager, "view-show-sample-points", show);
}

gboolean
gimp_display_shell_get_show_sample_points (GimpDisplayShell *shell)
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

  return GET_OPTIONS (shell)->show_sample_points;
}

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
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;

      SET_ACTIVE (shell->menubar_manager, "view-snap-to-grid", snap);

      if (IS_ACTIVE_DISPLAY (shell))
        SET_ACTIVE (shell->popup_manager, "view-snap-to-grid", snap);
    }
}

gboolean
gimp_display_shell_get_snap_to_grid (GimpDisplayShell *shell)
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

  return shell->snap_to_grid;
}

488 489 490 491 492 493 494 495 496 497
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;

498
      SET_ACTIVE (shell->menubar_manager, "view-snap-to-guides", snap);
499 500

      if (IS_ACTIVE_DISPLAY (shell))
501
        SET_ACTIVE (shell->popup_manager, "view-snap-to-guides", snap);
502 503 504 505 506 507 508 509 510 511 512
    }
}

gboolean
gimp_display_shell_get_snap_to_guides (GimpDisplayShell *shell)
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

  return shell->snap_to_guides;
}

513 514 515 516 517 518 519 520 521 522 523 524 525 526 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 561 562
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;

      SET_ACTIVE (shell->menubar_manager, "view-snap-to-canvas", snap);

      if (IS_ACTIVE_DISPLAY (shell))
        SET_ACTIVE (shell->popup_manager, "view-snap-to-canvas", snap);
    }
}

gboolean
gimp_display_shell_get_snap_to_canvas (GimpDisplayShell *shell)
{
  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;

      SET_ACTIVE (shell->menubar_manager, "view-snap-to-vectors", snap);

      if (IS_ACTIVE_DISPLAY (shell))
        SET_ACTIVE (shell->popup_manager, "view-snap-to-vectors", snap);
    }
}

gboolean
gimp_display_shell_get_snap_to_vectors (GimpDisplayShell *shell)
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);

  return shell->snap_to_vectors;
}

563
void
564 565 566
gimp_display_shell_set_padding (GimpDisplayShell      *shell,
                                GimpCanvasPaddingMode  padding_mode,
                                const GimpRGB         *padding_color)
567
{
568
  GimpDisplayOptions *options;
569
  GimpRGB             color;
570 571 572 573

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

574
  options = GET_OPTIONS (shell);
575
  color   = *padding_color;
576

577
  switch (padding_mode)
578
    {
579
    case GIMP_CANVAS_PADDING_MODE_DEFAULT:
580 581 582
      if (shell->canvas)
        {
          gtk_widget_ensure_style (shell->canvas);
583 584
          gimp_rgb_set_gdk_color (&color,
                                  shell->canvas->style->bg + GTK_STATE_NORMAL);
585 586 587
        }
      break;

588
    case GIMP_CANVAS_PADDING_MODE_LIGHT_CHECK:
589
      color = *gimp_render_light_check_color ();
590 591
      break;

592
    case GIMP_CANVAS_PADDING_MODE_DARK_CHECK:
593
      color = *gimp_render_dark_check_color ();
594 595
      break;

596
    case GIMP_CANVAS_PADDING_MODE_CUSTOM:
597
    case GIMP_CANVAS_PADDING_MODE_RESET:
598 599 600
      break;
    }

601 602 603 604 605
  g_object_set (options,
                "padding-mode",  padding_mode,
                "padding-color", &color,
                NULL);

606
  gimp_canvas_set_bg_color (GIMP_CANVAS (shell->canvas), &color);
607

608 609
  SET_COLOR (shell->menubar_manager, "view-padding-color-menu",
             &options->padding_color);
610

611 612 613
  if (IS_ACTIVE_DISPLAY (shell))
    SET_COLOR (shell->popup_manager, "view-padding-color-menu",
               &options->padding_color);
614 615 616 617 618

  gimp_display_shell_expose_full (shell);
}

void
619 620 621
gimp_display_shell_get_padding (GimpDisplayShell      *shell,
                                GimpCanvasPaddingMode *padding_mode,
                                GimpRGB               *padding_color)
622
{
623
  GimpDisplayOptions *options;
624 625 626

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

627
  options = GET_OPTIONS (shell);
628 629

  if (padding_mode)
630
    *padding_mode = options->padding_mode;
631 632

  if (padding_color)
633
    *padding_color = options->padding_color;
634
}