1
/* gtktextmark.c - mark segments
3
* Copyright (c) 1994 The Regents of the University of California.
4
* Copyright (c) 1994-1997 Sun Microsystems, Inc.
5
* Copyright (c) 2000 Red Hat, Inc.
6
* Tk -> Gtk port by Havoc Pennington <hp@redhat.com>
8
* This software is copyrighted by the Regents of the University of
9
* California, Sun Microsystems, Inc., and other parties. The
10
* following terms apply to all files associated with the software
11
* unless explicitly disclaimed in individual files.
13
* The authors hereby grant permission to use, copy, modify,
14
* distribute, and license this software and its documentation for any
15
* purpose, provided that existing copyright notices are retained in
16
* all copies and that this notice is included verbatim in any
17
* distributions. No written agreement, license, or royalty fee is
18
* required for any of the authorized uses. Modifications to this
19
* software may be copyrighted by their authors and need not follow
20
* the licensing terms described here, provided that the new terms are
21
* clearly indicated on the first page of each file where they apply.
23
* IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY
24
* PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
25
* DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION,
26
* OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED
27
* OF THE POSSIBILITY OF SUCH DAMAGE.
29
* THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
30
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
32
* NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
33
* AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
34
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
36
* GOVERNMENT USE: If you are acquiring this software on behalf of the
37
* U.S. government, the Government shall have only "Restricted Rights"
38
* in the software and related documentation as defined in the Federal
39
* Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you
40
* are acquiring the software on behalf of the Department of Defense,
41
* the software shall be classified as "Commercial Computer Software"
42
* and the Government shall have only "Restricted Rights" as defined
43
* in Clause 252.227-7013 (c) (1) of DFARs. Notwithstanding the
44
* foregoing, the authors grant the U.S. Government and others acting
45
* in its behalf permission to use and distribute the software in
46
* accordance with the terms specified in this license.
50
#define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
52
#include "gtktextbtree.h"
56
static void gtk_text_mark_finalize (GObject *obj);
58
G_DEFINE_TYPE (GtkTextMark, gtk_text_mark, G_TYPE_OBJECT)
61
gtk_text_mark_init (GtkTextMark *mark)
67
gtk_text_mark_class_init (GtkTextMarkClass *klass)
69
GObjectClass *object_class = G_OBJECT_CLASS (klass);
71
object_class->finalize = gtk_text_mark_finalize;
75
gtk_text_mark_finalize (GObject *obj)
78
GtkTextLineSegment *seg;
80
mark = GTK_TEXT_MARK (obj);
86
if (seg->body.mark.tree != NULL)
87
g_warning ("GtkTextMark being finalized while still in the buffer; "
88
"someone removed a reference they didn't own! Crash "
91
g_free (seg->body.mark.name);
97
/* chain parent_class' handler */
98
G_OBJECT_CLASS (gtk_text_mark_parent_class)->finalize (obj);
102
* gtk_text_mark_get_visible:
103
* @mark: a #GtkTextMark
105
* Returns %TRUE if the mark is visible (i.e. a cursor is displayed
108
* Return value: %TRUE if visible
111
gtk_text_mark_get_visible (GtkTextMark *mark)
113
GtkTextLineSegment *seg;
117
return seg->body.mark.visible;
121
* gtk_text_mark_get_name:
122
* @mark: a #GtkTextMark
124
* Returns the mark name; returns NULL for anonymous marks.
126
* Return value: mark name
129
gtk_text_mark_get_name (GtkTextMark *mark)
131
GtkTextLineSegment *seg;
135
return seg->body.mark.name;
139
* gtk_text_mark_get_deleted:
140
* @mark: a #GtkTextMark
142
* Returns %TRUE if the mark has been removed from its buffer
143
* with gtk_text_buffer_delete_mark(). Marks can't be used
146
* Return value: whether the mark is deleted
149
gtk_text_mark_get_deleted (GtkTextMark *mark)
151
GtkTextLineSegment *seg;
153
g_return_val_if_fail (GTK_IS_TEXT_MARK (mark), FALSE);
160
return seg->body.mark.tree == NULL;
164
* gtk_text_mark_get_buffer:
165
* @mark: a #GtkTextMark
167
* Gets the buffer this mark is located inside,
168
* or NULL if the mark is deleted.
170
* Return value: the mark's #GtkTextBuffer
173
gtk_text_mark_get_buffer (GtkTextMark *mark)
175
GtkTextLineSegment *seg;
177
g_return_val_if_fail (GTK_IS_TEXT_MARK (mark), NULL);
181
if (seg->body.mark.tree == NULL)
184
return _gtk_text_btree_get_buffer (seg->body.mark.tree);
188
* gtk_text_mark_get_left_gravity:
189
* @mark: a #GtkTextMark
191
* Determines whether the mark has left gravity.
193
* Return value: %TRUE if the mark has left gravity, %FALSE otherwise
196
gtk_text_mark_get_left_gravity (GtkTextMark *mark)
198
GtkTextLineSegment *seg;
200
g_return_val_if_fail (GTK_IS_TEXT_MARK (mark), FALSE);
204
return seg->type == >k_text_left_mark_type;
208
* Macro that determines the size of a mark segment:
211
#define MSEG_SIZE ((unsigned) (G_STRUCT_OFFSET (GtkTextLineSegment, body) \
212
+ sizeof (GtkTextMarkBody)))
216
_gtk_mark_segment_new (GtkTextBTree *tree,
217
gboolean left_gravity,
220
GtkTextLineSegment *mark;
222
mark = (GtkTextLineSegment *) g_malloc0 (MSEG_SIZE);
223
mark->body.mark.name = g_strdup (name);
226
mark->type = >k_text_left_mark_type;
228
mark->type = >k_text_right_mark_type;
230
mark->byte_count = 0;
231
mark->char_count = 0;
233
mark->body.mark.obj = g_object_new (GTK_TYPE_TEXT_MARK, NULL);
234
mark->body.mark.obj->segment = mark;
236
mark->body.mark.tree = tree;
237
mark->body.mark.line = NULL;
240
mark->body.mark.visible = FALSE;
241
mark->body.mark.not_deleteable = FALSE;
246
static int mark_segment_delete_func (GtkTextLineSegment *segPtr,
249
static GtkTextLineSegment *mark_segment_cleanup_func (GtkTextLineSegment *segPtr,
251
static void mark_segment_check_func (GtkTextLineSegment *segPtr,
256
* The following structures declare the "mark" segment types.
257
* There are actually two types for marks, one with left gravity
258
* and one with right gravity. They are identical except for
259
* their gravity property.
262
const GtkTextLineSegmentClass gtk_text_right_mark_type = {
264
FALSE, /* leftGravity */
265
NULL, /* splitFunc */
266
mark_segment_delete_func, /* deleteFunc */
267
mark_segment_cleanup_func, /* cleanupFunc */
268
NULL, /* lineChangeFunc */
269
mark_segment_check_func /* checkFunc */
272
const GtkTextLineSegmentClass gtk_text_left_mark_type = {
274
TRUE, /* leftGravity */
275
NULL, /* splitFunc */
276
mark_segment_delete_func, /* deleteFunc */
277
mark_segment_cleanup_func, /* cleanupFunc */
278
NULL, /* lineChangeFunc */
279
mark_segment_check_func /* checkFunc */
283
*--------------------------------------------------------------
285
* mark_segment_delete_func --
287
* This procedure is invoked by the text B-tree code whenever
288
* a mark lies in a range of characters being deleted.
291
* Returns 1 to indicate that deletion has been rejected,
295
* Frees mark if tree is going away
297
*--------------------------------------------------------------
301
mark_segment_delete_func (GtkTextLineSegment *seg,
307
_gtk_text_btree_release_mark_segment (seg->body.mark.tree, seg);
315
*--------------------------------------------------------------
317
* mark_segment_cleanup_func --
319
* This procedure is invoked by the B-tree code whenever a
320
* mark segment is moved from one line to another.
326
* The line field of the segment gets updated.
328
*--------------------------------------------------------------
331
static GtkTextLineSegment *
332
mark_segment_cleanup_func (GtkTextLineSegment *seg,
335
/* not sure why Tk did this here and not in LineChangeFunc */
336
seg->body.mark.line = line;
341
*--------------------------------------------------------------
343
* mark_segment_check_func --
345
* This procedure is invoked by the B-tree code to perform
346
* consistency checks on mark segments.
352
* The procedure panics if it detects anything wrong with
355
*--------------------------------------------------------------
359
mark_segment_check_func (GtkTextLineSegment *seg,
362
if (seg->body.mark.line != line)
363
g_error ("mark_segment_check_func: seg->body.mark.line bogus");
366
#define __GTK_TEXT_MARK_C__
367
#include "gtkaliasdef.c"