view-commands.c 6.94 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"
Michael Natterer's avatar
Michael Natterer committed
33
#include "display/gimpdisplayshell.h"
34
#include "display/gimpdisplayshell-scale.h"
35
#include "display/gimpdisplayshell-selection.h"
36

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


void
52 53
view_zoom_in_cmd_callback (GtkWidget *widget,
                           gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
54
{
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

Michael Natterer's avatar
Michael Natterer committed
58
  gimp_display_shell_scale (GIMP_DISPLAY_SHELL (gdisp->shell), GIMP_ZOOM_IN);
Michael Natterer's avatar
Michael Natterer committed
59 60 61
}

void
62 63
view_zoom_out_cmd_callback (GtkWidget *widget,
                            gpointer   data)
Michael Natterer's avatar
Michael Natterer committed
64
{
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

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

71 72 73 74 75 76 77 78 79 80
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
81 82 83 84 85
void
view_zoom_cmd_callback (GtkWidget *widget,
			gpointer   data,
			guint      action)
{
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

Michael Natterer's avatar
Michael Natterer committed
89
  gimp_display_shell_scale (GIMP_DISPLAY_SHELL (gdisp->shell), action);
Michael Natterer's avatar
Michael Natterer committed
90 91 92 93 94 95
}

void
view_dot_for_dot_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

Michael Natterer's avatar
Michael Natterer committed
99 100
  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
101 102 103 104 105 106
}

void
view_info_window_cmd_callback (GtkWidget *widget,
			       gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
107 108
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
109
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
110

Michael Natterer's avatar
Michael Natterer committed
111 112
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

Michael Natterer's avatar
Michael Natterer committed
113 114
  if (! gimprc.info_window_follows_mouse)
    {
Michael Natterer's avatar
Michael Natterer committed
115 116
      if (! shell->info_dialog)
	shell->info_dialog = info_window_create (gdisp);
Michael Natterer's avatar
Michael Natterer committed
117

Michael Natterer's avatar
Michael Natterer committed
118
      info_dialog_popup (shell->info_dialog);
Michael Natterer's avatar
Michael Natterer committed
119 120 121
    }
  else
    {
Michael Natterer's avatar
Michael Natterer committed
122
      info_window_follow_auto (gdisp->gimage->gimp);
Michael Natterer's avatar
Michael Natterer committed
123 124 125 126 127 128 129
    }
}

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

Michael Natterer's avatar
Michael Natterer committed
134 135
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

Michael Natterer's avatar
Michael Natterer committed
136 137
  if (gimprc.nav_window_per_display)
    {
Michael Natterer's avatar
Michael Natterer committed
138 139
      if (! shell->nav_dialog)
	shell->nav_dialog = nav_dialog_create (gdisp);
Michael Natterer's avatar
Michael Natterer committed
140

Michael Natterer's avatar
Michael Natterer committed
141
      nav_dialog_popup (shell->nav_dialog);
Michael Natterer's avatar
Michael Natterer committed
142 143 144 145 146 147 148 149 150 151 152
    }
  else
    {
      nav_dialog_follow_auto ();
    }
}

void
view_toggle_selection_cmd_callback (GtkWidget *widget,
				    gpointer   data)
{
153 154 155
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
  gint              new_val;
Michael Natterer's avatar
Michael Natterer committed
156
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
157

158 159
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

Michael Natterer's avatar
Michael Natterer committed
160 161 162
  new_val = GTK_CHECK_MENU_ITEM (widget)->active;

  /*  hidden == TRUE corresponds to the menu toggle being FALSE  */
163
  if (new_val == shell->select->hidden)
Michael Natterer's avatar
Michael Natterer committed
164
    {
165
      gimp_display_shell_selection_toggle (shell->select);
Michael Natterer's avatar
Michael Natterer committed
166

Michael Natterer's avatar
Michael Natterer committed
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
      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
190 191 192 193 194 195 196
    }
}

