~ubuntu-branches/ubuntu/dapper/newt/dapper

« back to all changes in this revision

Viewing changes to newt.h

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2005-03-22 12:44:37 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050322124437-nuhl0pqjcijjno9z
Tags: 0.51.6-20ubuntu3
Add Xhosa translation (thanks, Adi Attar).

Show diffs side-by-side

added added

removed removed

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