edit-commands.c 7.52 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
/* 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"

Hans Breuer's avatar
Hans Breuer committed
21
22
#include <string.h>

Michael Natterer's avatar
Michael Natterer committed
23
24
25
26
#include <gtk/gtk.h>

#include "libgimpwidgets/gimpwidgets.h"

27
#include "gui-types.h"
Michael Natterer's avatar
Michael Natterer committed
28

29
#include "core/gimp.h"
Michael Natterer's avatar
Michael Natterer committed
30
31
32
33
#include "core/gimpbuffer.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "core/gimpdrawable.h"
Michael Natterer's avatar
Michael Natterer committed
34
#include "core/gimpedit.h"
Michael Natterer's avatar
Michael Natterer committed
35
36
37
#include "core/gimpimage.h"
#include "core/gimpimage-mask.h"

38
39
#include "display/gimpdisplay.h"

Michael Natterer's avatar
Michael Natterer committed
40
41
#include "tools/tool_manager.h"

Michael Natterer's avatar
Michael Natterer committed
42
43
44
#include "widgets/gimpdialogfactory.h"

#include "dialogs.h"
Michael Natterer's avatar
Michael Natterer committed
45
46
47
48
49
50
51
#include "edit-commands.h"

#include "undo.h"

#include "libgimp/gimpintl.h"


Michael Natterer's avatar
Michael Natterer committed
52
53
54
55
56
57
58
59
60
#define return_if_no_display(gdisp,data) \
  gdisp = gimp_context_get_display (gimp_get_user_context (GIMP (data))); \
  if (! gdisp) \
    return

#define return_if_no_image(gimage,data) \
  gimage = gimp_context_get_image (gimp_get_user_context (GIMP (data))); \
  if (! gimage) \
    return
Michael Natterer's avatar
Michael Natterer committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78


/*  local function prototypes  */

static void   cut_named_buffer_callback  (GtkWidget *widget,
					  gchar     *name,
					  gpointer   data);
static void   copy_named_buffer_callback (GtkWidget *widget,
					  gchar     *name,
					  gpointer   data);


/*  public functions  */

void
edit_undo_cmd_callback (GtkWidget *widget,
			gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
79
80
  GimpImage *gimage;
  return_if_no_image (gimage, data);
Michael Natterer's avatar
Michael Natterer committed
81

82
  if (undo_pop (gimage))
83
    gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
84
85
86
87
88
89
}

void
edit_redo_cmd_callback (GtkWidget *widget,
			gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
90
91
  GimpImage *gimage;
  return_if_no_image (gimage, data);
Michael Natterer's avatar
Michael Natterer committed
92

93
  if (undo_redo (gimage))
94
    gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
95
96
97
98
99
100
}

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

  /*  stop any active tool  */
105
  tool_manager_control_active (gdisp->gimage->gimp, HALT, gdisp);
Michael Natterer's avatar
Michael Natterer committed
106

Michael Natterer's avatar
Michael Natterer committed
107
108
  if (gimp_edit_cut (gdisp->gimage,
		     gimp_image_active_drawable (gdisp->gimage)))
Michael Natterer's avatar
Michael Natterer committed
109
    {
110
      gimp_image_flush (gdisp->gimage);
Michael Natterer's avatar
Michael Natterer committed
111
112
113
114
115
116
117
    }
}

void
edit_copy_cmd_callback (GtkWidget *widget,
			gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
118
119
  GimpImage *gimage;
  return_if_no_image (gimage, data);
Michael Natterer's avatar
Michael Natterer committed
120

121
122
  if (gimp_edit_copy (gimage, gimp_image_active_drawable (gimage)))
    {
123
      gimp_image_flush (gimage);
124
    }
Michael Natterer's avatar
Michael Natterer committed
125
126
127
128
129
130
}

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

134
  if (gdisp->gimage->gimp->global_buffer)
