]> git.ipfire.org Git - thirdparty/newt.git/blob - newt.h
f7b44350112fb69167ca9515e381d9e2fc963aa1
[thirdparty/newt.git] / newt.h
1 #ifndef H_NEWT
2 #define H_NEWT
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 #define NEWT_COLORSET_ROOT 2
9 #define NEWT_COLORSET_BORDER 3
10 #define NEWT_COLORSET_WINDOW 4
11 #define NEWT_COLORSET_SHADOW 5
12 #define NEWT_COLORSET_TITLE 6
13 #define NEWT_COLORSET_BUTTON 7
14 #define NEWT_COLORSET_ACTBUTTON 8
15 #define NEWT_COLORSET_CHECKBOX 9
16 #define NEWT_COLORSET_ACTCHECKBOX 10
17 #define NEWT_COLORSET_ENTRY 11
18 #define NEWT_COLORSET_LABEL 12
19 #define NEWT_COLORSET_LISTBOX 13
20 #define NEWT_COLORSET_ACTLISTBOX 14
21 #define NEWT_COLORSET_TEXTBOX 15
22 #define NEWT_COLORSET_ACTTEXTBOX 16
23 #define NEWT_COLORSET_HELPLINE 17
24 #define NEWT_COLORSET_ROOTTEXT 18
25 #define NEWT_COLORSET_EMPTYSCALE 19
26 #define NEWT_COLORSET_FULLSCALE 20
27 #define NEWT_COLORSET_DISENTRY 21
28 #define NEWT_COLORSET_COMPACTBUTTON 22
29 #define NEWT_COLORSET_ACTSELLISTBOX 23
30 #define NEWT_COLORSET_SELLISTBOX 24
31
32 struct newtColors {
33 char * rootFg, * rootBg;
34 char * borderFg, * borderBg;
35 char * windowFg, * windowBg;
36 char * shadowFg, * shadowBg;
37 char * titleFg, * titleBg;
38 char * buttonFg, * buttonBg;
39 char * actButtonFg, * actButtonBg;
40 char * checkboxFg, * checkboxBg;
41 char * actCheckboxFg, * actCheckboxBg;
42 char * entryFg, * entryBg;
43 char * labelFg, * labelBg;
44 char * listboxFg, * listboxBg;
45 char * actListboxFg, * actListboxBg;
46 char * textboxFg, * textboxBg;
47 char * actTextboxFg, * actTextboxBg;
48 char * helpLineFg, * helpLineBg;
49 char * rootTextFg, * rootTextBg;
50 char * emptyScale, * fullScale;
51 char * disabledEntryFg, * disabledEntryBg;
52 char * compactButtonFg, * compactButtonBg;
53 char * actSelListboxFg, * actSelListboxBg;
54 char * selListboxFg, * selListboxBg;
55 };
56
57 enum newtFlagsSense { NEWT_FLAGS_SET, NEWT_FLAGS_RESET, NEWT_FLAGS_TOGGLE };
58
59 #define NEWT_FLAG_RETURNEXIT (1 << 0)
60 #define NEWT_FLAG_HIDDEN (1 << 1)
61 #define NEWT_FLAG_SCROLL (1 << 2)
62 #define NEWT_FLAG_DISABLED (1 << 3)
63 #define NEWT_FLAG_NOSCROLL (1 << 4) /* for listboxes */
64 #define NEWT_FLAG_DOBORDER (1 << 5)
65 #define NEWT_FLAG_WRAP (1 << 6)
66 #define NEWT_FLAG_NOF12 (1 << 7)
67 #define NEWT_FLAG_MULTIPLE (1 << 8)
68 #define NEWT_FLAG_SELECTED (1 << 9)
69
70 /* Backwards compatibility */
71 #define NEWT_LISTBOX_RETURNEXIT NEWT_FLAG_RETURNEXIT
72 #define NEWT_ENTRY_SCROLL NEWT_FLAG_SCROLL
73 #define NEWT_ENTRY_HIDDEN NEWT_FLAG_HIDDEN
74 #define NEWT_ENTRY_RETURNEXIT NEWT_FLAG_RETURNEXIT
75 #define NEWT_ENTRY_DISABLED NEWT_FLAG_DISABLED
76
77 #define NEWT_TEXTBOX_WRAP NEWT_FLAG_WRAP
78 #define NEWT_TEXTBOX_SCROLL NEWT_FLAG_SCROLL
79 #define NEWT_FORM_NOF12 NEWT_FLAG_NOF12
80
81 typedef struct newtComponent_struct * newtComponent;
82
83 extern struct newtColors newtDefaultColorPalette;
84
85 typedef void (*newtCallback)(newtComponent, void *);
86 typedef void (*newtSuspendCallback)(void);
87
88 int newtInit(void);
89 int newtFinished(void);
90 void newtCls(void);
91 void newtWaitForKey(void);
92 void newtClearKeyBuffer(void);
93 void newtDelay(int usecs);
94 /* top, left are *not* counting the border */
95 int newtOpenWindow(int left, int top, int width, int height,
96 const char * title);
97 void newtPopWindow(void);
98 void newtSetColors(struct newtColors colors);
99 void newtRefresh(void);
100 void newtSuspend(void);
101 void newtSetSuspendCallback(newtSuspendCallback cb);
102 void newtResume(void);
103 void newtPushHelpLine(const char * text);
104 void newtRedrawHelpLine(void);
105 void newtPopHelpLine(void);
106 void newtDrawRootText(int row, int col, const char * text);
107 void newtBell(void);
108
109 /* Components */
110
111 newtComponent newtCompactButton(int left, int top, const char * text);
112 newtComponent newtButton(int left, int top, const char * text);
113 newtComponent newtCheckbox(int left, int top, const char * text, char defValue,
114 const char * seq, char * result);
115 newtComponent newtRadiobutton(int left, int top, const char * text, int isDefault,
116 newtComponent prevButton);
117 newtComponent newtRadioGetCurrent(newtComponent setMember);
118 newtComponent newtListitem(int left, int top, const char * text, int isDefault,
119 newtComponent prevItem, const void * data, int flags);
120 void newtListitemSet(newtComponent co, const char * text);
121 void * newtListitemGetData(newtComponent co);
122
123 newtComponent newtLabel(int left, int top, const char * text);
124 void newtLabelSetText(newtComponent co, const char * text);
125 newtComponent newtVerticalScrollbar(int left, int top, int height,
126 int normalColorset, int thumbColorset);
127 void newtScrollbarSet(newtComponent co, int where, int total);
128
129 newtComponent newtListbox(int left, int top, int height, int flags);
130 void * newtListboxGetCurrent(newtComponent co);
131 void newtListboxSetCurrent(newtComponent co, int num);
132 void newtListboxSetText(newtComponent co, int num, const char * text);
133 void newtListboxSetEntry(newtComponent co, int num, const char * text);
134 void newtListboxSetWidth(newtComponent co, int width);
135 /* return the data passed to AddEntry */
136 void newtListboxSetData(newtComponent co, int num, void * data);
137 int newtListboxAddEntry(newtComponent co, const char * text, const void * data);
138 int newtListboxInsertEntry(newtComponent co, const char * text, const void * data, int num);
139 int newtListboxDeleteEntry(newtComponent co, int num);
140 void newtListboxClear(newtComponent co); /* removes all entries from listbox */
141 void newtListboxGetEntry(newtComponent co, int num, char **text, void **data);
142 /* Returns an array of data pointers from items, last element is NULL */
143 void **newtListboxGetSelection(newtComponent co, int *numitems);
144 void newtListboxClearSelection(newtComponent co);
145 void newtListboxSelectItem(newtComponent co, int item,
146 enum newtFlagsSense sense);
147
148
149 newtComponent newtTextbox(int left, int top, int with, int height, int flags);
150 void newtTextboxSetText(newtComponent co, const char * text);
151 void newtTextboxSetHeight(newtComponent co, int height);
152 int newtTextboxGetNumLines(newtComponent co);
153
154 struct newtExitStruct {
155 enum { NEWT_EXIT_HOTKEY, NEWT_EXIT_COMPONENT } reason;
156 union {
157 int key;
158 newtComponent co;
159 } u;
160 } ;
161
162 newtComponent newtForm(newtComponent vertBar, const char * help, int flags);
163 newtComponent newtFormGetCurrent(newtComponent co);
164 void newtFormSetBackground(newtComponent co, int color);
165 void newtFormSetCurrent(newtComponent co, newtComponent subco);
166 void newtFormAddComponent(newtComponent form, newtComponent co);
167 void newtFormAddComponents(newtComponent form, ...);
168 void newtFormSetHeight(newtComponent co, int height);
169 void newtFormSetWidth(newtComponent co, int width);
170 newtComponent newtRunForm(newtComponent form); /* obsolete */
171 void newtFormRun(newtComponent co, struct newtExitStruct * es);
172 void newtDrawForm(newtComponent form);
173 void newtFormAddHotKey(newtComponent co, int key);
174
175 newtComponent newtEntry(int left, int top, const char * initialValue, int width,
176 char ** resultPtr, int flags);
177 void newtEntrySet(newtComponent co, const char * value, int cursorAtEnd);
178 void newtEntrySetFlags(newtComponent co, int flags, enum newtFlagsSense sense);
179
180 newtComponent newtScale(int left, int top, int width, long long fullValue);
181 void newtScaleSet(newtComponent co, unsigned long long amount);
182
183 void newtComponentAddCallback(newtComponent co, newtCallback f, void * data);
184 void newtComponentTakesFocus(newtComponent co, int val);
185
186 /* this also destroys all of the components (including other forms) on the
187 form */
188 void newtFormDestroy(newtComponent form);
189
190 /* Key codes */
191
192 #define NEWT_KEY_TAB '\t'
193 #define NEWT_KEY_ENTER '\r'
194 #define NEWT_KEY_SUSPEND '\032' /* ctrl - z*/
195 #define NEWT_KEY_RETURN NEWT_KEY_ENTER
196
197 #define NEWT_KEY_EXTRA_BASE 0x8000
198 #define NEWT_KEY_UP NEWT_KEY_EXTRA_BASE + 1
199 #define NEWT_KEY_DOWN NEWT_KEY_EXTRA_BASE + 2
200 #define NEWT_KEY_LEFT NEWT_KEY_EXTRA_BASE + 4
201 #define NEWT_KEY_RIGHT NEWT_KEY_EXTRA_BASE + 5
202 #define NEWT_KEY_BKSPC NEWT_KEY_EXTRA_BASE + 6
203 #define NEWT_KEY_DELETE NEWT_KEY_EXTRA_BASE + 7
204 #define NEWT_KEY_HOME NEWT_KEY_EXTRA_BASE + 8
205 #define NEWT_KEY_END NEWT_KEY_EXTRA_BASE + 9
206 #define NEWT_KEY_UNTAB NEWT_KEY_EXTRA_BASE + 10
207 #define NEWT_KEY_PGUP NEWT_KEY_EXTRA_BASE + 11
208 #define NEWT_KEY_PGDN NEWT_KEY_EXTRA_BASE + 12
209
210 #define NEWT_KEY_F1 NEWT_KEY_EXTRA_BASE + 101
211 #define NEWT_KEY_F2 NEWT_KEY_EXTRA_BASE + 102
212 #define NEWT_KEY_F3 NEWT_KEY_EXTRA_BASE + 103
213 #define NEWT_KEY_F4 NEWT_KEY_EXTRA_BASE + 104
214 #define NEWT_KEY_F5 NEWT_KEY_EXTRA_BASE + 105
215 #define NEWT_KEY_F6 NEWT_KEY_EXTRA_BASE + 106
216 #define NEWT_KEY_F7 NEWT_KEY_EXTRA_BASE + 107
217 #define NEWT_KEY_F8 NEWT_KEY_EXTRA_BASE + 108
218 #define NEWT_KEY_F9 NEWT_KEY_EXTRA_BASE + 109
219 #define NEWT_KEY_F10 NEWT_KEY_EXTRA_BASE + 110
220 #define NEWT_KEY_F11 NEWT_KEY_EXTRA_BASE + 111
221 #define NEWT_KEY_F12 NEWT_KEY_EXTRA_BASE + 112
222
223 #define NEWT_ANCHOR_LEFT (1 << 0)
224 #define NEWT_ANCHOR_RIGHT (1 << 1)
225 #define NEWT_ANCHOR_TOP (1 << 2)
226 #define NEWT_ANCHOR_BOTTOM (1 << 3)
227
228 #define NEWT_GRID_FLAG_GROWX (1 << 0)
229 #define NEWT_GRID_FLAG_GROWY (1 << 1)
230
231 typedef struct grid_s * newtGrid;
232 enum newtGridElement { NEWT_GRID_EMPTY = 0,
233 NEWT_GRID_COMPONENT, NEWT_GRID_SUBGRID };
234
235 newtGrid newtCreateGrid(int cols, int rows);
236 void newtGridSetField(newtGrid grid, int col, int row,
237 enum newtGridElement type, void * val, int padLeft,
238 int padTop, int padRight, int padBottom, int anchor,
239 int flags);
240 void newtGridPlace(newtGrid grid, int left, int top);
241 void newtGridFree(newtGrid grid, int recurse);
242 void newtGridGetSize(newtGrid grid, int * width, int * height);
243
244 #ifdef __cplusplus
245 } /* End of extern "C" { */
246 #endif
247
248 #endif /* H_NEWT */