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 * object-editor.c: object properties editor module
8 * Copyright (C) 2003 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
26 #include "object-editor.h"
28 #include <glib/gi18n.h>
29 #include <glade/glade-xml.h>
30 #include <gtk/gtklabel.h>
31 #include <gtk/gtknotebook.h>
32 #include <gtk/gtkcombobox.h>
33 #include <gtk/gtktogglebutton.h>
38 #include "color-combo.h"
40 #include "wdgt-chain-button.h"
41 #include "wdgt-merge-menu.h"
45 #include "object-editor-private.h"
49 /*===========================================*/
51 /*===========================================*/
53 /*===========================================*/
54 /* Private data types */
55 /*===========================================*/
57 typedef void (*ChangedSignal) (GObject * object, gpointer data);
59 /*===========================================*/
61 /*===========================================*/
63 gint gl_object_editor_signals[LAST_SIGNAL] = { 0 };
65 /*===========================================*/
66 /* Local function prototypes */
67 /*===========================================*/
69 static void gl_object_editor_finalize (GObject *object);
71 static void gl_object_notebook_construct_valist (glObjectEditor *editor,
73 glObjectEditorOption first_option,
76 static void prefs_changed_cb (glObjectEditor *editor);
78 static void label_changed_cb (glLabel *label,
79 glObjectEditor *editor);
82 /*****************************************************************************/
83 /* Boilerplate object stuff. */
84 /*****************************************************************************/
85 G_DEFINE_TYPE (glObjectEditor, gl_object_editor, GTK_TYPE_VBOX);
88 gl_object_editor_class_init (glObjectEditorClass *class)
90 GObjectClass *object_class = G_OBJECT_CLASS (class);
92 gl_debug (DEBUG_EDITOR, "START");
94 gl_object_editor_parent_class = g_type_class_peek_parent (class);
96 object_class->finalize = gl_object_editor_finalize;
98 gl_object_editor_signals[CHANGED] =
99 g_signal_new ("changed",
100 G_OBJECT_CLASS_TYPE(object_class),
102 G_STRUCT_OFFSET (glObjectEditorClass, changed),
104 gl_marshal_VOID__VOID,
107 gl_object_editor_signals[SIZE_CHANGED] =
108 g_signal_new ("size_changed",
109 G_OBJECT_CLASS_TYPE(object_class),
111 G_STRUCT_OFFSET (glObjectEditorClass, size_changed),
113 gl_marshal_VOID__VOID,
116 gl_debug (DEBUG_EDITOR, "END");
120 gl_object_editor_init (glObjectEditor *editor)
122 gl_debug (DEBUG_EDITOR, "START");
124 editor->priv = g_new0 (glObjectEditorPrivate, 1);
126 editor->priv->gui = glade_xml_new (GLABELS_GLADE_DIR "object-editor.glade",
130 if (!editor->priv->gui) {
131 g_critical ("Could not open object-editor.glade. gLabels may not be installed correctly!");
135 editor->priv->editor_vbox = glade_xml_get_widget (editor->priv->gui,
137 gtk_box_pack_start (GTK_BOX(editor),
138 editor->priv->editor_vbox,
141 editor->priv->title_image = glade_xml_get_widget (editor->priv->gui,
143 editor->priv->title_label = glade_xml_get_widget (editor->priv->gui,
145 editor->priv->notebook = glade_xml_get_widget (editor->priv->gui,
148 gtk_widget_show_all (GTK_WIDGET(editor));
150 /* Hide all notebook pages to start with. */
151 gtk_widget_hide_all (editor->priv->notebook);
152 gtk_widget_set_no_show_all (editor->priv->notebook, TRUE);
154 gl_debug (DEBUG_EDITOR, "END");
158 gl_object_editor_finalize (GObject *object)
160 glObjectEditor* editor = GL_OBJECT_EDITOR (object);;
162 gl_debug (DEBUG_EDITOR, "START");
164 g_return_if_fail (object != NULL);
165 g_return_if_fail (GL_IS_OBJECT_EDITOR (editor));
166 g_return_if_fail (editor->priv != NULL);
168 g_signal_handlers_disconnect_by_func (G_OBJECT(gl_prefs),
169 prefs_changed_cb, editor);
170 g_signal_handlers_disconnect_by_func (G_OBJECT(editor->priv->label),
171 label_changed_cb, editor);
173 g_object_unref (editor->priv->gui);
174 g_free (editor->priv);
176 G_OBJECT_CLASS (gl_object_editor_parent_class)->finalize (object);
178 gl_debug (DEBUG_EDITOR, "END");
181 /*****************************************************************************/
182 /* NEW object editor. */
183 /*****************************************************************************/
185 gl_object_editor_new (gchar *image,
188 glObjectEditorOption first_option, ...)
190 glObjectEditor *editor;
193 gl_debug (DEBUG_EDITOR, "START");
195 editor = GL_OBJECT_EDITOR (g_object_new (GL_TYPE_OBJECT_EDITOR, NULL));
198 gtk_image_set_from_stock (GTK_IMAGE(editor->priv->title_image),
200 GTK_ICON_SIZE_LARGE_TOOLBAR);
206 s = g_strdup_printf ("<span weight=\"bold\">%s</span>",
208 gtk_label_set_text (GTK_LABEL(editor->priv->title_label), s);
211 gtk_label_set_use_markup (GTK_LABEL(editor->priv->title_label), TRUE);
215 gtk_notebook_set_homogeneous_tabs (GTK_NOTEBOOK(editor->priv->notebook), TRUE);
217 va_start (args, first_option);
218 gl_object_notebook_construct_valist (editor, label, first_option, args);
221 gl_debug (DEBUG_EDITOR, "END");
223 return GTK_WIDGET(editor);
226 /*--------------------------------------------------------------------------*/
227 /* PRIVATE. Construct notebook. */
228 /*--------------------------------------------------------------------------*/
230 gl_object_notebook_construct_valist (glObjectEditor *editor,
232 glObjectEditorOption first_option,
235 glObjectEditorOption option;
238 gl_debug (DEBUG_EDITOR, "START");
240 editor->priv->label = label;
242 option = first_option;
244 for ( option=first_option; option; option=va_arg (args, glObjectEditorOption) ) {
248 case GL_OBJECT_EDITOR_EMPTY:
249 gtk_widget_set_sensitive (editor->priv->title_image, FALSE);
250 gtk_widget_set_sensitive (editor->priv->title_label, FALSE);
253 case GL_OBJECT_EDITOR_POSITION_PAGE:
254 gl_object_editor_prepare_position_page (editor);
258 case GL_OBJECT_EDITOR_SIZE_PAGE:
259 case GL_OBJECT_EDITOR_SIZE_IMAGE_PAGE:
260 gl_object_editor_prepare_size_page (editor, option);
264 case GL_OBJECT_EDITOR_SIZE_LINE_PAGE:
265 gl_object_editor_prepare_lsize_page (editor);
269 case GL_OBJECT_EDITOR_FILL_PAGE:
270 gl_object_editor_prepare_fill_page (editor);
274 case GL_OBJECT_EDITOR_LINE_PAGE:
275 gl_object_editor_prepare_line_page (editor);
279 case GL_OBJECT_EDITOR_IMAGE_PAGE:
280 gl_object_editor_prepare_image_page (editor);
284 case GL_OBJECT_EDITOR_TEXT_PAGE:
285 gl_object_editor_prepare_text_page (editor);
289 case GL_OBJECT_EDITOR_EDIT_PAGE:
290 gl_object_editor_prepare_edit_page (editor);
294 case GL_OBJECT_EDITOR_BC_PAGE:
295 gl_object_editor_prepare_bc_page (editor);
299 case GL_OBJECT_EDITOR_DATA_PAGE:
300 gl_object_editor_prepare_data_page (editor);
304 case GL_OBJECT_EDITOR_SHADOW_PAGE:
305 gl_object_editor_prepare_shadow_page (editor);
310 g_message ("option = %d", option);
311 g_assert_not_reached ();
316 gtk_widget_show (editor->priv->notebook);
319 g_signal_connect_swapped (G_OBJECT (gl_prefs), "changed",
320 G_CALLBACK (prefs_changed_cb),
324 label_changed_cb (label, editor);
325 g_signal_connect (G_OBJECT (label), "size_changed",
326 G_CALLBACK (label_changed_cb),
328 g_signal_connect (G_OBJECT (label), "merge_changed",
329 G_CALLBACK (label_changed_cb),
333 gl_debug (DEBUG_EDITOR, "END");
336 /*--------------------------------------------------------------------------*/
337 /* PRIVATE. Widget changed callback. Emit our "changed" signal. */
338 /*--------------------------------------------------------------------------*/
340 gl_object_editor_changed_cb (glObjectEditor *editor)
342 if (editor->priv->stop_signals) return;
344 gl_debug (DEBUG_EDITOR, "START");
346 /* Emit our "changed" signal */
347 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
349 gl_debug (DEBUG_EDITOR, "END");
352 /*--------------------------------------------------------------------------*/
353 /* PRIVATE. Widget size changed callback. Emit our "size-changed" signal. */
354 /*--------------------------------------------------------------------------*/
356 gl_object_editor_size_changed_cb (glObjectEditor *editor)
358 if (editor->priv->stop_signals) return;
360 gl_debug (DEBUG_EDITOR, "START");
362 /* Emit our "size_changed" signal */
363 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[SIZE_CHANGED], 0);
365 gl_debug (DEBUG_EDITOR, "END");
368 /*****************************************************************************/
369 /* Set possible key names from merge object. */
370 /*****************************************************************************/
372 gl_object_editor_set_key_names (glObjectEditor *editor,
381 gl_debug (DEBUG_EDITOR, "START");
383 if (editor->priv->text_auto_shrink_check) {
384 gtk_widget_set_sensitive (editor->priv->text_auto_shrink_check,
388 if (editor->priv->text_page_vbox) {
389 gtk_widget_set_sensitive (editor->priv->text_color_key_radio, merge != NULL);
391 gtk_toggle_button_set_active (
392 GTK_TOGGLE_BUTTON(editor->priv->text_color_radio), TRUE);
393 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
394 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
396 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(editor->priv->text_color_key_radio));
397 gtk_widget_set_sensitive (editor->priv->text_color_combo, !state);
398 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, state);
403 if (editor->priv->edit_insert_field_button) {
404 gtk_widget_set_sensitive (editor->priv->edit_insert_field_button,
408 if (editor->priv->img_key_combo) {
409 gtk_widget_set_sensitive (editor->priv->img_key_combo, merge != NULL);
412 if (editor->priv->img_key_radio) {
413 gtk_widget_set_sensitive (editor->priv->img_key_radio, merge != NULL);
415 gtk_toggle_button_set_active (
416 GTK_TOGGLE_BUTTON(editor->priv->img_file_radio), TRUE);
420 if (editor->priv->data_key_combo) {
421 gtk_widget_set_sensitive (editor->priv->data_key_combo, merge != NULL);
424 if (editor->priv->data_key_radio) {
425 gtk_widget_set_sensitive (editor->priv->data_key_radio, merge != NULL);
427 gtk_toggle_button_set_active (
428 GTK_TOGGLE_BUTTON(editor->priv->data_literal_radio), TRUE);
432 fixed_flag = editor->priv->data_format_fixed_flag;
433 if (editor->priv->data_format_label) {
434 gtk_widget_set_sensitive (editor->priv->data_format_label,
437 if (editor->priv->data_ex_label) {
438 gtk_widget_set_sensitive (editor->priv->data_ex_label,
441 if (editor->priv->data_digits_label) {
442 gtk_widget_set_sensitive (editor->priv->data_digits_label,
443 (merge != NULL) && !fixed_flag);
445 if (editor->priv->data_digits_spin) {
446 gtk_widget_set_sensitive (editor->priv->data_digits_spin,
447 (merge != NULL) && !fixed_flag);
450 if (editor->priv->fill_page_vbox) {
451 gtk_widget_set_sensitive (editor->priv->fill_key_radio, merge != NULL);
453 gtk_toggle_button_set_active (
454 GTK_TOGGLE_BUTTON(editor->priv->fill_color_radio), TRUE);
455 gtk_widget_set_sensitive (editor->priv->fill_color_combo, TRUE);
456 gtk_widget_set_sensitive (editor->priv->fill_key_combo, FALSE);
458 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(editor->priv->fill_key_radio));
459 gtk_widget_set_sensitive (editor->priv->fill_color_combo, !state);
460 gtk_widget_set_sensitive (editor->priv->fill_key_combo, state);
465 if (editor->priv->line_page_vbox) {
466 gtk_widget_set_sensitive (editor->priv->line_key_radio, merge != NULL);
468 gtk_toggle_button_set_active (
469 GTK_TOGGLE_BUTTON(editor->priv->line_color_radio), TRUE);
470 gtk_widget_set_sensitive (editor->priv->line_color_combo, TRUE);
471 gtk_widget_set_sensitive (editor->priv->line_key_combo, FALSE);
473 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(editor->priv->line_key_radio));
474 gtk_widget_set_sensitive (editor->priv->line_color_combo, !state);
475 gtk_widget_set_sensitive (editor->priv->line_key_combo, state);
480 if (editor->priv->bc_page_vbox) {
481 gtk_widget_set_sensitive (editor->priv->bc_key_radio, merge != NULL);
483 gtk_toggle_button_set_active (
484 GTK_TOGGLE_BUTTON(editor->priv->bc_color_radio), TRUE);
485 gtk_widget_set_sensitive (editor->priv->bc_color_combo, TRUE);
486 gtk_widget_set_sensitive (editor->priv->bc_key_combo, FALSE);
488 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(editor->priv->bc_key_radio));
489 gtk_widget_set_sensitive (editor->priv->bc_color_combo, !state);
490 gtk_widget_set_sensitive (editor->priv->bc_key_combo, state);
495 if (editor->priv->shadow_page_vbox) {
496 gtk_widget_set_sensitive (editor->priv->shadow_key_radio, merge != NULL);
498 gtk_toggle_button_set_active (
499 GTK_TOGGLE_BUTTON(editor->priv->shadow_color_radio), TRUE);
500 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, TRUE);
501 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, FALSE);
503 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(editor->priv->shadow_key_radio));
504 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, !state);
505 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, state);
510 keys = gl_merge_get_key_list (merge);
511 if ( keys == NULL ) {
512 keys = g_list_append (keys, g_strdup (""));
515 combo = editor->priv->img_key_combo;
517 gl_util_combo_box_set_strings (GTK_COMBO_BOX (combo), keys);
520 menu = editor->priv->edit_insert_field_menu;
522 gl_wdgt_merge_menu_set_fields (GL_WDGT_MERGE_MENU(menu), keys);
525 combo = editor->priv->data_key_combo;
527 gl_util_combo_box_set_strings (GTK_COMBO_BOX (combo), keys);
530 combo = editor->priv->fill_key_combo;
532 gl_util_combo_box_set_strings (GTK_COMBO_BOX (combo), keys);
535 combo = editor->priv->text_color_key_combo;
537 gl_util_combo_box_set_strings (GTK_COMBO_BOX (combo), keys);
540 combo = editor->priv->line_key_combo;
542 gl_util_combo_box_set_strings (GTK_COMBO_BOX (combo), keys);
545 combo = editor->priv->bc_key_combo;
547 gl_util_combo_box_set_strings (GTK_COMBO_BOX (combo), keys);
550 combo = editor->priv->shadow_key_combo;
552 gl_util_combo_box_set_strings (GTK_COMBO_BOX (combo), keys);
555 gl_merge_free_key_list (&keys);
557 gl_debug (DEBUG_EDITOR, "END");
560 /*****************************************************************************/
561 /* Construct color combo "Custom widget". */
562 /*****************************************************************************/
564 gl_object_editor_construct_color_combo (gchar *name,
570 GtkWidget *color_combo;
577 color = GL_COLOR_SHADOW_DEFAULT;
578 no_color = _("Default");
582 color = gl_prefs->default_text_color;
583 no_color = _("Default");
587 color = gl_prefs->default_line_color;
588 no_color = _("No line");
593 color = gl_prefs->default_fill_color;
594 no_color = _("No fill");
599 color_combo = gl_color_combo_new (NULL, no_color, color, color);
601 gl_color_combo_set_relief (GL_COLOR_COMBO(color_combo), GTK_RELIEF_NORMAL);
606 /*****************************************************************************/
607 /* Construct chain button "Custom widget". */
608 /*****************************************************************************/
610 gl_object_editor_construct_chain_button (gchar *name,
616 GtkWidget *chain_button;
618 chain_button = gl_wdgt_chain_button_new (GL_WDGT_CHAIN_RIGHT);
619 gl_wdgt_chain_button_set_active (GL_WDGT_CHAIN_BUTTON(chain_button), TRUE);
624 /*--------------------------------------------------------------------------*/
625 /* PRIVATE. Prefs changed callback. Update units related items. */
626 /*--------------------------------------------------------------------------*/
628 prefs_changed_cb (glObjectEditor *editor)
631 gl_debug (DEBUG_EDITOR, "START");
633 if (editor->priv->lsize_r_spin) {
634 lsize_prefs_changed_cb (editor);
637 if (editor->priv->size_w_spin) {
638 size_prefs_changed_cb (editor);
641 if (editor->priv->pos_x_spin) {
642 position_prefs_changed_cb (editor);
645 if (editor->priv->shadow_x_spin) {
646 shadow_prefs_changed_cb (editor);
649 gl_debug (DEBUG_EDITOR, "END");
652 /*---------------------------------------------------------------------------*/
653 /* PRIVATE. label "changed" callback. */
654 /*---------------------------------------------------------------------------*/
656 label_changed_cb (glLabel *label,
657 glObjectEditor *editor)
659 gdouble label_width, label_height;
662 gl_debug (DEBUG_EDITOR, "START");
664 gl_label_get_size (label, &label_width, &label_height);
665 gl_object_editor_set_max_position (GL_OBJECT_EDITOR (editor),
666 label_width, label_height);
667 gl_object_editor_set_max_size (GL_OBJECT_EDITOR (editor),
668 label_width, label_height);
669 gl_object_editor_set_max_lsize (GL_OBJECT_EDITOR (editor),
670 label_width, label_height);
671 gl_object_editor_set_max_shadow_offset (GL_OBJECT_EDITOR (editor),
672 label_width, label_height);
674 merge = gl_label_get_merge (label);
675 gl_object_editor_set_key_names (editor, merge);
677 gl_debug (DEBUG_EDITOR, "END");