Michael Natterer's avatar
Michael Natterer committed
135
136
    {
      /*  stop any active tool  */
137
      tool_manager_control_active (gdisp->gimage->gimp, HALT, gdisp);
Michael Natterer's avatar
Michael Natterer committed
138

Michael Natterer's avatar
Michael Natterer committed
139
140
      if (gimp_edit_paste (gdisp->gimage,
			   gimp_image_active_drawable (gdisp->gimage), 
141
			   gdisp->gimage->gimp->global_buffer,
Michael Natterer's avatar
Michael Natterer committed
142
			   FALSE))
Michael Natterer's avatar
Michael Natterer committed
143
	{
144
          gimp_image_flush (gdisp->gimage);
Michael Natterer's avatar
Michael Natterer committed
145
146
147
148
149
150
151
152
	}
    }
}

void
edit_paste_into_cmd_callback (GtkWidget *widget,
			      gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
153
154
  GimpDisplay *gdisp;
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
155

156
  if (gdisp->gimage->gimp->global_buffer)
Michael Natterer's avatar
Michael Natterer committed
157
158
    {
      /*  stop any active tool  */
159
      tool_manager_control_active (gdisp->gimage->gimp, HALT, gdisp);
Michael Natterer's avatar
Michael Natterer committed
160

Michael Natterer's avatar
Michael Natterer committed
161
162
      if (gimp_edit_paste (gdisp->gimage,
			   gimp_image_active_drawable (gdisp->gimage), 
163
			   gdisp->gimage->gimp->global_buffer,
Michael Natterer's avatar
Michael Natterer committed
164
			   TRUE))
Michael Natterer's avatar
Michael Natterer committed
165
	{
166
          gimp_image_flush (gdisp->gimage);
Michael Natterer's avatar
Michael Natterer committed
167
168
169
170
171
172
173
174
	}
    }
}

void
edit_paste_as_new_cmd_callback (GtkWidget *widget,
				gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
175
176
  GimpDisplay *gdisp;
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
177

178
  if (gdisp->gimage->gimp->global_buffer)
Michael Natterer's avatar
Michael Natterer committed
179
180
    {
      /*  stop any active tool  */
181
      tool_manager_control_active (gdisp->gimage->gimp, HALT, gdisp);
Michael Natterer's avatar
Michael Natterer committed
182

183
184
185
      gimp_edit_paste_as_new (gdisp->gimage->gimp,
			      gdisp->gimage,
			      gdisp->gimage->gimp->global_buffer);
Michael Natterer's avatar
Michael Natterer committed
186
187
188
189
190
191
192
    }
}

void
edit_named_cut_cmd_callback (GtkWidget *widget,
			     gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
193
194
195
  GimpDisplay *gdisp;
  GtkWidget   *qbox;
  return_if_no_display (gdisp, data);
Michael Natterer's avatar
Michael Natterer committed
196
197

  /*  stop any active tool  */
198
  tool_manager_control_active (gdisp->gimage->gimp, HALT, gdisp);
Michael Natterer's avatar
Michael Natterer committed
199
200
201
202
203
204

  qbox = gimp_query_string_box (_("Cut Named"),
				gimp_standard_help_func,
				"dialogs/cut_named.html",
				_("Enter a name for this buffer"),
				NULL,
205
				G_OBJECT (gdisp->gimage), "disconnect",
Michael Natterer's avatar
Michael Natterer committed
206
207
208
209
210
211
212
213
				cut_named_buffer_callback, gdisp->gimage);
  gtk_widget_show (qbox);
}

void
edit_named_copy_cmd_callback (GtkWidget *widget,
			      gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
214
  GimpImage *gimage;
Michael Natterer's avatar
Michael Natterer committed
215
  GtkWidget *qbox;
Michael Natterer's avatar
Michael Natterer committed
216
  return_if_no_image (gimage, data);
Michael Natterer's avatar
Michael Natterer committed
217
218
219
220
221
222

  qbox = gimp_query_string_box (_("Copy Named"),
				gimp_standard_help_func,
				"dialogs/copy_named.html",
				_("Enter a name for this buffer"),
				NULL,
Michael Natterer's avatar
Michael Natterer committed
223
224
				G_OBJECT (gimage), "disconnect",
				copy_named_buffer_callback, gimage);
Michael Natterer's avatar
Michael Natterer committed
225
226
227
228
229
230
231
  gtk_widget_show (qbox);
}

void
edit_named_paste_cmd_callback (GtkWidget *widget,
			       gpointer   data)
{
232
  gimp_dialog_factory_dialog_raise (global_dock_factory, "gimp-buffer-list", -1);
Michael Natterer's avatar
Michael Natterer committed
233
234
235
236
237
238
}

