13
void disableCallback(newtComponent co, void * data) {
14
struct callbackInfo * cbi = data;
16
if (*cbi->state == ' ') {
17
newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
19
newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
25
void suspend(void * d) {
31
void helpCallback(newtComponent co, void * tag) {
32
newtWinMessage("Help", "Ok", tag);
36
newtComponent b1, b2, r1, r2, r3, e2, e3, l1, l2, l3, scale;
37
newtComponent lb, t, rsf, answer, timeLabel;
39
newtComponent f, chklist, e1;
40
struct callbackInfo cbis[3];
42
char * enr2, * enr3, * scaleVal;
46
const char * spinner = "-\\|/\\|/";
47
const char * spinState;
48
struct newtExitStruct es;
53
newtSetSuspendCallback(suspend, NULL);
54
newtSetHelpCallback(helpCallback);
56
newtDrawRootText(0, 0, "Newt test program");
57
newtPushHelpLine(NULL);
58
newtDrawRootText(-50, 0, "More root text");
60
newtOpenWindow(2, 2, 30, 10, "first window");
61
newtOpenWindow(10, 5, 65, 16, "window 2");
63
f = newtForm(NULL, "This is some help text", 0);
64
chklist = newtForm(NULL, NULL, 0);
66
b1 = newtButton(3, 1, "Exit");
67
b2 = newtButton(18, 1, "Update");
68
r1 = newtRadiobutton(20, 10, "Choice 1", 0, NULL);
69
r2 = newtRadiobutton(20, 11, "Chc 2", 1, r1);
70
r3 = newtRadiobutton(20, 12, "Choice 3", 0, r2);
71
rsf = newtForm(NULL, NULL, 0);
72
newtFormAddComponents(rsf, r1, r2, r3, NULL);
73
newtFormSetBackground(rsf, NEWT_COLORSET_CHECKBOX);
75
for (i = 0; i < 10; i++) {
76
sprintf(buf, "Check %d", i);
77
cs[i] = newtCheckbox(3, 10 + i, buf, ' ', NULL, &results[i]);
78
newtFormAddComponent(chklist, cs[i]);
81
l1 = newtLabel(3, 6, "Scale:");
82
l2 = newtLabel(3, 7, "Scrolls:");
83
l3 = newtLabel(3, 8, "Hidden:");
84
e1 = newtEntry(12, 6, "", 20, &scaleVal, 0);
85
e2 = newtEntry(12, 7, "Default", 20, &enr2, NEWT_FLAG_SCROLL);
86
/* e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_HIDDEN); */
87
e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_PASSWORD);
89
cbis[0].state = &results[0];
91
newtComponentAddCallback(cs[0], disableCallback, &cbis[0]);
93
scale = newtScale(3, 14, 32, 100);
95
newtFormSetHeight(chklist, 3);
97
newtFormAddComponents(f, b1, b2, l1, l2, l3, e1, e2, e3, chklist, NULL);
98
newtFormAddComponents(f, rsf, scale, NULL);
100
lb = newtListbox(45, 1, 6, NEWT_FLAG_MULTIPLE | NEWT_FLAG_BORDER |
102
newtListboxAppendEntry(lb, "First", (void *) 1);
103
newtListboxAppendEntry(lb, "Second", (void *) 2);
104
newtListboxAppendEntry(lb, "Third", (void *) 3);
105
newtListboxAppendEntry(lb, "Fourth", (void *) 4);
106
newtListboxAppendEntry(lb, "Sixth", (void *) 6);
107
newtListboxAppendEntry(lb, "Seventh", (void *) 7);
108
newtListboxAppendEntry(lb, "Eighth", (void *) 8);
109
newtListboxAppendEntry(lb, "Ninth", (void *) 9);
110
newtListboxAppendEntry(lb, "Tenth", (void *) 10);
112
newtListboxInsertEntry(lb, "Fifth", (void *) 5, (void *) 4);
113
newtListboxInsertEntry(lb, "Eleventh", (void *) 11, (void *) 10);
114
newtListboxDeleteEntry(lb, (void *) 11);
117
timeLabel = newtLabel(45, 8, "Spinner: -");
119
t = newtTextbox(45, 10, 17, 5, NEWT_FLAG_WRAP);
120
newtTextboxSetText(t, "This is some text does it look okay?\nThis should be alone.\nThis shouldn't be printed");
122
newtFormAddComponents(f, lb, timeLabel, t, NULL);
124
newtFormSetTimer(f, 200);
129
if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == b2) {
130
newtScaleSet(scale, atoi(scaleVal));
133
} else if (es.reason == NEWT_EXIT_TIMER) {
135
if (!*spinState) spinState = spinner;
136
sprintf(buf, "Spinner: %c", *spinState);
137
newtLabelSetText(timeLabel, buf);
139
} while (es.reason != NEWT_EXIT_COMPONENT);
141
scaleVal = strdup(scaleVal);
145
selectedList = newtListboxGetSelection(lb, &numsel);
153
printf("got string 1: %s\n", scaleVal);
154
printf("got string 2: %s\n", enr2);
155
printf("got string 3: %s\n", enr3);
158
printf("\nSelected listbox items:\n");
159
for(i = 0; i < numsel; i++)
160
puts(selectedList[i]);