(failed ?) attempt at cleaner ip interface
[nvi.git] / motif_l / m_func.c
blobc1fd051557ed7b3b922c3a7edc13cc46bcdb6c4b
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.24 2000/07/05 11:33:18 skimo Exp $ (Berkeley) $Date: 2000/07/05 11:33:18 $";
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(ipvi, str1, len1)
34 char *str1;
35 u_int32_t len1;
37 #ifdef TRACE
38 vtrace("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 str1, len1);
43 memset(FlagAt(__vi_screen, __vi_screen->cury, __vi_screen->curx),
44 __vi_screen->color, len1);
46 /* Draw from backing store. */
47 __vi_draw_text(__vi_screen,
48 __vi_screen->cury, __vi_screen->curx, len1);
50 /* Advance the caret. */
51 __vi_move_caret(__vi_screen,
52 __vi_screen->cury, __vi_screen->curx + len1);
53 return (0);
56 static int
57 vi_attribute(ipvi, val1, val2)
58 u_int32_t val1;
59 u_int32_t val2;
61 switch (val1) {
62 case SA_ALTERNATE:
63 /* XXX: Nothing. */
64 break;
65 case SA_INVERSE:
66 __vi_screen->color = val2;
67 break;
69 return (0);
72 static int
73 vi_bell(ipvi)
76 * XXX
77 * Future... implement visible bell.
79 XBell(XtDisplay(__vi_screen->area), 0);
80 return (0);
83 static int
84 vi_busyon(ipvi, str1, len1)
85 char *str1;
86 u_int32_t len1;
88 __vi_set_cursor(__vi_screen, 1);
89 return (0);
92 static int
93 vi_busyoff(ipvi)
95 __vi_set_cursor(__vi_screen, 0);
96 return (0);
99 static int
100 vi_clrtoeol(ipvi)
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(ipvi)
122 int y, rows, len, height, width;
124 y = __vi_screen->cury;
125 rows = __vi_screen->rows - (y+1);
126 len = __vi_screen->cols * rows;
128 /* Don't want to copy the caret! */
129 __vi_erase_caret(__vi_screen);
131 /* Adjust backing store and the flags. */
132 memmove(CharAt(__vi_screen, y, 0), CharAt(__vi_screen, y+1, 0), len);
133 memmove(FlagAt(__vi_screen, y, 0), FlagAt(__vi_screen, y+1, 0), len);
135 /* Move the bits on the screen. */
136 width = __vi_screen->ch_width * __vi_screen->cols;
137 height = __vi_screen->ch_height * rows;
138 XCopyArea(XtDisplay(__vi_screen->area), /* display */
139 XtWindow(__vi_screen->area), /* src */
140 XtWindow(__vi_screen->area), /* dest */
141 __vi_copy_gc, /* context */
142 0, YTOP(__vi_screen, y+1), /* srcx, srcy */
143 width, height,
144 0, YTOP(__vi_screen, y) /* dstx, dsty */
146 /* Need to let X take over. */
147 XmUpdateDisplay(__vi_screen->area);
149 return (1);
152 static int
153 vi_discard(ipvi)
155 /* XXX: Nothing. */
156 return (0);
159 static int
160 vi_insertln(ipvi)
162 int y, rows, height, width;
163 char *from, *to;
165 y = __vi_screen->cury;
166 rows = __vi_screen->rows - (1+y);
167 from = CharAt(__vi_screen, y, 0),
168 to = CharAt(__vi_screen, y+1, 0);
170 /* Don't want to copy the caret! */
171 __vi_erase_caret(__vi_screen);
173 /* Adjust backing store. */
174 memmove(to, from, __vi_screen->cols * rows);
175 memset(from, ' ', __vi_screen->cols);
177 /* And the backing store. */
178 from = FlagAt(__vi_screen, y, 0),
179 to = FlagAt(__vi_screen, y+1, 0);
180 memmove(to, from, __vi_screen->cols * rows);
181 memset(from, COLOR_STANDARD, __vi_screen->cols);
183 /* Move the bits on the screen. */
184 width = __vi_screen->ch_width * __vi_screen->cols;
185 height = __vi_screen->ch_height * rows;
187 XCopyArea(XtDisplay(__vi_screen->area), /* display */
188 XtWindow(__vi_screen->area), /* src */
189 XtWindow(__vi_screen->area), /* dest */
190 __vi_copy_gc, /* context */
191 0, YTOP(__vi_screen, y), /* srcx, srcy */
192 width, height,
193 0, YTOP(__vi_screen, y+1) /* dstx, dsty */
196 /* clear out the new space */
197 XClearArea(XtDisplay(__vi_screen->area), /* display */
198 XtWindow(__vi_screen->area), /* window */
199 0, YTOP(__vi_screen, y), /* srcx, srcy */
200 0, __vi_screen->ch_height, /* w=full, height */
201 True /* no exposures */
204 /* Need to let X take over. */
205 XmUpdateDisplay(__vi_screen->area);
207 return (1);
210 static int
211 vi_move(ipvi, val1, val2)
212 u_int32_t val1;
213 u_int32_t val2;
215 __vi_move_caret(__vi_screen, val1, val2);
216 return (0);
219 static int
220 vi_redraw(ipvi)
222 __vi_expose_func(0, __vi_screen, 0);
223 return (0);
226 static int
227 vi_refresh(ipvi)
229 /* probably ok to scroll again */
230 __vi_clear_scroll_block();
232 /* if the tag stack widget is active, set the text field there
233 * to agree with the current caret position.
234 * Note that this really ought to be done by core due to wrapping issues
236 __vi_set_word_at_caret( __vi_screen );
238 /* similarly, the text ruler... */
239 __vi_set_text_ruler( __vi_screen->cury, __vi_screen->curx );
241 return (0);
244 static int
245 vi_quit(ipvi)
247 if (__vi_exitp != NULL)
248 __vi_exitp();
250 return (0);
253 static int
254 vi_rename(ipvi, str1, len1)
255 char *str1;
256 u_int32_t len1;
258 Widget shell;
259 size_t len;
260 const char *tail, *p;
262 /* For the icon, use the tail. */
263 for (p = str1, len = len1; len > 1; ++p, --len)
264 if (p[0] == '/')
265 tail = p + 1;
267 * XXX
268 * Future: Attach a title to each screen. For now, we change
269 * the title of the shell.
271 shell = __vi_screen->area;
272 while ( ! XtIsShell(shell) ) shell = XtParent(shell);
273 XtVaSetValues(shell,
274 XmNiconName, tail,
275 XmNtitle, str1,
278 return (0);
281 static int
282 vi_rewrite(ipvi, val1)
283 u_int32_t val1;
285 /* XXX: Nothing. */
286 return (0);
290 static int
291 vi_scrollbar(ipvi, val1, val2, val3)
292 u_int32_t val1;
293 u_int32_t val2;
294 u_int32_t val3;
296 int top, size, maximum, old_max;
298 /* in the buffer,
299 * val1 contains the top visible line number
300 * val2 contains the number of visible lines
301 * val3 contains the number of lines in the file
303 top = val1;
304 size = val2;
305 maximum = val3;
307 #if 0
308 fprintf( stderr, "Setting scrollbar\n" );
309 fprintf( stderr, "\tvalue\t\t%d\n", top );
310 fprintf( stderr, "\tsize\t\t%d\n", size );
311 fprintf( stderr, "\tmaximum\t\t%d\n", maximum );
312 #endif
314 /* armor plating. core thinks there are no lines in an
315 * empty file, but says we are on line 1
317 if ( top >= maximum ) {
318 #if 0
319 fprintf( stderr, "Correcting for top >= maximum\n" );
320 #endif
321 maximum = top + 1;
322 size = 1;
325 /* armor plating. core may think there are more
326 * lines visible than remain in the file
328 if ( top+size >= maximum ) {
329 #if 0
330 fprintf( stderr, "Correcting for top+size >= maximum\n" );
331 #endif
332 size = maximum - top;
335 /* need to increase the maximum before changing the values */
336 XtVaGetValues( __vi_screen->scroll, XmNmaximum, &old_max, 0 );
337 if ( maximum > old_max )
338 XtVaSetValues( __vi_screen->scroll, XmNmaximum, maximum, 0 );
340 /* change the rest of the values without generating a callback */
341 XmScrollBarSetValues( __vi_screen->scroll,
342 top,
343 size,
344 1, /* increment */
345 size, /* page_increment */
346 False /* do not notify me */
349 /* need to decrease the maximum after changing the values */
350 if ( maximum < old_max )
351 XtVaSetValues( __vi_screen->scroll, XmNmaximum, maximum, 0 );
353 /* done */
354 return (0);
357 static int
358 vi_select(ipvi, str1, len1)
359 char *str1;
360 u_int32_t len1;
362 /* XXX: Nothing. */
363 return (0);
366 static int
367 vi_split(ipvi)
369 /* XXX: Nothing. */
370 return (0);
373 IPSIOPS ipsi_ops_motif = {
374 vi_addstr,
375 vi_attribute,
376 vi_bell,
377 vi_busyoff,
378 vi_busyon,
379 vi_clrtoeol,
380 vi_deleteln,
381 vi_discard,
382 __vi_editopt,
383 vi_insertln,
384 vi_move,
385 vi_quit,
386 vi_redraw,
387 vi_refresh,
388 vi_rename,
389 vi_rewrite,
390 vi_scrollbar,
391 vi_select,
392 vi_split,