-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtestgrid.c
108 lines (82 loc) · 3.46 KB
/
testgrid.c
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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include "newt.h"
int main(void) {
newtComponent b1, b2, b3, b4;
newtComponent f, t;
newtGrid grid, subgrid;
char * flowedText;
int textWidth, textHeight, rc, i;
char * menuContents[] = { "One", "Two", "Three", "Four", "Five", NULL };
char * entries[10];
struct newtWinEntry autoEntries[] = {
{ "An entry", entries + 0, 0 },
{ "Another entry", entries + 1, 0 },
{ "Third entry", entries + 2, 0 },
{ "Fourth entry", entries + 3, 0 },
{ NULL, NULL, 0 } };
memset(entries, 0, sizeof(entries));
newtInit();
newtCls();
b1 = newtCheckbox(-1, -1, "An pretty long checkbox for testing", ' ', NULL, NULL);
b2 = newtButton(-1, -1, "Another Button");
b3 = newtButton(-1, -1, "But, but");
b4 = newtButton(-1, -1, "But what?");
f = newtForm(NULL, NULL, 0);
grid = newtCreateGrid(2, 2);
newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0,
NEWT_ANCHOR_RIGHT, 0);
newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);
newtGridSetField(grid, 1, 0, NEWT_GRID_COMPONENT, b3, 0, 0, 0, 0, 0, 0);
newtGridSetField(grid, 1, 1, NEWT_GRID_COMPONENT, b4, 0, 0, 0, 0, 0, 0);
newtFormAddComponents(f, b1, b2, b3, b4, NULL);
newtGridWrappedWindow(grid, "first window");
newtGridFree(grid, 1);
newtRunForm(f);
newtFormDestroy(f);
newtPopWindow();
flowedText = newtReflowText("This is a quite a bit of text. It is 40 "
"columns long, so some wrapping should be "
"done. Did you know that the quick, brown "
"fox jumped over the lazy dog?\n\n"
"In other news, it's pretty important that we "
"can properly force a line break.",
40, 5, 5, &textWidth, &textHeight);
t = newtTextbox(-1, -1, textWidth, textHeight, NEWT_FLAG_WRAP);
newtTextboxSetText(t, flowedText);
free(flowedText);
b1 = newtButton(-1, -1, "Okay");
b2 = newtButton(-1, -1, "Cancel");
grid = newtCreateGrid(1, 2);
subgrid = newtCreateGrid(2, 1);
newtGridSetField(subgrid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0, 0, 0);
newtGridSetField(subgrid, 1, 0, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);
newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, t, 0, 0, 0, 1, 0, 0);
newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, subgrid, 0, 0, 0, 0, 0,
NEWT_GRID_FLAG_GROWX);
newtGridWrappedWindow(grid, "another example");
newtGridDestroy(grid, 1);
f = newtForm(NULL, NULL, 0);
newtFormAddComponents(f, b1, t, b2, NULL);
newtRunForm(f);
newtPopWindow();
newtFormDestroy(f);
newtWinMessage("Simple", "Ok", "This is a simple message window");
newtWinChoice("Simple", "Ok", "Cancel", "This is a simple choice window");
textWidth = 0;
rc = newtWinMenu("Test Menu", "This is a sample invovation of the "
"newtWinMenu() call. It may or may not have a scrollbar, "
"depending on the need for one.", 50, 5, 5, 3,
menuContents, &textWidth, "Ok", "Cancel", NULL);
rc = newtWinEntries("Text newtWinEntries()", "This is a sample invovation of "
"newtWinEntries() call. It lets you get a lot of input "
"quite easily.", 50, 5, 5, 20, autoEntries, "Ok",
"Cancel", NULL);
for (i = 0; i < sizeof (autoEntries) / sizeof (struct newtWinEntry) && autoEntries[i].value; i++)
free(*(autoEntries[i].value));
newtFinished();
printf("rc = 0x%x item = %d\n", rc, textWidth);
return 0;
}