14
void disableCallback(newtComponent co, void * data) {
15
struct callbackInfo * cbi = data;
17
if (*cbi->state == ' ') {
18
newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
20
newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
26
void suspend(void * d) {
32
void helpCallback(newtComponent co, void * tag) {
33
newtWinMessage("Help", "Ok", tag);
37
newtComponent b1, b2, r1, r2, r3, e2, e3, l1, l2, l3, scale;
38
newtComponent lb, t, rsf, timeLabel;
40
newtComponent f, chklist, e1;
41
struct callbackInfo cbis[3];
43
char * enr2, * enr3, * scaleVal;
47
const char * spinner = "-\\|/\\|/";
48
const char * spinState;
49
struct newtExitStruct es;
51
setlocale(LC_ALL, "");
56
newtSetSuspendCallback(suspend, NULL);
57
newtSetHelpCallback(helpCallback);
59
newtDrawRootText(0, 0, "Newt test program");
60
newtPushHelpLine(NULL);
61
newtDrawRootText(-50, 0, "More root text");
63
newtOpenWindow(2, 2, 30, 10, "first window");
64
newtOpenWindow(10, 5, 65, 16, "window 2");
66
f = newtForm(NULL, "This is some help text", 0);
67
chklist = newtForm(NULL, NULL, 0);
69
b1 = newtButton(3, 1, "Exit");
70
b2 = newtButton(18, 1, "Update");
71
r1 = newtRadiobutton(20, 10, "Choice 1", 0, NULL);
72
r2 = newtRadiobutton(20, 11, "Chc 2", 1, r1);
73
r3 = newtRadiobutton(20, 12, "Choice 3", 0, r2);
74
rsf = newtForm(NULL, NULL, 0);
75
newtFormAddComponents(rsf, r1, r2, r3, NULL);
76
newtFormSetBackground(rsf, NEWT_COLORSET_CHECKBOX);
78
for (i = 0; i < 10; i++) {
79
sprintf(buf, "Check %d", i);
80
cs[i] = newtCheckbox(3, 10 + i, buf, ' ', NULL, &results[i]);
81
newtFormAddComponent(chklist, cs[i]);
84
l1 = newtLabel(3, 6, "Scale:");
85
l2 = newtLabel(3, 7, "Scrolls:");
86
l3 = newtLabel(3, 8, "Hidden:");
87
e1 = newtEntry(12, 6, "", 20, &scaleVal, 0);
88
e2 = newtEntry(12, 7, "Default", 20, &enr2, NEWT_FLAG_SCROLL);
89
/* e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_HIDDEN); */
90
e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_PASSWORD);
92
cbis[0].state = &results[0];
94
newtComponentAddCallback(cs[0], disableCallback, &cbis[0]);
96
scale = newtScale(3, 14, 32, 100);
98
newtFormSetHeight(chklist, 3);
100
newtFormAddComponents(f, b1, b2, l1, l2, l3, e1, e2, e3, chklist, NULL);
101
newtFormAddComponents(f, rsf, scale, NULL);
103
lb = newtListbox(45, 1, 6, NEWT_FLAG_MULTIPLE | NEWT_FLAG_BORDER |
105
newtListboxAppendEntry(lb, "First", (void *) 1);
106
newtListboxAppendEntry(lb, "Second", (void *) 2);
107
newtListboxAppendEntry(lb, "Third", (void *) 3);
108
newtListboxAppendEntry(lb, "Fourth", (void *) 4);
109
newtListboxAppendEntry(lb, "Sixth", (void *) 6);
110
newtListboxAppendEntry(lb, "Seventh", (void *) 7);
111
newtListboxAppendEntry(lb, "Eighth", (void *) 8);
112
newtListboxAppendEntry(lb, "Ninth", (void *) 9);
113
newtListboxAppendEntry(lb, "Tenth", (void *) 10);
115
newtListboxInsertEntry(lb, "Fifth", (void *) 5, (void *) 4);
116
newtListboxInsertEntry(lb, "Eleventh", (void *) 11, (void *) 10);
117
newtListboxDeleteEntry(lb, (void *) 11);
120
timeLabel = newtLabel(45, 8, "Spinner: -");
122
t = newtTextbox(45, 10, 17, 5, NEWT_FLAG_WRAP);
123
newtTextboxSetText(t, "This is some text does it look okay?\nThis should be alone.\nThis shouldn't be printed");
125
newtFormAddComponents(f, lb, timeLabel, t, NULL);
127
newtFormSetTimer(f, 200);
132
if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == b2) {
133
newtScaleSet(scale, atoi(scaleVal));
136
} else if (es.reason == NEWT_EXIT_TIMER) {
138
if (!*spinState) spinState = spinner;
139
sprintf(buf, "Spinner: %c", *spinState);
140
newtLabelSetText(timeLabel, buf);
142
} while (es.reason != NEWT_EXIT_COMPONENT);
144
scaleVal = strdup(scaleVal);
148
selectedList = newtListboxGetSelection(lb, &numsel);
156
printf("got string 1: %s\n", scaleVal);
157
printf("got string 2: %s\n", enr2);
158
printf("got string 3: %s\n", enr3);
161
printf("\nSelected listbox items:\n");
162
for(i = 0; i < numsel; i++)
163
puts(selectedList[i]);