3 * Rob Zimmermann. All rights reserved.
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
12 #include <sys/cdefs.h>
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 ";
18 __RCSID("$NetBSD: m_func.c,v 1.2 2014/01/26 21:43:45 christos Exp $");
21 #include <sys/types.h>
22 #include <sys/queue.h>
24 #include <Xm/PanedW.h>
25 #include <Xm/ScrollBar.h>
27 #include <bitstring.h>
33 #include "../common/common.h"
34 #include "../ipc/ip.h"
39 vi_addstr(int ipvi
, char *str1
, u_int32_t len1
)
42 vtrace("addstr() {%.*s}\n", ipbp
->len1
, ipbp
->str1
);
44 /* Add to backing store. */
45 memcpy(CharAt(__vi_screen
, __vi_screen
->cury
, __vi_screen
->curx
),
47 memset(FlagAt(__vi_screen
, __vi_screen
->cury
, __vi_screen
->curx
),
48 __vi_screen
->color
, len1
);
50 /* Draw from backing store. */
51 __vi_draw_text(__vi_screen
,
52 __vi_screen
->cury
, __vi_screen
->curx
, len1
);
54 /* Advance the caret. */
55 __vi_move_caret(__vi_screen
,
56 __vi_screen
->cury
, __vi_screen
->curx
+ len1
);
61 vi_attribute(int ipvi
, u_int32_t val1
, u_int32_t val2
)
68 __vi_screen
->color
= val2
;
79 * Future... implement visible bell.
81 XBell(XtDisplay(__vi_screen
->area
), 0);
86 vi_busyon(int ipvi
, char *str1
, u_int32_t len1
)
88 __vi_set_cursor(__vi_screen
, 1);
95 __vi_set_cursor(__vi_screen
, 0);
100 vi_clrtoeol(int ipvi
)
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
);
120 vi_deleteln(int 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 */
144 0, YTOP(__vi_screen
, y
) /* dstx, dsty */
146 /* Need to let X take over. */
147 XmUpdateDisplay(__vi_screen
->area
);
160 vi_insertln(int ipvi
)
162 int y
, rows
, height
, width
;
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 */
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
);
211 vi_move(int ipvi
, u_int32_t val1
, u_int32_t val2
)
213 __vi_move_caret(__vi_screen
, val1
, val2
);
220 __vi_expose_func(0, __vi_screen
, 0);
227 /* probably ok to scroll again */
228 __vi_clear_scroll_block();
230 /* if the tag stack widget is active, set the text field there
231 * to agree with the current caret position.
232 * Note that this really ought to be done by core due to wrapping issues
234 __vi_set_word_at_caret( __vi_screen
);
236 /* similarly, the text ruler... */
237 __vi_set_text_ruler( __vi_screen
->cury
, __vi_screen
->curx
);
245 if (__vi_exitp
!= NULL
)
252 vi_rename(int ipvi
, char *str1
, u_int32_t len1
)
256 const char *tail
, *p
;
258 /* For the icon, use the tail. */
259 for (p
= str1
, len
= len1
; len
> 1; ++p
, --len
)
264 * Future: Attach a title to each screen. For now, we change
265 * the title of the shell.
267 shell
= __vi_screen
->area
;
268 while ( ! XtIsShell(shell
) ) shell
= XtParent(shell
);
278 vi_rewrite(int ipvi
, u_int32_t val1
)
286 vi_scrollbar(int ipvi
, u_int32_t val1
, u_int32_t val2
, u_int32_t val3
)
288 int top
, size
, maximum
, old_max
;
291 * val1 contains the top visible line number
292 * val2 contains the number of visible lines
293 * val3 contains the number of lines in the file
300 fprintf( stderr
, "Setting scrollbar\n" );
301 fprintf( stderr
, "\tvalue\t\t%d\n", top
);
302 fprintf( stderr
, "\tsize\t\t%d\n", size
);
303 fprintf( stderr
, "\tmaximum\t\t%d\n", maximum
);
306 /* armor plating. core thinks there are no lines in an
307 * empty file, but says we are on line 1
309 if ( top
>= maximum
) {
311 fprintf( stderr
, "Correcting for top >= maximum\n" );
317 /* armor plating. core may think there are more
318 * lines visible than remain in the file
320 if ( top
+size
>= maximum
) {
322 fprintf( stderr
, "Correcting for top+size >= maximum\n" );
324 size
= maximum
- top
;
327 /* need to increase the maximum before changing the values */
328 XtVaGetValues( __vi_screen
->scroll
, XmNmaximum
, &old_max
, 0 );
329 if ( maximum
> old_max
)
330 XtVaSetValues( __vi_screen
->scroll
, XmNmaximum
, maximum
, 0 );
332 /* change the rest of the values without generating a callback */
333 XmScrollBarSetValues( __vi_screen
->scroll
,
337 size
, /* page_increment */
338 False
/* do not notify me */
341 /* need to decrease the maximum after changing the values */
342 if ( maximum
< old_max
)
343 XtVaSetValues( __vi_screen
->scroll
, XmNmaximum
, maximum
, 0 );
350 vi_select(int ipvi
, char *str1
, u_int32_t len1
)
363 IPSIOPS ipsi_ops_motif
= {