Mercurial > dwindows
annotate dwtestoo.cpp @ 2882:99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
use traditional function pointers instead. Also added inital menu support
although it is incomplete as of this commit.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 22 Dec 2022 13:59:46 +0000 |
parents | 0bbfb19022e7 |
children | d301fed4bc23 |
rev | line source |
---|---|
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
1 /* |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
2 * Simple C++ Dynamic Windows Example |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
3 */ |
2871
4b7c4cd7a11d
OS2: Fix building the C++ bindings on OS/2 with GCC.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2869
diff
changeset
|
4 #include "dw.hpp" |
2861
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
5 |
2868
5ee1aaa48fc7
C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2867
diff
changeset
|
6 class MyWindow : public DW::Window |
2861
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
7 { |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
8 public: |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
9 MyWindow() { |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
10 SetText("Basic application"); |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
11 SetSize(200, 200); |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
12 } |
2873
0bbfb19022e7
C++: GCC prior to 4.7 does not support the override keyword.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2871
diff
changeset
|
13 int OnDelete() override { DW::App *app = DW::App::Init(); app->MainQuit(); return FALSE; } |
0bbfb19022e7
C++: GCC prior to 4.7 does not support the override keyword.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2871
diff
changeset
|
14 int OnConfigure(int width, int height) override { return FALSE; } |
2861
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
15 }; |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
16 |
2882
99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2873
diff
changeset
|
17 #ifndef DW_CPP11 |
99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2873
diff
changeset
|
18 int button_clicked() |
99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2873
diff
changeset
|
19 { |
99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2873
diff
changeset
|
20 app->MessageBox("Button", DW_MB_OK | DW_MB_WARNING, "Clicked!"); |
99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2873
diff
changeset
|
21 return TRUE; |
99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2873
diff
changeset
|
22 } |
99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2873
diff
changeset
|
23 #endif |
99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2873
diff
changeset
|
24 |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
25 int dwmain(int argc, char* argv[]) |
2861
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
26 { |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
27 DW::App *app = DW::App::Init(argc, argv, "org.dbsoft.dwindows.dwtestoo"); |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
28 MyWindow *window = new MyWindow(); |
2882
99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2873
diff
changeset
|
29 DW::Button *button = new DW::Button("Test window"); |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
30 |
2882
99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2873
diff
changeset
|
31 window->PackStart(button, DW_SIZE_AUTO, DW_SIZE_AUTO, TRUE, TRUE, 0); |
99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2873
diff
changeset
|
32 #ifdef DW_CPP11 |
99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2873
diff
changeset
|
33 button->ConnectClicked([app] () -> int |
99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2873
diff
changeset
|
34 { |
99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2873
diff
changeset
|
35 app->MessageBox("Button", DW_MB_OK | DW_MB_WARNING, "Clicked!"); |
99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2873
diff
changeset
|
36 return TRUE; |
99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2873
diff
changeset
|
37 }); |
99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2873
diff
changeset
|
38 #else |
99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2873
diff
changeset
|
39 button ->ConnectClicked(&button_clicked); |
99311a9091af
C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2873
diff
changeset
|
40 #endif |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
41 window->Show(); |
2861
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
42 |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
43 app->Main(); |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
44 app->Exit(0); |
2861
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
45 |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
46 return 0; |
2861
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
47 } |