Mercurial > dwindows
annotate dw.hpp @ 2869:c873b6f862b9
C++: Add text widget and packing to the window.
Also reformat both files using spaces instead of tabs.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 18 Dec 2022 12:13:46 +0000 |
parents | 5ee1aaa48fc7 |
children | 7b4e30c19757 |
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 |
2867
ada74f4d3f39
C++: Implement conditional signal handlers based on overrides.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2866
diff
changeset
|
3 * Requires 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 |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
10 namespace DW |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
11 { |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
12 |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
13 // 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
|
14 // The base system handles |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
15 class Handle |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
16 { |
2868
5ee1aaa48fc7
C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2867
diff
changeset
|
17 protected: |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
18 void *handle; |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
19 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
|
20 public: |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
21 void *GetHandle() { return handle; } |
2861
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
22 }; |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
23 |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
24 // Widget class allows packing and style |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
25 class Widget : public Handle |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
26 { |
2868
5ee1aaa48fc7
C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2867
diff
changeset
|
27 protected: |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
28 void SetHWND(HWND newhwnd) { |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
29 hwnd = newhwnd; |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
30 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
|
31 // 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
|
32 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
|
33 } |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
34 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
|
35 public: |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
36 HWND GetHWND() { return hwnd; } |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
37 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
|
38 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
|
39 void SetTooltip(char *bubbletext) { dw_window_set_tooltip(hwnd, bubbletext); } |
2861
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
40 }; |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
41 |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
42 // Box class is a packable object |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
43 class Box : public Widget |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
44 { |
2868
5ee1aaa48fc7
C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2867
diff
changeset
|
45 public: |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
46 void PackStart(Widget *item, int width, int height, int hsize, int vsize, int pad) { |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
47 dw_box_pack_start(hwnd, item ? item->GetHWND() : nullptr, width, height, hsize, vsize, pad); } |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
48 void PackEnd(Widget *item, int width, int height, int hsize, int vsize, int pad) { |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
49 dw_box_pack_end(hwnd, item ? item->GetHWND() : nullptr, width, height, hsize, vsize, pad); } |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
50 void PackAtIndex(Widget *item, int index, int width, int height, int hsize, int vsize, int pad) { |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
51 dw_box_pack_at_index(hwnd, item ? item->GetHWND() : nullptr, index, width, height, hsize, vsize, pad); } |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
52 Widget *UnpackAtIndex(int index) { HWND widget = dw_box_unpack_at_index(hwnd, index); |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
53 void *classptr = widget ? dw_window_get_data(widget, "_dw_classptr") : nullptr; |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
54 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
|
55 } |
2861
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
56 }; |
2868
5ee1aaa48fc7
C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2867
diff
changeset
|
57 |
5ee1aaa48fc7
C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2867
diff
changeset
|
58 // 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
|
59 // 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
|
60 #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
|
61 |
2861
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
62 // Top-level window class is packable |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
63 class Window : public Box |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
64 { |
2865
fd32dce7fecd
Initial signal handler support for the C++ bindings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2861
diff
changeset
|
65 private: |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
66 void Setup() { |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
67 if(IsOverridden(Window::OnConfigure, this)) |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
68 dw_signal_connect(hwnd, DW_SIGNAL_DELETE, DW_SIGNAL_FUNC(_OnDelete), this); |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
69 if(IsOverridden(Window::OnConfigure, this)) |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
70 dw_signal_connect(hwnd, DW_SIGNAL_CONFIGURE, DW_SIGNAL_FUNC(_OnConfigure), this); |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
71 } |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
72 static int _OnDelete(HWND window, void *data) { return reinterpret_cast<Window *>(data)->OnDelete(); } |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
73 static int _OnConfigure(HWND window, int width, int height, void *data) { return reinterpret_cast<Window *>(data)->OnConfigure(width, height); } |
2861
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
74 public: |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
75 // Constructors |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
84 // User functions |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
85 void SetText(const char *text) { dw_window_set_text(hwnd, text); } |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 int Lower() { return dw_window_lower(hwnd); } |
2868
5ee1aaa48fc7
C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2867
diff
changeset
|
93 protected: |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
94 // 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
|
95 // If they are not overridden and an event is generated, remove the unused handler |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
96 virtual int OnDelete() { dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_DELETE); return FALSE; } |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
97 virtual int OnConfigure(int width, int height) { dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_CONFIGURE); return FALSE; }; |
2861
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
98 }; |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
99 |
2868
5ee1aaa48fc7
C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2867
diff
changeset
|
100 // Class for handling static text widget |
5ee1aaa48fc7
C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2867
diff
changeset
|
101 class Text : public Widget |
5ee1aaa48fc7
C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2867
diff
changeset
|
102 { |
5ee1aaa48fc7
C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2867
diff
changeset
|
103 public: |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
104 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
|
105 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
|
106 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
|
107 Text() { SetHWND(dw_text_new("", 0)); } |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
108 void SetText(const char *text) { dw_window_set_text(hwnd, text); } |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
109 int SetFont(const char *font) { return dw_window_set_font(hwnd, font); } |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
110 char *GetFont() { return dw_window_get_font(hwnd); } |
2868
5ee1aaa48fc7
C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2867
diff
changeset
|
111 }; |
5ee1aaa48fc7
C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2867
diff
changeset
|
112 |
5ee1aaa48fc7
C++: The last signal handler change only worked with Clang/LLVM.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2867
diff
changeset
|
113 |
2861
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
114 class App |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
115 { |
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
|
116 protected: |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
117 App() { } |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
118 static App *_app; |
2861
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
119 public: |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
120 // 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
|
121 App(App &other) = delete; |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
122 // 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
|
123 void operator=(const App &) = delete; |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
124 // Initialization functions for creating App |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
125 static App *Init() { if(!_app) { _app = new App; dw_init(TRUE, 0, NULL); } return _app; } |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
126 static App *Init(const char *appid) { if(!_app) { _app = new App(); dw_app_id_set(appid, NULL); dw_init(TRUE, 0, NULL); } return _app; } |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
127 static App *Init(const char *appid, const char *appname) { if(!_app) { _app = new App(); dw_app_id_set(appid, appname); dw_init(TRUE, 0, NULL); } return _app; } |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
128 static App *Init(int argc, char *argv[]) { if(!_app) { _app = new App(); dw_init(TRUE, argc, argv); } return _app; } |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
129 static App *Init(int argc, char *argv[], const char *appid) { if(!_app) { _app = new App(); dw_app_id_set(appid, NULL); dw_init(TRUE, argc, argv); } return _app; } |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
130 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
|
131 |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
132 void Main() { dw_main(); } |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
133 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
|
134 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
|
135 void Exit(int exitcode) { dw_exit(exitcode); } |
2861
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
136 }; |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
137 |
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
|
138 // Static singleton reference declared outside of the class |
6ea67d0809eb
Convert DW::App class into a singleton so subsequent DW::App::Init() calls
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2865
diff
changeset
|
139 App* App::_app = nullptr; |
6ea67d0809eb
Convert DW::App class into a singleton so subsequent DW::App::Init() calls
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2865
diff
changeset
|
140 |
2861
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
141 #if 0 |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
142 // Class that allows drawing, either to screen or picture (pixmap) |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
143 class Drawable |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
144 { |
2869
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
145 void DrawPoint(int x, int y); |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
146 void DrawLine(int x1, int y1, int x2, int y2); |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
147 void DrawPolygon(int flags, int x[], int y[]); |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
148 void DrawRect(int fill, int x, int y, int width, int height); |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
149 void DrawArc(int flags, int xorigin, int yorigin, int x1, int y1, int x2, int y2); |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
150 void DrawText(int x, int y, std::string text); |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
151 int BitBltStretch(int xdest, int ydest, int width, int height, HWND src, int xsrc, int ysrc, int srcwidth, int srcheight); |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
152 int BitBltStretch(int xdest, int ydest, int width, int height, HPIXMAP srcp, int xsrc, int ysrc, int srcwidth, int srcheight); |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
153 void BitBlt(int xdest, int ydest, int width, int height, HWND src, int xsrc, int ysrc); |
c873b6f862b9
C++: Add text widget and packing to the window.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2868
diff
changeset
|
154 void BitBlt(int xdest, int ydest, int width, int height, HPIXMAP srcp, int xsrc, int ysrc); |
2861
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
155 }; |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
156 |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
157 class Render : public Drawable, public Widget |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
158 { |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
159 }; |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
160 |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
161 class Pixmap : public Drawable, public Handle |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
162 { |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
163 }; |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
164 #endif |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
165 |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
166 } /* namespace DW */ |
ef7a414f9b71
Add initial C++ binding header and example program.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
167 #endif |