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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
/* See LICENSE file for copyright and license details. */
#include "common.h"
static void
reload_current_file(void)
{
if (load_image(get_file(), 0))
reload_redraw();
}
static void
reset_transformations(void)
{
enum transformation augment = reset_transformations_without_redraw();
if (augment != TRANS_NONE)
transform_redraw(augment);
}
static void
transform(enum transformation augment)
{
if (add_transformation_without_redraw(augment))
transform_redraw(augment);
}
static void
set_zoom_fit(GtkToggleAction *action, enum zoom_mode mode)
{
struct image image;
if (gtk_toggle_action_get_active(action)) {
zoom_mode = mode;
if (get_image(&image))
set_zoom_and_recentre(calculate_zoom_mode(&image, zoom_mode));
} else if (zoom_mode == mode) {
zoom_mode = ZOOM_CUSTOM; /* deselect zoom */
}
clear_toggles(GROUP_ZOOM, action);
}
static void
navigate(size_t jump, size_t move)
{
if (navigate_without_redraw(jump, move))
navigate_redraw();
}
void
open_action(GtkAction *action, void *user)
{
GtkFileChooser *chooser;
(void) action;
(void) user;
chooser = construct_chooser();
add_image_filters(chooser);
if (gtk_dialog_run(GTK_DIALOG(chooser)) == GTK_RESPONSE_ACCEPT)
set_images_from_list(gtk_file_chooser_get_filenames(chooser));
gtk_widget_destroy(GTK_WIDGET(chooser));
}
void
reload_action(GtkAction *action, void *user)
{
(void) action;
(void) user;
reload_current_file();
}
void
print_action(GtkAction *action, void *user)
{
struct image image;
(void) action;
(void) user;
if (get_image(&image))
open_print(&image);
}
void
properties_action(GtkAction *action, void *user)
{
(void) action;
(void) user;
open_properties(get_file());
}
void
preferences_action(GtkAction *action, void *user)
{
(void) action;
(void) user;
open_preferences();
}
void
property_pane_action(GtkToggleAction *action, void *user)
{
(void) user;
set_property_pane_visible(gtk_toggle_action_get_active(action));
}
void
collection_pane_action(GtkToggleAction *action, void *user)
{
(void) user;
set_collection_pane_visible(gtk_toggle_action_get_active(action));
}
void
close_action(GtkAction *action, void *user)
{
(void) action;
(void) user;
gtk_main_quit();
}
void
fullscreen_action(GtkToggleAction *action, void *user)
{
int active = gtk_toggle_action_get_active(action);
(void) user;
if (active && current_file >= nfiles)
gtk_toggle_action_set_active(action, 0);
else
set_fullscreen_mode(active);
}
void
reset_transformations_action(GtkAction *action, void *user)
{
(void) action;
(void) user;
reset_transformations();
}
void
rotate_clockwise_action(GtkAction *action, void *user)
{
(void) action;
(void) user;
transform(TRANS_CLOCKWISE);
}
void
rotate_180_degrees_action(GtkAction *action, void *user)
{
(void) action;
(void) user;
transform(TRANS_180_DEGREES);
}
void
rotate_anticlockwise_action(GtkAction *action, void *user)
{
(void) action;
(void) user;
transform(TRANS_ANTICLOCKWISE);
}
void
flop_action(GtkAction *action, void *user)
{
(void) action;
(void) user;
transform(TRANS_FLOP);
}
void
flip_action(GtkAction *action, void *user)
{
(void) action;
(void) user;
transform(TRANS_FLIP);
}
void
transpose_action(GtkAction *action, void *user)
{
(void) action;
(void) user;
transform(TRANS_TRANSPOSE);
}
void
antitranspose_action(GtkAction *action, void *user)
{
(void) action;
(void) user;
transform(TRANS_ANTITRANSPOSE);
}
void
invert_action(GtkToggleAction *action, void *user)
{
enum transformation tr;
(void) user;
tr = gtk_toggle_action_get_active(action) ? TRANS_NEGATIVE : TRANS_NONE;
transform(tr ^ (trans & TRANS_NEGATIVE));
}
void
zoom_in_action(GtkAction *action, void *user)
{
(void) action;
(void) user;
clear_toggles(GROUP_ZOOM, NULL);
set_zoom_around_centre(zoom_in(zoom));
}
void
zoom_out_action(GtkAction *action, void *user)
{
(void) action;
(void) user;
clear_toggles(GROUP_ZOOM, NULL);
set_zoom_around_centre(zoom_out(zoom));
}
void
normal_size_action(GtkToggleAction *action, void *user)
{
(void) action;
(void) user;
clear_toggles(GROUP_ZOOM, NULL);
set_zoom_around_centre(normal_zoom);
}
#define X(E, A, ...)\
void\
A(GtkToggleAction *action, void *user)\
{\
(void) user;\
set_zoom_fit(action, E);\
}
LIST_ZOOM_MODES(X,)
#undef X
void
next_action(GtkAction *action, void *user)
{
(void) action;
(void) user;
navigate(current_file, +(size_t)1);
}
void
previous_action(GtkAction *action, void *user)
{
(void) action;
(void) user;
navigate(current_file ? current_file : nfiles, -(size_t)1);
}
void
first_action(GtkAction *action, void *user)
{
(void) action;
(void) user;
navigate(0u, 0u);
}
void
last_action(GtkAction *action, void *user)
{
(void) action;
(void) user;
navigate(nfiles, -(size_t)1);
}
int
key_pressed(GtkWidget *widget, GdkEventKey *event, void *user)
{
GtkAdjustment *hadjustment, *vadjustment;
int left, right, up, down, amount;
double hamount, vamount;
(void) widget;
(void) user;
if (event->keyval == GDK_Escape) {
deactivate_fullscreen(NULL);
return 1;
}
if (event->state & GDK_CONTROL_MASK)
return 0;
if (gtk_window_get_focus(GTK_WINDOW(window)) != display_area)
return 0;
amount = (event->state & GDK_MOD1_MASK) ? 1 : SCROLL_AMOUNT;
hamount = (double)amount;
vamount = (double)amount;
if (event->state & GDK_SHIFT_MASK) {
hadjustment = logical_scroll_pane_get_hadjustment(LOGICAL_SCROLL_PANE(scroll));
vadjustment = logical_scroll_pane_get_vadjustment(LOGICAL_SCROLL_PANE(scroll));
hamount = 0.25 * hadjustment->page_size;
vamount = 0.25 * vadjustment->page_size;
}
left = event->keyval == GDK_Left;
right = event->keyval == GDK_Right;
up = event->keyval == GDK_Up;
down = event->keyval == GDK_Down;
if (left | right | up | down) {
scroll_by(right * hamount - left * hamount,
down * vamount - up * vamount);
return 1;
}
return 0;
}
int
scroll_event(GtkWidget *widget, GdkEventScroll *event, void *user)
{
GtkAdjustment *hadjustment = logical_scroll_pane_get_hadjustment(LOGICAL_SCROLL_PANE(scroll));
GtkAdjustment *vadjustment = logical_scroll_pane_get_vadjustment(LOGICAL_SCROLL_PANE(scroll));
double hamount = hadjustment->step_increment;
double vamount = vadjustment->step_increment;
int shift = !!(event->state & GDK_SHIFT_MASK);
int ctrl = !!(event->state & GDK_CONTROL_MASK);
int up = event->direction == GDK_SCROLL_UP;
int down = event->direction == GDK_SCROLL_DOWN;
int left = event->direction == GDK_SCROLL_LEFT;
int right = event->direction == GDK_SCROLL_RIGHT;
int x0, y0;
(void) widget;
(void) user;
if (shift) {
left = up, up = 0;
right = down, down = 0;
}
if (!ctrl) {
/* needed for shift+scroll to work */
scroll_by(right * hamount - left * hamount,
down * vamount - up * vamount);
} else if (up | down) {
gdk_window_get_origin(display_area->window, &x0, &y0);
clear_toggles(GROUP_ZOOM, NULL);
set_zoom_around_point(up ? zoom_in(zoom) : zoom_out(zoom), event->x_root - x0, event->y_root - y0);
} else {
return 0;
}
return 1;
}
|