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>
29 #include <libglabels/libglabels.h>
30 #include "mini-label-preview.h"
37 /*========================================================*/
38 /* Private macros and constants. */
39 /*========================================================*/
44 /*===========================================*/
46 /*===========================================*/
48 struct _glRotateLabelButtonPrivate {
50 GtkWidget *no_rotate_radio;
51 GtkWidget *rotate_radio;
52 GtkWidget *no_rotate_preview;
53 GtkWidget *rotate_preview;
62 /*===========================================*/
64 /*===========================================*/
66 static gint rotate_label_button_signals[LAST_SIGNAL] = { 0 };
69 /*===========================================*/
70 /* Local function prototypes */
71 /*===========================================*/
73 static void gl_rotate_label_button_finalize (GObject *object);
75 static void toggled_cb (GtkToggleButton *toggle,
79 /****************************************************************************/
80 /* Boilerplate Object stuff. */
81 /****************************************************************************/
82 G_DEFINE_TYPE (glRotateLabelButton, gl_rotate_label_button, GTK_TYPE_HBOX);
86 gl_rotate_label_button_class_init (glRotateLabelButtonClass *class)
88 GObjectClass *object_class = G_OBJECT_CLASS (class);
90 gl_rotate_label_button_parent_class = g_type_class_peek_parent (class);
92 object_class->finalize = gl_rotate_label_button_finalize;
94 rotate_label_button_signals[CHANGED] =
95 g_signal_new ("changed",
96 G_OBJECT_CLASS_TYPE(object_class),
98 G_STRUCT_OFFSET (glRotateLabelButtonClass, changed),
100 gl_marshal_VOID__VOID,
107 gl_rotate_label_button_init (glRotateLabelButton *this)
112 this->priv = g_new0 (glRotateLabelButtonPrivate, 1);
114 gtk_container_set_border_width (GTK_CONTAINER (this), GL_HIG_PAD2);
116 this->priv->no_rotate_radio = gtk_radio_button_new (NULL);
117 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (this->priv->no_rotate_radio),
119 vbox = gtk_vbox_new (FALSE, 1);
120 this->priv->no_rotate_preview = gl_mini_label_preview_new (SIZE, SIZE);
121 gtk_box_pack_start (GTK_BOX (vbox), this->priv->no_rotate_preview, FALSE, FALSE, 0);
122 label = gtk_label_new (_("Normal"));
123 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
124 gtk_container_add (GTK_CONTAINER (this->priv->no_rotate_radio), vbox);
127 this->priv->rotate_radio = gtk_radio_button_new_from_widget (GTK_RADIO_BUTTON (this->priv->no_rotate_radio));
128 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (this->priv->rotate_radio),
130 vbox = gtk_vbox_new (FALSE, 1);
131 this->priv->rotate_preview = gl_mini_label_preview_new (SIZE, SIZE);
132 gtk_box_pack_start (GTK_BOX (vbox), this->priv->rotate_preview, FALSE, FALSE, 0);
133 label = gtk_label_new (_("Rotated"));
134 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
135 gtk_container_add (GTK_CONTAINER (this->priv->rotate_radio), vbox);
137 gtk_box_pack_start (GTK_BOX (this),
138 this->priv->no_rotate_radio,
139 FALSE, FALSE, GL_HIG_PAD1);
140 gtk_box_pack_start (GTK_BOX (this),
141 this->priv->rotate_radio,
142 FALSE, FALSE, GL_HIG_PAD1);
144 /* Connect signals to controls */
145 g_signal_connect (G_OBJECT (this->priv->no_rotate_radio),
147 G_CALLBACK (toggled_cb), this);
148 g_signal_connect (G_OBJECT (this->priv->rotate_radio),
150 G_CALLBACK (toggled_cb), this);
155 gl_rotate_label_button_finalize (GObject *object)
157 glRotateLabelButton *this = GL_ROTATE_LABEL_BUTTON (object);
159 g_return_if_fail (object != NULL);
160 g_return_if_fail (GL_IS_ROTATE_LABEL_BUTTON (object));
164 G_OBJECT_CLASS (gl_rotate_label_button_parent_class)->finalize (object);
169 gl_rotate_label_button_new (void)
171 glRotateLabelButton *this;
173 this = g_object_new (gl_rotate_label_button_get_type (), NULL);
175 return GTK_WIDGET (this);
179 /*--------------------------------------------------------------------------*/
180 /* PRIVATE. modify widget due to change of check button */
181 /*--------------------------------------------------------------------------*/
183 toggled_cb (GtkToggleButton *toggle,
187 /* Emit our "changed" signal */
188 g_signal_emit (G_OBJECT (user_data),
189 rotate_label_button_signals[CHANGED], 0);
194 /****************************************************************************/
195 /* query state of widget. */
196 /****************************************************************************/
198 gl_rotate_label_button_get_state (glRotateLabelButton *this)
201 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
202 (this->priv->rotate_radio));
205 /****************************************************************************/
206 /* set state of widget. */
207 /****************************************************************************/
209 gl_rotate_label_button_set_state (glRotateLabelButton *this,
212 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
213 (this->priv->rotate_radio), state);
216 /****************************************************************************/
217 /* set template for widget. */
218 /****************************************************************************/
220 gl_rotate_label_button_set_template_name (glRotateLabelButton *this,
223 lglTemplate *template;
224 const lglTemplateFrame *frame;
225 gdouble raw_w, raw_h;
229 gtk_widget_set_sensitive (this->priv->no_rotate_radio, FALSE);
230 gtk_widget_set_sensitive (this->priv->rotate_radio, FALSE);
234 template = lgl_db_lookup_template_from_name (name);
235 frame = (lglTemplateFrame *)template->frames->data;
237 gl_mini_label_preview_set_by_name (GL_MINI_LABEL_PREVIEW (this->priv->no_rotate_preview),
239 gl_mini_label_preview_set_by_name (GL_MINI_LABEL_PREVIEW (this->priv->rotate_preview),
242 lgl_template_frame_get_size (frame, &raw_w, &raw_h);
243 gtk_widget_set_sensitive (this->priv->no_rotate_radio,
245 gtk_widget_set_sensitive (this->priv->rotate_radio,
248 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
249 (this->priv->no_rotate_radio), TRUE);
250 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
251 (this->priv->rotate_radio), FALSE);
259 * Local Variables: -- emacs
261 * c-basic-offset: 8 -- emacs
262 * tab-width: 8 -- emacs
263 * indent-tabs-mode: nil -- emacs