~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/tools/tool_manager.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
35
35
 
36
36
#include "display/gimpdisplay.h"
37
37
 
38
 
#include "gimpdrawtool.h"
 
38
#include "gimptool.h"
39
39
#include "gimptoolcontrol.h"
40
40
#include "tool_manager.h"
41
41
 
42
 
#include "gimp-intl.h"
43
 
 
44
42
 
45
43
typedef struct _GimpToolManager GimpToolManager;
46
44
 
62
60
static void   tool_manager_tool_changed      (GimpContext     *user_context,
63
61
                                              GimpToolInfo    *tool_info,
64
62
                                              gpointer         data);
65
 
static void   tool_manager_image_clean_dirty (GimpImage       *gimage,
 
63
static void   tool_manager_image_clean_dirty (GimpImage       *image,
66
64
                                              GimpDirtyMask    dirty_mask,
67
65
                                              GimpToolManager *tool_manager);
68
66
 
88
86
 
89
87
  tool_manager->image_clean_handler_id =
90
88
    gimp_container_add_handler (gimp->images, "clean",
91
 
                                G_CALLBACK (tool_manager_image_clean_dirty),
92
 
                                tool_manager);
 
89
                                G_CALLBACK (tool_manager_image_clean_dirty),
 
90
                                tool_manager);
93
91
 
94
92
  tool_manager->image_dirty_handler_id =
95
93
    gimp_container_add_handler (gimp->images, "dirty",
96
 
                                G_CALLBACK (tool_manager_image_clean_dirty),
97
 
                                tool_manager);
 
94
                                G_CALLBACK (tool_manager_image_clean_dirty),
 
95
                                tool_manager);
98
96
 
99
97
  user_context = gimp_get_user_context (gimp);
100
98
 
101
 
  g_signal_connect (user_context, "tool_changed",
102
 
                    G_CALLBACK (tool_manager_tool_changed),
103
 
                    tool_manager);
 
99
  g_signal_connect (user_context, "tool-changed",
 
100
                    G_CALLBACK (tool_manager_tool_changed),
 
101
                    tool_manager);
104
102
}
105
103
 
106
104
void
114
112
  tool_manager_set (gimp, NULL);
115
113
 
116
114
  gimp_container_remove_handler (gimp->images,
117
 
                                 tool_manager->image_clean_handler_id);
 
115
                                 tool_manager->image_clean_handler_id);
118
116
  gimp_container_remove_handler (gimp->images,
119
 
                                 tool_manager->image_dirty_handler_id);
 
117
                                 tool_manager->image_dirty_handler_id);
120
118
 
121
119
  if (tool_manager->active_tool)
122
120
    g_object_unref (tool_manager->active_tool);
138
136
 
139
137
void
140
138
tool_manager_select_tool (Gimp     *gimp,
141
 
                          GimpTool *tool)
 
139
                          GimpTool *tool)
142
140
{
143
141
  GimpToolManager *tool_manager;
144
142
 
149
147
 
150
148
  if (tool_manager->active_tool)
151
149
    {
152
 
      GimpDisplay *gdisp = tool_manager->active_tool->gdisp;
153
 
 
154
 
      if (! gdisp && GIMP_IS_DRAW_TOOL (tool_manager->active_tool))
155
 
        gdisp = GIMP_DRAW_TOOL (tool_manager->active_tool)->gdisp;
156
 
 
157
 
      if (gdisp)
158
 
        tool_manager_control_active (gimp, HALT, gdisp);
159
 
 
 
150
      GimpTool    *active_tool = tool_manager->active_tool;
 
151
      GimpDisplay *display;
 
152
 
 
153
      /*  NULL image returns any display (if there is any)  */
 
154
      display = gimp_tool_has_image (active_tool, NULL);
 
155
 
 
156
      tool_manager_control_active (gimp, GIMP_TOOL_ACTION_HALT, display);
160
157
      tool_manager_focus_display_active (gimp, NULL);
161
158
 
162
159
      g_object_unref (tool_manager->active_tool);
167
164
 
168
165
void
169
166
tool_manager_push_tool (Gimp     *gimp,
170
 
                        GimpTool *tool)
 
167
                        GimpTool *tool)
171
168
{
172
169
  GimpToolManager *tool_manager;
 
170
  GimpDisplay     *focus_display = NULL;
173
171
 
174
172
  g_return_if_fail (GIMP_IS_GIMP (gimp));
175
173
  g_return_if_fail (GIMP_IS_TOOL (tool));
178
176
 
179
177
  if (tool_manager->active_tool)
180
178
    {
 
179
      focus_display = tool_manager->active_tool->focus_display;
 
180
 
181
181
      tool_manager->tool_stack = g_slist_prepend (tool_manager->tool_stack,
182
 
                                                  tool_manager->active_tool);
 
182
                                                  tool_manager->active_tool);
183
183
 
184
184
      g_object_ref (tool_manager->tool_stack->data);
185
185
    }
186
186
 
187
187
  tool_manager_select_tool (gimp, tool);
 
188
 
 
189
  if (focus_display)
 
190
    tool_manager_focus_display_active (gimp, focus_display);
188
191
}
189
192
 
