3 * Rob Zimmermann. All rights reserved.
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
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 $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <Xm/PanedW.h>
20 #include <Xm/ScrollBar.h>
22 #include <bitstring.h>
27 #include "../common/common.h"
28 #include "../ipc/ip.h"
37 vtrace("addstr() {%.*s}\n", ipbp
->len1
, ipbp
->str1
);
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
);
64 __vi_screen
->color
= ipbp
->val2
;
76 * Future... implement visible bell.
78 XBell(XtDisplay(__vi_screen
->area
), 0);
86 __vi_set_cursor(__vi_screen
, 1);
94 __vi_set_cursor(__vi_screen
, 0);
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
);
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 */
145 0, YTOP(__vi_screen
, y
) /* dstx, dsty */
147 /* Need to let X take over. */
148 XmUpdateDisplay(__vi_screen
->area
);
165 int y
, rows
, height
, width
;
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 */
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
);
217 __vi_move_caret(__vi_screen
, ipbp
->val1
, ipbp
->val2
);
225 __vi_expose_func(0, __vi_screen
, 0);
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
);
252 if (__vi_exitp
!= NULL
)
264 const char *tail
, *p
;
266 /* For the icon, use the tail. */
267 for (p
= ipbp
->str1
, len
= ipbp
->len1
; len
> 1; ++p
, --len
)
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
);
279 XmNtitle
, ipbp
->str1
,
298 int top
, size
, maximum
, old_max
;
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
307 maximum
= ipbp
->val3
;
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
);
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
) {
321 fprintf( stderr
, "Correcting for top >= maximum\n" );
327 /* armor plating. core may think there are more
328 * lines visible than remain in the file
330 if ( top
+size
>= maximum
) {
332 fprintf( stderr
, "Correcting for top+size >= maximum\n" );
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
,
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 );
375 int (*__vi_iplist
[SI_EVENT_MAX
]) __P((IP_BUF
*)) = {