Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Source/CursesDialog/form/form.h
5017 views
1
/****************************************************************************
2
* Copyright (c) 1998 Free Software Foundation, Inc. *
3
* *
4
* Permission is hereby granted, free of charge, to any person obtaining a *
5
* copy of this software and associated documentation files (the *
6
* "Software"), to deal in the Software without restriction, including *
7
* without limitation the rights to use, copy, modify, merge, publish, *
8
* distribute, distribute with modifications, sublicense, and/or sell *
9
* copies of the Software, and to permit persons to whom the Software is *
10
* furnished to do so, subject to the following conditions: *
11
* *
12
* The above copyright notice and this permission notice shall be included *
13
* in all copies or substantial portions of the Software. *
14
* *
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
22
* *
23
* Except as contained in this notice, the name(s) of the above copyright *
24
* holders shall not be used in advertising or otherwise to promote the *
25
* sale, use or other dealings in this Software without prior written *
26
* authorization. *
27
****************************************************************************/
28
29
/****************************************************************************
30
* Author: Juergen Pfeifer <[email protected]> 1995,1997 *
31
****************************************************************************/
32
33
#ifndef FORM_H
34
#define FORM_H
35
36
#include "cmFormConfigure.h"
37
38
/* figure out which curses.h to include */
39
# if defined(CURSES_HAVE_NCURSES_H)
40
# include <ncurses.h>
41
# elif defined(CURSES_HAVE_NCURSES_NCURSES_H)
42
# include <ncurses/ncurses.h>
43
# elif defined(CURSES_HAVE_NCURSES_CURSES_H)
44
# include <ncurses/curses.h>
45
# else
46
# if defined(__hpux)
47
# if defined(_XOPEN_SOURCE_EXTENDED)
48
# define HAVE__XOPEN_SOURCE_EXTENDED
49
# else
50
# define _XOPEN_SOURCE_EXTENDED
51
# endif
52
# endif
53
# include <curses.h>
54
# if defined(__hpux) && !defined(HAVE__XOPEN_SOURCE_EXTENDED)
55
# undef _XOPEN_SOURCE_EXTENDED
56
# endif
57
/* Some curses/term headers define lower-case macros that
58
conflict with our source code. Undefine them. */
59
# undef newline
60
# endif
61
62
#include <eti.h>
63
#include <stdarg.h>
64
65
#ifdef __cplusplus
66
extern "C" {
67
#endif
68
69
typedef int Form_Options;
70
typedef int Field_Options;
71
72
/**********
73
* _PAGE *
74
**********/
75
76
typedef struct {
77
short pmin; /* index of first field on page */
78
short pmax; /* index of last field on page */
79
short smin; /* index of top leftmost field on page */
80
short smax; /* index of bottom rightmost field on page */
81
} _PAGE;
82
83
/**********
84
* FIELD *
85
**********/
86
87
typedef struct fieldnode {
88
unsigned short status; /* flags */
89
short rows; /* size in rows */
90
short cols; /* size in cols */
91
short frow; /* first row */
92
short fcol; /* first col */
93
int drows; /* dynamic rows */
94
int dcols; /* dynamic cols */
95
int maxgrow; /* maximum field growth */
96
int nrow; /* offscreen rows */
97
short nbuf; /* additional buffers */
98
short just; /* justification */
99
short page; /* page on form */
100
short index; /* into form -> field */
101
int pad; /* pad character */
102
chtype fore; /* foreground attribute */
103
chtype back; /* background attribute */
104
Field_Options opts; /* options */
105
struct fieldnode * snext; /* sorted order pointer */
106
struct fieldnode * sprev; /* sorted order pointer */
107
struct fieldnode * link; /* linked field chain */
108
struct formnode * form; /* containing form */
109
struct typenode * type; /* field type */
110
void * arg; /* argument for type */
111
char * buf; /* field buffers */
112
void * usrptr; /* user pointer */
113
} FIELD;
114
115
/**************
116
* FIELDTYPE *
117
**************/
118
119
typedef struct typenode {
120
unsigned short status; /* flags */
121
long ref; /* reference count */
122
struct typenode * left; /* ptr to operand for | */
123
struct typenode * right; /* ptr to operand for | */
124
125
void* (*makearg)(va_list *); /* make fieldtype arg */
126
void* (*copyarg)(const void *); /* copy fieldtype arg */
127
void (*freearg)(void *); /* free fieldtype arg */
128
129
bool (*fcheck)(FIELD *,const void *); /* field validation */
130
bool (*ccheck)(int,const void *); /* character validation */
131
132
bool (*next)(FIELD *,const void *); /* enumerate next value */
133
bool (*prev)(FIELD *,const void *); /* enumerate prev value */
134
135
} FIELDTYPE;
136
137
/*********
138
* FORM *
139
*********/
140
141
typedef struct formnode {
142
unsigned short status; /* flags */
143
short rows; /* size in rows */
144
short cols; /* size in cols */
145
int currow; /* current row in field window*/
146
int curcol; /* current col in field window*/
147
int toprow; /* in scrollable field window */
148
int begincol; /* in horiz. scrollable field */
149
short maxfield; /* number of fields */
150
short maxpage; /* number of pages */
151
short curpage; /* index into page */
152
Form_Options opts; /* options */
153
WINDOW * win; /* window */
154
WINDOW * sub; /* subwindow */
155
WINDOW * w; /* window for current field */
156
FIELD ** field; /* field [maxfield] */
157
FIELD * current; /* current field */
158
_PAGE * page; /* page [maxpage] */
159
void * usrptr; /* user pointer */
160
161
void (*forminit)(struct formnode *);
162
void (*formterm)(struct formnode *);
163
void (*fieldinit)(struct formnode *);
164
void (*fieldterm)(struct formnode *);
165
166
} FORM;
167
168
typedef void (*Form_Hook)(FORM *);
169
170
/***************************
171
* miscellaneous #defines *
172
***************************/
173
174
/* field justification */
175
#define NO_JUSTIFICATION (0)
176
#define JUSTIFY_LEFT (1)
177
#define JUSTIFY_CENTER (2)
178
#define JUSTIFY_RIGHT (3)
179
180
/* field options */
181
#define O_VISIBLE (0x0001)
182
#define O_ACTIVE (0x0002)
183
#define O_PUBLIC (0x0004)
184
#define O_EDIT (0x0008)
185
#define O_WRAP (0x0010)
186
#define O_BLANK (0x0020)
187
#define O_AUTOSKIP (0x0040)
188
#define O_NULLOK (0x0080)
189
#define O_PASSOK (0x0100)
190
#define O_STATIC (0x0200)
191
192
/* form options */
193
#define O_NL_OVERLOAD (0x0001)
194
#define O_BS_OVERLOAD (0x0002)
195
196
/* form driver commands */
197
#define REQ_NEXT_PAGE (KEY_MAX + 1) /* move to next page */
198
#define REQ_PREV_PAGE (KEY_MAX + 2) /* move to previous page */
199
#define REQ_FIRST_PAGE (KEY_MAX + 3) /* move to first page */
200
#define REQ_LAST_PAGE (KEY_MAX + 4) /* move to last page */
201
202
#define REQ_NEXT_FIELD (KEY_MAX + 5) /* move to next field */
203
#define REQ_PREV_FIELD (KEY_MAX + 6) /* move to previous field */
204
#define REQ_FIRST_FIELD (KEY_MAX + 7) /* move to first field */
205
#define REQ_LAST_FIELD (KEY_MAX + 8) /* move to last field */
206
#define REQ_SNEXT_FIELD (KEY_MAX + 9) /* move to sorted next field */
207
#define REQ_SPREV_FIELD (KEY_MAX + 10) /* move to sorted prev field */
208
#define REQ_SFIRST_FIELD (KEY_MAX + 11) /* move to sorted first field */
209
#define REQ_SLAST_FIELD (KEY_MAX + 12) /* move to sorted last field */
210
#define REQ_LEFT_FIELD (KEY_MAX + 13) /* move to left to field */
211
#define REQ_RIGHT_FIELD (KEY_MAX + 14) /* move to right to field */
212
#define REQ_UP_FIELD (KEY_MAX + 15) /* move to up to field */
213
#define REQ_DOWN_FIELD (KEY_MAX + 16) /* move to down to field */
214
215
#define REQ_NEXT_CHAR (KEY_MAX + 17) /* move to next char in field */
216
#define REQ_PREV_CHAR (KEY_MAX + 18) /* move to prev char in field */
217
#define REQ_NEXT_LINE (KEY_MAX + 19) /* move to next line in field */
218
#define REQ_PREV_LINE (KEY_MAX + 20) /* move to prev line in field */
219
#define REQ_NEXT_WORD (KEY_MAX + 21) /* move to next word in field */
220
#define REQ_PREV_WORD (KEY_MAX + 22) /* move to prev word in field */
221
#define REQ_BEG_FIELD (KEY_MAX + 23) /* move to first char in field */
222
#define REQ_END_FIELD (KEY_MAX + 24) /* move after last char in fld */
223
#define REQ_BEG_LINE (KEY_MAX + 25) /* move to beginning of line */
224
#define REQ_END_LINE (KEY_MAX + 26) /* move after last char in line */
225
#define REQ_LEFT_CHAR (KEY_MAX + 27) /* move left in field */
226
#define REQ_RIGHT_CHAR (KEY_MAX + 28) /* move right in field */
227
#define REQ_UP_CHAR (KEY_MAX + 29) /* move up in field */
228
#define REQ_DOWN_CHAR (KEY_MAX + 30) /* move down in field */
229
230
#define REQ_NEW_LINE (KEY_MAX + 31) /* insert/overlay new line */
231
#define REQ_INS_CHAR (KEY_MAX + 32) /* insert blank char at cursor */
232
#define REQ_INS_LINE (KEY_MAX + 33) /* insert blank line at cursor */
233
#define REQ_DEL_CHAR (KEY_MAX + 34) /* delete char at cursor */
234
#define REQ_DEL_PREV (KEY_MAX + 35) /* delete char before cursor */
235
#define REQ_DEL_LINE (KEY_MAX + 36) /* delete line at cursor */
236
#define REQ_DEL_WORD (KEY_MAX + 37) /* delete line at cursor */
237
#define REQ_CLR_EOL (KEY_MAX + 38) /* clear to end of line */
238
#define REQ_CLR_EOF (KEY_MAX + 39) /* clear to end of field */
239
#define REQ_CLR_FIELD (KEY_MAX + 40) /* clear entire field */
240
#define REQ_OVL_MODE (KEY_MAX + 41) /* begin overlay mode */
241
#define REQ_INS_MODE (KEY_MAX + 42) /* begin insert mode */
242
#define REQ_SCR_FLINE (KEY_MAX + 43) /* scroll field forward a line */
243
#define REQ_SCR_BLINE (KEY_MAX + 44) /* scroll field backward a line */
244
#define REQ_SCR_FPAGE (KEY_MAX + 45) /* scroll field forward a page */
245
#define REQ_SCR_BPAGE (KEY_MAX + 46) /* scroll field backward a page */
246
#define REQ_SCR_FHPAGE (KEY_MAX + 47) /* scroll field forward half page */
247
#define REQ_SCR_BHPAGE (KEY_MAX + 48) /* scroll field backward half page */
248
#define REQ_SCR_FCHAR (KEY_MAX + 49) /* horizontal scroll char */
249
#define REQ_SCR_BCHAR (KEY_MAX + 50) /* horizontal scroll char */
250
#define REQ_SCR_HFLINE (KEY_MAX + 51) /* horizontal scroll line */
251
#define REQ_SCR_HBLINE (KEY_MAX + 52) /* horizontal scroll line */
252
#define REQ_SCR_HFHALF (KEY_MAX + 53) /* horizontal scroll half line */
253
#define REQ_SCR_HBHALF (KEY_MAX + 54) /* horizontal scroll half line */
254
255
#define REQ_VALIDATION (KEY_MAX + 55) /* validate field */
256
#define REQ_NEXT_CHOICE (KEY_MAX + 56) /* display next field choice */
257
#define REQ_PREV_CHOICE (KEY_MAX + 57) /* display prev field choice */
258
259
#define MIN_FORM_COMMAND (KEY_MAX + 1) /* used by form_driver */
260
#define MAX_FORM_COMMAND (KEY_MAX + 57) /* used by form_driver */
261
262
#if defined(MAX_COMMAND)
263
# if (MAX_FORM_COMMAND > MAX_COMMAND)
264
# error Something is wrong -- MAX_FORM_COMMAND is greater than MAX_COMMAND
265
# elif (MAX_COMMAND != (KEY_MAX + 128))
266
# error Something is wrong -- MAX_COMMAND is already inconsistently defined.
267
# endif
268
#else
269
# define MAX_COMMAND (KEY_MAX + 128)
270
#endif
271
272
/*************************
273
* standard field types *
274
*************************/
275
extern FIELDTYPE *TYPE_ALPHA,
276
*TYPE_ALNUM,
277
*TYPE_ENUM,
278
*TYPE_INTEGER,
279
*TYPE_NUMERIC,
280
*TYPE_REGEXP;
281
282
/************************************
283
* built-in additional field types *
284
* They are not defined in SVr4 *
285
************************************/
286
extern FIELDTYPE *TYPE_IPV4; /* Internet IP Version 4 address */
287
288
/***********************
289
* Default objects *
290
***********************/
291
extern FORM *_nc_Default_Form;
292
extern FIELD *_nc_Default_Field;
293
294
295
/***********************
296
* FIELDTYPE routines *
297
***********************/
298
extern FIELDTYPE
299
*new_fieldtype(
300
bool (* const field_check)(FIELD *,const void *),
301
bool (* const char_check)(int,const void *)),
302
*link_fieldtype(FIELDTYPE *,FIELDTYPE *);
303
304
extern int free_fieldtype(FIELDTYPE *),
305
set_fieldtype_choice (FIELDTYPE *,
306
bool (* const next_choice)(FIELD *,const void *),
307
bool (* const prev_choice)(FIELD *,const void *));
308
309
/*******************
310
* FIELD routines *
311
*******************/
312
extern FIELD *new_field(int,int,int,int,int,int),
313
*dup_field(FIELD *,int,int),
314
*link_field(FIELD *,int,int);
315
316
extern int free_field(FIELD *),
317
field_info(const FIELD *,int *,int *,int *,int *,int *,int *),
318
dynamic_field_info(const FIELD *,int *,int *,int *),
319
set_max_field( FIELD *,int),
320
move_field(FIELD *,int,int),
321
set_field_type(FIELD *,FIELDTYPE *,...),
322
set_new_page(FIELD *,bool),
323
set_field_just(FIELD *,int),
324
field_just(const FIELD *),
325
set_field_fore(FIELD *,chtype),
326
set_field_back(FIELD *,chtype),
327
set_field_pad(FIELD *,int),
328
field_pad(const FIELD *),
329
set_field_buffer(FIELD *,int,const char *),
330
set_field_status(FIELD *,bool),
331
set_field_userptr(FIELD *, void *),
332
set_field_opts(FIELD *,Field_Options),
333
field_opts_on(FIELD *,Field_Options),
334
field_opts_off(FIELD *,Field_Options);
335
336
extern chtype field_fore(const FIELD *),
337
field_back(const FIELD *);
338
339
extern bool new_page(const FIELD *),
340
field_status(const FIELD *);
341
342
extern void *field_arg(const FIELD *);
343
344
extern void *field_userptr(const FIELD *);
345
346
extern FIELDTYPE
347
*field_type(const FIELD *);
348
349
extern char* field_buffer(const FIELD *,int);
350
351
extern Field_Options
352
field_opts(const FIELD *);
353
354
/******************
355
* FORM routines *
356
******************/
357
extern FORM *new_form(FIELD **);
358
359
extern FIELD **form_fields(const FORM *),
360
*current_field(const FORM *);
361
362
extern WINDOW *form_win(const FORM *),
363
*form_sub(const FORM *);
364
365
extern Form_Hook
366
form_init(const FORM *),
367
form_term(const FORM *),
368
field_init(const FORM *),
369
field_term(const FORM *);
370
371
extern int free_form(FORM *),
372
set_form_fields(FORM *,FIELD **),
373
field_count(const FORM *),
374
set_form_win(FORM *,WINDOW *),
375
set_form_sub(FORM *,WINDOW *),
376
set_current_field(FORM *,FIELD *),
377
field_index(const FIELD *),
378
set_form_page(FORM *,int),
379
form_page(const FORM *),
380
scale_form(const FORM *,int *,int *),
381
set_form_init(FORM *,Form_Hook),
382
set_form_term(FORM *,Form_Hook),
383
set_field_init(FORM *,Form_Hook),
384
set_field_term(FORM *,Form_Hook),
385
post_form(FORM *),
386
unpost_form(FORM *),
387
pos_form_cursor(FORM *),
388
form_driver(FORM *,int),
389
set_form_userptr(FORM *,void *),
390
set_form_opts(FORM *,Form_Options),
391
form_opts_on(FORM *,Form_Options),
392
form_opts_off(FORM *,Form_Options),
393
form_request_by_name(const char *);
394
395
extern const char
396
*form_request_name(int);
397
398
extern void *form_userptr(const FORM *);
399
400
extern Form_Options
401
form_opts(const FORM *);
402
403
extern bool data_ahead(const FORM *),
404
data_behind(const FORM *);
405
406
#ifdef __cplusplus
407
}
408
#endif
409
410
#endif /* FORM_H */
411
412