/* gtktextmark.c - mark segments
- *
+ *
* Copyright (c) 1994 The Regents of the University of California.
* Copyright (c) 1994-1997 Sun Microsystems, Inc.
* Copyright (c) 2000 Red Hat, Inc.
* California, Sun Microsystems, Inc., and other parties. The
* following terms apply to all files associated with the software
* unless explicitly disclaimed in individual files.
- *
+ *
* The authors hereby grant permission to use, copy, modify,
* distribute, and license this software and its documentation for any
* purpose, provided that existing copyright notices are retained in
* software may be copyrighted by their authors and need not follow
* the licensing terms described here, provided that the new terms are
* clearly indicated on the first page of each file where they apply.
- *
+ *
* IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY
* PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
* DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION,
* OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
- *
+ *
* THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
* foregoing, the authors grant the U.S. Government and others acting
* in its behalf permission to use and distribute the software in
* accordance with the terms specified in this license.
- *
+ *
*/
-
+#define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
#include "gtktextbtree.h"
static void gtk_text_mark_init (GtkTextMark *mark);
0, /* n_preallocs */
(GInstanceInitFunc) gtk_text_mark_init,
};
-
+
object_type = g_type_register_static (G_TYPE_OBJECT,
"GtkTextMark",
- &object_info);
+ &object_info, 0);
}
-
+
return object_type;
}
if (seg)
{
- g_return_if_fail (seg->body.mark.tree == NULL);
-
if (seg->body.mark.tree != NULL)
g_warning ("GtkTextMark being finalized while still in the buffer; "
"someone removed a reference they didn't own! Crash "
"impending");
-
+
g_free (seg->body.mark.name);
g_free (seg);
mark->segment = NULL;
}
+
+ /* chain parent_class' handler */
+ G_OBJECT_CLASS (parent_class)->finalize (obj);
}
+/**
+ * gtk_text_mark_get_visible:
+ * @mark: a #GtkTextMark
+ *
+ * Returns %TRUE if the mark is visible (i.e. a cursor is displayed
+ * for it)
+ *
+ * Return value: %TRUE if visible
+ **/
gboolean
-gtk_text_mark_is_visible(GtkTextMark *mark)
+gtk_text_mark_get_visible (GtkTextMark *mark)
{
GtkTextLineSegment *seg;
return seg->body.mark.visible;
}
+/**
+ * gtk_text_mark_get_name:
+ * @mark: a #GtkTextMark
+ *
+ * Returns the mark name; returns NULL for anonymous marks.
+ *
+ * Return value: mark name
+ **/
const char *
gtk_text_mark_get_name (GtkTextMark *mark)
{
return seg->body.mark.name;
}
+/**
+ * gtk_text_mark_get_deleted:
+ * @mark: a #GtkTextMark
+ *
+ * Returns %TRUE if the mark has been removed from its buffer
+ * with gtk_text_buffer_delete_mark(). Marks can't be used
+ * once deleted.
+ *
+ * Return value: whether the mark is deleted
+ **/
gboolean
gtk_text_mark_get_deleted (GtkTextMark *mark)
{
GtkTextLineSegment *seg;
-
- g_return_val_if_fail (mark != NULL, FALSE);
+
+ g_return_val_if_fail (GTK_IS_TEXT_MARK (mark), FALSE);
seg = mark->segment;
if (seg == NULL)
return TRUE;
-
+
return seg->body.mark.tree == NULL;
}
+/**
+ * gtk_text_mark_get_buffer:
+ * @mark: a #GtkTextMark
+ *
+ * Gets the buffer this mark is located inside,
+ * or NULL if the mark is deleted.
+ *
+ * Return value: the mark's #GtkTextBuffer
+ **/
+GtkTextBuffer*
+gtk_text_mark_get_buffer (GtkTextMark *mark)
+{
+ GtkTextLineSegment *seg;
+
+ g_return_val_if_fail (GTK_IS_TEXT_MARK (mark), FALSE);
+
+ seg = mark->segment;
+
+ if (seg->body.mark.tree == NULL)
+ return NULL;
+ else
+ return _gtk_text_btree_get_buffer (seg->body.mark.tree);
+}
+
+/**
+ * gtk_text_mark_get_left_gravity:
+ * @mark: a #GtkTextMark
+ *
+ * Determines whether the mark has left gravity.
+ *
+ * Return value: %TRUE if the mark has left gravity, %FALSE otherwise
+ **/
+gboolean
+gtk_text_mark_get_left_gravity (GtkTextMark *mark)
+{
+ GtkTextLineSegment *seg;
+
+ g_return_val_if_fail (GTK_IS_TEXT_MARK (mark), FALSE);
+
+ seg = mark->segment;
+
+ return seg->type == >k_text_left_mark_type;
+}
+
/*
* Macro that determines the size of a mark segment:
*/
-#define MSEG_SIZE ((unsigned) (G_STRUCT_OFFSET(GtkTextLineSegment, body) \
- + sizeof(GtkTextMarkBody)))
+#define MSEG_SIZE ((unsigned) (G_STRUCT_OFFSET (GtkTextLineSegment, body) \
+ + sizeof (GtkTextMarkBody)))
GtkTextLineSegment*
-_mark_segment_new (GtkTextBTree *tree,
- gboolean left_gravity,
- const gchar *name)
+_gtk_mark_segment_new (GtkTextBTree *tree,
+ gboolean left_gravity,
+ const gchar *name)
{
GtkTextLineSegment *mark;
mark->type = >k_text_left_mark_type;
else
mark->type = >k_text_right_mark_type;
-
+
mark->byte_count = 0;
mark->char_count = 0;
mark->body.mark.obj = g_object_new (GTK_TYPE_TEXT_MARK, NULL);
mark->body.mark.obj->segment = mark;
-
+
mark->body.mark.tree = tree;
mark->body.mark.line = NULL;
mark->next = NULL;
mark->body.mark.visible = FALSE;
mark->body.mark.not_deleteable = FALSE;
-
+
return mark;
}
*/
GtkTextLineSegmentClass gtk_text_right_mark_type = {
- "mark", /* name */
- FALSE, /* leftGravity */
- NULL, /* splitFunc */
- mark_segment_delete_func, /* deleteFunc */
- mark_segment_cleanup_func, /* cleanupFunc */
- NULL, /* lineChangeFunc */
- mark_segment_check_func /* checkFunc */
+ "mark", /* name */
+ FALSE, /* leftGravity */
+ NULL, /* splitFunc */
+ mark_segment_delete_func, /* deleteFunc */
+ mark_segment_cleanup_func, /* cleanupFunc */
+ NULL, /* lineChangeFunc */
+ mark_segment_check_func /* checkFunc */
};
GtkTextLineSegmentClass gtk_text_left_mark_type = {
- "mark", /* name */
- TRUE, /* leftGravity */
- NULL, /* splitFunc */
- mark_segment_delete_func, /* deleteFunc */
- mark_segment_cleanup_func, /* cleanupFunc */
- NULL, /* lineChangeFunc */
- mark_segment_check_func /* checkFunc */
+ "mark", /* name */
+ TRUE, /* leftGravity */
+ NULL, /* splitFunc */
+ mark_segment_delete_func, /* deleteFunc */
+ mark_segment_cleanup_func, /* cleanupFunc */
+ NULL, /* lineChangeFunc */
+ mark_segment_check_func /* checkFunc */
};
/*
*
* mark_segment_delete_func --
*
- * This procedure is invoked by the text B-tree code whenever
- * a mark lies in a range of characters being deleted.
+ * This procedure is invoked by the text B-tree code whenever
+ * a mark lies in a range of characters being deleted.
*
* Results:
- * Returns 1 to indicate that deletion has been rejected.
+ * Returns 1 to indicate that deletion has been rejected,
+ * or 0 otherwise
*
* Side effects:
- * None (even if the whole tree is being deleted we don't
- * free up the mark; it will be done elsewhere).
+ * Frees mark if tree is going away
*
*--------------------------------------------------------------
*/
static gboolean
-mark_segment_delete_func (GtkTextLineSegment *segPtr,
+mark_segment_delete_func (GtkTextLineSegment *seg,
GtkTextLine *line,
gboolean tree_gone)
{
- return TRUE;
+ if (tree_gone)
+ {
+ _gtk_text_btree_release_mark_segment (seg->body.mark.tree, seg);
+ return FALSE;
+ }
+ else
+ return TRUE;
}
/*
*
* mark_segment_cleanup_func --
*
- * This procedure is invoked by the B-tree code whenever a
- * mark segment is moved from one line to another.
+ * This procedure is invoked by the B-tree code whenever a
+ * mark segment is moved from one line to another.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * The line field of the segment gets updated.
+ * The line field of the segment gets updated.
*
*--------------------------------------------------------------
*/
static GtkTextLineSegment *
-mark_segment_cleanup_func(GtkTextLineSegment *seg,
- GtkTextLine *line)
+mark_segment_cleanup_func (GtkTextLineSegment *seg,
+ GtkTextLine *line)
{
/* not sure why Tk did this here and not in LineChangeFunc */
seg->body.mark.line = line;
*
* mark_segment_check_func --
*
- * This procedure is invoked by the B-tree code to perform
- * consistency checks on mark segments.
+ * This procedure is invoked by the B-tree code to perform
+ * consistency checks on mark segments.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * The procedure panics if it detects anything wrong with
- * the mark.
+ * The procedure panics if it detects anything wrong with
+ * the mark.
*
*--------------------------------------------------------------
*/
static void
-mark_segment_check_func(GtkTextLineSegment *seg,
- GtkTextLine *line)
+mark_segment_check_func (GtkTextLineSegment *seg,
+ GtkTextLine *line)
{
if (seg->body.mark.line != line)
- g_error("mark_segment_check_func: seg->body.mark.line bogus");
+ g_error ("mark_segment_check_func: seg->body.mark.line bogus");
}