190
193
void
198
201
 
199
202
  if (tool_manager->tool_stack)
200
203
    {
201
 
      tool_manager_select_tool (gimp,
202
 
                                GIMP_TOOL (tool_manager->tool_stack->data));
 
204
      GimpTool    *tool          = tool_manager->tool_stack->data;
 
205
      GimpDisplay *focus_display = NULL;
203
206
 
204
 
      g_object_unref (tool_manager->tool_stack->data);
 
207
      if (tool_manager->active_tool)
 
208
        focus_display = tool_manager->active_tool->focus_display;
205
209
 
206
210
      tool_manager->tool_stack = g_slist_remove (tool_manager->tool_stack,
207
 
                                                 tool_manager->active_tool);
 
211
                                                 tool);
 
212
 
 
213
      tool_manager_select_tool (gimp, tool);
 
214
      g_object_unref (tool);
 
215
 
 
216
      if (focus_display)
 
217
        tool_manager_focus_display_active (gimp, focus_display);
208
218
    }
209
219
}
210
220
 
211
221
gboolean
212
222
tool_manager_initialize_active (Gimp        *gimp,
213
 
                                GimpDisplay *gdisp)
 
223
                                GimpDisplay *display)
214
224
{
215
225
  GimpToolManager *tool_manager;
216
 
  GimpTool        *tool;
217
226
 
218
227
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
219
 
  g_return_val_if_fail (GIMP_IS_DISPLAY (gdisp), FALSE);
 
228
  g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE);
220
229
 
221
230
  tool_manager = tool_manager_get (gimp);
222
231
 
223
232
  if (tool_manager->active_tool)
224
233
    {
225
 
      tool = tool_manager->active_tool;
 
234
      GimpTool *tool = tool_manager->active_tool;
226
235
 
227
 
      if (gimp_tool_initialize (tool, gdisp))
 
236
      if (gimp_tool_initialize (tool, display))
228
237
        {
229
 
          tool->drawable = gimp_image_active_drawable (gdisp->gimage);
 
238
          tool->drawable = gimp_image_active_drawable (display->image);
230
239
 
231
240
          return TRUE;
232
241
        }
237
246
 
238
247
void
239
248
tool_manager_control_active (Gimp           *gimp,
240
 
                             GimpToolAction  action,
241
 
                             GimpDisplay    *gdisp)
 
249
                             GimpToolAction  action,
 
250
                             GimpDisplay    *display)
242
251
{
243
252
  GimpToolManager *tool_manager;
244
253
 
246
255
 
247
256
  tool_manager = tool_manager_get (gimp);
248
257
 
249
 
  if (! tool_manager->active_tool)
250
 
    return;
 
258
  if (tool_manager->active_tool)
 
259
    {
 
260
      GimpTool *tool = tool_manager->active_tool;
251
261
 
252
 
  if (gdisp && (tool_manager->active_tool->gdisp == gdisp ||
253
 
                (GIMP_IS_DRAW_TOOL (tool_manager->active_tool) &&
254
 
                 GIMP_DRAW_TOOL (tool_manager->active_tool)->gdisp == gdisp)))
255
 
    {
256
 
      gimp_tool_control (tool_manager->active_tool, action, gdisp);
257
 
    }
258
 
  else if (action == HALT)
259
 
    {
260
 
      if (gimp_tool_control_is_active (tool_manager->active_tool->control))
261
 
        gimp_tool_control_halt (tool_manager->active_tool->control);
 
262
      if (display && gimp_tool_has_display (tool, display))
 
263
        {
 
264
          gimp_tool_control (tool, action, display);
 
265
        }
 
266
      else if (action == GIMP_TOOL_ACTION_HALT)
 
267
        {
 
268
          if (gimp_tool_control_is_active (tool->control))
 
269
            gimp_tool_control_halt (tool->control);
 
270
        }
262
271
    }
263
272
}
264
273
 
267
276
                                  GimpCoords      *coords,
268
277
                                  guint32          time,
269
278
                                  GdkModifierType  state,
270
 
                                  GimpDisplay     *gdisp)
 
279
                                  GimpDisplay     *display)
271
280
{
272
281
  GimpToolManager *tool_manager;
273
282
 
279
288
    {
280
289
      gimp_tool_button_press (tool_manager->active_tool,
281
290
                              coords, time, state,
282
 
                              gdisp);
 
291
                              display);
283
292
    }
