2 * (GLABELS) Label and Business Card Creation program for GNOME
4 * wdgt_print_copies.c: custom print copies widget module
6 * Copyright (C) 2001 Jim Evins <evins@snaught.com>.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <glib/gi18n.h>
27 #include "wdgt-print-copies.h"
28 #include "wdgt-mini-preview.h"
33 #define WDGT_MINI_PREVIEW_HEIGHT 175
34 #define WDGT_MINI_PREVIEW_WIDTH 150
36 /*===========================================*/
38 /*===========================================*/
40 static GObjectClass *parent_class;
42 /*===========================================*/
43 /* Local function prototypes */
44 /*===========================================*/
46 static void gl_wdgt_print_copies_class_init (glWdgtPrintCopiesClass * class);
47 static void gl_wdgt_print_copies_instance_init (glWdgtPrintCopies * copies);
48 static void gl_wdgt_print_copies_finalize (GObject * object);
50 static void gl_wdgt_print_copies_construct (glWdgtPrintCopies * copies,
53 static void sheets_radio_cb (GtkToggleButton * togglebutton,
55 static void first_spin_cb (GtkSpinButton * spinbutton,
57 static void last_spin_cb (GtkSpinButton * spinbutton,
61 preview_pressed (glWdgtMiniPreview *mini_preview,
62 gint first, gint last, gpointer user_data);
65 /****************************************************************************/
66 /* Boilerplate Object stuff. */
67 /****************************************************************************/
69 gl_wdgt_print_copies_get_type (void)
71 static GType type = 0;
74 static const GTypeInfo info = {
75 sizeof (glWdgtPrintCopiesClass),
78 (GClassInitFunc) gl_wdgt_print_copies_class_init,
81 sizeof (glWdgtPrintCopies),
83 (GInstanceInitFunc) gl_wdgt_print_copies_instance_init,
87 type = g_type_register_static (GL_TYPE_HIG_HBOX,
88 "glWdgtPrintCopies", &info, 0);
95 gl_wdgt_print_copies_class_init (glWdgtPrintCopiesClass * class)
97 GObjectClass *object_class;
99 object_class = (GObjectClass *) class;
101 parent_class = g_type_class_peek_parent (class);
103 object_class->finalize = gl_wdgt_print_copies_finalize;
107 gl_wdgt_print_copies_instance_init (glWdgtPrintCopies * copies)
109 copies->labels_per_sheet = 0;
111 copies->mini_preview = NULL;
113 copies->sheets_radio = NULL;
114 copies->sheets_spin = NULL;
116 copies->labels_radio = NULL;
117 copies->first_spin = NULL;
118 copies->last_spin = NULL;
122 gl_wdgt_print_copies_finalize (GObject * object)
124 glWdgtPrintCopies *copies;
125 glWdgtPrintCopiesClass *class;
127 g_return_if_fail (object != NULL);
128 g_return_if_fail (GL_IS_WDGT_PRINT_COPIES (object));
130 copies = GL_WDGT_PRINT_COPIES (object);
132 G_OBJECT_CLASS (parent_class)->finalize (object);
136 gl_wdgt_print_copies_new (glLabel * label)
138 glWdgtPrintCopies *copies;
140 copies = g_object_new (gl_wdgt_print_copies_get_type (), NULL);
142 gl_wdgt_print_copies_construct (copies, label);
144 return GTK_WIDGET (copies);
147 /*--------------------------------------------------------------------------*/
148 /* Construct composite widget. */
149 /*--------------------------------------------------------------------------*/
151 gl_wdgt_print_copies_construct (glWdgtPrintCopies *copies,
154 glTemplate *template;
155 const glTemplateLabelType *label_type;
156 GtkWidget *whbox, *wvbox, *whbox1;
157 GSList *radio_group = NULL;
160 whbox = GTK_WIDGET (copies);
162 template = gl_label_get_template (label);
163 label_type = gl_template_get_first_label_type (template);
165 copies->labels_per_sheet = gl_template_get_n_labels (label_type);
167 /* mini_preview canvas */
168 copies->mini_preview = gl_wdgt_mini_preview_new (WDGT_MINI_PREVIEW_HEIGHT,
169 WDGT_MINI_PREVIEW_WIDTH);
170 gl_wdgt_mini_preview_set_template (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
172 gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), copies->mini_preview);
174 wvbox = gl_hig_vbox_new (GL_HIG_VBOX_INNER);
175 gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), wvbox);
178 whbox1 = gl_hig_hbox_new ();
179 gl_hig_vbox_add_widget (GL_HIG_VBOX(wvbox), whbox1);
180 copies->sheets_radio =
181 gtk_radio_button_new_with_label (radio_group, _("Sheets:"));
182 gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox1), copies->sheets_radio);
183 adjust = gtk_adjustment_new (1, 1.0, 10.0, 1.0, 10.0, 10.0);
184 copies->sheets_spin = gtk_spin_button_new (GTK_ADJUSTMENT (adjust),
186 gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox1), copies->sheets_spin);
187 gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
188 1, copies->labels_per_sheet);
191 gl_hig_vbox_add_widget (GL_HIG_VBOX(wvbox), gtk_label_new (""));
194 whbox1 = gl_hig_hbox_new ();
195 gl_hig_vbox_add_widget (GL_HIG_VBOX(wvbox), whbox1);
197 gtk_radio_button_get_group (GTK_RADIO_BUTTON (copies->sheets_radio));
198 copies->labels_radio =
199 gtk_radio_button_new_with_label (radio_group, _("Labels"));
200 gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox1), copies->labels_radio);
201 gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox1),
202 gtk_label_new (_("from:")));
203 adjust = gtk_adjustment_new (1, 1.0, copies->labels_per_sheet,
205 copies->first_spin = gtk_spin_button_new (GTK_ADJUSTMENT (adjust),
207 gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox1), copies->first_spin);
208 gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox1),
209 gtk_label_new (_("to:")));
210 adjust = gtk_adjustment_new (copies->labels_per_sheet,
211 1.0, copies->labels_per_sheet,
213 copies->last_spin = gtk_spin_button_new (GTK_ADJUSTMENT (adjust),
215 gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox1), copies->last_spin);
216 gtk_widget_set_sensitive (copies->first_spin, FALSE);
217 gtk_widget_set_sensitive (copies->last_spin, FALSE);
219 /* Connect signals to controls */
220 g_signal_connect (G_OBJECT (copies->mini_preview), "pressed",
221 G_CALLBACK (preview_pressed), copies);
222 g_signal_connect (G_OBJECT (copies->sheets_radio), "toggled",
223 G_CALLBACK (sheets_radio_cb), copies);
224 g_signal_connect (G_OBJECT (copies->first_spin), "changed",
225 G_CALLBACK (first_spin_cb), copies);
226 g_signal_connect (G_OBJECT (copies->last_spin), "changed",
227 G_CALLBACK (last_spin_cb), copies);
229 gl_template_free (template);
232 /*--------------------------------------------------------------------------*/
233 /* PRIVATE. Enable/Disable appropriate controls due to radio button toggle.*/
234 /*--------------------------------------------------------------------------*/
236 sheets_radio_cb (GtkToggleButton * togglebutton,
239 glWdgtPrintCopies *copies = GL_WDGT_PRINT_COPIES (user_data);
242 if (gtk_toggle_button_get_active (togglebutton)) {
244 gtk_widget_set_sensitive (copies->sheets_spin, TRUE);
245 gtk_widget_set_sensitive (copies->first_spin, FALSE);
246 gtk_widget_set_sensitive (copies->last_spin, FALSE);
248 gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
249 1, copies->labels_per_sheet);
253 gtk_widget_set_sensitive (copies->sheets_spin, FALSE);
254 gtk_widget_set_sensitive (copies->first_spin, TRUE);
255 gtk_widget_set_sensitive (copies->last_spin, TRUE);
258 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
259 (copies->first_spin));
261 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
262 (copies->last_spin));
263 gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
269 /*--------------------------------------------------------------------------*/
270 /* PRIVATE. modify widget due to change of first spin button */
271 /*--------------------------------------------------------------------------*/
273 first_spin_cb (GtkSpinButton * spinbutton,
276 glWdgtPrintCopies *copies = GL_WDGT_PRINT_COPIES (user_data);
280 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
281 (copies->first_spin));
283 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
284 (copies->last_spin));
286 gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (copies->last_spin))->
289 gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
293 /*--------------------------------------------------------------------------*/
294 /* PRIVATE. modify widget due to change of last spin button */
295 /*--------------------------------------------------------------------------*/
297 last_spin_cb (GtkSpinButton * spinbutton,
300 glWdgtPrintCopies *copies = GL_WDGT_PRINT_COPIES (user_data);
304 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
305 (copies->first_spin));
307 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
308 (copies->last_spin));
310 gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (copies->first_spin))->
313 gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
317 /*--------------------------------------------------------------------------*/
318 /* PRIVATE. Canvas event handler, select first and last items. */
319 /*--------------------------------------------------------------------------*/
321 preview_pressed (glWdgtMiniPreview *mini_preview,
326 glWdgtPrintCopies *copies = GL_WDGT_PRINT_COPIES (user_data);
328 gl_wdgt_print_copies_set_range (copies, 1, first, last);
331 /****************************************************************************/
332 /* query selected range of labels within sheet or number of sheets. */
333 /****************************************************************************/
335 gl_wdgt_print_copies_get_range (glWdgtPrintCopies * copies,
340 gboolean sheets_active;
343 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
344 (copies->sheets_radio));
348 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
349 (copies->sheets_spin));
351 *last_label = copies->labels_per_sheet;
355 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
356 (copies->first_spin));
358 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
359 (copies->last_spin));
363 /****************************************************************************/
364 /* set range of labels within sheet or number of sheets */
365 /****************************************************************************/
367 gl_wdgt_print_copies_set_range (glWdgtPrintCopies * copies,
372 gint old_first_label;
375 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
376 (copies->first_spin));
378 if (first_label > old_first_label) {
379 gtk_spin_button_set_value (GTK_SPIN_BUTTON (copies->last_spin),
381 gtk_spin_button_set_value (GTK_SPIN_BUTTON (copies->first_spin),
384 gtk_spin_button_set_value (GTK_SPIN_BUTTON (copies->first_spin),
386 gtk_spin_button_set_value (GTK_SPIN_BUTTON (copies->last_spin),
389 if ((first_label == 1) && (last_label == copies->labels_per_sheet)) {
390 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
391 (copies->sheets_radio), TRUE);
392 gtk_spin_button_set_value (GTK_SPIN_BUTTON
393 (copies->sheets_spin), n_sheets);
395 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
396 (copies->labels_radio), TRUE);
397 gtk_spin_button_set_value (GTK_SPIN_BUTTON
398 (copies->sheets_spin), 1.0);