annotate dw.hpp @ 2889:4b075e64536c

C++: Add some simple menu code to see if things are working.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 22 Dec 2022 19:20:39 +0000
parents df1b7f7d1703
children ab4c86ddc63a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1 /* Dynamic Windows C++ Language Bindings
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2 * Copyright 2022 Brian Smith
2878
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
3 * Recommends a C++11 compatible compiler.
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4 */
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6 #ifndef _HPP_DW
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7 #define _HPP_DW
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8 #include <dw.h>
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9
2872
e62fc9b3b09c C++: Add DW_NULL which is nullptr on C++11 and NULL on older versions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2871
diff changeset
10 // Attempt to support compilers without nullptr type literal
e62fc9b3b09c C++: Add DW_NULL which is nullptr on C++11 and NULL on older versions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2871
diff changeset
11 #if __cplusplus >= 201103L
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
12 #define DW_CPP11
2872
e62fc9b3b09c C++: Add DW_NULL which is nullptr on C++11 and NULL on older versions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2871
diff changeset
13 #define DW_NULL nullptr
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
14 #include <functional>
2872
e62fc9b3b09c C++: Add DW_NULL which is nullptr on C++11 and NULL on older versions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2871
diff changeset
15 #else
e62fc9b3b09c C++: Add DW_NULL which is nullptr on C++11 and NULL on older versions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2871
diff changeset
16 #define DW_NULL NULL
e62fc9b3b09c C++: Add DW_NULL which is nullptr on C++11 and NULL on older versions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2871
diff changeset
17 #endif
e62fc9b3b09c C++: Add DW_NULL which is nullptr on C++11 and NULL on older versions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2871
diff changeset
18
2873
0bbfb19022e7 C++: GCC prior to 4.7 does not support the override keyword.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2872
diff changeset
19 // Attempt to allow compilation on GCC older than 4.7
0bbfb19022e7 C++: GCC prior to 4.7 does not support the override keyword.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2872
diff changeset
20 #if defined(__GNUC__) && (__GNuC__ < 5 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7))
0bbfb19022e7 C++: GCC prior to 4.7 does not support the override keyword.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2872
diff changeset
21 #define override
0bbfb19022e7 C++: GCC prior to 4.7 does not support the override keyword.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2872
diff changeset
22 #endif
0bbfb19022e7 C++: GCC prior to 4.7 does not support the override keyword.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2872
diff changeset
23
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
24 namespace DW
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
25 {
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
26
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
27 // Forward declare these so they can be referenced
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
28 class Render;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
29 class Pixmap;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
30 class MenuItem;
2885
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
31 class Window;
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
32
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
33 // Base handle class which allows opaque access to
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
34 // The base system handles
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
35 class Handle
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
36 {
2868
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
37 protected:
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
38 void *handle;
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
39 void SetHandle(void *newhandle) { handle = newhandle; }
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
40 public:
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
41 void *GetHandle() { return handle; }
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
42 };
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
43
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
44 // Widget class allows packing and style
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
45 class Widget : public Handle
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
46 {
2868
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
47 protected:
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
48 void SetHWND(HWND newhwnd) {
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
49 hwnd = newhwnd;
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
50 SetHandle(reinterpret_cast<void *>(newhwnd));
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
51 // Save the C++ class pointer in the window data for later
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
52 dw_window_set_data(hwnd, "_dw_classptr", this);
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
53 }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
54 HWND hwnd;
2868
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
55 public:
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
56 HWND GetHWND() { return hwnd; }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
57 int Unpack() { return dw_box_unpack(hwnd); }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
58 void SetStyle(unsigned long style, unsigned long mask) { dw_window_set_style(hwnd, style, mask); }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
59 void SetTooltip(char *bubbletext) { dw_window_set_tooltip(hwnd, bubbletext); }
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
60 int SetColor(unsigned long fore, unsigned long back) { return dw_window_set_color(hwnd, fore, back); }
2877
6f31b7991fa0 C++: Fix Combobox class by making the parent classes virtual.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2876
diff changeset
61 void SetData(const char *dataname, void *data) { dw_window_set_data(hwnd, dataname, data); }
6f31b7991fa0 C++: Fix Combobox class by making the parent classes virtual.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2876
diff changeset
62 void *GetData(const char *dataname) { return dw_window_get_data(hwnd, dataname); }
2878
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
63 void SetPointer(int cursortype) { dw_window_set_pointer(hwnd, cursortype); }
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
64 Widget *FromID(int id) {
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
65 HWND child = dw_window_from_id(hwnd, id);
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
66 if(child) {
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
67 return reinterpret_cast<Widget *>(dw_window_get_data(child, "_dw_classptr"));
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
68 }
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
69 return DW_NULL;
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
70 }
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
71 void GetPreferredSize(int *width, int *height) { dw_window_get_preferred_size(hwnd, width, height); }
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
72 };
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
73
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
74 // Box class is a packable object
2877
6f31b7991fa0 C++: Fix Combobox class by making the parent classes virtual.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2876
diff changeset
75 class Boxes : virtual public Widget
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
76 {
2868
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
77 public:
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
78 // User functions
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
79 void PackStart(Widget *item, int width, int height, int hsize, int vsize, int pad) {
2871
4b7c4cd7a11d OS2: Fix building the C++ bindings on OS/2 with GCC.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2870
diff changeset
80 dw_box_pack_start(hwnd, item ? item->GetHWND() : DW_NOHWND, width, height, hsize, vsize, pad); }
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
81 void PackEnd(Widget *item, int width, int height, int hsize, int vsize, int pad) {
2871
4b7c4cd7a11d OS2: Fix building the C++ bindings on OS/2 with GCC.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2870
diff changeset
82 dw_box_pack_end(hwnd, item ? item->GetHWND() : DW_NOHWND, width, height, hsize, vsize, pad); }
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
83 void PackAtIndex(Widget *item, int index, int width, int height, int hsize, int vsize, int pad) {
2871
4b7c4cd7a11d OS2: Fix building the C++ bindings on OS/2 with GCC.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2870
diff changeset
84 dw_box_pack_at_index(hwnd, item ? item->GetHWND() : DW_NOHWND, index, width, height, hsize, vsize, pad); }
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
85 Widget *UnpackAtIndex(int index) { HWND widget = dw_box_unpack_at_index(hwnd, index);
2872
e62fc9b3b09c C++: Add DW_NULL which is nullptr on C++11 and NULL on older versions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2871
diff changeset
86 void *classptr = widget ? dw_window_get_data(widget, "_dw_classptr") : DW_NULL;
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
87 return reinterpret_cast<Widget *>(classptr);
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
88 }
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
89 };
2868
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
90
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
91 class Box : public Boxes
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
92 {
2877
6f31b7991fa0 C++: Fix Combobox class by making the parent classes virtual.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2876
diff changeset
93 public:
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
94 // Constructors
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
95 Box(int type, int pad) { SetHWND(dw_box_new(type, pad)); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
96 Box(int type) { SetHWND(dw_box_new(type, 0)); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
97 };
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
98
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
99 // Special scrollable box
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
100 class ScrollBox : public Boxes
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
101 {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
102 public:
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
103 // Constructors
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
104 ScrollBox(int type, int pad) { SetHWND(dw_scrollbox_new(type, pad)); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
105 ScrollBox(int type) { SetHWND(dw_scrollbox_new(type, 0)); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
106
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
107 // User functions
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
108 int GetRange(int orient) { return dw_scrollbox_get_range(hwnd, orient); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
109 int GetPos(int orient) { return dw_scrollbox_get_pos(hwnd, orient); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
110 };
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
111
2868
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
112 // TODO: Find a way to implement this cross platform...
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
113 // That way we can skip adding unused signal handlers
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
114 #define IsOverridden(a, b) true
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
115
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
116 // Base class for several types of widgets including buttons and menu items
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
117 class Clickable : virtual public Widget
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
118 {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
119 private:
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
120 bool ClickedConnected;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
121 #ifdef DW_CPP11
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
122 std::function<int()> _ConnectClicked;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
123 #else
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
124 int (*_ConnectClicked)();
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
125 #endif
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
126 static int _OnClicked(HWND window, void *data) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
127 if(reinterpret_cast<Clickable *>(data)->_ConnectClicked)
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
128 return reinterpret_cast<Clickable *>(data)->_ConnectClicked();
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
129 return reinterpret_cast<Clickable *>(data)->OnClicked(); }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
130 protected:
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
131 void Setup() {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
132 if(IsOverridden(Clickable::OnClicked, this)) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
133 dw_signal_connect(hwnd, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_OnClicked), this);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
134 ClickedConnected = true;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
135 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
136 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
137 // Our signal handler functions to be overriden...
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
138 // If they are not overridden and an event is generated, remove the unused handler
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
139 virtual int OnClicked() {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
140 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_CLICKED);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
141 ClickedConnected = false;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
142 return FALSE;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
143 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
144 public:
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
145 #ifdef DW_CPP11
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
146 void ConnectClicked(std::function<int()> userfunc)
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
147 #else
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
148 void ConnectClicked(int (*userfunc)())
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
149 #endif
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
150 {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
151 _ConnectClicked = userfunc;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
152 if(!ClickedConnected) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
153 dw_signal_connect(hwnd, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_OnClicked), this);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
154 ClickedConnected = true;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
155 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
156 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
157 };
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
158
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
159 class Menus : public Handle
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
160 {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
161 protected:
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
162 void SetHMENUI(HMENUI newmenu) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
163 menu = newmenu;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
164 SetHandle(reinterpret_cast<void *>(newmenu));
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
165 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
166 HMENUI menu;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
167 public:
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
168 // User functions
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
169 HMENUI GetHMENUI() { return menu; }
2889
4b075e64536c C++: Add some simple menu code to see if things are working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2885
diff changeset
170 MenuItem *AppendItem(const char *title, unsigned long id, unsigned long flags, int end, int check, Menus *submenu);
4b075e64536c C++: Add some simple menu code to see if things are working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2885
diff changeset
171 MenuItem *AppendItem(const char *title, Menus *submenu);
4b075e64536c C++: Add some simple menu code to see if things are working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2885
diff changeset
172 MenuItem *AppendItem(const char *title);
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
173 };
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
174
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
175 class Menu : public Menus
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
176 {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
177 public:
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
178 // Constructors
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
179 Menu(unsigned long id) { SetHMENUI(dw_menu_new(id)); }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
180 Menu() { SetHMENUI(dw_menu_new(0)); }
2885
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
181
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
182 // User functions
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
183 void Popup(Window *window, int x, int y);
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
184 void Popup(Window *window);
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
185 };
2885
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
186
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
187 class MenuBar : public Menus
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
188 {
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
189 public:
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
190 // Constructors
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
191 MenuBar(HWND location) { SetHMENUI(dw_menubar_new(location)); }
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
192 };
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
193
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
194 class MenuItem : public Clickable
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
195 {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
196 public:
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
197 // Constructors
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
198 MenuItem(Menus *menu, const char *title, unsigned long id, unsigned long flags, int end, int check, Menus *submenu) {
2885
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
199 SetHWND(dw_menu_append_item(menu->GetHMENUI(), title, id, flags, end, check, submenu ? submenu->GetHMENUI() : DW_NOMENU));
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
200 }
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
201 MenuItem(Menus *menu, const char *title, Menus *submenu) {
2889
4b075e64536c C++: Add some simple menu code to see if things are working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2885
diff changeset
202 SetHWND(dw_menu_append_item(menu->GetHMENUI(), title, DW_MENU_AUTO, 0, TRUE, FALSE, submenu ? submenu->GetHMENUI() : DW_NOMENU));
2885
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
203 }
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
204 MenuItem(Menus *menu, const char *title) {
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
205 SetHWND(dw_menu_append_item(menu->GetHMENUI(), title, DW_MENU_AUTO, 0, TRUE, FALSE, DW_NOMENU));
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
206 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
207
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
208 // User functions
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
209 void SetState(unsigned long flags) { dw_window_set_style(hwnd, flags, flags); }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
210 void SetStyle(unsigned long flags, unsigned long mask) { dw_window_set_style(hwnd, flags, mask); }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
211 };
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
212
2889
4b075e64536c C++: Add some simple menu code to see if things are working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2885
diff changeset
213 MenuItem *Menus::AppendItem(const char *title, unsigned long id, unsigned long flags, int end, int check, Menus *submenu) {
2885
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
214 return new MenuItem((Menus *)menu, title, id, flags, end, check, submenu);
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
215 }
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
216
2889
4b075e64536c C++: Add some simple menu code to see if things are working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2885
diff changeset
217 MenuItem *Menus::AppendItem(const char *title, Menus *submenu) {
2885
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
218 return new MenuItem((Menus *)menu, title, submenu);
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
219 }
2889
4b075e64536c C++: Add some simple menu code to see if things are working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2885
diff changeset
220 MenuItem *Menus::AppendItem(const char *title) {
2885
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
221 return new MenuItem((Menus *)menu, title);
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
222 }
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
223
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
224
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
225 // Top-level window class is packable
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
226 class Window : public Boxes
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
227 {
2865
fd32dce7fecd Initial signal handler support for the C++ bindings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2861
diff changeset
228 private:
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
229 bool DeleteConnected, ConfigureConnected;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
230 #ifdef DW_CPP11
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
231 std::function<int()> _ConnectDelete;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
232 std::function<int(int, int)> _ConnectConfigure;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
233 #else
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
234 int (*_ConnectDelete)();
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
235 int (*_ConnectConfigure)(int width, int height);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
236 #endif
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
237 void Setup() {
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
238 if(IsOverridden(Window::OnDelete, this)) {
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
239 dw_signal_connect(hwnd, DW_SIGNAL_DELETE, DW_SIGNAL_FUNC(_OnDelete), this);
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
240 DeleteConnected = true;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
241 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
242 if(IsOverridden(Window::OnConfigure, this)) {
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
243 dw_signal_connect(hwnd, DW_SIGNAL_CONFIGURE, DW_SIGNAL_FUNC(_OnConfigure), this);
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
244 ConfigureConnected = true;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
245 }
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
246 }
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
247 static int _OnDelete(HWND window, void *data) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
248 if(reinterpret_cast<Window *>(data)->_ConnectDelete)
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
249 return reinterpret_cast<Window *>(data)->_ConnectDelete();
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
250 return reinterpret_cast<Window *>(data)->OnDelete(); }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
251 static int _OnConfigure(HWND window, int width, int height, void *data) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
252 if(reinterpret_cast<Window *>(data)->_ConnectConfigure)
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
253 return reinterpret_cast<Window *>(data)->_ConnectConfigure(width, height);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
254 return reinterpret_cast<Window *>(data)->OnConfigure(width, height); }
2884
06e475feaac0 C++: Split Menu and MenuBar to prevent type conflicts.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2882
diff changeset
255 MenuBar *menu;
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
256 public:
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
257 // Constructors
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
258 Window(HWND owner, const char *title, unsigned long style) { SetHWND(dw_window_new(owner, title, style)); Setup(); }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
259 Window(const char *title, unsigned long style) { SetHWND(dw_window_new(HWND_DESKTOP, title, style)); Setup(); }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
260 Window(unsigned long style) { SetHWND(dw_window_new(HWND_DESKTOP, "", style)); Setup(); }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
261 Window(const char *title) { SetHWND(dw_window_new(HWND_DESKTOP, title, DW_FCF_SYSMENU | DW_FCF_TITLEBAR |
2865
fd32dce7fecd Initial signal handler support for the C++ bindings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2861
diff changeset
262 DW_FCF_TASKLIST | DW_FCF_SIZEBORDER | DW_FCF_MINMAX)); Setup(); }
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
263 Window() { SetHWND(dw_window_new(HWND_DESKTOP, "", DW_FCF_SYSMENU | DW_FCF_TITLEBAR |
2865
fd32dce7fecd Initial signal handler support for the C++ bindings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2861
diff changeset
264 DW_FCF_TASKLIST | DW_FCF_SIZEBORDER | DW_FCF_MINMAX)); Setup(); }
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
265
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
266 // User functions
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
267 void SetText(const char *text) { dw_window_set_text(hwnd, text); }
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
268 char *GetText() { return dw_window_get_text(hwnd); }
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
269 void SetSize(unsigned long width, unsigned long height) { dw_window_set_size(hwnd, width, height); }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
270 int Show() { return dw_window_show(hwnd); }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
271 int Hide() { return dw_window_hide(hwnd); }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
272 void SetGravity(int horz, int vert) { dw_window_set_gravity(hwnd, horz, vert); }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
273 int Minimize() { return dw_window_minimize(hwnd); }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
274 int Raise() { return dw_window_raise(hwnd); }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
275 int Lower() { return dw_window_lower(hwnd); }
2878
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
276 void Redraw() { dw_window_redraw(hwnd); }
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
277 void Default(Widget *defaultitem) { if(defaultitem) dw_window_default(hwnd, defaultitem->GetHWND()); }
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
278 void SetIcon(HICN icon) { dw_window_set_icon(hwnd, icon); }
2889
4b075e64536c C++: Add some simple menu code to see if things are working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2885
diff changeset
279 MenuBar *MenuBarNew() { if(!menu) menu = new MenuBar(hwnd); return menu; }
4b075e64536c C++: Add some simple menu code to see if things are working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2885
diff changeset
280 void Popup(Menu *menu, int x, int y) {
2885
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
281 if(menu) {
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
282 HMENUI pmenu = menu;
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
283
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
284 dw_menu_popup(&pmenu, hwnd, x, y);
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
285 delete menu;
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
286 }
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
287 }
2889
4b075e64536c C++: Add some simple menu code to see if things are working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2885
diff changeset
288 void Popup(Menu *menu) {
4b075e64536c C++: Add some simple menu code to see if things are working.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2885
diff changeset
289 if(menu) {
2885
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
290 long x, y;
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
291 HMENUI pmenu = menu;
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
292
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
293 dw_pointer_query_pos(&x, &y);
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
294 dw_menu_popup(&pmenu, hwnd, (int)x, (int)y);
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
295 delete menu;
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
296 }
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
297 }
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
298 #ifdef DW_CPP11
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
299 void ConnectDelete(std::function<int()> userfunc)
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
300 #else
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
301 void ConnectDelete(int (*userfunc)())
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
302 #endif
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
303 {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
304 _ConnectDelete = userfunc;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
305 if(!DeleteConnected) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
306 dw_signal_connect(hwnd, DW_SIGNAL_DELETE, DW_SIGNAL_FUNC(_OnDelete), this);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
307 DeleteConnected = true;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
308 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
309 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
310 #ifdef DW_CPP11
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
311 void ConnectConfigure(std::function<int(int, int)> userfunc)
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
312 #else
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
313 void ConnectConfigure(int (*userfunc)(int, int))
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
314 #endif
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
315 {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
316 _ConnectConfigure = userfunc;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
317 if(!ConfigureConnected) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
318 dw_signal_connect(hwnd, DW_SIGNAL_CONFIGURE, DW_SIGNAL_FUNC(_OnConfigure), this);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
319 ConfigureConnected = true;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
320 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
321 }
2868
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
322 protected:
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
323 // Our signal handler functions to be overriden...
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
324 // If they are not overridden and an event is generated, remove the unused handler
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
325 virtual int OnDelete() {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
326 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_DELETE);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
327 DeleteConnected = false;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
328 return FALSE;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
329 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
330 virtual int OnConfigure(int width, int height) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
331 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_CONFIGURE);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
332 ConfigureConnected = false;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
333 return FALSE;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
334 };
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
335 };
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
336
2885
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
337 void Menu::Popup(Window *window, int x, int y)
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
338 {
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
339 if(window)
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
340 {
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
341 HMENUI pmenu = menu;
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
342
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
343 dw_menu_popup(&pmenu, window->GetHWND(), x, y);
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
344 delete this;
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
345 }
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
346 }
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
347
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
348 void Menu::Popup(Window *window)
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
349 {
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
350 if(window) {
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
351 long x, y;
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
352 HMENUI pmenu = menu;
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
353
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
354 dw_pointer_query_pos(&x, &y);
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
355 dw_menu_popup(&pmenu, window->GetHWND(), (int)x, (int)y);
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
356 delete this;
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
357 }
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
358 }
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
359
2878
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
360 // Class for focusable widgets
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
361 class Focusable : virtual public Widget
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
362 {
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
363 public:
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
364 void Enable() { dw_window_enable(hwnd); }
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
365 void Disable() { dw_window_disable(hwnd); }
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
366 void SetFocus() { dw_window_set_focus(hwnd); }
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
367 };
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
368
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
369 // Text based button
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
370 class TextButton : public Clickable, public Focusable
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
371 {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
372 public:
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
373 // User functions
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
374 void SetText(const char *text) { dw_window_set_text(hwnd, text); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
375 char *GetText() { return dw_window_get_text(hwnd); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
376 };
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
377
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
378 class Button : public TextButton
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
379 {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
380 public:
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
381 // Constructors
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
382 Button(const char *text, unsigned long id) { SetHWND(dw_button_new(text, id)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
383 Button(unsigned long id) { SetHWND(dw_button_new("", id)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
384 Button(const char *text) { SetHWND(dw_button_new(text, 0)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
385 Button() { SetHWND(dw_button_new("", 0)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
386 };
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
387
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
388 // Image based button
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
389 class BitmapButton : public Clickable, public Focusable
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
390 {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
391 public:
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
392 // Constructors
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
393 BitmapButton(const char *text, unsigned long id) { SetHWND(dw_bitmapbutton_new(text, id)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
394 BitmapButton(unsigned long id) { SetHWND(dw_bitmapbutton_new("", id)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
395 BitmapButton(const char *text, unsigned long id, const char *file) { SetHWND(dw_bitmapbutton_new_from_file(text, id, file)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
396 BitmapButton(const char *text, const char *file) { SetHWND(dw_bitmapbutton_new_from_file(text, 0, file)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
397 BitmapButton(const char *text, unsigned long id, const char *data, int len) { SetHWND(dw_bitmapbutton_new_from_data(text, id, data, len)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
398 BitmapButton(const char *text, const char *data, int len) { SetHWND(dw_bitmapbutton_new_from_data(text, 0, data, len)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
399 };
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
400
2877
6f31b7991fa0 C++: Fix Combobox class by making the parent classes virtual.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2876
diff changeset
401 class CheckBoxes : virtual public TextButton
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
402 {
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
403 public:
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
404 // User functions
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
405 void Set(int value) { dw_checkbox_set(hwnd, value); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
406 int Get() { return dw_checkbox_get(hwnd); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
407 };
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
408
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
409 class CheckBox : public CheckBoxes
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
410 {
2877
6f31b7991fa0 C++: Fix Combobox class by making the parent classes virtual.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2876
diff changeset
411 public:
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
412 // Constructors
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
413 CheckBox(const char *text, unsigned long id) { SetHWND(dw_checkbox_new(text, id)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
414 CheckBox(unsigned long id) { SetHWND(dw_checkbox_new("", id)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
415 CheckBox(const char *text) { SetHWND(dw_checkbox_new(text, 0)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
416 CheckBox() { SetHWND(dw_checkbox_new("", 0)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
417 };
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
418
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
419 class RadioButton : public CheckBoxes
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
420 {
2877
6f31b7991fa0 C++: Fix Combobox class by making the parent classes virtual.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2876
diff changeset
421 public:
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
422 // Constructors
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
423 RadioButton(const char *text, unsigned long id) { SetHWND(dw_radiobutton_new(text, id)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
424 RadioButton(unsigned long id) { SetHWND(dw_radiobutton_new("", id)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
425 RadioButton(const char *text) { SetHWND(dw_radiobutton_new(text, 0)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
426 RadioButton() { SetHWND(dw_radiobutton_new("", 0)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
427 };
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
428
2868
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
429 // Class for handling static text widget
2878
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
430 class TextWidget : virtual public Widget
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
431 {
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
432 public:
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
433 // User functions
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
434 void SetText(const char *text) { dw_window_set_text(hwnd, text); }
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
435 char *GetText() { return dw_window_get_text(hwnd); }
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
436 int SetFont(const char *font) { return dw_window_set_font(hwnd, font); }
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
437 char *GetFont() { return dw_window_get_font(hwnd); }
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
438 };
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
439
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
440 // Class for handling static text widget
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
441 class Text : public TextWidget
2868
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
442 {
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
443 public:
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
444 // Constructors
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
445 Text(const char *text, unsigned long id) { SetHWND(dw_text_new(text, id)); }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
446 Text(const char *text) { SetHWND(dw_text_new(text, 0)); }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
447 Text(unsigned long id) { SetHWND(dw_text_new("", id)); }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
448 Text() { SetHWND(dw_text_new("", 0)); }
2878
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
449 };
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
450
2878
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
451 class StatusText : public TextWidget
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
452 {
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
453 public:
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
454 // Constructors
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
455 StatusText(const char *text, unsigned long id) { SetHWND(dw_status_text_new(text, id)); }
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
456 StatusText(const char *text) { SetHWND(dw_status_text_new(text, 0)); }
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
457 StatusText(unsigned long id) { SetHWND(dw_status_text_new("", id)); }
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
458 StatusText() { SetHWND(dw_status_text_new("", 0)); }
2868
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
459 };
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
460
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
461 // Class for handing static image widget
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
462 class Bitmap : public Widget
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
463 {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
464 public:
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
465 // Constructors
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
466 Bitmap(const char *data, int len) { SetHWND(dw_bitmap_new(0)); dw_window_set_bitmap_from_data(hwnd, 0, data, len); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
467 Bitmap(const char *file) { SetHWND(dw_bitmap_new(0)); dw_window_set_bitmap(hwnd, 0, file); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
468 Bitmap(unsigned long id) { SetHWND(dw_bitmap_new(id)); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
469 Bitmap() { SetHWND(dw_bitmap_new(0)); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
470
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
471 // User functions
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
472 void Set(unsigned long id) { dw_window_set_bitmap(hwnd, id, DW_NULL); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
473 void Set(const char *file) { dw_window_set_bitmap(hwnd, 0, file); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
474 void Set(const char *data, int len) { dw_window_set_bitmap_from_data(hwnd, 0, data, len); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
475 };
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
476
2879
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
477 // Class for handing calendar widget
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
478 class Calendar : public Widget
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
479 {
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
480 public:
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
481 // Constructors
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
482 Calendar(unsigned long id) { SetHWND(dw_calendar_new(id)); }
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
483 Calendar() { SetHWND(dw_calendar_new(0)); }
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
484
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
485 // User functions
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
486 void GetData(unsigned int *year, unsigned int *month, unsigned int *day) { dw_calendar_get_date(hwnd, year, month, day); }
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
487 void SetData(unsigned int year, unsigned int month, unsigned int day) { dw_calendar_set_date(hwnd, year, month, day); }
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
488 };
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
489
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
490
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
491 // Abstract class that defines drawing, either to screen or picture (pixmap)
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
492 class Drawable
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
493 {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
494 public:
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
495 virtual void DrawPoint(int x, int y) = 0;
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
496 virtual void DrawLine(int x1, int y1, int x2, int y2) = 0;
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
497 virtual void DrawPolygon(int flags, int npoints, int x[], int y[]) = 0;
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
498 virtual void DrawRect(int fill, int x, int y, int width, int height) = 0;
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
499 virtual void DrawArc(int flags, int xorigin, int yorigin, int x1, int y1, int x2, int y2) = 0;
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
500 virtual void DrawText(int x, int y, const char *text) = 0;
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
501 virtual int BitBltStretch(int xdest, int ydest, int width, int height, Render *src, int xsrc, int ysrc, int srcwidth, int srcheight) = 0;
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
502 virtual int BitBltStretch(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc, int srcwidth, int srcheight) = 0;
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
503 virtual void BitBlt(int xdest, int ydest, int width, int height, Render *src, int xsrc, int ysrc) = 0;
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
504 virtual void BitBlt(int xdest, int ydest, int width, int height, Pixmap *srcp, int xsrc, int ysrc) = 0;
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
505 void SetColor(unsigned long fore, unsigned long back) { dw_color_foreground_set(fore); dw_color_background_set(back); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
506 void SetBackgroundColor(unsigned long back) { dw_color_background_set(back); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
507 void SetForegroundColor(unsigned long fore) { dw_color_foreground_set(fore); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
508 };
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
509
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
510 class Render : public Drawable, public Widget
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
511 {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
512 private:
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
513 bool ExposeConnected, ConfigureConnected;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
514 #ifdef DW_CPP11
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
515 std::function<int(DWExpose *)> _ConnectExpose;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
516 std::function<int(int, int)> _ConnectConfigure;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
517 #else
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
518 int (*_ConnectExpose)(DWExpose *);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
519 int (*_ConnectConfigure)(int width, int height);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
520 #endif
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
521 void Setup() {
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
522 if(IsOverridden(Render::OnExpose, this)) {
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
523 dw_signal_connect(hwnd, DW_SIGNAL_EXPOSE, DW_SIGNAL_FUNC(_OnExpose), this);
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
524 ExposeConnected = true;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
525 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
526 if(IsOverridden(Render::OnConfigure, this)) {
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
527 dw_signal_connect(hwnd, DW_SIGNAL_CONFIGURE, DW_SIGNAL_FUNC(_OnConfigure), this);
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
528 ConfigureConnected = true;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
529 }
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
530 }
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
531 static int _OnExpose(HWND window, DWExpose *exp, void *data) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
532 if(reinterpret_cast<Render *>(data)->_ConnectExpose)
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
533 return reinterpret_cast<Render *>(data)->_ConnectExpose(exp);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
534 return reinterpret_cast<Render *>(data)->OnExpose(exp); }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
535 static int _OnConfigure(HWND window, int width, int height, void *data) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
536 if(reinterpret_cast<Render *>(data)->_ConnectConfigure)
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
537 return reinterpret_cast<Render *>(data)->_ConnectConfigure(width, height);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
538 return reinterpret_cast<Render *>(data)->OnConfigure(width, height); }
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
539 public:
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
540 // Constructors
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
541 Render(unsigned long id) { SetHWND(dw_render_new(id)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
542 Render() { SetHWND(dw_render_new(0)); Setup(); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
543
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
544 // User functions
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
545 void DrawPoint(int x, int y) { dw_draw_point(hwnd, DW_NULL, x, y); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
546 void DrawLine(int x1, int y1, int x2, int y2) { dw_draw_line(hwnd, DW_NULL, x1, y1, x2, y2); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
547 void DrawPolygon(int flags, int npoints, int x[], int y[]) { dw_draw_polygon(hwnd, DW_NULL, flags, npoints, x, y); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
548 void DrawRect(int fill, int x, int y, int width, int height) { dw_draw_rect(hwnd, DW_NULL, fill, x, y, width, height); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
549 void DrawArc(int flags, int xorigin, int yorigin, int x1, int y1, int x2, int y2) { dw_draw_arc(hwnd, DW_NULL, flags, xorigin, yorigin, x1, y1, x2, y2); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
550 void DrawText(int x, int y, const char *text) { dw_draw_text(hwnd, DW_NULL, x, y, text); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
551 int BitBltStretch(int xdest, int ydest, int width, int height, Render *src, int xsrc, int ysrc, int srcwidth, int srcheight) {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
552 return dw_pixmap_stretch_bitblt(hwnd, DW_NULL, xdest, ydest, width, height, src ? src->GetHWND() : DW_NOHWND, DW_NULL, xsrc, ysrc, srcwidth, srcheight);
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
553 }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
554 int BitBltStretch(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc, int srcwidth, int srcheight);
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
555 void BitBlt(int xdest, int ydest, int width, int height, Render *src, int xsrc, int ysrc) {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
556 return dw_pixmap_bitblt(hwnd, DW_NULL, xdest, ydest, width, height, src ? src->GetHWND() : DW_NOHWND, DW_NULL, xsrc, ysrc);
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
557 }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
558 void BitBlt(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc);
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
559 int SetFont(const char *fontname) { return dw_window_set_font(hwnd, fontname); }
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
560 void GetTextExtents(const char *text, int *width, int *height) { dw_font_text_extents_get(hwnd, DW_NULL, text, width, height); }
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
561 char *GetFont() { return dw_window_get_font(hwnd); }
2878
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
562 void Redraw() { dw_render_redraw(hwnd); }
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
563 #ifdef DW_CPP11
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
564 void ConnectExpose(std::function<int(DWExpose *)> userfunc)
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
565 #else
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
566 void ConnectExpose(int (*userfunc)(DWExpose *))
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
567 #endif
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
568 {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
569 _ConnectExpose = userfunc;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
570 if(!ExposeConnected) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
571 dw_signal_connect(hwnd, DW_SIGNAL_EXPOSE, DW_SIGNAL_FUNC(_OnExpose), this);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
572 ExposeConnected = true;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
573 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
574 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
575 #ifdef DW_CPP11
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
576 void ConnectConfigure(std::function<int(int, int)> userfunc)
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
577 #else
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
578 void ConnectConfigure(int (*userfunc)(int, int))
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
579 #endif
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
580 {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
581 _ConnectConfigure = userfunc;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
582 if(!ConfigureConnected) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
583 dw_signal_connect(hwnd, DW_SIGNAL_CONFIGURE, DW_SIGNAL_FUNC(_OnConfigure), this);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
584 ConfigureConnected = true;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
585 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
586 }
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
587 protected:
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
588 // Our signal handler functions to be overriden...
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
589 // If they are not overridden and an event is generated, remove the unused handler
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
590 virtual int OnExpose(DWExpose *exp) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
591 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_EXPOSE);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
592 ExposeConnected = false;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
593 return FALSE;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
594 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
595 virtual int OnConfigure(int width, int height) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
596 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_CONFIGURE);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
597 ConfigureConnected = false;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
598 return FALSE;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
599 };
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
600 };
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
601
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
602 class Pixmap : public Drawable, public Handle
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
603 {
2877
6f31b7991fa0 C++: Fix Combobox class by making the parent classes virtual.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2876
diff changeset
604 private:
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
605 void SetHPIXMAP(HPIXMAP newpixmap) {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
606 hpixmap = newpixmap;
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
607 SetHandle(reinterpret_cast<void *>(newpixmap));
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
608 }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
609 HPIXMAP hpixmap;
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
610 public:
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
611 // Constructors
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
612 Pixmap(HWND window, unsigned long width, unsigned long height, int depth) { SetHPIXMAP(dw_pixmap_new(window, width, height, depth)); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
613 Pixmap(HWND window, unsigned long width, unsigned long height) { SetHPIXMAP(dw_pixmap_new(window, width, height, 32)); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
614
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
615 // User functions
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
616 HPIXMAP GetHPIXMAP() { return hpixmap; }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
617 void DrawPoint(int x, int y) { dw_draw_point(DW_NOHWND, hpixmap, x, y); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
618 void DrawLine(int x1, int y1, int x2, int y2) { dw_draw_line(DW_NOHWND, hpixmap, x1, y1, x2, y2); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
619 void DrawPolygon(int flags, int npoints, int x[], int y[]) { dw_draw_polygon(DW_NOHWND, hpixmap, flags, npoints, x, y); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
620 void DrawRect(int fill, int x, int y, int width, int height) { dw_draw_rect(DW_NOHWND, hpixmap, fill, x, y, width, height); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
621 void DrawArc(int flags, int xorigin, int yorigin, int x1, int y1, int x2, int y2) { dw_draw_arc(DW_NOHWND, hpixmap, flags, xorigin, yorigin, x1, y1, x2, y2); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
622 void DrawText(int x, int y, const char *text) { dw_draw_text(DW_NOHWND, hpixmap, x, y, text); }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
623 int BitBltStretch(int xdest, int ydest, int width, int height, Render *src, int xsrc, int ysrc, int srcwidth, int srcheight) {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
624 return dw_pixmap_stretch_bitblt(DW_NOHWND, hpixmap, xdest, ydest, width, height, src ? src->GetHWND() : DW_NOHWND, DW_NULL, xsrc, ysrc, srcwidth, srcheight);
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
625 }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
626 int BitBltStretch(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc, int srcwidth, int srcheight) {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
627 return dw_pixmap_stretch_bitblt(DW_NOHWND, hpixmap, xdest, ydest, width, height, DW_NOHWND, src ? src->GetHPIXMAP() : DW_NULL, xsrc, ysrc, srcwidth, srcheight);
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
628 }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
629 void BitBlt(int xdest, int ydest, int width, int height, Render *src, int xsrc, int ysrc) {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
630 dw_pixmap_bitblt(DW_NOHWND, hpixmap, xdest, ydest, width, height, src ? src->GetHWND() : DW_NOHWND, DW_NULL, xsrc, ysrc);
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
631 }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
632 void BitBlt(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc) {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
633 dw_pixmap_bitblt(DW_NOHWND, hpixmap, xdest, ydest, width, height, DW_NOHWND, src ? src->GetHPIXMAP() : DW_NULL, xsrc, ysrc);
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
634 }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
635 int SetFont(const char *fontname) { return dw_pixmap_set_font(hpixmap, fontname); }
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
636 void GetTextExtents(const char *text, int *width, int *height) { dw_font_text_extents_get(DW_NOHWND, hpixmap, text, width, height); }
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
637 };
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
638
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
639 // Need to declare these here after Pixmap is defined
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
640 int Render::BitBltStretch(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc, int srcwidth, int srcheight)
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
641 {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
642 return dw_pixmap_stretch_bitblt(hwnd, DW_NULL, xdest, ydest, width, height, DW_NOHWND, src ? src->GetHPIXMAP() : DW_NULL, xsrc, ysrc, srcwidth, srcheight);
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
643 }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
644
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
645 void Render::BitBlt(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc)
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
646 {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
647 dw_pixmap_bitblt(hwnd, DW_NULL, xdest, ydest, width, height, DW_NOHWND, src ? src->GetHPIXMAP() : DW_NULL, xsrc, ysrc);
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
648 }
2868
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
649
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
650 // Class for the HTML rendering widget
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
651 class HTML : public Widget
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
652 {
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
653 private:
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
654 bool ChangedConnected, ResultConnected;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
655 #ifdef DW_CPP11
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
656 std::function<int(int, char *)> _ConnectChanged;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
657 std::function<int(int, char *, void *)> _ConnectResult;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
658 #else
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
659 int (*_ConnectChanged)(int status, char *url);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
660 int (*_ConnectResult)(int status, char *result, void *scriptdata);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
661 #endif
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
662 void Setup() {
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
663 if(IsOverridden(HTML::OnChanged, this)) {
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
664 dw_signal_connect(hwnd, DW_SIGNAL_HTML_CHANGED, DW_SIGNAL_FUNC(_OnChanged), this);
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
665 ChangedConnected = true;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
666 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
667 if(IsOverridden(HTML::OnResult, this)) {
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
668 dw_signal_connect(hwnd, DW_SIGNAL_HTML_CHANGED, DW_SIGNAL_FUNC(_OnResult), this);
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
669 ResultConnected = true;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
670 }
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
671 }
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
672 static int _OnChanged(HWND window, int status, char *url, void *data) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
673 if(reinterpret_cast<HTML *>(data)->_ConnectChanged)
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
674 return reinterpret_cast<HTML *>(data)->_ConnectChanged(status, url);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
675 return reinterpret_cast<HTML *>(data)->OnChanged(status, url); }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
676 static int _OnResult(HWND window, int status, char *result, void *scriptdata, void *data) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
677 if(reinterpret_cast<HTML *>(data)->_ConnectResult)
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
678 return reinterpret_cast<HTML *>(data)->_ConnectResult(status, result, scriptdata);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
679 return reinterpret_cast<HTML *>(data)->OnResult(status, result, scriptdata); }
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
680 public:
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
681 // Constructors
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
682 HTML(unsigned long id) { SetHWND(dw_html_new(id)); Setup(); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
683 HTML() { SetHWND(dw_html_new(0)); Setup(); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
684
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
685 // User functions
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
686 void Action(int action) { dw_html_action(hwnd, action); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
687 int JavascriptRun(const char *script, void *scriptdata) { return dw_html_javascript_run(hwnd, script, scriptdata); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
688 int Raw(const char *buffer) { return dw_html_raw(hwnd, buffer); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
689 int URL(const char *url) { return dw_html_url(hwnd, url); }
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
690 #ifdef DW_CPP11
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
691 void ConnectChanged(std::function<int(int, char *)> userfunc)
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
692 #else
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
693 void ConnectChanged(int (*userfunc)(int, char *))
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
694 #endif
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
695 {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
696 _ConnectChanged = userfunc;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
697 if(!ChangedConnected) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
698 dw_signal_connect(hwnd, DW_SIGNAL_HTML_CHANGED, DW_SIGNAL_FUNC(_OnChanged), this);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
699 ChangedConnected = true;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
700 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
701 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
702 #ifdef DW_CPP11
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
703 void ConnectResult(std::function<int(int, char *, void *)> userfunc)
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
704 #else
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
705 void ConnectResult(int (*userfunc)(int, char *, void *))
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
706 #endif
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
707 {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
708 _ConnectResult = userfunc;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
709 if(!ResultConnected) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
710 dw_signal_connect(hwnd, DW_SIGNAL_HTML_CHANGED, DW_SIGNAL_FUNC(_OnResult), this);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
711 ResultConnected = true;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
712 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
713 }
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
714 protected:
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
715 // Our signal handler functions to be overriden...
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
716 // If they are not overridden and an event is generated, remove the unused handler
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
717 virtual int OnChanged(int status, char *url) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
718 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_HTML_CHANGED);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
719 ChangedConnected = false;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
720 return FALSE;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
721 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
722 virtual int OnResult(int status, char *result, void *scriptdata) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
723 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_HTML_RESULT);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
724 ResultConnected = false;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
725 return FALSE;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
726 };
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
727 };
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
728
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
729 // Base class for several widgets that allow text entry
2878
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
730 class TextEntry : virtual public Focusable, virtual public TextWidget
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
731 {
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
732 public:
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
733 // User functions
2879
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
734 void ClickDefault(Focusable *next) { if(next) dw_window_click_default(hwnd, next->GetHWND()); }
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
735 };
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
736
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
737 class Entryfield : public TextEntry
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
738 {
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
739 public:
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
740 // Constructors
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
741 Entryfield(const char *text, unsigned long id) { SetHWND(dw_entryfield_new(text, id)); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
742 Entryfield(unsigned long id) { SetHWND(dw_entryfield_new("", id)); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
743 Entryfield(const char *text) { SetHWND(dw_entryfield_new(text, 0)); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
744 Entryfield() { SetHWND(dw_entryfield_new("", 0)); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
745 };
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
746
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
747 class EntryfieldPassword : public TextEntry
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
748 {
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
749 public:
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
750 // Constructors
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
751 EntryfieldPassword(const char *text, unsigned long id) { SetHWND(dw_entryfield_password_new(text, id)); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
752 EntryfieldPassword(unsigned long id) { SetHWND(dw_entryfield_password_new("", id)); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
753 EntryfieldPassword(const char *text) { SetHWND(dw_entryfield_password_new(text, 0)); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
754 EntryfieldPassword() { SetHWND(dw_entryfield_password_new("", 0)); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
755 };
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
756
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
757 // Base class for several widgets that have a list of elements
2878
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
758 class ListBoxes : virtual public Focusable
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
759 {
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
760 private:
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
761 bool ListSelectConnected;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
762 #ifdef DW_CPP11
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
763 std::function<int(int)> _ConnectListSelect;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
764 #else
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
765 int (*_ConnectListSelect)(int index);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
766 #endif
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
767 void Setup() {
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
768 if(IsOverridden(ListBoxes::OnListSelect, this)) {
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
769 dw_signal_connect(hwnd, DW_SIGNAL_LIST_SELECT, DW_SIGNAL_FUNC(_OnListSelect), this);
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
770 ListSelectConnected = true;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
771 }
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
772 }
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
773 static int _OnListSelect(HWND window, int index, void *data) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
774 if(reinterpret_cast<ListBoxes *>(data)->_ConnectListSelect)
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
775 return reinterpret_cast<ListBoxes *>(data)->_ConnectListSelect(index);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
776 return reinterpret_cast<ListBoxes *>(data)->OnListSelect(index);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
777 }
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
778 public:
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
779 // User functions
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
780 void Append(const char *text) { dw_listbox_append(hwnd, text); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
781 void Clear() { dw_listbox_clear(hwnd); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
782 int Count() { return dw_listbox_count(hwnd); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
783 void Delete(int index) { dw_listbox_delete(hwnd, index); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
784 void GetText(unsigned int index, char *buffer, unsigned int length) { dw_listbox_get_text(hwnd, index, buffer, length); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
785 void SetText(unsigned int index, char *buffer) { dw_listbox_set_text(hwnd, index, buffer); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
786 void Insert(const char *text, int pos) { dw_listbox_insert(hwnd, text, pos); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
787 void ListAppend(char **text, int count) { dw_listbox_list_append(hwnd, text, count); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
788 void Select(int index, int state) { dw_listbox_select(hwnd, index, state); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
789 int Selected() { return dw_listbox_selected(hwnd); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
790 int Selected(int where) { return dw_listbox_selected_multi(hwnd, where); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
791 void SetTop(int top) { dw_listbox_set_top(hwnd, top); }
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
792 #ifdef DW_CPP11
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
793 void ConnectListSelect(std::function<int(int)> userfunc)
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
794 #else
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
795 void ConnectListSelect(int (*userfunc)(int))
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
796 #endif
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
797 {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
798 _ConnectListSelect = userfunc;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
799 if(!ListSelectConnected) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
800 dw_signal_connect(hwnd, DW_SIGNAL_LIST_SELECT, DW_SIGNAL_FUNC(_OnListSelect), this);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
801 ListSelectConnected = true;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
802 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
803 }
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
804 protected:
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
805 // Our signal handler functions to be overriden...
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
806 // If they are not overridden and an event is generated, remove the unused handler
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
807 virtual int OnListSelect(int index) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
808 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_LIST_SELECT);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
809 ListSelectConnected = false;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
810 return FALSE;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
811 }
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
812 };
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
813
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
814 class Combobox : public TextEntry, public ListBoxes
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
815 {
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
816 public:
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
817 // Constructors
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
818 Combobox(const char *text, unsigned long id) { SetHWND(dw_combobox_new(text, id)); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
819 Combobox(unsigned long id) { SetHWND(dw_combobox_new("", id)); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
820 Combobox(const char *text) { SetHWND(dw_combobox_new(text, 0)); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
821 Combobox() { SetHWND(dw_combobox_new("", 0)); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
822 };
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
823
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
824 class Listbox : public ListBoxes
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
825 {
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
826 public:
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
827 // Constructors
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
828 Listbox(unsigned long id, int multi) { SetHWND(dw_listbox_new(id, multi)); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
829 Listbox(unsigned long id) { SetHWND(dw_listbox_new(id, FALSE)); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
830 Listbox(int multi) { SetHWND(dw_listbox_new(0, multi)); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
831 Listbox() { SetHWND(dw_listbox_new(0, FALSE)); }
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
832 };
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
833
2880
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
834 // Base class for several ranged type widgets
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
835 class Ranged : virtual public Widget
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
836 {
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
837 private:
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
838 bool ValueChangedConnected;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
839 #ifdef DW_CPP11
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
840 std::function<int(int)> _ConnectValueChanged;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
841 #else
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
842 int (*_ConnectValueChanged)(int value);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
843 #endif
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
844 static int _OnValueChanged(HWND window, int value, void *data) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
845 if(reinterpret_cast<Ranged *>(data)->_ConnectValueChanged)
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
846 return reinterpret_cast<Ranged *>(data)->_ConnectValueChanged(value);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
847 return reinterpret_cast<Ranged *>(data)->OnValueChanged(value);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
848 }
2880
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
849 protected:
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
850 void Setup() {
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
851 if(IsOverridden(Ranged::OnValueChanged, this)) {
2880
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
852 dw_signal_connect(hwnd, DW_SIGNAL_VALUE_CHANGED, DW_SIGNAL_FUNC(_OnValueChanged), this);
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
853 ValueChangedConnected = true;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
854 }
2880
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
855 }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
856 // Our signal handler functions to be overriden...
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
857 // If they are not overridden and an event is generated, remove the unused handler
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
858 virtual int OnValueChanged(int value) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
859 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_VALUE_CHANGED);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
860 ValueChangedConnected = false;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
861 return FALSE;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
862 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
863 public:
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
864 #ifdef DW_CPP11
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
865 void ConnectValueChanged(std::function<int(int)> userfunc)
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
866 #else
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
867 void ConnectValueChanged(int (*userfunc)(int))
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
868 #endif
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
869 {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
870 _ConnectValueChanged = userfunc;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
871 if(!ValueChangedConnected) {
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
872 dw_signal_connect(hwnd, DW_SIGNAL_VALUE_CHANGED, DW_SIGNAL_FUNC(_OnValueChanged), this);
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
873 ValueChangedConnected = true;
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
874 }
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
875 }
2880
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
876 };
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
877
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
878 class Slider : public Ranged
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
879 {
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
880 public:
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
881 // Constructors
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
882 Slider(int orient, int increments, unsigned long id) { SetHWND(dw_slider_new(orient, increments, id)); Setup(); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
883 Slider(int orient, int increments) { SetHWND(dw_slider_new(orient, increments, 0)); Setup(); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
884
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
885 // User functions
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
886 unsigned int GetPos() { return dw_slider_get_pos(hwnd); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
887 void SetPos(unsigned int position) { dw_slider_set_pos(hwnd, position); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
888 };
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
889
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
890 class Scrollbar : public Ranged
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
891 {
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
892 public:
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
893 // Constructors
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
894 Scrollbar(int orient, unsigned long id) { SetHWND(dw_scrollbar_new(orient, id)); Setup(); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
895 Scrollbar(int orient) { SetHWND(dw_scrollbar_new(orient, 0)); Setup(); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
896
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
897 // User functions
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
898 unsigned int GetPos() { return dw_scrollbar_get_pos(hwnd); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
899 void SetPos(unsigned int position) { dw_scrollbar_set_pos(hwnd, position); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
900 void SetRange(unsigned int range, unsigned int visible) { dw_scrollbar_set_range(hwnd, range, visible); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
901 };
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
902
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
903 class SpinButton : public Ranged, public TextEntry
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
904 {
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
905 public:
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
906 // Constructors
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
907 SpinButton(const char *text, unsigned long id) { SetHWND(dw_spinbutton_new(text, id)); Setup(); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
908 SpinButton(unsigned long id) { SetHWND(dw_spinbutton_new("", id)); Setup(); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
909 SpinButton(const char *text) { SetHWND(dw_spinbutton_new(text, 0)); Setup(); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
910 SpinButton() { SetHWND(dw_spinbutton_new("", 0)); Setup(); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
911
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
912 // User functions
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
913 long GetPos() { return dw_spinbutton_get_pos(hwnd); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
914 void SetPos(long position) { dw_spinbutton_set_pos(hwnd, position); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
915 void SetLimits(long upper, long lower) { dw_spinbutton_set_limits(hwnd, upper, lower); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
916 };
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
917
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
918 // Multi-line Edit widget
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
919 class MLE : public Focusable
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
920 {
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
921 public:
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
922 // Constructors
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
923 MLE(unsigned long id) { SetHWND(dw_mle_new(id)); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
924 MLE() { SetHWND(dw_mle_new(0)); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
925
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
926 // User functions
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
927 void Freeze() { dw_mle_freeze(hwnd); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
928 void Thaw() { dw_mle_thaw(hwnd); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
929 void Clear() { dw_mle_clear(hwnd); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
930 void Delete(int startpoint, int length) { dw_mle_delete(hwnd, startpoint, length); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
931 void Export(char *buffer, int startpoint, int length) { dw_mle_export(hwnd, buffer, startpoint, length); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
932 void Import(const char *buffer, int startpoint) { dw_mle_import(hwnd, buffer, startpoint); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
933 void GetSize(unsigned long *bytes, unsigned long *lines) { dw_mle_get_size(hwnd, bytes, lines); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
934 void Search(const char *text, int point, unsigned long flags) { dw_mle_search(hwnd, text, point, flags); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
935 void SetAutoComplete(int state) { dw_mle_set_auto_complete(hwnd, state); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
936 void SetCursor(int point) { dw_mle_set_cursor(hwnd, point); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
937 void SetEditable(int state) { dw_mle_set_editable(hwnd, state); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
938 void SetVisible(int line) { dw_mle_set_visible(hwnd, line); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
939 void SetWordWrap(int state) { dw_mle_set_word_wrap(hwnd, state); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
940 };
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
941
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
942 class App
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
943 {
2866
6ea67d0809eb Convert DW::App class into a singleton so subsequent DW::App::Init() calls
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2865
diff changeset
944 protected:
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
945 App() { }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
946 static App *_app;
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
947 public:
2870
7b4e30c19757 C++: Disable singleton safety code for non C++11 compilers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2869
diff changeset
948 // Allow the code to compile if handicapped on older compilers
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
949 #ifdef DW_CPP11
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
950 // Singletons should not be cloneable.
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
951 App(App &other) = delete;
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
952 // Singletons should not be assignable.
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
953 void operator=(const App &) = delete;
2870
7b4e30c19757 C++: Disable singleton safety code for non C++11 compilers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2869
diff changeset
954 #endif
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
955 // Initialization functions for creating App
2872
e62fc9b3b09c C++: Add DW_NULL which is nullptr on C++11 and NULL on older versions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2871
diff changeset
956 static App *Init() { if(!_app) { _app = new App; dw_init(TRUE, 0, DW_NULL); } return _app; }
e62fc9b3b09c C++: Add DW_NULL which is nullptr on C++11 and NULL on older versions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2871
diff changeset
957 static App *Init(const char *appid) { if(!_app) { _app = new App(); dw_app_id_set(appid, DW_NULL); dw_init(TRUE, 0, DW_NULL); } return _app; }
e62fc9b3b09c C++: Add DW_NULL which is nullptr on C++11 and NULL on older versions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2871
diff changeset
958 static App *Init(const char *appid, const char *appname) { if(!_app) { _app = new App(); dw_app_id_set(appid, appname); dw_init(TRUE, 0, DW_NULL); } return _app; }
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
959 static App *Init(int argc, char *argv[]) { if(!_app) { _app = new App(); dw_init(TRUE, argc, argv); } return _app; }
2872
e62fc9b3b09c C++: Add DW_NULL which is nullptr on C++11 and NULL on older versions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2871
diff changeset
960 static App *Init(int argc, char *argv[], const char *appid) { if(!_app) { _app = new App(); dw_app_id_set(appid, DW_NULL); dw_init(TRUE, argc, argv); } return _app; }
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
961 static App *Init(int argc, char *argv[], const char *appid, const char *appname) { if(!_app) { _app = new App(); dw_app_id_set(appid, appname); dw_init(TRUE, argc, argv); } return _app; }
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
962
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
963 // User functions
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
964 void Main() { dw_main(); }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
965 void MainIteration() { dw_main_iteration(); }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
966 void MainQuit() { dw_main_quit(); }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
967 void Exit(int exitcode) { dw_exit(exitcode); }
2882
99311a9091af C++: Add lambda support via Connect functions on C++11, on older compilers
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2880
diff changeset
968 int MessageBox(const char *title, int flags, const char *format) { return dw_messagebox(title, flags, format); }
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
969 };
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
970
2866
6ea67d0809eb Convert DW::App class into a singleton so subsequent DW::App::Init() calls
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2865
diff changeset
971 // Static singleton reference declared outside of the class
2872
e62fc9b3b09c C++: Add DW_NULL which is nullptr on C++11 and NULL on older versions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2871
diff changeset
972 App* App::_app = DW_NULL;
2866
6ea67d0809eb Convert DW::App class into a singleton so subsequent DW::App::Init() calls
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2865
diff changeset
973
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
974 } /* namespace DW */
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
975 #endif