From c888cdec61b7c3fdf164b15841b6aa148f0148d5 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Fri, 25 Sep 2015 18:47:53 +0000 Subject: Toaster: crash fix; check in options for enable/disable git-svn-id: http://svn.miranda-ng.org/main/trunk@15443 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Toaster/res/resource.rc | 15 +++++++++------ plugins/Toaster/src/options.cpp | 14 +++++++++++++- plugins/Toaster/src/options.h | 2 ++ plugins/Toaster/src/resource.h | 8 +++++--- plugins/Toaster/src/services.cpp | 7 ++----- plugins/Toaster/src/toast_event_handler.cpp | 23 +++++++++-------------- plugins/Toaster/src/toast_event_handler.h | 2 ++ plugins/Toaster/src/toast_notification.cpp | 6 +++--- 8 files changed, 45 insertions(+), 32 deletions(-) (limited to 'plugins') diff --git a/plugins/Toaster/res/resource.rc b/plugins/Toaster/res/resource.rc index 4618ccd183..0881d7b231 100644 --- a/plugins/Toaster/res/resource.rc +++ b/plugins/Toaster/res/resource.rc @@ -13,7 +13,7 @@ #undef APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// -// Neutral resources +// Нейтральный resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU) LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL @@ -31,6 +31,7 @@ FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN PUSHBUTTON "Preview",IDC_PREVIEW,219,203,73,14 PUSHBUTTON "Add shortcut",IDC_SHORTCUT,11,203,73,14 + CONTROL "Enabled",IDC_CHECK_ENABLED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,30,123,10 END @@ -44,6 +45,8 @@ GUIDELINES DESIGNINFO BEGIN IDD_OPTIONS_MAIN, DIALOG BEGIN + VERTGUIDE, 14 + HORZGUIDE, 30 HORZGUIDE, 203 END END @@ -55,17 +58,17 @@ END // AFX_DIALOG_LAYOUT // -IDD_OPTIONS_MAIN AFX_DIALOG_LAYOUT +IDD_OPTIONS_MAIN AFX_DIALOG_LAYOUT BEGIN - 0 + 0x0000 END -#endif // Neutral resources +#endif // Нейтральный resources ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// -// Russian (Russia) resources +// Русский (Россия) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS) LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT @@ -96,7 +99,7 @@ END #endif // APSTUDIO_INVOKED -#endif // Russian (Russia) resources +#endif // Русский (Россия) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/plugins/Toaster/src/options.cpp b/plugins/Toaster/src/options.cpp index 2cca826654..a899aaafed 100644 --- a/plugins/Toaster/src/options.cpp +++ b/plugins/Toaster/src/options.cpp @@ -3,10 +3,13 @@ COptions::COptions() : CDlgBase(g_hInstance, IDD_OPTIONS_MAIN), m_shortcut(this, IDC_SHORTCUT), - m_preview(this, IDC_PREVIEW) + m_preview(this, IDC_PREVIEW), + m_enabled(this, IDC_CHECK_ENABLED) { m_shortcut.OnClick = Callback(this, &COptions::Shortcut_OnClick); m_preview.OnClick = Callback(this, &COptions::Preview_OnClick); + m_enabled.SetState(CallService(MS_POPUP_QUERY, PUQS_GETSTATUS)); + m_enabled.OnChange = Callback(this, &COptions::Enabled_OnChange); } void COptions::OnInitDialog() @@ -30,6 +33,14 @@ void COptions::Preview_OnClick(CCtrlBase*) CallService(MS_POPUP_SHOWMESSAGEW, (WPARAM)TranslateT("Error"), (LPARAM)SM_ERROR); } +void COptions::Enabled_OnChange(CCtrlCheck* chk) +{ + if (chk->GetState()) + CallService(MS_POPUP_QUERY, PUQS_ENABLEPOPUPS); + else + CallService(MS_POPUP_QUERY, PUQS_DISABLEPOPUPS); +} + ///////////////////////////////////////////////////////////////////////////////// int OnOptionsInitialized(WPARAM wParam, LPARAM) @@ -44,3 +55,4 @@ int OnOptionsInitialized(WPARAM wParam, LPARAM) return 0; } + diff --git a/plugins/Toaster/src/options.h b/plugins/Toaster/src/options.h index 35d6c049b6..73d50a9877 100644 --- a/plugins/Toaster/src/options.h +++ b/plugins/Toaster/src/options.h @@ -6,12 +6,14 @@ class COptions : public CDlgBase private: CCtrlButton m_shortcut; CCtrlButton m_preview; + CCtrlCheck m_enabled; protected: void OnInitDialog(); void Shortcut_OnClick(CCtrlBase*); void Preview_OnClick(CCtrlBase*); + void Enabled_OnChange(CCtrlCheck*); public: COptions(); diff --git a/plugins/Toaster/src/resource.h b/plugins/Toaster/src/resource.h index 0e65385bd2..08def87a34 100644 --- a/plugins/Toaster/src/resource.h +++ b/plugins/Toaster/src/resource.h @@ -1,8 +1,10 @@ //{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by E:\Projects\C++\MirandaNG\plugins\Toaster\res\resource.rc +// Включаемый файл, созданный в Microsoft Visual C++. +// Используется d:\Others\SVN\MirandaNG\trunk\plugins\Toaster\res\resource.rc // #define IDD_OPTIONS_MAIN 107 +#define IDC_CHECK1 1013 +#define IDC_CHECK_ENABLED 1013 #define IDC_PREVIEW 1033 #define IDC_SHORTCUT 1034 @@ -12,7 +14,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 108 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1013 +#define _APS_NEXT_CONTROL_VALUE 1014 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/plugins/Toaster/src/services.cpp b/plugins/Toaster/src/services.cpp index 1209ebe0cd..ebfb13b3a5 100644 --- a/plugins/Toaster/src/services.cpp +++ b/plugins/Toaster/src/services.cpp @@ -262,11 +262,8 @@ static INT_PTR ShowMessage(WPARAM wParam, LPARAM lParam) void __stdcall HideAllToasts(void*) { mir_cslock lck(csNotifications); - while (lstNotifications.getCount()) - { - lstNotifications[0].Hide(); - lstNotifications.remove(0); - } + for (int i = 0; i < lstNotifications.getCount(); i++) + lstNotifications[i].Hide(); } void InitServices() diff --git a/plugins/Toaster/src/toast_event_handler.cpp b/plugins/Toaster/src/toast_event_handler.cpp index a5b11705cc..5b1bdaf1f5 100644 --- a/plugins/Toaster/src/toast_event_handler.cpp +++ b/plugins/Toaster/src/toast_event_handler.cpp @@ -13,8 +13,6 @@ ToastEventHandler::~ToastEventHandler() { if (_thd->pPopupProc) _thd->pPopupProc((HWND)this, UM_FREEPLUGINDATA, 0, 0); - - lstNotifications.remove(_thd->tstNotification); } IFACEMETHODIMP_(ULONG) ToastEventHandler::AddRef() @@ -51,8 +49,7 @@ IFACEMETHODIMP ToastEventHandler::Invoke(_In_ IToastNotification*, _In_ IInspect if (_thd->pPopupProc) _thd->pPopupProc((HWND)this, WM_COMMAND, 0, 0); - mir_cslock lck(csNotifications); - lstNotifications.remove(_thd->tstNotification); + DestroyNotification(); return S_OK; } @@ -64,12 +61,6 @@ IFACEMETHODIMP ToastEventHandler::Invoke(_In_ IToastNotification*, _In_ IToastDi switch (tdr) { - case ToastDismissalReason_ApplicationHidden: - { - if (_thd->pPopupProc) - _thd->pPopupProc((HWND)this, WM_CONTEXTMENU, 0, 0); - break; - } case ToastDismissalReason_UserCanceled: { if (_thd->pPopupProc) @@ -77,21 +68,25 @@ IFACEMETHODIMP ToastEventHandler::Invoke(_In_ IToastNotification*, _In_ IToastDi _thd->tstNotification->Hide(); break; } + case ToastDismissalReason_ApplicationHidden: case ToastDismissalReason_TimedOut: + DestroyNotification(); break; } - mir_cslock lck(csNotifications); - lstNotifications.remove(_thd->tstNotification); - return S_OK; } IFACEMETHODIMP ToastEventHandler::Invoke(_In_ IToastNotification*, _In_ IToastFailedEventArgs*) +{ + DestroyNotification(); + return S_OK; +} + +void ToastEventHandler::DestroyNotification() { mir_cslock lck(csNotifications); lstNotifications.remove(_thd->tstNotification); - return S_OK; } void* ToastEventHandler::GetPluginData() diff --git a/plugins/Toaster/src/toast_event_handler.h b/plugins/Toaster/src/toast_event_handler.h index 321b1b4764..f4a74534fb 100644 --- a/plugins/Toaster/src/toast_event_handler.h +++ b/plugins/Toaster/src/toast_event_handler.h @@ -28,6 +28,8 @@ public: private: ULONG _ref; std::unique_ptr _thd; + + void DestroyNotification(); }; #endif //_TOAST_EVENT_HANDLER_H_ \ No newline at end of file diff --git a/plugins/Toaster/src/toast_notification.cpp b/plugins/Toaster/src/toast_notification.cpp index acbb5d627c..0275920c64 100644 --- a/plugins/Toaster/src/toast_notification.cpp +++ b/plugins/Toaster/src/toast_notification.cpp @@ -77,9 +77,9 @@ HRESULT ToastNotification::Show(_In_ ToastEventHandler* handler) { ComPtr eventHandler(handler); - notification->add_Activated(eventHandler.Get(), &_ertActivated); - notification->add_Dismissed(eventHandler.Get(), &_ertDismissed); - notification->add_Failed(eventHandler.Get(), &_ertFailed); + CHECKHR(notification->add_Activated(eventHandler.Get(), &_ertActivated)); + CHECKHR(notification->add_Dismissed(eventHandler.Get(), &_ertDismissed)); + CHECKHR(notification->add_Failed(eventHandler.Get(), &_ertFailed)); return notifier->Show(notification.Get()); } -- cgit v1.2.3