comparison win/wintoast.cpp @ 2104:6e55c6f8d816

Added initial notification callback code to the test program. Win: Added initial notification callback handler glue and fixed a memory leak. The activation callbacks do not seem to be triggering so added some debug code to test.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 16 Jun 2020 00:16:59 +0000
parents 665d87a50eac
children 35abef6e33a9
comparison
equal deleted inserted replaced
2103:2417bc294e30 2104:6e55c6f8d816
2 2
3 #include "wintoastlib.h" 3 #include "wintoastlib.h"
4 4
5 using namespace WinToastLib; 5 using namespace WinToastLib;
6 6
7 extern "C" {
8 LRESULT CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2);
9 void dw_signal_disconnect_by_window(HWND window);
10 #ifdef DEBUG
11 void dw_debug(const char *format, ...);
12 #endif
13 }
14
7 class DWHandler : public IWinToastHandler { 15 class DWHandler : public IWinToastHandler {
8 public: 16 public:
17 WinToastTemplate *templ;
18
9 void toastActivated() const { 19 void toastActivated() const {
10 // The user clicked in this toast 20 // The user clicked in this toast
21 #ifdef DEBUG
22 dw_debug("Sending notification to DW eventhandler\n");
23 #endif
24 _wndproc((HWND)templ, WM_USER+102, 0, 0);
11 } 25 }
12 26
13 void toastActivated(int actionIndex) const { 27 void toastActivated(int actionIndex) const {
14 // The user clicked on action 28 // The user clicked on action
29 #ifdef DEBUG
30 dw_debug("Sending notification to DW eventhandler via action\n");
31 #endif
32 _wndproc((HWND)templ, WM_USER+102, 0, 0);
15 } 33 }
16 34
17 void toastDismissed(WinToastDismissalReason state) const { 35 void toastDismissed(WinToastDismissalReason state) const {
18 switch (state) { 36 switch (state) {
19 case UserCanceled: 37 case UserCanceled:
20 // The user dismissed this toast" 38 // The user dismissed this toast
39 #ifdef DEBUG
40 dw_debug("The user dismissed this toast\n");
41 #endif
42 delete templ;
21 break; 43 break;
22 case TimedOut: 44 case TimedOut:
23 // The toast has timed out 45 // The toast has timed out
46 #ifdef DEBUG
47 dw_debug("The toast has timed out\n");
48 #endif
24 break; 49 break;
25 case ApplicationHidden: 50 case ApplicationHidden:
26 // The application hid the toast using ToastNotifier.hide() 51 // The application hid the toast using ToastNotifier.hide()
52 #ifdef DEBUG
53 dw_debug("The application hid the toast using ToastNotifier.hide()\n");
54 #endif
27 break; 55 break;
28 default: 56 default:
29 // Toast not activated 57 // Toast not activated
30 break; 58 break;
31 } 59 }
32 } 60 }
33 61
34 void toastFailed() const { 62 void toastFailed() const {
35 // Error showing current toast 63 // Error showing current toast
64 #ifdef DEBUG
65 dw_debug("Toast failed freeing template\n");
66 #endif
67 delete templ;
36 } 68 }
37 }; 69 };
38 70
39 71
40 enum Results { 72 enum Results {
80 int _dw_notification_send(void *notification) 112 int _dw_notification_send(void *notification)
81 { 113 {
82 if(WinToast::isCompatible()) 114 if(WinToast::isCompatible())
83 { 115 {
84 WinToastTemplate *templ = (WinToastTemplate *)notification; 116 WinToastTemplate *templ = (WinToastTemplate *)notification;
85 117 DWHandler *handler = new DWHandler();
86 if(templ && WinToast::instance()->showToast(*templ, new DWHandler()) >= 0) 118 handler->templ = templ;
119
120 if(templ && WinToast::instance()->showToast(*templ, handler) >= 0)
87 return 0; // DW_ERROR_NONE 121 return 0; // DW_ERROR_NONE
88 } 122 }
89 return -1; // DW_ERROR_UNKNOWN 123 return -1; // DW_ERROR_UNKNOWN
90 } 124 }
91 125
92 BOOL _dw_toast_is_compatible(void) 126 BOOL _dw_toast_is_compatible(void)
93 { 127 {
94 return WinToast::isCompatible(); 128 return WinToast::isCompatible();
95 } 129 }
96 } 130 }