4 * This file contains the procedure that implement marks for
7 * Copyright (c) 1994 The Regents of the University of California.
8 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
10 * See the file "license.terms" for information on usage and redistribution
11 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16 #include "gtktextbtree.h"
19 gtk_text_mark_is_visible(GtkTextMark *mark)
21 GtkTextLineSegment *seg;
23 seg = (GtkTextLineSegment*)mark;
25 return seg->body.mark.visible;
29 gtk_text_mark_get_name (GtkTextMark *mark)
31 GtkTextLineSegment *seg;
33 seg = (GtkTextLineSegment*)mark;
35 return g_strdup (seg->body.mark.name);
39 * Macro that determines the size of a mark segment:
42 #define MSEG_SIZE ((unsigned) (G_STRUCT_OFFSET(GtkTextLineSegment, body) \
43 + sizeof(GtkTextMarkBody)))
47 mark_segment_new(GtkTextBTree *tree,
48 gboolean left_gravity,
51 GtkTextLineSegment *mark;
53 mark = (GtkTextLineSegment *) g_malloc0(MSEG_SIZE);
54 mark->body.mark.name = g_strdup(name);
57 mark->type = >k_text_left_mark_type;
59 mark->type = >k_text_right_mark_type;
64 mark->body.mark.tree = tree;
65 mark->body.mark.line = NULL;
68 mark->body.mark.refcount = 1;
70 mark->body.mark.visible = FALSE;
76 mark_segment_ref(GtkTextLineSegment *mark)
78 g_return_if_fail(mark != NULL);
79 g_return_if_fail(mark->type == >k_text_right_mark_type ||
80 mark->type == >k_text_left_mark_type);
81 g_return_if_fail(mark->body.mark.refcount > 0);
83 mark->body.mark.refcount += 1;
87 mark_segment_unref(GtkTextLineSegment *mark)
89 g_return_if_fail(mark != NULL);
90 g_return_if_fail(mark->type == >k_text_right_mark_type ||
91 mark->type == >k_text_left_mark_type);
92 g_return_if_fail(mark->body.mark.refcount > 0);
94 mark->body.mark.refcount -= 1;
96 if (mark->body.mark.refcount == 0)
98 g_free(mark->body.mark.name);
105 * Forward references for procedures defined in this file:
108 static int mark_segment_delete_func (GtkTextLineSegment *segPtr,
111 static GtkTextLineSegment *mark_segment_cleanup_func (GtkTextLineSegment *segPtr,
113 static void mark_segment_check_func (GtkTextLineSegment *segPtr,
117 * The following structures declare the "mark" segment types.
118 * There are actually two types for marks, one with left gravity
119 * and one with right gravity. They are identical except for
120 * their gravity property.
123 GtkTextLineSegmentClass gtk_text_right_mark_type = {
125 FALSE, /* leftGravity */
126 (GtkTextLineSegmentSplitFunc) NULL, /* splitFunc */
127 mark_segment_delete_func, /* deleteFunc */
128 mark_segment_cleanup_func, /* cleanupFunc */
129 (GtkTextLineSegmentLineChangeFunc) NULL, /* lineChangeFunc */
130 mark_segment_check_func /* checkFunc */
133 GtkTextLineSegmentClass gtk_text_left_mark_type = {
135 TRUE, /* leftGravity */
136 (GtkTextLineSegmentSplitFunc) NULL, /* splitFunc */
137 mark_segment_delete_func, /* deleteFunc */
138 mark_segment_cleanup_func, /* cleanupFunc */
139 (GtkTextLineSegmentLineChangeFunc) NULL, /* lineChangeFunc */
140 mark_segment_check_func /* checkFunc */
145 *--------------------------------------------------------------
147 * mark_segment_delete_func --
149 * This procedure is invoked by the text B-tree code whenever
150 * a mark lies in a range of characters being deleted.
153 * Returns 1 to indicate that deletion has been rejected.
156 * None (even if the whole tree is being deleted we don't
157 * free up the mark; it will be done elsewhere).
159 *--------------------------------------------------------------
164 mark_segment_delete_func(segPtr, line, treeGone)
165 GtkTextLineSegment *segPtr; /* Segment being deleted. */
166 GtkTextLine *line; /* Line containing segment. */
167 int treeGone; /* Non-zero means the entire tree is
168 * being deleted, so everything must
175 *--------------------------------------------------------------
177 * mark_segment_cleanup_func --
179 * This procedure is invoked by the B-tree code whenever a
180 * mark segment is moved from one line to another.
186 * The line field of the segment gets updated.
188 *--------------------------------------------------------------
191 static GtkTextLineSegment *
192 mark_segment_cleanup_func(markPtr, line)
193 GtkTextLineSegment *markPtr; /* Mark segment that's being moved. */
194 GtkTextLine *line; /* Line that now contains segment. */
196 markPtr->body.mark.line = line;
204 *--------------------------------------------------------------
206 * GtkTextInsertDisplayFunc --
208 * This procedure is called to display the insertion
215 * Graphics are drawn.
217 *--------------------------------------------------------------
222 GtkTextInsertDisplayFunc(chunkPtr, x, y, height, baseline, display, dst, screenY)
223 GtkTextDisplayChunk *chunkPtr; /* Chunk that is to be drawn. */
224 int x; /* X-position in dst at which to
225 * draw this chunk (may differ from
226 * the x-position in the chunk because
228 int y; /* Y-position at which to draw this
229 * chunk in dst (x-position is in
230 * the chunk itself). */
231 int height; /* Total height of line. */
232 int baseline; /* Offset of baseline from y. */
233 Display *display; /* Display to use for drawing. */
234 Drawable dst; /* Pixmap or window in which to draw
236 int screenY; /* Y-coordinate in text window that
237 * corresponds to y. */
239 GtkTextView *tkxt = (GtkTextView *) chunkPtr->clientData;
240 int halfWidth = tkxt->insertWidth/2;
242 if ((x + halfWidth) < 0) {
244 * The insertion cursor is off-screen. Just return.
251 * As a special hack to keep the cursor visible on mono displays
252 * (or anywhere else that the selection and insertion cursors
253 * have the same color) write the default background in the cursor
254 * area (instead of nothing) when the cursor isn't on. Otherwise
255 * the selection might hide the cursor.
258 if (tkxt->flags & INSERT_ON) {
259 Tk_Fill3DRectangle(tkxt->tkwin, dst, tkxt->insertBorder,
260 x - tkxt->insertWidth/2, y, tkxt->insertWidth,
261 height, tkxt->insertBorderWidth, TK_RELIEF_RAISED);
262 } else if (tkxt->selBorder == tkxt->insertBorder) {
263 Tk_Fill3DRectangle(tkxt->tkwin, dst, tkxt->border,
264 x - tkxt->insertWidth/2, y, tkxt->insertWidth,
265 height, 0, TK_RELIEF_FLAT);
270 *--------------------------------------------------------------
272 * InsertUndisplayFunc --
274 * This procedure is called when the insertion cursor is no
275 * longer at a visible point on the display. It does nothing
284 *--------------------------------------------------------------
289 InsertUndisplayFunc(tkxt, chunkPtr)
290 GtkTextView *tkxt; /* Overall information about text
292 GtkTextDisplayChunk *chunkPtr; /* Chunk that is about to be freed. */
299 *--------------------------------------------------------------
301 * mark_segment_check_func --
303 * This procedure is invoked by the B-tree code to perform
304 * consistency checks on mark segments.
310 * The procedure panics if it detects anything wrong with
313 *--------------------------------------------------------------
317 mark_segment_check_func(markPtr, line)
318 GtkTextLineSegment *markPtr; /* Segment to check. */
319 GtkTextLine *line; /* Line containing segment. */
321 if (markPtr->body.mark.line != line)
322 g_error("mark_segment_check_func: markPtr->body.mark.line bogus");
324 /* No longer do this because we don't have access to btree
328 * Make sure that the mark is still present in the text's mark
331 for (hPtr = Tcl_FirstHashEntry(&markPtr->body.mark.tkxt->markTable,
332 &search); hPtr != markPtr->body.mark.hPtr;
333 hPtr = Tcl_NextHashEntry(&search)) {
335 panic("mark_segment_check_func couldn't find hash table entry for mark");