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

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-appearance.h"
37
#include "display/gimpdisplayshell-scale.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_out_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

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

void
70 71
view_zoom_in_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

76
  gimp_display_shell_scale (GIMP_DISPLAY_SHELL (gdisp->shell), GIMP_ZOOM_IN);
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 95 96 97
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  guchar            scalesrc;
  guchar            scaledest;
Michael Natterer's avatar
Michael Natterer committed
98
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
99

100 101 102 103 104 105 106 107 108 109
  if (! GTK_CHECK_MENU_ITEM (widget)->active)
    return;

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  scalesrc  = CLAMP (action % 100, 1, 0xFF);
  scaledest = CLAMP (action / 100, 1, 0xFF);

  if (scalesrc != SCALESRC (shell) || scaledest != SCALEDEST (shell))
    gimp_display_shell_scale (shell, action);
Michael Natterer's avatar
Michael Natterer committed
110 111
}

112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
void
view_zoom_other_cmd_callback (GtkWidget *widget,
                              gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  return_if_no_display (gdisp, data);

  if (! GTK_CHECK_MENU_ITEM (widget)->active)
    return;

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  /*  check if we are activated by the user or from image_menu_set_zoom()  */
  if (shell->scale != shell->other_scale)
    gimp_display_shell_scale_dialog (shell);
}

Michael Natterer's avatar
Michael Natterer committed
130 131 132 133
void
view_dot_for_dot_cmd_callback (GtkWidget *widget,
			       gpointer   data)
{
134 135
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
136
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
137

138 139 140 141 142 143 144 145 146 147 148 149 150 151
  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
152 153
}

154 155 156 157 158 159 160 161 162 163 164
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);

165 166
  gimp_display_shell_set_fullscreen (shell,
                                     GTK_CHECK_MENU_ITEM (widget)->active);
167

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

170 171 172 173 174 175 176 177 178
  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);
    }
179 180
}

Michael Natterer's avatar
Michael Natterer committed
181 182 183 184
void
view_info_window_cmd_callback (GtkWidget *widget,
			       gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
185 186
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
187
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
188

Michael Natterer's avatar
Michael Natterer committed
189 190
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

191
  if (GIMP_GUI_CONFIG (gdisp->gimage->gimp->config)->info_window_per_display)
Michael Natterer's avatar
Michael Natterer committed
192
    {
Michael Natterer's avatar
Michael Natterer committed
193 194
      if (! shell->info_dialog)
	shell->info_dialog = info_window_create (gdisp);
Michael Natterer's avatar
Michael Natterer committed
195

Michael Natterer's avatar
Michael Natterer committed
196
      info_dialog_popup (shell->info_dialog);
Michael Natterer's avatar
Michael Natterer committed
197 198 199
    }
  else
    {
Michael Natterer's avatar
Michael Natterer committed
200
      info_window_follow_auto (gdisp->gimage->gimp);
Michael Natterer's avatar
Michael Natterer committed
201 202 203 204
    }
}

void
205 206
view_navigation_window_cmd_callback (GtkWidget *widget,
                                     gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
207
{
Michael Natterer's avatar
Michael Natterer committed
208 209
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
210
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
211

Michael Natterer's avatar
Michael Natterer committed
212 213
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

Michael Natterer's avatar
Michael Natterer committed
214 215
  gimp_dialog_factory_dialog_raise (global_dock_factory,
                                    "gimp-navigation-view", -1);
Michael Natterer's avatar
Michael Natterer committed
216 217
}

218 219 220 221 222 223 224 225 226 227 228
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,
229
                                  "gimp-display-filters-dialog", -1);
230 231
}

Michael Natterer's avatar
Michael Natterer committed
232 233 234 235
void
view_toggle_selection_cmd_callback (GtkWidget *widget,
				    gpointer   data)
{
236 237
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
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
  gimp_display_shell_set_show_selection (shell,
                                         GTK_CHECK_MENU_ITEM (widget)->active);
Michael Natterer's avatar
Michael Natterer committed
244 245 246 247 248 249 250 251 252 253 254 255
}

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

