]> git.ipfire.org Git - thirdparty/newt.git/blob - newt.h
- add newtPopWindowNoRefresh()
[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 #define NEWT_FLAG_PASSWORD (1 << 11) /* draw '*' of chars in entrybox */
76 #define NEWT_FLAG_SHOWCURSOR (1 << 12) /* Only applies to listbox for now */
77 #define NEWT_FD_READ (1 << 0)
78 #define NEWT_FD_WRITE (1 << 1)
79 #define NEWT_FD_EXCEPT (1 << 2)
80
81 #define NEWT_CHECKBOXTREE_UNSELECTABLE (1 << 12)
82 #define NEWT_CHECKBOXTREE_HIDE_BOX (1 << 13)
83
84 #define NEWT_CHECKBOXTREE_COLLAPSED '\0'
85 #define NEWT_CHECKBOXTREE_EXPANDED '\1'
86 #define NEWT_CHECKBOXTREE_UNSELECTED ' '
87 #define NEWT_CHECKBOXTREE_SELECTED '*'
88
89 /* Backwards compatibility */
90 #define NEWT_LISTBOX_RETURNEXIT NEWT_FLAG_RETURNEXIT
91 #define NEWT_ENTRY_SCROLL NEWT_FLAG_SCROLL
92 #define NEWT_ENTRY_HIDDEN NEWT_FLAG_HIDDEN
93 #define NEWT_ENTRY_RETURNEXIT NEWT_FLAG_RETURNEXIT
94 #define NEWT_ENTRY_DISABLED NEWT_FLAG_DISABLED
95
96 #define NEWT_TEXTBOX_WRAP NEWT_FLAG_WRAP
97 #define NEWT_TEXTBOX_SCROLL NEWT_FLAG_SCROLL
98 #define NEWT_FORM_NOF12 NEWT_FLAG_NOF12
99
100 #define newtListboxAddEntry newtListboxAppendEntry
101
102
103 typedef struct newtComponent_struct * newtComponent;
104
105 extern const struct newtColors newtDefaultColorPalette;
106
107 typedef void (*newtCallback)(newtComponent, void *);
108 typedef void (*newtSuspendCallback)(void * data);
109
110 int newtInit(void);
111 int newtFinished(void);
112 void newtCls(void);
113 void newtResizeScreen(int redraw);
114 void newtWaitForKey(void);
115 void newtClearKeyBuffer(void);
116 void newtDelay(unsigned int usecs);
117 /* top, left are *not* counting the border */
118 int newtOpenWindow(int left,int top,
119 unsigned int width,unsigned int height,
120 const char * title);
121 int newtCenteredWindow(unsigned int width,unsigned int height, const char * title);
122 void newtPopWindow(void);
123 void newtPopWindowNoRefresh(void);
124 void newtSetColors(struct newtColors colors);
125 void newtRefresh(void);
126 void newtSuspend(void);
127 void newtSetSuspendCallback(newtSuspendCallback cb, void * data);
128 void newtSetHelpCallback(newtCallback cb);
129 int newtResume(void);
130 void newtPushHelpLine(const char * text);
131 void newtRedrawHelpLine(void);
132 void newtPopHelpLine(void);
133 void newtDrawRootText(int col, int row, const char * text);
134 void newtBell(void);
135 void newtCursorOff(void);
136 void newtCursorOn(void);
137
138 /* Components */
139
140 newtComponent newtCompactButton(int left, int top, const char * text);
141 newtComponent newtButton(int left, int top, const char * text);
142 newtComponent newtCheckbox(int left, int top, const char * text, char defValue,
143 const char * seq, char * result);
144 char newtCheckboxGetValue(newtComponent co);
145 void newtCheckboxSetValue(newtComponent co, char value);
146 void newtCheckboxSetFlags(newtComponent co, int flags, enum newtFlagsSense sense);
147
148
149 newtComponent newtRadiobutton(int left, int top, const char * text, int isDefault,
150 newtComponent prevButton);
151 newtComponent newtRadioGetCurrent(newtComponent setMember);
152 newtComponent newtListitem(int left, int top, const char * text, int isDefault,
153 newtComponent prevItem, const void * data, int flags);
154 void newtListitemSet(newtComponent co, const char * text);
155 void * newtListitemGetData(newtComponent co);
156 void newtGetScreenSize(int * cols, int * rows);
157
158 newtComponent newtLabel(int left, int top, const char * text);
159 void newtLabelSetText(newtComponent co, const char * text);
160 newtComponent newtVerticalScrollbar(int left, int top, int height,
161 int normalColorset, int thumbColorset);
162 void newtScrollbarSet(newtComponent co, int where, int total);
163
164 newtComponent newtListbox(int left, int top, int height, int flags);
165 void * newtListboxGetCurrent(newtComponent co);
166 void newtListboxSetCurrent(newtComponent co, int num);
167 void newtListboxSetCurrentByKey(newtComponent co, void * key);
168 void newtListboxSetEntry(newtComponent co, int num, const char * text);
169 void newtListboxSetWidth(newtComponent co, int width);
170 void newtListboxSetData(newtComponent co, int num, void * data);
171 int newtListboxAppendEntry(newtComponent co, const char * text,
172 const void * data);
173 /* Send the key to insert after, or NULL to insert at the top */
174 int newtListboxInsertEntry(newtComponent co, const char * text, const void * data, void * key);
175 int newtListboxDeleteEntry(newtComponent co, void * data);
176 void newtListboxClear(newtComponent co); /* removes all entries from listbox */
177 void newtListboxGetEntry(newtComponent co, int num, char **text, void **data);
178 /* Returns an array of data pointers from items, last element is NULL */
179 void **newtListboxGetSelection(newtComponent co, int *numitems);
180 void newtListboxClearSelection(newtComponent co);
181 void newtListboxSelectItem(newtComponent co, const void * key,
182 enum newtFlagsSense sense);
183 /* Returns number of items currently in listbox. */
184 int newtListboxItemCount(newtComponent co);
185
186 newtComponent newtCheckboxTree(int left, int top, int height, int flags);
187 newtComponent newtCheckboxTreeMulti(int left, int top, int height, char *seq, int flags);
188 const void ** newtCheckboxTreeGetSelection(newtComponent co, int *numitems);
189 const void * newtCheckboxTreeGetCurrent(newtComponent co);
190 void newtCheckboxTreeSetCurrent(newtComponent co, void * item);
191 const void ** newtCheckboxTreeGetMultiSelection(newtComponent co, int *numitems, char seqnum);
192 /* last item is NEWT_ARG_LAST for all of these */
193 int newtCheckboxTreeAddItem(newtComponent co,
194 const char * text, const void * data,
195 int flags, int index, ...);
196 int newtCheckboxTreeAddArray(newtComponent co,
197 const char * text, const void * data,
198 int flags, int * indexes);
199 int * newtCheckboxTreeFindItem(newtComponent co, void * data);
200 void newtCheckboxTreeSetEntry(newtComponent co, const void * data,
201 const char * text);
202 void newtCheckboxTreeSetWidth(newtComponent co, int width);
203 char newtCheckboxTreeGetEntryValue(newtComponent co, const void * data);
204 void newtCheckboxTreeSetEntryValue(newtComponent co, const void * data,
205 char value);
206
207 newtComponent newtTextboxReflowed(int left, int top, char * text, int width,
208 int flexDown, int flexUp, int flags);
209 newtComponent newtTextbox(int left, int top, int width, int height, int flags);
210 void newtTextboxSetText(newtComponent co, const char * text);
211 void newtTextboxSetHeight(newtComponent co, int height);
212 int newtTextboxGetNumLines(newtComponent co);
213 char * newtReflowText(char * text, int width, int flexDown, int flexUp,
214 int * actualWidth, int * actualHeight);
215
216 struct newtExitStruct {
217 enum { NEWT_EXIT_HOTKEY, NEWT_EXIT_COMPONENT, NEWT_EXIT_FDREADY,
218 NEWT_EXIT_TIMER } reason;
219 union {
220 int watch;
221 int key;
222 newtComponent co;
223 } u;
224 } ;
225
226 newtComponent newtForm(newtComponent vertBar, void * helpTag, int flags);
227 void newtFormSetTimer(newtComponent form, int millisecs);
228 void newtFormWatchFd(newtComponent form, int fd, int fdFlags);
229 void newtFormSetSize(newtComponent co);
230 newtComponent newtFormGetCurrent(newtComponent co);
231 void newtFormSetBackground(newtComponent co, int color);
232 void newtFormSetCurrent(newtComponent co, newtComponent subco);
233 void newtFormAddComponent(newtComponent form, newtComponent co);
234 void newtFormAddComponents(newtComponent form, ...);
235 void newtFormSetHeight(newtComponent co, int height);
236 void newtFormSetWidth(newtComponent co, int width);
237 newtComponent newtRunForm(newtComponent form); /* obsolete */
238 void newtFormRun(newtComponent co, struct newtExitStruct * es);
239 void newtDrawForm(newtComponent form);
240 void newtFormAddHotKey(newtComponent co, int key);
241
242 typedef int (*newtEntryFilter)(newtComponent entry, void * data, int ch,
243 int cursor);
244 newtComponent newtEntry(int left, int top, const char * initialValue, int width,
245 const char ** resultPtr, int flags);
246 void newtEntrySet(newtComponent co, const char * value, int cursorAtEnd);
247 void newtEntrySetFilter(newtComponent co, newtEntryFilter filter, void * data);
248 char * newtEntryGetValue(newtComponent co);
249 void newtEntrySetFlags(newtComponent co, int flags, enum newtFlagsSense sense);
250
251 newtComponent newtScale(int left, int top, int width, long long fullValue);
252 void newtScaleSet(newtComponent co, unsigned long long amount);
253
254 void newtComponentAddCallback(newtComponent co, newtCallback f, void * data);
255 void newtComponentTakesFocus(newtComponent co, int val);
256
257 /* this also destroys all of the components (including other forms) on the
258 form */
259 void newtFormDestroy(newtComponent form);
260
261 /* Key codes */
262
263 #define NEWT_KEY_TAB '\t'
264 #define NEWT_KEY_ENTER '\r'
265 #define NEWT_KEY_SUSPEND '\032' /* ctrl - z*/
266 #define NEWT_KEY_ESCAPE '\e'
267 #define NEWT_KEY_RETURN NEWT_KEY_ENTER
268
269 #define NEWT_KEY_EXTRA_BASE 0x8000
270 #define NEWT_KEY_UP NEWT_KEY_EXTRA_BASE + 1
271 #define NEWT_KEY_DOWN NEWT_KEY_EXTRA_BASE + 2
272 #define NEWT_KEY_LEFT NEWT_KEY_EXTRA_BASE + 4
273 #define NEWT_KEY_RIGHT NEWT_KEY_EXTRA_BASE + 5
274 #define NEWT_KEY_BKSPC NEWT_KEY_EXTRA_BASE + 6
275 #define NEWT_KEY_DELETE NEWT_KEY_EXTRA_BASE + 7
276 #define NEWT_KEY_HOME NEWT_KEY_EXTRA_BASE + 8
277 #define NEWT_KEY_END NEWT_KEY_EXTRA_BASE + 9
278 #define NEWT_KEY_UNTAB NEWT_KEY_EXTRA_BASE + 10
279 #define NEWT_KEY_PGUP NEWT_KEY_EXTRA_BASE + 11
280 #define NEWT_KEY_PGDN NEWT_KEY_EXTRA_BASE + 12
281 #define NEWT_KEY_INSERT NEWT_KEY_EXTRA_BASE + 13
282
283 #define NEWT_KEY_F1 NEWT_KEY_EXTRA_BASE + 101
284 #define NEWT_KEY_F2 NEWT_KEY_EXTRA_BASE + 102
285 #define NEWT_KEY_F3 NEWT_KEY_EXTRA_BASE + 103
286 #define NEWT_KEY_F4 NEWT_KEY_EXTRA_BASE + 104
287 #define NEWT_KEY_F5 NEWT_KEY_EXTRA_BASE + 105
288 #define NEWT_KEY_F6 NEWT_KEY_EXTRA_BASE + 106
289 #define NEWT_KEY_F7 NEWT_KEY_EXTRA_BASE + 107
290 #define NEWT_KEY_F8 NEWT_KEY_EXTRA_BASE + 108
291 #define NEWT_KEY_F9 NEWT_KEY_EXTRA_BASE + 109
292 #define NEWT_KEY_F10 NEWT_KEY_EXTRA_BASE + 110
293 #define NEWT_KEY_F11 NEWT_KEY_EXTRA_BASE + 111
294 #define NEWT_KEY_F12 NEWT_KEY_EXTRA_BASE + 112
295
296 /* not really a key, but newtGetKey returns it */
297 #define NEWT_KEY_RESIZE NEWT_KEY_EXTRA_BASE + 113
298
299 #define NEWT_ANCHOR_LEFT (1 << 0)
300 #define NEWT_ANCHOR_RIGHT (1 << 1)
301 #define NEWT_ANCHOR_TOP (1 << 2)
302 #define NEWT_ANCHOR_BOTTOM (1 << 3)
303
304 #define NEWT_GRID_FLAG_GROWX (1 << 0)
305 #define NEWT_GRID_FLAG_GROWY (1 << 1)
306
307 typedef struct grid_s * newtGrid;
308 enum newtGridElement { NEWT_GRID_EMPTY = 0,
309 NEWT_GRID_COMPONENT, NEWT_GRID_SUBGRID };
310
311 newtGrid newtCreateGrid(int cols, int rows);
312 /* TYPE, what, TYPE, what, ..., NULL */
313 newtGrid newtGridVStacked(enum newtGridElement type, void * what, ...);
314 newtGrid newtGridVCloseStacked(enum newtGridElement type, void * what, ...);
315 newtGrid newtGridHStacked(enum newtGridElement type1, void * what1, ...);
316 newtGrid newtGridHCloseStacked(enum newtGridElement type1, void * what1, ...);
317 newtGrid newtGridBasicWindow(newtComponent text, newtGrid middle,
318 newtGrid buttons);
319 newtGrid newtGridSimpleWindow(newtComponent text, newtComponent middle,
320 newtGrid buttons);
321 void newtGridSetField(newtGrid grid, int col, int row,
322 enum newtGridElement type, void * val, int padLeft,
323 int padTop, int padRight, int padBottom, int anchor,
324 int flags);
325 void newtGridPlace(newtGrid grid, int left, int top);
326 #define newtGridDestroy newtGridFree
327 void newtGridFree(newtGrid grid, int recurse);
328 void newtGridGetSize(newtGrid grid, int * width, int * height);
329 void newtGridWrappedWindow(newtGrid grid, char * title);
330 void newtGridWrappedWindowAt(newtGrid grid, char * title, int left, int top);
331 void newtGridAddComponentsToForm(newtGrid grid, newtComponent form,
332 int recurse);
333
334 /* convienve */
335 newtGrid newtButtonBarv(char * button1, newtComponent * b1comp, va_list args);
336 newtGrid newtButtonBar(char * button1, newtComponent * b1comp, ...);
337
338 /* automatically centered and shrink wrapped */
339 void newtWinMessage(char * title, char * buttonText, char * text, ...);
340 void newtWinMessagev(char * title, char * buttonText, char * text,
341 va_list argv);
342
343 /* having separate calls for these two seems silly, but having two separate
344 variable length-arg lists seems like a bad idea as well */
345
346 /* Returns 0 if F12 was pressed, 1 for button1, 2 for button2 */
347 int newtWinChoice(char * title, char * button1, char * button2,
348 char * text, ...);
349 /* Returns 0 if F12 was pressed, 1 for button1, 2 for button2,
350 3 for button3 */
351 int newtWinTernary(char * title, char * button1, char * button2,
352 char * button3, char * message, ...);
353
354 /* Returns the button number pressed, 0 on F12 */
355 int newtWinMenu(char * title, char * text, int suggestedWidth, int flexDown,
356 int flexUp, int maxListHeight, char ** items, int * listItem,
357 char * button1, ...);
358
359 struct newtWinEntry {
360 char * text;
361 const char ** value; /* may be initialized to set default */
362 int flags;
363 };
364
365 /* Returns the button number pressed, 0 on F12. The final values are
366 dynamically allocated, and need to be freed. */
367 int newtWinEntries(char * title, char * text, int suggestedWidth, int flexDown,
368 int flexUp, int dataWidth,
369 struct newtWinEntry * items, char * button1, ...);
370
371 #ifdef __cplusplus
372 } /* End of extern "C" { */
373 #endif
374
375 #endif /* H_NEWT */