Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / nvi / motif_l / m_func.c
blobba8d622d9910baefeac0dedd8c52a0b3485276be
1 /* $NetBSD$ */
3 /*-
4 * Copyright (c) 1996
5 * Rob Zimmermann. All rights reserved.
6 * Copyright (c) 1996
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
12 #include "config.h"
14 #ifndef lint
15 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";
16 #endif /* not lint */
18 #include <sys/types.h>
19 #include <sys/queue.h>
21 #include <Xm/PanedW.h>
22 #include <Xm/ScrollBar.h>
24 #include <bitstring.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
29 #undef LOCK_SUCCESS
30 #include "../common/common.h"
31 #include "../ipc/ip.h"
32 #include "m_motif.h"
35 static int
36 vi_addstr(int ipvi, char *str1, u_int32_t len1)
38 #ifdef TRACE
39 vtrace("addstr() {%.*s}\n", ipbp->len1, ipbp->str1);
40 #endif
41 /* Add to backing store. */
42 memcpy(CharAt(__vi_screen, __vi_screen->cury, __vi_screen->curx),
43 str1, len1);
44 memset(FlagAt(__vi_screen, __vi_screen->cury, __vi_screen->curx),
45 __vi_screen->color, len1);
47 /* Draw from backing store. */
48 __vi_draw_text(__vi_screen,
49 __vi_screen->cury, __vi_screen->curx, len1);
51 /* Advance the caret. */
52 __vi_move_caret(__vi_screen,
53 __vi_screen->cury, __vi_screen->curx + len1);
54 return (0);
57 static int
58 vi_attribute(int ipvi, u_int32_t val1, u_int32_t val2)
60 switch (val1) {
61 case SA_ALTERNATE:
62 /* XXX: Nothing. */
63 break;
64 case SA_INVERSE:
65 __vi_screen->color = val2;
66 break;
68 return (0);
71 static int
72 vi_bell(int ipvi)
75 * XXX
76 * Future... implement visible bell.
78 XBell(XtDisplay(__vi_screen->area), 0);
79 return (0);
82 static int
83 vi_busyon(int ipvi, char *str1, u_int32_t len1)
85 __vi_set_cursor(__vi_screen, 1);
86 return (0);
89 static int
90 vi_busyoff(int ipvi)
92 __vi_set_cursor(__vi_screen, 0);
93 return (0);
96 static int
97 vi_clrtoeol(int ipvi)
99 int len;
100 char *ptr;
102 len = __vi_screen->cols - __vi_screen->curx;
103 ptr = CharAt(__vi_screen, __vi_screen->cury, __vi_screen->curx);
105 /* Clear backing store. */
106 memset(ptr, ' ', len);
107 memset(FlagAt(__vi_screen, __vi_screen->cury, __vi_screen->curx),
108 COLOR_STANDARD, len);
110 /* Draw from backing store. */
111 __vi_draw_text(__vi_screen, __vi_screen->cury, __vi_screen->curx, len);
113 return (0);
116 static int
117 vi_deleteln(int ipvi)
119 int y, rows, len, height, width;
121 y = __vi_screen->cury;
122 rows = __vi_screen->rows - (y+1);
123 len = __vi_screen->cols * rows;
125 /* Don't want to copy the caret! */
126 __vi_erase_caret(__vi_screen);
128 /* Adjust backing store and the flags. */
129 memmove(CharAt(__vi_screen, y, 0), CharAt(__vi_screen, y+1, 0), len);
130 memmove(FlagAt(__vi_screen, y, 0), FlagAt(__vi_screen, y+1, 0), len);
132 /* Move the bits on the screen. */
133 width = __vi_screen->ch_width * __vi_screen->cols;
134 height = __vi_screen->ch_height * rows;
135 XCopyArea(XtDisplay(__vi_screen->area), /* display */
136 XtWindow(__vi_screen->area), /* src */
137 XtWindow(__vi_screen->area), /* dest */
138 __vi_copy_gc, /* context */
139 0, YTOP(__vi_screen, y+1), /* srcx, srcy */
140 width, height,
141 0, YTOP(__vi_screen, y) /* dstx, dsty */
143 /* Need to let X take over. */
144 XmUpdateDisplay(__vi_screen->area);
146 return (0);
149 static int
150 vi_discard(int ipvi)
152 /* XXX: Nothing. */
153 return (0);
156 static int
157 vi_insertln(int ipvi)
159 int y, rows, height, width;
160 char *from, *to;
162 y = __vi_screen->cury;
163 rows = __vi_screen->rows - (1+y);
164 from = CharAt(__vi_screen, y, 0),
165 to = CharAt(__vi_screen, y+1, 0);
167 /* Don't want to copy the caret! */
168 __vi_erase_caret(__vi_screen);
170 /* Adjust backing store. */
171 memmove(to, from, __vi_screen->cols * rows);
172 memset(from, ' ', __vi_screen->cols);
174 /* And the backing store. */
175 from = FlagAt(__vi_screen, y, 0),
176 to = FlagAt(__vi_screen, y+1, 0);
177 memmove(to, from, __vi_screen->cols * rows);
178 memset(from, COLOR_STANDARD, __vi_screen->cols);
180 /* Move the bits on the screen. */
181 width = __vi_screen->ch_width * __vi_screen->cols;
182 height = __vi_screen->ch_height * rows;
184 XCopyArea(XtDisplay(__vi_screen->area), /* display */
185 XtWindow(__vi_screen->area), /* src */
186 XtWindow(__vi_screen->area), /* dest */
187 __vi_copy_gc, /* context */
188 0, YTOP(__vi_screen, y), /* srcx, srcy */
189 width, height,
190 0, YTOP(__vi_screen, y+1) /* dstx, dsty */
193 /* clear out the new space */
194 XClearArea(XtDisplay(__vi_screen->area), /* display */
195 XtWindow(__vi_screen->area), /* window */
196 0, YTOP(__vi_screen, y), /* srcx, srcy */
197 0, __vi_screen->ch_height, /* w=full, height */
198 True /* no exposures */
201 /* Need to let X take over. */
202 XmUpdateDisplay(__vi_screen->area);
204 return (0);
207 static int
208 vi_move(int ipvi, u_int32_t val1, u_int32_t val2)
210 __vi_move_caret(__vi_screen, val1, val2);
211 return (0);
214 static int
215 vi_redraw(int ipvi)
217 __vi_expose_func(0, __vi_screen, 0);
218 return (0);
221 static int
222 vi_refresh(int ipvi)
224 /* probably ok to scroll again */
225 __vi_clear_scroll_block();
227 /* if the tag stack widget is active, set the text field there
228 * to agree with the current caret position.
229 * Note that this really ought to be done by core due to wrapping issues
231 __vi_set_word_at_caret( __vi_screen );
233 /* similarly, the text ruler... */
234 __vi_set_text_ruler( __vi_screen->cury, __vi_screen->curx );
236 return (0);
239 static int
240 vi_quit(int ipvi)
242 if (__vi_exitp != NULL)
243 __vi_exitp();
245 return (0);
248 static int
249 vi_rename(int ipvi, char *str1, u_int32_t len1)
251 Widget shell;
252 size_t len;
253 const char *tail, *p;
255 /* For the icon, use the tail. */
256 for (p = str1, len = len1; len > 1; ++p, --len)
257 if (p[0] == '/')
258 tail = p + 1;
260 * XXX
261 * Future: Attach a title to each screen. For now, we change
262 * the title of the shell.
264 shell = __vi_screen->area;
265 while ( ! XtIsShell(shell) ) shell = XtParent(shell);
266 XtVaSetValues(shell,
267 XmNiconName, tail,
268 XmNtitle, str1,
271 return (0);
274 static int
275 vi_rewrite(int ipvi, u_int32_t val1)
277 /* XXX: Nothing. */
278 return (0);
282 static int
283 vi_scrollbar(int ipvi, u_int32_t val1, u_int32_t val2, u_int32_t val3)
285 int top, size, maximum, old_max;
287 /* in the buffer,
288 * val1 contains the top visible line number
289 * val2 contains the number of visible lines
290 * val3 contains the number of lines in the file
292 top = val1;
293 size = val2;
294 maximum = val3;
296 #if 0
297 fprintf( stderr, "Setting scrollbar\n" );
298 fprintf( stderr, "\tvalue\t\t%d\n", top );
299 fprintf( stderr, "\tsize\t\t%d\n", size );
300 fprintf( stderr, "\tmaximum\t\t%d\n", maximum );
301 #endif
303 /* armor plating. core thinks there are no lines in an
304 * empty file, but says we are on line 1
306 if ( top >= maximum ) {
307 #if 0
308 fprintf( stderr, "Correcting for top >= maximum\n" );
309 #endif
310 maximum = top + 1;
311 size = 1;
314 /* armor plating. core may think there are more
315 * lines visible than remain in the file
317 if ( top+size >= maximum ) {
318 #if 0
319 fprintf( stderr, "Correcting for top+size >= maximum\n" );
320 #endif
321 size = maximum - top;
324 /* need to increase the maximum before changing the values */
325 XtVaGetValues( __vi_screen->scroll, XmNmaximum, &old_max, 0 );
326 if ( maximum > old_max )
327 XtVaSetValues( __vi_screen->scroll, XmNmaximum, maximum, 0 );
329 /* change the rest of the values without generating a callback */
330 XmScrollBarSetValues( __vi_screen->scroll,
331 top,
332 size,
333 1, /* increment */
334 size, /* page_increment */
335 False /* do not notify me */
338 /* need to decrease the maximum after changing the values */
339 if ( maximum < old_max )
340 XtVaSetValues( __vi_screen->scroll, XmNmaximum, maximum, 0 );
342 /* done */
343 return (0);
346 static int
347 vi_select(int ipvi, char *str1, u_int32_t len1)
349 /* XXX: Nothing. */
350 return (0);
353 static int
354 vi_split(int ipvi)
356 /* XXX: Nothing. */
357 return (0);
360 IPSIOPS ipsi_ops_motif = {
361 vi_addstr,
362 vi_attribute,
363 vi_bell,
364 vi_busyoff,
365 vi_busyon,
366 vi_clrtoeol,
367 vi_deleteln,
368 vi_discard,
369 __vi_editopt,
370 vi_insertln,
371 vi_move,
372 vi_quit,
373 vi_redraw,
374 vi_refresh,
375 vi_rename,
376 vi_rewrite,
377 vi_scrollbar,
378 vi_select,
379 vi_split,
380 vi_addstr,