view-commands.c 8.53 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
40
41
#include "widgets/gimpdialogfactory.h"

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


Michael Natterer's avatar
Michael Natterer committed
47
#define return_if_no_display(gdisp, data) \
48
49
50
51
52
53
  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
54
55
  if (! gdisp) \
    return
Michael Natterer's avatar
Michael Natterer committed
56
57
58


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

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

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

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

78
79
80
81
82
83
84
85
86
87
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
88
89
90
91
92
void
view_zoom_cmd_callback (GtkWidget *widget,
			gpointer   data,
			guint      action)
{
93
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
94
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
95

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

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

Michael Natterer's avatar
Michael Natterer committed
106
107
  gimp_display_shell_scale_set_dot_for_dot (GIMP_DISPLAY_SHELL (gdisp->shell),
                                            GTK_CHECK_MENU_ITEM (widget)->active);
Michael Natterer's avatar
Michael Natterer committed
108
109
110
111
112
113
}

void
view_info_window_cmd_callback (GtkWidget *widget,
			       gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
114
115
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
116
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
117

Michael Natterer's avatar
Michael Natterer committed
118
119
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

120
  if (GIMP_GUI_CONFIG (gdisp->gimage->gimp->config)->info_window_per_display)
Michael Natterer's avatar
Michael Natterer committed
121
    {
Michael Natterer's avatar
Michael Natterer committed
122
123
      if (! shell->info_dialog)
	shell->info_dialog = info_window_create (gdisp);
Michael Natterer's avatar
Michael Natterer committed
124

Michael Natterer's avatar
Michael Natterer committed
125
      info_dialog_popup (shell->info_dialog);
Michael Natterer's avatar
Michael Natterer committed
126
127
128
    }
  else
    {
Michael Natterer's avatar
Michael Natterer committed
129
      info_window_follow_auto (gdisp->gimage->gimp);
Michael Natterer's avatar
Michael Natterer committed
130
131
132
133
    }
}

void
134
135
view_navigation_window_cmd_callback (GtkWidget *widget,
                                     gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
136
{
Michael Natterer's avatar
Michael Natterer committed
137
138
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
139
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
140

Michael Natterer's avatar
Michael Natterer committed
141
142
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

Michael Natterer's avatar
Michael Natterer committed
143
144
  gimp_dialog_factory_dialog_raise (global_dock_factory,
                                    "gimp-navigation-view", -1);
Michael Natterer's avatar
Michael Natterer committed
145
146
}

147
148
149
150
151
152
153
154
155
156
157
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,
158
                                  "gimp-display-filters-dialog", -1);
159
160
}

Michael Natterer's avatar
Michael Natterer committed
161
162
163
164
void
view_toggle_selection_cmd_callback (GtkWidget *widget,
				    gpointer   data)
{
165
166
167
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  gint              new_val;
Michael Natterer's avatar
Michael Natterer committed
168
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
169

170
171
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

Michael Natterer's avatar
Michael Natterer committed
172
173
174
  new_val = GTK_CHECK_MENU_ITEM (widget)->active;

  /*  hidden == TRUE corresponds to the menu toggle being FALSE  */
175
  if (new_val == shell->select->hidden)
Michael Natterer's avatar
Michael Natterer committed
176
    {
177
      gimp_display_shell_selection_toggle (shell->select);
Michael Natterer's avatar
Michael Natterer committed
178

Michael Natterer's avatar
Michael Natterer committed
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
      gimp_display_shell_flush (shell);
    }
}

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

  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

  new_val = GTK_CHECK_MENU_ITEM (widget)->active;

  /*  hidden == TRUE corresponds to the menu toggle being FALSE  */
  if (new_val == shell->select->layer_hidden)
    {
      gimp_display_shell_selection_toggle_layer (shell->select);

      gimp_display_shell_flush (shell);
Michael Natterer's avatar
Michael Natterer committed
202
203
204
    }
}

205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
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;

  if (! GTK_CHECK_MENU_ITEM (widget)->active)
    {
      if (GTK_WIDGET_VISIBLE (menubar))
	gtk_widget_hide (menubar);
    }
  else
    {
      if (! GTK_WIDGET_VISIBLE (menubar))
	gtk_widget_show (menubar);
    }

  gimp_display_shell_set_menu_sensitivity (shell, gdisp->gimage->gimp, FALSE);
}

