Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 205 lines (180 sloc) 5.692 kB
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
1 /* gui.c */
2 /* Copyright 1995 by Steve Kirkendall */
3
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
4 char id_gui[] = "$Id: gui.c,v 2.13 1997/12/24 03:12:52 steve Exp $";
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
5
6 #include "elvis.h"
7
8 /* This is a pointer to the chosen GUI. */
9 GUI *gui;
10
11 /* This function calls the GUI's moveto() function. This function performs a
12 * tiny amount of optimization, however: if the cursor is already in the
13 * correct position, it does nothing.
14 */
15 void guimoveto(win, column, row)
16 WINDOW win; /* window whose cursor is to be moved */
17 int column; /* column where cursor should be placed */
18 int row; /* row where cursor should be placed */
19 {
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
20 /* perform the moveto */
21 (*gui->moveto)(win->gw, column, row);
22 win->cursx = column;
23 win->cursy = row;
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
24 }
25
26 /* This function calls the GUI's draw() function, and then updates elvis'
27 * own idea of where the cursor is. The guimove() function depends on your
28 * calling guidraw() instead of (*gui->draw)().
29 */
30 void guidraw(win, font, text, len)
31 WINDOW win; /* window where text is to be drawn */
32 _char_ font; /* font to use for drawing */
33 CHAR *text; /* text to be drawn */
34 int len; /* number of characters in text */
35 {
36 (*gui->draw)(win->gw, font, text, len);
37 win->cursx += len;
38 }
39
40 /* This function calls the GUI's scroll() function, but only if the number of
41 * lines to be deleted/inserted is smaller than the number of lines remaining.
42 * And only if the GUI has a scroll() function, of course.
43 *
44 * Returns True if the scrolling happened as requested, else False.
45 */
46 BOOLEAN guiscroll(win, qty, notlast)
47 WINDOW win; /* window to be scrolled */
48 int qty; /* rows to insert (may be negative to delete) */
49 BOOLEAN notlast;/* if True, scrolling shouldn't affect last row */
50 {
51 /* if there is no gui->scroll() function, or if we're trying to
52 * insert/delete too many rows, then fail.
53 */
54 if (gui->scroll == NULL || abs(qty) >= o_lines(win) - win->cursy)
55 {
56 return False;
57 }
58
59 /* else give the GUI a try */
60 return (*gui->scroll)(win->gw, qty, notlast);
61 }
62
63 /* This function calls the GUI's shift() function, but only if the number of
64 * characters to the right of the cursor is larger than the requested shift
65 * amount. And only if the GUI has a shift() function, of course.
66 *
67 * Returns True if the shifting happened as requested, else False.
68 */
69 BOOLEAN guishift(win, qty, rows)
70 WINDOW win; /* window to be shifted */
71 int qty; /* columns to insert (may be negative to delete) */
72 int rows; /* number of rows affected */
73 {
74 /* if there is no gui->shift() function, or if we're trying to
75 * insert/delete too many characters, then fail.
76 */
77 if (!gui->shift || abs(qty) >= o_columns(win) - win->cursx)
78 {
79 return False;
80 }
81
82 /* else give the GUI a try */
83 return (*gui->shift)(win->gw, qty, rows);
84 }
85
86 /* This function calls the GUI's cltroeol() function. If it doesn't exist,
87 * or returns False, then this function writes enough space characters to
88 * simulate a clrtoeol()
89 */
90 void guiclrtoeol(win)
91 WINDOW win; /* window whose row is to be cleared */
92 {
93 static CHAR blanks[10] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '};
94 int width;
95
96 /* if already at EOL, we're done */
97 width = o_columns(win) - win->cursx;
98 if (width <= 0)
99 {
100 return;
101 }
102
103 /* try to make the GUI do it */
104 if (gui->clrtoeol == NULL || !(*gui->clrtoeol)(win->gw))
105 {
106 /* No, we need to do it the hard way */
107 (*gui->moveto)(win->gw, win->cursx, win->cursy);
108 while (width > 10)
109 {
110 (*gui->draw)(win->gw, 'n', blanks, 10);
111 width -= 10;
112 }
113 (*gui->draw)(win->gw, 'n', blanks, width);
114 (*gui->moveto)(win->gw, win->cursx, win->cursy);
115 }
116 }
117
118
119 /* This function calls the GUI's reset function (if it has one) and also
120 * resets the portable GUI wrapper functions' variables.
121 *
122 * Why do this? Because the wrapper functions, and some GUI drawing functions,
123 * perform some internal optimizations by assuming that nothing else affects
124 * the screen when we aren't looking; so we ^L is going to force the whole
125 * screen to be redrawn, that assumption is unsafe.
126 */
127 void guireset()
128 {
129 WINDOW w;
130
131 /* if the GUI has a reset function call it */
132 if (gui->reset)
133 {
134 (*gui->reset)();
135 }
136
137 /* reset the wrapper functions' variables */
138 for (w = windows; w; w = w->next)
139 {
140 w->cursx = w->cursy = -1;
141 }
142 }
143
144
145 /* This function calls the GUI's poll() function. If it has no poll() function
146 * then this function always returns False to indicate that the current work
147 * should continue. This function is also sensitive to the pollfrequency
148 * option, to reduce the number of calls to poll() since poll() may be slow.
149 *
150 * Returns False if the current work should continue, or True if the user
151 * has requested that it be cut short.
152 */
153 BOOLEAN guipoll(reset)
154 BOOLEAN reset; /* reset the pollctr variable? */
155 {
156 static long pollctr = 0;
157
158 /* if just supposed to reset, then do that and then quit */
159 if (reset)
160 {
161 pollctr = 0;
162 if (gui && gui->poll)
163 return (*gui->poll)(reset);
164 else
165 return False;
166 }
167
168 /* if there is no poll() function, or pollfrequency indicates that
169 * poll() shouldn't be called yet, then return False so the current
170 * operation will continue.
171 */
172 if (!gui || !gui->poll || ++pollctr < o_pollfrequency)
173 {
174 return False;
175 }
176
177 /* reset the pollctr variable */
178 pollctr = 0;
179
180 /* call the GUI's poll() function, and return its value */
181 reset = (*gui->poll)(reset);
182 if (reset)
183 {
184 msg(MSG_ERROR, "aborted");
185 }
186 return reset;
187 }
188
189 /* ring the bell, if there is one. Limit it to one ding per eventdraw() */
190 void guibeep(win)
191 WINDOW win; /* window to ding, or NULL to indicate an eventdraw() */
192 {
193 static BOOLEAN dingable = True;
194
195 if (!win)
196 {
197 dingable = True;
198 }
199 else if (gui && gui->beep && dingable)
200 {
201 (*gui->beep)(win->gw);
202 dingable = False;
203 }
204 }
Something went wrong with that request. Please try again.