merge m_util.h into m_motif.h; naming cleanups
[nvi.git] / motif_l / m_func.c
blobb3f5ded567549d058738b0b5a094a05f72450469
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.17 1996/12/14 14:04:00 bostic Exp $ (Berkeley) $Date: 1996/12/14 14:04:00 $";
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->len1, ipbp->str1);
39 #endif
40 /* Add to backing store. */
41 memcpy(CharAt(__vi_screen, __vi_screen->cury, __vi_screen->curx),
42 ipbp->str1, ipbp->len1);
43 memset(FlagAt(__vi_screen, __vi_screen->cury, __vi_screen->curx),
44 __vi_screen->color, ipbp->len1);
46 /* Draw from backing store. */
47 __vi_draw_text(__vi_screen,
48 __vi_screen->cury, __vi_screen->curx, ipbp->len1);
50 /* Advance the caret. */
51 __vi_move_caret(__vi_screen,
52 __vi_screen->cury, __vi_screen->curx + ipbp->len1);
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 /* similarly, the text ruler... */
244 __vi_set_text_ruler( __vi_screen->cury, __vi_screen->curx );
246 return (0);
249 static int
250 vi_quit(ipbp)
251 IP_BUF *ipbp;
253 if (__vi_exitp != NULL)
254 __vi_exitp();
256 return (0);
259 static int
260 vi_rename(ipbp)
261 IP_BUF *ipbp;
263 const char *tail;
264 Widget shell;
266 /* For the icon, use the tail. */
267 if ((tail = strrchr(ipbp->str1, '/')) == NULL || *(tail + 1) == '\0')
268 tail = ipbp->str1;
269 else
270 tail++;
273 * XXX
274 * Future: Attach a title to each screen. For now, we change
275 * the title of the shell.
277 shell = __vi_screen->area;
278 while ( ! XtIsShell(shell) ) shell = XtParent(shell);
279 XtVaSetValues(shell,
280 XmNiconName, tail,
281 XmNtitle, ipbp->str1,
284 return (0);
287 static int
288 vi_rewrite(ipbp)
289 IP_BUF *ipbp;
291 /* XXX: Nothing. */
292 return (0);
296 static int
297 vi_scrollbar(ipbp)
298 IP_BUF *ipbp;
300 int top, size, maximum, old_max;
302 /* in the buffer,
303 * val1 contains the top visible line number
304 * val2 contains the number of visible lines
305 * val3 contains the number of lines in the file
307 top = ipbp->val1;
308 size = ipbp->val2;
309 maximum = ipbp->val3;
311 #if 0
312 fprintf( stderr, "Setting scrollbar\n" );
313 fprintf( stderr, "\tvalue\t\t%d\n", top );
314 fprintf( stderr, "\tsize\t\t%d\n", size );
315 fprintf( stderr, "\tmaximum\t\t%d\n", maximum );
316 #endif
318 /* armor plating. core thinks there are no lines in an
319 * empty file, but says we are on line 1
321 if ( top > maximum ) {
322 #if 0
323 fprintf( stderr, "Correcting for top > maximum\n" );
324 #endif
325 maximum = top + 1;
326 size = 1;
329 /* armor plating. core may think there are more
330 * lines visible than remain in the file
332 if ( top+size >= maximum ) {
333 #if 0
334 fprintf( stderr, "Correcting for top+size >= maximum\n" );
335 #endif
336 size = maximum - top;
339 /* need to increase the maximum before changing the values */
340 XtVaGetValues( __vi_screen->scroll, XmNmaximum, &old_max, 0 );
341 if ( maximum > old_max )
342 XtVaSetValues( __vi_screen->scroll, XmNmaximum, maximum, 0 );
344 /* change the rest of the values without generating a callback */
345 XmScrollBarSetValues( __vi_screen->scroll,
346 top,
347 size,
348 1, /* increment */
349 size, /* page_increment */
350 False /* do not notify me */
353 /* need to decrease the maximum after changing the values */
354 if ( maximum < old_max )
355 XtVaSetValues( __vi_screen->scroll, XmNmaximum, maximum, 0 );
357 /* done */
358 return (0);
361 static int
362 vi_split(ipbp)
363 IP_BUF *ipbp;
365 /* XXX: Nothing. */
366 return (0);
369 int (*__vi_iplist[SI_EVENT_MAX]) __P((IP_BUF *)) = {
370 vi_addstr,
371 vi_attribute,
372 vi_bell,
373 vi_busyoff,
374 vi_busyon,
375 vi_clrtoeol,
376 vi_deleteln,
377 vi_discard,
378 __vi_editopt,
379 vi_insertln,
380 vi_move,
381 vi_quit,
382 vi_redraw,
383 vi_refresh,
384 vi_rename,
385 vi_rewrite,
386 vi_scrollbar,
387 vi_split