]> git.ipfire.org Git - thirdparty/newt.git/blob - newt.h
reworked checkboxtree implementation to function as a tree
[thirdparty/newt.git] / newt.h
1 #ifndef H_NEWT
2 #define H_NEWT
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 #include <stdarg.h>
9
10 #define NEWT_COLORSET_ROOT 2
11 #define NEWT_COLORSET_BORDER 3
12 #define NEWT_COLORSET_WINDOW 4
13 #define NEWT_COLORSET_SHADOW 5
14 #define NEWT_COLORSET_TITLE 6
15 #define NEWT_COLORSET_BUTTON 7
16 #define NEWT_COLORSET_ACTBUTTON 8
17 #define NEWT_COLORSET_CHECKBOX 9
18 #define NEWT_COLORSET_ACTCHECKBOX 10
19 #define NEWT_COLORSET_ENTRY 11
20 #define NEWT_COLORSET_LABEL 12
21 #define NEWT_COLORSET_LISTBOX 13
22 #define NEWT_COLORSET_ACTLISTBOX 14
23 #define NEWT_COLORSET_TEXTBOX 15
24 #define NEWT_COLORSET_ACTTEXTBOX 16
25 #define NEWT_COLORSET_HELPLINE 17
26 #define NEWT_COLORSET_ROOTTEXT 18
27 #define NEWT_COLORSET_EMPTYSCALE 19
28 #define NEWT_COLORSET_FULLSCALE 20
29 #define NEWT_COLORSET_DISENTRY 21
30 #define NEWT_COLORSET_COMPACTBUTTON 22
31 #define NEWT_COLORSET_ACTSELLISTBOX 23
32 #define NEWT_COLORSET_SELLISTBOX 24
33
34 #define NEWT_ARG_LAST -100000
35 #define NEWT_ARG_APPEND -1
36
37 struct newtColors {
38 char * rootFg, * rootBg;
39 char * borderFg, * borderBg;
40 char * windowFg, * windowBg;
41 char * shadowFg, * shadowBg;
42 char * titleFg, * titleBg;
43 char * buttonFg, * buttonBg;
44 char * actButtonFg, * actButtonBg;
45 char * checkboxFg, * checkboxBg;
46 char * actCheckboxFg, * actCheckboxBg;
47 char * entryFg, * entryBg;
48 char * labelFg, * labelBg;
49 char * listboxFg, * listboxBg;
50 char * actListboxFg, * actListboxBg;
51 char * textboxFg, * textboxBg;
52 char * actTextboxFg, * actTextboxBg;
53 char * helpLineFg, * helpLineBg;
54 char * rootTextFg, * rootTextBg;
55 char * emptyScale, * fullScale;
56 char * disabledEntryFg, * disabledEntryBg;
57 char * compactButtonFg, * compactButtonBg;
58 char * actSelListboxFg, * actSelListboxBg;
59 char * selListboxFg, * selListboxBg;
60 };
61
62 enum newtFlagsSense { NEWT_FLAGS_SET, NEWT_FLAGS_RESET, NEWT_FLAGS_TOGGLE };
63
64 #define NEWT_FLAG_RETURNEXIT (1 << 0)
65 #define NEWT_FLAG_HIDDEN (1 << 1)
66 #define NEWT_FLAG_SCROLL (1 << 2)
67 #define NEWT_FLAG_DISABLED (1 << 3)
68 /* OBSOLETE #define NEWT_FLAG_NOSCROLL (1 << 4) for listboxes */
69 #define NEWT_FLAG_BORDER (1 << 5)
70 #define NEWT_FLAG_WRAP (1 << 6)
71 #define NEWT_FLAG_NOF12 (1 << 7)
72 #define NEWT_FLAG_MULTIPLE (1 << 8)
73 #define NEWT_FLAG_SELECTED (1 << 9)
74 #define NEWT_FLAG_CHECKBOX (1 << 10)
75
76 #define NEWT_FD_READ (1 << 0)
77 #define NEWT_FD_WRITE (1 << 1)
78
79 /* Backwards compatibility */
80 #define NEWT_LISTBOX_RETURNEXIT NEWT_FLAG_RETURNEXIT
81 #define NEWT_ENTRY_SCROLL NEWT_FLAG_SCROLL
82 #define NEWT_ENTRY_HIDDEN NEWT_FLAG_HIDDEN
83 #define NEWT_ENTRY_RETURNEXIT NEWT_FLAG_RETURNEXIT
84 #define NEWT_ENTRY_DISABLED NEWT_FLAG_DISABLED
85
86 #define NEWT_TEXTBOX_WRAP NEWT_FLAG_WRAP
87 #define NEWT_TEXTBOX_SCROLL NEWT_FLAG_SCROLL
88 #define NEWT_FORM_NOF12 NEWT_FLAG_NOF12
89
90 #define newtListboxAddEntry newtListboxAppendEntry
91
92
93 typedef struct newtComponent_struct * newtComponent;
94
95 extern const struct newtColors newtDefaultColorPalette;
96
97 typedef void (*newtCallback)(newtComponent, void *);
98 typedef void (*newtSuspendCallback)(void * data);
99
100 int newtInit(void);
101 int newtFinished(void);
102 void newtCls(void);
103 void newtResizeScreen(int redraw);
104 void newtWaitForKey(void);
105 void newtClearKeyBuffer(void);
106 void newtDelay(int usecs);
107 /* top, left are *not* counting the border */
108 int newtOpenWindow(int left, int top, int width, int height,
109 const char * title);
110 int newtCenteredWindow(int width, int height, const char * title);
111 void newtPopWindow(void);
112 void newtSetColors(struct newtColors colors);
113 void newtRefresh(void);
114 void newtSuspend(void);
115 void newtSetSuspendCallback(newtSuspendCallback cb, void * data);
116 void newtResume(void);
117 void newtPushHelpLine(const char * text);
118 void newtRedrawHelpLine(void);
119 void newtPopHelpLine(void);
120 void newtDrawRootText(int col, int row, const char * text);
121 void newtBell(void);
122
123 /* Components */
124
125 newtComponent newtCompactButton(int left, int top, const char * text);
126 newtComponent newtButton(int left, int top, const char * text);
127 newtComponent newtCheckbox(int left, int top, const char * text, char defValue,
128 const char * seq, char * result);
129 char newtCheckboxGetValue(newtComponent co);
130 void newtCheckboxSetValue(newtComponent co, char value);
131 void newtCheckboxSetFlags(newtComponent co, int flags, enum newtFlagsSense sense);
132
133
134 newtComponent newtRadiobutton(int left, int top, const char * text, int isDefault,
135 newtComponent prevButton);
136 newtComponent newtRadioGetCurrent(newtComponent setMember);
137 newtComponent newtListitem(int left, int top, const char * text, int isDefault,
138 newtComponent prevItem, const void * data, int flags);
139 void newtListitemSet(newtComponent co, const char * text);
140 void * newtListitemGetData(newtComponent co);
141 void newtGetScreenSize(int * cols, int * rows);
142
143 newtComponent newtLabel(int left, int top, const char * text);
144 void newtLabelSetText(newtComponent co, const char * text);
145 newtComponent newtVerticalScrollbar(int left, int top, int height,
146 int normalColorset, int thumbColorset);
147 void newtScrollbarSet(newtComponent co, int where, int total);
148
149 newtComponent newtListbox(int left, int top, int height, int flags);
150 void * newtListboxGetCurrent(newtComponent co);
151 void newtListboxSetCurrent(newtComponent co, int num);
152 void newtListboxSetCurrentByKey(newtComponent co, void * key);
153 void newtListboxSetEntry(newtComponent co, int num, const char * text);
154 void newtListboxSetWidth(newtComponent co, int width);
155 void newtListboxSetData(newtComponent co, int num, void * data);
156 int newtListboxAppendEntry(newtComponent co, const char * text,
157 const void * data);
158 /* Send the key to insert after, or NULL to insert at the top */
159 int newtListboxInsertEntry(newtComponent co, const char * text, const void * data, void * key);
160 int newtListboxDeleteEntry(newtComponent co, void * data);
161 void newtListboxClear(newtComponent co); /* removes all entries from listbox */
162 void newtListboxGetEntry(newtComponent co, int num, char **text, void **data);
163 /* Returns an array of data pointers from items, last element is NULL */
164 void **newtListboxGetSelection(newtComponent co, int *numitems);
165 void newtListboxClearSelection(newtComponent co);
166 void newtListboxSelectItem(newtComponent co, const void * key,
167 enum newtFlagsSense sense);
168
169 newtComponent newtCheckboxTree(int left, int top, int height, int flags);
170 void ** newtCheckboxTreeGetSelection(newtComponent co, int *numitems);
171 /* last item is NEWT_ARG_LAST for all of these */
172 int newtCheckboxTreeAddItem(newtComponent co,
173 const char * text, const void * data,
174 int flags, int index, ...);
175 int newtCheckboxTreeAddArray(newtComponent co,
176 const char * text, const void * data,
177 int flags, int * indexes);
178 int * newtCheckboxTreeFindItem(newtComponent co, void * data);
179
180 newtComponent newtTextboxReflowed(int left, int top, char * text, int width,
181 int flexDown, int flexUp, int flags);
182 newtComponent newtTextbox(int left, int top, int width, int height, int flags);
183 void newtTextboxSetText(newtComponent co, const char * text);
184 void newtTextboxSetHeight(newtComponent co, int height);
185 int newtTextboxGetNumLines(newtComponent co);
186 char * newtReflowText(char * text, int width, int flexDown, int flexUp,
187 int * actualWidth, int * actualHeight);
188
189 struct newtExitStruct {
190 enum { NEWT_EXIT_HOTKEY, NEWT_EXIT_COMPONENT, NEWT_EXIT_FDREADY } reason;
191 union {
192 int key;
193 newtComponent co;
194 } u;
195 } ;
196
197 newtComponent newtForm(newtComponent vertBar, const char * help, int flags);
198 void newtFormWatchFd(newtComponent form, int fd, int fdFlags);
199 void newtFormSetSize(newtComponent co);
200 newtComponent newtFormGetCurrent(newtComponent co);
201 void newtFormSetBackground(newtComponent co, int color);
202 void newtFormSetCurrent(newtComponent co, newtComponent subco);
203 void newtFormAddComponent(newtComponent form, newtComponent co);
204 void newtFormAddComponents(newtComponent form, ...);
205 void newtFormSetHeight(newtComponent co, int height);
206 void newtFormSetWidth(newtComponent co, int width);
207 newtComponent newtRunForm(newtComponent form); /* obsolete */
208 void newtFormRun(newtComponent co, struct newtExitStruct * es);
209 void newtDrawForm(newtComponent form);
210 void newtFormAddHotKey(newtComponent co, int key);
211
212 typedef int (*newtEntryFilter)(newtComponent entry, void * data, int ch,
213 int cursor);
214 newtComponent newtEntry(int left, int top, const char * initialValue, int width,
215 char ** resultPtr, int flags);
216 void newtEntrySet(newtComponent co, const char * value, int cursorAtEnd);
217 void newtEntrySetFilter(newtComponent co, newtEntryFilter filter, void * data);
218 char * newtEntryGetValue(newtComponent co);
219 void newtEntrySetFlags(newtComponent co, int flags, enum newtFlagsSense sense);
220
221 newtComponent newtScale(int left, int top, int width, long long fullValue);
222 void newtScaleSet(newtComponent co, unsigned long long amount);
223
224 void newtComponentAddCallback(newtComponent co, newtCallback f, void * data);
225 void newtComponentTakesFocus(newtComponent co, int val);
226
227 /* this also destroys all of the components (including other forms) on the
228 form */
229 void newtFormDestroy(newtComponent form);
230
231 /* Key codes */
232
233 #define NEWT_KEY_TAB '\t'
234 #define NEWT_KEY_ENTER '\r'
235 #define NEWT_KEY_SUSPEND '\032' /* ctrl - z*/
236 #define NEWT_KEY_RETURN NEWT_KEY_ENTER
237
238 #define NEWT_KEY_EXTRA_BASE 0x8000
239 #define NEWT_KEY_UP NEWT_KEY_EXTRA_BASE + 1
240 #define NEWT_KEY_DOWN NEWT_KEY_EXTRA_BASE + 2
241 #define NEWT_KEY_LEFT NEWT_KEY_EXTRA_BASE + 4
242 #define NEWT_KEY_RIGHT NEWT_KEY_EXTRA_BASE + 5
243 #define NEWT_KEY_BKSPC NEWT_KEY_EXTRA_BASE + 6
244 #define NEWT_KEY_DELETE NEWT_KEY_EXTRA_BASE + 7
245 #define NEWT_KEY_HOME NEWT_KEY_EXTRA_BASE + 8
246 #define NEWT_KEY_END NEWT_KEY_EXTRA_BASE + 9
247 #define NEWT_KEY_UNTAB NEWT_KEY_EXTRA_BASE + 10
248 #define NEWT_KEY_PGUP NEWT_KEY_EXTRA_BASE + 11
249 #define NEWT_KEY_PGDN NEWT_KEY_EXTRA_BASE + 12
250 #define NEWT_KEY_INSERT NEWT_KEY_EXTRA_BASE + 13
251
252 #define NEWT_KEY_F1 NEWT_KEY_EXTRA_BASE + 101
253 #define NEWT_KEY_F2 NEWT_KEY_EXTRA_BASE + 102
254 #define NEWT_KEY_F3 NEWT_KEY_EXTRA_BASE + 103
255 #define NEWT_KEY_F4 NEWT_KEY_EXTRA_BASE + 104
256 #define NEWT_KEY_F5 NEWT_KEY_EXTRA_BASE + 105
257 #define NEWT_KEY_F6 NEWT_KEY_EXTRA_BASE + 106
258 #define NEWT_KEY_F7 NEWT_KEY_EXTRA_BASE + 107
259 #define NEWT_KEY_F8 NEWT_KEY_EXTRA_BASE + 108
260 #define NEWT_KEY_F9 NEWT_KEY_EXTRA_BASE + 109
261 #define NEWT_KEY_F10 NEWT_KEY_EXTRA_BASE + 110
262 #define NEWT_KEY_F11 NEWT_KEY_EXTRA_BASE + 111
263 #define NEWT_KEY_F12 NEWT_KEY_EXTRA_BASE + 112
264
265 /* not really a key, but newtGetKey returns it */
266 #define NEWT_KEY_RESIZE NEWT_KEY_EXTRA_BASE + 113
267
268 #define NEWT_ANCHOR_LEFT (1 << 0)
269 #define NEWT_ANCHOR_RIGHT (1 << 1)
270 #define NEWT_ANCHOR_TOP (1 << 2)
271 #define NEWT_ANCHOR_BOTTOM (1 << 3)
272
273 #define NEWT_GRID_FLAG_GROWX (1 << 0)
274 #define NEWT_GRID_FLAG_GROWY (1 << 1)
275
276 typedef struct grid_s * newtGrid;
277 enum newtGridElement { NEWT_GRID_EMPTY = 0,
278 NEWT_GRID_COMPONENT, NEWT_GRID_SUBGRID };
279
280 newtGrid newtCreateGrid(int cols, int rows);
281 /* TYPE, what, TYPE, what, ..., NULL */
282 newtGrid newtGridVStacked(enum newtGridElement type, void * what, ...);
283 newtGrid newtGridVCloseStacked(enum newtGridElement type, void * what, ...);
284 newtGrid newtGridHStacked(enum newtGridElement type1, void * what1, ...);
285 newtGrid newtGridHCloseStacked(enum newtGridElement type1, void * what1, ...);
286 newtGrid newtGridBasicWindow(newtComponent text, newtGrid middle,
287 newtGrid buttons);
288 newtGrid newtGridSimpleWindow(newtComponent text, newtComponent middle,
289 newtGrid buttons);
290 void newtGridSetField(newtGrid grid, int col, int row,
291 enum newtGridElement type, void * val, int padLeft,
292 int padTop, int padRight, int padBottom, int anchor,
293 int flags);
294 void newtGridPlace(newtGrid grid, int left, int top);
295 #define newtGridDestroy newtGridFree
296 void newtGridFree(newtGrid grid, int recurse);
297 void newtGridGetSize(newtGrid grid, int * width, int * height);
298 void newtGridWrappedWindow(newtGrid grid, char * title);
299 void newtGridWrappedWindowAt(newtGrid grid, char * title, int left, int top);
300 void newtGridAddComponentsToForm(newtGrid grid, newtComponent form,
301 int recurse);
302
303 /* convienve */
304 newtGrid newtButtonBarv(char * button1, newtComponent * b1comp, va_list args);
305 newtGrid newtButtonBar(char * button1, newtComponent * b1comp, ...);
306
307 /* automatically centered and shrink wrapped */
308 void newtWinMessage(char * title, char * buttonText, char * text, ...);
309 void newtWinMessagev(char * title, char * buttonText, char * text,
310 va_list argv);
311
312 /* having separate calls for these two seems silly, but having two separate
313 variable length-arg lists seems like a bad idea as well */
314
315 /* Returns 0 if F12 was pressed, 1 for button1, 2 for button2 */
316 int newtWinChoice(char * title, char * button1, char * button2,
317 char * text, ...);
318 /* Returns 0 if F12 was pressed, 1 for button1, 2 for button2,
319 3 for button3 */
320 int newtWinTernary(char * title, char * button1, char * button2,
321 char * button3, char * message, ...);
322
323 /* Returns the button number pressed, 0 on F12 */
324 int newtWinMenu(char * title, char * text, int suggestedWidth, int flexDown,
325 int flexUp, int maxListHeight, char ** items, int * listItem,
326 char * button1, ...);
327
328 struct newtWinEntry {
329 char * text;
330 char ** value; /* may be initialized to set default */
331 int flags;
332 };
333
334 /* Returns the button number pressed, 0 on F12. The final values are
335 dynamically allocated, and need to be freed. */
336 int newtWinEntries(char * title, char * text, int suggestedWidth, int flexDown,
337 int flexUp, int dataWidth,
338 struct newtWinEntry * items, char * button1, ...);
339
340 #ifdef __cplusplus
341 } /* End of extern "C" { */
342 #endif
343
344 #endif /* H_NEWT */