]> git.ipfire.org Git - thirdparty/newt.git/blob - testgrid.c
test newtWinMenu()
[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
16 newtInit();
17 newtCls();
18
19 newtOpenWindow(2, 2, 40, 15, "first window");
20
21 b1 = newtButton(-1, -1, "Button 1");
22 b2 = newtButton(-1, -1, "Another Button");
23 b3 = newtButton(-1, -1, "But, but");
24 b4 = newtButton(-1, -1, "But what?");
25
26 f = newtForm(NULL, NULL, 0);
27
28 grid = newtCreateGrid(2, 2);
29 newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0,
30 NEWT_ANCHOR_RIGHT, 0);
31 newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);
32 newtGridSetField(grid, 1, 0, NEWT_GRID_COMPONENT, b3, 0, 0, 0, 0, 0, 0);
33 newtGridSetField(grid, 1, 1, NEWT_GRID_COMPONENT, b4, 0, 0, 0, 0, 0, 0);
34
35
36 newtFormAddComponents(f, b1, b2, b3, b4, NULL);
37
38 newtGridPlace(grid, 1, 1);
39
40 answer = newtRunForm(f);
41
42 newtFormDestroy(f);
43
44 newtPopWindow();
45
46 flowedText = newtReflowText("This is a quite a bit of text. It is 40 "
47 "columns long, so some wrapping should be "
48 "done. Did you know that the quick, brown "
49 "fox jumped over the lazy dog?\n\n"
50 "In other news, it's pretty important that we "
51 "can properly force a line break.",
52 40, 5, 5, &textWidth, &textHeight);
53 t = newtTextbox(-1, -1, textWidth, textHeight, NEWT_FLAG_WRAP);
54 newtTextboxSetText(t, flowedText);
55 free(flowedText);
56
57
58 b1 = newtButton(-1, -1, "Okay");
59 b2 = newtButton(-1, -1, "Cancel");
60
61 grid = newtCreateGrid(1, 2);
62 subgrid = newtCreateGrid(2, 1);
63
64 newtGridSetField(subgrid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0, 0, 0);
65 newtGridSetField(subgrid, 1, 0, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);
66
67 newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, t, 0, 0, 0, 1, 0, 0);
68 newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, subgrid, 0, 0, 0, 0, 0,
69 NEWT_GRID_FLAG_GROWX);
70 newtGridWrappedWindow(grid, "another example");
71
72 f = newtForm(NULL, NULL, 0);
73 newtFormAddComponents(f, b1, t, b2, NULL);
74 answer = newtRunForm(f);
75
76 newtPopWindow();
77
78 newtWinMessage("Simple", "Ok", "This is a simple message window");
79 newtWinChoice("Simple", "Ok", "Cancel", "This is a simple choice window");
80
81 textWidth = 0;
82 rc = newtWinMenu("Test Menu", "This is a sample invovation of the "
83 "newtWinMenu() call. It may or may not have a scrollbar, "
84 "depending on the need for one.", 50, 5, 5, 3,
85 menuContents, &textWidth, "Ok", "Cancel", NULL);
86
87 newtFinished();
88 printf("rc = 0x%x item = %d\n", rc, textWidth);
89
90 return 0;
91 }