view-commands.c 12.3 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"

25
#include "gui-types.h"
Michael Natterer's avatar
Michael Natterer committed
26

27 28
#include "config/gimpguiconfig.h"

29 30
#include "core/gimp.h"
#include "core/gimpcontext.h"
Michael Natterer's avatar
Michael Natterer committed
31 32
#include "core/gimpimage.h"

33
#include "display/gimpdisplay.h"
34
#include "display/gimpdisplay-foreach.h"
Michael Natterer's avatar
Michael Natterer committed
35
#include "display/gimpdisplayshell.h"
36
#include "display/gimpdisplayshell-scale.h"
37
#include "display/gimpdisplayshell-selection.h"
38

39
#include "widgets/gimpdialogfactory.h"
40
#include "widgets/gimpitemfactory.h"
41 42

#include "dialogs.h"
Michael Natterer's avatar
Michael Natterer committed
43 44 45 46 47
#include "info-dialog.h"
#include "info-window.h"
#include "view-commands.h"


Michael Natterer's avatar
Michael Natterer committed
48
#define return_if_no_display(gdisp, data) \
49 50 51 52 53 54
  if (GIMP_IS_DISPLAY (data)) \
    gdisp = data; \
  else if (GIMP_IS_GIMP (data)) \
    gdisp = gimp_context_get_display (gimp_get_user_context (GIMP (data))); \
  else \
    gdisp = NULL; \
Michael Natterer's avatar
Michael Natterer committed
55 56
  if (! gdisp) \
    return
Michael Natterer's avatar
Michael Natterer committed
57 58 59


void
60 61
view_zoom_in_cmd_callback (GtkWidget *widget,
                           gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
62
{
63
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
64
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
65

Michael Natterer's avatar
Michael Natterer committed
66
  gimp_display_shell_scale (GIMP_DISPLAY_SHELL (gdisp->shell), GIMP_ZOOM_IN);
Michael Natterer's avatar
Michael Natterer committed
67 68 69
}

void
70 71
view_zoom_out_cmd_callback (GtkWidget *widget,
                            gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
72
{
73
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
74
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
75

Michael Natterer's avatar
Michael Natterer committed
76
  gimp_display_shell_scale (GIMP_DISPLAY_SHELL (gdisp->shell), GIMP_ZOOM_OUT);
Michael Natterer's avatar
Michael Natterer committed
77 78
}

79 80 81 82 83 84 85 86 87 88
void
view_zoom_fit_cmd_callback (GtkWidget *widget,
                            gpointer   data)
{
  GimpDisplay *gdisp;
  return_if_no_display (gdisp, data);

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

Michael Natterer's avatar
Michael Natterer committed
89 90 91 92 93
void
view_zoom_cmd_callback (GtkWidget *widget,
			gpointer   data,
			guint      action)
{
94
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
95
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
96

Michael Natterer's avatar
Michael Natterer committed
97
  gimp_display_shell_scale (GIMP_DISPLAY_SHELL (gdisp->shell), action);
Michael Natterer's avatar
Michael Natterer committed
98 99 100 101 102 103
}

void
view_dot_for_dot_cmd_callback (GtkWidget *widget,
			       gpointer   data)
{
104 105
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
106
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
107

108 109 110 111 112 113 114 115 116 117 118 119 120 121
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  if (shell->dot_for_dot != GTK_CHECK_MENU_ITEM (widget)->active)
    {
      gimp_display_shell_scale_set_dot_for_dot (shell,
                                                GTK_CHECK_MENU_ITEM (widget)->active);

      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->menubar_factory),
                                    "/View/Dot for Dot",
                                    shell->dot_for_dot);
      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->popup_factory),
                                    "/View/Dot for Dot",
                                    shell->dot_for_dot);
    }
Michael Natterer's avatar
Michael Natterer committed
122 123
}

124 125 126 127 128 129 130 131 132 133 134
void
view_fullscreen_cmd_callback (GtkWidget *widget,
			      gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  gboolean          fullscreen;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

135 136
  gimp_display_shell_set_fullscreen (shell,
                                     GTK_CHECK_MENU_ITEM (widget)->active);
137

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

140 141 142 143 144 145 146 147 148
  if (fullscreen != GTK_CHECK_MENU_ITEM (widget)->active)
    {
      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->menubar_factory),
                                    "/View/Fullscreen",
                                    fullscreen);
      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->popup_factory),
                                    "/View/Fullscreen",
                                    fullscreen);
    }
149 150
}

