~ubuntu-branches/ubuntu/dapper/newt/dapper-updates

« back to all changes in this revision

Viewing changes to testgrid.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2005-03-22 12:44:37 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050322124437-nuhl0pqjcijjno9z
Tags: 0.51.6-20ubuntu3
Add Xhosa translation (thanks, Adi Attar).

Show diffs side-by-side

added added

removed removed

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