changeset 2865:fd32dce7fecd

Initial signal handler support for the C++ bindings. Need to may App a singleton so we don't require a global "app" variable. Also need to only attach signal handlers to overloaded callback functions.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 17 Dec 2022 09:03:32 +0000
parents 939fbceec13f
children 6ea67d0809eb
files dw.hpp dwtestoo.cpp
diffstat 2 files changed, 23 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/dw.hpp	Sat Dec 17 01:50:26 2022 +0000
+++ b/dw.hpp	Sat Dec 17 09:03:32 2022 +0000
@@ -37,18 +37,26 @@
 // Top-level window class is packable
 class Window : public Box
 {
+private:
+	void Setup() {	dw_signal_connect(hwnd, DW_SIGNAL_DELETE, DW_SIGNAL_FUNC(_OnDelete), this);
+					dw_signal_connect(hwnd, DW_SIGNAL_CONFIGURE, DW_SIGNAL_FUNC(_OnConfigure), this); }
+	static int _OnDelete(HWND window, void *data) { return reinterpret_cast<Window *>(data)->OnDelete(); }
+	static int _OnConfigure(HWND window, int width, int height, void *data) { return reinterpret_cast<Window *>(data)->OnConfigure(width, height); }
 public:
-	Window(HWND owner, const char *title, unsigned long style) { SetHWND(dw_window_new(owner, title, style)); }
-	Window(const char *title, unsigned long style) { SetHWND(dw_window_new(HWND_DESKTOP, title, style)); }
-	Window(unsigned long style) { SetHWND(dw_window_new(HWND_DESKTOP, "", style)); }
+	Window(HWND owner, const char *title, unsigned long style) { SetHWND(dw_window_new(owner, title, style)); Setup(); }
+	Window(const char *title, unsigned long style) { SetHWND(dw_window_new(HWND_DESKTOP, title, style)); Setup(); }
+	Window(unsigned long style) { SetHWND(dw_window_new(HWND_DESKTOP, "", style)); Setup(); }
 	Window(const char *title) { SetHWND(dw_window_new(HWND_DESKTOP, title,  DW_FCF_SYSMENU | DW_FCF_TITLEBAR |
-                        DW_FCF_TASKLIST | DW_FCF_SIZEBORDER | DW_FCF_MINMAX)); }
+                        DW_FCF_TASKLIST | DW_FCF_SIZEBORDER | DW_FCF_MINMAX)); Setup(); }
 	Window() { SetHWND(dw_window_new(HWND_DESKTOP, "", DW_FCF_SYSMENU | DW_FCF_TITLEBAR |
-                        DW_FCF_TASKLIST | DW_FCF_SIZEBORDER | DW_FCF_MINMAX)); }
+                        DW_FCF_TASKLIST | DW_FCF_SIZEBORDER | DW_FCF_MINMAX)); Setup(); }
 
 	void SetText(const char *text) { dw_window_set_text(hwnd, text); }
 	void SetSize(unsigned long width, unsigned long height) { dw_window_set_size(hwnd, width, height); }
 	void Show() { dw_window_show(hwnd); }
+protected:
+	virtual int OnDelete() = 0;
+	virtual int OnConfigure(int width, int height) = 0;
 };
 
 class App
--- a/dwtestoo.cpp	Sat Dec 17 01:50:26 2022 +0000
+++ b/dwtestoo.cpp	Sat Dec 17 09:03:32 2022 +0000
@@ -1,20 +1,22 @@
 #include <dw.hpp>
 
+DW::App *app;
+
 class MyWindow : public DW::Window
 {
 public:
-  MyWindow();
+  MyWindow() {
+	SetText("Basic application");
+	SetSize(200, 200);
+	}
+protected:
+	virtual int OnDelete() { app->MainQuit(); return FALSE; }
+	virtual int OnConfigure(int width, int height)  { return FALSE; }
 };
 
-MyWindow::MyWindow()
-{
-  SetText("Basic application");
-  SetSize(200, 200);
-}
-
 int dwmain(int argc, char* argv[])
 {
-  DW::App *app = new DW::App(argc, argv, "org.dbsoft.dwindows.dwtestoo");
+  app = new DW::App(argc, argv, "org.dbsoft.dwindows.dwtestoo");
   MyWindow *window = new MyWindow();
 
   window->Show();