void
edit_clear_cmd_callback (GtkWidget *widget,
			 gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
239
240
  GimpImage *gimage;
  return_if_no_image (gimage, data);
Michael Natterer's avatar
Michael Natterer committed
241

Michael Natterer's avatar
Michael Natterer committed
242
  gimp_edit_clear (gimage, gimp_image_active_drawable (gimage));
243
  gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
244
245
246
247
248
249
250
}

void
edit_fill_cmd_callback (GtkWidget *widget,
			gpointer   data,
			guint      action)
{
Michael Natterer's avatar
Michael Natterer committed
251
  GimpImage    *gimage;
Michael Natterer's avatar
Michael Natterer committed
252
  GimpFillType  fill_type;
Michael Natterer's avatar
Michael Natterer committed
253
  return_if_no_image (gimage, data);
Michael Natterer's avatar
Michael Natterer committed
254
255
256

  fill_type = (GimpFillType) action;

Michael Natterer's avatar
Michael Natterer committed
257
258
  gimp_edit_fill (gimage,
		  gimp_image_active_drawable (gimage),
Michael Natterer's avatar
Michael Natterer committed
259
		  fill_type);
260
  gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
261
262
263
264
265
266
}

void
edit_stroke_cmd_callback (GtkWidget *widget,
			  gpointer   data)
{
Michael Natterer's avatar
Michael Natterer committed
267
268
  GimpImage *gimage;
  return_if_no_image (gimage, data);
Michael Natterer's avatar
Michael Natterer committed
269

270
271
272
  gimp_image_mask_stroke (gimage,
                          gimp_image_active_drawable (gimage),
                          gimp_get_current_context (gimage->gimp));
273
  gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
274
275
276
277
278
279
280
281
282
283
}


/*  private functions  */

static void
cut_named_buffer_callback (GtkWidget *widget,
			   gchar     *name,
			   gpointer   data)
{
284
285
  GimpBuffer *cut_buffer;
  GimpImage  *gimage;
Michael Natterer's avatar
Michael Natterer committed
286
287
288

  gimage = (GimpImage *) data;

289
290
291
292
  cut_buffer = gimp_edit_cut (gimage,
                              gimp_image_active_drawable (gimage));

  if (cut_buffer)
Michael Natterer's avatar
Michael Natterer committed
293
    {
294
295
      GimpBuffer *new_buffer;

296
297
298
      if (! (name && strlen (name)))
        name = _("(Unnamed Buffer)");

299
      new_buffer = gimp_buffer_new (cut_buffer->tiles, name, TRUE);
Michael Natterer's avatar
Michael Natterer committed
300

301
302
      gimp_container_add (gimage->gimp->named_buffers,
                          GIMP_OBJECT (new_buffer));
Michael Natterer's avatar
Michael Natterer committed
303
304
    }

305
  gimp_image_flush (gimage);
Michael Natterer's avatar
Michael Natterer committed
306
307
308
309
310
311
312
}

static void
copy_named_buffer_callback (GtkWidget *widget,
			    gchar     *name,
			    gpointer   data)
{
313
314
  GimpBuffer *copy_buffer;
  GimpImage  *gimage;
Michael Natterer's avatar
Michael Natterer committed
315
316

  gimage = (GimpImage *) data;
Michael Natterer's avatar
Michael Natterer committed
317

318
319
  copy_buffer = gimp_edit_copy (gimage,
                                gimp_image_active_drawable (gimage));
Michael Natterer's avatar
Michael Natterer committed
320

321
  if (copy_buffer)
Michael Natterer's avatar
Michael Natterer committed
322
    {
323
324
      GimpBuffer *new_buffer;

325
326
327
      if (! (name && strlen (name)))
        name = _("(Unnamed Buffer)");

328
      new_buffer = gimp_buffer_new (copy_buffer->tiles, name, TRUE);
Michael Natterer's avatar
Michael Natterer committed
329

330
331
      gimp_container_add (gimage->gimp->named_buffers,
                          GIMP_OBJECT (new_buffer));
Michael Natterer's avatar
Michael Natterer committed
332
333
    }
}