284
293
}
285
294
 
288
297
                                    GimpCoords      *coords,
289
298
                                    guint32          time,
290
299
                                    GdkModifierType  state,
291
 
                                    GimpDisplay     *gdisp)
 
300
                                    GimpDisplay     *display)
292
301
{
293
302
  GimpToolManager *tool_manager;
294
303
 
300
309
    {
301
310
      gimp_tool_button_release (tool_manager->active_tool,
302
311
                                coords, time, state,
303
 
                                gdisp);
 
312
                                display);
304
313
    }
305
314
}
306
315
 
309
318
                            GimpCoords      *coords,
310
319
                            guint32          time,
311
320
                            GdkModifierType  state,
312
 
                            GimpDisplay     *gdisp)
 
321
                            GimpDisplay     *display)
313
322
{
314
323
  GimpToolManager *tool_manager;
315
324
 
321
330
    {
322
331
      gimp_tool_motion (tool_manager->active_tool,
323
332
                        coords, time, state,
324
 
                        gdisp);
 
333
                        display);
325
334
    }
326
335
}
327
336
 
328
337
gboolean
329
338
tool_manager_key_press_active (Gimp        *gimp,
330
339
                               GdkEventKey *kevent,
331
 
                               GimpDisplay *gdisp)
 
340
                               GimpDisplay *display)
332
341
{
333
342
  GimpToolManager *tool_manager;
334
343
 
340
349
    {
341
350
      return gimp_tool_key_press (tool_manager->active_tool,
342
351
                                  kevent,
343
 
                                  gdisp);
 
352
                                  display);
344
353
    }
345
354
 
346
355
  return FALSE;
348
357
 
349
358
void
350
359
tool_manager_focus_display_active (Gimp        *gimp,
351
 
                                   GimpDisplay *gdisp)
 
360
                                   GimpDisplay *display)
352
361
{
353
362
  GimpToolManager *tool_manager;
354
363
 
359
368
  if (tool_manager->active_tool)
360
369
    {
361
370
      gimp_tool_set_focus_display (tool_manager->active_tool,
362
 
                                   gdisp);
 
371
                                   display);
363
372
    }
364
373
}
365
374
 
366
375
void
367
376
tool_manager_modifier_state_active (Gimp            *gimp,
368
377
                                    GdkModifierType  state,
369
 
                                    GimpDisplay     *gdisp)
 
378
                                    GimpDisplay     *display)
370
379
{
371
380
  GimpToolManager *tool_manager;
372
381
 
378
387
    {
379
388
      gimp_tool_set_modifier_state (tool_manager->active_tool,
380
389
                                    state,
381
 
                                    gdisp);
 
390
                                    display);
 
391
    }
 
392
}
 
393
 
 
394
void
 
395
tool_manager_active_modifier_state_active (Gimp            *gimp,
 
396
                                           GdkModifierType  state,
 
397
                                           GimpDisplay     *display)
 
398
{
 
399
  GimpToolManager *tool_manager;
 
400
 
 
401
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
402
 
 
403
  tool_manager = tool_manager_get (gimp);
 
404
 
 
405
  if (tool_manager->active_tool)
 
406
    {
 
407
      gimp_tool_set_active_modifier_state (tool_manager->active_tool,
 
408
                                           state,
 
409
                                           display);
382
410
    }
383
411
}
384
412
 
386
414
tool_manager_oper_update_active (Gimp            *gimp,
387
415
                                 GimpCoords      *coords,
388
416
                                 GdkModifierType  state,
389
 
                                 GimpDisplay     *gdisp)
 
417
                                 gboolean         proximity,
 
418
                                 GimpDisplay     *display)
390
419
{
391
420
  GimpToolManager *tool_manager;
392
421
 
397
426
  if (tool_manager->active_tool)
398
427
    {
399
428
      gimp_tool_oper_update (tool_manager->active_tool,
400
 
                             coords, state,
401
 
                             gdisp);
 
429
                             coords, state, proximity,
 
430
                             display);
402
431
    }
403
432
}
404
433
 
406
435
tool_manager_cursor_update_active (Gimp            *gimp,
407
436
                                   GimpCoords      *coords,
408
437
                                   GdkModifierType  state,
409
 
                                   GimpDisplay     *gdisp)
 
438
                                   GimpDisplay     *display)
410
439
{
411
440
  GimpToolManager *tool_manager;
412
441
 
418
447
    {
419
448
      gimp_tool_cursor_update (tool_manager->active_tool,
420
449
                               coords, state,
421
 
                               gdisp);
 
450
                               display);
422
451
    }
423
452
}
424
453
 
438
467
 
