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 "wdgt-print-copies.h"
26 #include "wdgt-mini-preview.h"
31 #define WDGT_MINI_PREVIEW_HEIGHT 175
32 #define WDGT_MINI_PREVIEW_WIDTH 150
34 /*===========================================*/
36 /*===========================================*/
38 static GObjectClass *parent_class;
40 /*===========================================*/
41 /* Local function prototypes */
42 /*===========================================*/
44 static void gl_wdgt_print_copies_class_init (glWdgtPrintCopiesClass * class);
45 static void gl_wdgt_print_copies_instance_init (glWdgtPrintCopies * copies);
46 static void gl_wdgt_print_copies_finalize (GObject * object);
48 static void gl_wdgt_print_copies_construct (glWdgtPrintCopies * copies,
51 static void sheets_radio_cb (GtkToggleButton * togglebutton,
53 static void first_spin_cb (GtkSpinButton * spinbutton,
55 static void last_spin_cb (GtkSpinButton * spinbutton,
59 preview_pressed (glWdgtMiniPreview *mini_preview,
60 gint first, gint last, gpointer user_data);
63 /****************************************************************************/
64 /* Boilerplate Object stuff. */
65 /****************************************************************************/
67 gl_wdgt_print_copies_get_type (void)
69 static guint wdgt_print_copies_type = 0;
71 if (!wdgt_print_copies_type) {
72 GTypeInfo wdgt_print_copies_info = {
73 sizeof (glWdgtPrintCopiesClass),
76 (GClassInitFunc) gl_wdgt_print_copies_class_init,
79 sizeof (glWdgtPrintCopies),
81 (GInstanceInitFunc) gl_wdgt_print_copies_instance_init,
84 wdgt_print_copies_type =
85 g_type_register_static (gl_hig_hbox_get_type (),
87 &wdgt_print_copies_info, 0);
90 return wdgt_print_copies_type;
94 gl_wdgt_print_copies_class_init (glWdgtPrintCopiesClass * class)
96 GObjectClass *object_class;
98 object_class = (GObjectClass *) class;
100 parent_class = g_type_class_peek_parent (class);
102 object_class->finalize = gl_wdgt_print_copies_finalize;
106 gl_wdgt_print_copies_instance_init (glWdgtPrintCopies * copies)
108 copies->labels_per_sheet = 0;
110 copies->mini_preview = NULL;
112 copies->sheets_radio = NULL;
113 copies->sheets_spin = NULL;
115 copies->labels_radio = NULL;
116 copies->first_spin = NULL;
117 copies->last_spin = NULL;
121 gl_wdgt_print_copies_finalize (GObject * object)
123 glWdgtPrintCopies *copies;
124 glWdgtPrintCopiesClass *class;
126 g_return_if_fail (object != NULL);
127 g_return_if_fail (GL_IS_WDGT_PRINT_COPIES (object));
129 copies = GL_WDGT_PRINT_COPIES (object);
131 G_OBJECT_CLASS (parent_class)->finalize (object);
135 gl_wdgt_print_copies_new (glLabel * label)
137 glWdgtPrintCopies *copies;
139 copies = g_object_new (gl_wdgt_print_copies_get_type (), NULL);
141 gl_wdgt_print_copies_construct (copies, label);
143 return GTK_WIDGET (copies);
146 /*--------------------------------------------------------------------------*/
147 /* Construct composite widget. */
148 /*--------------------------------------------------------------------------*/
150 gl_wdgt_print_copies_construct (glWdgtPrintCopies *copies,
153 GtkWidget *whbox, *wvbox, *whbox1;
154 GSList *radio_group = NULL;
156 const glTemplate *template;
158 whbox = GTK_WIDGET (copies);
160 template = gl_label_get_template (label);
161 copies->labels_per_sheet = gl_template_get_n_labels (template);
163 /* mini_preview canvas */
164 copies->mini_preview = gl_wdgt_mini_preview_new (WDGT_MINI_PREVIEW_HEIGHT,
165 WDGT_MINI_PREVIEW_WIDTH);
166 gl_wdgt_mini_preview_set_template (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
168 gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), copies->mini_preview);
170 wvbox = gl_hig_vbox_new (GL_HIG_VBOX_INNER);
171 gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), wvbox);
174 whbox1 = gl_hig_hbox_new ();
175 gl_hig_vbox_add_widget (GL_HIG_VBOX(wvbox), whbox1);
176 copies->sheets_radio =
177 gtk_radio_button_new_with_label (radio_group, _("Sheets:"));
178 gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox1), copies->sheets_radio);
179 adjust = gtk_adjustment_new (1, 1.0, 10.0, 1.0, 10.0, 10.0);
180 copies->sheets_spin = gtk_spin_button_new (GTK_ADJUSTMENT (adjust),
182 gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox1), copies->sheets_spin);
183 gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
184 1, copies->labels_per_sheet);
187 gl_hig_vbox_add_widget (GL_HIG_VBOX(wvbox), gtk_label_new (""));
190 whbox1 = gl_hig_hbox_new ();
191 gl_hig_vbox_add_widget (GL_HIG_VBOX(wvbox), whbox1);
193 gtk_radio_button_get_group (GTK_RADIO_BUTTON (copies->sheets_radio));
194 copies->labels_radio =
195 gtk_radio_button_new_with_label (radio_group, _("Labels"));
196 gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox1), copies->labels_radio);
197 gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox1),
198 gtk_label_new (_("from:")));
199 adjust = gtk_adjustment_new (1, 1.0, copies->labels_per_sheet,
201 copies->first_spin = gtk_spin_button_new (GTK_ADJUSTMENT (adjust),
203 gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox1), copies->first_spin);
204 gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox1),
205 gtk_label_new (_("to:")));
206 adjust = gtk_adjustment_new (copies->labels_per_sheet,
207 1.0, copies->labels_per_sheet,
209 copies->last_spin = gtk_spin_button_new (GTK_ADJUSTMENT (adjust),
211 gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox1), copies->last_spin);
212 gtk_widget_set_sensitive (copies->first_spin, FALSE);
213 gtk_widget_set_sensitive (copies->last_spin, FALSE);
215 /* Connect signals to controls */
216 g_signal_connect (G_OBJECT (copies->mini_preview), "pressed",
217 G_CALLBACK (preview_pressed), copies);
218 g_signal_connect (G_OBJECT (copies->sheets_radio), "toggled",
219 G_CALLBACK (sheets_radio_cb), copies);
220 g_signal_connect (G_OBJECT (copies->first_spin), "changed",
221 G_CALLBACK (first_spin_cb), copies);
222 g_signal_connect (G_OBJECT (copies->last_spin), "changed",
223 G_CALLBACK (last_spin_cb), copies);
226 /*--------------------------------------------------------------------------*/
227 /* PRIVATE. Enable/Disable appropriate controls due to radio button toggle.*/
228 /*--------------------------------------------------------------------------*/
230 sheets_radio_cb (GtkToggleButton * togglebutton,
233 glWdgtPrintCopies *copies = GL_WDGT_PRINT_COPIES (user_data);
236 if (gtk_toggle_button_get_active (togglebutton)) {
238 gtk_widget_set_sensitive (copies->sheets_spin, TRUE);
239 gtk_widget_set_sensitive (copies->first_spin, FALSE);
240 gtk_widget_set_sensitive (copies->last_spin, FALSE);
242 gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
243 1, copies->labels_per_sheet);
247 gtk_widget_set_sensitive (copies->sheets_spin, FALSE);
248 gtk_widget_set_sensitive (copies->first_spin, TRUE);
249 gtk_widget_set_sensitive (copies->last_spin, TRUE);
252 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
253 (copies->first_spin));
255 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
256 (copies->last_spin));
257 gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
263 /*--------------------------------------------------------------------------*/
264 /* PRIVATE. modify widget due to change of first spin button */
265 /*--------------------------------------------------------------------------*/
267 first_spin_cb (GtkSpinButton * spinbutton,
270 glWdgtPrintCopies *copies = GL_WDGT_PRINT_COPIES (user_data);
274 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
275 (copies->first_spin));
277 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
278 (copies->last_spin));
280 gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (copies->last_spin))->
283 gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
287 /*--------------------------------------------------------------------------*/
288 /* PRIVATE. modify widget due to change of last spin button */
289 /*--------------------------------------------------------------------------*/
291 last_spin_cb (GtkSpinButton * spinbutton,
294 glWdgtPrintCopies *copies = GL_WDGT_PRINT_COPIES (user_data);
298 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
299 (copies->first_spin));
301 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
302 (copies->last_spin));
304 gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (copies->first_spin))->
307 gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
311 /*--------------------------------------------------------------------------*/
312 /* PRIVATE. Canvas event handler, select first and last items. */
313 /*--------------------------------------------------------------------------*/
315 preview_pressed (glWdgtMiniPreview *mini_preview,
320 glWdgtPrintCopies *copies = GL_WDGT_PRINT_COPIES (user_data);
322 gl_wdgt_print_copies_set_range (copies, 1, first, last);
325 /****************************************************************************/
326 /* query selected range of labels within sheet or number of sheets. */
327 /****************************************************************************/
329 gl_wdgt_print_copies_get_range (glWdgtPrintCopies * copies,
334 gboolean sheets_active;
337 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
338 (copies->sheets_radio));
342 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
343 (copies->sheets_spin));
345 *last_label = copies->labels_per_sheet;
349 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
350 (copies->first_spin));
352 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
353 (copies->last_spin));
357 /****************************************************************************/
358 /* set range of labels within sheet or number of sheets */
359 /****************************************************************************/
361 gl_wdgt_print_copies_set_range (glWdgtPrintCopies * copies,
366 gint old_first_label;
369 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
370 (copies->first_spin));
372 if (first_label > old_first_label) {
373 gtk_spin_button_set_value (GTK_SPIN_BUTTON (copies->last_spin),
375 gtk_spin_button_set_value (GTK_SPIN_BUTTON (copies->first_spin),
378 gtk_spin_button_set_value (GTK_SPIN_BUTTON (copies->first_spin),
380 gtk_spin_button_set_value (GTK_SPIN_BUTTON (copies->last_spin),
383 if ((first_label == 1) && (last_label == copies->labels_per_sheet)) {
384 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
385 (copies->sheets_radio), TRUE);
386 gtk_spin_button_set_value (GTK_SPIN_BUTTON
387 (copies->sheets_spin), n_sheets);
389 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
390 (copies->labels_radio), TRUE);
391 gtk_spin_button_set_value (GTK_SPIN_BUTTON
392 (copies->sheets_spin), 1.0);