~ubuntu-branches/ubuntu/edgy/newt/edgy

« back to all changes in this revision

Viewing changes to test.c

  • Committer: Bazaar Package Importer
  • Author(s): Junichi Uekawa
  • Date: 2002-03-31 09:38:18 UTC
  • Revision ID: james.westby@ubuntu.com-20020331093818-t3cla7103r07qnyw
Tags: upstream-0.50.17
ImportĀ upstreamĀ versionĀ 0.50.17

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdlib.h>
 
2
#include <stdio.h>
 
3
#include <string.h>
 
4
#include <signal.h>
 
5
 
 
6
#include "newt.h"
 
7
 
 
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 == ' ') {
 
17
        newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
 
18
    } else {
 
19
        newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
 
20
    }
 
21
 
 
22
    newtRefresh();
 
23
}
 
24
 
 
25
void suspend(void * d) {
 
26
    newtSuspend();
 
27
    raise(SIGTSTP);
 
28
    newtResume();
 
29
}
 
30
 
 
31
void helpCallback(newtComponent co, void * tag) {
 
32
    newtWinMessage("Help", "Ok", tag);
 
33
}
 
34
 
 
35
int main(void) {
 
36
    newtComponent b1, b2, r1, r2, r3, e2, e3, l1, l2, l3, scale;
 
37
    newtComponent lb, t, rsf, answer, timeLabel;
 
38
    newtComponent cs[10];
 
39
    newtComponent f, chklist, e1;
 
40
    struct callbackInfo cbis[3];
 
41
    char results[10];
 
42
    char * enr2, * enr3, * scaleVal;
 
43
    void ** selectedList;
 
44
    int i, numsel;
 
45
    char buf[20];
 
46
    const char * spinner = "-\\|/\\|/";
 
47
    const char * spinState;
 
48
    struct newtExitStruct es;
 
49
 
 
50
    newtInit();
 
51
    newtCls();
 
52
 
 
53
    newtSetSuspendCallback(suspend, NULL);
 
54
    newtSetHelpCallback(helpCallback);
 
55
 
 
56
    newtDrawRootText(0, 0, "Newt test program");
 
57
    newtPushHelpLine(NULL);
 
58
    newtDrawRootText(-50, 0, "More root text");
 
59
 
 
60
    newtOpenWindow(2, 2, 30, 10, "first window");
 
61
    newtOpenWindow(10, 5, 65, 16, "window 2");
 
62
 
 
63
    f = newtForm(NULL, "This is some help text", 0);
 
64
    chklist = newtForm(NULL, NULL, 0);
 
65
 
 
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);
 
74
 
 
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]);
 
79
    }
 
80
 
 
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);
 
88
 
 
89
    cbis[0].state = &results[0];
 
90
    cbis[0].en = e1;
 
91
    newtComponentAddCallback(cs[0], disableCallback, &cbis[0]);
 
92
 
 
93
    scale = newtScale(3, 14, 32, 100);
 
94
 
 
95
    newtFormSetHeight(chklist, 3);
 
96
 
 
97
    newtFormAddComponents(f, b1, b2, l1, l2, l3, e1, e2, e3, chklist, NULL);
 
98
    newtFormAddComponents(f, rsf, scale, NULL);
 
99
 
 
100
    lb = newtListbox(45, 1, 6, NEWT_FLAG_MULTIPLE | NEWT_FLAG_BORDER |
 
101
                                NEWT_FLAG_SCROLL);
 
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);
 
111
 
 
112
    newtListboxInsertEntry(lb, "Fifth", (void *) 5, (void *) 4);
 
113
    newtListboxInsertEntry(lb, "Eleventh", (void *) 11, (void *) 10);
 
114
    newtListboxDeleteEntry(lb, (void *) 11);
 
115
 
 
116
    spinState = spinner;
 
117
    timeLabel = newtLabel(45, 8, "Spinner: -");
 
118
 
 
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");
 
121
 
 
122
    newtFormAddComponents(f, lb, timeLabel, t, NULL);
 
123
    newtRefresh();
 
124
    newtFormSetTimer(f, 200);
 
125
 
 
126
    do {
 
127
        newtFormRun(f, &es);
 
128
 
 
129
        if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == b2) {
 
130
            newtScaleSet(scale, atoi(scaleVal));
 
131
            newtRefresh();
 
132
            answer = NULL;
 
133
        } else if (es.reason == NEWT_EXIT_TIMER) {
 
134
            spinState++;
 
135
            if (!*spinState) spinState = spinner;
 
136
            sprintf(buf, "Spinner: %c", *spinState);
 
137
            newtLabelSetText(timeLabel, buf);
 
138
        }
 
139
    } while (es.reason != NEWT_EXIT_COMPONENT);
 
140
 
 
141
    scaleVal = strdup(scaleVal);
 
142
    enr2 = strdup(enr2);
 
143
    enr3 = strdup(enr3);
 
144
 
 
145
    selectedList = newtListboxGetSelection(lb, &numsel);
 
146
 
 
147
    newtFormDestroy(f);
 
148
 
 
149
    newtPopWindow();
 
150
    newtPopWindow();
 
151
    newtFinished();
 
152
 
 
153
    printf("got string 1: %s\n", scaleVal);
 
154
    printf("got string 2: %s\n", enr2);
 
155
    printf("got string 3: %s\n", enr3);
 
156
 
 
157
    if(selectedList) {
 
158
        printf("\nSelected listbox items:\n");
 
159
        for(i = 0; i < numsel; i++)
 
160
            puts(selectedList[i]);
 
161
    }
 
162
 
 
163
    return 0;
 
164
}