Michael Natterer's avatar
Michael Natterer committed
232
233
234
235
void
view_toggle_rulers_cmd_callback (GtkWidget *widget,
				 gpointer   data)
{
236
237
238
  GimpDisplay       *gdisp;
  GimpDisplayShell  *shell;
  GimpDisplayConfig *config;
Michael Natterer's avatar
Michael Natterer committed
239
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
240

Michael Natterer's avatar
Michael Natterer committed
241
242
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

243
244
  config = GIMP_DISPLAY_CONFIG (gdisp->gimage->gimp->config);

Michael Natterer's avatar
Michael Natterer committed
245
246
  if (! GTK_CHECK_MENU_ITEM (widget)->active)
    {
247
      if (GTK_WIDGET_VISIBLE (shell->origin))
Michael Natterer's avatar
Michael Natterer committed
248
	{
249
          gtk_widget_hide (shell->origin);
Michael Natterer's avatar
Michael Natterer committed
250
251
	  gtk_widget_hide (shell->hrule);
	  gtk_widget_hide (shell->vrule);
Michael Natterer's avatar
Michael Natterer committed
252

Michael Natterer's avatar
Michael Natterer committed
253
	  gtk_widget_queue_resize (GTK_WIDGET (shell->origin->parent));
Michael Natterer's avatar
Michael Natterer committed
254
255
256
257
	}
    }
  else
    {
258
      if (! GTK_WIDGET_VISIBLE (shell->origin))
Michael Natterer's avatar
Michael Natterer committed
259
	{
260
          gtk_widget_show (shell->origin);
Michael Natterer's avatar
Michael Natterer committed
261
262
	  gtk_widget_show (shell->hrule);
	  gtk_widget_show (shell->vrule);
Michael Natterer's avatar
Michael Natterer committed
263

Michael Natterer's avatar
Michael Natterer committed
264
	  gtk_widget_queue_resize (GTK_WIDGET (shell->origin->parent));
Michael Natterer's avatar
Michael Natterer committed
265
266
	}
    }
267
268

  gimp_display_shell_set_menu_sensitivity (shell, gdisp->gimage->gimp, FALSE);
Michael Natterer's avatar
Michael Natterer committed
269
270
271
272
273
274
}

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

Michael Natterer's avatar
Michael Natterer committed
279
280
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

Michael Natterer's avatar
Michael Natterer committed
281
282
  if (! GTK_CHECK_MENU_ITEM (widget)->active)
    {
283
284
      if (GTK_WIDGET_VISIBLE (shell->statusbar))
	gtk_widget_hide (shell->statusbar);
Michael Natterer's avatar
Michael Natterer committed
285
286
287
    }
  else
    {
288
289
      if (! GTK_WIDGET_VISIBLE (shell->statusbar))
	gtk_widget_show (shell->statusbar);
Michael Natterer's avatar
Michael Natterer committed
290
    }
291
292

  gimp_display_shell_set_menu_sensitivity (shell, gdisp->gimage->gimp, FALSE);
Michael Natterer's avatar
Michael Natterer committed
293
294
295
296
297
298
}

void
view_toggle_guides_cmd_callback (GtkWidget *widget,
				 gpointer   data)
{
299
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
300
301
  gboolean     old_val;
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
302
303
304
305
306
307

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

  if ((old_val != gdisp->draw_guides) && gdisp->gimage->guides)
    {
Michael Natterer's avatar
Michael Natterer committed
308
      gimp_display_shell_expose_full (GIMP_DISPLAY_SHELL (gdisp->shell));
309
      gimp_display_flush (gdisp);
Michael Natterer's avatar
Michael Natterer committed
310
311
312
313
314
315
316
    }
}

void
view_snap_to_guides_cmd_callback (GtkWidget *widget,
				  gpointer   data)
{
317
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
318
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
319
320

  gdisp->snap_to_guides = GTK_CHECK_MENU_ITEM (widget)->active;
321
322
323

  gimp_display_shell_set_menu_sensitivity (GIMP_DISPLAY_SHELL (gdisp->shell),
                                           gdisp->gimage->gimp, FALSE);
Michael Natterer's avatar
Michael Natterer committed
324
325
326
327
328
329
}

void
view_new_view_cmd_callback (GtkWidget *widget,
			    gpointer   data)
{
330
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
331
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
332

333
334
  gimp_create_display (gdisp->gimage->gimp, gdisp->gimage,
                       GIMP_DISPLAY_SHELL (gdisp->shell)->scale);
Michael Natterer's avatar
Michael Natterer committed
335
336
337
338
339
340
}

void
view_shrink_wrap_cmd_callback (GtkWidget *widget,
			       gpointer   data)
{
341
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
342
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
343

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