]>
Commit | Line | Data |
---|---|---|
6fb96a3f | 1 | #include <stdlib.h> |
2 | #include <stdio.h> | |
3 | #include <string.h> | |
b7c1b763 | 4 | #include <signal.h> |
6fb96a3f | 5 | |
6 | #include "newt.h" | |
7 | ||
35775d32 | 8 | struct callbackInfo { |
9 | newtComponent en; | |
10 | char * state; | |
11 | }; | |
12 | ||
13 | void disableCallback(newtComponent co, void * data) { | |
14 | struct callbackInfo * cbi = data; | |
15 | ||
16 | if (*cbi->state == ' ') { | |
6f481af2 | 17 | newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET); |
35775d32 | 18 | } else { |
6f481af2 | 19 | newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET); |
35775d32 | 20 | } |
21 | ||
22 | newtRefresh(); | |
23 | } | |
24 | ||
06cf519e | 25 | void suspend(void * d) { |
b7c1b763 | 26 | newtSuspend(); |
27 | raise(SIGTSTP); | |
28 | newtResume(); | |
29 | } | |
30 | ||
72b71fa6 | 31 | void helpCallback(newtComponent co, void * tag) { |
32 | newtWinMessage("Help", "Ok", tag); | |
33 | } | |
34 | ||
a880525e | 35 | int main(void) { |
3cf3e1b9 | 36 | newtComponent b1, b2, r1, r2, r3, e2, e3, l1, l2, l3, scale; |
4fb7e108 | 37 | newtComponent lb, t, rsf, timeLabel; |
bb95cd1a | 38 | newtComponent cs[10]; |
3cf3e1b9 | 39 | newtComponent f, chklist, e1; |
35775d32 | 40 | struct callbackInfo cbis[3]; |
bb95cd1a | 41 | char results[10]; |
d78245ab | 42 | const char * enr2, * enr3, *scaleVal; |
46263d9e | 43 | void ** selectedList; |
cb586ef6 | 44 | int i, numsel; |
bb95cd1a | 45 | char buf[20]; |
66793a00 | 46 | const char * spinner = "-\\|/"; |
e67a6cab | 47 | const char * spinState; |
48 | struct newtExitStruct es; | |
6fb96a3f | 49 | |
50 | newtInit(); | |
51 | newtCls(); | |
52 | ||
06cf519e | 53 | newtSetSuspendCallback(suspend, NULL); |
72b71fa6 | 54 | newtSetHelpCallback(helpCallback); |
b7c1b763 | 55 | |
731ec2ae | 56 | newtDrawRootText(0, 0, "Newt test program"); |
59eb16cb | 57 | newtPushHelpLine(NULL); |
10465599 | 58 | newtDrawRootText(-50, 0, "More root text"); |
731ec2ae | 59 | |
cb12dfdb | 60 | newtOpenWindow(2, 2, 30, 10, "first window"); |
61 | newtOpenWindow(10, 5, 65, 16, "window 2"); | |
6fb96a3f | 62 | |
72b71fa6 | 63 | f = newtForm(NULL, "This is some help text", 0); |
3db08b60 | 64 | chklist = newtForm(NULL, NULL, 0); |
6fb96a3f | 65 | |
3cf3e1b9 | 66 | b1 = newtButton(3, 1, "Exit"); |
67 | b2 = newtButton(18, 1, "Update"); | |
68 | r1 = newtRadiobutton(20, 10, "Choice 1", 0, NULL); | |
d78245ab | 69 | r2 = newtRadiobutton(20, 11, "Choice 2", 1, r1); |
3cf3e1b9 | 70 | r3 = newtRadiobutton(20, 12, "Choice 3", 0, r2); |
9e6f00ba | 71 | rsf = newtForm(NULL, NULL, 0); |
72 | newtFormAddComponents(rsf, r1, r2, r3, NULL); | |
731ec2ae | 73 | newtFormSetBackground(rsf, NEWT_COLORSET_CHECKBOX); |
6fb96a3f | 74 | |
bb95cd1a | 75 | for (i = 0; i < 10; i++) { |
6f481af2 | 76 | sprintf(buf, "Check %d", i); |
77 | cs[i] = newtCheckbox(3, 10 + i, buf, ' ', NULL, &results[i]); | |
78 | newtFormAddComponent(chklist, cs[i]); | |
bb95cd1a | 79 | } |
6fb96a3f | 80 | |
3cf3e1b9 | 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); | |
4a93351d | 85 | e2 = newtEntry(12, 7, "Default", 20, &enr2, NEWT_FLAG_SCROLL); |
20fb366a | 86 | /* e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_HIDDEN); */ |
87 | e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_PASSWORD); | |
3cf3e1b9 | 88 | |
35775d32 | 89 | cbis[0].state = &results[0]; |
90 | cbis[0].en = e1; | |
91 | newtComponentAddCallback(cs[0], disableCallback, &cbis[0]); | |
92 | ||
3cf3e1b9 | 93 | scale = newtScale(3, 14, 32, 100); |
bb95cd1a | 94 | |
cb12dfdb | 95 | newtFormSetHeight(chklist, 3); |
c4827b34 | 96 | |
3cf3e1b9 | 97 | newtFormAddComponents(f, b1, b2, l1, l2, l3, e1, e2, e3, chklist, NULL); |
98 | newtFormAddComponents(f, rsf, scale, NULL); | |
6fb96a3f | 99 | |
45f6c4fd | 100 | lb = newtListbox(45, 1, 6, NEWT_FLAG_MULTIPLE | NEWT_FLAG_BORDER | |
6f481af2 | 101 | NEWT_FLAG_SCROLL | NEWT_FLAG_SHOWCURSOR); |
10465599 | 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); | |
a507b3ec | 111 | |
112 | newtListboxInsertEntry(lb, "Fifth", (void *) 5, (void *) 4); | |
113 | newtListboxInsertEntry(lb, "Eleventh", (void *) 11, (void *) 10); | |
114 | newtListboxDeleteEntry(lb, (void *) 11); | |
cb12dfdb | 115 | |
e67a6cab | 116 | spinState = spinner; |
117 | timeLabel = newtLabel(45, 8, "Spinner: -"); | |
118 | ||
4a93351d | 119 | t = newtTextbox(45, 10, 17, 5, NEWT_FLAG_WRAP); |
a40a9a8b | 120 | newtTextboxSetText(t, "This is some text does it look okay?\nThis should be alone.\nThis shouldn't be printed"); |
121 | ||
e67a6cab | 122 | newtFormAddComponents(f, lb, timeLabel, t, NULL); |
31cbf978 | 123 | newtRefresh(); |
e67a6cab | 124 | newtFormSetTimer(f, 200); |
cb12dfdb | 125 | |
3cf3e1b9 | 126 | do { |
6f481af2 | 127 | newtFormRun(f, &es); |
128 | ||
129 | if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == b2) { | |
130 | newtScaleSet(scale, atoi(scaleVal)); | |
131 | newtRefresh(); | |
6f481af2 | 132 | } else if (es.reason == NEWT_EXIT_TIMER) { |
133 | spinState++; | |
134 | if (!*spinState) spinState = spinner; | |
135 | sprintf(buf, "Spinner: %c", *spinState); | |
136 | newtLabelSetText(timeLabel, buf); | |
137 | } | |
587b86aa | 138 | } while (es.reason != NEWT_EXIT_COMPONENT || es.u.co == b2); |
45f6c4fd | 139 | |
fb77be14 | 140 | numsel = 0; |
cb586ef6 | 141 | selectedList = newtListboxGetSelection(lb, &numsel); |
46263d9e | 142 | |
6fb96a3f | 143 | newtPopWindow(); |
144 | newtPopWindow(); | |
145 | newtFinished(); | |
146 | ||
3cf3e1b9 | 147 | printf("got string 1: %s\n", scaleVal); |
6fb96a3f | 148 | printf("got string 2: %s\n", enr2); |
149 | printf("got string 3: %s\n", enr3); | |
46263d9e | 150 | |
fb77be14 ML |
151 | newtFormDestroy(f); |
152 | ||
16e8af2f | 153 | printf("\nSelected listbox items (%d):\n", numsel); |
46263d9e | 154 | if(selectedList) { |
6f481af2 | 155 | for(i = 0; i < numsel; i++) |
8bec7d99 | 156 | printf("#%d\n", (int)(long) selectedList[i]); |
46263d9e | 157 | } |
fb77be14 | 158 | free(selectedList); |
a880525e | 159 | |
160 | return 0; | |
6fb96a3f | 161 | } |