]> git.sur5r.net Git - glabels/commitdiff
Added text box support.
authorJim Evins <evins@snaught.com>
Tue, 7 Jan 2003 07:05:55 +0000 (07:05 +0000)
committerJim Evins <evins@snaught.com>
Tue, 7 Jan 2003 07:05:55 +0000 (07:05 +0000)
git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@242 f5e0f49d-192f-0410-a22d-a8d8700d0965

glabels2/src/label-object.c
glabels2/src/label-text.c
glabels2/src/label-text.h
glabels2/src/view-text.c
glabels2/src/xml-label.c

index dd825e7110b5c68278d8d592b499b3c962253ce6..f7d529e639a52a79705d7c051a7afe4876e08ed3 100644 (file)
@@ -70,6 +70,14 @@ static void gl_label_object_finalize      (GObject            *object);
 static void merge_changed_cb              (glLabel            *label,
                                           glLabelObject      *object);
 
+static void set_size                      (glLabelObject      *object,
+                                          gdouble             w,
+                                          gdouble             h);
+
+static void get_size                      (glLabelObject      *object,
+                                          gdouble            *w,
+                                          gdouble            *h);
+
 \f
 /*****************************************************************************/
 /* Boilerplate object stuff.                                                 */
@@ -102,17 +110,21 @@ gl_label_object_get_type (void)
 static void
 gl_label_object_class_init (glLabelObjectClass *klass)
 {
-       GObjectClass *object_class = (GObjectClass *) klass;
+       GObjectClass       *gobject_class = (GObjectClass *) klass;
+       glLabelObjectClass *object_class  = (glLabelObjectClass *) klass;
 
        gl_debug (DEBUG_LABEL, "START");
 
        parent_class = g_type_class_peek_parent (klass);
 
-       object_class->finalize = gl_label_object_finalize;
+       gobject_class->finalize = gl_label_object_finalize;
+
+       object_class->set_size = set_size;
+       object_class->get_size = get_size;
 
        signals[CHANGED] =
                g_signal_new ("changed",
-                             G_OBJECT_CLASS_TYPE (object_class),
+                             G_OBJECT_CLASS_TYPE (gobject_class),
                              G_SIGNAL_RUN_LAST,
                              G_STRUCT_OFFSET (glLabelObjectClass, changed),
                              NULL, NULL,
@@ -122,7 +134,7 @@ gl_label_object_class_init (glLabelObjectClass *klass)
 
        signals[MOVED] =
                g_signal_new ("moved",
-                             G_OBJECT_CLASS_TYPE (object_class),
+                             G_OBJECT_CLASS_TYPE (gobject_class),
                              G_SIGNAL_RUN_LAST,
                              G_STRUCT_OFFSET (glLabelObjectClass, moved),
                              NULL, NULL,
@@ -131,7 +143,7 @@ gl_label_object_class_init (glLabelObjectClass *klass)
                              2, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
        signals[FLIP_ROTATE] =
                g_signal_new ("flip_rotate",
-                             G_OBJECT_CLASS_TYPE (object_class),
+                             G_OBJECT_CLASS_TYPE (gobject_class),
                              G_SIGNAL_RUN_LAST,
                              G_STRUCT_OFFSET (glLabelObjectClass, flip_rotate),
                              NULL, NULL,
@@ -140,7 +152,7 @@ gl_label_object_class_init (glLabelObjectClass *klass)
                              0);
        signals[TOP] =
                g_signal_new ("top",
-                             G_OBJECT_CLASS_TYPE (object_class),
+                             G_OBJECT_CLASS_TYPE (gobject_class),
                              G_SIGNAL_RUN_LAST,
                              G_STRUCT_OFFSET (glLabelObjectClass, top),
                              NULL, NULL,
@@ -150,7 +162,7 @@ gl_label_object_class_init (glLabelObjectClass *klass)
 
        signals[BOTTOM] =
                g_signal_new ("bottom",
-                             G_OBJECT_CLASS_TYPE (object_class),
+                             G_OBJECT_CLASS_TYPE (gobject_class),
                              G_SIGNAL_RUN_LAST,
                              G_STRUCT_OFFSET (glLabelObjectClass, bottom),
                              NULL, NULL,
@@ -415,6 +427,20 @@ gl_label_object_get_position (glLabelObject *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+/*---------------------------------------------------------------------------*/
+/* PRIVATE.  Default set size method.                                        */
+/*---------------------------------------------------------------------------*/
+static void
+set_size (glLabelObject *object,
+         gdouble        w,
+         gdouble        h)
+{
+       g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
+
+       object->private->w = w;
+       object->private->h = h;
+}
+
 /*****************************************************************************/
 /* Set size of object.                                                       */
 /*****************************************************************************/
@@ -434,8 +460,8 @@ gl_label_object_set_size (glLabelObject *object,
 
        } else {
 
-               object->private->w = w;
-               object->private->h = h;
+               set_size (object, w, h);
+
        }
 
        g_signal_emit (G_OBJECT(object), signals[CHANGED], 0);
@@ -443,6 +469,20 @@ gl_label_object_set_size (glLabelObject *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+/*---------------------------------------------------------------------------*/
+/* PRIVATE.  Default get size method.                                        */
+/*---------------------------------------------------------------------------*/
+static void
+get_size (glLabelObject *object,
+         gdouble       *w,
+         gdouble       *h)
+{
+       g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
+
+       *w = object->private->w;
+       *h = object->private->h;
+}
+
 /*****************************************************************************/
 /* Get size of object.                                                       */
 /*****************************************************************************/
@@ -462,8 +502,8 @@ gl_label_object_get_size (glLabelObject *object,
 
        } else {
 
-               *w = object->private->w;
-               *h = object->private->h;
+               get_size (object, w, h);
+
        }
 
        gl_debug (DEBUG_LABEL, "END");
index 0be52cb37cb1ba81c97a32d376abeaf7cdc3e1c7..d60c2295ffa098e07388b281843b8dfbc89dd3eb 100644 (file)
@@ -60,7 +60,7 @@ struct _glLabelTextPrivate {
 /* Private globals.                                       */
 /*========================================================*/
 
-static GObjectClass *parent_class = NULL;
+static glLabelObjectClass *parent_class = NULL;
 
 static guint instance = 0;
 
@@ -332,6 +332,17 @@ gl_label_text_get_props (glLabelText      *ltext,
        gl_debug (DEBUG_LABEL, "just = %d", *just);
 }
 
+void
+gl_label_text_get_box (glLabelText *ltext,
+                      gdouble     *w,
+                      gdouble     *h)
+{
+       g_return_if_fail (ltext && GL_IS_LABEL_TEXT (ltext));
+
+       /* peek at the parent size. */
+       (* parent_class->get_size) (GL_LABEL_OBJECT(ltext), w, h);
+}
+
 /*---------------------------------------------------------------------------*/
 /* PRIVATE.  text buffer "changed" callback.                                 */
 /*---------------------------------------------------------------------------*/
@@ -358,11 +369,14 @@ get_size (glLabelObject *object,
        GnomeGlyphList *glyphlist;
        ArtDRect        bbox;
        gdouble         affine[6];
+       gdouble         w_parent, h_parent;
 
        gl_debug (DEBUG_LABEL, "START");
 
        g_return_if_fail (ltext && GL_IS_LABEL_TEXT (ltext));
 
+       (* parent_class->get_size) (object, &w_parent, &h_parent);
+
        font = gnome_font_find_closest_from_weight_slant (
                ltext->private->font_family,
                ltext->private->font_weight,
@@ -393,6 +407,11 @@ get_size (glLabelObject *object,
 
        }
 
+       if ( *h == 0.0 ) *h = ltext->private->font_size;
+
+       if ( *w < w_parent ) *w = w_parent;
+       if ( *h < h_parent ) *h = h_parent;
+
        g_strfreev (line);
 
        gl_debug (DEBUG_LABEL, "END");
index 2b5b36b590136375ddf9d55ef6ad4ee8465948c5..f26acce91fa9a91a678d07890bfa967452c51188 100644 (file)
@@ -75,6 +75,9 @@ void           gl_label_text_get_props    (glLabelText      *ltext,
                                           gboolean         *font_italic_flag,
                                           guint            *color,
                                           GtkJustification *just);
+void           gl_label_text_get_box      (glLabelText      *ltext,
+                                          gdouble          *w,
+                                          gdouble          *h);
 
 G_END_DECLS
 
index 58d04873d191916f3865d2f10d6e288fa901a1f8..a9d17c1fe95f300ad549c29aecf4a6d1a15a2f58 100644 (file)
@@ -217,7 +217,7 @@ gl_view_text_new (glLabelText *object,
        gl_view_object_set_view (GL_VIEW_OBJECT(view_text), view);
        gl_view_object_set_object (GL_VIEW_OBJECT(view_text),
                                   GL_LABEL_OBJECT(object),
-                                  GL_VIEW_HIGHLIGHT_SIMPLE);
+                                  GL_VIEW_HIGHLIGHT_BOX_RESIZABLE);
 
        group = gl_view_object_get_group (GL_VIEW_OBJECT(view_text));
 
index e7cb46a06ead3f1c76452348c402aa20e7622436..5f1edce719a3d893851b782893253a5104b184d8 100644 (file)
@@ -421,6 +421,7 @@ xml_parse_text_props (xmlNodePtr  object_node,
 {
        GObject          *object;
        GList            *lines;
+       gdouble           w, h;
        gchar            *font_family;
        gdouble           font_size;
        GnomeFontWeight   font_weight;
@@ -436,6 +437,9 @@ xml_parse_text_props (xmlNodePtr  object_node,
 
        object = gl_label_text_new (label);
 
+       w = gl_xml_get_prop_double (object_node, "w", 0);
+       h = gl_xml_get_prop_double (object_node, "h", 0);
+
        font_family = xmlGetProp (object_node, "font_family");
 
        font_size = gl_xml_get_prop_double (object_node, "font_size", 0.0);
@@ -490,11 +494,12 @@ xml_parse_text_props (xmlNodePtr  object_node,
 
        }
 
-       gl_label_text_set_lines (GL_LABEL_TEXT(object), lines);
-       gl_label_text_set_props (GL_LABEL_TEXT(object),
-                                font_family, font_size, font_weight,
-                                font_italic_flag,
-                                color, just);
+       gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
+       gl_label_text_set_lines  (GL_LABEL_TEXT(object), lines);
+       gl_label_text_set_props  (GL_LABEL_TEXT(object),
+                                 font_family, font_size, font_weight,
+                                 font_italic_flag,
+                                 color, just);
 
        gl_text_node_lines_free (&lines);
        g_free (font_family);
@@ -994,6 +999,7 @@ xml_create_text_props (xmlNodePtr     object_node,
 {
        xmlNodePtr        line_node, field_node, literal_node;
        GList            *lines;
+       gdouble           w, h;
        gchar            *font_family;
        gdouble           font_size;
        GnomeFontWeight   font_weight;
@@ -1008,12 +1014,20 @@ xml_create_text_props (xmlNodePtr     object_node,
 
        xmlSetProp (object_node, "type", "Text");
 
+       gl_label_text_get_box ( GL_LABEL_TEXT(object), &w, &h);
        lines = gl_label_text_get_lines (GL_LABEL_TEXT(object));
        gl_label_text_get_props (GL_LABEL_TEXT(object),
                                 &font_family, &font_size, &font_weight,
                                 &font_italic_flag,
                                 &color, &just);
 
+       string = g_strdup_printf ("%g", w);
+       xmlSetProp (object_node, "w", string);
+       g_free (string);
+       string = g_strdup_printf ("%g", h);
+       xmlSetProp (object_node, "h", string);
+       g_free (string);
+
        xmlSetProp (object_node, "font_family", font_family);
        string = g_strdup_printf ("%g", font_size);
        xmlSetProp (object_node, "font_size", string);