439
468
static void
440
469
tool_manager_set (Gimp            *gimp,
441
 
                  GimpToolManager *tool_manager)
 
470
                  GimpToolManager *tool_manager)
442
471
{
443
472
  if (! tool_manager_quark)
444
473
    tool_manager_quark = g_quark_from_static_string ("gimp-tool-manager");
448
477
 
449
478
static void
450
479
tool_manager_tool_changed (GimpContext  *user_context,
451
 
                           GimpToolInfo *tool_info,
452
 
                           gpointer      data)
 
480
                           GimpToolInfo *tool_info,
 
481
                           gpointer      data)
453
482
{
454
483
  GimpToolManager *tool_manager = data;
455
484
  GimpTool        *new_tool     = NULL;
460
489
  /* FIXME: gimp_busy HACK */
461
490
  if (user_context->gimp->busy)
462
491
    {
463
 
      /*  there may be contexts waiting for the user_context's "tool_changed"
 
492
      /*  there may be contexts waiting for the user_context's "tool-changed"
464
493
       *  signal, so stop emitting it.
465
494
       */
466
 
      g_signal_stop_emission_by_name (user_context, "tool_changed");
 
495
      g_signal_stop_emission_by_name (user_context, "tool-changed");
467
496
 
468
497
      if (G_TYPE_FROM_INSTANCE (tool_manager->active_tool) !=
469
 
          tool_info->tool_type)
470
 
        {
471
 
          g_signal_handlers_block_by_func (user_context,
472
 
                                           tool_manager_tool_changed,
473
 
                                           data);
 
498
          tool_info->tool_type)
 
499
        {
 
500
          g_signal_handlers_block_by_func (user_context,
 
501
                                           tool_manager_tool_changed,
 
502
                                           data);
474
503
 
475
 
          /*  explicitly set the current tool  */
476
 
          gimp_context_set_tool (user_context,
 
504
          /*  explicitly set the current tool  */
 
505
          gimp_context_set_tool (user_context,
477
506
                                 tool_manager->active_tool->tool_info);
478
507
 
479
 
          g_signal_handlers_unblock_by_func (user_context,
480
 
                                             tool_manager_tool_changed,
481
 
                                             data);
482
 
        }
 
508
          g_signal_handlers_unblock_by_func (user_context,
 
509
                                             tool_manager_tool_changed,
 
510
                                             data);
 
511
        }
483
512
 
484
513
      return;
485
514
    }
493
522
  else
494
523
    {
495
524
      g_warning ("%s: tool_info->tool_type is no GimpTool subclass",
496
 
                 G_STRFUNC);
 
525
                 G_STRFUNC);
497
526
      return;
498
527
    }
499
528
 
504
533
    {
505
534
      GimpToolInfo *old_tool_info = tool_manager->active_tool->tool_info;
506
535
 
507
 
      gimp_context_set_parent (GIMP_CONTEXT (old_tool_info->tool_options), NULL);
 
536
      gimp_context_set_parent (GIMP_CONTEXT (old_tool_info->tool_options),
 
537
                               NULL);
508
538
    }
509
539
 
510
540
  /*  connect the new tool's context  */
541
571
}
542
572
 
543
573
static void
544
 
tool_manager_image_clean_dirty (GimpImage       *gimage,
 
574
tool_manager_image_clean_dirty (GimpImage       *image,
545
575
                                GimpDirtyMask    dirty_mask,
546
576
                                GimpToolManager *tool_manager)
547
577
{
548
 
  GimpTool *active_tool = tool_manager->active_tool;
 
578
  GimpTool *tool = tool_manager->active_tool;
549
579
 
550
 
  if (active_tool &&
551
 
      ! gimp_tool_control_preserve (active_tool->control) &&
552
 
      (gimp_tool_control_dirty_mask (active_tool->control) & dirty_mask))
 
580
  if (tool &&
 
581
      ! gimp_tool_control_get_preserve (tool->control) &&
 
582
      (gimp_tool_control_get_dirty_mask (tool->control) & dirty_mask))
553
583
    {
554
 
      GimpDisplay *gdisp = active_tool->gdisp;
555
 
 
556
 
      if (! gdisp || gdisp->gimage != gimage)
557
 
        if (GIMP_IS_DRAW_TOOL (active_tool))
558
 
          gdisp = GIMP_DRAW_TOOL (active_tool)->gdisp;
559
 
 
560
 
      if (gdisp && gdisp->gimage == gimage)
561
 
        tool_manager_control_active (gimage->gimp, HALT, gdisp);
 
584
      GimpDisplay *display = gimp_tool_has_image (tool, image);
 
585
 
 
586
      if (display)
 
587
        tool_manager_control_active (image->gimp, GIMP_TOOL_ACTION_HALT,
 
588
                                     display);
562
589
    }
563
590
}