/*========================================================*/
struct _glLabelTextPrivate {
- GList *lines; /* list of glLabelTextNode lists */
+ GtkTextTagTable *tag_table;
+ GtkTextBuffer *buffer;
+
gchar *font_family;
gdouble font_size;
GnomeFontWeight font_weight;
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);
{
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
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);
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 (<ext->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");
}
/*****************************************************************************/
/* 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
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. */
/*---------------------------------------------------------------------------*/
{
glLabelText *ltext = (glLabelText *)object;
GnomeFont *font;
+ GtkTextIter start, end;
gchar *text;
gchar **line;
gint i;
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);
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
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);
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,
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);
/*---------------------------*/
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. */
/*---------------------------------------------------------------------------*/
glViewText *view_text)
{
gdouble x, y;
- GList *lines;
glMerge *merge;
gchar *font_family;
gdouble font_size;
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,
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),
/* 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),
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");
}
/* Private types */
/*===========================================*/
-enum {
- CHANGED,
- LAST_SIGNAL
-};
-
typedef void (*glWdgtTextEntrySignal) (GObject * object, gpointer data);
/*===========================================*/
static glHigVBoxClass *parent_class;
-static gint wdgt_text_entry_signals[LAST_SIGNAL] = { 0 };
-
/*===========================================*/
/* Local function prototypes */
/*===========================================*/
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
/****************************************************************************/
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");
}
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 ();
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. */
/*--------------------------------------------------------------------------*/
{
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),
}
/****************************************************************************/
-/* 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);
}
/*****************************************************************************/
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);