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.25 2001/06/18 20:16:42 skimo Exp $ (Berkeley) $Date: 2001/06/18 20:16:42 $";
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"
33 vi_addstr(ipvi
, str1
, len1
)
38 vtrace("addstr() {%.*s}\n", ipbp
->len1
, ipbp
->str1
);
40 /* Add to backing store. */
41 memcpy(CharAt(__vi_screen
, __vi_screen
->cury
, __vi_screen
->curx
),
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
);
57 vi_attribute(ipvi
, val1
, val2
)
66 __vi_screen
->color
= val2
;
77 * Future... implement visible bell.
79 XBell(XtDisplay(__vi_screen
->area
), 0);
84 vi_busyon(ipvi
, str1
, len1
)
88 __vi_set_cursor(__vi_screen
, 1);
95 __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
);
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
);
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(ipvi
, val1
, val2
)
215 __vi_move_caret(__vi_screen
, val1
, val2
);
222 __vi_expose_func(0, __vi_screen
, 0);
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
);
247 if (__vi_exitp
!= NULL
)
254 vi_rename(ipvi
, str1
, len1
)
260 const char *tail
, *p
;
262 /* For the icon, use the tail. */
263 for (p
= str1
, len
= len1
; len
> 1; ++p
, --len
)
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
);
282 vi_rewrite(ipvi
, val1
)
291 vi_scrollbar(ipvi
, val1
, val2
, val3
)
296 int top
, size
, maximum
, old_max
;
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
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
);
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
) {
319 fprintf( stderr
, "Correcting for top >= maximum\n" );
325 /* armor plating. core may think there are more
326 * lines visible than remain in the file
328 if ( top
+size
>= maximum
) {
330 fprintf( stderr
, "Correcting for top+size >= maximum\n" );
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
,
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 );
358 vi_select(ipvi
, str1
, len1
)
373 IPSIOPS ipsi_ops_motif
= {