]> git.karo-electronics.de Git - gbdfed.git/blob - guiops.c
Fixup several compile faults due to changes in recent distributions,
[gbdfed.git] / guiops.c
1 /*
2  * Copyright 2008 Department of Mathematical Sciences, New Mexico State University
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * DEPARTMENT OF MATHEMATICAL SCIENCES OR NEW MEXICO STATE UNIVERSITY BE
18  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22
23 #include "gbdfed.h"
24
25 static GtkWidget *ops_dialog;
26 static GtkWidget *ops_notebook;
27 static GtkWidget *ops_dx;
28 static GtkWidget *ops_dy;
29 static GtkWidget *ops_rotate;
30 static GtkWidget *ops_shear;
31 static GtkWidget *ops_degrees;
32 static GtkWidget *ops_all_glyphs;
33 static GtkWidget *ops_selected_glyphs;
34 static GtkWidget *ops_apply;
35 static gboolean translate_changed;
36 static gboolean degrees_changed;
37 static gboolean embolden_changed;
38 static gint page;
39
40 static void
41 apply_operation(GtkWidget *w, gint response, gpointer data)
42 {
43     gbdfed_editor_t *ed;
44     gint16 dx, dy;
45     gboolean all;
46
47     /*
48      * Turn off the Apply button for this page.
49      */
50     gtk_widget_set_sensitive(ops_apply, FALSE);
51
52     if (response == GTK_RESPONSE_CLOSE) {
53         gtk_widget_hide(ops_dialog);
54         gtk_widget_set_sensitive(ops_apply, FALSE);
55         translate_changed = degrees_changed = embolden_changed = FALSE;
56         return;
57     }
58
59     ed = editors +
60         GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(w), "editor"));
61
62     all = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ops_all_glyphs));
63
64     if (translate_changed) {
65         /*
66          * Do a glyph translate.
67          */
68         dx = _bdf_atos((char *) gtk_entry_get_text(GTK_ENTRY(ops_dx)), 0, 10);
69         dy = _bdf_atos((char *) gtk_entry_get_text(GTK_ENTRY(ops_dy)), 0, 10);
70         fontgrid_translate_glyphs(FONTGRID(ed->fgrid), dx, dy, all);
71         translate_changed = FALSE;
72     }
73
74     if (degrees_changed) {
75         /*
76          * Do either a rotate or a shear.
77          */
78         dx = _bdf_atos((char *) gtk_entry_get_text(GTK_ENTRY(ops_degrees)),
79                        0, 10);
80         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ops_rotate)))
81           fontgrid_rotate_glyphs(FONTGRID(ed->fgrid), dx, all);
82         else
83           fontgrid_shear_glyphs(FONTGRID(ed->fgrid), dx, all);
84         degrees_changed = FALSE;
85     }
86
87     if (embolden_changed) {
88         /*
89          * Embolden some glyphs.
90          */
91         fontgrid_embolden_glyphs(FONTGRID(ed->fgrid), all);
92         embolden_changed = FALSE;
93     }
94 }
95
96 static void
97 notebook_switch_page(GtkNotebook *nb, GtkNotebookPage *nbp, gint pageno,
98                      gpointer data)
99 {
100     GtkWidget *which = 0;
101
102     /*
103      * Force the focus on the entry fields when these pages become visible.
104      */
105     switch (pageno) {
106       case 0:
107         if (ops_apply != 0)
108           gtk_widget_set_sensitive(ops_apply, translate_changed);
109         which = ops_dx;
110         break;
111       case 1:
112         if (ops_apply != 0)
113           gtk_widget_set_sensitive(ops_apply, degrees_changed);
114         which = ops_degrees;
115         break;
116       case 2:
117         if (ops_apply != 0)
118           gtk_widget_set_sensitive(ops_apply, embolden_changed);
119         which = 0;
120     }
121     page = pageno;
122
123     if (which)
124       gtk_widget_grab_focus(which);
125 }
126
127 static void
128 enable_apply(GtkWidget *w, gpointer data)
129 {
130     gint which = GPOINTER_TO_INT(data);
131     gboolean val = TRUE;
132
133     if (which == 0)
134       translate_changed = TRUE;
135     else if (which == 1)
136       degrees_changed = TRUE;
137     else {
138         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)))
139           embolden_changed = TRUE;
140         else
141           embolden_changed = FALSE;
142         val = embolden_changed;
143     }
144
145     gtk_widget_set_sensitive(ops_apply, val);
146 }
147
148 static void
149 ops_dialog_setup(gbdfed_editor_t *ed)
150 {
151     GtkWidget *vbox, *hbox, *vbox1, *label, *table, *button;
152     GtkRadioButton *rb;
153     GtkAdjustment *adj;
154
155     if (ops_dialog == 0) {
156         translate_changed = degrees_changed = FALSE;
157
158         ops_dialog = gtk_dialog_new();
159         (void) g_signal_connect(G_OBJECT(ops_dialog), "delete_event",
160                                 G_CALLBACK(gtk_widget_hide), 0);
161
162         vbox = gtk_vbox_new(FALSE, 0);
163
164         ops_notebook = gtk_notebook_new();
165         (void) g_signal_connect(G_OBJECT(ops_notebook), "switch_page",
166                                 G_CALLBACK(notebook_switch_page), 0);
167
168         /*
169          * Create the notebook pages.
170          */
171         table = gtk_table_new(2, 2, FALSE);
172
173         label = gtk_label_new("DX:");
174         gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
175         gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL,
176                          GTK_FILL, 0, 0);
177
178         label = gtk_label_new("DY:");
179         gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
180         gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_FILL,
181                          GTK_FILL, 0, 0);
182
183         ops_dx = gtk_widget_new(gtk_entry_get_type(),
184                                 "max_length", 6, NULL);
185         (void) g_signal_connect(G_OBJECT(ops_dx), "changed",
186                                 G_CALLBACK(enable_apply),
187                                 GINT_TO_POINTER(0));
188         gtk_table_attach(GTK_TABLE(table), ops_dx, 1, 2, 0, 1, GTK_FILL,
189                          GTK_FILL, 5, 5);
190         ops_dy = gtk_widget_new(gtk_entry_get_type(),
191                                 "max_length", 6, NULL);
192         (void) g_signal_connect(G_OBJECT(ops_dx), "changed",
193                                 G_CALLBACK(enable_apply),
194                                 GINT_TO_POINTER(0));
195         gtk_table_attach(GTK_TABLE(table), ops_dy, 1, 2, 1, 2, GTK_FILL,
196                          GTK_FILL, 5, 5);
197
198         label = gtk_label_new("Translate Glyphs");
199         gtk_notebook_append_page(GTK_NOTEBOOK(ops_notebook), table, label);
200
201         vbox1 = gtk_vbox_new(FALSE, 0);
202
203         hbox = gtk_hbox_new(FALSE, 0);
204
205         ops_rotate = gtk_radio_button_new_with_label(0, "Rotate");
206         gtk_box_pack_start(GTK_BOX(hbox), ops_rotate, FALSE, FALSE, 2);
207         rb = GTK_RADIO_BUTTON(ops_rotate);
208         ops_shear = gtk_radio_button_new_with_label_from_widget(rb, "Shear");
209         gtk_box_pack_start(GTK_BOX(hbox), ops_shear, FALSE, FALSE, 2);
210
211         gtk_box_pack_start(GTK_BOX(vbox1), hbox, FALSE, FALSE, 0);
212
213         hbox = gtk_hbox_new(FALSE, 0);
214         label = gtk_label_new("Degrees:");
215         adj = (GtkAdjustment *) gtk_adjustment_new(0.0, -359.0, 359.0, 1.0,
216                                                    10.0, 0.0);
217         ops_degrees = gtk_widget_new(gtk_spin_button_get_type(),
218                                      "max_length", 6,
219                                      "adjustment", adj,
220                                      "climb_rate", 1.0,
221                                      "digits", 0,
222                                      "value", 0.0,
223                                      "numeric", TRUE,
224                                      NULL);
225         gtk_widget_set_size_request(ops_degrees, 60, -1);
226         (void) g_signal_connect(G_OBJECT(ops_degrees), "changed",
227                                 G_CALLBACK(enable_apply),
228                                 GINT_TO_POINTER(1));
229         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
230         gtk_box_pack_start(GTK_BOX(hbox), ops_degrees, FALSE, FALSE, 0);
231
232         gtk_box_pack_start(GTK_BOX(vbox1), hbox, FALSE, FALSE, 3);
233
234         label = gtk_label_new("Rotate/Shear Glyphs");
235         gtk_notebook_append_page(GTK_NOTEBOOK(ops_notebook), vbox1, label);
236
237         /*
238          * Add the embolden check button.
239          */
240         button = gtk_check_button_new_with_label("Embolden");
241         (void) g_signal_connect(G_OBJECT(button), "toggled",
242                                 G_CALLBACK(enable_apply),
243                                 GINT_TO_POINTER(2));
244         label = gtk_label_new("Embolden Glyphs");
245         gtk_notebook_append_page(GTK_NOTEBOOK(ops_notebook), button,
246                                  label);
247
248         /*
249          * Add the notebook to the containing vbox.
250          */
251         gtk_box_pack_start(GTK_BOX(vbox), ops_notebook, FALSE, FALSE, 0);
252
253         /*
254          * Add the radio buttons for choosing between all the glyphs or
255          * just the selected glyphs.
256          */
257         hbox = gtk_hbox_new(FALSE, 0);
258         ops_all_glyphs = gtk_radio_button_new_with_label(0, "All Glyphs");
259         rb = GTK_RADIO_BUTTON(ops_all_glyphs);
260         ops_selected_glyphs =
261             gtk_radio_button_new_with_label_from_widget(rb, "Selected Glyphs");
262         /*
263          * Default to the selected glyphs.
264          */
265         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ops_selected_glyphs),
266                                      TRUE);
267         gtk_box_pack_start(GTK_BOX(hbox), ops_all_glyphs, FALSE, FALSE, 2);
268         gtk_box_pack_start(GTK_BOX(hbox), ops_selected_glyphs,
269                            FALSE, FALSE, 2);
270
271         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 2);
272
273         /*
274          * Add the vbox to the dialog.
275          */
276         gtk_container_add(GTK_CONTAINER(GTK_DIALOG(ops_dialog)->vbox), vbox);
277
278         ops_apply = gtk_dialog_add_button(GTK_DIALOG(ops_dialog),
279                                           GTK_STOCK_APPLY,
280                                           GTK_RESPONSE_APPLY);
281         gtk_widget_set_sensitive(ops_apply, FALSE);
282
283         button = gtk_dialog_add_button(GTK_DIALOG(ops_dialog),
284                                        GTK_STOCK_CLOSE,
285                                        GTK_RESPONSE_CLOSE);
286
287         g_signal_connect(G_OBJECT(ops_dialog), "response",
288                          G_CALLBACK(apply_operation), 0);
289
290         gtk_widget_show_all(GTK_DIALOG(ops_dialog)->vbox);
291     }
292
293     if (fontgrid_has_selection(FONTGRID(ed->fgrid), 0))
294       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ops_selected_glyphs),
295                                    TRUE);
296     else
297       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ops_all_glyphs), TRUE);
298
299     /*
300      * Set the title of the dialog.
301      */
302     if (ed->file == 0)
303       sprintf(buffer1, "(unnamed%d): Glyph Operations", ed->id);
304     else
305       sprintf(buffer1, "%s: Glyph Operations", ed->file);
306
307     gtk_window_set_title(GTK_WINDOW(ops_dialog), buffer1);
308 }
309
310 void
311 guiops_show_translate(GtkWidget *w, gpointer data)
312 {
313     gbdfed_editor_t *ed = editors + GPOINTER_TO_UINT(data);
314
315     ops_dialog_setup(ed);
316
317     /*
318      * Set the object data to be the editor.
319      */
320     g_object_set_data(G_OBJECT(ops_dialog), "editor", data);
321
322     /*
323      * Show the translate page.
324      */
325     gtk_notebook_set_current_page(GTK_NOTEBOOK(ops_notebook), 0);
326
327     /*
328      * Show the dialog.
329      */
330     guiutil_show_dialog_centered(ops_dialog, ed->shell);
331
332     gtk_window_set_modal(GTK_WINDOW(ops_dialog), TRUE);
333 }
334
335 void
336 guiops_show_rotate(GtkWidget *w, gpointer data)
337 {
338     gbdfed_editor_t *ed = editors + GPOINTER_TO_UINT(data);
339
340     ops_dialog_setup(ed);
341
342     /*
343      * Set the object data to be the editor.
344      */
345     g_object_set_data(G_OBJECT(ops_dialog), "editor", data);
346
347     /*
348      * Show the rotate page.
349      */
350     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ops_rotate), TRUE);
351
352     /*
353      * Show the dialog.
354      */
355     guiutil_show_dialog_centered(ops_dialog, ed->shell);
356
357     gtk_notebook_set_current_page(GTK_NOTEBOOK(ops_notebook), 1);
358
359     gtk_window_set_modal(GTK_WINDOW(ops_dialog), TRUE);
360 }
361
362 void
363 guiops_show_shear(GtkWidget *w, gpointer data)
364 {
365     gbdfed_editor_t *ed = editors + GPOINTER_TO_UINT(data);
366
367     ops_dialog_setup(ed);
368
369     /*
370      * Set the object data to be the editor.
371      */
372     g_object_set_data(G_OBJECT(ops_dialog), "editor", data);
373
374     /*
375      * Show the shear page.
376      */
377     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ops_shear), TRUE);
378
379     /*
380      * Show the dialog.
381      */
382     guiutil_show_dialog_centered(ops_dialog, ed->shell);
383
384     gtk_notebook_set_current_page(GTK_NOTEBOOK(ops_notebook), 1);
385
386     gtk_window_set_modal(GTK_WINDOW(ops_dialog), TRUE);
387 }
388
389 void
390 guiops_show_embolden(GtkWidget *w, gpointer data)
391 {
392     gbdfed_editor_t *ed = editors + GPOINTER_TO_UINT(data);
393
394     ops_dialog_setup(ed);
395
396     /*
397      * Set the object data to be the editor.
398      */
399     g_object_set_data(G_OBJECT(ops_dialog), "editor", data);
400
401     /*
402      * Show the dialog.
403      */
404     guiutil_show_dialog_centered(ops_dialog, ed->shell);
405
406     gtk_notebook_set_current_page(GTK_NOTEBOOK(ops_notebook), 2);
407
408     gtk_window_set_modal(GTK_WINDOW(ops_dialog), TRUE);
409 }