annotate dw.hpp @ 2885:df1b7f7d1703

C++: Finish up the menu classes, not sure if this is ideal yet.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 22 Dec 2022 18:10:43 +0000
parents 06e475feaac0
children 4b075e64536c
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; }
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
170 MenuItem *MenuItemNew(const char *title, unsigned long id, unsigned long flags, int end, int check, Menus *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
171 MenuItem *MenuItemNew(const char *title, Menus *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
172 MenuItem *MenuItemNew(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) {
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
202 SetHWND(dw_menu_append_item(menu->GetHMENUI(), title, DW_MENU_AUTO, 0, TRUE, FALSE, 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
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
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
213 MenuItem *Menus::MenuItemNew(const char *title, unsigned long id, unsigned long flags, int end, int check, Menus *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
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
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
217 MenuItem *Menus::MenuItemNew(const char *title, Menus *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
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 }
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
220 MenuItem *Menus::MenuItemNew(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
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); }
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
279 Menus *MenuBarNew() { if(!menu) menu = new MenuBar(hwnd); return 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
280 void Popup(Menus *menu, 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
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 }
df1b7f7d1703 C++: Finish up the menu classes, not sure if this is ideal yet.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2884
diff changeset
288 void Popup(Menus *menu) { 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
289 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
290 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
291
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 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
293 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
294 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
295 }
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 }
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
297 #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
298 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
299 #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
300 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
301 #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
302 {
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 _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
304 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
305 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
306 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
307 }
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 #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
310 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
311 #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
312 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
313 #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
314 {
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 _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
316 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
317 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
318 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
319 }
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 }
2868
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
321 protected:
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
322 // 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
323 // 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
324 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
325 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
326 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
327 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
328 }
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 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
330 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
331 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
332 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
333 };
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
334 };
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
335
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
336 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
337 {
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 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
339 {
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 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
341
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 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
343 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
344 }
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 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
348 {
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 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
350 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
351 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
352
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 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
354 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
355 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
356 }
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
2878
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
359 // Class for focusable widgets
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
360 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
361 {
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
362 public:
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
363 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
364 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
365 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
366 };
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
367
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
368 // 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
369 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
370 {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
371 public:
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
372 // User functions
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
373 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
374 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
375 };
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 class Button : public TextButton
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
378 {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
379 public:
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
380 // Constructors
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
381 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
382 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
383 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
384 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
385 };
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 // 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
388 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
389 {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
390 public:
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
391 // Constructors
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
392 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
393 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
394 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
395 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
396 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
397 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
398 };
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
399
2877
6f31b7991fa0 C++: Fix Combobox class by making the parent classes virtual.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2876
diff changeset
400 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
401 {
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
402 public:
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
403 // User functions
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
404 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
405 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
406 };
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 class CheckBox : public CheckBoxes
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
409 {
2877
6f31b7991fa0 C++: Fix Combobox class by making the parent classes virtual.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2876
diff changeset
410 public:
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
411 // Constructors
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
412 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
413 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
414 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
415 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
416 };
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 class RadioButton : public CheckBoxes
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
419 {
2877
6f31b7991fa0 C++: Fix Combobox class by making the parent classes virtual.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2876
diff changeset
420 public:
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
421 // Constructors
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
422 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
423 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
424 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
425 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
426 };
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
427
2868
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
428 // 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
429 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
430 {
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
431 public:
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
432 // User functions
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
433 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
434 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
435 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
436 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
437 };
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 // 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
440 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
441 {
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
442 public:
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
443 // Constructors
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
444 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
445 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
446 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
447 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
448 };
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
449
2878
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
450 class StatusText : public TextWidget
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
451 {
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
452 public:
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
453 // Constructors
a290573a8b7c C++: Implement StatusText class, reorganize Text widgets to eliminate
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2877
diff changeset
454 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
455 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
456 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
457 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
458 };
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
459
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
460 // 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
461 class Bitmap : public Widget
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
462 {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
463 public:
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
464 // Constructors
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
465 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
466 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
467 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
468 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
469
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
470 // User functions
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
471 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
472 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
473 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
474 };
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
475
2879
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
476 // 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
477 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
478 {
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
479 public:
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
480 // Constructors
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
481 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
482 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
483
ec7f6e28166d C++: Add Calendar widget and fix an issue in that last commit.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2878
diff changeset
484 // 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
485 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
486 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
487 };
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
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
490 // 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
491 class Drawable
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
492 {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
493 public:
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
494 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
495 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
496 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
497 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
498 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
499 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
500 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
501 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
502 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
503 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
504 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
505 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
506 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
507 };
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 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
510 {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
511 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
512 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
513 #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
514 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
515 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
516 #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
517 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
518 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
519 #endif
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
520 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
521 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
522 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
523 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
524 }
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 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
526 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
527 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
528 }
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
529 }
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
530 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
531 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
532 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
533 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
534 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
535 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
536 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
537 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
538 public:
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
539 // Constructors
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
540 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
541 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
542
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
543 // User functions
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
544 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
545 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
546 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
547 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
548 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
549 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
550 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
551 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
552 }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
553 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
554 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
555 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
556 }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
557 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
558 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
559 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
560 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
561 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
562 #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
563 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
564 #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
565 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
566 #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
567 {
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 _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
569 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
570 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
571 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
572 }
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 #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
575 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
576 #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
577 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
578 #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
579 {
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 _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
581 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
582 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
583 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
584 }
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 }
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
586 protected:
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
587 // 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
588 // 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
589 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
590 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
591 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
592 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
593 }
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 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
595 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
596 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
597 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
598 };
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
599 };
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 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
602 {
2877
6f31b7991fa0 C++: Fix Combobox class by making the parent classes virtual.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2876
diff changeset
603 private:
2874
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
604 void SetHPIXMAP(HPIXMAP newpixmap) {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
605 hpixmap = newpixmap;
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
606 SetHandle(reinterpret_cast<void *>(newpixmap));
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
607 }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
608 HPIXMAP hpixmap;
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
609 public:
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
610 // Constructors
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
611 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
612 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
613
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
614 // User functions
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
615 HPIXMAP GetHPIXMAP() { return hpixmap; }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
616 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
617 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
618 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
619 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
620 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
621 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
622 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
623 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
624 }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
625 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
626 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
627 }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
628 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
629 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
630 }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
631 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
632 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
633 }
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
634 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
635 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
636 };
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 // 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
639 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
640 {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
641 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
642 }
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 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
645 {
585d0053b766 C++: Implement buttons, images, render, pixmap and boxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2873
diff changeset
646 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
647 }
2868
5ee1aaa48fc7 C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2867
diff changeset
648
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
649 // 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
650 class HTML : public Widget
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
651 {
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
652 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
653 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
654 #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
655 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
656 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
657 #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
658 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
659 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
660 #endif
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
661 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
662 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
663 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
664 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
665 }
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 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
667 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
668 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
669 }
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
670 }
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
671 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
672 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
673 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
674 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
675 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
676 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
677 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
678 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
679 public:
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
680 // Constructors
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
681 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
682 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
683
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
684 // User functions
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
685 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
686 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
687 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
688 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
689 #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
690 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
691 #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
692 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
693 #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
694 {
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 _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
696 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
697 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
698 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
699 }
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 #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
702 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
703 #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
704 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
705 #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
706 {
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 _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
708 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
709 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
710 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
711 }
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 }
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
713 protected:
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
714 // 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
715 // 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
716 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
717 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
718 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
719 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
720 }
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 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
722 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
723 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
724 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
725 };
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
726 };
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 // 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
729 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
730 {
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
731 public:
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
732 // 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
733 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
734 };
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 class Entryfield : public TextEntry
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
737 {
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
738 public:
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
739 // Constructors
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
740 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
741 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
742 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
743 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
744 };
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 class EntryfieldPassword : public TextEntry
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
747 {
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
748 public:
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
749 // Constructors
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
750 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
751 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
752 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
753 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
754 };
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 // 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
757 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
758 {
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
759 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
760 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
761 #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
762 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
763 #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
764 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
765 #endif
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
766 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
767 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
768 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
769 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
770 }
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
771 }
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
772 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
773 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
774 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
775 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
776 }
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
777 public:
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
778 // User functions
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
779 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
780 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
781 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
782 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
783 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
784 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
785 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
786 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
787 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
788 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
789 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
790 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
791 #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
792 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
793 #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
794 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
795 #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
796 {
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 _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
798 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
799 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
800 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
801 }
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 }
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
803 protected:
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
804 // 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
805 // 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
806 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
807 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
808 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
809 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
810 }
2876
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
811 };
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 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
814 {
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
815 public:
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
816 // Constructors
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
817 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
818 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
819 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
820 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
821 };
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 class Listbox : public ListBoxes
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
824 {
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
825 public:
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
826 // Constructors
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
827 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
828 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
829 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
830 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
831 };
e201a984d855 C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2874
diff changeset
832
2880
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
833 // 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
834 class Ranged : virtual public Widget
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
835 {
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
836 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
837 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
838 #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
839 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
840 #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
841 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
842 #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
843 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
844 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
845 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
846 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
847 }
2880
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
848 protected:
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
849 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
850 if(IsOverridden(Ranged::OnValueChanged, this)) {
2880
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
851 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
852 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
853 }
2880
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
854 }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
855 // 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
856 // 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
857 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
858 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
859 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
860 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
861 }
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 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
863 #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
864 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
865 #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
866 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
867 #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
868 {
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 _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
870 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
871 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
872 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
873 }
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 }
2880
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
875 };
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 class Slider : public Ranged
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
878 {
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
879 public:
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
880 // Constructors
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
881 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
882 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
883
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
884 // User functions
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
885 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
886 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
887 };
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 class Scrollbar : public Ranged
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
890 {
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
891 public:
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
892 // Constructors
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
893 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
894 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
895
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
896 // User functions
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
897 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
898 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
899 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
900 };
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 class SpinButton : public Ranged, public TextEntry
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
903 {
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
904 public:
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
905 // Constructors
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
906 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
907 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
908 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
909 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
910
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
911 // User functions
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
912 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
913 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
914 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
915 };
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 // Multi-line Edit widget
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
918 class MLE : public Focusable
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
919 {
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
920 public:
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
921 // Constructors
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
922 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
923 MLE() { SetHWND(dw_mle_new(0)); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
924
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
925 // User functions
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
926 void Freeze() { dw_mle_freeze(hwnd); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
927 void Thaw() { dw_mle_thaw(hwnd); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
928 void Clear() { dw_mle_clear(hwnd); }
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
929 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
930 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
931 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
932 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
933 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
934 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
935 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
936 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
937 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
938 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
939 };
2ba0959eb3cf C++: Implement Slider, Scrollbar, SpinButton, and MLE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2879
diff changeset
940
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
941 class App
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
942 {
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
943 protected:
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
944 App() { }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
945 static App *_app;
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
946 public:
2870
7b4e30c19757 C++: Disable singleton safety code for non C++11 compilers.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2869
diff changeset
947 // 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
948 #ifdef DW_CPP11
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
949 // 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
950 App(App &other) = delete;
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
951 // 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
952 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
953 #endif
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
954 // 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
955 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
956 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
957 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
958 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
959 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
960 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
961
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
962 // User functions
2869
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
963 void Main() { dw_main(); }
c873b6f862b9 C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2868
diff changeset
964 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
965 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
966 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
967 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
968 };
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
969
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
970 // 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
971 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
972
2861
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
973 } /* namespace DW */
ef7a414f9b71 Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
974 #endif