Mercurial > dwindows
comparison dwtestoo.cpp @ 2914:8af64b6d75a9
C++: Start rewriting dwtest in C++ as dwtestoo.
Only the lambda version currently, so will break on old compilers.
Only the main window and first page is implemented so far but...
the first page works on MacOS at least.
Fill in some missing pieces I ran into while porting dwtest to C++.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 28 Dec 2022 01:00:12 +0000 |
parents | 5a6bf6bd3001 |
children | 0cde119fc945 |
comparison
equal
deleted
inserted
replaced
2913:6981feb6210b | 2914:8af64b6d75a9 |
---|---|
1 /* | 1 /* |
2 * Simple C++ Dynamic Windows Example | 2 * Simple C++ Dynamic Windows Example |
3 */ | 3 */ |
4 #include "dw.hpp" | 4 #include "dw.hpp" |
5 | 5 |
6 class MyWindow : public DW::Window | 6 /* Select a fixed width font for our platform */ |
7 #ifdef __OS2__ | |
8 #define FIXEDFONT "5.System VIO" | |
9 #define PLATFORMFOLDER "os2\\" | |
10 #elif defined(__WIN32__) | |
11 #define FIXEDFONT "10.Lucida Console" | |
12 #define PLATFORMFOLDER "win\\" | |
13 #elif defined(__MAC__) | |
14 #define FIXEDFONT "9.Monaco" | |
15 #define PLATFORMFOLDER "mac/" | |
16 #elif defined(__IOS__) | |
17 #define FIXEDFONT "9.Monaco" | |
18 #elif defined(__ANDROID__) | |
19 #define FIXEDFONT "10.Monospace" | |
20 #elif GTK_MAJOR_VERSION > 1 | |
21 #define FIXEDFONT "10.monospace" | |
22 #define PLATFORMFOLDER "gtk/" | |
23 #else | |
24 #define FIXEDFONT "fixed" | |
25 #endif | |
26 | |
27 #define SHAPES_DOUBLE_BUFFERED 0 | |
28 #define SHAPES_DIRECT 1 | |
29 #define DRAW_FILE 2 | |
30 | |
31 class DWTest : public DW::Window | |
7 { | 32 { |
33 private: | |
34 const char *ResolveKeyName(int vk) { | |
35 const char *keyname; | |
36 switch(vk) { | |
37 case VK_LBUTTON : keyname = "VK_LBUTTON"; break; | |
38 case VK_RBUTTON : keyname = "VK_RBUTTON"; break; | |
39 case VK_CANCEL : keyname = "VK_CANCEL"; break; | |
40 case VK_MBUTTON : keyname = "VK_MBUTTON"; break; | |
41 case VK_TAB : keyname = "VK_TAB"; break; | |
42 case VK_CLEAR : keyname = "VK_CLEAR"; break; | |
43 case VK_RETURN : keyname = "VK_RETURN"; break; | |
44 case VK_PAUSE : keyname = "VK_PAUSE"; break; | |
45 case VK_CAPITAL : keyname = "VK_CAPITAL"; break; | |
46 case VK_ESCAPE : keyname = "VK_ESCAPE"; break; | |
47 case VK_SPACE : keyname = "VK_SPACE"; break; | |
48 case VK_PRIOR : keyname = "VK_PRIOR"; break; | |
49 case VK_NEXT : keyname = "VK_NEXT"; break; | |
50 case VK_END : keyname = "VK_END"; break; | |
51 case VK_HOME : keyname = "VK_HOME"; break; | |
52 case VK_LEFT : keyname = "VK_LEFT"; break; | |
53 case VK_UP : keyname = "VK_UP"; break; | |
54 case VK_RIGHT : keyname = "VK_RIGHT"; break; | |
55 case VK_DOWN : keyname = "VK_DOWN"; break; | |
56 case VK_SELECT : keyname = "VK_SELECT"; break; | |
57 case VK_PRINT : keyname = "VK_PRINT"; break; | |
58 case VK_EXECUTE : keyname = "VK_EXECUTE"; break; | |
59 case VK_SNAPSHOT: keyname = "VK_SNAPSHOT"; break; | |
60 case VK_INSERT : keyname = "VK_INSERT"; break; | |
61 case VK_DELETE : keyname = "VK_DELETE"; break; | |
62 case VK_HELP : keyname = "VK_HELP"; break; | |
63 case VK_LWIN : keyname = "VK_LWIN"; break; | |
64 case VK_RWIN : keyname = "VK_RWIN"; break; | |
65 case VK_NUMPAD0 : keyname = "VK_NUMPAD0"; break; | |
66 case VK_NUMPAD1 : keyname = "VK_NUMPAD1"; break; | |
67 case VK_NUMPAD2 : keyname = "VK_NUMPAD2"; break; | |
68 case VK_NUMPAD3 : keyname = "VK_NUMPAD3"; break; | |
69 case VK_NUMPAD4 : keyname = "VK_NUMPAD4"; break; | |
70 case VK_NUMPAD5 : keyname = "VK_NUMPAD5"; break; | |
71 case VK_NUMPAD6 : keyname = "VK_NUMPAD6"; break; | |
72 case VK_NUMPAD7 : keyname = "VK_NUMPAD7"; break; | |
73 case VK_NUMPAD8 : keyname = "VK_NUMPAD8"; break; | |
74 case VK_NUMPAD9 : keyname = "VK_NUMPAD9"; break; | |
75 case VK_MULTIPLY: keyname = "VK_MULTIPLY"; break; | |
76 case VK_ADD : keyname = "VK_ADD"; break; | |
77 case VK_SEPARATOR: keyname = "VK_SEPARATOR"; break; | |
78 case VK_SUBTRACT: keyname = "VK_SUBTRACT"; break; | |
79 case VK_DECIMAL : keyname = "VK_DECIMAL"; break; | |
80 case VK_DIVIDE : keyname = "VK_DIVIDE"; break; | |
81 case VK_F1 : keyname = "VK_F1"; break; | |
82 case VK_F2 : keyname = "VK_F2"; break; | |
83 case VK_F3 : keyname = "VK_F3"; break; | |
84 case VK_F4 : keyname = "VK_F4"; break; | |
85 case VK_F5 : keyname = "VK_F5"; break; | |
86 case VK_F6 : keyname = "VK_F6"; break; | |
87 case VK_F7 : keyname = "VK_F7"; break; | |
88 case VK_F8 : keyname = "VK_F8"; break; | |
89 case VK_F9 : keyname = "VK_F9"; break; | |
90 case VK_F10 : keyname = "VK_F10"; break; | |
91 case VK_F11 : keyname = "VK_F11"; break; | |
92 case VK_F12 : keyname = "VK_F12"; break; | |
93 case VK_F13 : keyname = "VK_F13"; break; | |
94 case VK_F14 : keyname = "VK_F14"; break; | |
95 case VK_F15 : keyname = "VK_F15"; break; | |
96 case VK_F16 : keyname = "VK_F16"; break; | |
97 case VK_F17 : keyname = "VK_F17"; break; | |
98 case VK_F18 : keyname = "VK_F18"; break; | |
99 case VK_F19 : keyname = "VK_F19"; break; | |
100 case VK_F20 : keyname = "VK_F20"; break; | |
101 case VK_F21 : keyname = "VK_F21"; break; | |
102 case VK_F22 : keyname = "VK_F22"; break; | |
103 case VK_F23 : keyname = "VK_F23"; break; | |
104 case VK_F24 : keyname = "VK_F24"; break; | |
105 case VK_NUMLOCK : keyname = "VK_NUMLOCK"; break; | |
106 case VK_SCROLL : keyname = "VK_SCROLL"; break; | |
107 case VK_LSHIFT : keyname = "VK_LSHIFT"; break; | |
108 case VK_RSHIFT : keyname = "VK_RSHIFT"; break; | |
109 case VK_LCONTROL: keyname = "VK_LCONTROL"; break; | |
110 case VK_RCONTROL: keyname = "VK_RCONTROL"; break; | |
111 default: keyname = "<unknown>"; break; | |
112 } | |
113 return keyname; | |
114 } | |
115 | |
116 const char *ResolveKeyModifiers(int mask) { | |
117 if((mask & KC_CTRL) && (mask & KC_SHIFT) && (mask & KC_ALT)) | |
118 return "KC_CTRL KC_SHIFT KC_ALT"; | |
119 else if((mask & KC_CTRL) && (mask & KC_SHIFT)) | |
120 return "KC_CTRL KC_SHIFT"; | |
121 else if((mask & KC_CTRL) && (mask & KC_ALT)) | |
122 return "KC_CTRL KC_ALT"; | |
123 else if((mask & KC_SHIFT) && (mask & KC_ALT)) | |
124 return "KC_SHIFT KC_ALT"; | |
125 else if((mask & KC_SHIFT)) | |
126 return "KC_SHIFT"; | |
127 else if((mask & KC_CTRL)) | |
128 return "KC_CTRL"; | |
129 else if((mask & KC_ALT)) | |
130 return "KC_ALT"; | |
131 else return "none"; | |
132 } | |
133 | |
134 // Add the menus to the window | |
135 void CreateMenus() { | |
136 // Setup the menu | |
137 DW::MenuBar *menubar = this->MenuBarNew(); | |
138 | |
139 // add menus to the menubar | |
140 DW::Menu *menu = new DW::Menu(); | |
141 DW::MenuItem *menuitem = menu->AppendItem("~Quit"); | |
142 menuitem->ConnectClicked([this] () -> int | |
143 { | |
144 if(this->app->MessageBox("dwtestoo", DW_MB_YESNO | DW_MB_QUESTION, "Are you sure you want to exit?") != 0) { | |
145 this->app->MainQuit(); | |
146 } | |
147 return TRUE; | |
148 }); | |
149 | |
150 // Add the "File" menu to the menubar... | |
151 menubar->AppendItem("~File", menu); | |
152 | |
153 menu = new DW::Menu(); | |
154 DW::MenuItem *checkable_menuitem = menu->AppendItem("~Checkable Menu Item", 0, TRUE); | |
155 checkable_menuitem->ConnectClicked([this]() -> int | |
156 { | |
157 this->app->MessageBox("Menu Item Callback", DW_MB_OK | DW_MB_INFORMATION, "\"Checkable Menu Item\" selected"); | |
158 return FALSE; | |
159 }); | |
160 DW::MenuItem *noncheckable_menuitem = menu->AppendItem("~Non-Checkable Menu Item"); | |
161 noncheckable_menuitem->ConnectClicked([this]() -> int | |
162 { | |
163 this->app->MessageBox("Menu Item Callback", DW_MB_OK | DW_MB_INFORMATION, "\"Non-Checkable Menu Item\" selected"); | |
164 return FALSE; | |
165 }); | |
166 menuitem = menu->AppendItem("~Disabled menu Item", DW_MIS_DISABLED|DW_MIS_CHECKED, TRUE); | |
167 // separator | |
168 menuitem = menu->AppendItem(DW_MENU_SEPARATOR); | |
169 menuitem = menu->AppendItem("~Menu Items Disabled", 0, TRUE); | |
170 menuitem->ConnectClicked([this, checkable_menuitem, noncheckable_menuitem]() -> int | |
171 { | |
172 // Toggle the variable | |
173 this->menu_enabled = !this->menu_enabled; | |
174 // Set the ENABLED/DISABLED state on the menu items | |
175 checkable_menuitem->SetStyle(menu_enabled ? DW_MIS_ENABLED : DW_MIS_DISABLED); | |
176 noncheckable_menuitem->SetStyle(menu_enabled ? DW_MIS_ENABLED : DW_MIS_DISABLED); | |
177 return FALSE; | |
178 }); | |
179 // Add the "Menu" menu to the menubar... | |
180 menubar->AppendItem("~Menu", menu); | |
181 | |
182 menu = new DW::Menu(); | |
183 menuitem = menu->AppendItem("~About"); | |
184 menuitem->ConnectClicked([this]() -> int | |
185 { | |
186 DWEnv env; | |
187 | |
188 this->app->GetEnvironment(&env); | |
189 this->app->MessageBox("About dwindows", DW_MB_OK | DW_MB_INFORMATION, "dwindows test\n\nOS: %s %s %s Version: %d.%d.%d.%d\n\nHTML: %s\n\ndwindows Version: %d.%d.%d\n\nScreen: %dx%d %dbpp", | |
190 env.osName, env.buildDate, env.buildTime, | |
191 env.MajorVersion, env.MinorVersion, env.MajorBuild, env.MinorBuild, | |
192 env.htmlEngine, | |
193 env.DWMajorVersion, env.DWMinorVersion, env.DWSubVersion, | |
194 this->app->GetScreenWidth(), this->app->GetScreenHeight(), this->app->GetColorDepth()); | |
195 return FALSE; | |
196 }); | |
197 // Add the "Help" menu to the menubar... | |
198 menubar->AppendItem("~Help", menu); | |
199 } | |
200 | |
201 // Notebook page 1 | |
202 void CreateInput(DW::Box *notebookbox) | |
203 { | |
204 DW::Box *lbbox = new DW::Box(DW_VERT, 10); | |
205 | |
206 notebookbox->PackStart(lbbox, 150, 70, TRUE, TRUE, 0); | |
207 | |
208 /* Copy and Paste */ | |
209 DW::Box *browsebox = new DW::Box(DW_HORZ, 0); | |
210 lbbox->PackStart(browsebox, 0, 0, FALSE, FALSE, 0); | |
211 | |
212 DW::Entryfield *copypastefield = new DW::Entryfield(); | |
213 copypastefield->SetLimit(260); | |
214 browsebox->PackStart(copypastefield, TRUE, FALSE, 4); | |
215 | |
216 DW::Button *copybutton = new DW::Button("Copy"); | |
217 browsebox->PackStart(copybutton, FALSE, FALSE, 0); | |
218 | |
219 DW::Button *pastebutton = new DW::Button("Paste"); | |
220 browsebox->PackStart(pastebutton, FALSE, FALSE, 0); | |
221 | |
222 /* Archive Name */ | |
223 DW::Text *stext = new DW::Text("File to browse"); | |
224 stext->SetStyle(DW_DT_VCENTER); | |
225 lbbox->PackStart(stext, 130, 15, TRUE, TRUE, 2); | |
226 | |
227 browsebox = new DW::Box(DW_HORZ, 0); | |
228 lbbox->PackStart(browsebox, 0, 0, TRUE, TRUE, 0); | |
229 | |
230 DW::Entryfield *entryfield = new DW::Entryfield(); | |
231 entryfield->SetLimit(260); | |
232 browsebox->PackStart(entryfield, 100, 15, TRUE, TRUE, 4); | |
233 | |
234 DW::Button *browsefilebutton = new DW::Button("Browse File"); | |
235 browsebox->PackStart(browsefilebutton, 40, 15, TRUE, TRUE, 0); | |
236 | |
237 DW::Button *browsefolderbutton = new DW::Button("Browse Folder"); | |
238 browsebox->PackStart(browsefolderbutton, 40, 15, TRUE, TRUE, 0); | |
239 | |
240 browsebox->SetColor(DW_CLR_PALEGRAY, DW_CLR_PALEGRAY); | |
241 stext->SetColor(DW_CLR_BLACK, DW_CLR_PALEGRAY); | |
242 | |
243 // Buttons | |
244 DW::Box *buttonbox = new DW::Box(DW_HORZ, 10); | |
245 lbbox->PackStart(buttonbox, 0, 0, TRUE, TRUE, 0); | |
246 | |
247 DW::Button *cancelbutton = new DW::Button("Exit"); | |
248 buttonbox->PackStart(cancelbutton, 130, 30, TRUE, TRUE, 2); | |
249 | |
250 DW::Button *cursortogglebutton = new DW::Button("Set Cursor pointer - CLOCK"); | |
251 buttonbox->PackStart(cursortogglebutton, 130, 30, TRUE, TRUE, 2); | |
252 | |
253 DW::Button *okbutton = new DW::Button("Turn Off Annoying Beep!"); | |
254 buttonbox->PackStart(okbutton, 130, 30, TRUE, TRUE, 2); | |
255 | |
256 cancelbutton->Unpack(); | |
257 buttonbox->PackStart(cancelbutton, 130, 30, TRUE, TRUE, 2); | |
258 //this->ClickDefault(cancelbutton); | |
259 | |
260 DW::Button *colorchoosebutton = new DW::Button("Color Chooser Dialog"); | |
261 buttonbox->PackStart(colorchoosebutton, 130, 30, TRUE, TRUE, 2); | |
262 | |
263 /* Set some nice fonts and colors */ | |
264 lbbox->SetColor(DW_CLR_DARKCYAN, DW_CLR_PALEGRAY); | |
265 buttonbox->SetColor(DW_CLR_DARKCYAN, DW_CLR_PALEGRAY); | |
266 okbutton->SetColor(DW_CLR_PALEGRAY, DW_CLR_DARKCYAN); | |
267 #ifdef COLOR_DEBUG | |
268 copypastefield->SetColor(DW_CLR_WHITE, DW_CLR_RED); | |
269 copybutton->SetColor(DW_CLR_WHITE, DW_CLR_RED); | |
270 // Set a color then clear it to make sure it clears correctly | |
271 entryfield->SetColor(DW_CLR_WHITE, DW_CLR_RED); | |
272 entryfield->SetColor(DW_CLR_DEFAULT, DW_CLR_DEFAULT); | |
273 // Set a color then clear it to make sure it clears correctly... again | |
274 pastebutton->SetColor(DW_CLR_WHITE, DW_CLR_RED); | |
275 pastebutton->SetColor(DW_CLR_DEFAULT, DW_CLR_DEFAULT); | |
276 #endif | |
277 | |
278 // Connect signals | |
279 browsefilebutton->ConnectClicked([this, entryfield, copypastefield]() -> int | |
280 { | |
281 char *tmp = this->app->FileBrowse("Pick a file", "dwtest.c", "c", DW_FILE_OPEN); | |
282 if(tmp) | |
283 { | |
284 #if 0 | |
285 char *errors = read_file(tmp); | |
286 char *title = "New file load"; | |
287 char *image = "image/test.png"; | |
288 DW::Notification *notification; | |
289 | |
290 if(errors) | |
291 notification = new DW::Notification(title, image, "dwtest failed to load \"%s\" into the file browser, %s.", tmp, errors); | |
292 else | |
293 notification = new DW::Notification(title, image, "dwtest loaded \"%s\" into the file browser on the Render tab, with \"File Display\" selected from the drop down list.", tmp); | |
294 #endif | |
295 | |
296 if(current_file) | |
297 this->app->Free(current_file); | |
298 current_file = tmp; | |
299 entryfield->SetText(current_file); | |
300 current_col = current_row = 0; | |
301 | |
302 #if 0 | |
303 render_draw(); | |
304 notification->ConnectClicked([this]() -> int { | |
305 return TRUE; | |
306 }); | |
307 notification->Send(); | |
308 #endif | |
309 } | |
310 copypastefield->SetFocus(); | |
311 return FALSE; | |
312 }); | |
313 | |
314 browsefolderbutton->ConnectClicked([this]() -> int | |
315 { | |
316 char *tmp = this->app->FileBrowse("Pick a folder", ".", "c", DW_DIRECTORY_OPEN); | |
317 this->app->Debug("Folder picked: %s\n", tmp ? tmp : "None"); | |
318 return FALSE; | |
319 }); | |
320 | |
321 copybutton->ConnectClicked([this, copypastefield, entryfield]() -> int { | |
322 char *test = copypastefield->GetText(); | |
323 | |
324 if(test) { | |
325 this->app->SetClipboard(test); | |
326 this->app->Free(test); | |
327 } | |
328 entryfield->SetFocus(); | |
329 return TRUE; | |
330 }); | |
331 | |
332 pastebutton->ConnectClicked([this, copypastefield]() -> int | |
333 { | |
334 char *test = this->app->GetClipboard(); | |
335 if(test) { | |
336 copypastefield->SetText(test); | |
337 this->app->Free(test); | |
338 } | |
339 return TRUE; | |
340 }); | |
341 | |
342 okbutton->ConnectClicked([this]() -> int | |
343 { | |
344 if(this->timer) { | |
345 delete this->timer; | |
346 this->timer = DW_NULL; | |
347 } | |
348 return TRUE; | |
349 }); | |
350 | |
351 cancelbutton->ConnectClicked([this] () -> int | |
352 { | |
353 if(this->app->MessageBox("dwtest", DW_MB_YESNO | DW_MB_QUESTION, "Are you sure you want to exit?") != 0) { | |
354 this->app->MainQuit(); | |
355 } | |
356 return TRUE; | |
357 }); | |
358 | |
359 cursortogglebutton->ConnectClicked([this, cursortogglebutton] () -> int | |
360 { | |
361 this->cursor_arrow = !this->cursor_arrow; | |
362 cursortogglebutton->SetText(this->cursor_arrow ? "Set Cursor pointer - ARROW" : | |
363 "Set Cursor pointer - CLOCK"); | |
364 this->SetPointer(this->cursor_arrow ? DW_POINTER_CLOCK : DW_POINTER_DEFAULT); | |
365 return FALSE; | |
366 }); | |
367 | |
368 colorchoosebutton->ConnectClicked([this]() -> int | |
369 { | |
370 this->current_color = this->app->ColorChoose(this->current_color); | |
371 return FALSE; | |
372 }); | |
373 } | |
8 public: | 374 public: |
9 MyWindow() { | 375 // Constructor creates the application |
10 SetText("Basic application"); | 376 DWTest(const char *title) { |
11 SetSize(200, 200); | 377 char fileiconpath[1025] = "file"; |
12 } | 378 char foldericonpath[1025] = "folder"; |
13 int OnDelete() override { DW::App *app = DW::App::Init(); app->MainQuit(); return FALSE; } | 379 |
14 int OnConfigure(int width, int height) override { return FALSE; } | 380 // Get our application singleton |
381 app = DW::App::Init(); | |
382 | |
383 // Add menus to the window | |
384 CreateMenus(); | |
385 | |
386 // Create our notebook and add it to the window | |
387 DW::Box *notebookbox = new DW::Box(DW_VERT, 5); | |
388 this->PackStart(notebookbox, 0, 0, TRUE, TRUE, 0); | |
389 | |
390 /* First try the current directory */ | |
391 foldericon = app->LoadIcon(foldericonpath); | |
392 fileicon = app->LoadIcon(fileiconpath); | |
393 | |
394 #ifdef PLATFORMFOLDER | |
395 /* In case we are running from the build directory... | |
396 * also check the appropriate platform subfolder | |
397 */ | |
398 if(!foldericon) | |
399 { | |
400 strncpy(foldericonpath, PLATFORMFOLDER "folder", 1024); | |
401 foldericon = app->LoadIcon(foldericonpath); | |
402 } | |
403 if(!fileicon) | |
404 { | |
405 strncpy(fileiconpath, PLATFORMFOLDER "file", 1024); | |
406 fileicon = app->LoadIcon(fileiconpath); | |
407 } | |
408 #endif | |
409 | |
410 /* Finally try from the platform application directory */ | |
411 if(!foldericon && !fileicon) | |
412 { | |
413 char *appdir = app->GetDir(); | |
414 char pathbuff[1025] = {0}; | |
415 int pos = (int)strlen(appdir); | |
416 | |
417 strncpy(pathbuff, appdir, 1024); | |
418 pathbuff[pos] = DW_DIR_SEPARATOR; | |
419 pos++; | |
420 strncpy(&pathbuff[pos], "folder", 1024-pos); | |
421 foldericon = app->LoadIcon(pathbuff); | |
422 if(foldericon) | |
423 strncpy(foldericonpath, pathbuff, 1025); | |
424 strncpy(&pathbuff[pos], "file", 1024-pos); | |
425 fileicon = app->LoadIcon(pathbuff); | |
426 if(fileicon) | |
427 strncpy(fileiconpath, pathbuff, 1025); | |
428 } | |
429 | |
430 DW::Notebook *notebook = new DW::Notebook(); | |
431 notebookbox->PackStart(notebook, TRUE, TRUE, 0); | |
432 notebook->ConnectSwitchPage([this](unsigned long page_num) -> int | |
433 { | |
434 this->app->Debug("DW_SIGNAL_SWITCH_PAGE: PageNum: %u\n", page_num); | |
435 return TRUE; | |
436 }); | |
437 | |
438 // Create Notebook page 1 | |
439 notebookbox = new DW::Box(DW_VERT, 5); | |
440 CreateInput(notebookbox); | |
441 unsigned long notebookpage = notebook->PageNew(0, TRUE); | |
442 notebook->Pack(notebookpage, notebookbox); | |
443 notebook->PageSetText(notebookpage, "buttons and entry"); | |
444 | |
445 // Finalize the window | |
446 this->SetSize(640, 550); | |
447 | |
448 timer = new DW::Timer(2000, [this]() -> int | |
449 { | |
450 this->app->Beep(200, 200); | |
451 | |
452 // Return TRUE so we get called again | |
453 return TRUE; | |
454 }); | |
455 } | |
456 | |
457 DW::App *app; | |
458 | |
459 // Page 1 | |
460 DW::Timer *timer; | |
461 int cursor_arrow = TRUE; | |
462 unsigned long current_color; | |
463 | |
464 // Page 2 | |
465 HPIXMAP text1pm,text2pm,image; | |
466 int image_x = 20, image_y = 20, image_stretch = 0; | |
467 | |
468 int font_width = 8, font_height=12; | |
469 int rows=10,width1=6,cols=80; | |
470 int num_lines=0, max_linewidth=0; | |
471 int current_row=0,current_col=0; | |
472 int render_type = SHAPES_DOUBLE_BUFFERED; | |
473 | |
474 FILE *fp=NULL; | |
475 char **lp; | |
476 | |
477 // Page 4 | |
478 int mle_point=-1; | |
479 | |
480 // Miscellaneous | |
481 int menu_enabled = 1; | |
482 char *current_file = NULL; | |
483 HICN fileicon,foldericon; | |
484 | |
485 int OnDelete() override { | |
486 if(app->MessageBox("dwtest", DW_MB_YESNO | DW_MB_QUESTION, "Are you sure you want to exit?") != 0) { | |
487 app->MainQuit(); | |
488 } | |
489 return TRUE; | |
490 } | |
15 }; | 491 }; |
16 | 492 |
17 #ifndef DW_LAMBDA | 493 /* Pretty list of features corresponding to the DWFEATURE enum in dw.h */ |
18 int button_clicked() | 494 const char *DWFeatureList[] = { |
19 { | 495 "Supports the HTML Widget", |
20 DW::App *app = DW::App::Init(); | 496 "Supports the DW_SIGNAL_HTML_RESULT callback", |
21 app->MessageBox("Button", DW_MB_OK | DW_MB_INFORMATION, "Clicked!"); | 497 "Supports custom window border sizes", |
22 return TRUE; | 498 "Supports window frame transparency", |
23 } | 499 "Supports Dark Mode user interface", |
24 | 500 "Supports auto completion in Multi-line Edit boxes", |
25 int exit_handler() | 501 "Supports word wrapping in Multi-line Edit boxes", |
26 { | 502 "Supports striped line display in container widgets", |
27 DW::App *app = DW::App::Init(); | 503 "Supports Multiple Document Interface window frame", |
28 if(app->MessageBox("dwtest", DW_MB_YESNO | DW_MB_QUESTION, "Are you sure you want to exit?") != 0) { | 504 "Supports status text area on notebook/tabbed controls", |
29 app->MainQuit(); | 505 "Supports sending system notifications", |
30 } | 506 "Supports UTF8 encoded Unicode text", |
31 return TRUE; | 507 "Supports Rich Edit based MLE control (Windows)", |
32 } | 508 "Supports icons in the taskbar or similar system widget", |
33 #endif | 509 "Supports the Tree Widget", |
34 | 510 "Supports arbitrary window placement", |
511 "Supports alternate container view modes", | |
512 NULL }; | |
513 | |
514 /* | |
515 * Let's demonstrate the functionality of this library. :) | |
516 */ | |
35 int dwmain(int argc, char* argv[]) | 517 int dwmain(int argc, char* argv[]) |
36 { | 518 { |
37 DW::App *app = DW::App::Init(argc, argv, "org.dbsoft.dwindows.dwtestoo"); | 519 /* Initialize the Dynamic Windows engine */ |
38 MyWindow *window = new MyWindow(); | 520 DW::App *app = DW::App::Init(argc, argv, "org.dbsoft.dwindows.dwtestoo", "Dynamic Windows Test C++"); |
39 DW::Button *button = new DW::Button("Test window"); | 521 |
40 | 522 /* Enable full dark mode on platforms that support it */ |
41 window->PackStart(button, DW_SIZE_AUTO, DW_SIZE_AUTO, TRUE, TRUE, 0); | 523 if(getenv("DW_DARK_MODE")) |
42 #ifdef DW_LAMBDA | 524 app->SetFeature(DW_FEATURE_DARK_MODE, DW_DARK_MODE_FULL); |
43 button->ConnectClicked([app] () -> int | 525 |
44 { | 526 #ifdef DW_MOBILE |
45 app->MessageBox("Button", DW_MB_OK | DW_MB_WARNING, "Clicked!"); | 527 /* Enable multi-line container display on Mobile platforms */ |
46 return TRUE; | 528 app->SetFeature(DW_FEATURE_CONTAINER_MODE, DW_CONTAINER_MODE_MULTI); |
47 }); | |
48 #else | |
49 button->ConnectClicked(&button_clicked); | |
50 #endif | 529 #endif |
51 | 530 |
52 DW::MenuBar *mainmenubar = window->MenuBarNew(); | 531 /* Test all the features and display the results */ |
53 | 532 for(int intfeat=DW_FEATURE_HTML; intfeat<DW_FEATURE_MAX; intfeat++) |
54 // add menus to the menubar | 533 { |
55 DW::Menu *menu = new DW::Menu(); | 534 DWFEATURE feat = static_cast<DWFEATURE>(intfeat); |
56 DW::MenuItem *menuitem = menu->AppendItem("~Quit"); | 535 int result = dw_feature_get(feat); |
57 #ifdef DW_LAMBDA | 536 const char *status = "Unsupported"; |
58 menuitem->ConnectClicked([app] () -> int | 537 |
59 { | 538 if(result == 0) |
60 if(app->MessageBox("dwtest", DW_MB_YESNO | DW_MB_QUESTION, "Are you sure you want to exit?") != 0) { | 539 status = "Disabled"; |
61 app->MainQuit(); | 540 else if(result > 0) |
62 } | 541 status = "Enabled"; |
63 return TRUE; | 542 |
64 }); | 543 app->Debug("%s: %s (%d)\n", DWFeatureList[feat], status, result); |
65 #else | 544 } |
66 menuitem->ConnectClicked(&exit_handler); | 545 |
67 #endif | 546 DWTest *window = new DWTest("dwindows test UTF8 中国語 (繁体) cañón"); |
68 | |
69 // Add the "File" menu to the menubar... | |
70 mainmenubar->AppendItem("~File", menu); | |
71 | |
72 window->Show(); | 547 window->Show(); |
73 | 548 |
74 app->Main(); | 549 app->Main(); |
75 app->Exit(0); | 550 app->Exit(0); |
76 | 551 |