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

« back to all changes in this revision

Viewing changes to app/dialogs/fade-dialog.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
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 */
 
18
 
 
19
#include "config.h"
 
20
 
 
21
#include <gtk/gtk.h>
 
22
 
 
23
#include "libgimpbase/gimpbase.h"
 
24
#include "libgimpwidgets/gimpwidgets.h"
 
25
 
 
26
#include "dialogs-types.h"
 
27
 
 
28
#include "core/gimp-edit.h"
 
29
#include "core/gimpcontext.h"
 
30
#include "core/gimpimage.h"
 
31
#include "core/gimpimage-undo.h"
 
32
#include "core/gimpdrawable.h"
 
33
#include "core/gimpdrawableundo.h"
 
34
#include "core/gimpundostack.h"
 
35
 
 
36
#include "widgets/gimppropwidgets.h"
 
37
#include "widgets/gimphelp-ids.h"
 
38
#include "widgets/gimpviewabledialog.h"
 
39
 
 
40
#include "fade-dialog.h"
 
41
 
 
42
#include "gimp-intl.h"
 
43
 
 
44
 
 
45
typedef struct _FadeDialog FadeDialog;
 
46
 
 
47
struct _FadeDialog
 
48
{
 
49
  GimpImage            *image;
 
50
  GimpDrawable         *drawable;
 
51
  GimpContext          *context;
 
52
 
 
53
  gboolean              applied;
 
54
  GimpLayerModeEffects  orig_paint_mode;
 
55
  gdouble               orig_opacity;
 
56
};
 
57
 
 
58
 
 
59
static void   fade_dialog_response        (GtkWidget  *dialog,
 
60
                                           gint        response_id,
 
61
                                           FadeDialog *private);
 
62
 
 
63
static void   fade_dialog_context_changed (FadeDialog *private);
 
64
 
 
65
 
 
66
/*  public functions  */
 
67
 
 
68
GtkWidget *
 
69
fade_dialog_new (GimpImage *image,
 
70
                 GtkWidget *parent)
 
71
{
 
72
  FadeDialog       *private;
 
73
  GimpDrawableUndo *undo;
 
74
  GimpDrawable     *drawable;
 
75
  GimpItem         *item;
 
76
 
 
77
  GtkWidget        *dialog;
 
78
  GtkWidget        *main_vbox;
 
79
  GtkWidget        *table;
 
80
  GtkWidget        *menu;
 
81
  GtkWidget        *label;
 
82
  gchar            *title;
 
83
  gint              table_row = 0;
 
84
 
 
85
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
 
86
  g_return_val_if_fail (GTK_IS_WIDGET (parent), NULL);
 
87
 
 
88
  undo = GIMP_DRAWABLE_UNDO (gimp_image_undo_get_fadeable (image));
 
89
 
 
90
  if (! (undo && undo->src2_tiles))
 
91
    return NULL;
 
92
 
 
93
  item      = GIMP_ITEM_UNDO (undo)->item;
 
94
  drawable  = GIMP_DRAWABLE (item);
 
95
 
 
96
  private = g_new0 (FadeDialog, 1);
 
97
 
 
98
  private->image           = image;
 
99
  private->drawable        = drawable;
 
100
  private->context         = gimp_context_new (image->gimp,
 
101
                                               "fade-dialog", NULL);
 
102
  private->applied         = FALSE;
 
103
  private->orig_paint_mode = undo->paint_mode;
 
104
  private->orig_opacity    = undo->opacity;
 
105
 
 
106
  g_object_set (private->context,
 
107
                "paint-mode", undo->paint_mode,
 
108
                "opacity",    undo->opacity,
 
109
                NULL);
 
110
 
 
111
  title = g_strdup_printf (_("Fade %s"),
 
112
                           gimp_object_get_name (GIMP_OBJECT (undo)));
 
113
 
 
114
 
 
115
  dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (drawable),
 
116
                                     private->context,
 
117
                                     title, "gimp-edit-fade",
 
118
                                     GTK_STOCK_UNDO, title,
 
119
                                     parent,
 
120
                                     gimp_standard_help_func,
 
121
                                     GIMP_HELP_EDIT_FADE,
 
122
 
 
123
                                     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
124
                                     _("_Fade"),       GTK_RESPONSE_OK,
 
125
 
 
126
                                     NULL);
 
127
 
 
128
  g_free (title);
 
129
 
 
130
  gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
 
131
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
 
132
                                           GTK_RESPONSE_OK,
 
133
                                           GTK_RESPONSE_CANCEL,
 
134
                                           -1);
 
135
 
 
136
  g_object_weak_ref (G_OBJECT (dialog), (GWeakNotify) g_free, private);
 
137
 
 
138
  g_signal_connect (dialog, "response",
 
139
                    G_CALLBACK (fade_dialog_response),
 
140
                    private);
 
141
 
 
142
  main_vbox = gtk_vbox_new (FALSE, 12);
 
143
  gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
 
144
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), main_vbox);
 
145
  gtk_widget_show (main_vbox);
 
146
 
 
147
  table = gtk_table_new (3, 3, FALSE);
 
148
  gtk_table_set_col_spacings (GTK_TABLE (table), 2);
 
149
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);
 
150
  gtk_box_pack_start (GTK_BOX (main_vbox), table, FALSE, FALSE, 0);
 
151
  gtk_widget_show (table);
 
152
 
 
153
  /*  the paint mode menu  */
 
154
  menu = gimp_prop_paint_mode_menu_new (G_OBJECT (private->context),
 
155
                                        "paint-mode", TRUE, TRUE);
 
156
  label = gimp_table_attach_aligned (GTK_TABLE (table), 0, table_row++,
 
157
                                     _("_Mode:"), 0.0, 0.5,
 
158
                                     menu, 2, FALSE);
 
159
 
 
160
  /*  the opacity scale  */
 
161
  gimp_prop_opacity_entry_new (G_OBJECT (private->context), "opacity",
 
162
                               GTK_TABLE (table), 0, table_row++,
 
163
                               _("_Opacity:"));
 
164
 
 
165
  g_signal_connect_swapped (private->context, "paint-mode-changed",
 
166
                            G_CALLBACK (fade_dialog_context_changed),
 
167
                            private);
 
168
  g_signal_connect_swapped (private->context, "opacity-changed",
 
169
                            G_CALLBACK (fade_dialog_context_changed),
 
170
                            private);
 
171
 
 
172
  return dialog;
 
173
}
 
174
 
 
175
 
 
176
/*  private functions  */
 
177
 
 
178
static void
 
179
fade_dialog_response (GtkWidget  *dialog,
 
180
                      gint        response_id,
 
181
                      FadeDialog *private)
 
182
{
 
183
  g_signal_handlers_disconnect_by_func (private->context,
 
184
                                        fade_dialog_context_changed,
 
185
                                        private);
 
186
 
 
187
  if (response_id != GTK_RESPONSE_OK && private->applied)
 
188
    {
 
189
      g_object_set (private->context,
 
190
                    "paint-mode", private->orig_paint_mode,
 
191
                    "opacity",    private->orig_opacity,
 
192
                    NULL);
 
193
 
 
194
      fade_dialog_context_changed (private);
 
195
    }
 
196
 
 
197
  g_object_unref (private->context);
 
198
  gtk_widget_destroy (dialog);
 
199
}
 
200
 
 
201
static void
 
202
fade_dialog_context_changed (FadeDialog *private)
 
203
{
 
204
  if (gimp_edit_fade (private->image, private->context))
 
205
    {
 
206
      private->applied = TRUE;
 
207
      gimp_image_flush (private->image);
 
208
    }
 
209
}