2 * (GLABELS) Label and Business Card Creation program for GNOME
4 * 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 "print_copies.h"
26 #include "mini_preview.h"
30 #define MINI_PREVIEW_HEIGHT 175
31 #define MINI_PREVIEW_WIDTH 150
33 /*===========================================*/
35 /*===========================================*/
37 static GtkContainerClass *parent_class;
39 /*===========================================*/
40 /* Local function prototypes */
41 /*===========================================*/
43 static void gl_print_copies_class_init (glPrintCopiesClass * class);
44 static void gl_print_copies_init (glPrintCopies * copies);
45 static void gl_print_copies_destroy (GtkObject * object);
47 static void gl_print_copies_construct (glPrintCopies * copies, glLabel * label);
49 static void sheets_radio_cb (GtkToggleButton * togglebutton, gpointer user_data);
50 static void first_spin_cb (GtkSpinButton * spinbutton, gpointer user_data);
51 static void last_spin_cb (GtkSpinButton * spinbutton, gpointer user_data);
54 preview_pressed (glMiniPreview *mini_preview,
55 gint first, gint last, gpointer user_data);
58 /****************************************************************************/
59 /* Boilerplate Object stuff. */
60 /****************************************************************************/
62 gl_print_copies_get_type (void)
64 static guint print_copies_type = 0;
66 if (!print_copies_type) {
67 GtkTypeInfo print_copies_info = {
69 sizeof (glPrintCopies),
70 sizeof (glPrintCopiesClass),
71 (GtkClassInitFunc) gl_print_copies_class_init,
72 (GtkObjectInitFunc) gl_print_copies_init,
77 print_copies_type = gtk_type_unique (gtk_hbox_get_type (),
81 return print_copies_type;
85 gl_print_copies_class_init (glPrintCopiesClass * class)
87 GtkObjectClass *object_class;
88 GtkWidgetClass *widget_class;
90 object_class = (GtkObjectClass *) class;
91 widget_class = (GtkWidgetClass *) class;
93 parent_class = gtk_type_class (gtk_hbox_get_type ());
95 object_class->destroy = gl_print_copies_destroy;
99 gl_print_copies_init (glPrintCopies * copies)
101 copies->labels_per_sheet = 0;
103 copies->mini_preview = NULL;
105 copies->sheets_radio = NULL;
106 copies->sheets_spin = NULL;
108 copies->labels_radio = NULL;
109 copies->first_spin = NULL;
110 copies->last_spin = NULL;
114 gl_print_copies_destroy (GtkObject * object)
116 glPrintCopies *copies;
117 glPrintCopiesClass *class;
119 g_return_if_fail (object != NULL);
120 g_return_if_fail (GL_IS_PRINT_COPIES (object));
122 copies = GL_PRINT_COPIES (object);
123 class = GL_PRINT_COPIES_CLASS (GTK_OBJECT (copies)->klass);
125 GTK_OBJECT_CLASS (parent_class)->destroy (object);
129 gl_print_copies_new (glLabel * label)
131 glPrintCopies *copies;
133 copies = gtk_type_new (gl_print_copies_get_type ());
135 gl_print_copies_construct (copies, label);
137 return GTK_WIDGET (copies);
140 /*--------------------------------------------------------------------------*/
141 /* Construct composite widget. */
142 /*--------------------------------------------------------------------------*/
144 gl_print_copies_construct (glPrintCopies * copies,
147 GtkWidget *whbox, *wvbox, *whbox1;
148 GSList *radio_group = NULL;
151 whbox = GTK_WIDGET (copies);
153 copies->labels_per_sheet = label->template->nx * label->template->ny;
155 /* mini_preview canvas */
156 copies->mini_preview = gl_mini_preview_new (MINI_PREVIEW_HEIGHT,
158 gl_mini_preview_set_label (GL_MINI_PREVIEW(copies->mini_preview),
159 label->template->name->data);
160 gtk_box_pack_start (GTK_BOX (whbox), copies->mini_preview,
161 TRUE, TRUE, GNOME_PAD);
163 wvbox = gtk_vbox_new (FALSE, GNOME_PAD);
164 gtk_box_pack_start (GTK_BOX (whbox), wvbox, TRUE, TRUE, GNOME_PAD);
167 whbox1 = gtk_hbox_new (FALSE, GNOME_PAD);
168 gtk_box_pack_start (GTK_BOX (wvbox), whbox1, FALSE, FALSE, GNOME_PAD);
169 copies->sheets_radio =
170 gtk_radio_button_new_with_label (radio_group, _("Sheets:"));
171 gtk_box_pack_start (GTK_BOX (whbox1), copies->sheets_radio,
173 adjust = gtk_adjustment_new (1, 1.0, 10.0, 1.0, 10.0, 10.0);
174 copies->sheets_spin = gtk_spin_button_new (GTK_ADJUSTMENT (adjust),
176 gtk_box_pack_start (GTK_BOX (whbox1), copies->sheets_spin,
178 gl_mini_preview_highlight_range (GL_MINI_PREVIEW(copies->mini_preview),
179 1, copies->labels_per_sheet);
182 whbox1 = gtk_hbox_new (FALSE, GNOME_PAD);
183 gtk_box_pack_start (GTK_BOX (wvbox), whbox1, FALSE, FALSE, GNOME_PAD);
185 gtk_radio_button_group (GTK_RADIO_BUTTON (copies->sheets_radio));
186 copies->labels_radio =
187 gtk_radio_button_new_with_label (radio_group, _("Labels"));
188 gtk_box_pack_start (GTK_BOX (whbox1), copies->labels_radio,
190 gtk_box_pack_start (GTK_BOX (whbox1), gtk_label_new (_("from:")),
192 adjust = gtk_adjustment_new (1, 1.0, copies->labels_per_sheet,
194 copies->first_spin = gtk_spin_button_new (GTK_ADJUSTMENT (adjust),
196 gtk_box_pack_start (GTK_BOX (whbox1), copies->first_spin,
198 gtk_box_pack_start (GTK_BOX (whbox1), gtk_label_new (_("to:")),
200 adjust = gtk_adjustment_new (copies->labels_per_sheet,
201 1.0, copies->labels_per_sheet,
203 copies->last_spin = gtk_spin_button_new (GTK_ADJUSTMENT (adjust),
205 gtk_box_pack_start (GTK_BOX (whbox1), copies->last_spin,
207 gtk_widget_set_sensitive (copies->first_spin, FALSE);
208 gtk_widget_set_sensitive (copies->last_spin, FALSE);
210 /* Connect signals to controls */
211 gtk_signal_connect (GTK_OBJECT (copies->mini_preview), "pressed",
212 GTK_SIGNAL_FUNC (preview_pressed), copies);
213 gtk_signal_connect (GTK_OBJECT (copies->sheets_radio), "toggled",
214 GTK_SIGNAL_FUNC (sheets_radio_cb), copies);
215 gtk_signal_connect (GTK_OBJECT (copies->first_spin), "changed",
216 GTK_SIGNAL_FUNC (first_spin_cb), copies);
217 gtk_signal_connect (GTK_OBJECT (copies->last_spin), "changed",
218 GTK_SIGNAL_FUNC (last_spin_cb), copies);
221 /*--------------------------------------------------------------------------*/
222 /* PRIVATE. Enable/Disable appropriate controls due to radio button toggle.*/
223 /*--------------------------------------------------------------------------*/
225 sheets_radio_cb (GtkToggleButton * togglebutton,
228 glPrintCopies *copies = GL_PRINT_COPIES (user_data);
231 if (gtk_toggle_button_get_active (togglebutton)) {
233 gtk_widget_set_sensitive (copies->sheets_spin, TRUE);
234 gtk_widget_set_sensitive (copies->first_spin, FALSE);
235 gtk_widget_set_sensitive (copies->last_spin, FALSE);
237 gl_mini_preview_highlight_range (GL_MINI_PREVIEW(copies->mini_preview),
238 1, copies->labels_per_sheet);
242 gtk_widget_set_sensitive (copies->sheets_spin, FALSE);
243 gtk_widget_set_sensitive (copies->first_spin, TRUE);
244 gtk_widget_set_sensitive (copies->last_spin, TRUE);
247 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
248 (copies->first_spin));
250 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
251 (copies->last_spin));
252 gl_mini_preview_highlight_range (GL_MINI_PREVIEW(copies->mini_preview),
258 /*--------------------------------------------------------------------------*/
259 /* PRIVATE. modify widget due to change of first spin button */
260 /*--------------------------------------------------------------------------*/
262 first_spin_cb (GtkSpinButton * spinbutton,
265 glPrintCopies *copies = GL_PRINT_COPIES (user_data);
269 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
270 (copies->first_spin));
272 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
273 (copies->last_spin));
275 gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (copies->last_spin))->
278 gl_mini_preview_highlight_range (GL_MINI_PREVIEW(copies->mini_preview),
282 /*--------------------------------------------------------------------------*/
283 /* PRIVATE. modify widget due to change of last spin button */
284 /*--------------------------------------------------------------------------*/
286 last_spin_cb (GtkSpinButton * spinbutton,
289 glPrintCopies *copies = GL_PRINT_COPIES (user_data);
293 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
294 (copies->first_spin));
296 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
297 (copies->last_spin));
299 gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (copies->first_spin))->
302 gl_mini_preview_highlight_range (GL_MINI_PREVIEW(copies->mini_preview),
306 /*--------------------------------------------------------------------------*/
307 /* PRIVATE. Canvas event handler, select first and last items. */
308 /*--------------------------------------------------------------------------*/
310 preview_pressed (glMiniPreview *mini_preview,
311 gint first, gint last, gpointer user_data)
313 glPrintCopies *copies = GL_PRINT_COPIES (user_data);
315 gl_print_copies_set_range (copies, 1, first, last);
318 /****************************************************************************/
319 /* query selected range of labels within sheet or number of sheets. */
320 /****************************************************************************/
322 gl_print_copies_get_range (glPrintCopies * copies,
327 gboolean sheets_active;
330 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
331 (copies->sheets_radio));
335 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
336 (copies->sheets_spin));
338 *last_label = copies->labels_per_sheet;
342 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
343 (copies->first_spin));
345 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
346 (copies->last_spin));
350 /****************************************************************************/
351 /* set range of labels within sheet or number of sheets */
352 /****************************************************************************/
354 gl_print_copies_set_range (glPrintCopies * copies,
359 gint old_first_label;
362 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
363 (copies->first_spin));
365 if (first_label > old_first_label) {
366 gtk_spin_button_set_value (GTK_SPIN_BUTTON (copies->last_spin),
368 gtk_spin_button_set_value (GTK_SPIN_BUTTON (copies->first_spin),
371 gtk_spin_button_set_value (GTK_SPIN_BUTTON (copies->first_spin),
373 gtk_spin_button_set_value (GTK_SPIN_BUTTON (copies->last_spin),
376 if ((first_label == 1) && (last_label == copies->labels_per_sheet)) {
377 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
378 (copies->sheets_radio), TRUE);
379 gtk_spin_button_set_value (GTK_SPIN_BUTTON
380 (copies->sheets_spin), n_sheets);
382 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
383 (copies->labels_radio), TRUE);
384 gtk_spin_button_set_value (GTK_SPIN_BUTTON
385 (copies->sheets_spin), 1.0);