From f580be3d9dcccb14831d6bed9e7dfca600f5b6f8 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 6 Mar 2019 16:15:45 +0300 Subject: popups: - internal implementation details & all service declarations moved to m_popup_int.h; - all service calls removed and replaced with function calls; - direct access to popup serttings replaced with Popup_Enable / Popup_Enabled; --- src/core/stdpopup/src/options.cpp | 8 +- src/core/stdpopup/src/services.cpp | 49 +++---------- src/core/stdpopup/src/stdafx.h | 2 +- src/core/stdpopup/src/yapp.cpp | 4 +- src/mir_app/src/chat_tools.cpp | 2 +- src/mir_app/src/mir_app.def | 21 ++++++ src/mir_app/src/mir_app64.def | 21 ++++++ src/mir_app/src/popups.cpp | 147 +++++++++++++++++++++++++++++++++++++ src/mir_app/src/stdafx.h | 54 +++++++------- 9 files changed, 233 insertions(+), 75 deletions(-) create mode 100644 src/mir_app/src/popups.cpp (limited to 'src') diff --git a/src/core/stdpopup/src/options.cpp b/src/core/stdpopup/src/options.cpp index c30ed0635e..1bb5d199f1 100644 --- a/src/core/stdpopup/src/options.cpp +++ b/src/core/stdpopup/src/options.cpp @@ -429,16 +429,16 @@ static INT_PTR CALLBACK DlgProcOptsClasses(HWND hwndDlg, UINT msg, WPARAM wParam POPUPCLASS pc = *arNewClasses[i]; pc.PluginWindowProc = nullptr; POPUPDATACLASS d = {sizeof(d), pc.pszName}; - d.pwszTitle = L"Preview"; - d.pwszText = L"The quick brown fox jumps over the lazy dog."; + d.szTitle.w = L"Preview"; + d.szText.w = L"The quick brown fox jumps over the lazy dog."; CallService(MS_POPUP_ADDPOPUPCLASS, (WPARAM)&pc, (LPARAM)&d); } else { POPUPCLASS pc = *arNewClasses[i]; pc.PluginWindowProc = nullptr; POPUPDATACLASS d = {sizeof(d), pc.pszName}; - d.pszTitle = "Preview"; - d.pszText = "The quick brown fox jumps over the lazy dog."; + d.szTitle.a = "Preview"; + d.szText.a = "The quick brown fox jumps over the lazy dog."; CallService(MS_POPUP_ADDPOPUPCLASS, (WPARAM)&pc, (LPARAM)&d); } break; diff --git a/src/core/stdpopup/src/services.cpp b/src/core/stdpopup/src/services.cpp index f01f16e83a..ce8650f2ce 100644 --- a/src/core/stdpopup/src/services.cpp +++ b/src/core/stdpopup/src/services.cpp @@ -70,7 +70,7 @@ static INT_PTR CreatePopup(WPARAM wParam, LPARAM) pd_out->timeout = pd_in->iSeconds; lstPopupHistory.Add(pd_out->pwzTitle, pd_out->pwzText, time(0)); - if (!db_get_b(0, "Popup", "ModuleIsEnabled", 1)) { + if (!Popup_Enabled()) { mir_free(pd_out->pwzTitle); mir_free(pd_out->pwzText); mir_free(pd_out); @@ -111,7 +111,7 @@ static INT_PTR CreatePopupW(WPARAM wParam, LPARAM) pd_out->timeout = pd_in->iSeconds; lstPopupHistory.Add(pd_out->pwzTitle, pd_out->pwzText, time(0)); - if (!db_get_b(0, "Popup", "ModuleIsEnabled", 1)) { + if (!Popup_Enabled()) { mir_free(pd_out->pwzTitle); mir_free(pd_out->pwzText); mir_free(pd_out); @@ -151,7 +151,7 @@ void ShowPopup(PopupData &pd_in) lstPopupHistory.Add(pd_out->pwzTitle, pd_out->pwzText, time(0)); - if (!db_get_b(0, "Popup", "ModuleIsEnabled", 1)) { + if (!Popup_Enabled()) { mir_free(pd_out->pwzTitle); mir_free(pd_out->pwzText); mir_free(pd_out); @@ -193,7 +193,7 @@ static INT_PTR GetOpaque(WPARAM wParam, LPARAM) void UpdateMenu() { - bool isEnabled = db_get_b(0, "Popup", "ModuleIsEnabled", 1) == 1; + bool isEnabled = Popup_Enabled() == 1; if (isEnabled) { Menu_ModifyItem(hMenuItem, LPGENW("Disable Popups"), IcoLib_GetIcon(ICO_POPUP_ON)); Menu_ModifyItem(hMenuRoot, nullptr, IcoLib_GetIcon(ICO_POPUP_ON)); @@ -207,38 +207,10 @@ void UpdateMenu() CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hTTButton, isEnabled ? TTBST_PUSHED : 0); } -INT_PTR PopupQuery(WPARAM wParam, LPARAM) -{ - switch(wParam) { - case PUQS_ENABLEPOPUPS: - { - bool enabled = db_get_b(0, "Popup", "ModuleIsEnabled", 1) != 0; - if (!enabled) db_set_b(0, "Popup", "ModuleIsEnabled", 1); - UpdateMenu(); - return !enabled; - } - break; - case PUQS_DISABLEPOPUPS: - { - bool enabled = db_get_b(0, "Popup", "ModuleIsEnabled", 1) != 0; - if (enabled) db_set_b(0, "Popup", "ModuleIsEnabled", 0); - UpdateMenu(); - return enabled; - } - break; - - case PUQS_GETSTATUS: - return db_get_b(0, "Popup", "ModuleIsEnabled", 1); - default: - UpdateMenu(); - return 1; - } -} - static INT_PTR TogglePopups(WPARAM, LPARAM) { - BYTE val = db_get_b(0, "Popup", "ModuleIsEnabled", 1); - db_set_b(0, "Popup", "ModuleIsEnabled", !val); + BYTE val = Popup_Enabled(); + Popup_Enable(!val); UpdateMenu(); return 0; } @@ -287,7 +259,7 @@ static INT_PTR ShowMessage(WPARAM wParam, LPARAM lParam) if (bShutdown) return -1; - if (db_get_b(0, "Popup", "ModuleIsEnabled", 1)) { + if (Popup_Enabled()) { POPUPDATAW pd = {0}; mir_wstrcpy(pd.lpwzContactName, lParam == SM_WARNING ? L"Warning" : L"Notification"); pd.lchIcon = LoadIcon(nullptr, lParam == SM_WARNING ? IDI_WARNING : IDI_INFORMATION); @@ -302,7 +274,7 @@ static INT_PTR ShowMessageW(WPARAM wParam, LPARAM lParam) if (bShutdown) return -1; - if (db_get_b(0, "Popup", "ModuleIsEnabled", 1)) { + if (Popup_Enabled()) { POPUPDATAW pd = {0}; mir_wstrcpy(pd.lpwzContactName, lParam == SM_WARNING ? L"Warning" : L"Notification"); pd.lchIcon = LoadIcon(nullptr, lParam == SM_WARNING ? IDI_WARNING : IDI_INFORMATION); @@ -399,8 +371,8 @@ static INT_PTR CreateClassPopup(WPARAM wParam, LPARAM lParam) pd.hContact = pdc->hContact; pd.opaque = pdc->PluginData; - pd.pszTitle = (char *)pdc->pszTitle; - pd.pszText = (char *)pdc->pszText; + pd.pszTitle = (char *)pdc->szTitle.a; + pd.pszText = (char *)pdc->szText.a; ShowPopup(pd); } @@ -428,7 +400,6 @@ void InitServices() CreateServiceFunction(MS_POPUP_CHANGEW, PopupChangeW); CreateServiceFunction(MS_POPUP_GETCONTACT, GetContact); CreateServiceFunction(MS_POPUP_GETPLUGINDATA, GetOpaque); - CreateServiceFunction(MS_POPUP_QUERY, PopupQuery); CreateServiceFunction(MS_POPUP_SHOWMESSAGE, ShowMessage); CreateServiceFunction(MS_POPUP_SHOWMESSAGEW, ShowMessageW); diff --git a/src/core/stdpopup/src/stdafx.h b/src/core/stdpopup/src/stdafx.h index 0255cba2d7..6cb4378305 100644 --- a/src/core/stdpopup/src/stdafx.h +++ b/src/core/stdpopup/src/stdafx.h @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/core/stdpopup/src/yapp.cpp b/src/core/stdpopup/src/yapp.cpp index 047c33502f..b440675cf6 100644 --- a/src/core/stdpopup/src/yapp.cpp +++ b/src/core/stdpopup/src/yapp.cpp @@ -77,7 +77,7 @@ static int TTBLoaded(WPARAM, LPARAM) ttb.pszService = "Popup/EnableDisableMenuCommand"; ttb.lParamUp = 1; ttb.dwFlags = TTBBF_VISIBLE | TTBBF_SHOWTOOLTIP | TTBBF_ASPUSHBUTTON; - if (db_get_b(0, "Popup", "ModuleIsEnabled", 1)) + if (Popup_Enabled()) ttb.dwFlags |= TTBBF_PUSHED; ttb.name = LPGEN("Toggle Popups"); ttb.hIconHandleUp = IcoLib_GetIconHandle(ICO_TB_POPUP_OFF); @@ -157,7 +157,7 @@ static void InitFonts() static void InitMenuItems(void) { - bool isEnabled = db_get_b(0, "Popup", "ModuleIsEnabled", 1) == 1; + bool isEnabled = Popup_Enabled() == 1; hMenuRoot = g_plugin.addRootMenu(MO_MAIN, LPGENW("Popups"), 500010000, IcoLib_GetIcon(isEnabled ? ICO_POPUP_ON : ICO_POPUP_OFF, 0)); Menu_ConfigureItem(hMenuRoot, MCI_OPT_UID, "043A641A-2767-4C57-AA57-9233D6F9DC54"); diff --git a/src/mir_app/src/chat_tools.cpp b/src/mir_app/src/chat_tools.cpp index 12e33f87eb..9762f03ee1 100644 --- a/src/mir_app/src/chat_tools.cpp +++ b/src/mir_app/src/chat_tools.cpp @@ -203,7 +203,7 @@ int ShowPopup(MCONTACT hContact, SESSION_INFO *si, HICON hIcon, char *pszProtoNa pd.PluginWindowProc = PopupDlgProc; pd.PluginData = si; - return PUAddPopupW(&pd); + return (INT_PTR)PUAddPopupW(&pd); } BOOL DoPopup(SESSION_INFO *si, GCEVENT *gce) diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 314a530e15..26df34bbb4 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -652,3 +652,24 @@ db_mc_tryMeta @732 ?setUString@PROTO_INTERFACE@@QAEXPBD0@Z @742 NONAME ?setUString@CMPluginBase@@QAEXIPBD0@Z @743 NONAME ?setUString@CMPluginBase@@QAEXPBD0@Z @744 NONAME +?getKeyList@GCSessionInfoBase@@QAEAAU?$LIST@UUSERINFO@@@@XZ @745 NONAME +PUAddPopup @746 +PUAddPopupW @747 +PUChangeTextW @748 +PUChangeW @749 +PUDeletePopup @750 +PUGetContact @751 +PUGetPluginData @752 +PURegisterActions @753 +PURegisterNotification @754 +PUShowMessage @755 +PUShowMessageW @756 +Popup_RegisterClass @757 +Popup_UnregisterClass @758 +ShowClassPopup @759 +ShowClassPopupW @760 +Popup_Enable @761 +Popup_Enabled @762 +Popup_AddClass @763 +Popup_Add @764 +Popup_Change @765 diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index b770ff95c3..44315b8df0 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -652,3 +652,24 @@ db_mc_tryMeta @732 ?setUString@PROTO_INTERFACE@@QEAAXPEBD0@Z @742 NONAME ?setUString@CMPluginBase@@QEAAXIPEBD0@Z @743 NONAME ?setUString@CMPluginBase@@QEAAXPEBD0@Z @744 NONAME +?getKeyList@GCSessionInfoBase@@QEAAAEAU?$LIST@UUSERINFO@@@@XZ @745 NONAME +PUAddPopup @746 +PUAddPopupW @747 +PUChangeTextW @748 +PUChangeW @749 +PUDeletePopup @750 +PUGetContact @751 +PUGetPluginData @752 +PURegisterActions @753 +PURegisterNotification @754 +PUShowMessage @755 +PUShowMessageW @756 +Popup_RegisterClass @757 +Popup_UnregisterClass @758 +ShowClassPopup @759 +ShowClassPopupW @760 +Popup_Enable @761 +Popup_Enabled @762 +Popup_AddClass @763 +Popup_Add @764 +Popup_Change @765 diff --git a/src/mir_app/src/popups.cpp b/src/mir_app/src/popups.cpp new file mode 100644 index 0000000000..67bee51a6e --- /dev/null +++ b/src/mir_app/src/popups.cpp @@ -0,0 +1,147 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (C) 2012-19 Miranda NG team (https://miranda-ng.org), +Copyright (c) 2000-12 Miranda IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "stdafx.h" + +MIR_APP_DLL(bool) Popup_Enabled() +{ + return db_get_b(0, "Popup", "ModuleIsEnabled", 1) != 0; +} + +MIR_APP_DLL(void) Popup_Enable(bool bEnable) +{ + db_set_b(0, "Popup", "ModuleIsEnabled", bEnable); +} + +///////////////////////////////////////////////////////////////////////////////////////// +// Popup v2.0 + +MIR_APP_DLL(HWND) Popup_Add(const POPUPDATA2 *ppdp, int flags) +{ + return (HWND)CallService(MS_POPUP_ADDPOPUP2, (WPARAM)ppdp, flags); +} + +MIR_APP_DLL(void) Popup_Change(HWND hwndPopup, const POPUPDATA2 *pData) +{ + CallService(MS_POPUP_CHANGEPOPUP2, (WPARAM)hwndPopup, (LPARAM)pData); +} + +///////////////////////////////////////////////////////////////////////////////////////// +// Popups v1.0 + +MIR_APP_DLL(HWND) PUAddPopup(POPUPDATA *ppdp, int flags) +{ + return (HWND)CallService(MS_POPUP_ADDPOPUP, (WPARAM)ppdp, flags); +} + +MIR_APP_DLL(HWND) PUAddPopupW(POPUPDATAW *ppdp, int flags) +{ + return (HWND)CallService(MS_POPUP_ADDPOPUPW, (WPARAM)ppdp, flags); +} + +MIR_APP_DLL(int) PUChangeW(HWND hWndPopup, POPUPDATAW *newData) +{ + return (int)CallService(MS_POPUP_CHANGEW, (WPARAM)hWndPopup, (LPARAM)newData); +} + +MIR_APP_DLL(int) PUChangeTextW(HWND hWndPopup, const wchar_t *lpwzNewText) +{ + return (int)CallService(MS_POPUP_CHANGETEXTW, (WPARAM)hWndPopup, (LPARAM)lpwzNewText); +} + +MIR_APP_DLL(int) PUDeletePopup(HWND hWndPopup) +{ + return (int)CallService(MS_POPUP_DESTROYPOPUP, 0, (LPARAM)hWndPopup); +} + +MIR_APP_DLL(MCONTACT) PUGetContact(HWND hPopupWindow) +{ + return (MCONTACT)CallService(MS_POPUP_GETCONTACT, (WPARAM)hPopupWindow, 0); +} + +MIR_APP_DLL(void*) PUGetPluginData(HWND hPopupWindow) +{ + return (void*)CallService(MS_POPUP_GETPLUGINDATA, (WPARAM)hPopupWindow, 0); +} + +///////////////////////////////////////////////////////////////////////////////////////// +// Messages + +MIR_APP_DLL(int) PUShowMessage(const char *lpzText, DWORD kind) +{ + return (int)CallService(MS_POPUP_SHOWMESSAGE, (WPARAM)lpzText, (LPARAM)kind); +} + +MIR_APP_DLL(int) PUShowMessageW(const wchar_t *lpwzText, DWORD kind) +{ + return (int)CallService(MS_POPUP_SHOWMESSAGEW, (WPARAM)lpwzText, (LPARAM)kind); +} + +///////////////////////////////////////////////////////////////////////////////////////// +// Actions + +MIR_APP_DLL(int) PURegisterActions(POPUPACTION *actions, int count) +{ + return (int)CallService(MS_POPUP_REGISTERACTIONS, (WPARAM)actions, (LPARAM)count); +} + +MIR_APP_DLL(HANDLE) PURegisterNotification(LPPOPUPNOTIFICATION notification) +{ + return (HANDLE)CallService(MS_POPUP_REGISTERNOTIFICATION, (WPARAM)notification, 0); +} + +///////////////////////////////////////////////////////////////////////////////////////// +// Popup classes + +MIR_APP_DLL(HANDLE) Popup_RegisterClass(POPUPCLASS *pc) +{ + return (HANDLE)CallService(MS_POPUP_REGISTERCLASS, 0, LPARAM(pc)); +} + +MIR_APP_DLL(void) Popup_UnregisterClass(HANDLE ppc) +{ + if (ppc) + CallService(MS_POPUP_UNREGISTERCLASS, 0, LPARAM(ppc)); +} + +MIR_APP_DLL(HWND) Popup_AddClass(POPUPDATACLASS *pData) +{ + return (HWND)CallService(MS_POPUP_ADDPOPUPCLASS, 0, (LPARAM)pData); +} + +MIR_APP_DLL(HWND) ShowClassPopup(const char *name, const char *title, const char *text) +{ + POPUPDATACLASS d = { sizeof(d), name }; + d.szTitle.a = title; + d.szText.a = text; + return (HWND)CallService(MS_POPUP_ADDPOPUPCLASS, 0, (LPARAM)&d); +} + +MIR_APP_DLL(HWND) ShowClassPopupW(const char *name, const wchar_t *title, const wchar_t *text) +{ + POPUPDATACLASS d = { sizeof(d), name }; + d.szTitle.w = title; + d.szText.w = text; + return (HWND)CallService(MS_POPUP_ADDPOPUPCLASS, 0, (LPARAM)&d); +} diff --git a/src/mir_app/src/stdafx.h b/src/mir_app/src/stdafx.h index de011d93a3..9d369695a0 100644 --- a/src/mir_app/src/stdafx.h +++ b/src/mir_app/src/stdafx.h @@ -60,48 +60,46 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define __NO_CMPLUGIN_NEEDED #include -#include #include -#include -#include -#include -#include -#include -#include #include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include -#include -#include +#include +#include #include #include +#include +#include +#include #include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include -#include +#include +#include #include +#include #include +#include #include "miranda.h" -#include -#include - typedef struct GlobalLogSettingsBase GlobalLogSettings; #include -- cgit v1.2.3