void
view_toggle_rulers_cmd_callback (GtkWidget *widget,
				 gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
197 198
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
199
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
200

Michael Natterer's avatar
Michael Natterer committed
201 202
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

Michael Natterer's avatar
Michael Natterer committed
203 204
  if (! GTK_CHECK_MENU_ITEM (widget)->active)
    {
Michael Natterer's avatar
Michael Natterer committed
205
      if (GTK_WIDGET_VISIBLE (shell->origin))
Michael Natterer's avatar
Michael Natterer committed
206
	{
Michael Natterer's avatar
Michael Natterer committed
207 208 209
	  gtk_widget_hide (shell->origin);
	  gtk_widget_hide (shell->hrule);
	  gtk_widget_hide (shell->vrule);
Michael Natterer's avatar
Michael Natterer committed
210

Michael Natterer's avatar
Michael Natterer committed
211
	  gtk_widget_queue_resize (GTK_WIDGET (shell->origin->parent));
Michael Natterer's avatar
Michael Natterer committed
212 213 214 215
	}
    }
  else
    {
Michael Natterer's avatar
Michael Natterer committed
216
      if (! GTK_WIDGET_VISIBLE (shell->origin))
Michael Natterer's avatar
Michael Natterer committed
217
	{
Michael Natterer's avatar
Michael Natterer committed
218 219 220
	  gtk_widget_show (shell->origin);
	  gtk_widget_show (shell->hrule);
	  gtk_widget_show (shell->vrule);
Michael Natterer's avatar
Michael Natterer committed
221

Michael Natterer's avatar
Michael Natterer committed
222
	  gtk_widget_queue_resize (GTK_WIDGET (shell->origin->parent));
Michael Natterer's avatar
Michael Natterer committed
223 224 225 226 227 228 229 230
	}
    }
}

void
view_toggle_statusbar_cmd_callback (GtkWidget *widget,
				    gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
231 232
  GimpDisplay      *gdisp;
  GimpDisplayShell *shell;
Michael Natterer's avatar
Michael Natterer committed
233
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
234

Michael Natterer's avatar
Michael Natterer committed
235 236
  shell = GIMP_DISPLAY_SHELL (gdisp->shell);

Michael Natterer's avatar
Michael Natterer committed
237 238
  if (! GTK_CHECK_MENU_ITEM (widget)->active)
    {
239 240
      if (GTK_WIDGET_VISIBLE (shell->statusbar))
	gtk_widget_hide (shell->statusbar);
Michael Natterer's avatar
Michael Natterer committed
241 242 243
    }
  else
    {
244 245
      if (! GTK_WIDGET_VISIBLE (shell->statusbar))
	gtk_widget_show (shell->statusbar);
Michael Natterer's avatar
Michael Natterer committed
246 247 248 249 250 251 252
    }
}

void
view_toggle_guides_cmd_callback (GtkWidget *widget,
				 gpointer   data)
{
253
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
254 255
  gboolean     old_val;
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
256 257 258 259 260 261

  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
262
      gimp_display_shell_expose_full (GIMP_DISPLAY_SHELL (gdisp->shell));
263
      gimp_display_flush (gdisp);
Michael Natterer's avatar
Michael Natterer committed
264 265 266 267 268 269 270
    }
}

void
view_snap_to_guides_cmd_callback (GtkWidget *widget,
				  gpointer   data)
{
271
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
272
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
273 274 275 276 277 278 279 280

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

void
view_new_view_cmd_callback (GtkWidget *widget,
			    gpointer   data)
{
281
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
282
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
283

Michael Natterer's avatar
Michael Natterer committed
284
  gimp_create_display (gdisp->gimage->gimp, gdisp->gimage, gdisp->scale);
Michael Natterer's avatar
Michael Natterer committed
285 286 287 288 289 290
}

void
view_shrink_wrap_cmd_callback (GtkWidget *widget,
			       gpointer   data)
{
291
  GimpDisplay *gdisp;
Michael Natterer's avatar
Michael Natterer committed
292
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
293

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