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
34 #define NEWT_ARG_LAST -100000
35 #define NEWT_ARG_APPEND -1
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
;
62 enum newtFlagsSense
{ NEWT_FLAGS_SET
, NEWT_FLAGS_RESET
, NEWT_FLAGS_TOGGLE
};
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)
76 #define NEWT_FD_READ (1 << 0)
77 #define NEWT_FD_WRITE (1 << 1)
79 #define NEWT_CHECKBOXTREE_COLLAPSED '\0'
80 #define NEWT_CHECKBOXTREE_EXPANDED '\1'
81 #define NEWT_CHECKBOXTREE_UNSELECTED ' '
82 #define NEWT_CHECKBOXTREE_SELECTED '*'
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
91 #define NEWT_TEXTBOX_WRAP NEWT_FLAG_WRAP
92 #define NEWT_TEXTBOX_SCROLL NEWT_FLAG_SCROLL
93 #define NEWT_FORM_NOF12 NEWT_FLAG_NOF12
95 #define newtListboxAddEntry newtListboxAppendEntry
98 typedef struct newtComponent_struct
* newtComponent
;
100 extern const struct newtColors newtDefaultColorPalette
;
102 typedef void (*newtCallback
)(newtComponent
, void *);
103 typedef void (*newtSuspendCallback
)(void * data
);
106 int newtFinished(void);
108 void newtResizeScreen(int redraw
);
109 void newtWaitForKey(void);
110 void newtClearKeyBuffer(void);
111 void newtDelay(int usecs
);
112 /* top, left are *not* counting the border */
113 int newtOpenWindow(int left
, int top
, int width
, int height
,
115 int newtCenteredWindow(int width
, int height
, const char * title
);
116 void newtPopWindow(void);
117 void newtSetColors(struct newtColors colors
);
118 void newtRefresh(void);
119 void newtSuspend(void);
120 void newtSetSuspendCallback(newtSuspendCallback cb
, void * data
);
121 void newtSetHelpCallback(newtCallback cb
);
122 void newtResume(void);
123 void newtPushHelpLine(const char * text
);
124 void newtRedrawHelpLine(void);
125 void newtPopHelpLine(void);
126 void newtDrawRootText(int col
, int row
, const char * text
);
131 newtComponent
newtCompactButton(int left
, int top
, const char * text
);
132 newtComponent
newtButton(int left
, int top
, const char * text
);
133 newtComponent
newtCheckbox(int left
, int top
, const char * text
, char defValue
,
134 const char * seq
, char * result
);
135 char newtCheckboxGetValue(newtComponent co
);
136 void newtCheckboxSetValue(newtComponent co
, char value
);
137 void newtCheckboxSetFlags(newtComponent co
, int flags
, enum newtFlagsSense sense
);
140 newtComponent
newtRadiobutton(int left
, int top
, const char * text
, int isDefault
,
141 newtComponent prevButton
);
142 newtComponent
newtRadioGetCurrent(newtComponent setMember
);
143 newtComponent
newtListitem(int left
, int top
, const char * text
, int isDefault
,
144 newtComponent prevItem
, const void * data
, int flags
);
145 void newtListitemSet(newtComponent co
, const char * text
);
146 void * newtListitemGetData(newtComponent co
);
147 void newtGetScreenSize(int * cols
, int * rows
);
149 newtComponent
newtLabel(int left
, int top
, const char * text
);
150 void newtLabelSetText(newtComponent co
, const char * text
);
151 newtComponent
newtVerticalScrollbar(int left
, int top
, int height
,
152 int normalColorset
, int thumbColorset
);
153 void newtScrollbarSet(newtComponent co
, int where
, int total
);
155 newtComponent
newtListbox(int left
, int top
, int height
, int flags
);
156 void * newtListboxGetCurrent(newtComponent co
);
157 void newtListboxSetCurrent(newtComponent co
, int num
);
158 void newtListboxSetCurrentByKey(newtComponent co
, void * key
);
159 void newtListboxSetEntry(newtComponent co
, int num
, const char * text
);
160 void newtListboxSetWidth(newtComponent co
, int width
);
161 void newtListboxSetData(newtComponent co
, int num
, void * data
);
162 int newtListboxAppendEntry(newtComponent co
, const char * text
,
164 /* Send the key to insert after, or NULL to insert at the top */
165 int newtListboxInsertEntry(newtComponent co
, const char * text
, const void * data
, void * key
);
166 int newtListboxDeleteEntry(newtComponent co
, void * data
);
167 void newtListboxClear(newtComponent co
); /* removes all entries from listbox */
168 void newtListboxGetEntry(newtComponent co
, int num
, char **text
, void **data
);
169 /* Returns an array of data pointers from items, last element is NULL */
170 void **newtListboxGetSelection(newtComponent co
, int *numitems
);
171 void newtListboxClearSelection(newtComponent co
);
172 void newtListboxSelectItem(newtComponent co
, const void * key
,
173 enum newtFlagsSense sense
);
175 newtComponent
newtCheckboxTree(int left
, int top
, int height
, int flags
);
176 newtComponent
newtCheckboxTreeMulti(int left
, int top
, int height
, char *seq
, int flags
);
177 const void ** newtCheckboxTreeGetSelection(newtComponent co
, int *numitems
);
178 const void * newtCheckboxTreeGetCurrent(newtComponent co
);
179 const void ** newtCheckboxTreeGetMultiSelection(newtComponent co
, int *numitems
, char seqnum
);
180 /* last item is NEWT_ARG_LAST for all of these */
181 int newtCheckboxTreeAddItem(newtComponent co
,
182 const char * text
, const void * data
,
183 int flags
, int index
, ...);
184 int newtCheckboxTreeAddArray(newtComponent co
,
185 const char * text
, const void * data
,
186 int flags
, int * indexes
);
187 int * newtCheckboxTreeFindItem(newtComponent co
, void * data
);
188 void newtCheckboxTreeSetEntry(newtComponent co
, const void * data
,
190 char newtCheckboxTreeGetEntryValue(newtComponent co
, const void * data
);
191 void newtCheckboxTreeSetEntryValue(newtComponent co
, const void * data
,
194 newtComponent
newtTextboxReflowed(int left
, int top
, char * text
, int width
,
195 int flexDown
, int flexUp
, int flags
);
196 newtComponent
newtTextbox(int left
, int top
, int width
, int height
, int flags
);
197 void newtTextboxSetText(newtComponent co
, const char * text
);
198 void newtTextboxSetHeight(newtComponent co
, int height
);
199 int newtTextboxGetNumLines(newtComponent co
);
200 char * newtReflowText(char * text
, int width
, int flexDown
, int flexUp
,
201 int * actualWidth
, int * actualHeight
);
203 struct newtExitStruct
{
204 enum { NEWT_EXIT_HOTKEY
, NEWT_EXIT_COMPONENT
, NEWT_EXIT_FDREADY
,
205 NEWT_EXIT_TIMER
} reason
;
212 newtComponent
newtForm(newtComponent vertBar
, void * helpTag
, int flags
);
213 void newtFormSetTimer(newtComponent form
, int millisecs
);
214 void newtFormWatchFd(newtComponent form
, int fd
, int fdFlags
);
215 void newtFormSetSize(newtComponent co
);
216 newtComponent
newtFormGetCurrent(newtComponent co
);
217 void newtFormSetBackground(newtComponent co
, int color
);
218 void newtFormSetCurrent(newtComponent co
, newtComponent subco
);
219 void newtFormAddComponent(newtComponent form
, newtComponent co
);
220 void newtFormAddComponents(newtComponent form
, ...);
221 void newtFormSetHeight(newtComponent co
, int height
);
222 void newtFormSetWidth(newtComponent co
, int width
);
223 newtComponent
newtRunForm(newtComponent form
); /* obsolete */
224 void newtFormRun(newtComponent co
, struct newtExitStruct
* es
);
225 void newtDrawForm(newtComponent form
);
226 void newtFormAddHotKey(newtComponent co
, int key
);
228 typedef int (*newtEntryFilter
)(newtComponent entry
, void * data
, int ch
,
230 newtComponent
newtEntry(int left
, int top
, const char * initialValue
, int width
,
231 char ** resultPtr
, int flags
);
232 void newtEntrySet(newtComponent co
, const char * value
, int cursorAtEnd
);
233 void newtEntrySetFilter(newtComponent co
, newtEntryFilter filter
, void * data
);
234 char * newtEntryGetValue(newtComponent co
);
235 void newtEntrySetFlags(newtComponent co
, int flags
, enum newtFlagsSense sense
);
237 newtComponent
newtScale(int left
, int top
, int width
, long long fullValue
);
238 void newtScaleSet(newtComponent co
, unsigned long long amount
);
240 void newtComponentAddCallback(newtComponent co
, newtCallback f
, void * data
);
241 void newtComponentTakesFocus(newtComponent co
, int val
);
243 /* this also destroys all of the components (including other forms) on the
245 void newtFormDestroy(newtComponent form
);
249 #define NEWT_KEY_TAB '\t'
250 #define NEWT_KEY_ENTER '\r'
251 #define NEWT_KEY_SUSPEND '\032' /* ctrl - z*/
252 #define NEWT_KEY_RETURN NEWT_KEY_ENTER
254 #define NEWT_KEY_EXTRA_BASE 0x8000
255 #define NEWT_KEY_UP NEWT_KEY_EXTRA_BASE + 1
256 #define NEWT_KEY_DOWN NEWT_KEY_EXTRA_BASE + 2
257 #define NEWT_KEY_LEFT NEWT_KEY_EXTRA_BASE + 4
258 #define NEWT_KEY_RIGHT NEWT_KEY_EXTRA_BASE + 5
259 #define NEWT_KEY_BKSPC NEWT_KEY_EXTRA_BASE + 6
260 #define NEWT_KEY_DELETE NEWT_KEY_EXTRA_BASE + 7
261 #define NEWT_KEY_HOME NEWT_KEY_EXTRA_BASE + 8
262 #define NEWT_KEY_END NEWT_KEY_EXTRA_BASE + 9
263 #define NEWT_KEY_UNTAB NEWT_KEY_EXTRA_BASE + 10
264 #define NEWT_KEY_PGUP NEWT_KEY_EXTRA_BASE + 11
265 #define NEWT_KEY_PGDN NEWT_KEY_EXTRA_BASE + 12
266 #define NEWT_KEY_INSERT NEWT_KEY_EXTRA_BASE + 13
268 #define NEWT_KEY_F1 NEWT_KEY_EXTRA_BASE + 101
269 #define NEWT_KEY_F2 NEWT_KEY_EXTRA_BASE + 102
270 #define NEWT_KEY_F3 NEWT_KEY_EXTRA_BASE + 103
271 #define NEWT_KEY_F4 NEWT_KEY_EXTRA_BASE + 104
272 #define NEWT_KEY_F5 NEWT_KEY_EXTRA_BASE + 105
273 #define NEWT_KEY_F6 NEWT_KEY_EXTRA_BASE + 106
274 #define NEWT_KEY_F7 NEWT_KEY_EXTRA_BASE + 107
275 #define NEWT_KEY_F8 NEWT_KEY_EXTRA_BASE + 108
276 #define NEWT_KEY_F9 NEWT_KEY_EXTRA_BASE + 109
277 #define NEWT_KEY_F10 NEWT_KEY_EXTRA_BASE + 110
278 #define NEWT_KEY_F11 NEWT_KEY_EXTRA_BASE + 111
279 #define NEWT_KEY_F12 NEWT_KEY_EXTRA_BASE + 112
281 /* not really a key, but newtGetKey returns it */
282 #define NEWT_KEY_RESIZE NEWT_KEY_EXTRA_BASE + 113
284 #define NEWT_ANCHOR_LEFT (1 << 0)
285 #define NEWT_ANCHOR_RIGHT (1 << 1)
286 #define NEWT_ANCHOR_TOP (1 << 2)
287 #define NEWT_ANCHOR_BOTTOM (1 << 3)
289 #define NEWT_GRID_FLAG_GROWX (1 << 0)
290 #define NEWT_GRID_FLAG_GROWY (1 << 1)
292 typedef struct grid_s
* newtGrid
;
293 enum newtGridElement
{ NEWT_GRID_EMPTY
= 0,
294 NEWT_GRID_COMPONENT
, NEWT_GRID_SUBGRID
};
296 newtGrid
newtCreateGrid(int cols
, int rows
);
297 /* TYPE, what, TYPE, what, ..., NULL */
298 newtGrid
newtGridVStacked(enum newtGridElement type
, void * what
, ...);
299 newtGrid
newtGridVCloseStacked(enum newtGridElement type
, void * what
, ...);
300 newtGrid
newtGridHStacked(enum newtGridElement type1
, void * what1
, ...);
301 newtGrid
newtGridHCloseStacked(enum newtGridElement type1
, void * what1
, ...);
302 newtGrid
newtGridBasicWindow(newtComponent text
, newtGrid middle
,
304 newtGrid
newtGridSimpleWindow(newtComponent text
, newtComponent middle
,
306 void newtGridSetField(newtGrid grid
, int col
, int row
,
307 enum newtGridElement type
, void * val
, int padLeft
,
308 int padTop
, int padRight
, int padBottom
, int anchor
,
310 void newtGridPlace(newtGrid grid
, int left
, int top
);
311 #define newtGridDestroy newtGridFree
312 void newtGridFree(newtGrid grid
, int recurse
);
313 void newtGridGetSize(newtGrid grid
, int * width
, int * height
);
314 void newtGridWrappedWindow(newtGrid grid
, char * title
);
315 void newtGridWrappedWindowAt(newtGrid grid
, char * title
, int left
, int top
);
316 void newtGridAddComponentsToForm(newtGrid grid
, newtComponent form
,
320 newtGrid
newtButtonBarv(char * button1
, newtComponent
* b1comp
, va_list args
);
321 newtGrid
newtButtonBar(char * button1
, newtComponent
* b1comp
, ...);
323 /* automatically centered and shrink wrapped */
324 void newtWinMessage(char * title
, char * buttonText
, char * text
, ...);
325 void newtWinMessagev(char * title
, char * buttonText
, char * text
,
328 /* having separate calls for these two seems silly, but having two separate
329 variable length-arg lists seems like a bad idea as well */
331 /* Returns 0 if F12 was pressed, 1 for button1, 2 for button2 */
332 int newtWinChoice(char * title
, char * button1
, char * button2
,
334 /* Returns 0 if F12 was pressed, 1 for button1, 2 for button2,
336 int newtWinTernary(char * title
, char * button1
, char * button2
,
337 char * button3
, char * message
, ...);
339 /* Returns the button number pressed, 0 on F12 */
340 int newtWinMenu(char * title
, char * text
, int suggestedWidth
, int flexDown
,
341 int flexUp
, int maxListHeight
, char ** items
, int * listItem
,
342 char * button1
, ...);
344 struct newtWinEntry
{
346 char ** value
; /* may be initialized to set default */
350 /* Returns the button number pressed, 0 on F12. The final values are
351 dynamically allocated, and need to be freed. */
352 int newtWinEntries(char * title
, char * text
, int suggestedWidth
, int flexDown
,
353 int flexUp
, int dataWidth
,
354 struct newtWinEntry
* items
, char * button1
, ...);
357 } /* End of extern "C" { */