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)
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)
81 #define NEWT_CHECKBOXTREE_UNSELECTABLE (1 << 12)
82 #define NEWT_CHECKBOXTREE_HIDE_BOX (1 << 13)
84 #define NEWT_CHECKBOXTREE_COLLAPSED '\0'
85 #define NEWT_CHECKBOXTREE_EXPANDED '\1'
86 #define NEWT_CHECKBOXTREE_UNSELECTED ' '
87 #define NEWT_CHECKBOXTREE_SELECTED '*'
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
96 #define NEWT_TEXTBOX_WRAP NEWT_FLAG_WRAP
97 #define NEWT_TEXTBOX_SCROLL NEWT_FLAG_SCROLL
98 #define NEWT_FORM_NOF12 NEWT_FLAG_NOF12
100 #define newtListboxAddEntry newtListboxAppendEntry
103 typedef struct newtComponent_struct
* newtComponent
;
105 extern const struct newtColors newtDefaultColorPalette
;
107 typedef void (*newtCallback
)(newtComponent
, void *);
108 typedef void (*newtSuspendCallback
)(void * data
);
111 int newtFinished(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
,
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 newtSetColor(int colorset
, char *fg
, char *bg
);
126 void newtRefresh(void);
127 void newtSuspend(void);
128 void newtSetSuspendCallback(newtSuspendCallback cb
, void * data
);
129 void newtSetHelpCallback(newtCallback cb
);
130 int newtResume(void);
131 void newtPushHelpLine(const char * text
);
132 void newtRedrawHelpLine(void);
133 void newtPopHelpLine(void);
134 void newtDrawRootText(int col
, int row
, const char * text
);
136 void newtCursorOff(void);
137 void newtCursorOn(void);
141 newtComponent
newtCompactButton(int left
, int top
, const char * text
);
142 newtComponent
newtButton(int left
, int top
, const char * text
);
143 newtComponent
newtCheckbox(int left
, int top
, const char * text
, char defValue
,
144 const char * seq
, char * result
);
145 char newtCheckboxGetValue(newtComponent co
);
146 void newtCheckboxSetValue(newtComponent co
, char value
);
147 void newtCheckboxSetFlags(newtComponent co
, int flags
, enum newtFlagsSense sense
);
150 newtComponent
newtRadiobutton(int left
, int top
, const char * text
, int isDefault
,
151 newtComponent prevButton
);
152 newtComponent
newtRadioGetCurrent(newtComponent setMember
);
153 void newtRadioSetCurrent(newtComponent setMember
);
154 newtComponent
newtListitem(int left
, int top
, const char * text
, int isDefault
,
155 newtComponent prevItem
, const void * data
, int flags
);
156 void newtListitemSet(newtComponent co
, const char * text
);
157 void * newtListitemGetData(newtComponent co
);
158 void newtGetScreenSize(int * cols
, int * rows
);
160 newtComponent
newtLabel(int left
, int top
, const char * text
);
161 void newtLabelSetText(newtComponent co
, const char * text
);
162 newtComponent
newtVerticalScrollbar(int left
, int top
, int height
,
163 int normalColorset
, int thumbColorset
);
164 void newtScrollbarSet(newtComponent co
, int where
, int total
);
166 newtComponent
newtListbox(int left
, int top
, int height
, int flags
);
167 void * newtListboxGetCurrent(newtComponent co
);
168 void newtListboxSetCurrent(newtComponent co
, int num
);
169 void newtListboxSetCurrentByKey(newtComponent co
, void * key
);
170 void newtListboxSetEntry(newtComponent co
, int num
, const char * text
);
171 void newtListboxSetWidth(newtComponent co
, int width
);
172 void newtListboxSetData(newtComponent co
, int num
, void * data
);
173 int newtListboxAppendEntry(newtComponent co
, const char * text
,
175 /* Send the key to insert after, or NULL to insert at the top */
176 int newtListboxInsertEntry(newtComponent co
, const char * text
, const void * data
, void * key
);
177 int newtListboxDeleteEntry(newtComponent co
, void * data
);
178 void newtListboxClear(newtComponent co
); /* removes all entries from listbox */
179 void newtListboxGetEntry(newtComponent co
, int num
, char **text
, void **data
);
180 /* Returns an array of data pointers from items, last element is NULL */
181 void **newtListboxGetSelection(newtComponent co
, int *numitems
);
182 void newtListboxClearSelection(newtComponent co
);
183 void newtListboxSelectItem(newtComponent co
, const void * key
,
184 enum newtFlagsSense sense
);
185 /* Returns number of items currently in listbox. */
186 int newtListboxItemCount(newtComponent co
);
188 newtComponent
newtCheckboxTree(int left
, int top
, int height
, int flags
);
189 newtComponent
newtCheckboxTreeMulti(int left
, int top
, int height
, char *seq
, int flags
);
190 const void ** newtCheckboxTreeGetSelection(newtComponent co
, int *numitems
);
191 const void * newtCheckboxTreeGetCurrent(newtComponent co
);
192 void newtCheckboxTreeSetCurrent(newtComponent co
, void * item
);
193 const void ** newtCheckboxTreeGetMultiSelection(newtComponent co
, int *numitems
, char seqnum
);
194 /* last item is NEWT_ARG_LAST for all of these */
195 int newtCheckboxTreeAddItem(newtComponent co
,
196 const char * text
, const void * data
,
197 int flags
, int index
, ...);
198 int newtCheckboxTreeAddArray(newtComponent co
,
199 const char * text
, const void * data
,
200 int flags
, int * indexes
);
201 int * newtCheckboxTreeFindItem(newtComponent co
, void * data
);
202 void newtCheckboxTreeSetEntry(newtComponent co
, const void * data
,
204 void newtCheckboxTreeSetWidth(newtComponent co
, int width
);
205 char newtCheckboxTreeGetEntryValue(newtComponent co
, const void * data
);
206 void newtCheckboxTreeSetEntryValue(newtComponent co
, const void * data
,
209 newtComponent
newtTextboxReflowed(int left
, int top
, char * text
, int width
,
210 int flexDown
, int flexUp
, int flags
);
211 newtComponent
newtTextbox(int left
, int top
, int width
, int height
, int flags
);
212 void newtTextboxSetText(newtComponent co
, const char * text
);
213 void newtTextboxSetHeight(newtComponent co
, int height
);
214 int newtTextboxGetNumLines(newtComponent co
);
215 char * newtReflowText(char * text
, int width
, int flexDown
, int flexUp
,
216 int * actualWidth
, int * actualHeight
);
218 struct newtExitStruct
{
219 enum { NEWT_EXIT_HOTKEY
, NEWT_EXIT_COMPONENT
, NEWT_EXIT_FDREADY
,
220 NEWT_EXIT_TIMER
} reason
;
228 newtComponent
newtForm(newtComponent vertBar
, void * helpTag
, int flags
);
229 void newtFormSetTimer(newtComponent form
, int millisecs
);
230 void newtFormWatchFd(newtComponent form
, int fd
, int fdFlags
);
231 void newtFormSetSize(newtComponent co
);
232 newtComponent
newtFormGetCurrent(newtComponent co
);
233 void newtFormSetBackground(newtComponent co
, int color
);
234 void newtFormSetCurrent(newtComponent co
, newtComponent subco
);
235 void newtFormAddComponent(newtComponent form
, newtComponent co
);
236 void newtFormAddComponents(newtComponent form
, ...);
237 void newtFormSetHeight(newtComponent co
, int height
);
238 void newtFormSetWidth(newtComponent co
, int width
);
239 newtComponent
newtRunForm(newtComponent form
); /* obsolete */
240 void newtFormRun(newtComponent co
, struct newtExitStruct
* es
);
241 void newtDrawForm(newtComponent form
);
242 void newtFormAddHotKey(newtComponent co
, int key
);
244 typedef int (*newtEntryFilter
)(newtComponent entry
, void * data
, int ch
,
246 newtComponent
newtEntry(int left
, int top
, const char * initialValue
, int width
,
247 const char ** resultPtr
, int flags
);
248 void newtEntrySet(newtComponent co
, const char * value
, int cursorAtEnd
);
249 void newtEntrySetFilter(newtComponent co
, newtEntryFilter filter
, void * data
);
250 char * newtEntryGetValue(newtComponent co
);
251 void newtEntrySetFlags(newtComponent co
, int flags
, enum newtFlagsSense sense
);
253 newtComponent
newtScale(int left
, int top
, int width
, long long fullValue
);
254 void newtScaleSet(newtComponent co
, unsigned long long amount
);
256 void newtComponentAddCallback(newtComponent co
, newtCallback f
, void * data
);
257 void newtComponentTakesFocus(newtComponent co
, int val
);
259 /* This callback is called when a component is destroyed. */
260 void newtComponentAddDestroyCallback(newtComponent co
,
261 newtCallback f
, void * data
);
263 /* this also destroys all of the components (including other forms) on the
265 void newtFormDestroy(newtComponent form
);
267 /* NB: You SHOULD NOT call this for components which have been added
268 * to a form (ie. almost all components). They are destroyed along
269 * with the form when you call newtFormDestroy.
271 void newtComponentDestroy(newtComponent co
);
275 #define NEWT_KEY_TAB '\t'
276 #define NEWT_KEY_ENTER '\r'
277 #define NEWT_KEY_SUSPEND '\032' /* ctrl - z*/
278 #define NEWT_KEY_ESCAPE '\e'
279 #define NEWT_KEY_RETURN NEWT_KEY_ENTER
281 #define NEWT_KEY_EXTRA_BASE 0x8000
282 #define NEWT_KEY_UP NEWT_KEY_EXTRA_BASE + 1
283 #define NEWT_KEY_DOWN NEWT_KEY_EXTRA_BASE + 2
284 #define NEWT_KEY_LEFT NEWT_KEY_EXTRA_BASE + 4
285 #define NEWT_KEY_RIGHT NEWT_KEY_EXTRA_BASE + 5
286 #define NEWT_KEY_BKSPC NEWT_KEY_EXTRA_BASE + 6
287 #define NEWT_KEY_DELETE NEWT_KEY_EXTRA_BASE + 7
288 #define NEWT_KEY_HOME NEWT_KEY_EXTRA_BASE + 8
289 #define NEWT_KEY_END NEWT_KEY_EXTRA_BASE + 9
290 #define NEWT_KEY_UNTAB NEWT_KEY_EXTRA_BASE + 10
291 #define NEWT_KEY_PGUP NEWT_KEY_EXTRA_BASE + 11
292 #define NEWT_KEY_PGDN NEWT_KEY_EXTRA_BASE + 12
293 #define NEWT_KEY_INSERT NEWT_KEY_EXTRA_BASE + 13
295 #define NEWT_KEY_F1 NEWT_KEY_EXTRA_BASE + 101
296 #define NEWT_KEY_F2 NEWT_KEY_EXTRA_BASE + 102
297 #define NEWT_KEY_F3 NEWT_KEY_EXTRA_BASE + 103
298 #define NEWT_KEY_F4 NEWT_KEY_EXTRA_BASE + 104
299 #define NEWT_KEY_F5 NEWT_KEY_EXTRA_BASE + 105
300 #define NEWT_KEY_F6 NEWT_KEY_EXTRA_BASE + 106
301 #define NEWT_KEY_F7 NEWT_KEY_EXTRA_BASE + 107
302 #define NEWT_KEY_F8 NEWT_KEY_EXTRA_BASE + 108
303 #define NEWT_KEY_F9 NEWT_KEY_EXTRA_BASE + 109
304 #define NEWT_KEY_F10 NEWT_KEY_EXTRA_BASE + 110
305 #define NEWT_KEY_F11 NEWT_KEY_EXTRA_BASE + 111
306 #define NEWT_KEY_F12 NEWT_KEY_EXTRA_BASE + 112
308 /* not really a key, but newtGetKey returns it */
309 #define NEWT_KEY_RESIZE NEWT_KEY_EXTRA_BASE + 113
311 #define NEWT_ANCHOR_LEFT (1 << 0)
312 #define NEWT_ANCHOR_RIGHT (1 << 1)
313 #define NEWT_ANCHOR_TOP (1 << 2)
314 #define NEWT_ANCHOR_BOTTOM (1 << 3)
316 #define NEWT_GRID_FLAG_GROWX (1 << 0)
317 #define NEWT_GRID_FLAG_GROWY (1 << 1)
319 typedef struct grid_s
* newtGrid
;
320 enum newtGridElement
{ NEWT_GRID_EMPTY
= 0,
321 NEWT_GRID_COMPONENT
, NEWT_GRID_SUBGRID
};
323 newtGrid
newtCreateGrid(int cols
, int rows
);
324 /* TYPE, what, TYPE, what, ..., NULL */
325 newtGrid
newtGridVStacked(enum newtGridElement type
, void * what
, ...);
326 newtGrid
newtGridVCloseStacked(enum newtGridElement type
, void * what
, ...);
327 newtGrid
newtGridHStacked(enum newtGridElement type1
, void * what1
, ...);
328 newtGrid
newtGridHCloseStacked(enum newtGridElement type1
, void * what1
, ...);
329 newtGrid
newtGridBasicWindow(newtComponent text
, newtGrid middle
,
331 newtGrid
newtGridSimpleWindow(newtComponent text
, newtComponent middle
,
333 void newtGridSetField(newtGrid grid
, int col
, int row
,
334 enum newtGridElement type
, void * val
, int padLeft
,
335 int padTop
, int padRight
, int padBottom
, int anchor
,
337 void newtGridPlace(newtGrid grid
, int left
, int top
);
338 #define newtGridDestroy newtGridFree
339 void newtGridFree(newtGrid grid
, int recurse
);
340 void newtGridGetSize(newtGrid grid
, int * width
, int * height
);
341 void newtGridWrappedWindow(newtGrid grid
, char * title
);
342 void newtGridWrappedWindowAt(newtGrid grid
, char * title
, int left
, int top
);
343 void newtGridAddComponentsToForm(newtGrid grid
, newtComponent form
,
347 newtGrid
newtButtonBarv(char * button1
, newtComponent
* b1comp
, va_list args
);
348 newtGrid
newtButtonBar(char * button1
, newtComponent
* b1comp
, ...);
350 /* automatically centered and shrink wrapped */
351 void newtWinMessage(char * title
, char * buttonText
, char * text
, ...);
352 void newtWinMessagev(char * title
, char * buttonText
, char * text
,
355 /* having separate calls for these two seems silly, but having two separate
356 variable length-arg lists seems like a bad idea as well */
358 /* Returns 0 if F12 was pressed, 1 for button1, 2 for button2 */
359 int newtWinChoice(char * title
, char * button1
, char * button2
,
361 /* Returns 0 if F12 was pressed, 1 for button1, 2 for button2,
363 int newtWinTernary(char * title
, char * button1
, char * button2
,
364 char * button3
, char * message
, ...);
366 /* Returns the button number pressed, 0 on F12 */
367 int newtWinMenu(char * title
, char * text
, int suggestedWidth
, int flexDown
,
368 int flexUp
, int maxListHeight
, char ** items
, int * listItem
,
369 char * button1
, ...);
371 struct newtWinEntry
{
373 char ** value
; /* may be initialized to set default */
377 /* Returns the button number pressed, 0 on F12. The final values are
378 dynamically allocated, and need to be freed. */
379 int newtWinEntries(char * title
, char * text
, int suggestedWidth
, int flexDown
,
380 int flexUp
, int dataWidth
,
381 struct newtWinEntry
* items
, char * button1
, ...);
384 } /* End of extern "C" { */