comparison 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
comparison
equal deleted inserted replaced
2088:94ea915bd917 2089:bcc7877dcdac
1 /* Simple WinToast forwarder from Dynamic Windows APIs */
2
3 #include "wintoastlib.h"
4
5 using namespace WinToastLib;
6
7 class DWHandler : public IWinToastHandler {
8 public:
9 void toastActivated() const {
10 // The user clicked in this toast
11 }
12
13 void toastActivated(int actionIndex) const {
14 // The user clicked on action
15 }
16
17 void toastDismissed(WinToastDismissalReason state) const {
18 switch (state) {
19 case UserCanceled:
20 // The user dismissed this toast"
21 break;
22 case TimedOut:
23 // The toast has timed out
24 break;
25 case ApplicationHidden:
26 // The application hid the toast using ToastNotifier.hide()
27 break;
28 default:
29 // Toast not activated
30 break;
31 }
32 }
33
34 void toastFailed() const {
35 // Error showing current toast
36 }
37 };
38
39
40 enum Results {
41 ToastClicked, // user clicked on the toast
42 ToastDismissed, // user dismissed the toast
43 ToastTimeOut, // toast timed out
44 ToastHided, // application hid the toast
45 ToastNotActivated, // toast was not activated
46 ToastFailed, // toast failed
47 SystemNotSupported, // system does not support toasts
48 UnhandledOption, // unhandled option
49 MultipleTextNotSupported, // multiple texts were provided
50 InitializationFailure, // toast notification manager initialization failure
51 ToastNotLaunched // toast could not be launched
52 };
53
54 extern "C" {
55
56 void _dw_toast_init(LPWSTR AppName, LPWSTR AppID)
57 {
58 if(WinToast::isCompatible())
59 {
60 WinToast::instance()->setAppName(AppName);
61 WinToast::instance()->setAppUserModelId(AppID);
62 WinToast::instance()->initialize();
63 }
64 }
65
66 void *_dw_notification_new(LPWSTR title, LPWSTR image, LPWSTR description)
67 {
68 if(WinToast::isCompatible())
69 {
70 WinToastTemplate *templ = new WinToastTemplate(image ? WinToastTemplate::ImageAndText02 : WinToastTemplate::Text02);
71 templ->setTextField(title, WinToastTemplate::FirstLine);
72 templ->setAttributionText(description);
73 if(image)
74 templ->setImagePath(image);
75 return (void *)templ;
76 }
77 return NULL;
78 }
79
80 int _dw_notification_send(void *notification)
81 {
82 if(WinToast::isCompatible())
83 {
84 WinToastTemplate *templ = (WinToastTemplate *)notification;
85
86 if(templ && WinToast::instance()->showToast(*templ, new DWHandler()) >= 0)
87 return 0; // DW_ERROR_NONE
88 }
89 return -1; // DW_ERROR_UNKNOWN
90 }
91 }