Mercurial > dwindows
comparison dwtestoo.cpp @ 2923:969cc3b8bec2
C++: Include the old style function support even when lambdas are available.
This allows old style applications to compile unmodified on lambda supported
compilers. Also include the original extremely simple test program in
dwtestoo.cpp so non-lambda compilers will see something besides a build
failure. Add a message to the old sample to upgrade to a lambda supported
compiler to see the full sample application.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 29 Dec 2022 21:56:58 +0000 |
parents | 235fef840df2 |
children | 248e32f744f0 |
comparison
equal
deleted
inserted
replaced
2922:0919c2b82109 | 2923:969cc3b8bec2 |
---|---|
1 /* | 1 // An example Dynamic Windows application and testing |
2 * Simple C++ Dynamic Windows Example | 2 // ground for Dynamic Windows features in C++. |
3 */ | 3 // By: Brian Smith and Mark Hessling |
4 #include "dw.hpp" | 4 #include "dw.hpp" |
5 | 5 |
6 /* Select a fixed width font for our platform */ | 6 // Select a fixed width font for our platform |
7 #ifdef __OS2__ | 7 #ifdef __OS2__ |
8 #define FIXEDFONT "5.System VIO" | 8 #define FIXEDFONT "5.System VIO" |
9 #define PLATFORMFOLDER "os2\\" | 9 #define PLATFORMFOLDER "os2\\" |
10 #elif defined(__WIN32__) | 10 #elif defined(__WIN32__) |
11 #define FIXEDFONT "10.Lucida Console" | 11 #define FIXEDFONT "10.Lucida Console" |
29 #define DRAW_FILE 2 | 29 #define DRAW_FILE 2 |
30 | 30 |
31 #define APP_TITLE "Dynamic Windows C++" | 31 #define APP_TITLE "Dynamic Windows C++" |
32 #define APP_EXIT "Are you sure you want to exit?" | 32 #define APP_EXIT "Are you sure you want to exit?" |
33 | 33 |
34 // Handle the case of very old compilers by using | |
35 // A simple non-lambda example instead. | |
36 #ifndef DW_LAMBDA | |
37 | |
38 // Simple C++ Dynamic Windows Example | |
39 | |
40 class DWTest : public DW::Window | |
41 { | |
42 public: | |
43 DW::App *app; | |
44 | |
45 DWTest() { | |
46 app = DW::App::Init(); | |
47 | |
48 SetText(APP_TITLE); | |
49 SetSize(200, 200); | |
50 } | |
51 int OnDelete() override { | |
52 if(app->MessageBox(APP_TITLE, DW_MB_YESNO | DW_MB_QUESTION, APP_EXIT) != 0) { | |
53 app->MainQuit(); | |
54 } | |
55 return FALSE; | |
56 } | |
57 }; | |
58 | |
59 int button_clicked(Clickable *classptr) | |
60 { | |
61 DW::App *app = DW::App::Init(); | |
62 app->MessageBox("Button", DW_MB_OK | DW_MB_INFORMATION, "Clicked!"); | |
63 return TRUE; | |
64 } | |
65 | |
66 int exit_handler(Clickable *classptr) | |
67 { | |
68 DW::App *app = DW::App::Init(); | |
69 if(app->MessageBox(APP_TITLE, DW_MB_YESNO | DW_MB_QUESTION, APP_EXIT) != 0) { | |
70 app->MainQuit(); | |
71 } | |
72 return TRUE; | |
73 } | |
74 | |
75 int dwmain(int argc, char* argv[]) | |
76 { | |
77 DW::App *app = DW::App::Init(argc, argv, "org.dbsoft.dwindows.dwtestoo"); | |
78 | |
79 app->MessageBox(APP_TITLE, DW_MB_OK | DW_MB_INFORMATION, | |
80 "Warning: You are viewing the simplified version of this sample program.\n\n" \ | |
81 "This is because your compiler does not have lambda support.\n\n" \ | |
82 "Please upgrade to Clang, GCC 4.5 or Visual Studio 2010 to see the full sample."); | |
83 | |
84 DWTest *window = new DWTest(); | |
85 DW::Button *button = new DW::Button("Test window"); | |
86 | |
87 window->PackStart(button, DW_SIZE_AUTO, DW_SIZE_AUTO, TRUE, TRUE, 0); | |
88 button->ConnectClicked(&button_clicked); | |
89 | |
90 DW::MenuBar *mainmenubar = window->MenuBarNew(); | |
91 | |
92 // add menus to the menubar | |
93 DW::Menu *menu = new DW::Menu(); | |
94 DW::MenuItem *menuitem = menu->AppendItem("~Quit"); | |
95 menuitem->ConnectClicked(&exit_handler); | |
96 | |
97 // Add the "File" menu to the menubar... | |
98 mainmenubar->AppendItem("~File", menu); | |
99 | |
100 window->Show(); | |
101 | |
102 app->Main(); | |
103 app->Exit(0); | |
104 | |
105 return 0; | |
106 } | |
107 #else | |
34 class DWTest : public DW::Window | 108 class DWTest : public DW::Window |
35 { | 109 { |
36 private: | 110 private: |
37 const char *ResolveKeyName(int vk) { | 111 const char *ResolveKeyName(int vk) { |
38 const char *keyname; | 112 const char *keyname; |
998 } | 1072 } |
999 return TRUE; | 1073 return TRUE; |
1000 } | 1074 } |
1001 }; | 1075 }; |
1002 | 1076 |
1003 /* Pretty list of features corresponding to the DWFEATURE enum in dw.h */ | 1077 // Pretty list of features corresponding to the DWFEATURE enum in dw.h |
1004 const char *DWFeatureList[] = { | 1078 const char *DWFeatureList[] = { |
1005 "Supports the HTML Widget", | 1079 "Supports the HTML Widget", |
1006 "Supports the DW_SIGNAL_HTML_RESULT callback", | 1080 "Supports the DW_SIGNAL_HTML_RESULT callback", |
1007 "Supports custom window border sizes", | 1081 "Supports custom window border sizes", |
1008 "Supports window frame transparency", | 1082 "Supports window frame transparency", |
1019 "Supports the Tree Widget", | 1093 "Supports the Tree Widget", |
1020 "Supports arbitrary window placement", | 1094 "Supports arbitrary window placement", |
1021 "Supports alternate container view modes", | 1095 "Supports alternate container view modes", |
1022 NULL }; | 1096 NULL }; |
1023 | 1097 |
1024 /* | 1098 // Let's demonstrate the functionality of this library. :) |
1025 * Let's demonstrate the functionality of this library. :) | |
1026 */ | |
1027 int dwmain(int argc, char* argv[]) | 1099 int dwmain(int argc, char* argv[]) |
1028 { | 1100 { |
1029 /* Initialize the Dynamic Windows engine */ | 1101 // Initialize the Dynamic Windows engine |
1030 DW::App *app = DW::App::Init(argc, argv, "org.dbsoft.dwindows.dwtestoo", "Dynamic Windows Test C++"); | 1102 DW::App *app = DW::App::Init(argc, argv, "org.dbsoft.dwindows.dwtestoo", "Dynamic Windows Test C++"); |
1031 | 1103 |
1032 /* Enable full dark mode on platforms that support it */ | 1104 // Enable full dark mode on platforms that support it |
1033 if(getenv("DW_DARK_MODE")) | 1105 if(getenv("DW_DARK_MODE")) |
1034 app->SetFeature(DW_FEATURE_DARK_MODE, DW_DARK_MODE_FULL); | 1106 app->SetFeature(DW_FEATURE_DARK_MODE, DW_DARK_MODE_FULL); |
1035 | 1107 |
1036 #ifdef DW_MOBILE | 1108 #ifdef DW_MOBILE |
1037 /* Enable multi-line container display on Mobile platforms */ | 1109 // Enable multi-line container display on Mobile platforms |
1038 app->SetFeature(DW_FEATURE_CONTAINER_MODE, DW_CONTAINER_MODE_MULTI); | 1110 app->SetFeature(DW_FEATURE_CONTAINER_MODE, DW_CONTAINER_MODE_MULTI); |
1039 #endif | 1111 #endif |
1040 | 1112 |
1041 /* Test all the features and display the results */ | 1113 // Test all the features and display the results |
1042 for(int intfeat=DW_FEATURE_HTML; intfeat<DW_FEATURE_MAX; intfeat++) | 1114 for(int intfeat=DW_FEATURE_HTML; intfeat<DW_FEATURE_MAX; intfeat++) |
1043 { | 1115 { |
1044 DWFEATURE feat = static_cast<DWFEATURE>(intfeat); | 1116 DWFEATURE feat = static_cast<DWFEATURE>(intfeat); |
1045 int result = dw_feature_get(feat); | 1117 int result = dw_feature_get(feat); |
1046 const char *status = "Unsupported"; | 1118 const char *status = "Unsupported"; |
1059 app->Main(); | 1131 app->Main(); |
1060 app->Exit(0); | 1132 app->Exit(0); |
1061 | 1133 |
1062 return 0; | 1134 return 0; |
1063 } | 1135 } |
1136 #endif |