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.28 2003/11/05 17:09:59 skimo Exp (Berkeley) Date: 2003/11/05 17:09:59 ";
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <Xm/PanedW.h>
20 #include <Xm/ScrollBar.h>
22 #include <bitstring.h>
28 #include "../common/common.h"
29 #include "../ipc/ip.h"
34 vi_addstr(int ipvi
, char *str1
, u_int32_t len1
)
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
),
42 memset(FlagAt(__vi_screen
, __vi_screen
->cury
, __vi_screen
->curx
),
43 __vi_screen
->color
, len1
);
45 /* Draw from backing store. */
46 __vi_draw_text(__vi_screen
,
47 __vi_screen
->cury
, __vi_screen
->curx
, len1
);
49 /* Advance the caret. */
50 __vi_move_caret(__vi_screen
,
51 __vi_screen
->cury
, __vi_screen
->curx
+ len1
);
56 vi_attribute(int ipvi
, u_int32_t val1
, u_int32_t val2
)
63 __vi_screen
->color
= val2
;
74 * Future... implement visible bell.
76 XBell(XtDisplay(__vi_screen
->area
), 0);
81 vi_busyon(int ipvi
, char *str1
, u_int32_t len1
)
83 __vi_set_cursor(__vi_screen
, 1);
90 __vi_set_cursor(__vi_screen
, 0);
100 len
= __vi_screen
->cols
- __vi_screen
->curx
;
101 ptr
= CharAt(__vi_screen
, __vi_screen
->cury
, __vi_screen
->curx
);
103 /* Clear backing store. */
104 memset(ptr
, ' ', len
);
105 memset(FlagAt(__vi_screen
, __vi_screen
->cury
, __vi_screen
->curx
),
106 COLOR_STANDARD
, len
);
108 /* Draw from backing store. */
109 __vi_draw_text(__vi_screen
, __vi_screen
->cury
, __vi_screen
->curx
, len
);
115 vi_deleteln(int ipvi
)
117 int y
, rows
, len
, height
, width
;
119 y
= __vi_screen
->cury
;
120 rows
= __vi_screen
->rows
- (y
+1);
121 len
= __vi_screen
->cols
* rows
;
123 /* Don't want to copy the caret! */
124 __vi_erase_caret(__vi_screen
);
126 /* Adjust backing store and the flags. */
127 memmove(CharAt(__vi_screen
, y
, 0), CharAt(__vi_screen
, y
+1, 0), len
);
128 memmove(FlagAt(__vi_screen
, y
, 0), FlagAt(__vi_screen
, y
+1, 0), len
);
130 /* Move the bits on the screen. */
131 width
= __vi_screen
->ch_width
* __vi_screen
->cols
;
132 height
= __vi_screen
->ch_height
* rows
;
133 XCopyArea(XtDisplay(__vi_screen
->area
), /* display */
134 XtWindow(__vi_screen
->area
), /* src */
135 XtWindow(__vi_screen
->area
), /* dest */
136 __vi_copy_gc
, /* context */
137 0, YTOP(__vi_screen
, y
+1), /* srcx, srcy */
139 0, YTOP(__vi_screen
, y
) /* dstx, dsty */
141 /* Need to let X take over. */
142 XmUpdateDisplay(__vi_screen
->area
);
155 vi_insertln(int ipvi
)
157 int y
, rows
, height
, width
;
160 y
= __vi_screen
->cury
;
161 rows
= __vi_screen
->rows
- (1+y
);
162 from
= CharAt(__vi_screen
, y
, 0),
163 to
= CharAt(__vi_screen
, y
+1, 0);
165 /* Don't want to copy the caret! */
166 __vi_erase_caret(__vi_screen
);
168 /* Adjust backing store. */
169 memmove(to
, from
, __vi_screen
->cols
* rows
);
170 memset(from
, ' ', __vi_screen
->cols
);
172 /* And the backing store. */
173 from
= FlagAt(__vi_screen
, y
, 0),
174 to
= FlagAt(__vi_screen
, y
+1, 0);
175 memmove(to
, from
, __vi_screen
->cols
* rows
);
176 memset(from
, COLOR_STANDARD
, __vi_screen
->cols
);
178 /* Move the bits on the screen. */
179 width
= __vi_screen
->ch_width
* __vi_screen
->cols
;
180 height
= __vi_screen
->ch_height
* rows
;
182 XCopyArea(XtDisplay(__vi_screen
->area
), /* display */
183 XtWindow(__vi_screen
->area
), /* src */
184 XtWindow(__vi_screen
->area
), /* dest */
185 __vi_copy_gc
, /* context */
186 0, YTOP(__vi_screen
, y
), /* srcx, srcy */
188 0, YTOP(__vi_screen
, y
+1) /* dstx, dsty */
191 /* clear out the new space */
192 XClearArea(XtDisplay(__vi_screen
->area
), /* display */
193 XtWindow(__vi_screen
->area
), /* window */
194 0, YTOP(__vi_screen
, y
), /* srcx, srcy */
195 0, __vi_screen
->ch_height
, /* w=full, height */
196 True
/* no exposures */
199 /* Need to let X take over. */
200 XmUpdateDisplay(__vi_screen
->area
);
206 vi_move(int ipvi
, u_int32_t val1
, u_int32_t val2
)
208 __vi_move_caret(__vi_screen
, val1
, val2
);
215 __vi_expose_func(0, __vi_screen
, 0);
222 /* probably ok to scroll again */
223 __vi_clear_scroll_block();
225 /* if the tag stack widget is active, set the text field there
226 * to agree with the current caret position.
227 * Note that this really ought to be done by core due to wrapping issues
229 __vi_set_word_at_caret( __vi_screen
);
231 /* similarly, the text ruler... */
232 __vi_set_text_ruler( __vi_screen
->cury
, __vi_screen
->curx
);
240 if (__vi_exitp
!= NULL
)
247 vi_rename(int ipvi
, char *str1
, u_int32_t len1
)
251 const char *tail
, *p
;
253 /* For the icon, use the tail. */
254 for (p
= str1
, len
= len1
; len
> 1; ++p
, --len
)
259 * Future: Attach a title to each screen. For now, we change
260 * the title of the shell.
262 shell
= __vi_screen
->area
;
263 while ( ! XtIsShell(shell
) ) shell
= XtParent(shell
);
273 vi_rewrite(int ipvi
, u_int32_t val1
)
281 vi_scrollbar(int ipvi
, u_int32_t val1
, u_int32_t val2
, u_int32_t val3
)
283 int top
, size
, maximum
, old_max
;
286 * val1 contains the top visible line number
287 * val2 contains the number of visible lines
288 * val3 contains the number of lines in the file
295 fprintf( stderr
, "Setting scrollbar\n" );
296 fprintf( stderr
, "\tvalue\t\t%d\n", top
);
297 fprintf( stderr
, "\tsize\t\t%d\n", size
);
298 fprintf( stderr
, "\tmaximum\t\t%d\n", maximum
);
301 /* armor plating. core thinks there are no lines in an
302 * empty file, but says we are on line 1
304 if ( top
>= maximum
) {
306 fprintf( stderr
, "Correcting for top >= maximum\n" );
312 /* armor plating. core may think there are more
313 * lines visible than remain in the file
315 if ( top
+size
>= maximum
) {
317 fprintf( stderr
, "Correcting for top+size >= maximum\n" );
319 size
= maximum
- top
;
322 /* need to increase the maximum before changing the values */
323 XtVaGetValues( __vi_screen
->scroll
, XmNmaximum
, &old_max
, 0 );
324 if ( maximum
> old_max
)
325 XtVaSetValues( __vi_screen
->scroll
, XmNmaximum
, maximum
, 0 );
327 /* change the rest of the values without generating a callback */
328 XmScrollBarSetValues( __vi_screen
->scroll
,
332 size
, /* page_increment */
333 False
/* do not notify me */
336 /* need to decrease the maximum after changing the values */
337 if ( maximum
< old_max
)
338 XtVaSetValues( __vi_screen
->scroll
, XmNmaximum
, maximum
, 0 );
345 vi_select(int ipvi
, char *str1
, u_int32_t len1
)
358 IPSIOPS ipsi_ops_motif
= {