Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/bx-conf/ds_cell.c
1069 views
1
/*
2
* Program source is Copyright 1993 Colten Edwards.
3
* Central Data Services is granted the right to use this source
4
* in thier product known as Quote Menu. They are also granted the right
5
* to modify this source in the advent of problems and or new features
6
* which they may want to add to the program.
7
*/
8
9
10
#include <stdlib.h>
11
#include <ctype.h>
12
#include <ncurses.h>
13
#ifdef __EMX__
14
#include <sys/types.h>
15
#endif
16
17
#include "ds_cell.h"
18
#include "ds_keys.h"
19
#include "func_pr.h"
20
21
22
/*
23
* This routine sets the stage for all menu actions except those that are
24
* specific for a menu.
25
* Home, PgUp, PgDn, End, Cursor up, Cursor Dn are defined within this source
26
*/
27
28
/* Get the current menu item.
29
*
30
* Save the current position, save the start of the list.
31
* if key was not a enter key then
32
* Convert character to uppercase
33
* While double linked list is not NULL
34
* if entered key is equal to stored key value
35
* break loop
36
* else
37
* get next double linked list item
38
* set current item equal
39
*
40
* if double linked list item is equal to NULL
41
* restore current item to entry value.
42
* return to caller with FALSE { didn't find the a valid key}
43
* Set redraw = TRUE and
44
* return TRUE to indicate found valid key
45
*/
46
47
int get_current(CELL *c) {
48
dlistptr x = c->start;
49
dlistptr y = c->current;
50
if (c->key != ENTER) {
51
c->key = toupper(c->key);
52
while (x)
53
if (c->key == x->datainfo.other) {
54
break;
55
} else
56
x = x->nextlistptr;
57
c->current = x;
58
}
59
if (x == NULL) {
60
c->current = y;
61
return FALSE;
62
}
63
if(c->ListPaintProc != NULL)
64
(*c->ListPaintProc)(c);
65
return TRUE;
66
}
67
68
/*
69
* Purpose is set the list start and end values. Main use is for lists that
70
* stretch longer then the window settings.
71
*/
72
73
int set_list_end(CELL *c) {
74
register int x = 0;
75
if (c->current == NULL)
76
return x;
77
c->list_end = c->list_start;
78
while (x < (c->erow - c->srow)) {
79
if (c->list_end->nextlistptr)
80
c->list_end = c->list_end->nextlistptr;
81
else
82
break;
83
x++;
84
}
85
return x;
86
}
87
88
/*
89
Move the cursor up a line with wrapping
90
*/
91
92
int wrap_cursor_up (CELL * c)
93
{
94
if (!cursor_up (c))
95
ls_end (c);
96
return TRUE;
97
}
98
99
100
101
/*
102
Move the cursor down a line with wrapping
103
*/
104
int wrap_cursor_dn (CELL * c)
105
{
106
if (!cursor_dn (c))
107
ls_home (c);
108
return TRUE;
109
}
110
111
/*
112
Move the cursor up a line.
113
114
Returns: TRUE if successful.
115
FALSE if it fails. Fails because we are already at the
116
first item of the list.
117
*/
118
119
int cursor_up (CELL * c)
120
{
121
c->redraw = TRUE;
122
if (c->current == NULL)
123
c->redraw = FALSE;
124
else {
125
if (c->current == c->list_start) {
126
if (c->current->prevlistptr) {
127
c->current = c->list_start = c->current->prevlistptr;
128
set_list_end(c);
129
} else
130
c->redraw = FALSE;
131
} else {
132
if (c->current->prevlistptr)
133
c->current = c->current->prevlistptr;
134
else
135
c->redraw = FALSE;
136
}
137
}
138
c->desc_start = 0;
139
c->cur_pos = CURCOL;
140
return c->redraw;
141
}
142
143
/*
144
Move the cursor down a line.
145
146
Returns: TRUE if successful.
147
FALSE if it fails. Fails because we are already at the
148
first item of the list.
149
*/
150
151
int cursor_dn (CELL * c)
152
{
153
c->redraw = TRUE;
154
if (c->current == NULL)
155
c->redraw = FALSE;
156
else {
157
if (c->current == c->list_end) {
158
if (c->list_end->nextlistptr) {
159
c->list_end = c->current = c->list_end->nextlistptr;
160
if (c->list_start->nextlistptr)
161
c->list_start = c->list_start->nextlistptr;
162
} else
163
c->redraw = FALSE;
164
} else {
165
if (c->current->nextlistptr != NULL)
166
c->current = c->current->nextlistptr;
167
else
168
c->redraw = FALSE;
169
}
170
}
171
c->desc_start = 0;
172
c->cur_pos = CURCOL;
173
return c->redraw;
174
}
175
176
/*
177
* Purpose to pgup through the list values
178
*/
179
int ls_pgup (CELL * c)
180
{
181
register int pagesize = c->erow - c->srow;
182
if (c->current == NULL)
183
return TRUE;
184
while ((pagesize) && (c->current->prevlistptr != NULL)){
185
c->current = c->current->prevlistptr;
186
pagesize--;
187
}
188
c->list_start = c->current;
189
set_list_end(c);
190
c -> redraw = TRUE;
191
c->desc_start = 0;
192
c->cur_pos = CURCOL;
193
return TRUE;
194
}
195
196
/*
197
* Purpose to pgdn through the list values
198
*/
199
200
int ls_pgdn (CELL * c)
201
{
202
register int pagesize = c->erow - c->srow;
203
if (c->current == NULL)
204
return TRUE;
205
while ((pagesize) && (c->current->nextlistptr != NULL)){
206
c->current = c->current->nextlistptr;
207
pagesize--;
208
}
209
if (pagesize == 0)
210
c->list_start = c->current;
211
set_list_end(c);
212
c->redraw = TRUE;
213
c->desc_start = 0;
214
c->cur_pos = CURCOL;
215
return TRUE;
216
}
217
218
/*
219
* purpose to set the home the list.
220
*/
221
int ls_home (CELL * c)
222
{
223
c->current = c->list_start = c->start;
224
set_list_end(c);
225
c->redraw = TRUE;
226
return TRUE;
227
}
228
229
/*
230
* Purpose is to go to end of list.
231
*/
232
233
int ls_end (CELL * c)
234
{
235
int x = 0;
236
if (c->current == NULL)
237
return TRUE;
238
c->current = c->list_end = c->list_start = c->end;
239
while (x < (c->erow - c->srow)){
240
if (c->list_start->prevlistptr)
241
c->list_start = c->list_start->prevlistptr;
242
else
243
break;
244
x++;
245
}
246
c -> redraw = TRUE;
247
return TRUE;
248
}
249
250
251
252
/*
253
* This is the main routine used throughout.
254
* Purpose is to be a function despatcher.
255
* On entry
256
* set termkey = 0
257
* if we have a list entry procedure then
258
* exec that procedure. It usely draws the box and creates the list
259
* Make sure the list start and end are set so we do not overstep boundries
260
* While terminate key is equal to 0
261
* set function hit = false
262
* if list redraw is TRUE and we have a redraw procedure
263
* exec redraw procedure. Usually draws only items in the list.
264
* if we have a UpdateStatusProc
265
* exec Updatestatusproc. Usually displays counts, Menus, etc.
266
* if termkey is equal to 0
267
* if othergetkey is TRUE and othergetkeyproc is not equal to NULL
268
* exec othergetkeyproc. Used to provide edit functions
269
* else
270
* call get char function
271
* Set special to 0. Indicates which function to call, iff found in list.
272
* Check menu list until end of list (-1) for a matching key value.
273
* if key and menu item key match and function is not NULL
274
* set special equal to special number
275
* exec function and save returned value in hit.
276
* hit indicates whether or not we have exec'd a function for a key
277
* break to end of loop
278
* if hit is FALSE and current_event is not equal to NULL
279
* exec current event. This allows us to check for both upper and lower
280
* case keys.
281
* loop to top and check termkey.
282
*
283
* if termkey was set then
284
* we clear the list and exit function dispatch.
285
* return terminate key
286
*/
287
288
int ls_dispatch (CELL * c)
289
{
290
long x;
291
long hit;
292
293
c -> termkey = 0;
294
if ((*c -> ListEntryProc) != NULL)
295
x = (*c -> ListEntryProc) (c);
296
/*
297
if (c->start == NULL) {
298
return c->termkey;
299
}
300
*/
301
set_list_end(c);
302
303
while (c -> termkey == 0/* && c->start*/) {
304
hit = FALSE;
305
if (c->redraw && ((*c -> ListPaintProc) != NULL))
306
(*c -> ListPaintProc) (c);
307
if (*c -> UpdateStatusProc != NULL)
308
(*c -> UpdateStatusProc) (c);
309
if (c -> termkey == 0) {
310
if ((*c -> OtherGetKeyProc) != NULL && c->other_getkey)
311
c -> key = (*c->OtherGetKeyProc) (c);
312
else
313
c->key = getch();
314
#if 0
315
c->key = get_char (c, (int)c->menu_bar);
316
#endif
317
}
318
c->special = 0;
319
for (x = 0; c ->keytable[x].key != -1; x++)
320
if ((c -> keytable[x].key == c->key) && ((*c->func_table[c->keytable[x].func_num].func) != NULL)) {
321
c->special = c->keytable[x].func_num;
322
hit = (*c->func_table[c->keytable[x].func_num].func)(c);
323
break;
324
}
325
if (hit == FALSE && *c->current_event != NULL)
326
(*c -> current_event) (c);
327
}
328
if (*c -> ListExitProc != NULL)
329
(*c -> ListExitProc) (c);
330
return c -> termkey;
331
}
332
333
/*
334
* Terminate function. Set termkey to the keystroke entered.
335
*/
336
337
int ls_quit (CELL * c)
338
{
339
c->termkey = c->key;
340
return TRUE;
341
}
342
343
344
345