]>
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 == ' ') { | |
4a93351d | 17 | newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET); |
35775d32 | 18 | } else { |
4a93351d | 19 | newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET); |
35775d32 | 20 | } |
21 | ||
22 | newtRefresh(); | |
23 | } | |
24 | ||
b7c1b763 | 25 | void suspend(void) { |
26 | newtSuspend(); | |
27 | raise(SIGTSTP); | |
28 | newtResume(); | |
29 | } | |
30 | ||
6fb96a3f | 31 | void main(void) { |
3cf3e1b9 | 32 | newtComponent b1, b2, r1, r2, r3, e2, e3, l1, l2, l3, scale; |
33 | newtComponent lb, t, rsf, answer; | |
bb95cd1a | 34 | newtComponent cs[10]; |
3cf3e1b9 | 35 | newtComponent f, chklist, e1; |
35775d32 | 36 | struct callbackInfo cbis[3]; |
bb95cd1a | 37 | char results[10]; |
3cf3e1b9 | 38 | char * enr2, * enr3, * scaleVal; |
bb95cd1a | 39 | int i; |
40 | char buf[20]; | |
6fb96a3f | 41 | |
42 | newtInit(); | |
43 | newtCls(); | |
44 | ||
b7c1b763 | 45 | newtSetSuspendCallback(suspend); |
46 | ||
731ec2ae | 47 | newtDrawRootText(0, 0, "Newt test program"); |
59eb16cb | 48 | newtPushHelpLine(NULL); |
731ec2ae | 49 | |
cb12dfdb | 50 | newtOpenWindow(2, 2, 30, 10, "first window"); |
51 | newtOpenWindow(10, 5, 65, 16, "window 2"); | |
6fb96a3f | 52 | |
3db08b60 | 53 | f = newtForm(NULL, NULL, 0); |
54 | chklist = newtForm(NULL, NULL, 0); | |
6fb96a3f | 55 | |
3cf3e1b9 | 56 | b1 = newtButton(3, 1, "Exit"); |
57 | b2 = newtButton(18, 1, "Update"); | |
58 | r1 = newtRadiobutton(20, 10, "Choice 1", 0, NULL); | |
59 | r2 = newtRadiobutton(20, 11, "Chc 2", 1, r1); | |
60 | r3 = newtRadiobutton(20, 12, "Choice 3", 0, r2); | |
9e6f00ba | 61 | rsf = newtForm(NULL, NULL, 0); |
62 | newtFormAddComponents(rsf, r1, r2, r3, NULL); | |
731ec2ae | 63 | newtFormSetBackground(rsf, NEWT_COLORSET_CHECKBOX); |
6fb96a3f | 64 | |
bb95cd1a | 65 | for (i = 0; i < 10; i++) { |
66 | sprintf(buf, "Check %d", i); | |
3cf3e1b9 | 67 | cs[i] = newtCheckbox(3, 10 + i, buf, ' ', NULL, &results[i]); |
bb95cd1a | 68 | newtFormAddComponent(chklist, cs[i]); |
69 | } | |
6fb96a3f | 70 | |
3cf3e1b9 | 71 | l1 = newtLabel(3, 6, "Scale:"); |
72 | l2 = newtLabel(3, 7, "Scrolls:"); | |
73 | l3 = newtLabel(3, 8, "Hidden:"); | |
74 | e1 = newtEntry(12, 6, "", 20, &scaleVal, 0); | |
4a93351d | 75 | e2 = newtEntry(12, 7, "Default", 20, &enr2, NEWT_FLAG_SCROLL); |
76 | e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_HIDDEN); | |
3cf3e1b9 | 77 | |
35775d32 | 78 | cbis[0].state = &results[0]; |
79 | cbis[0].en = e1; | |
80 | newtComponentAddCallback(cs[0], disableCallback, &cbis[0]); | |
81 | ||
3cf3e1b9 | 82 | scale = newtScale(3, 14, 32, 100); |
bb95cd1a | 83 | |
cb12dfdb | 84 | newtFormSetHeight(chklist, 3); |
c4827b34 | 85 | |
3cf3e1b9 | 86 | newtFormAddComponents(f, b1, b2, l1, l2, l3, e1, e2, e3, chklist, NULL); |
87 | newtFormAddComponents(f, rsf, scale, NULL); | |
6fb96a3f | 88 | |
de3571d9 | 89 | lb = newtListbox(45, 3, 4, 0); |
80456bd4 | 90 | newtListboxAddEntry(lb, "First", NULL); |
91 | newtListboxAddEntry(lb, "Second", NULL); | |
92 | newtListboxAddEntry(lb, "Third", NULL); | |
93 | newtListboxAddEntry(lb, "Fourth", NULL); | |
94 | newtListboxAddEntry(lb, "Fifth", NULL); | |
95 | newtListboxAddEntry(lb, "Sixth", NULL); | |
96 | newtListboxAddEntry(lb, "Seventh", NULL); | |
97 | newtListboxAddEntry(lb, "Eighth", NULL); | |
98 | newtListboxAddEntry(lb, "Ninth", NULL); | |
99 | newtListboxAddEntry(lb, "Tenth", NULL); | |
cb12dfdb | 100 | |
4a93351d | 101 | t = newtTextbox(45, 10, 17, 5, NEWT_FLAG_WRAP); |
a40a9a8b | 102 | newtTextboxSetText(t, "This is some text does it look okay?\nThis should be alone.\nThis shouldn't be printed"); |
103 | ||
104 | newtFormAddComponents(f, lb, t, NULL); | |
cb12dfdb | 105 | |
3cf3e1b9 | 106 | do { |
107 | answer = newtRunForm(f); | |
108 | ||
109 | if (answer == b2) { | |
110 | newtScaleSet(scale, atoi(scaleVal)); | |
111 | newtRefresh(); | |
112 | answer = NULL; | |
113 | } | |
114 | } while (!answer); | |
6fb96a3f | 115 | |
3cf3e1b9 | 116 | scaleVal = strdup(scaleVal); |
6fb96a3f | 117 | enr2 = strdup(enr2); |
118 | enr3 = strdup(enr3); | |
119 | ||
c4827b34 | 120 | newtFormDestroy(f); |
6fb96a3f | 121 | |
122 | newtPopWindow(); | |
123 | newtPopWindow(); | |
124 | newtFinished(); | |
125 | ||
3cf3e1b9 | 126 | printf("got string 1: %s\n", scaleVal); |
6fb96a3f | 127 | printf("got string 2: %s\n", enr2); |
128 | printf("got string 3: %s\n", enr3); | |
129 | } |