1bcefe442db65c27bb3c748d71e4059038d2d5fc
[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 25, 2002");
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
117    String bgcolor = config.find_parameter("colors", "background");
118    if (bgcolor != "")
119    {
120       main_frame->Background(color(bgcolor));
121    }
122
123    fr = new button(*main_frame, 20, 30, "Up");
124
125    fr = new toggle_button(*main_frame, 20, 100, "Down");
126
127    fr = new frame(*main_frame, 180, 30, "Left");
128    fr->TextAlign(Left, Middle);
129
130    fr = new frame(*main_frame, 180, 70, "Center");
131    fr->TextAlign(Center, Middle);
132    fr->Strength(0);
133
134    fr = new frame(*main_frame, 180, 110, "Right");
135    fr->TextAlign(Right, Middle);
136
137    fr = new frame(*main_frame, 180, 150, "Top");
138    fr->TextAlign(Center, Top);
139
140    fr = new frame(*main_frame, 180, 190, "Middle");
141    fr->TextAlign(Center, Middle);
142    fr->Strength(0);
143
144    fr = new frame(*main_frame, 180, 230, "Bottom");
145    fr->TextAlign(Center, Bottom);
146    fr->WindowGravity(SouthEastGravity);
147
148    scr = new scrollbar(*main_frame, 200, 130, 30);
149    scr->SetSizes(1000, 200);
150    scr->Realize();
151
152    edt = new edit(*main_frame, 20, 140, "This is editable text");
153    edt = new edit(*main_frame, 20, 170, "And another text field");
154
155    menu = new menu_bar(*main_frame);
156
157    item = new menu_label(*menu, "Help");
158    popup = new popup_menu;
159    item->Popup(popup);
160    item  = new menu_label(*popup, "About...", CMD_ABOUT);
161    item->Map();
162
163    item = new menu_label(*menu, "View");
164
165    popup = new popup_menu;
166    item->Popup(popup);
167
168    item = new menu_label(*popup, "Status");
169    item->Map();
170
171    item = new menu_label(*popup, "Tools");
172    item->Map();
173
174    item = new menu_label(*menu, "Edit");
175
176    popup = new popup_menu;
177    item->Popup(popup);
178    edit_menu = popup;
179
180    item = new menu_label(*popup, "Paste");
181    item->Map();
182
183    item = new menu_label(*popup, "Copy");
184    item->Map();
185
186    item = new menu_label(*popup, "Cut");
187    item->Map();
188
189    item = new menu_label(*menu, "File");
190
191    popup = new popup_menu;
192    item->Popup(popup);   
193
194    item = new menu_label(*popup, "Quit", CMD_QUIT);
195    item->Map();
196
197    item = new menu_separator(*popup);
198    item->Map();
199
200    save_item = new menu_label(*popup, "Save", CMD_SAVE);
201    save_item->Map();
202    save_item->Enable(0);
203
204    item = new menu_label(*popup, "Open...", CMD_OPEN);
205    item->Map();
206
207    item = new menu_label(*popup, "New ->");
208    item->Map();
209
210    popup = new popup_menu;
211    item->Popup(popup);
212
213    item = new menu_label(*popup, "Type B");
214    item->Map();
215
216    item = new menu_label(*popup, "Type A");
217    item->Map();
218
219    icon *logo;
220    logo = new icon(*main_frame, 10, 200, pinguin_xpm);
221    main_frame->Realize();
222    menu->Realize();
223
224    pixmap   pinguin(pinguin_xpm);
225
226    main_frame->DrawPixmap(text_normal_gc, 270, 100, pinguin);
227 }
228
229 int xapp::DoCommand(int code)
230 {
231    printf("Command : %d\n", code);
232
233    switch (code)
234    {
235    case CMD_QUIT:
236       return 0;
237
238    case CMD_OPEN:
239       OnOpen();
240       return 1;
241
242    case FILE_OPEN:
243       cout << "Opening " << FileDialog->PathName() << "\n";
244       save_item->Enable(1);
245       return 1;
246
247    case CMD_SAVE:
248       OnSave();
249       save_item->Enable(0);
250       return 1;
251
252    case CMD_ABOUT:
253       About->Realize();
254       return 1;
255
256    default:
257       return 1;
258    }
259 }