view-commands.c 5.45 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 "core/gimp.h"
#include "core/gimpcontext.h"
Michael Natterer's avatar
Michael Natterer committed
29
30
#include "core/gimpimage.h"

31
#include "display/gimpdisplay.h"
32
#include "display/gimpdisplay-foreach.h"
33
34
35
36
#include "display/gimpdisplay-ops.h"
#include "display/gimpdisplay-scale.h"
#include "display/gimpdisplay-selection.h"

Michael Natterer's avatar
Michael Natterer committed
37
38
39
40
41
42
43
44
#include "info-dialog.h"
#include "info-window.h"
#include "view-commands.h"

#include "gimprc.h"
#include "nav_window.h"


Michael Natterer's avatar
Michael Natterer committed
45
46
47
48
#define return_if_no_display(gdisp, data) \
  gdisp = gimp_context_get_display (gimp_get_user_context (GIMP (data))); \
  if (! gdisp) \
    return
Michael Natterer's avatar
Michael Natterer committed
49
50
51
52
53
54


void
view_zoomin_cmd_callback (GtkWidget *widget,
			  gpointer   data)
{
55
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
56
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
57

58
  gimp_display_scale (gdisp, GIMP_ZOOM_IN);
Michael Natterer's avatar
Michael Natterer committed
59
60
61
62
63
64
}

void
view_zoomout_cmd_callback (GtkWidget *widget,
			   gpointer   data)
{
65
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
66
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
67

68
  gimp_display_scale (gdisp, GIMP_ZOOM_OUT);
Michael Natterer's avatar
Michael Natterer committed
69
70
71
72
73
74
75
}

void
view_zoom_cmd_callback (GtkWidget *widget,
			gpointer   data,
			guint      action)
{
76
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
77
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
78

79
  gimp_display_scale (gdisp, action);
Michael Natterer's avatar
Michael Natterer committed
80
81
82
83
84
85
}

void
view_dot_for_dot_cmd_callback (GtkWidget *widget,
			       gpointer   data)
{
86
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
87
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
88
89
90
91
92
93
94
95

  gdisplay_set_dot_for_dot (gdisp, GTK_CHECK_MENU_ITEM (widget)->active);
}

void
view_info_window_cmd_callback (GtkWidget *widget,
			       gpointer   data)
{
96
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
97
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
98
99
100
101
102
103
104
105
106
107
108

  if (! gimprc.info_window_follows_mouse)
    {
      if (! gdisp->window_info_dialog)
	gdisp->window_info_dialog = info_window_create (gdisp);

      info_window_update (gdisp);
      info_dialog_popup (gdisp->window_info_dialog);
    }
  else
    {
Michael Natterer's avatar
Michael Natterer committed
109
      info_window_follow_auto (gdisp->gimage->gimp);
Michael Natterer's avatar
Michael Natterer committed
110
111
112
113
114
115
116
    }
}

void
view_nav_window_cmd_callback (GtkWidget *widget,
			      gpointer   data)
{
117
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
118
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

  if (gimprc.nav_window_per_display)
    {
      if (! gdisp->window_nav_dialog)
	gdisp->window_nav_dialog = nav_dialog_create (gdisp);

      nav_dialog_popup (gdisp->window_nav_dialog);
    }
  else
    {
      nav_dialog_follow_auto ();
    }
}

void
view_toggle_selection_cmd_callback (GtkWidget *widget,
				    gpointer   data)
{
137
138
  GimpDisplay *gdisp;
  gint         new_val;
Michael Natterer's avatar
Michael Natterer committed
139

Michael Natterer's avatar
Michael Natterer committed
140
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156

  new_val = GTK_CHECK_MENU_ITEM (widget)->active;

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

      gdisplays_flush ();
    }
}

void
view_toggle_rulers_cmd_callback (GtkWidget *widget,
				 gpointer   data)
{
157
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
158
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187

  if (! GTK_CHECK_MENU_ITEM (widget)->active)
    {
      if (GTK_WIDGET_VISIBLE (gdisp->origin))
	{
	  gtk_widget_hide (gdisp->origin);
	  gtk_widget_hide (gdisp->hrule);
	  gtk_widget_hide (gdisp->vrule);

	  gtk_widget_queue_resize (GTK_WIDGET (gdisp->origin->parent));
	}
    }
  else
    {
      if (! GTK_WIDGET_VISIBLE (gdisp->origin))
	{
	  gtk_widget_show (gdisp->origin);
	  gtk_widget_show (gdisp->hrule);
	  gtk_widget_show (gdisp->vrule);

	  gtk_widget_queue_resize (GTK_WIDGET (gdisp->origin->parent));
	}
    }
}

void
view_toggle_statusbar_cmd_callback (GtkWidget *widget,
				    gpointer   data)
{
188
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
189
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206

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

void
view_toggle_guides_cmd_callback (GtkWidget *widget,
				 gpointer   data)
{
207
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
208
209
  gboolean     old_val;
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224

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

  if ((old_val != gdisp->draw_guides) && gdisp->gimage->guides)
    {
      gdisplay_expose_full (gdisp);
      gdisplays_flush ();
    }
}

void
view_snap_to_guides_cmd_callback (GtkWidget *widget,
				  gpointer   data)
{
225
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
226
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
227
228
229
230
231
232
233
234

  gdisp->snap_to_guides = GTK_CHECK_MENU_ITEM (widget)->active;
}

void
view_new_view_cmd_callback (GtkWidget *widget,
			    gpointer   data)
{
235
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
236
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
237
238
239
240
241
242
243
244

  gdisplay_new_view (gdisp);
}

void
view_shrink_wrap_cmd_callback (GtkWidget *widget,
			       gpointer   data)
{
245
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
246
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
247

248
  gimp_display_scale_shrink_wrap (gdisp);
Michael Natterer's avatar
Michael Natterer committed
249
}