comparison dw.hpp @ 2867:ada74f4d3f39

C++: Implement conditional signal handlers based on overrides. This uses templates in a sort of hacky way to determine if our virtual functions have been overridden. Leaving some debug code in for the moment to make sure it works on all platforms. OS/2 will require using GCC for the C++ bindings, since VisualAge only supports C++99 and Watcom doesn't even support that as far as I know.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 17 Dec 2022 21:39:00 +0000
parents 6ea67d0809eb
children 5ee1aaa48fc7
comparison
equal deleted inserted replaced
2866:6ea67d0809eb 2867:ada74f4d3f39
1 /* Dynamic Windows C++ Language Bindings 1 /* Dynamic Windows C++ Language Bindings
2 * Copyright 2022 Brian Smith 2 * Copyright 2022 Brian Smith
3 * Requires a C++11 compatible compiler.
3 */ 4 */
4 5
5 #ifndef _HPP_DW 6 #ifndef _HPP_DW
6 #define _HPP_DW 7 #define _HPP_DW
7 #include <dw.h> 8 #include <dw.h>
33 class Box : public Widget 34 class Box : public Widget
34 { 35 {
35 }; 36 };
36 37
37 // Top-level window class is packable 38 // Top-level window class is packable
39 template <class Derived>
38 class Window : public Box 40 class Window : public Box
39 { 41 {
40 private: 42 private:
41 void Setup() { dw_signal_connect(hwnd, DW_SIGNAL_DELETE, DW_SIGNAL_FUNC(_OnDelete), this); 43 void Setup() {
42 dw_signal_connect(hwnd, DW_SIGNAL_CONFIGURE, DW_SIGNAL_FUNC(_OnConfigure), this); } 44 if(&Derived::OnDelete != &Window::OnDelete) {
45 dw_signal_connect(hwnd, DW_SIGNAL_DELETE, DW_SIGNAL_FUNC(_OnDelete), this);
46 dw_debug("DW_SIGNAL_DELETE\n");
47 }
48 if(&Derived::OnConfigure != &Window::OnConfigure) {
49 dw_signal_connect(hwnd, DW_SIGNAL_CONFIGURE, DW_SIGNAL_FUNC(_OnConfigure), this);
50 dw_debug("DW_SIGNAL_CONFIGURE\n");
51 }
52 }
43 static int _OnDelete(HWND window, void *data) { return reinterpret_cast<Window *>(data)->OnDelete(); } 53 static int _OnDelete(HWND window, void *data) { return reinterpret_cast<Window *>(data)->OnDelete(); }
44 static int _OnConfigure(HWND window, int width, int height, void *data) { return reinterpret_cast<Window *>(data)->OnConfigure(width, height); } 54 static int _OnConfigure(HWND window, int width, int height, void *data) { return reinterpret_cast<Window *>(data)->OnConfigure(width, height); }
45 public: 55 public:
46 Window(HWND owner, const char *title, unsigned long style) { SetHWND(dw_window_new(owner, title, style)); Setup(); } 56 Window(HWND owner, const char *title, unsigned long style) { SetHWND(dw_window_new(owner, title, style)); Setup(); }
47 Window(const char *title, unsigned long style) { SetHWND(dw_window_new(HWND_DESKTOP, title, style)); Setup(); } 57 Window(const char *title, unsigned long style) { SetHWND(dw_window_new(HWND_DESKTOP, title, style)); Setup(); }
52 DW_FCF_TASKLIST | DW_FCF_SIZEBORDER | DW_FCF_MINMAX)); Setup(); } 62 DW_FCF_TASKLIST | DW_FCF_SIZEBORDER | DW_FCF_MINMAX)); Setup(); }
53 63
54 void SetText(const char *text) { dw_window_set_text(hwnd, text); } 64 void SetText(const char *text) { dw_window_set_text(hwnd, text); }
55 void SetSize(unsigned long width, unsigned long height) { dw_window_set_size(hwnd, width, height); } 65 void SetSize(unsigned long width, unsigned long height) { dw_window_set_size(hwnd, width, height); }
56 void Show() { dw_window_show(hwnd); } 66 void Show() { dw_window_show(hwnd); }
57 protected: 67 // Our signal handler functions to be overriden
58 virtual int OnDelete() = 0; 68 virtual int OnDelete() { return FALSE; }
59 virtual int OnConfigure(int width, int height) = 0; 69 virtual int OnConfigure(int width, int height) { return FALSE; };
60 }; 70 };
61 71
62 class App 72 class App
63 { 73 {
64 protected: 74 protected: