2 * rotate-label-button.c
3 * Copyright (C) 2001-2009 Jim Evins <evins@snaught.com>.
5 * This file is part of gLabels.
7 * gLabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * gLabels is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with gLabels. If not, see <http://www.gnu.org/licenses/>.
23 #include "rotate-label-button.h"
25 #include <glib/gi18n.h>
26 #include <gtk/gtkradiobutton.h>
27 #include <gtk/gtklabel.h>
28 #include <gtk/gtkvbox.h>
30 #include "mini-label-preview.h"
31 #include <libglabels/db.h>
38 /*========================================================*/
39 /* Private macros and constants. */
40 /*========================================================*/
45 /*===========================================*/
47 /*===========================================*/
49 struct _glRotateLabelButtonPrivate {
51 GtkWidget *no_rotate_radio;
52 GtkWidget *rotate_radio;
53 GtkWidget *no_rotate_preview;
54 GtkWidget *rotate_preview;
63 /*===========================================*/
65 /*===========================================*/
67 static gint rotate_label_button_signals[LAST_SIGNAL] = { 0 };
70 /*===========================================*/
71 /* Local function prototypes */
72 /*===========================================*/
74 static void gl_rotate_label_button_finalize (GObject *object);
76 static void toggled_cb (GtkToggleButton *toggle,
80 /****************************************************************************/
81 /* Boilerplate Object stuff. */
82 /****************************************************************************/
83 G_DEFINE_TYPE (glRotateLabelButton, gl_rotate_label_button, GTK_TYPE_HBOX);
87 gl_rotate_label_button_class_init (glRotateLabelButtonClass *class)
89 GObjectClass *object_class = G_OBJECT_CLASS (class);
91 gl_rotate_label_button_parent_class = g_type_class_peek_parent (class);
93 object_class->finalize = gl_rotate_label_button_finalize;
95 rotate_label_button_signals[CHANGED] =
96 g_signal_new ("changed",
97 G_OBJECT_CLASS_TYPE(object_class),
99 G_STRUCT_OFFSET (glRotateLabelButtonClass, changed),
101 gl_marshal_VOID__VOID,
108 gl_rotate_label_button_init (glRotateLabelButton *this)
113 this->priv = g_new0 (glRotateLabelButtonPrivate, 1);
115 gtk_container_set_border_width (GTK_CONTAINER (this), GL_HIG_PAD2);
117 this->priv->no_rotate_radio = gtk_radio_button_new (NULL);
118 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (this->priv->no_rotate_radio),
120 vbox = gtk_vbox_new (FALSE, 1);
121 this->priv->no_rotate_preview = gl_mini_label_preview_new (SIZE, SIZE);
122 gtk_box_pack_start (GTK_BOX (vbox), this->priv->no_rotate_preview, FALSE, FALSE, 0);
123 label = gtk_label_new (_("Normal"));
124 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
125 gtk_container_add (GTK_CONTAINER (this->priv->no_rotate_radio), vbox);
128 this->priv->rotate_radio = gtk_radio_button_new_from_widget (GTK_RADIO_BUTTON (this->priv->no_rotate_radio));
129 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (this->priv->rotate_radio),
131 vbox = gtk_vbox_new (FALSE, 1);
132 this->priv->rotate_preview = gl_mini_label_preview_new (SIZE, SIZE);
133 gtk_box_pack_start (GTK_BOX (vbox), this->priv->rotate_preview, FALSE, FALSE, 0);
134 label = gtk_label_new (_("Rotated"));
135 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
136 gtk_container_add (GTK_CONTAINER (this->priv->rotate_radio), vbox);
138 gtk_box_pack_start (GTK_BOX (this),
139 this->priv->no_rotate_radio,
140 FALSE, FALSE, GL_HIG_PAD1);
141 gtk_box_pack_start (GTK_BOX (this),
142 this->priv->rotate_radio,
143 FALSE, FALSE, GL_HIG_PAD1);
145 /* Connect signals to controls */
146 g_signal_connect (G_OBJECT (this->priv->no_rotate_radio),
148 G_CALLBACK (toggled_cb), this);
149 g_signal_connect (G_OBJECT (this->priv->rotate_radio),
151 G_CALLBACK (toggled_cb), this);
156 gl_rotate_label_button_finalize (GObject *object)
158 glRotateLabelButton *this = GL_ROTATE_LABEL_BUTTON (object);
160 g_return_if_fail (object != NULL);
161 g_return_if_fail (GL_IS_ROTATE_LABEL_BUTTON (object));
165 G_OBJECT_CLASS (gl_rotate_label_button_parent_class)->finalize (object);
170 gl_rotate_label_button_new (void)
172 glRotateLabelButton *this;
174 this = g_object_new (gl_rotate_label_button_get_type (), NULL);
176 return GTK_WIDGET (this);
180 /*--------------------------------------------------------------------------*/
181 /* PRIVATE. modify widget due to change of check button */
182 /*--------------------------------------------------------------------------*/
184 toggled_cb (GtkToggleButton *toggle,
188 /* Emit our "changed" signal */
189 g_signal_emit (G_OBJECT (user_data),
190 rotate_label_button_signals[CHANGED], 0);
195 /****************************************************************************/
196 /* query state of widget. */
197 /****************************************************************************/
199 gl_rotate_label_button_get_state (glRotateLabelButton *this)
202 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
203 (this->priv->rotate_radio));
206 /****************************************************************************/
207 /* set state of widget. */
208 /****************************************************************************/
210 gl_rotate_label_button_set_state (glRotateLabelButton *this,
213 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
214 (this->priv->rotate_radio), state);
217 /****************************************************************************/
218 /* set template for widget. */
219 /****************************************************************************/
221 gl_rotate_label_button_set_template_name (glRotateLabelButton *this,
224 lglTemplate *template;
225 const lglTemplateFrame *frame;
226 gdouble raw_w, raw_h;
230 gtk_widget_set_sensitive (this->priv->no_rotate_radio, FALSE);
231 gtk_widget_set_sensitive (this->priv->rotate_radio, FALSE);
235 template = lgl_db_lookup_template_from_name (name);
236 frame = (lglTemplateFrame *)template->frames->data;
238 gl_mini_label_preview_set_by_name (GL_MINI_LABEL_PREVIEW (this->priv->no_rotate_preview),
240 gl_mini_label_preview_set_by_name (GL_MINI_LABEL_PREVIEW (this->priv->rotate_preview),
243 lgl_template_frame_get_size (frame, &raw_w, &raw_h);
244 gtk_widget_set_sensitive (this->priv->no_rotate_radio,
246 gtk_widget_set_sensitive (this->priv->rotate_radio,
249 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
250 (this->priv->no_rotate_radio), TRUE);
251 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
252 (this->priv->rotate_radio), FALSE);
260 * Local Variables: -- emacs
262 * c-basic-offset: 8 -- emacs
263 * tab-width: 8 -- emacs
264 * indent-tabs-mode: nil -- emacs