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