]> Pileus Git - ~andy/gtk/blob - gtk/gtktextmark.c
Remove all references to offscreen flag which was no longer used.
[~andy/gtk] / gtk / gtktextmark.c
1 /* 
2  * tkTextMark.c --
3  *
4  *      This file contains the procedure that implement marks for
5  *      text widgets.
6  *
7  * Copyright (c) 1994 The Regents of the University of California.
8  * Copyright (c) 1994-1997 Sun Microsystems, Inc.
9  *
10  * See the file "license.terms" for information on usage and redistribution
11  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12  *
13  * RCS: @(#) $Id$
14  */
15
16 #include "gtktextbtree.h"
17
18 gboolean
19 gtk_text_mark_is_visible(GtkTextMark *mark)
20 {
21   GtkTextLineSegment *seg;
22
23   seg = (GtkTextLineSegment*)mark;
24
25   return seg->body.mark.visible;
26 }
27
28 char *
29 gtk_text_mark_get_name (GtkTextMark *mark)
30 {
31   GtkTextLineSegment *seg;
32
33   seg = (GtkTextLineSegment*)mark;
34
35   return g_strdup (seg->body.mark.name);
36 }
37
38 /*
39  * Macro that determines the size of a mark segment:
40  */
41
42 #define MSEG_SIZE ((unsigned) (G_STRUCT_OFFSET(GtkTextLineSegment, body) \
43         + sizeof(GtkTextMarkBody)))
44
45
46 GtkTextLineSegment*
47 mark_segment_new(GtkTextBTree *tree,
48                  gboolean left_gravity,
49                  const gchar *name)
50 {
51   GtkTextLineSegment *mark;
52
53   mark = (GtkTextLineSegment *) g_malloc0(MSEG_SIZE);
54   mark->body.mark.name = g_strdup(name);
55
56   if (left_gravity)
57     mark->type = &gtk_text_left_mark_type;
58   else
59     mark->type = &gtk_text_right_mark_type;
60
61   mark->byte_count = 0;
62   mark->char_count = 0;
63
64   mark->body.mark.tree = tree;
65   mark->body.mark.line = NULL;
66   mark->next = NULL;
67
68   mark->body.mark.refcount = 1;
69
70   mark->body.mark.visible = FALSE;
71   
72   return mark;
73 }
74
75 void
76 mark_segment_ref(GtkTextLineSegment *mark)
77 {
78   g_return_if_fail(mark != NULL);
79   g_return_if_fail(mark->type == &gtk_text_right_mark_type ||
80                    mark->type == &gtk_text_left_mark_type);
81   g_return_if_fail(mark->body.mark.refcount > 0);
82   
83   mark->body.mark.refcount += 1;
84 }
85
86 void
87 mark_segment_unref(GtkTextLineSegment *mark)
88 {
89   g_return_if_fail(mark != NULL);
90   g_return_if_fail(mark->type == &gtk_text_right_mark_type ||
91                    mark->type == &gtk_text_left_mark_type);
92   g_return_if_fail(mark->body.mark.refcount > 0);
93
94   mark->body.mark.refcount -= 1;
95
96   if (mark->body.mark.refcount == 0)
97     {
98       g_free(mark->body.mark.name);
99       
100       g_free(mark);
101     }
102 }
103
104 /*
105  * Forward references for procedures defined in this file:
106  */
107
108 static int              mark_segment_delete_func  (GtkTextLineSegment   *segPtr,
109                                                    GtkTextLine      *line,
110                                                    int                treeGone);
111 static GtkTextLineSegment *mark_segment_cleanup_func (GtkTextLineSegment   *segPtr,
112                                                    GtkTextLine      *line);
113 static void             mark_segment_check_func   (GtkTextLineSegment   *segPtr,
114                                                    GtkTextLine      *line);
115
116 /*
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.
121  */
122
123 GtkTextLineSegmentClass gtk_text_right_mark_type = {
124     "mark",                                     /* name */
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 */
131 };
132
133 GtkTextLineSegmentClass gtk_text_left_mark_type = {
134     "mark",                                     /* name */
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 */
141 };
142
143 \f
144 /*
145  *--------------------------------------------------------------
146  *
147  * mark_segment_delete_func --
148  *
149  *      This procedure is invoked by the text B-tree code whenever
150  *      a mark lies in a range of characters being deleted.
151  *
152  * Results:
153  *      Returns 1 to indicate that deletion has been rejected.
154  *
155  * Side effects:
156  *      None (even if the whole tree is being deleted we don't
157  *      free up the mark;  it will be done elsewhere).
158  *
159  *--------------------------------------------------------------
160  */
161
162         /* ARGSUSED */
163 static int
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
169                                          * get cleaned up. */
170 {
171     return 1;
172 }
173 \f
174 /*
175  *--------------------------------------------------------------
176  *
177  * mark_segment_cleanup_func --
178  *
179  *      This procedure is invoked by the B-tree code whenever a
180  *      mark segment is moved from one line to another.
181  *
182  * Results:
183  *      None.
184  *
185  * Side effects:
186  *      The line field of the segment gets updated.
187  *
188  *--------------------------------------------------------------
189  */
190
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. */
195 {
196     markPtr->body.mark.line = line;
197     return markPtr;
198 }
199
200 #if 0
201
202 \f
203 /*
204  *--------------------------------------------------------------
205  *
206  * GtkTextInsertDisplayFunc --
207  *
208  *      This procedure is called to display the insertion
209  *      cursor.
210  *
211  * Results:
212  *      None.
213  *
214  * Side effects:
215  *      Graphics are drawn.
216  *
217  *--------------------------------------------------------------
218  */
219
220         /* ARGSUSED */
221 void
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
227                                          * of scrolling). */
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
235                                          * chunk. */
236     int screenY;                        /* Y-coordinate in text window that
237                                          * corresponds to y. */
238 {
239     GtkTextView *tkxt = (GtkTextView *) chunkPtr->clientData;
240     int halfWidth = tkxt->insertWidth/2;
241
242     if ((x + halfWidth) < 0) {
243         /*
244          * The insertion cursor is off-screen.  Just return.
245          */
246
247         return;
248     }
249
250     /*
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.
256      */
257
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);
266     }
267 }
268 \f
269 /*
270  *--------------------------------------------------------------
271  *
272  * InsertUndisplayFunc --
273  *
274  *      This procedure is called when the insertion cursor is no
275  *      longer at a visible point on the display.  It does nothing
276  *      right now.
277  *
278  * Results:
279  *      None.
280  *
281  * Side effects:
282  *      None.
283  *
284  *--------------------------------------------------------------
285  */
286
287         /* ARGSUSED */
288 static void
289 InsertUndisplayFunc(tkxt, chunkPtr)
290     GtkTextView *tkxt;                  /* Overall information about text
291                                          * widget. */
292     GtkTextDisplayChunk *chunkPtr;              /* Chunk that is about to be freed. */
293 {
294     return;
295 }
296 \f
297 #endif
298 /*
299  *--------------------------------------------------------------
300  *
301  * mark_segment_check_func --
302  *
303  *      This procedure is invoked by the B-tree code to perform
304  *      consistency checks on mark segments.
305  *
306  * Results:
307  *      None.
308  *
309  * Side effects:
310  *      The procedure panics if it detects anything wrong with
311  *      the mark.
312  *
313  *--------------------------------------------------------------
314  */
315
316 static void
317 mark_segment_check_func(markPtr, line)
318     GtkTextLineSegment *markPtr;                /* Segment to check. */
319     GtkTextLine *line;          /* Line containing segment. */
320 {
321     if (markPtr->body.mark.line != line)
322       g_error("mark_segment_check_func: markPtr->body.mark.line bogus");
323
324     /* No longer do this because we don't have access to btree
325        struct members */
326 #if 0
327     /*
328      * Make sure that the mark is still present in the text's mark
329      * hash table.
330      */
331     for (hPtr = Tcl_FirstHashEntry(&markPtr->body.mark.tkxt->markTable,
332             &search); hPtr != markPtr->body.mark.hPtr;
333             hPtr = Tcl_NextHashEntry(&search)) {
334         if (hPtr == NULL) {
335             panic("mark_segment_check_func couldn't find hash table entry for mark");
336         }
337     }
338 #endif
339 }