]> git.ipfire.org Git - thirdparty/newt.git/blob - testgrid.c
- cleaned up const qualifiers in interfaces
[thirdparty/newt.git] / testgrid.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <signal.h>
5
6 #include "newt.h"
7
8 int main(void) {
9 newtComponent b1, b2, b3, b4;
10 newtComponent answer, f, t;
11 newtGrid grid, subgrid;
12 char * flowedText;
13 int textWidth, textHeight, rc;
14 char * menuContents[] = { "One", "Two", "Three", "Four", "Five", NULL };
15 const char * entries[10];
16 struct newtWinEntry autoEntries[] = {
17 { "An entry", entries + 0, 0 },
18 { "Another entry", entries + 1, 0 },
19 { "Third entry", entries + 2, 0 },
20 { "Fourth entry", entries + 3, 0 },
21 { NULL, NULL, 0 } };
22
23 memset(entries, 0, sizeof(entries));
24
25 newtInit();
26 newtCls();
27
28 b1 = newtCheckbox(-1, -1, "An pretty long checkbox for testing", ' ', NULL, NULL);
29 b2 = newtButton(-1, -1, "Another Button");
30 b3 = newtButton(-1, -1, "But, but");
31 b4 = newtButton(-1, -1, "But what?");
32
33 f = newtForm(NULL, NULL, 0);
34
35 grid = newtCreateGrid(2, 2);
36 newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0,
37 NEWT_ANCHOR_RIGHT, 0);
38 newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);
39 newtGridSetField(grid, 1, 0, NEWT_GRID_COMPONENT, b3, 0, 0, 0, 0, 0, 0);
40 newtGridSetField(grid, 1, 1, NEWT_GRID_COMPONENT, b4, 0, 0, 0, 0, 0, 0);
41
42
43 newtFormAddComponents(f, b1, b2, b3, b4, NULL);
44
45 newtGridWrappedWindow(grid, "first window");
46 newtGridFree(grid, 1);
47
48 answer = newtRunForm(f);
49
50 newtFormDestroy(f);
51 newtPopWindow();
52
53 flowedText = newtReflowText("This is a quite a bit of text. It is 40 "
54 "columns long, so some wrapping should be "
55 "done. Did you know that the quick, brown "
56 "fox jumped over the lazy dog?\n\n"
57 "In other news, it's pretty important that we "
58 "can properly force a line break.",
59 40, 5, 5, &textWidth, &textHeight);
60 t = newtTextbox(-1, -1, textWidth, textHeight, NEWT_FLAG_WRAP);
61 newtTextboxSetText(t, flowedText);
62 free(flowedText);
63
64
65 b1 = newtButton(-1, -1, "Okay");
66 b2 = newtButton(-1, -1, "Cancel");
67
68 grid = newtCreateGrid(1, 2);
69 subgrid = newtCreateGrid(2, 1);
70
71 newtGridSetField(subgrid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0, 0, 0);
72 newtGridSetField(subgrid, 1, 0, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);
73
74 newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, t, 0, 0, 0, 1, 0, 0);
75 newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, subgrid, 0, 0, 0, 0, 0,
76 NEWT_GRID_FLAG_GROWX);
77 newtGridWrappedWindow(grid, "another example");
78 newtGridDestroy(grid, 1);
79
80 f = newtForm(NULL, NULL, 0);
81 newtFormAddComponents(f, b1, t, b2, NULL);
82 answer = newtRunForm(f);
83
84 newtPopWindow();
85 newtFormDestroy(f);
86
87 newtWinMessage("Simple", "Ok", "This is a simple message window");
88 newtWinChoice("Simple", "Ok", "Cancel", "This is a simple choice window");
89
90 textWidth = 0;
91 rc = newtWinMenu("Test Menu", "This is a sample invovation of the "
92 "newtWinMenu() call. It may or may not have a scrollbar, "
93 "depending on the need for one.", 50, 5, 5, 3,
94 menuContents, &textWidth, "Ok", "Cancel", NULL);
95
96 rc = newtWinEntries("Text newtWinEntries()", "This is a sample invovation of "
97 "newtWinEntries() call. It lets you get a lot of input "
98 "quite easily.", 50, 5, 5, 20, autoEntries, "Ok",
99 "Cancel", NULL);
100
101 newtFinished();
102
103 printf("rc = 0x%x item = %d\n", rc, textWidth);
104
105 return 0;
106 }