From 1282b07f72de900661dc4b3d8d11efca5a314b00 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Wed, 25 Sep 2002 03:13:22 +0000 Subject: [PATCH] view_text and view_barcode dialogs now track changes to label's merge properties. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@133 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/src/label-object.c | 19 +++++++ glabels2/src/label.c | 11 ++++ glabels2/src/label.h | 2 + glabels2/src/view-barcode.c | 26 +++++----- glabels2/src/view-text.c | 2 + glabels2/src/wdgt-bc-data.c | 91 ++++++++++++++++++++++++++++++---- glabels2/src/wdgt-bc-data.h | 1 + glabels2/src/wdgt-text-entry.c | 43 ++++++++++++---- glabels2/src/wdgt-text-entry.h | 16 +++--- 9 files changed, 174 insertions(+), 37 deletions(-) diff --git a/glabels2/src/label-object.c b/glabels2/src/label-object.c index 76eaa670..4499b57b 100644 --- a/glabels2/src/label-object.c +++ b/glabels2/src/label-object.c @@ -63,6 +63,9 @@ static void gl_label_object_class_init (glLabelObjectClass *klass); static void gl_label_object_instance_init (glLabelObject *object); static void gl_label_object_finalize (GObject *object); +static void merge_changed_cb (glLabel *label, + glLabelObject *object); + /*****************************************************************************/ /* Boilerplate object stuff. */ @@ -223,10 +226,16 @@ gl_label_object_set_parent (glLabelObject *object, old_parent = object->parent; if ( old_parent != NULL ) { + g_signal_handlers_disconnect_by_func (old_parent, + G_CALLBACK(merge_changed_cb), + object); gl_label_remove_object( old_parent, object ); } gl_label_add_object( label, object ); + g_signal_connect (G_OBJECT(label), "merge_changed", + G_CALLBACK(merge_changed_cb), object); + g_signal_emit (G_OBJECT(object), signals[CHANGED], 0); gl_debug (DEBUG_LABEL, "END"); @@ -424,3 +433,13 @@ gl_label_object_lower_to_bottom (glLabelObject *object) gl_debug (DEBUG_LABEL, "END"); } +/*--------------------------------------------------------------------------*/ +/* PRIVATE. Label's merge data changed callback. */ +/*--------------------------------------------------------------------------*/ +static void +merge_changed_cb (glLabel *label, + glLabelObject *object) +{ + gl_label_object_emit_changed (object); +} + diff --git a/glabels2/src/label.c b/glabels2/src/label.c index f857ef3d..498dc526 100644 --- a/glabels2/src/label.c +++ b/glabels2/src/label.c @@ -62,6 +62,7 @@ enum { CHANGED, NAME_CHANGED, MODIFIED_CHANGED, + MERGE_CHANGED, LAST_SIGNAL }; @@ -158,6 +159,15 @@ gl_label_class_init (glLabelClass *klass) gl_marshal_VOID__VOID, G_TYPE_NONE, 0); + signals[MERGE_CHANGED] = + g_signal_new ("merge_changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (glLabelClass, merge_changed), + NULL, NULL, + gl_marshal_VOID__VOID, + G_TYPE_NONE, + 0); gl_debug (DEBUG_LABEL, "END"); } @@ -501,6 +511,7 @@ gl_label_set_merge (glLabel *label, label->private->modified_flag = TRUE; + g_signal_emit (G_OBJECT(label), signals[MERGE_CHANGED], 0); g_signal_emit (G_OBJECT(label), signals[MODIFIED_CHANGED], 0); g_signal_emit (G_OBJECT(label), signals[CHANGED], 0); diff --git a/glabels2/src/label.h b/glabels2/src/label.h index 3924de14..fbf4688c 100644 --- a/glabels2/src/label.h +++ b/glabels2/src/label.h @@ -58,6 +58,8 @@ struct _glLabelClass { void (*modified_changed) (glLabel *label, gpointer user_data); + void (*merge_changed) (glLabel *label, gpointer user_data); + }; diff --git a/glabels2/src/view-barcode.c b/glabels2/src/view-barcode.c index aad1f2af..6d2441e7 100644 --- a/glabels2/src/view-barcode.c +++ b/glabels2/src/view-barcode.c @@ -310,6 +310,18 @@ construct_properties_dialog (glViewBarcode *view_barcode) wsection = gl_hig_category_new (_("Properties")); gl_hig_dialog_add_widget (GL_HIG_DIALOG(dialog), wsection); + /* Barcode style widget */ + view_barcode->private->bc_style = gl_wdgt_bc_style_new (); + gl_wdgt_bc_style_set_label_size_group (GL_WDGT_BC_STYLE(view_barcode->private->bc_style), + label_size_group); + gl_wdgt_bc_style_set_params (GL_WDGT_BC_STYLE (view_barcode->private->bc_style), + style, text_flag); + gl_hig_category_add_widget (GL_HIG_CATEGORY(wsection), + view_barcode->private->bc_style); + g_signal_connect (G_OBJECT (view_barcode->private->bc_style), + "changed", G_CALLBACK (bc_style_changed_cb), + view_barcode); + /* barcode props entry */ gl_debug (DEBUG_VIEW, "Creating props entry..."); view_barcode->private->bc_props = gl_wdgt_bc_props_new (); @@ -323,18 +335,6 @@ construct_properties_dialog (glViewBarcode *view_barcode) "changed", G_CALLBACK (bc_props_changed_cb), view_barcode); - /* Barcode style widget */ - view_barcode->private->bc_style = gl_wdgt_bc_style_new (); - gl_wdgt_bc_style_set_label_size_group (GL_WDGT_BC_STYLE(view_barcode->private->bc_style), - label_size_group); - gl_wdgt_bc_style_set_params (GL_WDGT_BC_STYLE (view_barcode->private->bc_style), - style, text_flag); - gl_hig_category_add_widget (GL_HIG_CATEGORY(wsection), - view_barcode->private->bc_style); - g_signal_connect (G_OBJECT (view_barcode->private->bc_style), - "changed", G_CALLBACK (bc_style_changed_cb), - view_barcode); - /*----------------------------*/ /* Position section */ @@ -549,6 +549,8 @@ update_dialog_cb (glLabelObject *object, gl_wdgt_bc_data_set_data (GL_WDGT_BC_DATA(view_barcode->private->bc_data), (merge->type != GL_MERGE_NONE), text_node); + gl_wdgt_bc_data_set_field_defs (GL_WDGT_BC_DATA(view_barcode->private->bc_data), + merge->field_defs); gl_wdgt_bc_props_set_params (GL_WDGT_BC_PROPS(view_barcode->private->bc_props), scale, color); gl_wdgt_bc_style_set_params (GL_WDGT_BC_STYLE(view_barcode->private->bc_style), diff --git a/glabels2/src/view-text.c b/glabels2/src/view-text.c index 638ebad6..2092a23d 100644 --- a/glabels2/src/view-text.c +++ b/glabels2/src/view-text.c @@ -504,6 +504,8 @@ update_dialog_cb (glLabelObject *object, gl_wdgt_text_entry_set_text (GL_WDGT_TEXT_ENTRY(view_text->private->text_entry), (merge->type != GL_MERGE_NONE), lines); + gl_wdgt_text_entry_set_field_defs (GL_WDGT_TEXT_ENTRY(view_text->private->text_entry), + merge->field_defs); gl_wdgt_text_props_set_params (GL_WDGT_TEXT_PROPS(view_text->private->text_props), font_family, font_size, font_weight, font_italic_flag, color, just); diff --git a/glabels2/src/wdgt-bc-data.c b/glabels2/src/wdgt-bc-data.c index 42d3844f..58f6a0ea 100644 --- a/glabels2/src/wdgt-bc-data.c +++ b/glabels2/src/wdgt-bc-data.c @@ -97,6 +97,8 @@ gl_wdgt_bc_data_class_init (glWdgtBCDataClass *class) { GObjectClass *object_class; + gl_debug (DEBUG_WDGT, "START"); + object_class = (GObjectClass *) class; parent_class = g_type_class_peek_parent (class); @@ -112,16 +114,22 @@ gl_wdgt_bc_data_class_init (glWdgtBCDataClass *class) gl_marshal_VOID__VOID, G_TYPE_NONE, 0); + gl_debug (DEBUG_WDGT, "END"); } static void gl_wdgt_bc_data_instance_init (glWdgtBCData *bc_data) { + gl_debug (DEBUG_WDGT, "START"); + bc_data->literal_radio = NULL; bc_data->literal_entry = NULL; bc_data->key_radio = NULL; + bc_data->key_combo = NULL; bc_data->key_entry = NULL; + + gl_debug (DEBUG_WDGT, "END"); } static void @@ -130,12 +138,16 @@ gl_wdgt_bc_data_finalize (GObject *object) glWdgtBCData *bc_data; glWdgtBCDataClass *class; + gl_debug (DEBUG_WDGT, "START"); + g_return_if_fail (object != NULL); g_return_if_fail (GL_IS_WDGT_BC_DATA (object)); bc_data = GL_WDGT_BC_DATA (object); G_OBJECT_CLASS (parent_class)->finalize (object); + + gl_debug (DEBUG_WDGT, "END"); } /****************************************************************************/ @@ -146,10 +158,14 @@ gl_wdgt_bc_data_new (GList *field_defs) { glWdgtBCData *bc_data; + gl_debug (DEBUG_WDGT, "START"); + bc_data = g_object_new (gl_wdgt_bc_data_get_type (), NULL); gl_wdgt_bc_data_construct (bc_data, field_defs); + gl_debug (DEBUG_WDGT, "END"); + return GTK_WIDGET (bc_data); } @@ -160,10 +176,12 @@ static void gl_wdgt_bc_data_construct (glWdgtBCData *bc_data, GList *field_defs) { - GtkWidget *wvbox, *whbox, *wcombo; + GtkWidget *wvbox, *whbox; GSList *radio_group = NULL; GList *keys; + gl_debug (DEBUG_WDGT, "START"); + wvbox = GTK_WIDGET (bc_data); /* ---- Literal line ---- */ @@ -202,18 +220,21 @@ gl_wdgt_bc_data_construct (glWdgtBCData *bc_data, gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), bc_data->key_radio); /* Key entry widget */ - wcombo = gtk_combo_new (); + bc_data->key_combo = gtk_combo_new (); keys = gl_merge_get_key_list (field_defs); if (keys != NULL) - gtk_combo_set_popdown_strings (GTK_COMBO (wcombo), keys); + gtk_combo_set_popdown_strings (GTK_COMBO (bc_data->key_combo), + keys); gl_merge_free_key_list (&keys); - bc_data->key_entry = GTK_COMBO (wcombo)->entry; + bc_data->key_entry = GTK_COMBO (bc_data->key_combo)->entry; gtk_entry_set_editable (GTK_ENTRY (bc_data->key_entry), FALSE); - gtk_widget_set_size_request (wcombo, 200, -1); + gtk_widget_set_size_request (bc_data->key_combo, 200, -1); g_signal_connect_swapped (G_OBJECT (bc_data->key_entry), "changed", G_CALLBACK (changed_cb), G_OBJECT (bc_data)); - gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), wcombo); + gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), bc_data->key_combo); + + gl_debug (DEBUG_WDGT, "END"); } /*--------------------------------------------------------------------------*/ @@ -222,8 +243,12 @@ gl_wdgt_bc_data_construct (glWdgtBCData *bc_data, static void changed_cb (glWdgtBCData *bc_data) { + gl_debug (DEBUG_WDGT, "START"); + /* Emit our "changed" signal */ g_signal_emit (G_OBJECT (bc_data), wdgt_bc_data_signals[CHANGED], 0); + + gl_debug (DEBUG_WDGT, "END"); } /*--------------------------------------------------------------------------*/ @@ -233,19 +258,50 @@ static void radio_toggled_cb (GtkToggleButton *togglebutton, glWdgtBCData *bc_data) { + gl_debug (DEBUG_WDGT, "START"); + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (bc_data->literal_radio))) { gtk_widget_set_sensitive (bc_data->literal_entry, TRUE); - gtk_widget_set_sensitive (bc_data->key_entry, FALSE); + gtk_widget_set_sensitive (bc_data->key_combo, FALSE); } else { gtk_widget_set_sensitive (bc_data->literal_entry, FALSE); - gtk_widget_set_sensitive (bc_data->key_entry, TRUE); + gtk_widget_set_sensitive (bc_data->key_combo, TRUE); } /* Emit our "changed" signal */ g_signal_emit (G_OBJECT (bc_data), wdgt_bc_data_signals[CHANGED], 0); + + gl_debug (DEBUG_WDGT, "END"); } +/****************************************************************************/ +/* Set new field definitions. */ +/****************************************************************************/ +void +gl_wdgt_bc_data_set_field_defs (glWdgtBCData *bc_data, + GList *field_defs) +{ + GList *keys; + + gl_debug (DEBUG_WDGT, "START"); + + keys = gl_merge_get_key_list (field_defs); + if ( keys != NULL ) { + gtk_combo_set_popdown_strings (GTK_COMBO (bc_data->key_combo), + keys); + gl_merge_free_key_list (&keys); + } else { + keys = g_list_append (keys, ""); + gtk_combo_set_popdown_strings (GTK_COMBO (bc_data->key_combo), + keys); + g_list_free (keys); + } + + gl_debug (DEBUG_WDGT, "END"); +} + + /****************************************************************************/ /* Get widget data. */ /****************************************************************************/ @@ -254,6 +310,8 @@ gl_wdgt_bc_data_get_data (glWdgtBCData *bc_data) { glTextNode *text_node; + gl_debug (DEBUG_WDGT, "START"); + text_node = g_new0(glTextNode,1); if (gtk_toggle_button_get_active @@ -267,7 +325,13 @@ gl_wdgt_bc_data_get_data (glWdgtBCData *bc_data) text_node->data = gtk_editable_get_chars (GTK_EDITABLE (bc_data->key_entry), 0, -1); + gl_debug (DEBUG_WDGT, "text_node: field_flag=%d, data=%s", + text_node->field_flag, text_node->data); } + + gl_debug (DEBUG_WDGT, "END"); + + return text_node; } /****************************************************************************/ @@ -280,6 +344,8 @@ gl_wdgt_bc_data_set_data (glWdgtBCData *bc_data, { gint pos; + gl_debug (DEBUG_WDGT, "START"); + gtk_widget_set_sensitive (bc_data->key_radio, merge_flag); if (!text_node->field_flag) { @@ -288,7 +354,7 @@ gl_wdgt_bc_data_set_data (glWdgtBCData *bc_data, (bc_data->literal_radio), TRUE); gtk_widget_set_sensitive (bc_data->literal_entry, TRUE); - gtk_widget_set_sensitive (bc_data->key_entry, FALSE); + gtk_widget_set_sensitive (bc_data->key_combo, FALSE); g_signal_handlers_block_by_func (G_OBJECT (bc_data->literal_entry), @@ -312,7 +378,7 @@ gl_wdgt_bc_data_set_data (glWdgtBCData *bc_data, (bc_data->key_radio), TRUE); gtk_widget_set_sensitive (bc_data->literal_entry, FALSE); - gtk_widget_set_sensitive (bc_data->key_entry, TRUE); + gtk_widget_set_sensitive (bc_data->key_combo, TRUE); g_signal_handlers_block_by_func (G_OBJECT (bc_data->key_entry), @@ -332,6 +398,7 @@ gl_wdgt_bc_data_set_data (glWdgtBCData *bc_data, &pos); } + gl_debug (DEBUG_WDGT, "END"); } /****************************************************************************/ @@ -341,6 +408,10 @@ void gl_wdgt_bc_data_set_label_size_group (glWdgtBCData *bc_data, GtkSizeGroup *label_size_group) { + gl_debug (DEBUG_WDGT, "START"); + gtk_size_group_add_widget (label_size_group, bc_data->literal_radio); gtk_size_group_add_widget (label_size_group, bc_data->key_radio); + + gl_debug (DEBUG_WDGT, "END"); } diff --git a/glabels2/src/wdgt-bc-data.h b/glabels2/src/wdgt-bc-data.h index 909d52f4..06e15126 100644 --- a/glabels2/src/wdgt-bc-data.h +++ b/glabels2/src/wdgt-bc-data.h @@ -49,6 +49,7 @@ struct _glWdgtBCData { GtkWidget *literal_entry; GtkWidget *key_radio; + GtkWidget *key_combo; GtkWidget *key_entry; }; diff --git a/glabels2/src/wdgt-text-entry.c b/glabels2/src/wdgt-text-entry.c index 679f1503..1f445550 100644 --- a/glabels2/src/wdgt-text-entry.c +++ b/glabels2/src/wdgt-text-entry.c @@ -120,8 +120,10 @@ gl_wdgt_text_entry_instance_init (glWdgtTextEntry *text_entry) { gl_debug (DEBUG_WDGT, "START"); - text_entry->text_entry = NULL; - text_entry->key_entry = NULL; + text_entry->text_entry = NULL; + + text_entry->key_combo = NULL; + text_entry->key_entry = NULL; text_entry->insert_button = NULL; gl_debug (DEBUG_WDGT, "END"); @@ -171,7 +173,7 @@ static void gl_wdgt_text_entry_construct (glWdgtTextEntry *text_entry, GList *field_defs) { - GtkWidget *wvbox, *whbox, *wscroll, *wcombo; + GtkWidget *wvbox, *whbox, *wscroll; GList *keys; gl_debug (DEBUG_WDGT, "START"); @@ -213,15 +215,16 @@ gl_wdgt_text_entry_construct (glWdgtTextEntry *text_entry, gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), text_entry->key_label); /* Key entry widget */ - wcombo = gtk_combo_new (); + text_entry->key_combo = gtk_combo_new (); keys = gl_merge_get_key_list (field_defs); if (keys != NULL) - gtk_combo_set_popdown_strings (GTK_COMBO (wcombo), keys); + gtk_combo_set_popdown_strings (GTK_COMBO (text_entry->key_combo), + keys); gl_merge_free_key_list (&keys); - text_entry->key_entry = GTK_COMBO (wcombo)->entry; + text_entry->key_entry = GTK_COMBO (text_entry->key_combo)->entry; gtk_entry_set_editable (GTK_ENTRY (text_entry->key_entry), FALSE); - gtk_widget_set_size_request (wcombo, 200, -1); - gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), wcombo); + gtk_widget_set_size_request (text_entry->key_combo, 200, -1); + gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), text_entry->key_combo); /* Insert button */ text_entry->insert_button = @@ -275,6 +278,28 @@ insert_cb (glWdgtTextEntry *text_entry) gl_debug (DEBUG_WDGT, "END"); } +/****************************************************************************/ +/* Set new field definitions. */ +/****************************************************************************/ +void +gl_wdgt_text_entry_set_field_defs (glWdgtTextEntry *text_entry, + GList *field_defs) +{ + GList *keys; + + keys = gl_merge_get_key_list (field_defs); + if ( keys != NULL ) { + gtk_combo_set_popdown_strings (GTK_COMBO (text_entry->key_combo), + keys); + gl_merge_free_key_list (&keys); + } else { + keys = g_list_append (keys, ""); + gtk_combo_set_popdown_strings (GTK_COMBO (text_entry->key_combo), + keys); + g_list_free (keys); + } +} + /****************************************************************************/ /* Get widget data. */ /****************************************************************************/ @@ -316,7 +341,7 @@ gl_wdgt_text_entry_set_text (glWdgtTextEntry *text_entry, gl_debug (DEBUG_WDGT, "START"); - gtk_widget_set_sensitive (text_entry->key_entry, merge_flag); + gtk_widget_set_sensitive (text_entry->key_combo, merge_flag); gtk_widget_set_sensitive (text_entry->insert_button, merge_flag); text = gl_text_node_lines_expand (lines, NULL); diff --git a/glabels2/src/wdgt-text-entry.h b/glabels2/src/wdgt-text-entry.h index 5be2242a..930b93ca 100644 --- a/glabels2/src/wdgt-text-entry.h +++ b/glabels2/src/wdgt-text-entry.h @@ -49,6 +49,7 @@ struct _glWdgtTextEntry { GtkWidget *text_entry; GtkWidget *key_label; + GtkWidget *key_combo; GtkWidget *key_entry; GtkWidget *insert_button; @@ -61,15 +62,18 @@ struct _glWdgtTextEntryClass { void (*changed) (glWdgtTextEntry * text_entry, gpointer user_data); }; -guint gl_wdgt_text_entry_get_type (void); +guint gl_wdgt_text_entry_get_type (void); -GtkWidget *gl_wdgt_text_entry_new (GList *field_defs); +GtkWidget *gl_wdgt_text_entry_new (GList *field_defs); -GList *gl_wdgt_text_entry_get_text (glWdgtTextEntry *text_entry); +void gl_wdgt_text_entry_set_field_defs (glWdgtTextEntry *text_entry, + GList *field_defs); -void gl_wdgt_text_entry_set_text (glWdgtTextEntry *text_entry, - gboolean merge_flag, - GList *lines); +GList *gl_wdgt_text_entry_get_text (glWdgtTextEntry *text_entry); + +void gl_wdgt_text_entry_set_text (glWdgtTextEntry *text_entry, + gboolean merge_flag, + GList *lines); void gl_wdgt_text_entry_set_label_size_group (glWdgtTextEntry *text_entry, GtkSizeGroup *label_size_group); -- 2.39.5