]> git.sur5r.net Git - glabels/commitdiff
- View now tracks label resize events.
authorJim Evins <evins@snaught.com>
Mon, 30 Jun 2003 01:34:46 +0000 (01:34 +0000)
committerJim Evins <evins@snaught.com>
Mon, 30 Jun 2003 01:34:46 +0000 (01:34 +0000)
- 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
glabels2/src/label.c
glabels2/src/label.h
glabels2/src/template.c
glabels2/src/template.h
glabels2/src/view.c
glabels2/src/wdgt-print-copies.c
glabels2/src/wdgt-print-merge.c
glabels2/src/xml-template.c

index cebbda0b287e742613b636d701c4340d4d165ea8..ee07bbb9dd9ed8ea357fc9d978099ab500c9610c 100644 (file)
@@ -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);
 
index 8d4a16f779d7020de362646adbc5c415fa26f9f8..1f75df3e4537e4a2cef91b1c31c9bbec661813a4 100644 (file)
@@ -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");
 }
index 6d639e102bbd7da94dffe021fa106db849f726d8..b225fee5171c3c308238cd30bd226ec266682bc4 100644 (file)
@@ -61,6 +61,8 @@ struct _glLabelClass {
 
        void (*merge_changed)    (glLabel *label, gpointer user_data);
 
+       void (*size_changed)     (glLabel *label, gpointer user_data);
+
 };
 
 
index 474762d09b6499a8b66b49415bb696b0c947cede..22ef2af802144b0023f4cd6642554c0d82642852 100644 (file)
@@ -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;
index 68b2e823bd6118514891a292c4f52a4c5326eb8f..c70a186f8002cb122618b351513278a35ff26a2a 100644 (file)
@@ -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);
 
index 13e563882d6353b357161bf26aa33d0fccf434be..eb1e3f36e4d6e96660f891da26448ccfd07b5d32 100644 (file)
@@ -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));
 }
 
 /*---------------------------------------------------------------------------*/
index 0f8fe09be1661afcda9dca855cd42c74ebab6562..2e2f960eed5a4e000ad3dc1d4723d9099ed399e6 100644 (file)
@@ -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);
index e082ecc98c486a60e5e1967d0bfac4b286bd69a0..f635baa64354569fd399e83c46769fa1d48be79f 100644 (file)
@@ -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);
index ac00dbb573e5071cbc6aca2afcca34b095d6030f..fc897fa237334fec99535209c0c36e229245d86c 100644 (file)
@@ -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");