1 /* editor book mark handling
3 Copyright (C) 1996, 1997 the Free Software Foundation
5 Authors: 1996, 1997 Paul Sheer
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 #if defined (HAVE_MAD) && ! defined (MIDNIGHT) && ! defined (GTK)
30 /* note, if there is more than one bookmark on a line, then they are
31 appended after each other and the last one is always the one found
32 by book_mark_found() i.e. last in is the one seen */
34 static inline struct _book_mark
*double_marks (WEdit
* edit
, struct _book_mark
*p
)
37 while (p
->next
->line
== p
->line
)
42 /* returns the first bookmark on or before this line */
43 struct _book_mark
*book_mark_find (WEdit
* edit
, int line
)
46 if (!edit
->book_mark
) {
47 /* must have an imaginary top bookmark at line -1 to make things less complicated */
48 edit
->book_mark
= malloc (sizeof (struct _book_mark
));
49 memset (edit
->book_mark
, 0, sizeof (struct _book_mark
));
50 edit
->book_mark
->line
= -1;
51 return edit
->book_mark
;
53 for (p
= edit
->book_mark
; p
; p
= p
->next
) {
55 break; /* gone past it going downward */
56 if (p
->line
<= line
) {
58 if (p
->next
->line
> line
) {
60 return double_marks (edit
, p
);
64 return double_marks (edit
, p
);
68 for (p
= edit
->book_mark
; p
; p
= p
->prev
) {
70 if (p
->next
->line
<= line
)
71 break; /* gone past it going upward */
72 if (p
->line
<= line
) {
74 if (p
->next
->line
> line
) {
76 return double_marks (edit
, p
);
80 return double_marks (edit
, p
);
84 return 0; /* can't get here */
87 /* returns true if a bookmark exists at this line of colour c */
88 int book_mark_query_color (WEdit
* edit
, int line
, int c
)
93 for (p
= book_mark_find (edit
, line
); p
; p
= p
->prev
) {
102 /* returns the number of bookmarks at this line and a list of their colours in c
103 up to a maximum of 8 colours */
104 int book_mark_query_all (WEdit
* edit
, int line
, int *c
)
107 struct _book_mark
*p
;
108 if (!edit
->book_mark
)
110 for (i
= 0, p
= book_mark_find (edit
, line
); p
&& i
< 8; p
= p
->prev
, i
++) {
118 /* insert a bookmark at this line */
119 void book_mark_insert (WEdit
* edit
, int line
, int c
)
121 struct _book_mark
*p
, *q
;
122 p
= book_mark_find (edit
, line
);
124 if (p
->line
== line
) { /* already exists, so just change the colour */
126 edit
->force
|= REDRAW_LINE
;
132 edit
->force
|= REDRAW_LINE
;
133 /* create list entry */
134 q
= malloc (sizeof (struct _book_mark
));
135 memset (q
, 0, sizeof (struct _book_mark
));
139 /* insert into list */
144 #if !defined (GTK) && !defined (MIDNIGHT)
145 render_scrollbar (edit
->widget
->vert_scrollbar
);
149 /* remove a bookmark if there is one at this line matching this colour - c of -1 clear all */
150 /* returns non-zero on not-found */
151 int book_mark_clear (WEdit
* edit
, int line
, int c
)
153 struct _book_mark
*p
, *q
;
156 if (!edit
->book_mark
)
158 for (p
= book_mark_find (edit
, line
); p
; p
= q
) {
160 if (p
->line
== line
&& (p
->c
== c
|| c
== -1)) {
162 edit
->force
|= REDRAW_LINE
;
163 edit
->book_mark
= p
->prev
;
164 p
->prev
->next
= p
->next
;
166 p
->next
->prev
= p
->prev
;
172 /* if there is only our dummy book mark left, clear it for speed */
173 if (edit
->book_mark
->line
== -1 && !edit
->book_mark
->next
) {
174 free (edit
->book_mark
);
177 #if !defined (GTK) && !defined (MIDNIGHT)
179 render_scrollbar (edit
->widget
->vert_scrollbar
);
184 /* clear all bookmarks matching this colour, if c is -1 clears all */
185 void book_mark_flush (WEdit
* edit
, int c
)
187 struct _book_mark
*p
, *q
;
189 if (!edit
->book_mark
)
191 edit
->force
|= REDRAW_PAGE
;
192 while (edit
->book_mark
->prev
)
193 edit
->book_mark
= edit
->book_mark
->prev
;
194 for (q
= edit
->book_mark
->next
; q
; q
= p
) {
196 if (q
->c
== c
|| c
== -1) {
197 q
->prev
->next
= q
->next
;
204 if (!edit
->book_mark
->next
) {
205 free (edit
->book_mark
);
208 #if !defined (GTK) && !defined (MIDNIGHT)
210 render_scrollbar (edit
->widget
->vert_scrollbar
);
214 /* shift down bookmarks after this line */
215 void book_mark_inc (WEdit
* edit
, int line
)
218 if (edit
->book_mark
) {
219 struct _book_mark
*p
;
220 p
= book_mark_find (edit
, line
);
221 for (p
= p
->next
; p
; p
= p
->next
) {
226 #if !defined (GTK) && !defined (MIDNIGHT)
228 render_scrollbar (edit
->widget
->vert_scrollbar
);
232 /* shift up bookmarks after this line */
233 void book_mark_dec (WEdit
* edit
, int line
)
236 if (edit
->book_mark
) {
237 struct _book_mark
*p
;
238 p
= book_mark_find (edit
, line
);
239 for (p
= p
->next
; p
; p
= p
->next
) {
244 #if !defined (GTK) && !defined (MIDNIGHT)
246 render_scrollbar (edit
->widget
->vert_scrollbar
);