changeset 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 2417bc294e30
children 10c22853b479
files dwtest.c win/dw.c win/wintoast.cpp
diffstat 3 files changed, 54 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/dwtest.c	Mon Jun 15 22:05:55 2020 +0000
+++ b/dwtest.c	Tue Jun 16 00:16:59 2020 +0000
@@ -587,6 +587,11 @@
     return TRUE;
 }
 
+int DWSIGNAL notification_clicked_callback(HWND notification, void *data)
+{
+    dw_debug("Notification clicked\n");
+}
+
 int DWSIGNAL browse_file_callback(HWND window, void *data)
 {
     char *tmp;
@@ -604,6 +609,7 @@
         read_file();
         current_col = current_row = 0;
         update_render();
+        dw_signal_connect(notification, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(notification_clicked_callback), NULL);
         dw_notification_send(notification);
     }
     dw_window_set_focus(copypastefield);
--- a/win/dw.c	Mon Jun 15 22:05:55 2020 +0000
+++ b/win/dw.c	Tue Jun 16 00:16:59 2020 +0000
@@ -2476,6 +2476,16 @@
                      }
                   }
                   break;
+               case WM_USER+102:
+                  {
+                     if(hWnd == tmp->window)
+                     {
+                        int (DWSIGNAL *clickfunc)(HWND, void *) = tmp->signalfunction;
+
+                        return clickfunc(tmp->window, tmp->data);
+                     }
+                  }
+                  break;
             }
          }
          if(tmp)
--- 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();