5 * Rob Zimmermann. All rights reserved.
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
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 #include <sys/types.h>
19 #include <sys/queue.h>
21 #include <Xm/PanedW.h>
22 #include <Xm/ScrollBar.h>
24 #include <bitstring.h>
30 #include "../common/common.h"
31 #include "../ipc/ip.h"
36 vi_addstr(int ipvi
, char *str1
, u_int32_t len1
)
39 vtrace("addstr() {%.*s}\n", ipbp
->len1
, ipbp
->str1
);
41 /* Add to backing store. */
42 memcpy(CharAt(__vi_screen
, __vi_screen
->cury
, __vi_screen
->curx
),
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
);
58 vi_attribute(int ipvi
, u_int32_t val1
, u_int32_t val2
)
65 __vi_screen
->color
= val2
;
76 * Future... implement visible bell.
78 XBell(XtDisplay(__vi_screen
->area
), 0);
83 vi_busyon(int ipvi
, char *str1
, u_int32_t len1
)
85 __vi_set_cursor(__vi_screen
, 1);
92 __vi_set_cursor(__vi_screen
, 0);
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
);
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 */
141 0, YTOP(__vi_screen
, y
) /* dstx, dsty */
143 /* Need to let X take over. */
144 XmUpdateDisplay(__vi_screen
->area
);
157 vi_insertln(int ipvi
)
159 int y
, rows
, height
, width
;
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 */
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
);
208 vi_move(int ipvi
, u_int32_t val1
, u_int32_t val2
)
210 __vi_move_caret(__vi_screen
, val1
, val2
);
217 __vi_expose_func(0, __vi_screen
, 0);
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
);
242 if (__vi_exitp
!= NULL
)
249 vi_rename(int ipvi
, char *str1
, u_int32_t len1
)
253 const char *tail
, *p
;
255 /* For the icon, use the tail. */
256 for (p
= str1
, len
= len1
; len
> 1; ++p
, --len
)
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
);
275 vi_rewrite(int ipvi
, u_int32_t val1
)
283 vi_scrollbar(int ipvi
, u_int32_t val1
, u_int32_t val2
, u_int32_t val3
)
285 int top
, size
, maximum
, old_max
;
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
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
);
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
) {
308 fprintf( stderr
, "Correcting for top >= maximum\n" );
314 /* armor plating. core may think there are more
315 * lines visible than remain in the file
317 if ( top
+size
>= maximum
) {
319 fprintf( stderr
, "Correcting for top+size >= maximum\n" );
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
,
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 );
347 vi_select(int ipvi
, char *str1
, u_int32_t len1
)
360 IPSIOPS ipsi_ops_motif
= {