Bug 1825212 [wpt PR 39266] - [@scope] Propagate proximity from SubResult, a=testonly
[gecko.git] / third_party / WinToast / upstream-add-toast-scenario.patch
blob0be8bf878d69a919025ecc74659b1703cf4556c1
1 diff --git a/src/wintoastlib.cpp b/src/wintoastlib.cpp
2 index 3cf5f21..1adfe19 100644
3 --- a/src/wintoastlib.cpp
4 +++ b/src/wintoastlib.cpp
5 @@ -677,6 +677,10 @@ INT64 WinToast::showToast(_In_ const WinToastTemplate& toast, _In_ IWinToastHan
6 (toast.duration() == WinToastTemplate::Duration::Short) ? L"short" : L"long");
9 + if (SUCCEEDED(hr)) {
10 + hr = addScenarioHelper(xmlDocument.Get(), toast.scenario());
11 + }
13 } else {
14 DEBUG_MSG("Modern features (Actions/Sounds/Attributes) not supported in this os version");
16 @@ -828,6 +832,28 @@ HRESULT WinToast::addDurationHelper(_In_ IXmlDocument *xml, _In_ const std::wstr
17 return hr;
20 +HRESULT WinToast::addScenarioHelper(_In_ IXmlDocument* xml, _In_ const std::wstring& scenario) {
21 + ComPtr<IXmlNodeList> nodeList;
22 + HRESULT hr = xml->GetElementsByTagName(WinToastStringWrapper(L"toast").Get(), &nodeList);
23 + if (SUCCEEDED(hr)) {
24 + UINT32 length;
25 + hr = nodeList->get_Length(&length);
26 + if (SUCCEEDED(hr)) {
27 + ComPtr<IXmlNode> toastNode;
28 + hr = nodeList->Item(0, &toastNode);
29 + if (SUCCEEDED(hr)) {
30 + ComPtr<IXmlElement> toastElement;
31 + hr = toastNode.As(&toastElement);
32 + if (SUCCEEDED(hr)) {
33 + hr = toastElement->SetAttribute(WinToastStringWrapper(L"scenario").Get(),
34 + WinToastStringWrapper(scenario).Get());
35 + }
36 + }
37 + }
38 + }
39 + return hr;
42 HRESULT WinToast::setTextFieldHelper(_In_ IXmlDocument *xml, _In_ const std::wstring& text, _In_ UINT32 pos) {
43 ComPtr<IXmlNodeList> nodeList;
44 HRESULT hr = xml->GetElementsByTagName(WinToastStringWrapper(L"text").Get(), &nodeList);
45 @@ -1065,6 +1091,15 @@ void WinToastTemplate::setExpiration(_In_ INT64 millisecondsFromNow) {
46 _expiration = millisecondsFromNow;
49 +void WinToastLib::WinToastTemplate::setScenario(Scenario scenario) {
50 + switch (scenario) {
51 + case Scenario::Default: _scenario = L"Default"; break;
52 + case Scenario::Alarm: _scenario = L"Alarm"; break;
53 + case Scenario::IncomingCall: _scenario = L"IncomingCall"; break;
54 + case Scenario::Reminder: _scenario = L"Reminder"; break;
55 + }
58 void WinToastTemplate::setAttributionText(_In_ const std::wstring& attributionText) {
59 _attributionText = attributionText;
61 @@ -1112,6 +1147,10 @@ const std::wstring& WinToastTemplate::attributionText() const {
62 return _attributionText;
65 +const std::wstring& WinToastLib::WinToastTemplate::scenario() const {
66 + return _scenario;
69 INT64 WinToastTemplate::expiration() const {
70 return _expiration;
72 diff --git a/src/wintoastlib.h b/src/wintoastlib.h
73 index d028994..291e15f 100644
74 --- a/src/wintoastlib.h
75 +++ b/src/wintoastlib.h
76 @@ -63,6 +63,7 @@ namespace WinToastLib {
78 class WinToastTemplate {
79 public:
80 + enum class Scenario { Default, Alarm, IncomingCall, Reminder };
81 enum Duration { System, Short, Long };
82 enum AudioOption { Default = 0, Silent, Loop };
83 enum TextField { FirstLine = 0, SecondLine, ThirdLine };
84 @@ -114,13 +115,14 @@ namespace WinToastLib {
85 void setSecondLine(_In_ const std::wstring& text);
86 void setThirdLine(_In_ const std::wstring& text);
87 void setTextField(_In_ const std::wstring& txt, _In_ TextField pos);
88 - void setAttributionText(_In_ const std::wstring & attributionText);
89 + void setAttributionText(_In_ const std::wstring& attributionText);
90 void setImagePath(_In_ const std::wstring& imgPath);
91 void setAudioPath(_In_ WinToastTemplate::AudioSystemFile audio);
92 void setAudioPath(_In_ const std::wstring& audioPath);
93 void setAudioOption(_In_ WinToastTemplate::AudioOption audioOption);
94 void setDuration(_In_ Duration duration);
95 void setExpiration(_In_ INT64 millisecondsFromNow);
96 + void setScenario(_In_ Scenario scenario);
97 void addAction(_In_ const std::wstring& label);
99 std::size_t textFieldsCount() const;
100 @@ -132,6 +134,7 @@ namespace WinToastLib {
101 const std::wstring& imagePath() const;
102 const std::wstring& audioPath() const;
103 const std::wstring& attributionText() const;
104 + const std::wstring& scenario() const;
105 INT64 expiration() const;
106 WinToastTemplateType type() const;
107 WinToastTemplate::AudioOption audioOption() const;
108 @@ -142,6 +145,7 @@ namespace WinToastLib {
109 std::wstring _imagePath{};
110 std::wstring _audioPath{};
111 std::wstring _attributionText{};
112 + std::wstring _scenario{L"Default"};
113 INT64 _expiration{0};
114 AudioOption _audioOption{WinToastTemplate::AudioOption::Default};
115 WinToastTemplateType _type{WinToastTemplateType::Text01};
116 @@ -210,6 +214,7 @@ namespace WinToastLib {
117 HRESULT setAttributionTextFieldHelper(_In_ IXmlDocument *xml, _In_ const std::wstring& text);
118 HRESULT addActionHelper(_In_ IXmlDocument *xml, _In_ const std::wstring& action, _In_ const std::wstring& arguments);
119 HRESULT addDurationHelper(_In_ IXmlDocument *xml, _In_ const std::wstring& duration);
120 + HRESULT addScenarioHelper(_In_ IXmlDocument *xml, _In_ const std::wstring& scenario);
121 ComPtr<IToastNotifier> notifier(_In_ bool* succeded) const;
122 void setError(_Out_opt_ WinToastError* error, _In_ WinToastError value);