[gtksourceview] region: turn it into a GObject class
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] region: turn it into a GObject class
- Date: Sat, 2 Apr 2016 13:33:35 +0000 (UTC)
commit b064ffe90ab10d3ac4a25e32f505517119fff0d6
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Apr 2 14:03:38 2016 +0200
region: turn it into a GObject class
To have reference counting, mainly. And the goal is to publicize
GtkSourceRegion, so it's better if it's a GObject.
.../words/gtksourcecompletionwordsbuffer.c | 6 +-
gtksourceview/gtksourcecontextengine.c | 4 +-
gtksourceview/gtksourceregion.c | 379 +++++++++++++-------
gtksourceview/gtksourceregion.h | 22 +-
gtksourceview/gtksourcesearchcontext.c | 50 ++--
testsuite/test-region.c | 4 +-
6 files changed, 292 insertions(+), 173 deletions(-)
---
diff --git a/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.c
b/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.c
index 6a050c6..4ccb7c4 100644
--- a/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.c
+++ b/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.c
@@ -110,7 +110,7 @@ gtk_source_completion_words_buffer_dispose (GObject *object)
if (buffer->priv->scan_region != NULL)
{
- gtk_source_region_destroy (buffer->priv->scan_region);
+ g_object_unref (buffer->priv->scan_region);
buffer->priv->scan_region = NULL;
}
@@ -475,7 +475,7 @@ invalidate_region (GtkSourceCompletionWordsBuffer *buffer,
remove_region = compute_remove_region (buffer, &start_iter, &end_iter);
remove_words_in_region (buffer, remove_region);
- gtk_source_region_destroy (remove_region);
+ g_object_unref (remove_region);
}
static void
@@ -542,7 +542,7 @@ on_delete_range_before_cb (GtkTextBuffer *text_buffer,
{
remove_all_words (buffer);
- gtk_source_region_destroy (buffer->priv->scan_region);
+ g_object_unref (buffer->priv->scan_region);
buffer->priv->scan_region = gtk_source_region_new (text_buffer);
}
else
diff --git a/gtksourceview/gtksourcecontextengine.c b/gtksourceview/gtksourcecontextengine.c
index 007c360..cdd26fa 100644
--- a/gtksourceview/gtksourcecontextengine.c
+++ b/gtksourceview/gtksourcecontextengine.c
@@ -966,7 +966,7 @@ ensure_highlighted (GtkSourceContextEngine *ce,
gtk_source_region_iter_next (®_iter);
}
- gtk_source_region_destroy (region);
+ g_object_unref (region);
/* Remove the just highlighted region. */
gtk_source_region_subtract (ce->priv->refresh_region, start, end);
@@ -2560,7 +2560,7 @@ gtk_source_context_engine_attach_buffer (GtkSourceEngine *engine,
destroy_context_classes_list (ce);
if (ce->priv->refresh_region != NULL)
- gtk_source_region_destroy (ce->priv->refresh_region);
+ g_object_unref (ce->priv->refresh_region);
ce->priv->refresh_region = NULL;
}
diff --git a/gtksourceview/gtksourceregion.c b/gtksourceview/gtksourceregion.c
index 345e357..3d79bc1 100644
--- a/gtksourceview/gtksourceregion.c
+++ b/gtksourceview/gtksourceregion.c
@@ -1,5 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- * gtksourceregion.h - GtkTextMark based region utility functions
+ * gtksourceregion.c - GtkTextMark-based region utility
* This file is part of GtkSourceView
*
* Copyright (C) 2002 Gustavo Giráldez <gustavo giraldez gmx net>
@@ -33,20 +33,26 @@
#define DEBUG(x)
#endif
-typedef struct _Subregion
-{
- GtkTextMark *start;
- GtkTextMark *end;
-} Subregion;
+typedef struct _GtkSourceRegionPrivate GtkSourceRegionPrivate;
+typedef struct _Subregion Subregion;
+typedef struct _GtkSourceRegionIterReal GtkSourceRegionIterReal;
-struct _GtkSourceRegion
+struct _GtkSourceRegionPrivate
{
+ /* Weak pointer to the buffer. */
GtkTextBuffer *buffer;
- GList *subregions;
- guint32 timestamp;
+
+ /* List of sorted 'Subregion*' */
+ GList *subregions;
+
+ guint32 timestamp;
};
-typedef struct _GtkSourceRegionIterReal GtkSourceRegionIterReal;
+struct _Subregion
+{
+ GtkTextMark *start;
+ GtkTextMark *end;
+};
struct _GtkSourceRegionIterReal
{
@@ -55,6 +61,17 @@ struct _GtkSourceRegionIterReal
GList *subregions;
};
+enum
+{
+ PROP_0,
+ PROP_BUFFER,
+ LAST_PROP
+};
+
+static GParamSpec *properties[LAST_PROP];
+
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceRegion, gtk_source_region, G_TYPE_OBJECT)
+
/* Find and return a subregion node which contains the given text
* iter. If left_side is TRUE, return the subregion which contains
* the text iter or which is the leftmost; else return the rightmost
@@ -67,15 +84,15 @@ find_nearest_subregion (GtkSourceRegion *region,
gboolean leftmost,
gboolean include_edges)
{
+ GtkSourceRegionPrivate *priv = gtk_source_region_get_instance_private (region);
GList *retval;
GList *l;
- g_return_val_if_fail (region != NULL, NULL);
- g_return_val_if_fail (iter != NULL, NULL);
+ g_assert (iter != NULL);
if (begin == NULL)
{
- begin = region->subregions;
+ begin = priv->subregions;
}
if (begin != NULL)
@@ -95,7 +112,7 @@ find_nearest_subregion (GtkSourceRegion *region,
if (!leftmost)
{
- gtk_text_buffer_get_iter_at_mark (region->buffer, &sr_iter, sr->end);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, &sr_iter, sr->end);
cmp = gtk_text_iter_compare (iter, &sr_iter);
if (cmp < 0 || (cmp == 0 && include_edges))
{
@@ -106,7 +123,7 @@ find_nearest_subregion (GtkSourceRegion *region,
}
else
{
- gtk_text_buffer_get_iter_at_mark (region->buffer, &sr_iter, sr->start);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, &sr_iter, sr->start);
cmp = gtk_text_iter_compare (iter, &sr_iter);
if (cmp > 0 || (cmp == 0 && include_edges))
{
@@ -122,96 +139,158 @@ find_nearest_subregion (GtkSourceRegion *region,
return retval;
}
-GtkSourceRegion *
-gtk_source_region_new (GtkTextBuffer *buffer)
+static void
+gtk_source_region_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- GtkSourceRegion *region;
+ GtkSourceRegion *region = GTK_SOURCE_REGION (object);
- g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
+ switch (prop_id)
+ {
+ case PROP_BUFFER:
+ g_value_set_object (value, gtk_source_region_get_buffer (region));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
- region = g_slice_new (GtkSourceRegion);
- region->subregions = NULL;
- region->timestamp = 0;
- region->buffer = buffer;
+static void
+gtk_source_region_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkSourceRegionPrivate *priv = gtk_source_region_get_instance_private (GTK_SOURCE_REGION (object));
- g_object_add_weak_pointer (G_OBJECT (buffer),
- (gpointer *)®ion->buffer);
+ switch (prop_id)
+ {
+ case PROP_BUFFER:
+ g_assert (priv->buffer == NULL);
+ priv->buffer = g_value_get_object (value);
+ g_object_add_weak_pointer (G_OBJECT (priv->buffer),
+ (gpointer *) &priv->buffer);
+ break;
- return region;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
-void
-gtk_source_region_destroy (GtkSourceRegion *region)
+static void
+gtk_source_region_dispose (GObject *object)
{
- g_return_if_fail (region != NULL);
+ GtkSourceRegionPrivate *priv = gtk_source_region_get_instance_private (GTK_SOURCE_REGION (object));
- while (region->subregions)
+ while (priv->subregions != NULL)
{
- Subregion *sr = region->subregions->data;
+ Subregion *sr = priv->subregions->data;
- if (region->buffer != NULL)
+ if (priv->buffer != NULL)
{
- gtk_text_buffer_delete_mark (region->buffer, sr->start);
- gtk_text_buffer_delete_mark (region->buffer, sr->end);
+ gtk_text_buffer_delete_mark (priv->buffer, sr->start);
+ gtk_text_buffer_delete_mark (priv->buffer, sr->end);
}
g_slice_free (Subregion, sr);
- region->subregions = g_list_delete_link (region->subregions,
- region->subregions);
+ priv->subregions = g_list_delete_link (priv->subregions, priv->subregions);
}
- if (region->buffer != NULL)
+ if (priv->buffer != NULL)
{
- g_object_remove_weak_pointer (G_OBJECT (region->buffer),
- (gpointer *)®ion->buffer);
+ g_object_remove_weak_pointer (G_OBJECT (priv->buffer),
+ (gpointer *) &priv->buffer);
- region->buffer = NULL;
+ priv->buffer = NULL;
}
- g_slice_free (GtkSourceRegion, region);
+ G_OBJECT_CLASS (gtk_source_region_parent_class)->dispose (object);
+}
+
+static void
+gtk_source_region_class_init (GtkSourceRegionClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = gtk_source_region_get_property;
+ object_class->set_property = gtk_source_region_set_property;
+ object_class->dispose = gtk_source_region_dispose;
+
+ properties[PROP_BUFFER] =
+ g_param_spec_object ("buffer",
+ "Buffer",
+ "",
+ GTK_TYPE_TEXT_BUFFER,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, LAST_PROP, properties);
+}
+
+static void
+gtk_source_region_init (GtkSourceRegion *region)
+{
+}
+
+GtkSourceRegion *
+gtk_source_region_new (GtkTextBuffer *buffer)
+{
+ g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
+
+ return g_object_new (GTK_SOURCE_TYPE_REGION,
+ "buffer", buffer,
+ NULL);
}
GtkTextBuffer *
gtk_source_region_get_buffer (GtkSourceRegion *region)
{
- g_return_val_if_fail (region != NULL, NULL);
+ GtkSourceRegionPrivate *priv;
+
+ g_return_val_if_fail (GTK_SOURCE_IS_REGION (region), NULL);
- return region->buffer;
+ priv = gtk_source_region_get_instance_private (region);
+ return priv->buffer;
}
static void
gtk_source_region_clear_zero_length_subregions (GtkSourceRegion *region)
{
+ GtkSourceRegionPrivate *priv = gtk_source_region_get_instance_private (region);
GList *node;
- g_return_if_fail (region != NULL);
-
- node = region->subregions;
+ node = priv->subregions;
while (node != NULL)
{
Subregion *sr = node->data;
GtkTextIter start;
GtkTextIter end;
- gtk_text_buffer_get_iter_at_mark (region->buffer, &start, sr->start);
- gtk_text_buffer_get_iter_at_mark (region->buffer, &end, sr->end);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, &start, sr->start);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, &end, sr->end);
if (gtk_text_iter_equal (&start, &end))
{
- gtk_text_buffer_delete_mark (region->buffer, sr->start);
- gtk_text_buffer_delete_mark (region->buffer, sr->end);
+ gtk_text_buffer_delete_mark (priv->buffer, sr->start);
+ gtk_text_buffer_delete_mark (priv->buffer, sr->end);
g_slice_free (Subregion, sr);
- if (node == region->subregions)
+ if (node == priv->subregions)
{
- region->subregions = node = g_list_delete_link (node, node);
+ priv->subregions = node = g_list_delete_link (node, node);
}
else
{
node = g_list_delete_link (node, node);
}
- region->timestamp++;
+ priv->timestamp++;
}
else
{
@@ -225,16 +304,19 @@ gtk_source_region_add (GtkSourceRegion *region,
const GtkTextIter *_start,
const GtkTextIter *_end)
{
+ GtkSourceRegionPrivate *priv;
GList *start_node;
GList *end_node;
GtkTextIter start;
GtkTextIter end;
- g_return_if_fail (region != NULL);
+ g_return_if_fail (GTK_SOURCE_IS_REGION (region));
g_return_if_fail (_start != NULL);
g_return_if_fail (_end != NULL);
- if (region->buffer == NULL)
+ priv = gtk_source_region_get_instance_private (region);
+
+ if (priv->buffer == NULL)
{
return;
}
@@ -264,23 +346,23 @@ gtk_source_region_add (GtkSourceRegion *region,
{
/* Create the new subregion. */
Subregion *sr = g_slice_new0 (Subregion);
- sr->start = gtk_text_buffer_create_mark (region->buffer, NULL, &start, TRUE);
- sr->end = gtk_text_buffer_create_mark (region->buffer, NULL, &end, FALSE);
+ sr->start = gtk_text_buffer_create_mark (priv->buffer, NULL, &start, TRUE);
+ sr->end = gtk_text_buffer_create_mark (priv->buffer, NULL, &end, FALSE);
if (start_node == NULL)
{
/* Append the new region. */
- region->subregions = g_list_append (region->subregions, sr);
+ priv->subregions = g_list_append (priv->subregions, sr);
}
else if (end_node == NULL)
{
/* Prepend the new region. */
- region->subregions = g_list_prepend (region->subregions, sr);
+ priv->subregions = g_list_prepend (priv->subregions, sr);
}
else
{
/* We are in the middle of two subregions. */
- region->subregions = g_list_insert_before (region->subregions, start_node, sr);
+ priv->subregions = g_list_insert_before (priv->subregions, start_node, sr);
}
}
else
@@ -294,39 +376,39 @@ gtk_source_region_add (GtkSourceRegion *region,
GList *l = start_node->next;
Subregion *q;
- gtk_text_buffer_delete_mark (region->buffer, sr->end);
+ gtk_text_buffer_delete_mark (priv->buffer, sr->end);
while (l != end_node)
{
q = l->data;
- gtk_text_buffer_delete_mark (region->buffer, q->start);
- gtk_text_buffer_delete_mark (region->buffer, q->end);
+ gtk_text_buffer_delete_mark (priv->buffer, q->start);
+ gtk_text_buffer_delete_mark (priv->buffer, q->end);
g_slice_free (Subregion, q);
l = g_list_delete_link (l, l);
}
q = l->data;
- gtk_text_buffer_delete_mark (region->buffer, q->start);
+ gtk_text_buffer_delete_mark (priv->buffer, q->start);
sr->end = q->end;
g_slice_free (Subregion, q);
l = g_list_delete_link (l, l);
}
/* Now move marks if that action expands the region. */
- gtk_text_buffer_get_iter_at_mark (region->buffer, &iter, sr->start);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, &iter, sr->start);
if (gtk_text_iter_compare (&iter, &start) > 0)
{
- gtk_text_buffer_move_mark (region->buffer, sr->start, &start);
+ gtk_text_buffer_move_mark (priv->buffer, sr->start, &start);
}
- gtk_text_buffer_get_iter_at_mark (region->buffer, &iter, sr->end);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, &iter, sr->end);
if (gtk_text_iter_compare (&iter, &end) < 0)
{
- gtk_text_buffer_move_mark (region->buffer, sr->end, &end);
+ gtk_text_buffer_move_mark (priv->buffer, sr->end, &end);
}
}
- region->timestamp++;
+ priv->timestamp++;
DEBUG (_gtk_source_region_debug_print (region));
}
@@ -336,6 +418,7 @@ gtk_source_region_subtract (GtkSourceRegion *region,
const GtkTextIter *_start,
const GtkTextIter *_end)
{
+ GtkSourceRegionPrivate *priv;
GList *start_node;
GList *end_node;
GList *node;
@@ -348,11 +431,13 @@ gtk_source_region_subtract (GtkSourceRegion *region,
GtkTextIter start;
GtkTextIter end;
- g_return_if_fail (region != NULL);
+ g_return_if_fail (GTK_SOURCE_IS_REGION (region));
g_return_if_fail (_start != NULL);
g_return_if_fail (_end != NULL);
- if (region->buffer == NULL)
+ priv = gtk_source_region_get_instance_private (region);
+
+ if (priv->buffer == NULL)
{
return;
}
@@ -382,8 +467,8 @@ gtk_source_region_subtract (GtkSourceRegion *region,
start_is_outside = end_is_outside = FALSE;
sr = start_node->data;
- gtk_text_buffer_get_iter_at_mark (region->buffer, &sr_start_iter, sr->start);
- gtk_text_buffer_get_iter_at_mark (region->buffer, &sr_end_iter, sr->end);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, &sr_start_iter, sr->start);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, &sr_end_iter, sr->end);
if (gtk_text_iter_in_range (&start, &sr_start_iter, &sr_end_iter) &&
!gtk_text_iter_equal (&start, &sr_start_iter))
@@ -397,14 +482,14 @@ gtk_source_region_subtract (GtkSourceRegion *region,
*/
Subregion *new_sr = g_slice_new0 (Subregion);
new_sr->end = sr->end;
- new_sr->start = gtk_text_buffer_create_mark (region->buffer,
+ new_sr->start = gtk_text_buffer_create_mark (priv->buffer,
NULL,
&end,
TRUE);
start_node = g_list_insert_before (start_node, start_node->next, new_sr);
- sr->end = gtk_text_buffer_create_mark (region->buffer,
+ sr->end = gtk_text_buffer_create_mark (priv->buffer,
NULL,
&start,
FALSE);
@@ -419,7 +504,7 @@ gtk_source_region_subtract (GtkSourceRegion *region,
/* The ending point is outside, so just move
* the end of the subregion to the starting point.
*/
- gtk_text_buffer_move_mark (region->buffer, sr->end, &start);
+ gtk_text_buffer_move_mark (priv->buffer, sr->end, &start);
}
}
else
@@ -436,15 +521,15 @@ gtk_source_region_subtract (GtkSourceRegion *region,
if (start_node != end_node)
{
sr = end_node->data;
- gtk_text_buffer_get_iter_at_mark (region->buffer, &sr_start_iter, sr->start);
- gtk_text_buffer_get_iter_at_mark (region->buffer, &sr_end_iter, sr->end);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, &sr_start_iter, sr->start);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, &sr_end_iter, sr->end);
}
if (gtk_text_iter_in_range (&end, &sr_start_iter, &sr_end_iter) &&
!gtk_text_iter_equal (&end, &sr_end_iter))
{
/* Ending point is inside, move the start mark. */
- gtk_text_buffer_move_mark (region->buffer, sr->start, &end);
+ gtk_text_buffer_move_mark (priv->buffer, sr->start, &end);
}
else
{
@@ -474,16 +559,15 @@ gtk_source_region_subtract (GtkSourceRegion *region,
{
GList *l = node->next;
sr = node->data;
- gtk_text_buffer_delete_mark (region->buffer, sr->start);
- gtk_text_buffer_delete_mark (region->buffer, sr->end);
+ gtk_text_buffer_delete_mark (priv->buffer, sr->start);
+ gtk_text_buffer_delete_mark (priv->buffer, sr->end);
g_slice_free (Subregion, sr);
- region->subregions = g_list_delete_link (region->subregions,
- node);
+ priv->subregions = g_list_delete_link (priv->subregions, node);
node = l;
}
}
- region->timestamp++;
+ priv->timestamp++;
DEBUG (_gtk_source_region_debug_print (region));
@@ -539,26 +623,30 @@ gtk_source_region_get_bounds (GtkSourceRegion *region,
GtkTextIter *start,
GtkTextIter *end)
{
- g_return_val_if_fail (region != NULL, FALSE);
+ GtkSourceRegionPrivate *priv;
+
+ g_return_val_if_fail (GTK_SOURCE_IS_REGION (region), FALSE);
- if (region->buffer == NULL ||
+ priv = gtk_source_region_get_instance_private (region);
+
+ if (priv->buffer == NULL ||
gtk_source_region_is_empty (region))
{
return FALSE;
}
- g_assert (region->subregions != NULL);
+ g_assert (priv->subregions != NULL);
if (start != NULL)
{
- Subregion *first_subregion = region->subregions->data;
- gtk_text_buffer_get_iter_at_mark (region->buffer, start, first_subregion->start);
+ Subregion *first_subregion = priv->subregions->data;
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, start, first_subregion->start);
}
if (end != NULL)
{
- Subregion *last_subregion = g_list_last (region->subregions)->data;
- gtk_text_buffer_get_iter_at_mark (region->buffer, end, last_subregion->end);
+ Subregion *last_subregion = g_list_last (priv->subregions)->data;
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, end, last_subregion->end);
}
return TRUE;
@@ -569,6 +657,9 @@ gtk_source_region_intersect (GtkSourceRegion *region,
const GtkTextIter *_start,
const GtkTextIter *_end)
{
+ GtkSourceRegionPrivate *priv;
+ GtkSourceRegion *new_region;
+ GtkSourceRegionPrivate *new_priv;
GList *start_node;
GList *end_node;
GList *node;
@@ -577,15 +668,16 @@ gtk_source_region_intersect (GtkSourceRegion *region,
Subregion *sr;
Subregion *new_sr;
gboolean done;
- GtkSourceRegion *new_region;
GtkTextIter start;
GtkTextIter end;
- g_return_val_if_fail (region != NULL, NULL);
+ g_return_val_if_fail (GTK_SOURCE_IS_REGION (region), NULL);
g_return_val_if_fail (_start != NULL, NULL);
g_return_val_if_fail (_end != NULL, NULL);
- if (region->buffer == NULL)
+ priv = gtk_source_region_get_instance_private (region);
+
+ if (priv->buffer == NULL)
{
return NULL;
}
@@ -605,20 +697,21 @@ gtk_source_region_intersect (GtkSourceRegion *region,
return NULL;
}
- new_region = gtk_source_region_new (region->buffer);
+ new_region = gtk_source_region_new (priv->buffer);
+ new_priv = gtk_source_region_get_instance_private (new_region);
done = FALSE;
sr = start_node->data;
- gtk_text_buffer_get_iter_at_mark (region->buffer, &sr_start_iter, sr->start);
- gtk_text_buffer_get_iter_at_mark (region->buffer, &sr_end_iter, sr->end);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, &sr_start_iter, sr->start);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, &sr_end_iter, sr->end);
/* Starting node. */
if (gtk_text_iter_in_range (&start, &sr_start_iter, &sr_end_iter))
{
new_sr = g_slice_new0 (Subregion);
- new_region->subregions = g_list_prepend (new_region->subregions, new_sr);
+ new_priv->subregions = g_list_prepend (new_priv->subregions, new_sr);
- new_sr->start = gtk_text_buffer_create_mark (new_region->buffer,
+ new_sr->start = gtk_text_buffer_create_mark (new_priv->buffer,
NULL,
&start,
TRUE);
@@ -629,14 +722,14 @@ gtk_source_region_intersect (GtkSourceRegion *region,
done = TRUE;
if (gtk_text_iter_in_range (&end, &sr_start_iter, &sr_end_iter))
{
- new_sr->end = gtk_text_buffer_create_mark (new_region->buffer,
+ new_sr->end = gtk_text_buffer_create_mark (new_priv->buffer,
NULL,
&end,
FALSE);
}
else
{
- new_sr->end = gtk_text_buffer_create_mark (new_region->buffer,
+ new_sr->end = gtk_text_buffer_create_mark (new_priv->buffer,
NULL,
&sr_end_iter,
FALSE);
@@ -644,7 +737,7 @@ gtk_source_region_intersect (GtkSourceRegion *region,
}
else
{
- new_sr->end = gtk_text_buffer_create_mark (new_region->buffer,
+ new_sr->end = gtk_text_buffer_create_mark (new_priv->buffer,
NULL,
&sr_end_iter,
FALSE);
@@ -666,18 +759,18 @@ gtk_source_region_intersect (GtkSourceRegion *region,
{
/* Copy intermediate subregions verbatim. */
sr = node->data;
- gtk_text_buffer_get_iter_at_mark (region->buffer, &sr_start_iter, sr->start);
- gtk_text_buffer_get_iter_at_mark (region->buffer, &sr_end_iter, sr->end);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, &sr_start_iter, sr->start);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, &sr_end_iter, sr->end);
new_sr = g_slice_new0 (Subregion);
- new_region->subregions = g_list_prepend (new_region->subregions, new_sr);
+ new_priv->subregions = g_list_prepend (new_priv->subregions, new_sr);
- new_sr->start = gtk_text_buffer_create_mark (new_region->buffer,
+ new_sr->start = gtk_text_buffer_create_mark (new_priv->buffer,
NULL,
&sr_start_iter,
TRUE);
- new_sr->end = gtk_text_buffer_create_mark (new_region->buffer,
+ new_sr->end = gtk_text_buffer_create_mark (new_priv->buffer,
NULL,
&sr_end_iter,
FALSE);
@@ -688,70 +781,80 @@ gtk_source_region_intersect (GtkSourceRegion *region,
/* Ending node. */
sr = node->data;
- gtk_text_buffer_get_iter_at_mark (region->buffer, &sr_start_iter, sr->start);
- gtk_text_buffer_get_iter_at_mark (region->buffer, &sr_end_iter, sr->end);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, &sr_start_iter, sr->start);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, &sr_end_iter, sr->end);
new_sr = g_slice_new0 (Subregion);
- new_region->subregions = g_list_prepend (new_region->subregions, new_sr);
+ new_priv->subregions = g_list_prepend (new_priv->subregions, new_sr);
- new_sr->start = gtk_text_buffer_create_mark (new_region->buffer,
+ new_sr->start = gtk_text_buffer_create_mark (new_priv->buffer,
NULL,
&sr_start_iter,
TRUE);
if (gtk_text_iter_in_range (&end, &sr_start_iter, &sr_end_iter))
{
- new_sr->end = gtk_text_buffer_create_mark (new_region->buffer,
+ new_sr->end = gtk_text_buffer_create_mark (new_priv->buffer,
NULL,
&end,
FALSE);
}
else
{
- new_sr->end = gtk_text_buffer_create_mark (new_region->buffer,
+ new_sr->end = gtk_text_buffer_create_mark (new_priv->buffer,
NULL,
&sr_end_iter,
FALSE);
}
}
- new_region->subregions = g_list_reverse (new_region->subregions);
+ new_priv->subregions = g_list_reverse (new_priv->subregions);
return new_region;
}
static gboolean
check_iterator (GtkSourceRegionIterReal *real)
{
- if ((real->region == NULL) ||
- (real->region_timestamp != real->region->timestamp))
+ GtkSourceRegionPrivate *priv;
+
+ if (real->region == NULL)
{
- g_warning ("Invalid iterator: either the iterator "
- "is uninitialized, or the region "
- "has been modified since the iterator "
- "was created.");
+ goto invalid;
+ }
- return FALSE;
+ priv = gtk_source_region_get_instance_private (real->region);
+
+ if (real->region_timestamp == priv->timestamp)
+ {
+ return TRUE;
}
- return TRUE;
+invalid:
+ g_warning ("Invalid GtkSourceRegionIter: either the iterator is "
+ "uninitialized, or the region has been modified since the "
+ "iterator was created.");
+
+ return FALSE;
}
void
gtk_source_region_get_start_region_iter (GtkSourceRegion *region,
GtkSourceRegionIter *iter)
{
+ GtkSourceRegionPrivate *priv;
GtkSourceRegionIterReal *real;
- g_return_if_fail (region != NULL);
+ g_return_if_fail (GTK_SOURCE_IS_REGION (region));
g_return_if_fail (iter != NULL);
+ priv = gtk_source_region_get_instance_private (region);
real = (GtkSourceRegionIterReal *)iter;
- /* region->subregions may be NULL, -> end iter */
+ /* priv->subregions may be NULL, -> end iter */
real->region = region;
- real->subregions = region->subregions;
- real->region_timestamp = region->timestamp;
+ real->subregions = priv->subregions;
+ real->region_timestamp = priv->timestamp;
}
gboolean
@@ -792,6 +895,7 @@ gtk_source_region_iter_get_subregion (GtkSourceRegionIter *iter,
GtkTextIter *end)
{
GtkSourceRegionIterReal *real;
+ GtkSourceRegionPrivate *priv;
Subregion *sr;
g_return_val_if_fail (iter != NULL, FALSE);
@@ -800,22 +904,24 @@ gtk_source_region_iter_get_subregion (GtkSourceRegionIter *iter,
g_return_val_if_fail (check_iterator (real), FALSE);
g_return_val_if_fail (real->subregions != NULL, FALSE);
- if (real->region->buffer == NULL)
+ priv = gtk_source_region_get_instance_private (real->region);
+
+ if (priv->buffer == NULL)
{
return FALSE;
}
- sr = (Subregion*)real->subregions->data;
+ sr = real->subregions->data;
g_return_val_if_fail (sr != NULL, FALSE);
if (start != NULL)
{
- gtk_text_buffer_get_iter_at_mark (real->region->buffer, start, sr->start);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, start, sr->start);
}
if (end != NULL)
{
- gtk_text_buffer_get_iter_at_mark (real->region->buffer, end, sr->end);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, end, sr->end);
}
return TRUE;
@@ -824,25 +930,28 @@ gtk_source_region_iter_get_subregion (GtkSourceRegionIter *iter,
void
_gtk_source_region_debug_print (GtkSourceRegion *region)
{
+ GtkSourceRegionPrivate *priv;
GList *l;
- g_return_if_fail (region != NULL);
+ g_return_if_fail (GTK_SOURCE_IS_REGION (region));
+
+ priv = gtk_source_region_get_instance_private (region);
- if (region->buffer == NULL)
+ if (priv->buffer == NULL)
{
return;
}
g_print ("Subregions: ");
- for (l = region->subregions; l != NULL; l = l->next)
+ for (l = priv->subregions; l != NULL; l = l->next)
{
Subregion *sr = l->data;
GtkTextIter start;
GtkTextIter end;
- gtk_text_buffer_get_iter_at_mark (region->buffer, &start, sr->start);
- gtk_text_buffer_get_iter_at_mark (region->buffer, &end, sr->end);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, &start, sr->start);
+ gtk_text_buffer_get_iter_at_mark (priv->buffer, &end, sr->end);
g_print ("%d-%d ",
gtk_text_iter_get_offset (&start),
diff --git a/gtksourceview/gtksourceregion.h b/gtksourceview/gtksourceregion.h
index 4d73727..ae78d59 100644
--- a/gtksourceview/gtksourceregion.h
+++ b/gtksourceview/gtksourceregion.h
@@ -1,5 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- * gtksourceregion.h - GtkTextMark based region utility functions
+ * gtksourceregion.h - GtkTextMark-based region utility
* This file is part of GtkSourceView
*
* Copyright (C) 2002 Gustavo Giráldez <gustavo giraldez gmx net>
@@ -28,9 +28,22 @@
G_BEGIN_DECLS
-typedef struct _GtkSourceRegion GtkSourceRegion;
-typedef struct _GtkSourceRegionIter GtkSourceRegionIter;
+#define GTK_SOURCE_TYPE_REGION (gtk_source_region_get_type ())
+GTK_SOURCE_INTERNAL
+G_DECLARE_DERIVABLE_TYPE (GtkSourceRegion, gtk_source_region,
+ GTK_SOURCE, REGION,
+ GObject)
+
+struct _GtkSourceRegionClass
+{
+ GObjectClass parent_class;
+
+ /* Padding for future expansion */
+ gpointer padding[8];
+};
+
+typedef struct _GtkSourceRegionIter GtkSourceRegionIter;
struct _GtkSourceRegionIter
{
/* GtkSourceRegionIter is an opaque datatype; ignore all these fields.
@@ -47,9 +60,6 @@ GTK_SOURCE_INTERNAL
GtkSourceRegion * gtk_source_region_new (GtkTextBuffer *buffer);
GTK_SOURCE_INTERNAL
-void gtk_source_region_destroy (GtkSourceRegion *region);
-
-GTK_SOURCE_INTERNAL
GtkTextBuffer * gtk_source_region_get_buffer (GtkSourceRegion *region);
GTK_SOURCE_INTERNAL
diff --git a/gtksourceview/gtksourcesearchcontext.c b/gtksourceview/gtksourcesearchcontext.c
index 7f32b31..f536891 100644
--- a/gtksourceview/gtksourcesearchcontext.c
+++ b/gtksourceview/gtksourcesearchcontext.c
@@ -500,7 +500,7 @@ clear_task (GtkSourceSearchContext *search)
{
if (search->priv->task_region != NULL)
{
- gtk_source_region_destroy (search->priv->task_region);
+ g_object_unref (search->priv->task_region);
search->priv->task_region = NULL;
}
@@ -523,13 +523,13 @@ clear_search (GtkSourceSearchContext *search)
{
if (search->priv->scan_region != NULL)
{
- gtk_source_region_destroy (search->priv->scan_region);
+ g_object_unref (search->priv->scan_region);
search->priv->scan_region = NULL;
}
if (search->priv->high_priority_region != NULL)
{
- gtk_source_region_destroy (search->priv->high_priority_region);
+ g_object_unref (search->priv->high_priority_region);
search->priv->high_priority_region = NULL;
}
@@ -1025,7 +1025,7 @@ smart_forward_search_async_step (GtkSourceSearchContext *search,
if (region != NULL)
{
- gtk_source_region_destroy (region);
+ g_object_unref (region);
}
while (basic_forward_search (search, &iter, &match_start, &match_end, &limit))
@@ -1069,7 +1069,7 @@ smart_forward_search_async_step (GtkSourceSearchContext *search,
if (search->priv->task_region != NULL)
{
- gtk_source_region_destroy (search->priv->task_region);
+ g_object_unref (search->priv->task_region);
}
search->priv->task_region = region;
@@ -1161,7 +1161,7 @@ smart_backward_search_async_step (GtkSourceSearchContext *search,
if (region != NULL)
{
- gtk_source_region_destroy (region);
+ g_object_unref (region);
}
while (basic_backward_search (search, &iter, &match_start, &match_end, &limit))
@@ -1205,7 +1205,7 @@ smart_backward_search_async_step (GtkSourceSearchContext *search,
if (search->priv->task_region != NULL)
{
- gtk_source_region_destroy (search->priv->task_region);
+ g_object_unref (search->priv->task_region);
}
search->priv->task_region = region;
@@ -1309,7 +1309,7 @@ adjust_subregion (GtkSourceSearchContext *search,
if (region != NULL)
{
- gtk_source_region_destroy (region);
+ g_object_unref (region);
}
}
}
@@ -1362,7 +1362,7 @@ adjust_subregion (GtkSourceSearchContext *search,
if (region != NULL)
{
- gtk_source_region_destroy (region);
+ g_object_unref (region);
}
}
}
@@ -1484,7 +1484,7 @@ remove_occurrences_in_range (GtkSourceSearchContext *search,
if (region != NULL)
{
- gtk_source_region_destroy (region);
+ g_object_unref (region);
}
}
@@ -1670,7 +1670,7 @@ resume_task (GtkSourceSearchContext *search)
if (search->priv->task_region != NULL)
{
- gtk_source_region_destroy (search->priv->task_region);
+ g_object_unref (search->priv->task_region);
search->priv->task_region = NULL;
}
@@ -1720,7 +1720,7 @@ idle_scan_normal_search (GtkSourceSearchContext *search)
*/
scan_all_region (search, search->priv->high_priority_region);
- gtk_source_region_destroy (search->priv->high_priority_region);
+ g_object_unref (search->priv->high_priority_region);
search->priv->high_priority_region = NULL;
return G_SOURCE_CONTINUE;
@@ -1742,7 +1742,7 @@ idle_scan_normal_search (GtkSourceSearchContext *search)
if (search->priv->scan_region != NULL)
{
- gtk_source_region_destroy (search->priv->scan_region);
+ g_object_unref (search->priv->scan_region);
search->priv->scan_region = NULL;
}
@@ -1806,7 +1806,7 @@ regex_search_handle_high_priority_region (GtkSourceSearchContext *search)
gtk_source_region_iter_next (®ion_iter);
}
- gtk_source_region_destroy (region);
+ g_object_unref (region);
}
/* Returns TRUE if the segment is finished, and FALSE on partial match. */
@@ -2025,7 +2025,7 @@ idle_scan_regex_search (GtkSourceSearchContext *search)
{
regex_search_handle_high_priority_region (search);
- gtk_source_region_destroy (search->priv->high_priority_region);
+ g_object_unref (search->priv->high_priority_region);
search->priv->high_priority_region = NULL;
return G_SOURCE_CONTINUE;
@@ -2055,7 +2055,7 @@ idle_scan_regex_search (GtkSourceSearchContext *search)
if (search->priv->scan_region != NULL)
{
- gtk_source_region_destroy (search->priv->scan_region);
+ g_object_unref (search->priv->scan_region);
search->priv->scan_region = NULL;
}
@@ -2123,7 +2123,7 @@ smart_forward_search_step (GtkSourceSearchContext *search,
{
if (region != NULL)
{
- gtk_source_region_destroy (region);
+ g_object_unref (region);
}
while (basic_forward_search (search, &iter, match_start, match_end, &limit))
@@ -2152,7 +2152,7 @@ smart_forward_search_step (GtkSourceSearchContext *search,
scan_region_forward (search, region);
}
- gtk_source_region_destroy (region);
+ g_object_unref (region);
return FALSE;
}
@@ -2222,7 +2222,7 @@ smart_backward_search_step (GtkSourceSearchContext *search,
{
if (region != NULL)
{
- gtk_source_region_destroy (region);
+ g_object_unref (region);
}
while (basic_backward_search (search, &iter, match_start, match_end, &limit))
@@ -2251,7 +2251,7 @@ smart_backward_search_step (GtkSourceSearchContext *search,
scan_region_forward (search, region);
}
- gtk_source_region_destroy (region);
+ g_object_unref (region);
return FALSE;
}
@@ -3152,7 +3152,7 @@ gtk_source_search_context_get_occurrence_position (GtkSourceSearchContext *searc
if (region != NULL)
{
- gtk_source_region_destroy (region);
+ g_object_unref (region);
}
if (!empty)
@@ -3192,7 +3192,7 @@ gtk_source_search_context_get_occurrence_position (GtkSourceSearchContext *searc
if (region != NULL)
{
- gtk_source_region_destroy (region);
+ g_object_unref (region);
}
if (!empty)
@@ -3785,7 +3785,7 @@ _gtk_source_search_context_update_highlight (GtkSourceSearchContext *search,
{
if (region_to_highlight != NULL)
{
- gtk_source_region_destroy (region_to_highlight);
+ g_object_unref (region_to_highlight);
}
return;
@@ -3800,7 +3800,7 @@ _gtk_source_search_context_update_highlight (GtkSourceSearchContext *search,
* means that the visible region has changed. So we can
* destroy the old high_priority_region.
*/
- gtk_source_region_destroy (search->priv->high_priority_region);
+ g_object_unref (search->priv->high_priority_region);
}
search->priv->high_priority_region = region_to_highlight;
@@ -3824,6 +3824,6 @@ _gtk_source_search_context_update_highlight (GtkSourceSearchContext *search,
else
{
scan_all_region (search, region_to_highlight);
- gtk_source_region_destroy (region_to_highlight);
+ g_object_unref (region_to_highlight);
}
}
diff --git a/testsuite/test-region.c b/testsuite/test-region.c
index 3f5d808..8df4ec9 100644
--- a/testsuite/test-region.c
+++ b/testsuite/test-region.c
@@ -128,7 +128,7 @@ test_region (void)
intersection = gtk_source_region_intersect (region, &iter1, &iter2);
if (intersection) {
_gtk_source_region_debug_print (intersection);
- gtk_source_region_destroy (intersection);
+ g_object_unref (intersection);
} else {
g_print ("no intersection\n");
}
@@ -150,7 +150,7 @@ test_region (void)
g_print ("iterated %u subregions\n", i);
- gtk_source_region_destroy (region);
+ g_object_unref (region);
g_object_unref (buffer);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]