]>
Commit | Line | Data |
---|---|---|
dab8b9a2 | 1 | #include <stdlib.h> |
2 | #include <stdio.h> | |
3 | #include <string.h> | |
4 | #include <signal.h> | |
5 | ||
dab8b9a2 | 6 | #include "newt.h" |
7 | ||
8 | int main(void) { | |
9 | newtComponent b1, b2, b3, b4; | |
4fb7e108 | 10 | newtComponent f, t; |
676cfb93 | 11 | newtGrid grid, subgrid; |
03b35855 | 12 | char * flowedText; |
fb77be14 | 13 | int textWidth, textHeight, rc, i; |
ce852af9 | 14 | char * menuContents[] = { "One", "Two", "Three", "Four", "Five", NULL }; |
fb77be14 | 15 | char * entries[10]; |
abedc66c | 16 | struct newtWinEntry autoEntries[] = { |
6f481af2 | 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 } }; | |
abedc66c | 22 | |
23 | memset(entries, 0, sizeof(entries)); | |
dab8b9a2 | 24 | |
25 | newtInit(); | |
26 | newtCls(); | |
ce852af9 | 27 | |
c8fa0ee7 | 28 | b1 = newtCheckbox(-1, -1, "An pretty long checkbox for testing", ' ', NULL, NULL); |
dab8b9a2 | 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); | |
13fb760d | 36 | newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0, |
6f481af2 | 37 | NEWT_ANCHOR_RIGHT, 0); |
13fb760d | 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); | |
dab8b9a2 | 41 | |
dab8b9a2 | 42 | |
43 | newtFormAddComponents(f, b1, b2, b3, b4, NULL); | |
44 | ||
c8fa0ee7 | 45 | newtGridWrappedWindow(grid, "first window"); |
d7b43f93 | 46 | newtGridFree(grid, 1); |
f7540d34 | 47 | |
4fb7e108 | 48 | newtRunForm(f); |
6f481af2 | 49 | |
dab8b9a2 | 50 | newtFormDestroy(f); |
dab8b9a2 | 51 | newtPopWindow(); |
676cfb93 | 52 | |
03b35855 | 53 | flowedText = newtReflowText("This is a quite a bit of text. It is 40 " |
6f481af2 | 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); | |
03b35855 | 60 | t = newtTextbox(-1, -1, textWidth, textHeight, NEWT_FLAG_WRAP); |
61 | newtTextboxSetText(t, flowedText); | |
62 | free(flowedText); | |
63 | ||
676cfb93 | 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 | ||
f16e164f | 74 | newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, t, 0, 0, 0, 1, 0, 0); |
676cfb93 | 75 | newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, subgrid, 0, 0, 0, 0, 0, |
6f481af2 | 76 | NEWT_GRID_FLAG_GROWX); |
f16e164f | 77 | newtGridWrappedWindow(grid, "another example"); |
d7b43f93 | 78 | newtGridDestroy(grid, 1); |
676cfb93 | 79 | |
80 | f = newtForm(NULL, NULL, 0); | |
81 | newtFormAddComponents(f, b1, t, b2, NULL); | |
4fb7e108 | 82 | newtRunForm(f); |
676cfb93 | 83 | |
03b35855 | 84 | newtPopWindow(); |
d7b43f93 | 85 | newtFormDestroy(f); |
03b35855 | 86 | |
87 | newtWinMessage("Simple", "Ok", "This is a simple message window"); | |
cccf98b7 | 88 | newtWinChoice("Simple", "Ok", "Cancel", "This is a simple choice window"); |
03b35855 | 89 | |
ce852af9 | 90 | textWidth = 0; |
91 | rc = newtWinMenu("Test Menu", "This is a sample invovation of the " | |
6f481af2 | 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); | |
ce852af9 | 95 | |
abedc66c | 96 | rc = newtWinEntries("Text newtWinEntries()", "This is a sample invovation of " |
6f481af2 | 97 | "newtWinEntries() call. It lets you get a lot of input " |
98 | "quite easily.", 50, 5, 5, 20, autoEntries, "Ok", | |
99 | "Cancel", NULL); | |
fb77be14 ML |
100 | for (i = 0; i < sizeof (autoEntries) / sizeof (struct newtWinEntry) && autoEntries[i].value; i++) |
101 | free(*(autoEntries[i].value)); | |
abedc66c | 102 | |
dab8b9a2 | 103 | newtFinished(); |
abedc66c | 104 | |
ce852af9 | 105 | printf("rc = 0x%x item = %d\n", rc, textWidth); |
dab8b9a2 | 106 | |
107 | return 0; | |
108 | } |