1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
4 * (GLABELS) Label and Business Card Creation program for GNOME
6 * wdgt_print_copies.c: custom print copies widget module
8 * Copyright (C) 2001 Jim Evins <evins@snaught.com>.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wdgt-print-copies.h"
29 #include <glib/gi18n.h>
30 #include <gtk/gtktogglebutton.h>
31 #include <gtk/gtkspinbutton.h>
32 #include <gtk/gtkradiobutton.h>
33 #include <gtk/gtklabel.h>
34 #include <gtk/gtkvbox.h>
37 #include "wdgt-mini-preview.h"
42 #define WDGT_MINI_PREVIEW_HEIGHT 175
43 #define WDGT_MINI_PREVIEW_WIDTH 150
45 /*===========================================*/
47 /*===========================================*/
49 /*===========================================*/
50 /* Local function prototypes */
51 /*===========================================*/
53 static void gl_wdgt_print_copies_finalize (GObject * object);
55 static void gl_wdgt_print_copies_construct (glWdgtPrintCopies * copies,
58 static void sheets_radio_cb (GtkToggleButton * togglebutton,
60 static void first_spin_cb (GtkSpinButton * spinbutton,
62 static void last_spin_cb (GtkSpinButton * spinbutton,
66 preview_pressed (glWdgtMiniPreview *mini_preview,
67 gint first, gint last, gpointer user_data);
70 /****************************************************************************/
71 /* Boilerplate Object stuff. */
72 /****************************************************************************/
73 G_DEFINE_TYPE (glWdgtPrintCopies, gl_wdgt_print_copies, GTK_TYPE_HBOX);
76 gl_wdgt_print_copies_class_init (glWdgtPrintCopiesClass * class)
78 GObjectClass *object_class = G_OBJECT_CLASS (class);
80 gl_wdgt_print_copies_parent_class = g_type_class_peek_parent (class);
82 object_class->finalize = gl_wdgt_print_copies_finalize;
86 gl_wdgt_print_copies_init (glWdgtPrintCopies * copies)
88 copies->labels_per_sheet = 0;
90 copies->mini_preview = NULL;
92 copies->sheets_radio = NULL;
93 copies->sheets_spin = NULL;
95 copies->labels_radio = NULL;
96 copies->first_spin = NULL;
97 copies->last_spin = NULL;
101 gl_wdgt_print_copies_finalize (GObject * object)
103 g_return_if_fail (object != NULL);
104 g_return_if_fail (GL_IS_WDGT_PRINT_COPIES (object));
106 G_OBJECT_CLASS (gl_wdgt_print_copies_parent_class)->finalize (object);
110 gl_wdgt_print_copies_new (glLabel * label)
112 glWdgtPrintCopies *copies;
114 copies = g_object_new (gl_wdgt_print_copies_get_type (), NULL);
116 gl_wdgt_print_copies_construct (copies, label);
118 return GTK_WIDGET (copies);
121 /*--------------------------------------------------------------------------*/
122 /* Construct composite widget. */
123 /*--------------------------------------------------------------------------*/
125 gl_wdgt_print_copies_construct (glWdgtPrintCopies *copies,
128 const lglTemplateFrame *frame;
129 GtkWidget *whbox, *wvbox, *whbox1;
130 GSList *radio_group = NULL;
133 whbox = GTK_WIDGET (copies);
135 frame = (lglTemplateFrame *)label->template->frames->data;
137 copies->labels_per_sheet = lgl_template_frame_get_n_labels (frame);
139 /* mini_preview canvas */
140 copies->mini_preview = gl_wdgt_mini_preview_new (WDGT_MINI_PREVIEW_HEIGHT,
141 WDGT_MINI_PREVIEW_WIDTH);
142 gl_wdgt_mini_preview_set_template (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
144 gtk_box_pack_start (GTK_BOX(whbox), copies->mini_preview, FALSE, FALSE, 0);
146 wvbox = gtk_vbox_new (FALSE, GL_HIG_PAD1);
147 gtk_box_pack_start (GTK_BOX(whbox), wvbox, FALSE, FALSE, 0);
150 whbox1 = gtk_hbox_new (FALSE, GL_HIG_PAD2);
151 gtk_box_pack_start (GTK_BOX(wvbox), whbox1, FALSE, FALSE, 0);
152 copies->sheets_radio =
153 gtk_radio_button_new_with_label (radio_group, _("Sheets:"));
154 gtk_box_pack_start (GTK_BOX(whbox1), copies->sheets_radio, FALSE, FALSE, 0);
155 adjust = gtk_adjustment_new (1, 1.0, 10.0, 1.0, 10.0, 10.0);
156 copies->sheets_spin = gtk_spin_button_new (GTK_ADJUSTMENT (adjust),
158 gtk_box_pack_start (GTK_BOX(whbox1), copies->sheets_spin, FALSE, FALSE, 0);
159 gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
160 1, copies->labels_per_sheet);
163 gtk_box_pack_start (GTK_BOX(wvbox), gtk_label_new (""), FALSE, FALSE, 0);
166 whbox1 = gtk_hbox_new (FALSE, GL_HIG_PAD2);
167 gtk_box_pack_start (GTK_BOX(wvbox), whbox1, FALSE, FALSE, 0);
169 gtk_radio_button_get_group (GTK_RADIO_BUTTON (copies->sheets_radio));
170 copies->labels_radio =
171 gtk_radio_button_new_with_label (radio_group, _("Labels"));
172 gtk_box_pack_start (GTK_BOX(whbox1), copies->labels_radio, FALSE, FALSE, 0);
173 gtk_box_pack_start (GTK_BOX(whbox1), gtk_label_new (_("from:")), FALSE, FALSE, 0);
174 adjust = gtk_adjustment_new (1, 1.0, copies->labels_per_sheet,
176 copies->first_spin = gtk_spin_button_new (GTK_ADJUSTMENT (adjust),
178 gtk_box_pack_start (GTK_BOX(whbox1), copies->first_spin, FALSE, FALSE, 0);
179 gtk_box_pack_start (GTK_BOX(whbox1), gtk_label_new (_("to:")), FALSE, FALSE, 0);
180 adjust = gtk_adjustment_new (copies->labels_per_sheet,
181 1.0, copies->labels_per_sheet,
183 copies->last_spin = gtk_spin_button_new (GTK_ADJUSTMENT (adjust),
185 gtk_box_pack_start (GTK_BOX(whbox1), copies->last_spin, FALSE, FALSE, 0);
186 gtk_widget_set_sensitive (copies->first_spin, FALSE);
187 gtk_widget_set_sensitive (copies->last_spin, FALSE);
189 /* Connect signals to controls */
190 g_signal_connect (G_OBJECT (copies->mini_preview), "pressed",
191 G_CALLBACK (preview_pressed), copies);
192 g_signal_connect (G_OBJECT (copies->sheets_radio), "toggled",
193 G_CALLBACK (sheets_radio_cb), copies);
194 g_signal_connect (G_OBJECT (copies->first_spin), "changed",
195 G_CALLBACK (first_spin_cb), copies);
196 g_signal_connect (G_OBJECT (copies->last_spin), "changed",
197 G_CALLBACK (last_spin_cb), copies);
200 /*--------------------------------------------------------------------------*/
201 /* PRIVATE. Enable/Disable appropriate controls due to radio button toggle.*/
202 /*--------------------------------------------------------------------------*/
204 sheets_radio_cb (GtkToggleButton * togglebutton,
207 glWdgtPrintCopies *copies = GL_WDGT_PRINT_COPIES (user_data);
210 if (gtk_toggle_button_get_active (togglebutton)) {
212 gtk_widget_set_sensitive (copies->sheets_spin, TRUE);
213 gtk_widget_set_sensitive (copies->first_spin, FALSE);
214 gtk_widget_set_sensitive (copies->last_spin, FALSE);
216 gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
217 1, copies->labels_per_sheet);
221 gtk_widget_set_sensitive (copies->sheets_spin, FALSE);
222 gtk_widget_set_sensitive (copies->first_spin, TRUE);
223 gtk_widget_set_sensitive (copies->last_spin, TRUE);
226 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
227 (copies->first_spin));
229 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
230 (copies->last_spin));
231 gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
237 /*--------------------------------------------------------------------------*/
238 /* PRIVATE. modify widget due to change of first spin button */
239 /*--------------------------------------------------------------------------*/
241 first_spin_cb (GtkSpinButton * spinbutton,
244 glWdgtPrintCopies *copies = GL_WDGT_PRINT_COPIES (user_data);
248 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
249 (copies->first_spin));
251 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
252 (copies->last_spin));
254 gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (copies->last_spin))->
257 gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
261 /*--------------------------------------------------------------------------*/
262 /* PRIVATE. modify widget due to change of last spin button */
263 /*--------------------------------------------------------------------------*/
265 last_spin_cb (GtkSpinButton * spinbutton,
268 glWdgtPrintCopies *copies = GL_WDGT_PRINT_COPIES (user_data);
272 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
273 (copies->first_spin));
275 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
276 (copies->last_spin));
278 gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (copies->first_spin))->
281 gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
285 /*--------------------------------------------------------------------------*/
286 /* PRIVATE. Canvas event handler, select first and last items. */
287 /*--------------------------------------------------------------------------*/
289 preview_pressed (glWdgtMiniPreview *mini_preview,
294 glWdgtPrintCopies *copies = GL_WDGT_PRINT_COPIES (user_data);
296 gl_wdgt_print_copies_set_range (copies, 1, first, last);
299 /****************************************************************************/
300 /* query selected range of labels within sheet or number of sheets. */
301 /****************************************************************************/
303 gl_wdgt_print_copies_get_range (glWdgtPrintCopies * copies,
308 gboolean sheets_active;
311 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
312 (copies->sheets_radio));
316 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
317 (copies->sheets_spin));
319 *last_label = copies->labels_per_sheet;
323 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
324 (copies->first_spin));
326 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
327 (copies->last_spin));
331 /****************************************************************************/
332 /* set range of labels within sheet or number of sheets */
333 /****************************************************************************/
335 gl_wdgt_print_copies_set_range (glWdgtPrintCopies * copies,
340 gint old_first_label;
343 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
344 (copies->first_spin));
346 if (first_label > old_first_label) {
347 gtk_spin_button_set_value (GTK_SPIN_BUTTON (copies->last_spin),
349 gtk_spin_button_set_value (GTK_SPIN_BUTTON (copies->first_spin),
352 gtk_spin_button_set_value (GTK_SPIN_BUTTON (copies->first_spin),
354 gtk_spin_button_set_value (GTK_SPIN_BUTTON (copies->last_spin),
357 if ((first_label == 1) && (last_label == copies->labels_per_sheet)) {
358 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
359 (copies->sheets_radio), TRUE);
360 gtk_spin_button_set_value (GTK_SPIN_BUTTON
361 (copies->sheets_spin), n_sheets);
363 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
364 (copies->labels_radio), TRUE);
365 gtk_spin_button_set_value (GTK_SPIN_BUTTON
366 (copies->sheets_spin), 1.0);