]> git.sur5r.net Git - glabels/commitdiff
glLabelText now uses a GtkTextBuffer to store text, in preparation for editing of...
authorJim Evins <evins@snaught.com>
Sat, 28 Dec 2002 07:39:06 +0000 (07:39 +0000)
committerJim Evins <evins@snaught.com>
Sat, 28 Dec 2002 07:39:06 +0000 (07:39 +0000)
git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@227 f5e0f49d-192f-0410-a22d-a8d8700d0965

glabels2/src/label-text.c
glabels2/src/label-text.h
glabels2/src/view-text.c
glabels2/src/wdgt-text-entry.c
glabels2/src/wdgt-text-entry.h

index 240507d2194fad657035b15911ab4e48aaf8adef..0be52cb37cb1ba81c97a32d376abeaf7cdc3e1c7 100644 (file)
@@ -45,7 +45,9 @@
 /*========================================================*/
 
 struct _glLabelTextPrivate {
-       GList           *lines; /* list of glLabelTextNode lists */
+       GtkTextTagTable *tag_table;
+       GtkTextBuffer   *buffer;
+
        gchar           *font_family;
        gdouble          font_size;
        GnomeFontWeight  font_weight;
@@ -73,6 +75,9 @@ static void gl_label_text_finalize      (GObject          *object);
 static void copy                        (glLabelObject    *dst_object,
                                         glLabelObject    *src_object);
 
+static void buffer_changed_cb           (GtkTextBuffer    *textbuffer,
+                                        glLabelText      *ltext);
+
 static void get_size                    (glLabelObject    *object,
                                         gdouble          *w,
                                         gdouble          *h);
@@ -125,12 +130,18 @@ gl_label_text_instance_init (glLabelText *ltext)
 {
        ltext->private = g_new0 (glLabelTextPrivate, 1);
 
+       ltext->private->tag_table        = gtk_text_tag_table_new ();
+       ltext->private->buffer           = gtk_text_buffer_new (ltext->private->tag_table);
+
        ltext->private->font_family      = g_strdup(DEFAULT_FONT_FAMILY);
        ltext->private->font_size        = DEFAULT_FONT_SIZE;
        ltext->private->font_weight      = DEFAULT_FONT_WEIGHT;
        ltext->private->font_italic_flag = DEFAULT_FONT_ITALIC_FLAG;
        ltext->private->just             = DEFAULT_JUST;
        ltext->private->color            = DEFAULT_COLOR;
+
+       g_signal_connect (G_OBJECT(ltext->private->buffer), "changed",
+                         G_CALLBACK(buffer_changed_cb), ltext);
 }
 
 static void
@@ -142,6 +153,8 @@ gl_label_text_finalize (GObject *object)
 
        ltext = GL_LABEL_TEXT (object);
 
+       g_object_unref (ltext->private->tag_table);
+       g_object_unref (ltext->private->buffer);
        g_free (ltext->private);
 
        G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -210,14 +223,15 @@ void
 gl_label_text_set_lines (glLabelText *ltext,
                         GList       *lines)
 {
+       gchar *text;
+
        gl_debug (DEBUG_LABEL, "START");
 
        g_return_if_fail (ltext && GL_IS_LABEL_TEXT (ltext));
 
-       gl_text_node_lines_free (&ltext->private->lines);
-       ltext->private->lines = gl_text_node_lines_dup (lines);
-
-       gl_label_object_emit_changed (GL_LABEL_OBJECT(ltext));
+       text = gl_text_node_lines_expand (lines, NULL);
+       gtk_text_buffer_set_text (ltext->private->buffer, text, -1);
+       g_free (text);
 
        gl_debug (DEBUG_LABEL, "END");
 }
@@ -271,12 +285,30 @@ gl_label_text_set_props (glLabelText     *ltext,
 /*****************************************************************************/
 /* Get object params.                                                        */
 /*****************************************************************************/
+GtkTextBuffer *
+gl_label_text_get_buffer (glLabelText *ltext)
+{
+       g_return_val_if_fail (ltext && GL_IS_LABEL_TEXT (ltext), NULL);
+
+       return ltext->private->buffer;
+}
+
 GList *
 gl_label_text_get_lines (glLabelText *ltext)
 {
+       GtkTextIter  start, end;
+       gchar       *text;
+       GList       *lines;
+
        g_return_val_if_fail (ltext && GL_IS_LABEL_TEXT (ltext), NULL);
 
-       return gl_text_node_lines_dup (ltext->private->lines);
+       gtk_text_buffer_get_bounds (ltext->private->buffer, &start, &end);
+       text = gtk_text_buffer_get_text (ltext->private->buffer,
+                                        &start, &end, FALSE);
+       lines = gl_text_node_lines_new_from_text (text);
+       g_free (text);
+
+       return lines;
 }
 
 void
@@ -300,6 +332,15 @@ gl_label_text_get_props (glLabelText      *ltext,
        gl_debug (DEBUG_LABEL, "just = %d", *just);
 }
 
+/*---------------------------------------------------------------------------*/
+/* PRIVATE.  text buffer "changed" callback.                                 */
+/*---------------------------------------------------------------------------*/
+void buffer_changed_cb (GtkTextBuffer *textbuffer,
+                       glLabelText   *ltext)
+{
+       gl_label_object_emit_changed (GL_LABEL_OBJECT(ltext));
+}
+
 /*---------------------------------------------------------------------------*/
 /* PRIVATE.  get object size method.                                         */
 /*---------------------------------------------------------------------------*/
@@ -310,6 +351,7 @@ get_size (glLabelObject *object,
 {
        glLabelText    *ltext = (glLabelText *)object;
        GnomeFont      *font;
+       GtkTextIter     start, end;
        gchar          *text;
        gchar         **line;
        gint            i;
@@ -327,7 +369,9 @@ get_size (glLabelObject *object,
                ltext->private->font_italic_flag,
                ltext->private->font_size);
 
-       text = gl_text_node_lines_expand (ltext->private->lines, NULL);
+       gtk_text_buffer_get_bounds (ltext->private->buffer, &start, &end);
+       text = gtk_text_buffer_get_text (ltext->private->buffer,
+                                        &start, &end, FALSE);
        line = g_strsplit (text, "\n", -1);
        g_free (text);
 
index f315dd0b2544db4fb3a184ec90effe2ef752132d..2b5b36b590136375ddf9d55ef6ad4ee8465948c5 100644 (file)
@@ -52,28 +52,29 @@ struct _glLabelTextClass {
        glLabelObjectClass    parent_class;
 };
 
-GType         gl_label_text_get_type     (void);
-
-GObject      *gl_label_text_new          (glLabel          *label);
-
-void          gl_label_text_set_lines    (glLabelText      *ltext,
-                                         GList            *lines);
-void          gl_label_text_set_props    (glLabelText      *ltext,
-                                         gchar            *font_family,
-                                         gdouble           font_size,
-                                         GnomeFontWeight   font_weight,
-                                         gboolean          font_italic_flag,
-                                         guint             color,
-                                         GtkJustification  just);
-
-GList        *gl_label_text_get_lines    (glLabelText      *ltext);
-void          gl_label_text_get_props    (glLabelText      *ltext,
-                                         gchar           **font_family,
-                                         gdouble          *font_size,
-                                         GnomeFontWeight  *font_weight,
-                                         gboolean         *font_italic_flag,
-                                         guint            *color,
-                                         GtkJustification *just);
+GType          gl_label_text_get_type     (void);
+
+GObject       *gl_label_text_new          (glLabel          *label);
+
+void           gl_label_text_set_lines    (glLabelText      *ltext,
+                                          GList            *lines);
+void           gl_label_text_set_props    (glLabelText      *ltext,
+                                          gchar            *font_family,
+                                          gdouble           font_size,
+                                          GnomeFontWeight   font_weight,
+                                          gboolean          font_italic_flag,
+                                          guint             color,
+                                          GtkJustification  just);
+
+GtkTextBuffer *gl_label_text_get_buffer   (glLabelText      *ltext);
+GList         *gl_label_text_get_lines    (glLabelText      *ltext);
+void           gl_label_text_get_props    (glLabelText      *ltext,
+                                          gchar           **font_family,
+                                          gdouble          *font_size,
+                                          GnomeFontWeight  *font_weight,
+                                          gboolean         *font_italic_flag,
+                                          guint            *color,
+                                          GtkJustification *just);
 
 G_END_DECLS
 
index f3601a53c93759cbc4e51e1543be5e0c370adbdf..ee80ce6433461603d2d79f3db1bd59f5590965f7 100644 (file)
@@ -85,9 +85,6 @@ static void      response_cb                   (GtkDialog       *dialog,
                                                gint             response,
                                                glViewText      *view_text);
 
-static void      text_entry_changed_cb         (glWdgtTextEntry *text_entry,
-                                               glViewText      *view_text);
-
 static void      text_props_changed_cb         (glWdgtTextProps *text_props,
                                                glViewText      *view_text);
 
@@ -227,27 +224,27 @@ update_view_text_cb (glLabelObject *object,
 static GtkWidget *
 construct_properties_dialog (glViewObject *view_object)
 {
-       glViewText         *view_text = (glViewText *)view_object;
-       GtkWidget          *dialog, *wsection, *wbutton;
-       glLabelObject      *object;
+       glViewText        *view_text = (glViewText *)view_object;
+       GtkWidget         *dialog, *wsection, *wbutton;
+       glLabelObject     *object;
        gdouble            x, y, w, h, label_width, label_height;
-       GList              *lines;
-       gchar              *font_family;
+       GtkTextBuffer     *buffer;
+       gchar             *font_family;
        gdouble            font_size;
        GnomeFontWeight    font_weight;
        gboolean           font_italic_flag;
        guint              color;
        GtkJustification   just;
-       glMerge            *merge;
-       GtkSizeGroup       *label_size_group;
-       GtkWidget          *window;
+       glMerge           *merge;
+       GtkSizeGroup      *label_size_group;
+       GtkWidget         *window;
 
        gl_debug (DEBUG_VIEW, "START");
 
        /* retrieve object and query parameters */
        object = gl_view_object_get_object (GL_VIEW_OBJECT(view_text));
        gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
-       lines = gl_label_text_get_lines(GL_LABEL_TEXT(object));
+       buffer = gl_label_text_get_buffer(GL_LABEL_TEXT(object));
        gl_label_text_get_props (GL_LABEL_TEXT(object),
                                 &font_family, &font_size,
                                 &font_weight, &font_italic_flag,
@@ -282,14 +279,12 @@ construct_properties_dialog (glViewObject *view_object)
                gl_wdgt_text_entry_new (merge);
        gl_wdgt_text_entry_set_label_size_group (GL_WDGT_TEXT_ENTRY(view_text->private->text_entry),
                                                 label_size_group);
-       gl_wdgt_text_entry_set_text (GL_WDGT_TEXT_ENTRY(view_text->private->text_entry),
-                                    (merge != NULL),
-                                    lines);
+       gl_wdgt_text_entry_set_buffer (GL_WDGT_TEXT_ENTRY(view_text->private->text_entry),
+                                      buffer);
+       gl_wdgt_text_entry_set_field_defs (GL_WDGT_TEXT_ENTRY(view_text->private->text_entry),
+                                            merge);
        gl_hig_category_add_widget (GL_HIG_CATEGORY(wsection),
                                    view_text->private->text_entry);
-       g_signal_connect ( G_OBJECT(view_text->private->text_entry),
-                          "changed", G_CALLBACK (text_entry_changed_cb),
-                          view_text);
 
 
        /*---------------------------*/
@@ -377,33 +372,6 @@ response_cb (GtkDialog     *dialog,
        gl_debug (DEBUG_VIEW, "END");
 }
 
-/*---------------------------------------------------------------------------*/
-/* PRIVATE.  text_entry "changed" callback.                                  */
-/*---------------------------------------------------------------------------*/
-static void
-text_entry_changed_cb (glWdgtTextEntry  *text_entry,
-                      glViewText       *view_text)
-{
-       glLabelObject    *object;
-       GList            *lines;
-
-       gl_debug (DEBUG_VIEW, "START");
-
-       object = gl_view_object_get_object (GL_VIEW_OBJECT(view_text));
-
-       lines = gl_wdgt_text_entry_get_text (text_entry);
-
-       g_signal_handlers_block_by_func (G_OBJECT(object),
-                                        update_dialog_cb, view_text);
-       gl_label_text_set_lines (GL_LABEL_TEXT(object), lines);
-       g_signal_handlers_unblock_by_func (G_OBJECT(object),
-                                          update_dialog_cb, view_text);
-
-       gl_text_node_lines_free (&lines);
-
-       gl_debug (DEBUG_VIEW, "END");
-}
-
 /*---------------------------------------------------------------------------*/
 /* PRIVATE.  text_props "changed" callback.                                  */
 /*---------------------------------------------------------------------------*/
@@ -476,7 +444,6 @@ update_dialog_cb (glLabelObject  *object,
                  glViewText     *view_text)
 {
        gdouble            x, y;
-       GList              *lines;
        glMerge            *merge;
        gchar              *font_family;
        gdouble            font_size;
@@ -488,7 +455,6 @@ update_dialog_cb (glLabelObject  *object,
        gl_debug (DEBUG_VIEW, "START");
 
        /* Query properties of object. */
-       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,
@@ -497,8 +463,6 @@ update_dialog_cb (glLabelObject  *object,
        merge = gl_label_get_merge (GL_LABEL(object->parent));
 
        /* Block widget handlers to prevent recursion */
-       g_signal_handlers_block_by_func (G_OBJECT(view_text->private->text_entry),
-                                        text_entry_changed_cb, view_text);
        g_signal_handlers_block_by_func (G_OBJECT(view_text->private->text_props),
                                         text_props_changed_cb, view_text);
        g_signal_handlers_block_by_func (G_OBJECT(view_text->private->position),
@@ -506,9 +470,6 @@ update_dialog_cb (glLabelObject  *object,
 
        /* Update widgets in property dialog */
 
-       gl_wdgt_text_entry_set_text (GL_WDGT_TEXT_ENTRY(view_text->private->text_entry),
-                                    (merge != NULL),
-                                    lines);
        gl_wdgt_text_entry_set_field_defs (GL_WDGT_TEXT_ENTRY(view_text->private->text_entry),
                                           merge);
        gl_wdgt_text_props_set_params (GL_WDGT_TEXT_PROPS(view_text->private->text_props),
@@ -518,15 +479,11 @@ update_dialog_cb (glLabelObject  *object,
                                       x, y);
 
        /* Unblock widget handlers */
-       g_signal_handlers_unblock_by_func (G_OBJECT(view_text->private->text_entry),
-                                          text_entry_changed_cb, view_text);
        g_signal_handlers_unblock_by_func (G_OBJECT(view_text->private->text_props),
                                           text_props_changed_cb, view_text);
        g_signal_handlers_unblock_by_func (G_OBJECT(view_text->private->position),
                                           position_changed_cb, view_text);
 
-       gl_text_node_lines_free (&lines);
-
        gl_debug (DEBUG_VIEW, "END");
 }
 
index cb173b8ece869122fa49f1226823e7ec163d5501..ca498ff9c438d06c6e1d9ee17dfa77742b4325fa 100644 (file)
 /* Private types                             */
 /*===========================================*/
 
-enum {
-       CHANGED,
-       LAST_SIGNAL
-};
-
 typedef void (*glWdgtTextEntrySignal) (GObject * object, gpointer data);
 
 /*===========================================*/
@@ -46,8 +41,6 @@ typedef void (*glWdgtTextEntrySignal) (GObject * object, gpointer data);
 
 static glHigVBoxClass *parent_class;
 
-static gint wdgt_text_entry_signals[LAST_SIGNAL] = { 0 };
-
 /*===========================================*/
 /* Local function prototypes                 */
 /*===========================================*/
@@ -58,7 +51,6 @@ static void gl_wdgt_text_entry_finalize      (GObject              *object);
 static void gl_wdgt_text_entry_construct     (glWdgtTextEntry      *text_entry,
                                              glMerge              *merge);
 
-static void changed_cb (glWdgtTextEntry *text_entry);
 static void insert_cb  (glWdgtTextEntry *text_entry);
 \f
 /****************************************************************************/
@@ -104,14 +96,6 @@ gl_wdgt_text_entry_class_init (glWdgtTextEntryClass * class)
 
        object_class->finalize = gl_wdgt_text_entry_finalize;
 
-       wdgt_text_entry_signals[CHANGED] =
-           g_signal_new ("changed",
-                         G_OBJECT_CLASS_TYPE(object_class),
-                         G_SIGNAL_RUN_LAST,
-                         G_STRUCT_OFFSET (glWdgtTextEntryClass, changed),
-                         NULL, NULL,
-                         gl_marshal_VOID__VOID, G_TYPE_NONE, 0);
-
        gl_debug (DEBUG_WDGT, "END");
 }
 
@@ -201,9 +185,6 @@ gl_wdgt_text_entry_construct (glWdgtTextEntry *text_entry,
                gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_entry->text_entry));
        gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (wscroll),
                                               text_entry->text_entry);
-       g_signal_connect_swapped (G_OBJECT (text_entry->text_buffer),
-                                 "changed", G_CALLBACK (changed_cb),
-                                 G_OBJECT (text_entry));
 
        /* ---- Merge field line ---- */
        whbox = gl_hig_hbox_new ();
@@ -237,21 +218,6 @@ gl_wdgt_text_entry_construct (glWdgtTextEntry *text_entry,
        gl_debug (DEBUG_WDGT, "END");
 }
 
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Callback for when text has changed.                            */
-/*--------------------------------------------------------------------------*/
-static void
-changed_cb (glWdgtTextEntry *text_entry)
-{
-       gl_debug (DEBUG_WDGT, "START");
-
-       /* Emit our "changed" signal */
-       g_signal_emit (G_OBJECT (text_entry),
-                      wdgt_text_entry_signals[CHANGED], 0);
-
-       gl_debug (DEBUG_WDGT, "END");
-}
-
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Callback to insert field into text buffer.                     */
 /*--------------------------------------------------------------------------*/
@@ -288,6 +254,9 @@ gl_wdgt_text_entry_set_field_defs (glWdgtTextEntry *text_entry,
 {
        GList *keys;
 
+       gtk_widget_set_sensitive (text_entry->key_combo, merge != NULL);
+       gtk_widget_set_sensitive (text_entry->insert_button, merge != NULL);
+
        keys = gl_merge_get_key_list (merge);
        if ( keys != NULL ) {
                gtk_combo_set_popdown_strings (GTK_COMBO (text_entry->key_combo),
@@ -302,58 +271,15 @@ gl_wdgt_text_entry_set_field_defs (glWdgtTextEntry *text_entry,
 }
 
 /****************************************************************************/
-/* Get widget data.                                                         */
-/****************************************************************************/
-GList *
-gl_wdgt_text_entry_get_text (glWdgtTextEntry *text_entry)
-{
-       GtkTextBuffer *buffer;
-       gchar *text;
-       GList *lines;
-       GtkTextIter start, end;
-
-       gl_debug (DEBUG_WDGT, "START");
-
-       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_entry->text_entry));
-
-       gtk_text_buffer_get_bounds (buffer, &start, &end);
-
-       text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
-
-       lines = gl_text_node_lines_new_from_text (text);
-
-       g_free (text);
-
-       gl_debug (DEBUG_WDGT, "END");
-
-       return lines;
-}
-
-/****************************************************************************/
-/* Set widget data.                                                         */
+/* Set text buffer                                                          */
 /****************************************************************************/
 void
-gl_wdgt_text_entry_set_text (glWdgtTextEntry *text_entry,
-                            gboolean         merge_flag,
-                            GList           *lines)
+gl_wdgt_text_entry_set_buffer (glWdgtTextEntry *text_entry,
+                              GtkTextBuffer   *buffer)
 {
-       GtkTextBuffer *buffer;
-       gchar *text;
-
-       gl_debug (DEBUG_WDGT, "START");
+       text_entry->text_buffer = buffer;
 
-       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);
-
-       g_signal_handlers_block_by_func (G_OBJECT(text_entry->text_buffer),
-                                        changed_cb, text_entry);
-       gtk_text_buffer_set_text (text_entry->text_buffer, text, -1);
-       g_signal_handlers_unblock_by_func (G_OBJECT(text_entry->text_buffer),
-                                          changed_cb, text_entry);
-
-       gl_debug (DEBUG_WDGT, "END");
+       gtk_text_view_set_buffer (GTK_TEXT_VIEW(text_entry->text_entry), buffer);
 }
 
 /*****************************************************************************/
index c5f513e98a321fd3339c577000d297281e6847bb..d62ba0582c27402cbfa333bad6b4dea661f35b58 100644 (file)
@@ -69,11 +69,8 @@ GtkWidget *gl_wdgt_text_entry_new            (glMerge         *merge);
 void       gl_wdgt_text_entry_set_field_defs (glWdgtTextEntry *text_entry,
                                              glMerge         *merge);
 
-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_buffer     (glWdgtTextEntry *text_entry,
+                                             GtkTextBuffer   *buffer);
 
 void       gl_wdgt_text_entry_set_label_size_group (glWdgtTextEntry *text_entry,
                                                    GtkSizeGroup    *label_size_group);