2 * (GLABELS) Label and Business Card Creation program for GNOME
4 * prop_text.c: text properties widget module
6 * Copyright (C) 2001-2002 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 "prop_text.h"
29 #define RED(x) ( ((x)>>24) & 0xff )
30 #define GREEN(x) ( ((x)>>16) & 0xff )
31 #define BLUE(x) ( ((x)>>8) & 0xff )
32 #define ALPHA(x) ( (x) & 0xff )
34 /*===========================================*/
36 /*===========================================*/
43 typedef void (*glPropTextSignal) (GtkObject * object,
46 /*===========================================*/
48 /*===========================================*/
50 static GtkContainerClass *parent_class;
52 static gint prop_text_signals[LAST_SIGNAL] = { 0 };
54 /*===========================================*/
55 /* Local function prototypes */
56 /*===========================================*/
58 static void gl_prop_text_class_init (glPropTextClass * class);
59 static void gl_prop_text_init (glPropText * text);
60 static void gl_prop_text_destroy (GtkObject * object);
61 static void gl_prop_text_construct (glPropText * text, gchar * label);
63 static void changed_cb (glPropText * text);
64 static void just_toggled_cb (GtkToggleButton * togglebutton,
67 /*================================================================*/
68 /* Boilerplate Object stuff. */
69 /*================================================================*/
71 gl_prop_text_get_type (void)
73 static guint prop_text_type = 0;
75 if (!prop_text_type) {
76 GtkTypeInfo prop_text_info = {
79 sizeof (glPropTextClass),
80 (GtkClassInitFunc) gl_prop_text_class_init,
81 (GtkObjectInitFunc) gl_prop_text_init,
87 gtk_type_unique (gtk_vbox_get_type (), &prop_text_info);
90 return prop_text_type;
94 gl_prop_text_class_init (glPropTextClass * class)
96 GtkObjectClass *object_class;
97 GtkWidgetClass *widget_class;
99 object_class = (GtkObjectClass *) class;
100 widget_class = (GtkWidgetClass *) class;
102 parent_class = gtk_type_class (gtk_vbox_get_type ());
104 object_class->destroy = gl_prop_text_destroy;
106 prop_text_signals[CHANGED] =
107 gtk_signal_new ("changed", GTK_RUN_LAST, object_class->type,
108 GTK_SIGNAL_OFFSET (glPropTextClass, changed),
109 gtk_signal_default_marshaller, GTK_TYPE_NONE, 0);
110 gtk_object_class_add_signals (object_class, prop_text_signals,
113 class->changed = NULL;
117 gl_prop_text_init (glPropText * text)
119 text->font_family_entry = NULL;
120 text->font_size_spin = NULL;
121 text->font_b_button = NULL;
122 text->font_i_button = NULL;
124 text->color_picker = NULL;
126 text->left_button = NULL;
127 text->right_button = NULL;
128 text->center_button = NULL;
132 gl_prop_text_destroy (GtkObject * object)
135 glPropTextClass *class;
137 g_return_if_fail (object != NULL);
138 g_return_if_fail (GL_IS_PROP_TEXT (object));
140 text = GL_PROP_TEXT (object);
141 class = GL_PROP_TEXT_CLASS (GTK_OBJECT (text)->klass);
143 GTK_OBJECT_CLASS (parent_class)->destroy (object);
147 gl_prop_text_new (gchar * label)
151 text = gtk_type_new (gl_prop_text_get_type ());
153 gl_prop_text_construct (text, label);
155 return GTK_WIDGET (text);
158 /*============================================================*/
159 /* Construct composite widget. */
160 /*============================================================*/
162 gl_prop_text_construct (glPropText * text,
165 GtkWidget *wvbox, *wframe, *wtable, *wlabel, *whbox1, *wcombo;
166 GList *family_names = NULL;
169 wvbox = GTK_WIDGET (text);
171 wframe = gtk_frame_new (label);
172 gtk_box_pack_start (GTK_BOX (wvbox), wframe, FALSE, FALSE, 0);
174 wtable = gtk_table_new (3, 3, FALSE);
175 gtk_container_set_border_width (GTK_CONTAINER (wtable), 10);
176 gtk_table_set_row_spacings (GTK_TABLE (wtable), 5);
177 gtk_table_set_col_spacings (GTK_TABLE (wtable), 5);
178 gtk_container_add (GTK_CONTAINER (wframe), wtable);
181 wlabel = gtk_label_new (_("Font:"));
182 gtk_misc_set_alignment (GTK_MISC (wlabel), 0, 0.5);
183 gtk_label_set_justify (GTK_LABEL (wlabel), GTK_JUSTIFY_RIGHT);
184 gtk_table_attach_defaults (GTK_TABLE (wtable), wlabel, 0, 1, 0, 1);
186 /* Pack these widgets into an inner hbox */
187 whbox1 = gtk_hbox_new (FALSE, GNOME_PAD);
188 gtk_table_attach_defaults (GTK_TABLE (wtable), whbox1, 1, 3, 0, 1);
190 /* Font family entry widget */
191 wcombo = gtk_combo_new ();
192 family_names = gnome_font_family_list ();
193 gtk_combo_set_popdown_strings (GTK_COMBO (wcombo), family_names);
194 gnome_font_family_list_free (family_names);
195 text->font_family_entry = GTK_COMBO (wcombo)->entry;
196 gtk_entry_set_editable (GTK_ENTRY (text->font_family_entry), FALSE);
197 gtk_widget_set_usize (wcombo, 200, 0);
198 gtk_box_pack_start (GTK_BOX (whbox1), wcombo, FALSE, FALSE, 0);
199 gtk_signal_connect_object (GTK_OBJECT (text->font_family_entry),
200 "changed", GTK_SIGNAL_FUNC (changed_cb),
203 /* Font size entry widget */
204 adjust = gtk_adjustment_new (1.0, 1.0, 250.0, 1.0, 10.0, 10.0);
205 text->font_size_spin =
206 gtk_spin_button_new (GTK_ADJUSTMENT (adjust), 1.0, 0);
207 gtk_box_pack_start (GTK_BOX (whbox1), text->font_size_spin, FALSE,
209 gtk_signal_connect_object (GTK_OBJECT (text->font_size_spin), "changed",
210 GTK_SIGNAL_FUNC (changed_cb),
213 /* Font weight/italic button widgets */
214 text->font_b_button = gtk_toggle_button_new ();
215 gtk_container_add (GTK_CONTAINER (text->font_b_button),
216 gnome_stock_new_with_icon
217 (GNOME_STOCK_PIXMAP_TEXT_BOLD));
218 gtk_box_pack_start (GTK_BOX (whbox1), text->font_b_button, FALSE, FALSE,
220 gtk_signal_connect_object (GTK_OBJECT (text->font_b_button), "toggled",
221 GTK_SIGNAL_FUNC (changed_cb),
223 text->font_i_button = gtk_toggle_button_new ();
224 gtk_container_add (GTK_CONTAINER (text->font_i_button),
225 gnome_stock_new_with_icon
226 (GNOME_STOCK_PIXMAP_TEXT_ITALIC));
227 gtk_box_pack_start (GTK_BOX (whbox1), text->font_i_button, FALSE, FALSE,
229 gtk_signal_connect_object (GTK_OBJECT (text->font_i_button), "toggled",
230 GTK_SIGNAL_FUNC (changed_cb),
233 /* Text Color Label */
234 wlabel = gtk_label_new (_("Color:"));
235 gtk_misc_set_alignment (GTK_MISC (wlabel), 0, 0.5);
236 gtk_label_set_justify (GTK_LABEL (wlabel), GTK_JUSTIFY_RIGHT);
237 gtk_table_attach_defaults (GTK_TABLE (wtable), wlabel, 0, 1, 1, 2);
239 /* Text Color picker widget */
240 text->color_picker = gnome_color_picker_new ();
241 gtk_signal_connect_object (GTK_OBJECT (text->color_picker), "color_set",
242 GTK_SIGNAL_FUNC (changed_cb),
244 gtk_table_attach_defaults (GTK_TABLE (wtable), text->color_picker, 1, 2,
247 /* Alignment label */
248 wlabel = gtk_label_new (_("Alignment:"));
249 gtk_misc_set_alignment (GTK_MISC (wlabel), 0, 0.5);
250 gtk_label_set_justify (GTK_LABEL (wlabel), GTK_JUSTIFY_RIGHT);
251 gtk_table_attach_defaults (GTK_TABLE (wtable), wlabel, 0, 1, 2, 3);
253 /* Pack these widgets into an inner hbox */
254 whbox1 = gtk_hbox_new (FALSE, GNOME_PAD);
255 gtk_table_attach_defaults (GTK_TABLE (wtable), whbox1, 1, 2, 2, 3);
257 /* Justification entry widget */
258 text->left_button = gtk_toggle_button_new ();
259 gtk_container_add (GTK_CONTAINER (text->left_button),
260 gnome_stock_new_with_icon
261 (GNOME_STOCK_PIXMAP_ALIGN_LEFT));
262 gtk_box_pack_start (GTK_BOX (whbox1), text->left_button, FALSE, FALSE,
264 text->center_button = gtk_toggle_button_new ();
265 gtk_container_add (GTK_CONTAINER (text->center_button),
266 gnome_stock_new_with_icon
267 (GNOME_STOCK_PIXMAP_ALIGN_CENTER));
268 gtk_box_pack_start (GTK_BOX (whbox1), text->center_button, FALSE, FALSE,
270 text->right_button = gtk_toggle_button_new ();
271 gtk_container_add (GTK_CONTAINER (text->right_button),
272 gnome_stock_new_with_icon
273 (GNOME_STOCK_PIXMAP_ALIGN_RIGHT));
274 gtk_box_pack_start (GTK_BOX (whbox1), text->right_button, FALSE, FALSE,
277 /* Now connect a callback that makes these toggles mutually exclusive */
278 gtk_signal_connect (GTK_OBJECT (text->left_button), "toggled",
279 GTK_SIGNAL_FUNC (just_toggled_cb), text);
280 gtk_signal_connect (GTK_OBJECT (text->center_button), "toggled",
281 GTK_SIGNAL_FUNC (just_toggled_cb), text);
282 gtk_signal_connect (GTK_OBJECT (text->right_button), "toggled",
283 GTK_SIGNAL_FUNC (just_toggled_cb), text);
287 /*--------------------------------------------------------------------------*/
288 /* PRIVATE. Callback for when any control in the widget has changed. */
289 /*--------------------------------------------------------------------------*/
291 changed_cb (glPropText * text)
293 /* Emit our "changed" signal */
294 gtk_signal_emit (GTK_OBJECT (text), prop_text_signals[CHANGED]);
297 /*--------------------------------------------------------------------------*/
298 /* PRIVATE. Justify toggle button callback. */
299 /*--------------------------------------------------------------------------*/
301 just_toggled_cb (GtkToggleButton * togglebutton,
304 glPropText *text = GL_PROP_TEXT (user_data);
306 if (gtk_toggle_button_get_active (togglebutton)) {
308 if (GTK_WIDGET (togglebutton) == GTK_WIDGET (text->left_button)) {
309 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
310 (text->center_button),
312 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
313 (text->right_button),
315 } else if (GTK_WIDGET (togglebutton) ==
316 GTK_WIDGET (text->center_button)) {
317 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
320 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
321 (text->right_button),
323 } else if (GTK_WIDGET (togglebutton) ==
324 GTK_WIDGET (text->right_button)) {
325 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
328 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
329 (text->center_button),
335 /* Emit our "changed" signal */
336 gtk_signal_emit (GTK_OBJECT (text), prop_text_signals[CHANGED]);
339 /*====================================================================*/
340 /* query values from controls. */
341 /*====================================================================*/
343 gl_prop_text_get_params (glPropText * text,
344 gchar ** font_family,
346 GnomeFontWeight * font_weight,
347 gboolean * font_italic_flag,
349 GtkJustification * just)
353 /* ------ Get updated font information ------ */
355 gtk_editable_get_chars (GTK_EDITABLE (text->font_family_entry), 0,
358 gtk_spin_button_get_value_as_float (GTK_SPIN_BUTTON
359 (text->font_size_spin));
360 if (gtk_toggle_button_get_active
361 (GTK_TOGGLE_BUTTON (text->font_b_button))) {
362 *font_weight = GNOME_FONT_BOLD;
364 *font_weight = GNOME_FONT_BOOK;
367 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
368 (text->font_i_button));
370 /* ------ Get updated color ------ */
371 gnome_color_picker_get_i8 (GNOME_COLOR_PICKER (text->color_picker),
373 *color = GNOME_CANVAS_COLOR_A (r, g, b, a);
375 /* ------- Get updated justification ------ */
376 if (gtk_toggle_button_get_active
377 (GTK_TOGGLE_BUTTON (text->left_button))) {
378 *just = GTK_JUSTIFY_LEFT;
380 if (gtk_toggle_button_get_active
381 (GTK_TOGGLE_BUTTON (text->right_button))) {
382 *just = GTK_JUSTIFY_RIGHT;
384 if (gtk_toggle_button_get_active
385 (GTK_TOGGLE_BUTTON (text->center_button))) {
386 *just = GTK_JUSTIFY_CENTER;
388 *just = GTK_JUSTIFY_LEFT; /* Should not happen. */
393 /*====================================================================*/
394 /* fill in values and ranges for controls. */
395 /*====================================================================*/
397 gl_prop_text_set_params (glPropText * text,
400 GnomeFontWeight font_weight,
401 gboolean font_italic_flag,
403 GtkJustification just)
405 gtk_entry_set_text (GTK_ENTRY (text->font_family_entry), font_family);
407 gtk_spin_button_set_value (GTK_SPIN_BUTTON (text->font_size_spin),
410 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text->font_b_button),
411 (font_weight == GNOME_FONT_BOLD));
413 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text->font_i_button),
416 gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (text->color_picker),
417 RED (color), GREEN (color), BLUE (color),
420 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text->left_button),
421 (just == GTK_JUSTIFY_LEFT));
422 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text->center_button),
423 (just == GTK_JUSTIFY_CENTER));
424 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text->right_button),
425 (just == GTK_JUSTIFY_RIGHT));