diff 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
line wrap: on
line diff
--- a/win/wintoast.cpp	Mon Jun 15 22:05:55 2020 +0000
+++ b/win/wintoast.cpp	Tue Jun 16 00:16:59 2020 +0000
@@ -4,26 +4,54 @@
 
 using namespace WinToastLib;
 
+extern "C" {
+   LRESULT CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2);
+   void dw_signal_disconnect_by_window(HWND window);
+#ifdef DEBUG
+   void dw_debug(const char *format, ...);
+#endif
+}
+
 class DWHandler : public IWinToastHandler {
 public:
+    WinToastTemplate *templ;
+
     void toastActivated() const {
         // The user clicked in this toast
+#ifdef DEBUG
+        dw_debug("Sending notification to DW eventhandler\n");
+#endif
+        _wndproc((HWND)templ, WM_USER+102, 0, 0);
     }
 
     void toastActivated(int actionIndex) const {
         // The user clicked on action
+#ifdef DEBUG
+        dw_debug("Sending notification to DW eventhandler via action\n");
+#endif
+        _wndproc((HWND)templ, WM_USER+102, 0, 0);
     }
 
     void toastDismissed(WinToastDismissalReason state) const {
         switch (state) {
         case UserCanceled:
-            // The user dismissed this toast"
+            // The user dismissed this toast
+#ifdef DEBUG
+            dw_debug("The user dismissed this toast\n");
+#endif
+            delete templ;
             break;
         case TimedOut:
             // The toast has timed out
+#ifdef DEBUG
+            dw_debug("The toast has timed out\n");
+#endif
             break;
         case ApplicationHidden:
             // The application hid the toast using ToastNotifier.hide()
+#ifdef DEBUG
+            dw_debug("The application hid the toast using ToastNotifier.hide()\n");
+#endif
             break;
         default:
             // Toast not activated
@@ -33,6 +61,10 @@
 
     void toastFailed() const {
         // Error showing current toast
+#ifdef DEBUG
+        dw_debug("Toast failed freeing template\n");
+#endif
+        delete templ;
     }
 };
 
@@ -82,13 +114,15 @@
       if(WinToast::isCompatible()) 
       {
          WinToastTemplate *templ = (WinToastTemplate *)notification;
-         
-         if(templ && WinToast::instance()->showToast(*templ, new DWHandler()) >= 0)
+         DWHandler *handler = new DWHandler();
+         handler->templ = templ;
+
+         if(templ && WinToast::instance()->showToast(*templ, handler) >= 0)
             return 0; // DW_ERROR_NONE
       }
       return -1; // DW_ERROR_UNKNOWN
    }
-   
+
    BOOL _dw_toast_is_compatible(void)
    {
        return WinToast::isCompatible();