*** empty log message ***
[nvi.git] / motif_l / m_func.c
blob446b17e24a0f40b99f3086e5e68ff7f804578681
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.23 1997/08/02 16:50:10 bostic Exp $ (Berkeley) $Date: 1997/08/02 16:50:10 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <Xm/PanedW.h>
20 #include <Xm/ScrollBar.h>
22 #include <bitstring.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
27 #include "../common/common.h"
28 #include "../ipc/ip.h"
29 #include "m_motif.h"
32 static int
33 vi_addstr(ipbp)
34 IP_BUF *ipbp;
36 #ifdef TRACE
37 vtrace("addstr() {%.*s}\n", ipbp->len1, ipbp->str1);
38 #endif
39 /* Add to backing store. */
40 memcpy(CharAt(__vi_screen, __vi_screen->cury, __vi_screen->curx),
41 ipbp->str1, ipbp->len1);
42 memset(FlagAt(__vi_screen, __vi_screen->cury, __vi_screen->curx),
43 __vi_screen->color, ipbp->len1);
45 /* Draw from backing store. */
46 __vi_draw_text(__vi_screen,
47 __vi_screen->cury, __vi_screen->curx, ipbp->len1);
49 /* Advance the caret. */
50 __vi_move_caret(__vi_screen,
51 __vi_screen->cury, __vi_screen->curx + ipbp->len1);
52 return (0);
55 static int
56 vi_attribute(ipbp)
57 IP_BUF *ipbp;
59 switch (ipbp->val1) {
60 case SA_ALTERNATE:
61 /* XXX: Nothing. */
62 break;
63 case SA_INVERSE:
64 __vi_screen->color = ipbp->val2;
65 break;
67 return (0);
70 static int
71 vi_bell(ipbp)
72 IP_BUF *ipbp;
75 * XXX
76 * Future... implement visible bell.
78 XBell(XtDisplay(__vi_screen->area), 0);
79 return (0);
82 static int
83 vi_busyon(ipbp)
84 IP_BUF *ipbp;
86 __vi_set_cursor(__vi_screen, 1);
87 return (0);
90 static int
91 vi_busyoff(ipbp)
92 IP_BUF *ipbp;
94 __vi_set_cursor(__vi_screen, 0);
95 return (0);
98 static int
99 vi_clrtoeol(ipbp)
100 IP_BUF *ipbp;
102 int len;
103 char *ptr;
105 len = __vi_screen->cols - __vi_screen->curx;
106 ptr = CharAt(__vi_screen, __vi_screen->cury, __vi_screen->curx);
108 /* Clear backing store. */
109 memset(ptr, ' ', len);
110 memset(FlagAt(__vi_screen, __vi_screen->cury, __vi_screen->curx),
111 COLOR_STANDARD, len);
113 /* Draw from backing store. */
114 __vi_draw_text(__vi_screen, __vi_screen->cury, __vi_screen->curx, len);
116 return (0);
119 static int
120 vi_deleteln(ipbp)
121 IP_BUF *ipbp;
123 int y, rows, len, height, width;
125 y = __vi_screen->cury;
126 rows = __vi_screen->rows - (y+1);
127 len = __vi_screen->cols * rows;
129 /* Don't want to copy the caret! */
130 __vi_erase_caret(__vi_screen);
132 /* Adjust backing store and the flags. */
133 memmove(CharAt(__vi_screen, y, 0), CharAt(__vi_screen, y+1, 0), len);
134 memmove(FlagAt(__vi_screen, y, 0), FlagAt(__vi_screen, y+1, 0), len);
136 /* Move the bits on the screen. */
137 width = __vi_screen->ch_width * __vi_screen->cols;
138 height = __vi_screen->ch_height * rows;
139 XCopyArea(XtDisplay(__vi_screen->area), /* display */
140 XtWindow(__vi_screen->area), /* src */
141 XtWindow(__vi_screen->area), /* dest */
142 __vi_copy_gc, /* context */
143 0, YTOP(__vi_screen, y+1), /* srcx, srcy */
144 width, height,
145 0, YTOP(__vi_screen, y) /* dstx, dsty */
147 /* Need to let X take over. */
148 XmUpdateDisplay(__vi_screen->area);
150 return (1);
153 static int
154 vi_discard(ipbp)
155 IP_BUF *ipbp;
157 /* XXX: Nothing. */
158 return (0);
161 static int
162 vi_insertln(ipbp)
163 IP_BUF *ipbp;
165 int y, rows, height, width;
166 char *from, *to;
168 y = __vi_screen->cury;
169 rows = __vi_screen->rows - (1+y);
170 from = CharAt(__vi_screen, y, 0),
171 to = CharAt(__vi_screen, y+1, 0);
173 /* Don't want to copy the caret! */
174 __vi_erase_caret(__vi_screen);
176 /* Adjust backing store. */
177 memmove(to, from, __vi_screen->cols * rows);
178 memset(from, ' ', __vi_screen->cols);
180 /* And the backing store. */
181 from = FlagAt(__vi_screen, y, 0),
182 to = FlagAt(__vi_screen, y+1, 0);
183 memmove(to, from, __vi_screen->cols * rows);
184 memset(from, COLOR_STANDARD, __vi_screen->cols);
186 /* Move the bits on the screen. */
187 width = __vi_screen->ch_width * __vi_screen->cols;
188 height = __vi_screen->ch_height * rows;
190 XCopyArea(XtDisplay(__vi_screen->area), /* display */
191 XtWindow(__vi_screen->area), /* src */
192 XtWindow(__vi_screen->area), /* dest */
193 __vi_copy_gc, /* context */
194 0, YTOP(__vi_screen, y), /* srcx, srcy */
195 width, height,
196 0, YTOP(__vi_screen, y+1) /* dstx, dsty */
199 /* clear out the new space */
200 XClearArea(XtDisplay(__vi_screen->area), /* display */
201 XtWindow(__vi_screen->area), /* window */
202 0, YTOP(__vi_screen, y), /* srcx, srcy */
203 0, __vi_screen->ch_height, /* w=full, height */
204 True /* no exposures */
207 /* Need to let X take over. */
208 XmUpdateDisplay(__vi_screen->area);
210 return (1);
213 static int
214 vi_move(ipbp)
215 IP_BUF *ipbp;
217 __vi_move_caret(__vi_screen, ipbp->val1, ipbp->val2);
218 return (0);
221 static int
222 vi_redraw(ipbp)
223 IP_BUF *ipbp;
225 __vi_expose_func(0, __vi_screen, 0);
226 return (0);
229 static int
230 vi_refresh(ipbp)
231 IP_BUF *ipbp;
233 /* probably ok to scroll again */
234 __vi_clear_scroll_block();
236 /* if the tag stack widget is active, set the text field there
237 * to agree with the current caret position.
238 * Note that this really ought to be done by core due to wrapping issues
240 __vi_set_word_at_caret( __vi_screen );
242 /* similarly, the text ruler... */
243 __vi_set_text_ruler( __vi_screen->cury, __vi_screen->curx );
245 return (0);
248 static int
249 vi_quit(ipbp)
250 IP_BUF *ipbp;
252 if (__vi_exitp != NULL)
253 __vi_exitp();
255 return (0);
258 static int
259 vi_rename(ipbp)
260 IP_BUF *ipbp;
262 Widget shell;
263 size_t len;
264 const char *tail, *p;
266 /* For the icon, use the tail. */
267 for (p = ipbp->str1, len = ipbp->len1; len > 1; ++p, --len)
268 if (p[0] == '/')
269 tail = p + 1;
271 * XXX
272 * Future: Attach a title to each screen. For now, we change
273 * the title of the shell.
275 shell = __vi_screen->area;
276 while ( ! XtIsShell(shell) ) shell = XtParent(shell);
277 XtVaSetValues(shell,
278 XmNiconName, tail,
279 XmNtitle, ipbp->str1,
282 return (0);
285 static int
286 vi_rewrite(ipbp)
287 IP_BUF *ipbp;
289 /* XXX: Nothing. */
290 return (0);
294 static int
295 vi_scrollbar(ipbp)
296 IP_BUF *ipbp;
298 int top, size, maximum, old_max;
300 /* in the buffer,
301 * val1 contains the top visible line number
302 * val2 contains the number of visible lines
303 * val3 contains the number of lines in the file
305 top = ipbp->val1;
306 size = ipbp->val2;
307 maximum = ipbp->val3;
309 #if 0
310 fprintf( stderr, "Setting scrollbar\n" );
311 fprintf( stderr, "\tvalue\t\t%d\n", top );
312 fprintf( stderr, "\tsize\t\t%d\n", size );
313 fprintf( stderr, "\tmaximum\t\t%d\n", maximum );
314 #endif
316 /* armor plating. core thinks there are no lines in an
317 * empty file, but says we are on line 1
319 if ( top >= maximum ) {
320 #if 0
321 fprintf( stderr, "Correcting for top >= maximum\n" );
322 #endif
323 maximum = top + 1;
324 size = 1;
327 /* armor plating. core may think there are more
328 * lines visible than remain in the file
330 if ( top+size >= maximum ) {
331 #if 0
332 fprintf( stderr, "Correcting for top+size >= maximum\n" );
333 #endif
334 size = maximum - top;
337 /* need to increase the maximum before changing the values */
338 XtVaGetValues( __vi_screen->scroll, XmNmaximum, &old_max, 0 );
339 if ( maximum > old_max )
340 XtVaSetValues( __vi_screen->scroll, XmNmaximum, maximum, 0 );
342 /* change the rest of the values without generating a callback */
343 XmScrollBarSetValues( __vi_screen->scroll,
344 top,
345 size,
346 1, /* increment */
347 size, /* page_increment */
348 False /* do not notify me */
351 /* need to decrease the maximum after changing the values */
352 if ( maximum < old_max )
353 XtVaSetValues( __vi_screen->scroll, XmNmaximum, maximum, 0 );
355 /* done */
356 return (0);
359 static int
360 vi_select(ipbp)
361 IP_BUF *ipbp;
363 /* XXX: Nothing. */
364 return (0);
367 static int
368 vi_split(ipbp)
369 IP_BUF *ipbp;
371 /* XXX: Nothing. */
372 return (0);
375 int (*__vi_iplist[SI_EVENT_MAX]) __P((IP_BUF *)) = {
376 vi_addstr,
377 vi_attribute,
378 vi_bell,
379 vi_busyoff,
380 vi_busyon,
381 vi_clrtoeol,
382 vi_deleteln,
383 vi_discard,
384 __vi_editopt,
385 vi_insertln,
386 vi_move,
387 vi_quit,
388 vi_redraw,
389 vi_refresh,
390 vi_rename,
391 NULL,
392 vi_rewrite,
393 vi_scrollbar,
394 vi_select,
395 vi_split