Michael Natterer's avatar
Michael Natterer committed
151 152 153 154
void
view_info_window_cmd_callback (GtkWidget *widget,
			       gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
155 156
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
157
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
158

Michael Natterer's avatar
Michael Natterer committed
159 160
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

161
  if (GIMP_GUI_CONFIG (gdisp->gimage->gimp->config)->info_window_per_display)
Michael Natterer's avatar
Michael Natterer committed
162
    {
Michael Natterer's avatar
Michael Natterer committed
163 164
      if (! shell->info_dialog)
	shell->info_dialog = info_window_create (gdisp);
Michael Natterer's avatar
Michael Natterer committed
165

Michael Natterer's avatar
Michael Natterer committed
166
      info_dialog_popup (shell->info_dialog);
Michael Natterer's avatar
Michael Natterer committed
167 168 169
    }
  else
    {
Michael Natterer's avatar
Michael Natterer committed
170
      info_window_follow_auto (gdisp->gimage->gimp);
Michael Natterer's avatar
Michael Natterer committed
171 172 173 174
    }
}

void
175 176
view_navigation_window_cmd_callback (GtkWidget *widget,
                                     gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
177
{
Michael Natterer's avatar
Michael Natterer committed
178 179
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
180
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
181

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

Michael Natterer's avatar
Michael Natterer committed
184 185
  gimp_dialog_factory_dialog_raise (global_dock_factory,
                                    "gimp-navigation-view", -1);
Michael Natterer's avatar
Michael Natterer committed
186 187
}

188 189 190 191 192 193 194 195 196 197 198
void
view_display_filters_cmd_callback (GtkWidget *widget,
                                   gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  gimp_dialog_factory_dialog_new (global_dialog_factory,
199
                                  "gimp-display-filters-dialog", -1);
200 201
}

Michael Natterer's avatar
Michael Natterer committed
202 203 204 205
void
view_toggle_selection_cmd_callback (GtkWidget *widget,
				    gpointer   data)
{
206 207
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
208
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
209

210 211
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

Michael Natterer's avatar
Michael Natterer committed
212
  /*  hidden == TRUE corresponds to the menu toggle being FALSE  */
213
  if (GTK_CHECK_MENU_ITEM (widget)->active == shell->select->hidden)
Michael Natterer's avatar
Michael Natterer committed
214
    {
215
      gimp_display_shell_selection_toggle (shell->select);
216 217 218 219 220 221 222

      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->menubar_factory),
                                    "/View/Show Selection",
                                    ! shell->select->hidden);
      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->popup_factory),
                                    "/View/Show Selection",
                                    ! shell->select->hidden);
Michael Natterer's avatar
Michael Natterer committed
223 224 225 226 227 228 229 230 231 232 233 234 235 236
    }
}

void
view_toggle_layer_boundary_cmd_callback (GtkWidget *widget,
                                         gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  /*  hidden == TRUE corresponds to the menu toggle being FALSE  */
237
  if (GTK_CHECK_MENU_ITEM (widget)->active == shell->select->layer_hidden)
Michael Natterer's avatar
Michael Natterer committed
238 239
    {
      gimp_display_shell_selection_toggle_layer (shell->select);
240 241 242 243 244 245 246

      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->menubar_factory),
                                    "/View/Show Layer Boundary",
                                    ! shell->select->layer_hidden);
      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->popup_factory),
                                    "/View/Show Layer Boundary",
                                    ! shell->select->layer_hidden);
Michael Natterer's avatar
Michael Natterer committed
247 248 249
    }
}

250 251 252 253 254 255 256 257 258 259 260 261 262
void
view_toggle_menubar_cmd_callback (GtkWidget *widget,
                                  gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  GtkWidget        *menubar;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  menubar = GTK_ITEM_FACTORY (shell->menubar_factory)->widget;

263 264
  if (GTK_CHECK_MENU_ITEM (widget)->active !=
      GTK_WIDGET_VISIBLE (menubar))
265 266 267
    {
      if (GTK_WIDGET_VISIBLE (menubar))
	gtk_widget_hide (menubar);
268
      else
269 270
	gtk_widget_show (menubar);

271 272 273 274 275 276 277
      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->menubar_factory),
                                    "/View/Show Menubar",
                                    GTK_WIDGET_VISIBLE (menubar));
      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->popup_factory),
                                    "/View/Show Menubar",
                                    GTK_WIDGET_VISIBLE (menubar));
    }
278 279
}

