1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimptool-progress.c
* Copyright (C) 2011 Michael Natterer <mitch@gimp.org>
*
* 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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "tools-types.h"
#include "core/gimpprogress.h"
#include "widgets/gimpwidgets-utils.h"
#include "display/gimpcanvasprogress.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "display/gimpdisplayshell-items.h"
#include "display/gimpdisplayshell-transform.h"
#include "gimptool.h"
#include "gimptool-progress.h"
/* local function prototypes */
static GimpProgress * gimp_tool_progress_start (GimpProgress *progress,
gboolean cancellable,
const gchar *message);
static void gimp_tool_progress_end (GimpProgress *progress);
static gboolean gimp_tool_progress_is_active (GimpProgress *progress);
static void gimp_tool_progress_set_text (GimpProgress *progress,
const gchar *message);
static void gimp_tool_progress_set_value (GimpProgress *progress,
gdouble percentage);
static gdouble gimp_tool_progress_get_value (GimpProgress *progress);
static void gimp_tool_progress_pulse (GimpProgress *progress);
static gboolean gimp_tool_progress_message (GimpProgress *progress,
Gimp *gimp,
GimpMessageSeverity severity,
const gchar *domain,
const gchar *message);
/* public functions */
void
gimp_tool_progress_iface_init (GimpProgressInterface *iface)
{
iface->start = gimp_tool_progress_start;
iface->end = gimp_tool_progress_end;
iface->is_active = gimp_tool_progress_is_active;
iface->set_text = gimp_tool_progress_set_text;
iface->set_value = gimp_tool_progress_set_value;
iface->get_value = gimp_tool_progress_get_value;
iface->pulse = gimp_tool_progress_pulse;
iface->message = gimp_tool_progress_message;
}
/* private functions */
static gboolean
gimp_tool_progress_button_press (GtkWidget *widget,
const GdkEventButton *bevent,
GimpTool *tool)
{
if (bevent->type == GDK_BUTTON_PRESS &&
bevent->button == 1)
{
GtkWidget *event_widget;
GimpDisplayShell *shell;
event_widget = gtk_get_event_widget ((GdkEvent *) bevent);
shell = gimp_display_get_shell (tool->progress_display);
if (shell->canvas == event_widget)
{
gint x, y;
gimp_display_shell_unzoom_xy (shell, bevent->x, bevent->y,
&x, &y, FALSE);
if (gimp_canvas_item_hit (tool->progress, x, y))
{
gimp_progress_cancel (GIMP_PROGRESS (tool));
}
}
}
return TRUE;
}
static gboolean
gimp_tool_progress_key_press (GtkWidget *widget,
const GdkEventKey *kevent,
GimpTool *tool)
{
if (kevent->keyval == GDK_KEY_Escape)
{
gimp_progress_cancel (GIMP_PROGRESS (tool));
}
return TRUE;
}
static GimpProgress *
gimp_tool_progress_start (GimpProgress *progress,
gboolean cancellable,
const gchar *message)
{
GimpTool *tool = GIMP_TOOL (progress);
GimpDisplayShell *shell;
gint x, y;
g_return_val_if_fail (GIMP_IS_DISPLAY (tool->display), NULL);
g_return_val_if_fail (tool->progress == NULL, NULL);
shell = gimp_display_get_shell (tool->display);
x = shell->disp_width / 2;
y = shell->disp_height / 2;
gimp_display_shell_unzoom_xy (shell, x, y, &x, &y, FALSE);
tool->progress = gimp_canvas_progress_new (shell,
GIMP_HANDLE_ANCHOR_CENTER,
x, y);
gimp_display_shell_add_unrotated_item (shell, tool->progress);
g_object_unref (tool->progress);
gimp_progress_start (GIMP_PROGRESS (tool->progress), FALSE,
"%s", message);
gimp_widget_flush_expose (shell->canvas);
tool->progress_display = tool->display;
if (cancellable)
{
tool->progress_grab_widget = gtk_invisible_new ();
gtk_widget_show (tool->progress_grab_widget);
gtk_grab_add (tool->progress_grab_widget);
g_signal_connect (tool->progress_grab_widget, "button-press-event",
G_CALLBACK (gimp_tool_progress_button_press),
tool);
g_signal_connect (tool->progress_grab_widget, "key-press-event",
G_CALLBACK (gimp_tool_progress_key_press),
tool);
}
return progress;
}
static void
gimp_tool_progress_end (GimpProgress *progress)
{
GimpTool *tool = GIMP_TOOL (progress);
if (tool->progress)
{
GimpDisplayShell *shell = gimp_display_get_shell (tool->progress_display);
gimp_progress_end (GIMP_PROGRESS (tool->progress));
gimp_display_shell_remove_unrotated_item (shell, tool->progress);
tool->progress = NULL;
tool->progress_display = NULL;
if (tool->progress_grab_widget)
{
gtk_grab_remove (tool->progress_grab_widget);
gtk_widget_destroy (tool->progress_grab_widget);
tool->progress_grab_widget = NULL;
}
}
}
static gboolean
gimp_tool_progress_is_active (GimpProgress *progress)
{
GimpTool *tool = GIMP_TOOL (progress);
return tool->progress != NULL;
}
static void
gimp_tool_progress_set_text (GimpProgress *progress,
const gchar *message)
{
GimpTool *tool = GIMP_TOOL (progress);
if (tool->progress)
{
GimpDisplayShell *shell = gimp_display_get_shell (tool->progress_display);
gimp_progress_set_text_literal (GIMP_PROGRESS (tool->progress), message);
gimp_widget_flush_expose (shell->canvas);
}
}
static void
gimp_tool_progress_set_value (GimpProgress *progress,
gdouble percentage)
{
GimpTool *tool = GIMP_TOOL (progress);
if (tool->progress)
{
GimpDisplayShell *shell = gimp_display_get_shell (tool->progress_display);
gimp_progress_set_value (GIMP_PROGRESS (tool->progress), percentage);
gimp_widget_flush_expose (shell->canvas);
}
}
static gdouble
gimp_tool_progress_get_value (GimpProgress *progress)
{
GimpTool *tool = GIMP_TOOL (progress);
if (tool->progress)
return gimp_progress_get_value (GIMP_PROGRESS (tool->progress));
return 0.0;
}
static void
gimp_tool_progress_pulse (GimpProgress *progress)
{
}
static gboolean
gimp_tool_progress_message (GimpProgress *progress,
Gimp *gimp,
GimpMessageSeverity severity,
const gchar *domain,
const gchar *message)
{
return FALSE;
}
|