annotate win/wintoast.cpp @ 2089:bcc7877dcdac

Win: Add the required wintoast.cpp glue and undo a test change that did not help with the flicker on embedded Edge widgets.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 05 Jun 2020 16:49:31 +0000
parents
children 665d87a50eac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2089
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1 /* Simple WinToast forwarder from Dynamic Windows APIs */
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3 #include "wintoastlib.h"
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5 using namespace WinToastLib;
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7 class DWHandler : public IWinToastHandler {
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8 public:
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9 void toastActivated() const {
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10 // The user clicked in this toast
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
11 }
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
12
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
13 void toastActivated(int actionIndex) const {
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
14 // The user clicked on action
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
15 }
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
16
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
17 void toastDismissed(WinToastDismissalReason state) const {
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
18 switch (state) {
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
19 case UserCanceled:
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
20 // The user dismissed this toast"
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
21 break;
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
22 case TimedOut:
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
23 // The toast has timed out
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
24 break;
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
25 case ApplicationHidden:
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
26 // The application hid the toast using ToastNotifier.hide()
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
27 break;
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
28 default:
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
29 // Toast not activated
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
30 break;
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
31 }
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
32 }
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
33
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
34 void toastFailed() const {
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
35 // Error showing current toast
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
36 }
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
37 };
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
38
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
39
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
40 enum Results {
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
41 ToastClicked, // user clicked on the toast
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
42 ToastDismissed, // user dismissed the toast
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
43 ToastTimeOut, // toast timed out
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
44 ToastHided, // application hid the toast
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
45 ToastNotActivated, // toast was not activated
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
46 ToastFailed, // toast failed
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
47 SystemNotSupported, // system does not support toasts
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
48 UnhandledOption, // unhandled option
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
49 MultipleTextNotSupported, // multiple texts were provided
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
50 InitializationFailure, // toast notification manager initialization failure
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
51 ToastNotLaunched // toast could not be launched
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
52 };
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
53
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
54 extern "C" {
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
55
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
56 void _dw_toast_init(LPWSTR AppName, LPWSTR AppID)
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
57 {
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
58 if(WinToast::isCompatible())
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
59 {
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
60 WinToast::instance()->setAppName(AppName);
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
61 WinToast::instance()->setAppUserModelId(AppID);
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
62 WinToast::instance()->initialize();
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
63 }
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
64 }
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
65
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
66 void *_dw_notification_new(LPWSTR title, LPWSTR image, LPWSTR description)
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
67 {
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
68 if(WinToast::isCompatible())
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
69 {
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
70 WinToastTemplate *templ = new WinToastTemplate(image ? WinToastTemplate::ImageAndText02 : WinToastTemplate::Text02);
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
71 templ->setTextField(title, WinToastTemplate::FirstLine);
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
72 templ->setAttributionText(description);
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
73 if(image)
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
74 templ->setImagePath(image);
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
75 return (void *)templ;
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
76 }
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
77 return NULL;
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
78 }
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
79
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
80 int _dw_notification_send(void *notification)
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
81 {
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
82 if(WinToast::isCompatible())
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
83 {
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
84 WinToastTemplate *templ = (WinToastTemplate *)notification;
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
85
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
86 if(templ && WinToast::instance()->showToast(*templ, new DWHandler()) >= 0)
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
87 return 0; // DW_ERROR_NONE
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
88 }
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
89 return -1; // DW_ERROR_UNKNOWN
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
90 }
bcc7877dcdac Win: Add the required wintoast.cpp glue and undo a test change that did
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
91 }