256 257
  gimp_display_shell_set_show_layer (shell,
                                     GTK_CHECK_MENU_ITEM (widget)->active);
Michael Natterer's avatar
Michael Natterer committed
258 259
}

260 261 262 263 264 265 266 267 268 269
void
view_toggle_menubar_cmd_callback (GtkWidget *widget,
                                  gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  return_if_no_display (gdisp, data);

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

270 271
  gimp_display_shell_set_show_menubar (shell,
                                       GTK_CHECK_MENU_ITEM (widget)->active);
272 273
}

Michael Natterer's avatar
Michael Natterer committed
274 275 276 277
void
view_toggle_rulers_cmd_callback (GtkWidget *widget,
				 gpointer   data)
{
278 279
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
280
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
281

Michael Natterer's avatar
Michael Natterer committed
282 283
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

284 285 286
  gimp_display_shell_set_show_rulers (shell,
                                      GTK_CHECK_MENU_ITEM (widget)->active);
}
287

288 289 290 291 292 293 294
void
view_toggle_scrollbars_cmd_callback (GtkWidget *widget,
                                     gpointer   data)
{
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  return_if_no_display (gdisp, data);
295

296 297 298 299
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  gimp_display_shell_set_show_scrollbars (shell,
                                          GTK_CHECK_MENU_ITEM (widget)->active);
Michael Natterer's avatar
Michael Natterer committed
300 301 302 303 304 305
}

void
view_toggle_statusbar_cmd_callback (GtkWidget *widget,
				    gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
306 307
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
308
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
309

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

312 313
  gimp_display_shell_set_show_statusbar (shell,
                                         GTK_CHECK_MENU_ITEM (widget)->active);
Michael Natterer's avatar
Michael Natterer committed
314 315 316 317 318 319
}

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

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

  gimp_display_shell_set_show_guides (shell,
                                      GTK_CHECK_MENU_ITEM (widget)->active);
Michael Natterer's avatar
Michael Natterer committed
328 329 330 331 332 333
}

void
view_snap_to_guides_cmd_callback (GtkWidget *widget,
				  gpointer   data)
{
334 335
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
336
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
337

338
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);
339

340
  if (shell->snap_to_guides != GTK_CHECK_MENU_ITEM (widget)->active)
341
    {
342
      shell->snap_to_guides = GTK_CHECK_MENU_ITEM (widget)->active;
343 344 345

      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->menubar_factory),
                                    "/View/Snap to Guides",
346
                                    shell->snap_to_guides);
347 348
      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->popup_factory),
                                    "/View/Snap to Guides",
349
                                    shell->snap_to_guides);
350
    }
Michael Natterer's avatar
Michael Natterer committed
351 352
}

353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391

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

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  gimp_display_shell_set_show_grid (shell,
                                    GTK_CHECK_MENU_ITEM (widget)->active);

}

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

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  if (shell->snap_to_grid != GTK_CHECK_MENU_ITEM (widget)->active)
    {
      shell->snap_to_grid = GTK_CHECK_MENU_ITEM (widget)->active;

      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->menubar_factory),
                                    "/View/Snap to Grid",
                                    shell->snap_to_grid);
      gimp_item_factory_set_active (GTK_ITEM_FACTORY (shell->popup_factory),
                                    "/View/Snap to Grid",
                                    shell->snap_to_grid);
    }
}

Michael Natterer's avatar
Michael Natterer committed
392 393 394 395
void
view_new_view_cmd_callback (GtkWidget *widget,
			    gpointer   data)
{
396
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
397
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
398

399 400
  gimp_create_display (gdisp->gimage->gimp, gdisp->gimage,
                       GIMP_DISPLAY_SHELL (gdisp->shell)->scale);
Michael Natterer's avatar
Michael Natterer committed
401 402 403 404 405 406
}

void
view_shrink_wrap_cmd_callback (GtkWidget *widget,
			       gpointer   data)
{
407
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
408
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
409

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