dist/distrib: generate vi.0
[nvi.git] / motif_l / m_func.c
blob27650beb7f67cb43ee598883c062505c0b143220
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.28 2003/11/05 17:09:59 skimo Exp $ (Berkeley) $Date: 2003/11/05 17:09:59 $";
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 #undef LOCK_SUCCESS
28 #include "../common/common.h"
29 #include "../ipc/ip.h"
30 #include "m_motif.h"
33 static int
34 vi_addstr(int ipvi, char *str1, u_int32_t len1)
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 str1, len1);
42 memset(FlagAt(__vi_screen, __vi_screen->cury, __vi_screen->curx),
43 __vi_screen->color, len1);
45 /* Draw from backing store. */
46 __vi_draw_text(__vi_screen,
47 __vi_screen->cury, __vi_screen->curx, len1);
49 /* Advance the caret. */
50 __vi_move_caret(__vi_screen,
51 __vi_screen->cury, __vi_screen->curx + len1);
52 return (0);
55 static int
56 vi_attribute(int ipvi, u_int32_t val1, u_int32_t val2)
58 switch (val1) {
59 case SA_ALTERNATE:
60 /* XXX: Nothing. */
61 break;
62 case SA_INVERSE:
63 __vi_screen->color = val2;
64 break;
66 return (0);
69 static int
70 vi_bell(int ipvi)
73 * XXX
74 * Future... implement visible bell.
76 XBell(XtDisplay(__vi_screen->area), 0);
77 return (0);
80 static int
81 vi_busyon(int ipvi, char *str1, u_int32_t len1)
83 __vi_set_cursor(__vi_screen, 1);
84 return (0);
87 static int
88 vi_busyoff(int ipvi)
90 __vi_set_cursor(__vi_screen, 0);
91 return (0);
94 static int
95 vi_clrtoeol(int ipvi)
97 int len;
98 char *ptr;
100 len = __vi_screen->cols - __vi_screen->curx;
101 ptr = CharAt(__vi_screen, __vi_screen->cury, __vi_screen->curx);
103 /* Clear backing store. */
104 memset(ptr, ' ', len);
105 memset(FlagAt(__vi_screen, __vi_screen->cury, __vi_screen->curx),
106 COLOR_STANDARD, len);
108 /* Draw from backing store. */
109 __vi_draw_text(__vi_screen, __vi_screen->cury, __vi_screen->curx, len);
111 return (0);
114 static int
115 vi_deleteln(int ipvi)
117 int y, rows, len, height, width;
119 y = __vi_screen->cury;
120 rows = __vi_screen->rows - (y+1);
121 len = __vi_screen->cols * rows;
123 /* Don't want to copy the caret! */
124 __vi_erase_caret(__vi_screen);
126 /* Adjust backing store and the flags. */
127 memmove(CharAt(__vi_screen, y, 0), CharAt(__vi_screen, y+1, 0), len);
128 memmove(FlagAt(__vi_screen, y, 0), FlagAt(__vi_screen, y+1, 0), len);
130 /* Move the bits on the screen. */
131 width = __vi_screen->ch_width * __vi_screen->cols;
132 height = __vi_screen->ch_height * rows;
133 XCopyArea(XtDisplay(__vi_screen->area), /* display */
134 XtWindow(__vi_screen->area), /* src */
135 XtWindow(__vi_screen->area), /* dest */
136 __vi_copy_gc, /* context */
137 0, YTOP(__vi_screen, y+1), /* srcx, srcy */
138 width, height,
139 0, YTOP(__vi_screen, y) /* dstx, dsty */
141 /* Need to let X take over. */
142 XmUpdateDisplay(__vi_screen->area);
144 return (0);
147 static int
148 vi_discard(int ipvi)
150 /* XXX: Nothing. */
151 return (0);
154 static int
155 vi_insertln(int ipvi)
157 int y, rows, height, width;
158 char *from, *to;
160 y = __vi_screen->cury;
161 rows = __vi_screen->rows - (1+y);
162 from = CharAt(__vi_screen, y, 0),
163 to = CharAt(__vi_screen, y+1, 0);
165 /* Don't want to copy the caret! */
166 __vi_erase_caret(__vi_screen);
168 /* Adjust backing store. */
169 memmove(to, from, __vi_screen->cols * rows);
170 memset(from, ' ', __vi_screen->cols);
172 /* And the backing store. */
173 from = FlagAt(__vi_screen, y, 0),
174 to = FlagAt(__vi_screen, y+1, 0);
175 memmove(to, from, __vi_screen->cols * rows);
176 memset(from, COLOR_STANDARD, __vi_screen->cols);
178 /* Move the bits on the screen. */
179 width = __vi_screen->ch_width * __vi_screen->cols;
180 height = __vi_screen->ch_height * rows;
182 XCopyArea(XtDisplay(__vi_screen->area), /* display */
183 XtWindow(__vi_screen->area), /* src */
184 XtWindow(__vi_screen->area), /* dest */
185 __vi_copy_gc, /* context */
186 0, YTOP(__vi_screen, y), /* srcx, srcy */
187 width, height,
188 0, YTOP(__vi_screen, y+1) /* dstx, dsty */
191 /* clear out the new space */
192 XClearArea(XtDisplay(__vi_screen->area), /* display */
193 XtWindow(__vi_screen->area), /* window */
194 0, YTOP(__vi_screen, y), /* srcx, srcy */
195 0, __vi_screen->ch_height, /* w=full, height */
196 True /* no exposures */
199 /* Need to let X take over. */
200 XmUpdateDisplay(__vi_screen->area);
202 return (0);
205 static int
206 vi_move(int ipvi, u_int32_t val1, u_int32_t val2)
208 __vi_move_caret(__vi_screen, val1, val2);
209 return (0);
212 static int
213 vi_redraw(int ipvi)
215 __vi_expose_func(0, __vi_screen, 0);
216 return (0);
219 static int
220 vi_refresh(int ipvi)
222 /* probably ok to scroll again */
223 __vi_clear_scroll_block();
225 /* if the tag stack widget is active, set the text field there
226 * to agree with the current caret position.
227 * Note that this really ought to be done by core due to wrapping issues
229 __vi_set_word_at_caret( __vi_screen );
231 /* similarly, the text ruler... */
232 __vi_set_text_ruler( __vi_screen->cury, __vi_screen->curx );
234 return (0);
237 static int
238 vi_quit(int ipvi)
240 if (__vi_exitp != NULL)
241 __vi_exitp();
243 return (0);
246 static int
247 vi_rename(int ipvi, char *str1, u_int32_t len1)
249 Widget shell;
250 size_t len;
251 const char *tail, *p;
253 /* For the icon, use the tail. */
254 for (p = str1, len = len1; len > 1; ++p, --len)
255 if (p[0] == '/')
256 tail = p + 1;
258 * XXX
259 * Future: Attach a title to each screen. For now, we change
260 * the title of the shell.
262 shell = __vi_screen->area;
263 while ( ! XtIsShell(shell) ) shell = XtParent(shell);
264 XtVaSetValues(shell,
265 XmNiconName, tail,
266 XmNtitle, str1,
269 return (0);
272 static int
273 vi_rewrite(int ipvi, u_int32_t val1)
275 /* XXX: Nothing. */
276 return (0);
280 static int
281 vi_scrollbar(int ipvi, u_int32_t val1, u_int32_t val2, u_int32_t val3)
283 int top, size, maximum, old_max;
285 /* in the buffer,
286 * val1 contains the top visible line number
287 * val2 contains the number of visible lines
288 * val3 contains the number of lines in the file
290 top = val1;
291 size = val2;
292 maximum = val3;
294 #if 0
295 fprintf( stderr, "Setting scrollbar\n" );
296 fprintf( stderr, "\tvalue\t\t%d\n", top );
297 fprintf( stderr, "\tsize\t\t%d\n", size );
298 fprintf( stderr, "\tmaximum\t\t%d\n", maximum );
299 #endif
301 /* armor plating. core thinks there are no lines in an
302 * empty file, but says we are on line 1
304 if ( top >= maximum ) {
305 #if 0
306 fprintf( stderr, "Correcting for top >= maximum\n" );
307 #endif
308 maximum = top + 1;
309 size = 1;
312 /* armor plating. core may think there are more
313 * lines visible than remain in the file
315 if ( top+size >= maximum ) {
316 #if 0
317 fprintf( stderr, "Correcting for top+size >= maximum\n" );
318 #endif
319 size = maximum - top;
322 /* need to increase the maximum before changing the values */
323 XtVaGetValues( __vi_screen->scroll, XmNmaximum, &old_max, 0 );
324 if ( maximum > old_max )
325 XtVaSetValues( __vi_screen->scroll, XmNmaximum, maximum, 0 );
327 /* change the rest of the values without generating a callback */
328 XmScrollBarSetValues( __vi_screen->scroll,
329 top,
330 size,
331 1, /* increment */
332 size, /* page_increment */
333 False /* do not notify me */
336 /* need to decrease the maximum after changing the values */
337 if ( maximum < old_max )
338 XtVaSetValues( __vi_screen->scroll, XmNmaximum, maximum, 0 );
340 /* done */
341 return (0);
344 static int
345 vi_select(int ipvi, char *str1, u_int32_t len1)
347 /* XXX: Nothing. */
348 return (0);
351 static int
352 vi_split(int ipvi)
354 /* XXX: Nothing. */
355 return (0);
358 IPSIOPS ipsi_ops_motif = {
359 vi_addstr,
360 vi_attribute,
361 vi_bell,
362 vi_busyoff,
363 vi_busyon,
364 vi_clrtoeol,
365 vi_deleteln,
366 vi_discard,
367 __vi_editopt,
368 vi_insertln,
369 vi_move,
370 vi_quit,
371 vi_redraw,
372 vi_refresh,
373 vi_rename,
374 vi_rewrite,
375 vi_scrollbar,
376 vi_select,
377 vi_split,
378 vi_addstr,