Michael Natterer's avatar
Michael Natterer committed
280 281 282 283
void
view_toggle_rulers_cmd_callback (GtkWidget *widget,
				 gpointer   data)
{
284 285 286
  GimpDisplay       *gdisp;
  GimpDisplayShell  *shell;
  GimpDisplayConfig *config;
Michael Natterer's avatar
Michael Natterer committed
287
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
288

Michael Natterer's avatar
Michael Natterer committed
289 290
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

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

293 294
  if (GTK_CHECK_MENU_ITEM (widget)->active !=
      GTK_WIDGET_VISIBLE (shell->origin))
Michael Natterer's avatar
Michael Natterer committed
295
    {
296
      if (GTK_WIDGET_VISIBLE (shell->origin))
Michael Natterer's avatar
Michael Natterer committed
297
	{
298
          gtk_widget_hide (shell->origin);
Michael Natterer's avatar
Michael Natterer committed
299 300
	  gtk_widget_hide (shell->hrule);
	  gtk_widget_hide (shell->vrule);
Michael Natterer's avatar
Michael Natterer committed
301
	}
302
      else
Michael Natterer's avatar
Michael Natterer committed
303
	{
304
          gtk_widget_show (shell->origin);
Michael Natterer's avatar
Michael Natterer committed
305 306
	  gtk_widget_show (shell->hrule);
	  gtk_widget_show (shell->vrule);
Michael Natterer's avatar
Michael Natterer committed
307
	}
308

309 310 311 312 313 314 315
      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->menubar_factory),
                                    "/View/Show Rulers",
                                    GTK_WIDGET_VISIBLE (shell->origin));
      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->popup_factory),
                                    "/View/Show Rulers",
                                    GTK_WIDGET_VISIBLE (shell->origin));
    }
Michael Natterer's avatar
Michael Natterer committed
316 317 318 319 320 321
}

void
view_toggle_statusbar_cmd_callback (GtkWidget *widget,
				    gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
322 323
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
324
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
325

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

328 329
  if (GTK_CHECK_MENU_ITEM (widget)->active !=
      GTK_WIDGET_VISIBLE (shell->statusbar))
Michael Natterer's avatar
Michael Natterer committed
330
    {
331 332
      if (GTK_WIDGET_VISIBLE (shell->statusbar))
	gtk_widget_hide (shell->statusbar);
333
      else
334
	gtk_widget_show (shell->statusbar);
335

336 337 338 339 340 341 342
      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->menubar_factory),
                                    "/View/Show Statusbar",
                                    GTK_WIDGET_VISIBLE (shell->statusbar));
      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->popup_factory),
                                    "/View/Show Statusbar",
                                    GTK_WIDGET_VISIBLE (shell->statusbar));
    }
Michael Natterer's avatar
Michael Natterer committed
343 344 345 346 347 348
}

void
view_toggle_guides_cmd_callback (GtkWidget *widget,
				 gpointer   data)
{
349
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
350
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
351

352
  if (GTK_CHECK_MENU_ITEM (widget)->active != gdisp->draw_guides)
Michael Natterer's avatar
Michael Natterer committed
353
    {
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
      GimpDisplayShell *shell;

      shell = GIMP_DISPLAY_SHELL (gdisp->shell);

      gdisp->draw_guides = GTK_CHECK_MENU_ITEM (widget)->active;

      if (gdisp->gimage->guides)
        {
          gimp_display_shell_expose_full (shell);
          gimp_display_flush (gdisp);
        }
      else
        {
          gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->menubar_factory),
                                        "/View/Show Guides",
                                        gdisp->draw_guides);
          gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->popup_factory),
                                        "/View/Show Guides",
                                        gdisp->draw_guides);
        }
Michael Natterer's avatar
Michael Natterer committed
374 375 376 377 378 379 380
    }
}

void
view_snap_to_guides_cmd_callback (GtkWidget *widget,
				  gpointer   data)
{
381 382
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
383
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
384

385
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);
386

387 388 389 390 391 392 393 394 395 396 397
  if (gdisp->snap_to_guides != GTK_CHECK_MENU_ITEM (widget)->active)
    {
      gdisp->snap_to_guides = GTK_CHECK_MENU_ITEM (widget)->active;

      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->menubar_factory),
                                    "/View/Snap to Guides",
                                    gdisp->snap_to_guides);
      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->popup_factory),
                                    "/View/Snap to Guides",
                                    gdisp->snap_to_guides);
    }
Michael Natterer's avatar
Michael Natterer committed
398 399 400 401 402 403
}

void
view_new_view_cmd_callback (GtkWidget *widget,
			    gpointer   data)
{
404
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
405
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
406

407 408
  gimp_create_display (gdisp->gimage->gimp, gdisp->gimage,
                       GIMP_DISPLAY_SHELL (gdisp->shell)->scale);
Michael Natterer's avatar
Michael Natterer committed
409 410 411 412 413 414
}

void
view_shrink_wrap_cmd_callback (GtkWidget *widget,
			       gpointer   data)
{
415
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
416
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
417

Michael Natterer's avatar
Michael Natterer committed
418
  gimp_display_shell_scale_shrink_wrap (GIMP_DISPLAY_SHELL (gdisp->shell));
Michael Natterer's avatar
Michael Natterer committed
419
}