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