/* Popup Plus plugin for Miranda IM Copyright © 2002 Luca Santarelli, © 2004-2007 Victor Pavlychko 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 #include "..\..\include\newpluginapi.h" //#include "..\..\include\m_icolib.h" #include "..\..\include\m_popup.h" #define SIZEOF(X)(sizeof(X)/sizeof(X[0])) #if defined(MessageBoxA) #undef MessageBoxA #if !defined(NB_CUSTOM_MESSAGEBOXA) #define NB_CUSTOM_MESSAGEBOXA #endif /* !defined(NB_CUSTOM_MESSAGEBOXA) */ #endif /* defined(MessageBoxA) */ #if defined(MessageBoxW) #undef MessageBoxW #if !defined(NB_CUSTOM_MESSAGEBOXW) #define NB_CUSTOM_MESSAGEBOXW #endif /* !defined(NB_CUSTOM_MESSAGEBOXW) */ #endif /* defined(MessageBoxA) */ int mir_MessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType) { static signed char bUsePopups = -1; static BOOL bIconsNotLoaded = TRUE; static HICON hicNotify = NULL, hicWarning = NULL, hicError = NULL; BOOL bNeedMsgBox = TRUE; if (bUsePopups < 0) bUsePopups = (ServiceExists(MS_POPUP_ADDPOPUPEX) && DBGetContactSettingByte(NULL, "UI_Tweaks", "MsgBox2Popup", 1)) ? 1 : 0; if (bUsePopups && ((uType&MB_TYPEMASK) == MB_OK)) { POPUPDATAEX ppd = {0}; if (bIconsNotLoaded) { if (ServiceExists(MS_SKIN2_GETICON)) { hicNotify = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"popup_notify"); hicWarning = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"popup_warning"); hicError = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"popup_error"); } if (!hicNotify) hicNotify = LoadIcon(NULL, IDI_INFORMATION); if (!hicWarning) hicWarning = LoadIcon(NULL, IDI_WARNING); if (!hicError) hicError = LoadIcon(NULL, IDI_ERROR); bIconsNotLoaded = FALSE; } lstrcpynA(ppd.lpzContactName, lpCaption, SIZEOF(ppd.lpzContactName)); lstrcpynA(ppd.lpzText, lpText, SIZEOF(ppd.lpzText)); if ((uType&MB_ICONMASK) == MB_ICONSTOP) { ppd.lchIcon = hicError; ppd.colorBack = RGB(191,0,0); ppd.colorText = RGB(255,245,225); } else if ((uType&MB_ICONMASK) == MB_ICONWARNING) { ppd.lchIcon = hicWarning; ppd.colorBack = RGB(210,210,150); ppd.colorText = RGB(0,0,0); } else /* if ((uType&MB_ICONMASK) == MB_ICONINFORMATION) */ { ppd.lchIcon = hicNotify; ppd.colorBack = RGB(230,230,230); ppd.colorText = RGB(0,0,0); } PUAddPopUpEx(&ppd); bNeedMsgBox = FALSE; } if (bNeedMsgBox) return MessageBoxA(hWnd, lpText, lpCaption, uType); return IDOK; } #if defined(_UNICODE) || defined(UNICODE) int mir_MessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType) { static signed char bUsePopups = -1; static BOOL bIconsNotLoaded = TRUE; static HICON hicNotify = NULL, hicWarning = NULL, hicError = NULL; BOOL bNeedMsgBox = TRUE; if (bUsePopups < 0) bUsePopups = (ServiceExists(MS_POPUP_ADDPOPUPEX) && DBGetContactSettingByte(NULL, "UI_Tweaks", "MsgBox2Popup", 1)) ? 1 : 0; if (bUsePopups && ((uType&MB_TYPEMASK) == MB_OK)) { POPUPDATAW ppd = {0}; if (bIconsNotLoaded) { if (ServiceExists(MS_SKIN2_GETICON)) { hicNotify = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"popup_notify"); hicWarning = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"popup_warning"); hicError = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"popup_error"); } if (!hicNotify) hicNotify = LoadIcon(NULL, IDI_INFORMATION); if (!hicWarning) hicWarning = LoadIcon(NULL, IDI_WARNING); if (!hicError) hicError = LoadIcon(NULL, IDI_ERROR); bIconsNotLoaded = FALSE; } lstrcpynW(ppd.lpwzContactName, lpCaption, SIZEOF(ppd.lpwzContactName)); lstrcpynW(ppd.lpwzText, lpText, SIZEOF(ppd.lpwzText)); if ((uType&MB_ICONMASK) == MB_ICONSTOP) { ppd.lchIcon = hicError; ppd.colorBack = RGB(191,0,0); ppd.colorText = RGB(255,245,225); } else if ((uType&MB_ICONMASK) == MB_ICONWARNING) { ppd.lchIcon = hicWarning; ppd.colorBack = RGB(210,210,150); ppd.colorText = RGB(0,0,0); } else /* if ((uType&MB_ICONMASK) == MB_ICONINFORMATION) */ { ppd.lchIcon = hicNotify; ppd.colorBack = RGB(230,230,230); ppd.colorText = RGB(0,0,0); } PUAddPopUpW(&ppd); bNeedMsgBox = FALSE; } if (bNeedMsgBox) return MessageBoxW(hWnd, lpText, lpCaption, uType); return IDOK; } #endif #if defined(NB_CUSTOM_MESSAGEBOXA) && !defined(MessageBoxA) #define MessageBoxA(a,b,c,d) (mir_MessageBoxA((a),(b),(c),(d))) #endif #if (defined(UNICODE) || defined(_UNICODE)) && defined(NB_CUSTOM_MESSAGEBOXW) && !defined(MessageBoxW) #define MessageBoxW(a,b,c,d) (mir_MessageBoxW((a),(b),(c),(d))) #endif #if defined(NB_CUSTOM_MESSAGEBOXA) #undef NB_CUSTOM_MESSAGEBOXA #endif #if defined(NB_CUSTOM_MESSAGEBOXW) #undef NB_CUSTOM_MESSAGEBOXW #endif