~ubuntu-branches/ubuntu/lucid/newt/lucid

« back to all changes in this revision

Viewing changes to test.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2005-03-22 12:44:37 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050322124437-nuhl0pqjcijjno9z
Tags: 0.51.6-20ubuntu3
Add Xhosa translation (thanks, Adi Attar).

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