]> git.ipfire.org Git - thirdparty/newt.git/blob - test.c
added listbox test
[thirdparty/newt.git] / test.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4
5 #include "newt.h"
6
7 void main(void) {
8 newtComponent b1, b2, r1, r2, r3, e1, e2, e3, l1, l2, l3;
9 newtComponent lb;
10 newtComponent cs[10];
11 newtComponent f, chklist;
12 char results[10];
13 char * enr1, * enr2, * enr3;
14 int i;
15 char buf[20];
16
17 newtInit();
18 newtCls();
19
20 newtOpenWindow(2, 2, 30, 10, "first window");
21 newtOpenWindow(10, 5, 65, 16, "window 2");
22
23 f = newtForm();
24 chklist = newtForm();
25
26 b1 = newtButton(3, 1, "Push me");
27 b2 = newtButton(18, 1, "Not me");
28 r1 = newtRadiobutton(20, 6, "Choice 1", 0, NULL);
29 r2 = newtRadiobutton(20, 7, "Choice 2", 1, r1);
30 r3 = newtRadiobutton(20, 8, "Choice 3", 0, r2);
31
32 for (i = 0; i < 10; i++) {
33 sprintf(buf, "Check %d", i);
34 cs[i] = newtCheckbox(3, 6 + i, buf, ' ', NULL, &results[i]);
35 newtFormAddComponent(chklist, cs[i]);
36 }
37
38 l1 = newtLabel(3, 10, "Fixed:");
39 l2 = newtLabel(3, 11, "Scrolls:");
40 l3 = newtLabel(3, 12, "Hidden:");
41 e1 = newtEntry(12, 10, "", 20, &enr1, 0);
42 e2 = newtEntry(12, 11, "Default", 20, &enr2, NEWT_ENTRY_SCROLL);
43 e3 = newtEntry(12, 12, NULL, 20, &enr3, NEWT_ENTRY_HIDDEN);
44
45 newtFormSetHeight(chklist, 3);
46
47 newtFormAddComponents(f, b1, b2, chklist, NULL);
48 newtFormAddComponents(f, r1, r2, r3, l1, l2, l3, e1, e2, e3, NULL);
49
50 lb = newtListbox(45, 3, 2, 0);
51 newtListboxAddEntry(lb, "First ");
52 newtListboxAddEntry(lb, "Second");
53 newtListboxAddEntry(lb, "Third ");
54 newtListboxAddEntry(lb, "Fourth");
55
56 newtFormAddComponent(f, lb);
57
58 newtRunForm(f);
59
60 enr1 = strdup(enr1);
61 enr2 = strdup(enr2);
62 enr3 = strdup(enr3);
63
64 newtFormDestroy(f);
65
66 newtPopWindow();
67 newtPopWindow();
68 newtFinished();
69
70 printf("got string 1: %s\n", enr1);
71 printf("got string 2: %s\n", enr2);
72 printf("got string 3: %s\n", enr3);
73 }