add VI_C_SETTOP for scrollbar setting
[nvi.git] / motif_l / m_func.c
blob0bf44d8b20304ae5f4a65f7de902e0f48c119adb
1 /*-
2 * Copyright (c) 1996
3 * Rob Zimmermann. All rights reserved.
4 * Copyright (c) 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: m_func.c,v 8.15 1996/12/13 11:38:20 bostic Exp $ (Berkeley) $Date: 1996/12/13 11:38:20 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include "Xm/PanedW.h"
21 #include <bitstring.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
26 #include "../common/common.h"
27 #include "../ip/ip.h"
28 #include "m_motif.h"
29 #include "m_extern.h"
30 #include "ipc_extern.h"
33 static int
34 vi_addstr(ipbp)
35 IP_BUF *ipbp;
37 #ifdef TRACE
38 trace("addstr() {%.*s}\n", ipbp->len, ipbp->str);
39 #endif
40 /* Add to backing store. */
41 memcpy(CharAt(__vi_screen, __vi_screen->cury, __vi_screen->curx),
42 ipbp->str, ipbp->len);
43 memset(FlagAt(__vi_screen, __vi_screen->cury, __vi_screen->curx),
44 __vi_screen->color, ipbp->len);
46 /* Draw from backing store. */
47 __vi_draw_text(__vi_screen,
48 __vi_screen->cury, __vi_screen->curx, ipbp->len);
50 /* Advance the caret. */
51 __vi_move_caret(__vi_screen,
52 __vi_screen->cury, __vi_screen->curx + ipbp->len);
53 return (0);
56 static int
57 vi_attribute(ipbp)
58 IP_BUF *ipbp;
60 switch (ipbp->val1) {
61 case SA_ALTERNATE:
62 /* XXX: Nothing. */
63 break;
64 case SA_INVERSE:
65 __vi_screen->color = ipbp->val2;
66 break;
68 return (0);
71 static int
72 vi_bell(ipbp)
73 IP_BUF *ipbp;
76 * XXX
77 * Future... implement visible bell.
79 XBell(XtDisplay(__vi_screen->area), 0);
80 return (0);
83 static int
84 vi_busyon(ipbp)
85 IP_BUF *ipbp;
87 __vi_set_cursor(__vi_screen, 1);
88 return (0);
91 static int
92 vi_busyoff(ipbp)
93 IP_BUF *ipbp;
95 __vi_set_cursor(__vi_screen, 0);
96 return (0);
99 static int
100 vi_clrtoeol(ipbp)
101 IP_BUF *ipbp;
103 int len;
104 char *ptr;
106 len = __vi_screen->cols - __vi_screen->curx;
107 ptr = CharAt(__vi_screen, __vi_screen->cury, __vi_screen->curx);
109 /* Clear backing store. */
110 memset(ptr, ' ', len);
111 memset(FlagAt(__vi_screen, __vi_screen->cury, __vi_screen->curx),
112 COLOR_STANDARD, len);
114 /* Draw from backing store. */
115 __vi_draw_text(__vi_screen, __vi_screen->cury, __vi_screen->curx, len);
117 return (0);
120 static int
121 vi_deleteln(ipbp)
122 IP_BUF *ipbp;
124 int y, rows, len, height, width;
126 y = __vi_screen->cury;
127 rows = __vi_screen->rows - (y+1);
128 len = __vi_screen->cols * rows;
130 /* Don't want to copy the caret! */
131 __vi_erase_caret(__vi_screen);
133 /* Adjust backing store and the flags. */
134 memmove(CharAt(__vi_screen, y, 0), CharAt(__vi_screen, y+1, 0), len);
135 memmove(FlagAt(__vi_screen, y, 0), FlagAt(__vi_screen, y+1, 0), len);
137 /* Move the bits on the screen. */
138 width = __vi_screen->ch_width * __vi_screen->cols;
139 height = __vi_screen->ch_height * rows;
140 XCopyArea(XtDisplay(__vi_screen->area), /* display */
141 XtWindow(__vi_screen->area), /* src */
142 XtWindow(__vi_screen->area), /* dest */
143 __vi_copy_gc, /* context */
144 0, YTOP(__vi_screen, y+1), /* srcx, srcy */
145 width, height,
146 0, YTOP(__vi_screen, y) /* dstx, dsty */
148 /* Need to let X take over. */
149 XmUpdateDisplay(__vi_screen->area);
151 return (1);
154 static int
155 vi_discard(ipbp)
156 IP_BUF *ipbp;
158 /* XXX: Nothing. */
159 return (0);
162 static int
163 vi_insertln(ipbp)
164 IP_BUF *ipbp;
166 int y, rows, height, width;
167 char *from, *to;
169 y = __vi_screen->cury;
170 rows = __vi_screen->rows - (1+y);
171 from = CharAt(__vi_screen, y, 0),
172 to = CharAt(__vi_screen, y+1, 0);
174 /* Don't want to copy the caret! */
175 __vi_erase_caret(__vi_screen);
177 /* Adjust backing store. */
178 memmove(to, from, __vi_screen->cols * rows);
179 memset(from, ' ', __vi_screen->cols);
181 /* And the backing store. */
182 from = FlagAt(__vi_screen, y, 0),
183 to = FlagAt(__vi_screen, y+1, 0);
184 memmove(to, from, __vi_screen->cols * rows);
185 memset(from, COLOR_STANDARD, __vi_screen->cols);
187 /* Move the bits on the screen. */
188 width = __vi_screen->ch_width * __vi_screen->cols;
189 height = __vi_screen->ch_height * rows;
191 XCopyArea(XtDisplay(__vi_screen->area), /* display */
192 XtWindow(__vi_screen->area), /* src */
193 XtWindow(__vi_screen->area), /* dest */
194 __vi_copy_gc, /* context */
195 0, YTOP(__vi_screen, y), /* srcx, srcy */
196 width, height,
197 0, YTOP(__vi_screen, y+1) /* dstx, dsty */
200 /* clear out the new space */
201 XClearArea(XtDisplay(__vi_screen->area), /* display */
202 XtWindow(__vi_screen->area), /* window */
203 0, YTOP(__vi_screen, y), /* srcx, srcy */
204 0, __vi_screen->ch_height, /* w=full, height */
205 True /* no exposures */
208 /* Need to let X take over. */
209 XmUpdateDisplay(__vi_screen->area);
211 return (1);
214 static int
215 vi_move(ipbp)
216 IP_BUF *ipbp;
218 __vi_move_caret(__vi_screen, ipbp->val1, ipbp->val2);
219 return (0);
222 static int
223 vi_redraw(ipbp)
224 IP_BUF *ipbp;
226 __vi_expose_func(0, __vi_screen, 0);
227 return (0);
230 static int
231 vi_refresh(ipbp)
232 IP_BUF *ipbp;
234 /* probably ok to scroll again */
235 __vi_clear_scroll_block();
237 /* if the tag stack widget is active, set the text field there
238 * to agree with the current caret position.
239 * Note that this really ought to be done by core due to wrapping issues
241 __vi_set_word_at_caret( __vi_screen );
243 return (0);
246 static int
247 vi_quit(ipbp)
248 IP_BUF *ipbp;
250 if (__vi_exitp != NULL)
251 __vi_exitp();
253 return (0);
256 static int
257 vi_rename(ipbp)
258 IP_BUF *ipbp;
260 const char *tail;
261 Widget shell;
263 /* For the icon, use the tail. */
264 if ((tail = strrchr(ipbp->str, '/')) == NULL || *(tail + 1) == '\0')
265 tail = ipbp->str;
266 else
267 tail++;
270 * XXX
271 * Future: Attach a title to each screen. For now, we change
272 * the title of the shell.
274 shell = __vi_screen->area;
275 while ( ! XtIsShell(shell) ) shell = XtParent(shell);
276 XtVaSetValues(shell,
277 XmNiconName, tail,
278 XmNtitle, ipbp->str,
281 return (0);
284 static int
285 vi_rewrite(ipbp)
286 IP_BUF *ipbp;
288 /* XXX: Nothing. */
289 return (0);
293 static int
294 vi_scrollbar(ipbp)
295 IP_BUF *ipbp;
297 int top, size, maximum, old_max;
299 /* in the buffer,
300 * val1 contains the top visible line number
301 * val2 contains the number of visible lines
302 * val3 contains the number of lines in the file
304 top = ipbp->val1;
305 size = ipbp->val2;
306 maximum = ipbp->val3;
308 #if 0
309 fprintf( stderr, "Setting scrollbar\n" );
310 fprintf( stderr, "\tvalue\t\t%d\n", top );
311 fprintf( stderr, "\tsize\t\t%d\n", size );
312 fprintf( stderr, "\tmaximum\t\t%d\n", maximum );
313 #endif
315 /* armor plating. core thinks there are no lines in an
316 * empty file, but says we are on line 1
318 if ( top > maximum ) {
319 #if 0
320 fprintf( stderr, "Correcting for top > maximum\n" );
321 #endif
322 maximum = top + 1;
323 size = 1;
326 /* armor plating. core may think there are more
327 * lines visible than remain in the file
329 if ( top+size >= maximum ) {
330 #if 0
331 fprintf( stderr, "Correcting for top+size >= maximum\n" );
332 #endif
333 size = maximum - top;
336 /* need to increase the maximum before changing the values */
337 XtVaGetValues( __vi_screen->scroll, XmNmaximum, &old_max, 0 );
338 if ( maximum > old_max )
339 XtVaSetValues( __vi_screen->scroll, XmNmaximum, maximum, 0 );
341 /* change the rest of the values without generating a callback */
342 XmScrollBarSetValues( __vi_screen->scroll,
343 top,
344 size,
345 1, /* increment */
346 size, /* page_increment */
347 False /* do not notify me */
350 /* need to decrease the maximum after changing the values */
351 if ( maximum < old_max )
352 XtVaSetValues( __vi_screen->scroll, XmNmaximum, maximum, 0 );
354 /* done */
355 return (0);
358 static int
359 vi_split(ipbp)
360 IP_BUF *ipbp;
362 /* XXX: Nothing. */
363 return (0);
366 int (*__vi_iplist[SI_EVENT_MAX]) __P((IP_BUF *)) = {
367 vi_addstr,
368 vi_attribute,
369 vi_bell,
370 vi_busyoff,
371 vi_busyon,
372 vi_clrtoeol,
373 vi_deleteln,
374 vi_discard,
375 vi_insertln,
376 vi_move,
377 vi_quit,
378 vi_redraw,
379 vi_refresh,
380 vi_rename,
381 vi_rewrite,
382 vi_scrollbar,
383 vi_split