From 93756b4b8da8dc80900dc8f28499489ef31986b5 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Mon, 30 Jun 2003 01:34:46 +0000 Subject: [PATCH] - View now tracks label resize events. - Template instantiations assume name of actual alias selected. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@267 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/src/file.c | 12 ++++--- glabels2/src/label.c | 39 +++++++++++++++----- glabels2/src/label.h | 2 ++ glabels2/src/template.c | 62 ++++++++++++++++++++++---------- glabels2/src/template.h | 5 ++- glabels2/src/view.c | 30 ++++++++++++++++ glabels2/src/wdgt-print-copies.c | 2 +- glabels2/src/wdgt-print-merge.c | 2 +- glabels2/src/xml-template.c | 16 +++++---- 9 files changed, 127 insertions(+), 43 deletions(-) diff --git a/glabels2/src/file.c b/glabels2/src/file.c index cebbda0b..ee07bbb9 100644 --- a/glabels2/src/file.c +++ b/glabels2/src/file.c @@ -309,22 +309,24 @@ create_properties_dialog_widgets (glHigDialog *dlg, template = gl_label_get_template (label); rotate_flag = gl_label_get_rotate_flag (label); - gl_debug (DEBUG_FILE, "%s, %s", template->page_size, template->name->data); + gl_debug (DEBUG_FILE, "%s, %s", template->page_size, template->name); if (template->page_size != NULL) { gl_wdgt_media_select_set_page_size (GL_WDGT_MEDIA_SELECT (template_entry), template->page_size); } - if (template->name->data != NULL) { + if (template->name != NULL) { + gchar *template_name = gl_template_get_name_with_desc (template); gl_wdgt_media_select_set_name (GL_WDGT_MEDIA_SELECT (template_entry), - template->name->data); + template_name); gl_wdgt_rotate_label_set_template_name (GL_WDGT_ROTATE_LABEL - (rotate_sel), template->name->data); + (rotate_sel), template_name); + g_free (template_name); } else { sheet_name = gl_wdgt_media_select_get_name (GL_WDGT_MEDIA_SELECT (template_entry)); gl_wdgt_rotate_label_set_template_name (GL_WDGT_ROTATE_LABEL - (rotate_sel), sheet_name); + (rotate_sel), sheet_name); } gl_wdgt_rotate_label_set_state (GL_WDGT_ROTATE_LABEL (rotate_sel), rotate_flag); diff --git a/glabels2/src/label.c b/glabels2/src/label.c index 8d4a16f7..1f75df3e 100644 --- a/glabels2/src/label.c +++ b/glabels2/src/label.c @@ -58,6 +58,7 @@ enum { NAME_CHANGED, MODIFIED_CHANGED, MERGE_CHANGED, + SIZE_CHANGED, LAST_SIGNAL }; @@ -163,6 +164,15 @@ gl_label_class_init (glLabelClass *klass) gl_marshal_VOID__VOID, G_TYPE_NONE, 0); + signals[SIZE_CHANGED] = + g_signal_new ("size_changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (glLabelClass, size_changed), + NULL, NULL, + gl_marshal_VOID__VOID, + G_TYPE_NONE, + 0); gl_debug (DEBUG_LABEL, "END"); } @@ -382,13 +392,19 @@ gl_label_set_template (glLabel *label, g_return_if_fail (label && GL_IS_LABEL (label)); - gl_template_free (&label->private->template); - label->private->template = gl_template_dup (template); + if ((label->private->template == NULL) || + (g_strcasecmp (template->name, label->private->template->name) != 0)) { - label->private->modified_flag = TRUE; + gl_template_free (&label->private->template); + label->private->template = gl_template_dup (template); - g_signal_emit (G_OBJECT(label), signals[MODIFIED_CHANGED], 0); - g_signal_emit (G_OBJECT(label), signals[CHANGED], 0); + label->private->modified_flag = TRUE; + + g_signal_emit (G_OBJECT(label), signals[MODIFIED_CHANGED], 0); + g_signal_emit (G_OBJECT(label), signals[SIZE_CHANGED], 0); + g_signal_emit (G_OBJECT(label), signals[CHANGED], 0); + + } gl_debug (DEBUG_LABEL, "END"); } @@ -404,12 +420,17 @@ gl_label_set_rotate_flag (glLabel *label, g_return_if_fail (label && GL_IS_LABEL (label)); - label->private->rotate_flag = rotate_flag; + if (rotate_flag != label->private->rotate_flag) { - label->private->modified_flag = TRUE; + label->private->rotate_flag = rotate_flag; - g_signal_emit (G_OBJECT(label), signals[MODIFIED_CHANGED], 0); - g_signal_emit (G_OBJECT(label), signals[CHANGED], 0); + label->private->modified_flag = TRUE; + + g_signal_emit (G_OBJECT(label), signals[MODIFIED_CHANGED], 0); + g_signal_emit (G_OBJECT(label), signals[SIZE_CHANGED], 0); + g_signal_emit (G_OBJECT(label), signals[CHANGED], 0); + + } gl_debug (DEBUG_LABEL, "END"); } diff --git a/glabels2/src/label.h b/glabels2/src/label.h index 6d639e10..b225fee5 100644 --- a/glabels2/src/label.h +++ b/glabels2/src/label.h @@ -61,6 +61,8 @@ struct _glLabelClass { void (*merge_changed) (glLabel *label, gpointer user_data); + void (*size_changed) (glLabel *label, gpointer user_data); + }; diff --git a/glabels2/src/template.c b/glabels2/src/template.c index 474762d0..22ef2af8 100644 --- a/glabels2/src/template.c +++ b/glabels2/src/template.c @@ -100,7 +100,7 @@ gl_template_init (void) GList * gl_template_get_name_list (const gchar *page_size) { - GList *p_tmplt, *p_name; + GList *p_tmplt, *p_alias; glTemplate *template; gchar *str; GList *names = NULL; @@ -110,10 +110,10 @@ gl_template_get_name_list (const gchar *page_size) for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) { template = (glTemplate *) p_tmplt->data; if (g_strcasecmp (page_size, template->page_size) == 0) { - for (p_name = template->name; p_name != NULL; - p_name = p_name->next) { + for (p_alias = template->alias; p_alias != NULL; + p_alias = p_alias->next) { str = g_strdup_printf("%s: %s", - (gchar *) p_name->data, + (gchar *) p_alias->data, template->description); names = g_list_insert_sorted (names, str, (GCompareFunc)g_strcasecmp); @@ -155,8 +155,8 @@ gl_template_free_name_list (GList **names) glTemplate * gl_template_from_name (const gchar *name) { - GList *p_tmplt, *p_name; - glTemplate *template; + GList *p_tmplt, *p_alias; + glTemplate *template, *new_template; gchar **split_name; gl_debug (DEBUG_TEMPLATE, "START"); @@ -170,12 +170,20 @@ gl_template_from_name (const gchar *name) for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) { template = (glTemplate *) p_tmplt->data; - for (p_name = template->name; p_name != NULL; - p_name = p_name->next) { - if (g_strcasecmp (p_name->data, split_name[0]) == 0) { + for (p_alias = template->alias; p_alias != NULL; + p_alias = p_alias->next) { + if (g_strcasecmp (p_alias->data, split_name[0]) == 0) { + + new_template = gl_template_dup (template); + + /* Use the real name */ + g_free (new_template->name); + new_template->name = g_strdup (split_name[0]); + g_strfreev (split_name); gl_debug (DEBUG_TEMPLATE, "END"); - return gl_template_dup (template); + + return new_template; } } } @@ -186,6 +194,16 @@ gl_template_from_name (const gchar *name) return NULL; } +/*****************************************************************************/ +/* Get name and format with description. */ +/*****************************************************************************/ +gchar * +gl_template_get_name_with_desc (const glTemplate *template) +{ + return g_strdup_printf("%s: %s", template->name, template->description); +} + + /*****************************************************************************/ /* Copy a template. */ /*****************************************************************************/ @@ -200,9 +218,11 @@ glTemplate *gl_template_dup (const glTemplate *orig_template) template = g_new0 (glTemplate,1); - template->name = NULL; - for ( p=orig_template->name; p != NULL; p=p->next ) { - template->name = g_list_append (template->name, + template->name = g_strdup (orig_template->name); + + template->alias = NULL; + for ( p=orig_template->alias; p != NULL; p=p->next ) { + template->alias = g_list_append (template->alias, g_strdup (p->data)); } template->description = g_strdup (orig_template->description); @@ -243,12 +263,15 @@ void gl_template_free (glTemplate **template) if ( *template != NULL ) { - for ( p=(*template)->name; p != NULL; p=p->next ) { + g_free ((*template)->name); + (*template)->name = NULL; + + for ( p=(*template)->alias; p != NULL; p=p->next ) { g_free (p->data); p->data = NULL; } - g_list_free ((*template)->name); - (*template)->name = NULL; + g_list_free ((*template)->alias); + (*template)->alias = NULL; g_free ((*template)->description); (*template)->description = NULL; @@ -292,9 +315,10 @@ template_full_page (const gchar *page_size) template = g_new0 (glTemplate, 1); - template->name = g_list_append (template->name, - g_strdup_printf(_("Generic %s full page"), - page_size)); + template->name = g_strdup_printf (_("Generic %s full page"), page_size); + + template->alias = g_list_append (template->alias, template->name); + template->page_size = g_strdup(page_size); template->page_width = paper->width; template->page_height = paper->height; diff --git a/glabels2/src/template.h b/glabels2/src/template.h index 68b2e823..c70a186f 100644 --- a/glabels2/src/template.h +++ b/glabels2/src/template.h @@ -115,7 +115,7 @@ typedef struct { * Template */ typedef struct { - GList *name; + gchar *name; gchar *description; gchar *page_size; gdouble page_width; @@ -123,6 +123,7 @@ typedef struct { glTemplateLabel label; + GList *alias; } glTemplate; @@ -141,6 +142,8 @@ void gl_template_free_name_list (GList **names); glTemplate *gl_template_from_name (const gchar *name); +gchar *gl_template_get_name_with_desc (const glTemplate *template); + glTemplate *gl_template_dup (const glTemplate *orig); void gl_template_free (glTemplate **template); diff --git a/glabels2/src/view.c b/glabels2/src/view.c index 13e56388..eb1e3f36 100644 --- a/glabels2/src/view.c +++ b/glabels2/src/view.c @@ -109,6 +109,9 @@ static gdouble get_apropriate_scale (gdouble w, gdouble h); static void draw_layers (glView *view); +static void label_resized_cb (glLabel *label, + glView *view); + static void draw_label_layer (glView *view); static void draw_highlight_layer (glView *view); @@ -485,6 +488,33 @@ draw_layers (glView *view) gnome_canvas_item_raise_to_top (GNOME_CANVAS_ITEM(view->fg_group)); gnome_canvas_item_raise_to_top (GNOME_CANVAS_ITEM(view->highlight_group)); + + g_signal_connect (G_OBJECT (view->label), "size_changed", + G_CALLBACK (label_resized_cb), view); +} + +/*---------------------------------------------------------------------------*/ +/* PRIVATE. Handle label resize event. . */ +/*---------------------------------------------------------------------------*/ +static void +label_resized_cb (glLabel *label, + glView *view) +{ + g_return_if_fail (label && GL_IS_LABEL (label)); + g_return_if_fail (view && GL_IS_VIEW (view)); + + gtk_object_destroy (GTK_OBJECT (view->bg_group)); + gtk_object_destroy (GTK_OBJECT (view->grid_group)); + gtk_object_destroy (GTK_OBJECT (view->markup_group)); + gtk_object_destroy (GTK_OBJECT (view->fg_group)); + + draw_bg_fg_layers (view); + draw_grid_layer (view); + draw_markup_layer (view); + + gnome_canvas_item_raise_to_top (GNOME_CANVAS_ITEM(view->label_group)); + gnome_canvas_item_raise_to_top (GNOME_CANVAS_ITEM(view->fg_group)); + gnome_canvas_item_raise_to_top (GNOME_CANVAS_ITEM(view->highlight_group)); } /*---------------------------------------------------------------------------*/ diff --git a/glabels2/src/wdgt-print-copies.c b/glabels2/src/wdgt-print-copies.c index 0f8fe09b..2e2f960e 100644 --- a/glabels2/src/wdgt-print-copies.c +++ b/glabels2/src/wdgt-print-copies.c @@ -164,7 +164,7 @@ gl_wdgt_print_copies_construct (glWdgtPrintCopies *copies, copies->mini_preview = gl_wdgt_mini_preview_new (WDGT_MINI_PREVIEW_HEIGHT, WDGT_MINI_PREVIEW_WIDTH); gl_wdgt_mini_preview_set_label (GL_WDGT_MINI_PREVIEW(copies->mini_preview), - template->name->data); + template->name); gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), copies->mini_preview); wvbox = gl_hig_vbox_new (GL_HIG_VBOX_INNER); diff --git a/glabels2/src/wdgt-print-merge.c b/glabels2/src/wdgt-print-merge.c index e082ecc9..f635baa6 100644 --- a/glabels2/src/wdgt-print-merge.c +++ b/glabels2/src/wdgt-print-merge.c @@ -161,7 +161,7 @@ gl_wdgt_print_merge_construct (glWdgtPrintMerge * merge, merge->mini_preview = gl_wdgt_mini_preview_new (WDGT_MINI_PREVIEW_HEIGHT, WDGT_MINI_PREVIEW_WIDTH); gl_wdgt_mini_preview_set_label( GL_WDGT_MINI_PREVIEW (merge->mini_preview), - template->name->data ); + template->name ); gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), merge->mini_preview); gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(merge->mini_preview), 1, 1); diff --git a/glabels2/src/xml-template.c b/glabels2/src/xml-template.c index ac00dbb5..fc897fa2 100644 --- a/glabels2/src/xml-template.c +++ b/glabels2/src/xml-template.c @@ -140,9 +140,9 @@ gl_xml_template_parse_sheet (xmlNodePtr sheet_node) template = g_new0 (glTemplate, 1); - template->name = g_list_append (template->name, - xmlGetProp (sheet_node, "name")); - gl_debug (DEBUG_TEMPLATE, "Sheet = %s", template->name->data); + template->name = xmlGetProp (sheet_node, "name"); + template->alias = g_list_append (template->alias, g_strdup (template->name)); + gl_debug (DEBUG_TEMPLATE, "Sheet = %s", template->name); template->page_size = xmlGetProp (sheet_node, "size"); if (xmlStrEqual (template->page_size, "Other")) { @@ -350,7 +350,7 @@ xml_parse_alias (xmlNodePtr alias_node, { gl_debug (DEBUG_TEMPLATE, "START"); - template->name = g_list_append (template->name, + template->alias = g_list_append (template->alias, xmlGetProp (alias_node, "name")); gl_debug (DEBUG_TEMPLATE, "END"); @@ -371,7 +371,7 @@ gl_xml_template_add_sheet (const glTemplate *template, node = xmlNewChild (root, ns, "Sheet", NULL); - xmlSetProp (node, "name", template->name->data); + xmlSetProp (node, "name", template->name); xmlSetProp (node, "size", template->page_size); if (xmlStrEqual (template->page_size, "Other")) { @@ -385,8 +385,10 @@ gl_xml_template_add_sheet (const glTemplate *template, xml_add_label (template, node, ns); - for ( p=template->name->next; p != NULL; p=p->next ) { - xml_add_alias( p->data, node, ns ); + for ( p=template->alias; p != NULL; p=p->next ) { + if (!xmlStrEqual (template->name, p->data)) { + xml_add_alias( p->data, node, ns ); + } } gl_debug (DEBUG_TEMPLATE, "END"); -- 2.39.5