Move GtkTextBuffer sealed attributes to private struct.

This commit is contained in:
Ignacio Casal Quinteiro 2010-07-13 11:23:57 +02:00
parent e42c29ca98
commit a1be4eccb0
3 changed files with 112 additions and 89 deletions

View File

@ -44,7 +44,7 @@
#define GTK_TEXT_BUFFER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBufferPrivate))
typedef struct _GtkTextBufferPrivate GtkTextBufferPrivate;
typedef struct _GtkTextLogAttrCache GtkTextLogAttrCache;
struct _GtkTextBufferPrivate
{
@ -55,6 +55,21 @@ struct _GtkTextBufferPrivate
GtkTargetList *paste_target_list;
GtkTargetEntry *paste_target_entries;
gint n_paste_target_entries;
GtkTextTagTable *tag_table;
GtkTextBTree *btree;
GSList *clipboard_contents_buffers;
GSList *selection_clipboards;
GtkTextLogAttrCache *log_attr_cache;
guint user_action_count;
/* Whether the buffer has been modified since last save */
guint modified : 1;
guint has_selection : 1;
};
@ -608,8 +623,10 @@ gtk_text_buffer_class_init (GtkTextBufferClass *klass)
static void
gtk_text_buffer_init (GtkTextBuffer *buffer)
{
buffer->clipboard_contents_buffers = NULL;
buffer->tag_table = NULL;
buffer->priv = GTK_TEXT_BUFFER_GET_PRIVATE (buffer);
buffer->priv->clipboard_contents_buffers = NULL;
buffer->priv->tag_table = NULL;
/* allow copying of arbiatray stuff in the internal rich text format */
gtk_text_buffer_register_serialize_tagset (buffer, NULL);
@ -618,12 +635,14 @@ gtk_text_buffer_init (GtkTextBuffer *buffer)
static void
set_table (GtkTextBuffer *buffer, GtkTextTagTable *table)
{
g_return_if_fail (buffer->tag_table == NULL);
GtkTextBufferPrivate *priv = buffer->priv;
g_return_if_fail (priv->tag_table == NULL);
if (table)
{
buffer->tag_table = table;
g_object_ref (buffer->tag_table);
priv->tag_table = table;
g_object_ref (priv->tag_table);
_gtk_text_tag_table_add_buffer (table, buffer);
}
}
@ -631,13 +650,15 @@ set_table (GtkTextBuffer *buffer, GtkTextTagTable *table)
static GtkTextTagTable*
get_table (GtkTextBuffer *buffer)
{
if (buffer->tag_table == NULL)
GtkTextBufferPrivate *priv = buffer->priv;
if (priv->tag_table == NULL)
{
buffer->tag_table = gtk_text_tag_table_new ();
_gtk_text_tag_table_add_buffer (buffer->tag_table, buffer);
priv->tag_table = gtk_text_tag_table_new ();
_gtk_text_tag_table_add_buffer (priv->tag_table, buffer);
}
return buffer->tag_table;
return priv->tag_table;
}
static void
@ -698,7 +719,7 @@ gtk_text_buffer_get_property (GObject *object,
}
case PROP_HAS_SELECTION:
g_value_set_boolean (value, text_buffer->has_selection);
g_value_set_boolean (value, text_buffer->priv->has_selection);
break;
case PROP_CURSOR_POSITION:
@ -754,28 +775,30 @@ static void
gtk_text_buffer_finalize (GObject *object)
{
GtkTextBuffer *buffer;
GtkTextBufferPrivate *priv;
buffer = GTK_TEXT_BUFFER (object);
priv = buffer->priv;
remove_all_selection_clipboards (buffer);
if (buffer->tag_table)
if (priv->tag_table)
{
_gtk_text_tag_table_remove_buffer (buffer->tag_table, buffer);
g_object_unref (buffer->tag_table);
buffer->tag_table = NULL;
_gtk_text_tag_table_remove_buffer (priv->tag_table, buffer);
g_object_unref (priv->tag_table);
priv->tag_table = NULL;
}
if (buffer->btree)
if (priv->btree)
{
_gtk_text_btree_unref (buffer->btree);
buffer->btree = NULL;
_gtk_text_btree_unref (priv->btree);
priv->btree = NULL;
}
if (buffer->log_attr_cache)
free_log_attr_cache (buffer->log_attr_cache);
if (priv->log_attr_cache)
free_log_attr_cache (priv->log_attr_cache);
buffer->log_attr_cache = NULL;
priv->log_attr_cache = NULL;
gtk_text_buffer_free_target_lists (buffer);
@ -785,11 +808,13 @@ gtk_text_buffer_finalize (GObject *object)
static GtkTextBTree*
get_btree (GtkTextBuffer *buffer)
{
if (buffer->btree == NULL)
buffer->btree = _gtk_text_btree_new (gtk_text_buffer_get_tag_table (buffer),
buffer);
GtkTextBufferPrivate *priv = buffer->priv;
return buffer->btree;
if (priv->btree == NULL)
priv->btree = _gtk_text_btree_new (gtk_text_buffer_get_tag_table (buffer),
buffer);
return priv->btree;
}
GtkTextBTree*
@ -1398,8 +1423,8 @@ gtk_text_buffer_insert_range (GtkTextBuffer *buffer,
g_return_if_fail (end != NULL);
g_return_if_fail (gtk_text_iter_get_buffer (start) ==
gtk_text_iter_get_buffer (end));
g_return_if_fail (gtk_text_iter_get_buffer (start)->tag_table ==
buffer->tag_table);
g_return_if_fail (gtk_text_iter_get_buffer (start)->priv->tag_table ==
buffer->priv->tag_table);
g_return_if_fail (gtk_text_iter_get_buffer (iter) == buffer);
gtk_text_buffer_real_insert_range (buffer, iter, start, end, FALSE);
@ -1434,8 +1459,8 @@ gtk_text_buffer_insert_range_interactive (GtkTextBuffer *buffer,
g_return_val_if_fail (end != NULL, FALSE);
g_return_val_if_fail (gtk_text_iter_get_buffer (start) ==
gtk_text_iter_get_buffer (end), FALSE);
g_return_val_if_fail (gtk_text_iter_get_buffer (start)->tag_table ==
buffer->tag_table, FALSE);
g_return_val_if_fail (gtk_text_iter_get_buffer (start)->priv->tag_table ==
buffer->priv->tag_table, FALSE);
if (gtk_text_iter_can_insert (iter, default_editable))
{
@ -1545,7 +1570,7 @@ gtk_text_buffer_insert_with_tags_by_name (GtkTextBuffer *buffer,
{
GtkTextTag *tag;
tag = gtk_text_tag_table_lookup (buffer->tag_table,
tag = gtk_text_tag_table_lookup (buffer->priv->tag_table,
tag_name);
if (tag == NULL)
@ -1585,9 +1610,9 @@ gtk_text_buffer_real_delete_range (GtkTextBuffer *buffer,
update_selection_clipboards (buffer);
has_selection = gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL);
if (has_selection != buffer->has_selection)
if (has_selection != buffer->priv->has_selection)
{
buffer->has_selection = has_selection;
buffer->priv->has_selection = has_selection;
g_object_notify (G_OBJECT (buffer), "has-selection");
}
@ -2481,7 +2506,7 @@ gtk_text_buffer_real_apply_tag (GtkTextBuffer *buffer,
const GtkTextIter *start,
const GtkTextIter *end)
{
if (tag->table != buffer->tag_table)
if (tag->table != buffer->priv->tag_table)
{
g_warning ("Can only apply tags that are in the tag table for the buffer");
return;
@ -2496,7 +2521,7 @@ gtk_text_buffer_real_remove_tag (GtkTextBuffer *buffer,
const GtkTextIter *start,
const GtkTextIter *end)
{
if (tag->table != buffer->tag_table)
if (tag->table != buffer->priv->tag_table)
{
g_warning ("Can only remove tags that are in the tag table for the buffer");
return;
@ -2530,9 +2555,9 @@ gtk_text_buffer_real_mark_set (GtkTextBuffer *buffer,
NULL,
NULL);
if (has_selection != buffer->has_selection)
if (has_selection != buffer->priv->has_selection)
{
buffer->has_selection = has_selection;
buffer->priv->has_selection = has_selection;
g_object_notify (G_OBJECT (buffer), "has-selection");
}
}
@ -2588,7 +2613,7 @@ gtk_text_buffer_apply_tag (GtkTextBuffer *buffer,
g_return_if_fail (end != NULL);
g_return_if_fail (gtk_text_iter_get_buffer (start) == buffer);
g_return_if_fail (gtk_text_iter_get_buffer (end) == buffer);
g_return_if_fail (tag->table == buffer->tag_table);
g_return_if_fail (tag->table == buffer->priv->tag_table);
gtk_text_buffer_emit_tag (buffer, tag, TRUE, start, end);
}
@ -2617,7 +2642,7 @@ gtk_text_buffer_remove_tag (GtkTextBuffer *buffer,
g_return_if_fail (end != NULL);
g_return_if_fail (gtk_text_iter_get_buffer (start) == buffer);
g_return_if_fail (gtk_text_iter_get_buffer (end) == buffer);
g_return_if_fail (tag->table == buffer->tag_table);
g_return_if_fail (tag->table == buffer->priv->tag_table);
gtk_text_buffer_emit_tag (buffer, tag, FALSE, start, end);
}
@ -2999,7 +3024,7 @@ gtk_text_buffer_get_modified (GtkTextBuffer *buffer)
{
g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
return buffer->modified;
return buffer->priv->modified;
}
/**
@ -3023,11 +3048,11 @@ gtk_text_buffer_set_modified (GtkTextBuffer *buffer,
fixed_setting = setting != FALSE;
if (buffer->modified == fixed_setting)
if (buffer->priv->modified == fixed_setting)
return;
else
{
buffer->modified = fixed_setting;
buffer->priv->modified = fixed_setting;
g_signal_emit (buffer, signals[MODIFIED_CHANGED], 0);
}
}
@ -3047,7 +3072,7 @@ gtk_text_buffer_get_has_selection (GtkTextBuffer *buffer)
{
g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
return buffer->has_selection;
return buffer->priv->has_selection;
}
@ -3594,9 +3619,9 @@ static void
update_selection_clipboards (GtkTextBuffer *buffer)
{
GtkTextBufferPrivate *priv;
GSList *tmp_list = buffer->selection_clipboards;
GSList *tmp_list = buffer->priv->selection_clipboards;
priv = GTK_TEXT_BUFFER_GET_PRIVATE (buffer);
priv = buffer->priv;
gtk_text_buffer_get_copy_target_list (buffer);
@ -3638,7 +3663,7 @@ static SelectionClipboard *
find_selection_clipboard (GtkTextBuffer *buffer,
GtkClipboard *clipboard)
{
GSList *tmp_list = buffer->selection_clipboards;
GSList *tmp_list = buffer->priv->selection_clipboards;
while (tmp_list)
{
SelectionClipboard *selection_clipboard = tmp_list->data;
@ -3681,7 +3706,8 @@ gtk_text_buffer_add_selection_clipboard (GtkTextBuffer *buffer,
selection_clipboard->clipboard = clipboard;
selection_clipboard->ref_count = 1;
buffer->selection_clipboards = g_slist_prepend (buffer->selection_clipboards, selection_clipboard);
buffer->priv->selection_clipboards = g_slist_prepend (buffer->priv->selection_clipboards,
selection_clipboard);
}
}
@ -3712,8 +3738,8 @@ gtk_text_buffer_remove_selection_clipboard (GtkTextBuffer *buffer,
if (gtk_clipboard_get_owner (selection_clipboard->clipboard) == G_OBJECT (buffer))
gtk_clipboard_clear (selection_clipboard->clipboard);
buffer->selection_clipboards = g_slist_remove (buffer->selection_clipboards,
selection_clipboard);
buffer->priv->selection_clipboards = g_slist_remove (buffer->priv->selection_clipboards,
selection_clipboard);
g_free (selection_clipboard);
}
@ -3722,9 +3748,11 @@ gtk_text_buffer_remove_selection_clipboard (GtkTextBuffer *buffer,
static void
remove_all_selection_clipboards (GtkTextBuffer *buffer)
{
g_slist_foreach (buffer->selection_clipboards, (GFunc)g_free, NULL);
g_slist_free (buffer->selection_clipboards);
buffer->selection_clipboards = NULL;
GtkTextBufferPrivate *priv = buffer->priv;
g_slist_foreach (priv->selection_clipboards, (GFunc)g_free, NULL);
g_slist_free (priv->selection_clipboards);
priv->selection_clipboards = NULL;
}
/**
@ -3933,7 +3961,7 @@ cut_or_copy (GtkTextBuffer *buffer,
GtkTextIter start;
GtkTextIter end;
priv = GTK_TEXT_BUFFER_GET_PRIVATE (buffer);
priv = buffer->priv;
gtk_text_buffer_get_copy_target_list (buffer);
@ -4070,9 +4098,9 @@ gtk_text_buffer_begin_user_action (GtkTextBuffer *buffer)
{
g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
buffer->user_action_count += 1;
buffer->priv->user_action_count += 1;
if (buffer->user_action_count == 1)
if (buffer->priv->user_action_count == 1)
{
/* Outermost nested user action begin emits the signal */
g_signal_emit (buffer, signals[BEGIN_USER_ACTION], 0);
@ -4090,11 +4118,11 @@ void
gtk_text_buffer_end_user_action (GtkTextBuffer *buffer)
{
g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
g_return_if_fail (buffer->user_action_count > 0);
g_return_if_fail (buffer->priv->user_action_count > 0);
buffer->user_action_count -= 1;
buffer->priv->user_action_count -= 1;
if (buffer->user_action_count == 0)
if (buffer->priv->user_action_count == 0)
{
/* Ended the outermost-nested user action end, so emit the signal */
g_signal_emit (buffer, signals[END_USER_ACTION], 0);
@ -4104,7 +4132,7 @@ gtk_text_buffer_end_user_action (GtkTextBuffer *buffer)
static void
gtk_text_buffer_free_target_lists (GtkTextBuffer *buffer)
{
GtkTextBufferPrivate *priv = GTK_TEXT_BUFFER_GET_PRIVATE (buffer);
GtkTextBufferPrivate *priv = buffer->priv;
if (priv->copy_target_list)
{
@ -4178,7 +4206,7 @@ gtk_text_buffer_get_copy_target_list (GtkTextBuffer *buffer)
g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
priv = GTK_TEXT_BUFFER_GET_PRIVATE (buffer);
priv = buffer->priv;
if (! priv->copy_target_list)
priv->copy_target_list =
@ -4210,7 +4238,7 @@ gtk_text_buffer_get_paste_target_list (GtkTextBuffer *buffer)
g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
priv = GTK_TEXT_BUFFER_GET_PRIVATE (buffer);
priv = buffer->priv;
if (! priv->paste_target_list)
priv->paste_target_list =
@ -4312,6 +4340,7 @@ _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer *buffer,
const GtkTextIter *anywhere_in_line,
gint *char_len)
{
GtkTextBufferPrivate *priv;
gint line;
GtkTextLogAttrCache *cache;
gint i;
@ -4319,6 +4348,8 @@ _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer *buffer,
g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
g_return_val_if_fail (anywhere_in_line != NULL, NULL);
priv = buffer->priv;
/* special-case for empty last line in buffer */
if (gtk_text_iter_is_end (anywhere_in_line) &&
gtk_text_iter_get_line_offset (anywhere_in_line) == 0)
@ -4332,19 +4363,19 @@ _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer *buffer,
* the start of a paragraph changes
*/
if (buffer->log_attr_cache == NULL)
if (priv->log_attr_cache == NULL)
{
buffer->log_attr_cache = g_new0 (GtkTextLogAttrCache, 1);
buffer->log_attr_cache->chars_changed_stamp =
priv->log_attr_cache = g_new0 (GtkTextLogAttrCache, 1);
priv->log_attr_cache->chars_changed_stamp =
_gtk_text_btree_get_chars_changed_stamp (get_btree (buffer));
}
else if (buffer->log_attr_cache->chars_changed_stamp !=
else if (priv->log_attr_cache->chars_changed_stamp !=
_gtk_text_btree_get_chars_changed_stamp (get_btree (buffer)))
{
clear_log_attr_cache (buffer->log_attr_cache);
clear_log_attr_cache (priv->log_attr_cache);
}
cache = buffer->log_attr_cache;
cache = priv->log_attr_cache;
line = gtk_text_iter_get_line (anywhere_in_line);
i = 0;
@ -4385,8 +4416,8 @@ _gtk_text_buffer_notify_will_remove_tag (GtkTextBuffer *buffer,
* code messing things up at this point; the tag MUST be removed
* entirely.
*/
if (buffer->btree)
_gtk_text_btree_notify_will_remove_tag (buffer->btree, tag);
if (buffer->priv->btree)
_gtk_text_btree_notify_will_remove_tag (buffer->priv->btree, tag);
}
/*

View File

@ -60,8 +60,6 @@ typedef enum
typedef struct _GtkTextBTree GtkTextBTree;
typedef struct _GtkTextLogAttrCache GtkTextLogAttrCache;
#define GTK_TYPE_TEXT_BUFFER (gtk_text_buffer_get_type ())
#define GTK_TEXT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBuffer))
#define GTK_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
@ -69,26 +67,14 @@ typedef struct _GtkTextLogAttrCache GtkTextLogAttrCache;
#define GTK_IS_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_BUFFER))
#define GTK_TEXT_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
typedef struct _GtkTextBufferPrivate GtkTextBufferPrivate;
typedef struct _GtkTextBufferClass GtkTextBufferClass;
struct _GtkTextBuffer
{
GObject parent_instance;
GtkTextTagTable *GSEAL (tag_table);
GtkTextBTree *GSEAL (btree);
GSList *GSEAL (clipboard_contents_buffers);
GSList *GSEAL (selection_clipboards);
GtkTextLogAttrCache *GSEAL (log_attr_cache);
guint GSEAL (user_action_count);
/* Whether the buffer has been modified since last save */
guint GSEAL (modified) : 1;
guint GSEAL (has_selection) : 1;
GtkTextBufferPrivate *priv;
};
struct _GtkTextBufferClass

View File

@ -997,8 +997,11 @@ tag_exists (GMarkupParseContext *context,
ParseInfo *info,
GError **error)
{
GtkTextTagTable *tag_table;
const gchar *real_name;
tag_table = gtk_text_buffer_get_tag_table (info->buffer);
if (info->create_tags)
{
/* If we have an anonymous tag, just return it directly */
@ -1010,11 +1013,11 @@ tag_exists (GMarkupParseContext *context,
real_name = g_hash_table_lookup (info->substitutions, name);
if (real_name)
return gtk_text_tag_table_lookup (info->buffer->tag_table, real_name);
return gtk_text_tag_table_lookup (tag_table, real_name);
/* Next, try the list of defined tags */
if (g_hash_table_lookup (info->defined_tags, name) != NULL)
return gtk_text_tag_table_lookup (info->buffer->tag_table, name);
return gtk_text_tag_table_lookup (tag_table, name);
set_error (error, context,
G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
@ -1034,7 +1037,7 @@ tag_exists (GMarkupParseContext *context,
return NULL;
}
tag = gtk_text_tag_table_lookup (info->buffer->tag_table, name);
tag = gtk_text_tag_table_lookup (tag_table, name);
if (tag)
return tag;
@ -1225,6 +1228,7 @@ static gchar *
get_tag_name (ParseInfo *info,
const gchar *tag_name)
{
GtkTextTagTable *tag_table;
gchar *name;
gint i;
@ -1234,8 +1238,9 @@ get_tag_name (ParseInfo *info,
return name;
i = 0;
tag_table = gtk_text_buffer_get_tag_table (info->buffer);
while (gtk_text_tag_table_lookup (info->buffer->tag_table, name) != NULL)
while (gtk_text_tag_table_lookup (tag_table, name) != NULL)
{
g_free (name);
name = g_strdup_printf ("%s-%d", tag_name, ++i);
@ -1454,7 +1459,8 @@ end_element_handler (GMarkupParseContext *context,
TextTagPrio *prio = list->data;
if (info->create_tags)
gtk_text_tag_table_add (info->buffer->tag_table, prio->tag);
gtk_text_tag_table_add (gtk_text_buffer_get_tag_table (info->buffer),
prio->tag);
g_object_unref (prio->tag);
prio->tag = NULL;