First checkin, AXE release 0.2
[AXE.git] / demos / testaxe.cpp
1
2 #include "menu.h"
3 #include "filedialog.h"
4 #include "icon.h"
5 #include "configuration.h"
6
7 #include <stdio.h>
8
9 #define CMD_QUIT     1
10 #define CMD_OPEN     2
11 #define CMD_SAVE     3
12
13 #define CMD_ABOUT    9
14 #define FILE_OPEN    10
15
16 class testaxeconf: public configuration
17 {
18 };
19
20 popup_menu *edit_menu;
21
22 struct cmd_map_entry
23 {
24    int   code;
25    int   (*handler)(void);
26 };
27
28 class aboutbox : public managed_window
29 {
30    icon            *logo;
31    command_button  *ok;
32
33 public:
34
35    aboutbox() : managed_window("About AXE")
36    {
37       Background(Black);
38       logo  = new icon(*this, 10, 40, "andromeda.xpm");
39       ok = new command_button(*this, 300, 50, "OK", 0);
40       Resize(400, 128);
41       SelectInput(ExposureMask, 1);
42    }
43
44    virtual int EV_Expose(XExposeEvent ev)
45    {
46       DrawString(white_gc, 100, 30, "Andromeda X Windows Encapsulation");
47       DrawString(white_gc, 120, 90, "Version 0.2 - July 30, 2001");
48       return 1;
49    }
50
51    int  DoCommand(int code)
52    {
53       Unmap();
54       return 1;
55    }
56 };
57
58 class xapp: public xapplication
59 {
60    managed_window *main_frame;
61    menu_item *save_item;
62    file_dialog *FileDialog;
63    aboutbox    *About;
64
65    testaxeconf    config;
66
67    virtual void SetupResources(void);
68
69    virtual int DoCommand(int code);
70
71 public:
72
73    int OnOpen(void);
74
75    int OnSave(void);
76
77    int OnQuit(void) { printf("OnQuit\n"); return 0; }
78
79 };
80
81 xapp Application;
82
83
84 int xapp::OnOpen(void)
85 {
86    FileDialog->Realize();
87    return 1;
88 }
89
90 int xapp::OnSave(void)
91 {
92    FileDialog->Realize();
93    return 1;
94 }
95
96 /*  The pinguin icon as a static array */
97
98 #include "pinguin.xpm"
99
100 void xapp::SetupResources(void)
101 {
102    window *menu;
103    frame  *fr;
104    scrollbar  *scr;
105    edit *edt;
106    menu_item *item;
107    popup_menu *popup;
108
109    config.read("testaxe");
110
111    About      = new aboutbox;
112    FileDialog = new file_dialog(FILE_OPEN);
113
114    main_frame = new managed_window;
115    main_frame->Command_WhenClosed(CMD_QUIT);
116    main_frame->Background(color(config.find_parameter("colors", "background")));
117
118    fr = new button(*main_frame, 20, 30, "Up");
119
120    fr = new toggle_button(*main_frame, 20, 100, "Down");
121
122    fr = new frame(*main_frame, 180, 30, "Left");
123    fr->TextAlign(Left, Middle);
124
125    fr = new frame(*main_frame, 180, 70, "Center");
126    fr->TextAlign(Center, Middle);
127    fr->Strength(0);
128
129    fr = new frame(*main_frame, 180, 110, "Right");
130    fr->TextAlign(Right, Middle);
131
132    fr = new frame(*main_frame, 180, 150, "Top");
133    fr->TextAlign(Center, Top);
134
135    fr = new frame(*main_frame, 180, 190, "Middle");
136    fr->TextAlign(Center, Middle);
137    fr->Strength(0);
138
139    fr = new frame(*main_frame, 180, 230, "Bottom");
140    fr->TextAlign(Center, Bottom);
141    fr->WindowGravity(SouthEastGravity);
142
143    scr = new scrollbar(*main_frame, 200, 130, 30);
144    scr->SetSizes(1000, 200);
145    scr->Realize();
146
147    edt = new edit(*main_frame, 20, 140, "This is editable text");
148    edt = new edit(*main_frame, 20, 170, "And another text field");
149
150    menu = new menu_bar(*main_frame);
151
152    item = new menu_label(*menu, "Help");
153    popup = new popup_menu;
154    item->Popup(popup);
155    item  = new menu_label(*popup, "About...", CMD_ABOUT);
156    item->Map();
157
158    item = new menu_label(*menu, "View");
159
160    popup = new popup_menu;
161    item->Popup(popup);
162
163    item = new menu_label(*popup, "Status");
164    item->Map();
165
166    item = new menu_label(*popup, "Tools");
167    item->Map();
168
169    item = new menu_label(*menu, "Edit");
170
171    popup = new popup_menu;
172    item->Popup(popup);
173    edit_menu = popup;
174
175    item = new menu_label(*popup, "Paste");
176    item->Map();
177
178    item = new menu_label(*popup, "Copy");
179    item->Map();
180
181    item = new menu_label(*popup, "Cut");
182    item->Map();
183
184    item = new menu_label(*menu, "File");
185
186    popup = new popup_menu;
187    item->Popup(popup);   
188
189    item = new menu_label(*popup, "Quit", CMD_QUIT);
190    item->Map();
191
192    item = new menu_separator(*popup);
193    item->Map();
194
195    save_item = new menu_label(*popup, "Save", CMD_SAVE);
196    save_item->Map();
197    save_item->Enable(0);
198
199    item = new menu_label(*popup, "Open...", CMD_OPEN);
200    item->Map();
201
202    item = new menu_label(*popup, "New ->");
203    item->Map();
204
205    popup = new popup_menu;
206    item->Popup(popup);
207
208    item = new menu_label(*popup, "Type B");
209    item->Map();
210
211    item = new menu_label(*popup, "Type A");
212    item->Map();
213
214    icon *logo;
215    logo = new icon(*main_frame, 10, 200, pinguin_xpm);
216    main_frame->Realize();
217    menu->Realize();
218
219    pixmap   pinguin(pinguin_xpm);
220
221    main_frame->DrawPixmap(text_normal_gc, 270, 100, pinguin);
222 }
223
224 int xapp::DoCommand(int code)
225 {
226    printf("Command : %d\n", code);
227
228    switch (code)
229    {
230    case CMD_QUIT:
231       return 0;
232
233    case CMD_OPEN:
234       OnOpen();
235       return 1;
236
237    case FILE_OPEN:
238       cout << "Opening " << FileDialog->PathName() << "\n";
239       save_item->Enable(1);
240       return 1;
241
242    case CMD_SAVE:
243       OnSave();
244       save_item->Enable(0);
245       return 1;
246
247    case CMD_ABOUT:
248       About->Realize();
249       return 1;
250
251    default:
252       return 1;
253    }
254 }