From a75ce08f5ea46237b73e5052a956829c0e272678 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 17 Jun 2015 17:03:45 +0000 Subject: minus MS_UTILS_SAVEWINDOWPOSITION & MS_UTILS_RESTOREWINDOWPOSITION git-svn-id: http://svn.miranda-ng.org/main/trunk@14238 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- bin10/lib/mir_core.lib | Bin 324788 -> 325610 bytes bin10/lib/mir_core64.lib | Bin 327292 -> 328046 bytes bin12/lib/mir_core.lib | Bin 324788 -> 325610 bytes bin12/lib/mir_core64.lib | Bin 327292 -> 328046 bytes include/delphi/m_helpers.inc | 26 ----- include/delphi/m_utils.inc | 142 +++++++++++++------------- include/m_utils.h | 54 +++------- plugins/Console/src/Console.cpp | 4 +- plugins/RecentContacts/src/RecentContacts.cpp | 36 ++----- plugins/TooltipNotify/src/TooltipNotify.cpp | 6 +- src/core/stdfile/src/ftmanager.cpp | 6 +- src/core/stdmsg/src/msgdialog.cpp | 4 +- src/mir_app/src/clistmod.cpp | 2 +- src/mir_app/src/clui.cpp | 4 +- src/mir_app/src/miranda.h | 1 - src/mir_app/src/utils.cpp | 96 ----------------- src/mir_core/src/mir_core.def | 3 + src/mir_core/src/mir_core64.def | 3 + src/mir_core/src/winutil.cpp | 118 +++++++++++++++++++++ 19 files changed, 229 insertions(+), 276 deletions(-) create mode 100644 src/mir_core/src/winutil.cpp diff --git a/bin10/lib/mir_core.lib b/bin10/lib/mir_core.lib index 67991d4f4f..f50edb3dee 100644 Binary files a/bin10/lib/mir_core.lib and b/bin10/lib/mir_core.lib differ diff --git a/bin10/lib/mir_core64.lib b/bin10/lib/mir_core64.lib index 82363fc109..c4e2cb1505 100644 Binary files a/bin10/lib/mir_core64.lib and b/bin10/lib/mir_core64.lib differ diff --git a/bin12/lib/mir_core.lib b/bin12/lib/mir_core.lib index 67991d4f4f..f50edb3dee 100644 Binary files a/bin12/lib/mir_core.lib and b/bin12/lib/mir_core.lib differ diff --git a/bin12/lib/mir_core64.lib b/bin12/lib/mir_core64.lib index 82363fc109..c4e2cb1505 100644 Binary files a/bin12/lib/mir_core64.lib and b/bin12/lib/mir_core64.lib differ diff --git a/include/delphi/m_helpers.inc b/include/delphi/m_helpers.inc index 86bee1a2d6..f21a2c3f08 100644 --- a/include/delphi/m_helpers.inc +++ b/include/delphi/m_helpers.inc @@ -28,9 +28,6 @@ function Netlib_Send(hConn: THANDLE; const buf: PAnsiChar; len: int; flags: int) function Netlib_Recv(hConn: THANDLE; const buf: PAnsiChar; len: int; flags: int): int_ptr; procedure Netlib_Log(hNetLib: THANDLE; const sz: PAnsiChar); -function Utils_SaveWindowPosition (hWnd:HWND; hContact:TMCONTACT; const szModule, szNamePrefix: PAnsiChar): int_ptr; -function Utils_RestoreWindowPosition(hWnd:HWND; hContact:TMCONTACT; Flags: int; const szModule, szNamePrefix: PAnsiChar): int_ptr; - function mir_hashstr (const key:PAnsiChar):uint; {inline;} function mir_hashstrW(const key:PWideChar):uint; {inline;} function lrtrim (str:PAnsiChar):PAnsiChar; {inline} @@ -242,29 +239,6 @@ begin end; -function Utils_SaveWindowPosition(hWnd:HWND; hContact:TMCONTACT; const szModule, szNamePrefix: PAnsiChar): int_ptr; -var - swp: TSAVEWINDOWPOS; -begin - swp.hWnd := hWnd; - swp.hContact := hContact; - swp.szModule := szModule; - swp.szNamePrefix := szNamePrefix; - Result := CallService(MS_UTILS_SAVEWINDOWPOSITION, 0, lParam(@swp)); -end; - -function Utils_RestoreWindowPosition(hWnd:HWND; hContact:TMCONTACT; Flags:int; const szModule, szNamePrefix: PAnsiChar): int_ptr; -var - swp: TSAVEWINDOWPOS; -begin - swp.hWnd := hWnd; - swp.hContact := hContact; - swp.szModule := szModule; - swp.szNamePrefix := szNamePrefix; - Result := CallService(MS_UTILS_RESTOREWINDOWPOSITION, Flags, lParam(@swp)); -end; - - function mir_hashstr(const key:PAnsiChar):uint; {inline;} var len:int; diff --git a/include/delphi/m_utils.inc b/include/delphi/m_utils.inc index dea6497f48..23e4d240b7 100644 --- a/include/delphi/m_utils.inc +++ b/include/delphi/m_utils.inc @@ -154,10 +154,10 @@ const //******************************* Window lists ******************************* - { - Affect : Allocate a window list - Returns: A handle to the new window list - } +{ + Affect : Allocate a window list + Returns: A handle to the new window list +} function WindowList_Create() : Thandle; stdcall; external CoreDLL name 'WindowList_Create'; @@ -165,109 +165,105 @@ function WindowList_Create() : Thandle; stdcall; procedure WindowList_Destroy(hList:Thandle); stdcall; external CoreDLL name 'WindowList_Destroy'; - { - Affect : Add a window to a given window list handle - Returns: 0 on success, [non zero] on failure - } +{ + Affect : Add a window to a given window list handle + Returns: 0 on success, [non zero] on failure +} function WindowList_Add(hList:Thandle; hwnd:HWND; hContact:TMCONTACT) : int; stdcall; external CoreDLL name 'WindowList_Add'; - { - Affect : Remove a window from the specified window list - Returns: 0 on success, [non zero] on failure - } +{ + Affect : Remove a window from the specified window list + Returns: 0 on success, [non zero] on failure +} function WindowList_Remove(hList:Thandle; hwnd:HWND) : int; stdcall; external CoreDLL name 'WindowList_Remove'; - { - Affect : Find a window handle given the hContact - Returns: The found window handle or NULL(0) on failure - } +{ + Affect : Find a window handle given the hContact + Returns: The found window handle or NULL(0) on failure +} function WindowList_Find(hList:Thandle; hContact:TMCONTACT) : HWND; stdcall; external CoreDLL name 'WindowList_Find'; - { - Affect : sends a message to all windows in a list using SendMessage - Returns: 0 on success, [non zero] on failure - } +{ + Affect : sends a message to all windows in a list using SendMessage + Returns: 0 on success, [non zero] on failure +} function WindowList_Broadcast(hList:Thandle; message:UINT; wParam:TWPARAM; lParam:TLPARAM) : int; stdcall; external CoreDLL name 'WindowList_Broadcast'; - { - Affect : Sends a message to all windows in a list using PostMessage - Returns: 0 on success, nonzero on failure, this service does not fail, - even if PostMessage() fails for whatever reason - } +{ + Affect : Sends a message to all windows in a list using PostMessage + Returns: 0 on success, nonzero on failure, this service does not fail, + even if PostMessage() fails for whatever reason +} function WindowList_BroadcastAsync(hList:Thandle; message:UINT; wParam:TWPARAM; lParam:TLPARAM) : int; stdcall; external CoreDLL name 'WindowList_BroadcastAsync'; - { - There aren't any services here, there's no need for them, the control class - will obey the SS_LEFT (0), SS_CENTER (1), SS_RIGHT(2) styles - the control will send STN_CLICKED via WM_COMMAND when the link itself is clicked - - - These are defined by STATIC controls and STN_CLICKED is sent to standard - STATIC classes when they're clicked -- look at WINAPI docs for more info - } +{ + There aren't any services here, there's no need for them, the control class + will obey the SS_LEFT (0), SS_CENTER (1), SS_RIGHT(2) styles + the control will send STN_CLICKED via WM_COMMAND when the link itself is clicked + - + These are defined by STATIC controls and STN_CLICKED is sent to standard + STATIC classes when they're clicked -- look at WINAPI docs for more info +} const WNDCLASS_HYPERLINK = 'Hyperlink'; - { - wParam : 0 - lParam : Pointer to a initialised TSAVEWINDOWPOS structure - Affect : - Returns: 0 on success, [non zero] on failure - Notes : - Version: v0.1.1.0+ - } - MS_UTILS_SAVEWINDOWPOSITION:PAnsiChar = 'Utils/SaveWindowPos'; +{ + Returns: 0 on success, [non zero] on failure +} - { - wParam : see RWPF_* flags - lParam : Pointer to a initalised TSAVEWINDOWPOS - Affect : Restores the position of a window from the database, see notes - Returns: 0 on success, [non zero] on failure - Notes : If no position info was found, the service will return 1. - The NoSize version won't use stored information size, the window - is left the same size - - - See Utils_RestoreWindowPosition() Helper function, this function is - a bit different from the C function (which can be inlined too! dammit) - that there's only one function and not three (which just passed different flags) - Version: v0.1.1.0+ - } - MS_UTILS_RESTOREWINDOWPOSITION:PAnsiChar = 'Utils/RestoreWindowPos'; +function Utils_SaveWindowPosition(hwnd:HWND; hContact:TMCONTACT; const szModule,szNamePrefix:PAnsiChar) : int; stdcall; + external CoreDLL name 'Utils_SaveWindowPosition'; + +{ + Affect : Restores the position of a window from the database, see notes + Returns: 0 on success, [non zero] on failure + Notes : If no position info was found, the service will return 1. + The NoSize version won't use stored information size, the window + is left the same size + - + See Utils_RestoreWindowPosition() Helper function, this function is + a bit different from the C function (which can be inlined too! dammit) + that there's only one function and not three (which just passed different flags) +} + +function Utils_RestoreWindowPosition(hwnd:HWND; hContact:TMCONTACT; const szModule,szNamePrefix:PAnsiChar; flags:int) : int; stdcall; + external CoreDLL name 'Utils_RestoreWindowPosition'; { - wParam : pointer to RECT - lParam : 0 Affect : Moves a RECT inside screen if it is outside.It works with multiple monitors (v0.9.0.4+) Returns: <0 on error, 0 if not changed the rect, 1 if changed the rect } - MS_UTILS_ASSERTINSIDESCREEN:PAnsiChar = 'Utils/AssertInsideScreen'; - { - wParam : 0 - lParam : Pointer to a null terminated string containing filename - Affect : Loads a bitmap (or other graphic type, see Notes - Returns: HBITMAP on success, NULL(0) on failure - Notes : This function also supports JPEG, GIF (and maybe PNG too) - For speed, if the file extention is .bmp or .rle it will use LoadImage() - and not load OLE for the extra image support - - - Remember to delete the returned handle with DeleteObject (see GDI documentation for WINAPI) - Version: v0.1.2.1+ - } +function Utils_AssertInsideScreen(var rc:RECT) : int; stdcall; + external CoreDLL name 'Utils_AssertInsideScreen'; + +{ + wParam : 0 + lParam : Pointer to a null terminated string containing filename + Affect : Loads a bitmap (or other graphic type, see Notes + Returns: HBITMAP on success, NULL(0) on failure + Notes : This function also supports JPEG, GIF (and maybe PNG too) + For speed, if the file extention is .bmp or .rle it will use LoadImage() + and not load OLE for the extra image support + - + Remember to delete the returned handle with DeleteObject (see GDI documentation for WINAPI) +} + +const MS_UTILS_LOADBITMAP :PAnsiChar = 'Utils/LoadBitmap'; MS_UTILS_LOADBITMAPW:PAnsiChar = 'Utils/LoadBitmapW'; - { Affect : Saves a path to a relative path (from the miranda directory) Only saves as a relative path if the file is in the miranda diff --git a/include/m_utils.h b/include/m_utils.h index 9d9d689e3a..72508724ee 100644 --- a/include/m_utils.h +++ b/include/m_utils.h @@ -207,25 +207,14 @@ EXTERN_C MIR_CORE_DLL(int) WindowList_BroadcastAsync(MWindowList hList, UINT mes // lParam = not used #define HLK_SETDISABLECOLOUR (WM_USER+102) // added in 0.3.1 -/***************************** Window Position Saving ***************************/ +///////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////////// Window Position Saving //////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// -// saves the position of a window in the database v0.1.1.0+ -// wParam = 0 -// lParam = (LPARAM)(SAVEWINDOWPOS*)&swp +// saves the position of a window in the database // returns 0 on success, nonzero on failure -typedef struct { - HWND hwnd; - MCONTACT hContact; - const char *szModule; //module name to store the setting in - const char *szNamePrefix; //text to prefix on "x", "width", etc, to form setting names -} SAVEWINDOWPOS; -#define MS_UTILS_SAVEWINDOWPOSITION "Utils/SaveWindowPos" -__forceinline INT_PTR Utils_SaveWindowPosition(HWND hwnd, MCONTACT hContact, const char *szModule, const char *szNamePrefix) { - SAVEWINDOWPOS swp; - swp.hwnd = hwnd; swp.hContact = hContact; swp.szModule = szModule; swp.szNamePrefix = szNamePrefix; - return CallService(MS_UTILS_SAVEWINDOWPOSITION, 0, (LPARAM)&swp); -} + +EXTERN_C MIR_CORE_DLL(int) Utils_SaveWindowPosition(HWND hwnd, MCONTACT hContact, const char *szModule, const char *szNamePrefix); ///////////////////////////////////////////////////////////////////////////////////////// // restores the position of a window from the database v0.1.1.0+ @@ -240,32 +229,21 @@ __forceinline INT_PTR Utils_SaveWindowPosition(HWND hwnd, MCONTACT hContact, con #define RWPF_NOMOVE 2 //don't use stored position #define RWPF_NOACTIVATE 4 //show but don't activate v0.3.3.0+ #define RWPF_HIDDEN 8 //make it hidden -#define MS_UTILS_RESTOREWINDOWPOSITION "Utils/RestoreWindowPos" -__forceinline INT_PTR Utils_RestoreWindowPositionEx(HWND hwnd, int flags, MCONTACT hContact, const char *szModule, const char *szNamePrefix) { - SAVEWINDOWPOS swp; - swp.hwnd = hwnd; swp.hContact = hContact; swp.szModule = szModule; swp.szNamePrefix = szNamePrefix; - return CallService(MS_UTILS_RESTOREWINDOWPOSITION, flags, (LPARAM)&swp); -} -__forceinline INT_PTR Utils_RestoreWindowPosition(HWND hwnd, MCONTACT hContact, const char *szModule, const char *szNamePrefix) { - return Utils_RestoreWindowPositionEx(hwnd, 0, hContact, szModule, szNamePrefix); -} -__forceinline INT_PTR Utils_RestoreWindowPositionNoSize(HWND hwnd, MCONTACT hContact, const char *szModule, const char *szNamePrefix) { - return Utils_RestoreWindowPositionEx(hwnd, RWPF_NOSIZE, hContact, szModule, szNamePrefix); + +EXTERN_C MIR_CORE_DLL(int) Utils_RestoreWindowPosition(HWND hwnd, MCONTACT hContact, const char *szModule, const char *szNamePrefix, int flags = 0); + +__forceinline int Utils_RestoreWindowPositionNoSize(HWND hwnd, MCONTACT hContact, const char *szModule, const char *szNamePrefix) +{ return Utils_RestoreWindowPosition(hwnd, hContact, szModule, szNamePrefix, RWPF_NOSIZE); } -__forceinline INT_PTR Utils_RestoreWindowPositionNoMove(HWND hwnd, MCONTACT hContact, const char *szModule, const char *szNamePrefix) { - return Utils_RestoreWindowPositionEx(hwnd, RWPF_NOMOVE, hContact, szModule, szNamePrefix); +__forceinline int Utils_RestoreWindowPositionNoMove(HWND hwnd, MCONTACT hContact, const char *szModule, const char *szNamePrefix) +{ return Utils_RestoreWindowPosition(hwnd, hContact, szModule, szNamePrefix, RWPF_NOMOVE); } ///////////////////////////////////////////////////////////////////////////////////////// -// Moves a RECT inside screen if it is outside.It works with multiple monitors v0.9.0.4+ -// wParam = RECT * -// lParam = 0 -// returns <0 on error, 0 if not changed the rect, 1 if changed the rect - -#define MS_UTILS_ASSERTINSIDESCREEN "Utils/AssertInsideScreen" -__forceinline INT_PTR Utils_AssertInsideScreen(RECT *rc) { - return CallService(MS_UTILS_ASSERTINSIDESCREEN, (WPARAM)rc, 0); -} +// Moves a RECT inside screen if it is outside. It works with multiple monitors +// returns < 0 on error, 0 if not changed the rect, 1 if changed the rect + +EXTERN_C MIR_CORE_DLL(int) Utils_AssertInsideScreen(RECT *rc); /************************ Colour Picker Control (0.1.2.1+) **********************/ diff --git a/plugins/Console/src/Console.cpp b/plugins/Console/src/Console.cpp index 56e22e7f6d..4ab6c325c4 100644 --- a/plugins/Console/src/Console.cpp +++ b/plugins/Console/src/Console.cpp @@ -625,10 +625,8 @@ static INT_PTR CALLBACK ConsoleDlgProc(HWND hwndDlg, UINT message, WPARAM wParam hTabs = GetDlgItem(hwndDlg, IDC_TABS); - //TabCtrl_SetMinTabWidth(hTabs, 100); - // restore position - Utils_RestoreWindowPositionEx(hwndDlg, RWPF_HIDDEN, NULL, "Console", "Console"); + Utils_RestoreWindowPosition(hwndDlg, NULL, "Console", "Console", RWPF_HIDDEN); CallService(MS_DB_GETPROFILENAMET, (WPARAM)SIZEOF(name), (LPARAM)name); diff --git a/plugins/RecentContacts/src/RecentContacts.cpp b/plugins/RecentContacts/src/RecentContacts.cpp index dc8ac0b113..1e8a7ef15f 100644 --- a/plugins/RecentContacts/src/RecentContacts.cpp +++ b/plugins/RecentContacts/src/RecentContacts.cpp @@ -291,20 +291,12 @@ INT_PTR CALLBACK ShowListMainDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM wp.flags = 0; SetWindowPlacement(hDlg, &wp); - } else { - restorePos = true; } + else restorePos = true; } - if (restorePos) { - SAVEWINDOWPOS pos; - pos.hContact = NULL; - pos.hwnd = hDlg; - pos.szModule = dbLastUC_ModuleName; - pos.szNamePrefix = dbLastUC_WindowPosPrefix; - - CallService(MS_UTILS_RESTOREWINDOWPOSITION, 0, (LPARAM)&pos); - } + if (restorePos) + Utils_RestoreWindowPosition(hDlg, NULL, dbLastUC_ModuleName, dbLastUC_WindowPosPrefix); SendMessage(hDlg, WM_SIZE, 0, 0); WindowList_Add(hWindowList, hDlg, NULL); @@ -385,20 +377,14 @@ INT_PTR CALLBACK ShowListMainDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM break; case WM_DESTROY: - { - // Save current window position. - SAVEWINDOWPOS pos; - pos.hContact = NULL; - pos.hwnd = hDlg; - pos.szModule = dbLastUC_ModuleName; - pos.szNamePrefix = dbLastUC_WindowPosPrefix; - CallService(MS_UTILS_SAVEWINDOWPOSITION, 0, (LPARAM)&pos); - delete DlgDat->Contacts; - delete DlgDat; - // Remove entry from Window list - WindowList_Remove(hWindowList, hDlg); - break; - } + Utils_SaveWindowPosition(hDlg, NULL, dbLastUC_ModuleName, dbLastUC_WindowPosPrefix); + + delete DlgDat->Contacts; + delete DlgDat; + + // Remove entry from Window list + WindowList_Remove(hWindowList, hDlg); + break; } return FALSE; } diff --git a/plugins/TooltipNotify/src/TooltipNotify.cpp b/plugins/TooltipNotify/src/TooltipNotify.cpp index e1ab66d706..c51b7da658 100644 --- a/plugins/TooltipNotify/src/TooltipNotify.cpp +++ b/plugins/TooltipNotify/src/TooltipNotify.cpp @@ -306,10 +306,8 @@ CTooltip *CTooltipNotify::BeginNotify(STooltipData *pTooltipData) SystemParametersInfo(SPI_GETWORKAREA, 0, &WorkAreaRect, 0); pTooltip->get_Rect(&TooltipRect); - if (m_sOptions.bAutoPos || Utils_RestoreWindowPositionEx(pTooltip->GetHandle(), RWPF_NOSIZE | RWPF_NOACTIVATE, 0, MODULENAME, "toolwindow")) - pTooltip->set_Position( - WorkAreaRect.right - 10 - (TooltipRect.right-TooltipRect.left), - WorkAreaRect.bottom - 2 - (TooltipRect.bottom-TooltipRect.top)); + if (m_sOptions.bAutoPos || Utils_RestoreWindowPosition(pTooltip->GetHandle(), 0, MODULENAME, "toolwindow", RWPF_NOSIZE | RWPF_NOACTIVATE)) + pTooltip->set_Position(WorkAreaRect.right - 10 - (TooltipRect.right-TooltipRect.left), WorkAreaRect.bottom - 2 - (TooltipRect.bottom-TooltipRect.top)); UINT_PTR idTimer = SetTimer(0, 0, pTooltipData->uiTimeout, TooltipTimerProcWrapper); pTooltipData->idTimer = idTimer; diff --git a/src/core/stdfile/src/ftmanager.cpp b/src/core/stdfile/src/ftmanager.cpp index 139ffbffbd..35af052eb7 100644 --- a/src/core/stdfile/src/ftmanager.cpp +++ b/src/core/stdfile/src/ftmanager.cpp @@ -288,11 +288,7 @@ static INT_PTR CALLBACK FtMgrDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM tci.lParam = (LPARAM)dat->hwndOutgoing; TabCtrl_InsertItem(hwndTab, 1, &tci); - // Utils_RestoreWindowPosition(hwnd, NULL, "SRFile", "FtMgrDlg_"); - SAVEWINDOWPOS swp; - swp.hwnd = hwnd; swp.hContact = NULL; swp.szModule = "SRFile"; swp.szNamePrefix = "FtMgrDlg_"; - CallService(MS_UTILS_RESTOREWINDOWPOSITION, RWPF_NOACTIVATE, (LPARAM)&swp); - + Utils_RestoreWindowPosition(hwnd, NULL, "SRFile", "FtMgrDlg_", RWPF_NOACTIVATE); // Fall through to setup initial placement } case WM_SIZE: diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp index 775a202f20..b3a9bc050a 100644 --- a/src/core/stdmsg/src/msgdialog.cpp +++ b/src/core/stdmsg/src/msgdialog.cpp @@ -779,9 +779,9 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP { int flag = newData->noActivate ? RWPF_HIDDEN : 0; int savePerContact = db_get_b(NULL, SRMMMOD, SRMSGSET_SAVEPERCONTACT, SRMSGDEFSET_SAVEPERCONTACT); - if (Utils_RestoreWindowPositionEx(hwndDlg, flag, savePerContact ? dat->hContact : NULL, SRMMMOD, "")) { + if (Utils_RestoreWindowPosition(hwndDlg, savePerContact ? dat->hContact : NULL, SRMMMOD, "", flag)) { if (savePerContact) { - if (Utils_RestoreWindowPositionEx(hwndDlg, flag | RWPF_NOMOVE, NULL, SRMMMOD, "")) + if (Utils_RestoreWindowPosition(hwndDlg, NULL, SRMMMOD, "", flag | RWPF_NOMOVE)) SetWindowPos(hwndDlg, 0, 0, 0, 450, 300, SWP_NOZORDER | SWP_NOMOVE | SWP_SHOWWINDOW); } else SetWindowPos(hwndDlg, 0, 0, 0, 450, 300, SWP_NOZORDER | SWP_NOMOVE | SWP_SHOWWINDOW); diff --git a/src/mir_app/src/clistmod.cpp b/src/mir_app/src/clistmod.cpp index b124fffe8f..1b11108836 100644 --- a/src/mir_app/src/clistmod.cpp +++ b/src/mir_app/src/clistmod.cpp @@ -389,7 +389,7 @@ int fnShowHide(WPARAM, LPARAM) //this forces the window onto the visible screen GetWindowRect(cli.hwndContactList, &rcWindow); - if (AssertInsideScreen(rcWindow) == 1) { + if (Utils_AssertInsideScreen(&rcWindow) == 1) { MoveWindow(cli.hwndContactList, rcWindow.left, rcWindow.top, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top, TRUE); } diff --git a/src/mir_app/src/clui.cpp b/src/mir_app/src/clui.cpp index 0ee56992a9..773e68fb5b 100644 --- a/src/mir_app/src/clui.cpp +++ b/src/mir_app/src/clui.cpp @@ -291,7 +291,7 @@ int LoadCLUIModule(void) pos.right = pos.left + (int)db_get_dw(NULL, "CList", "Width", 108); pos.bottom = pos.top + (int)db_get_dw(NULL, "CList", "Height", 310); - AssertInsideScreen(pos); + Utils_AssertInsideScreen(&pos); cli.hwndContactList = CreateWindowEx( (db_get_b(NULL, "CList", "ToolWindow", SETTING_TOOLWINDOW_DEFAULT) ? WS_EX_TOOLWINDOW : WS_EX_APPWINDOW), @@ -750,7 +750,7 @@ LRESULT CALLBACK fnContactListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM { RECT rc; GetWindowRect(hwnd, &rc); - if (AssertInsideScreen(rc) == 1) + if (Utils_AssertInsideScreen(&rc) == 1) MoveWindow(hwnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE); } return DefWindowProc(hwnd, msg, wParam, lParam); diff --git a/src/mir_app/src/miranda.h b/src/mir_app/src/miranda.h index eceac3e7c0..174a79d2ca 100644 --- a/src/mir_app/src/miranda.h +++ b/src/mir_app/src/miranda.h @@ -172,7 +172,6 @@ INT_PTR CallProtoServiceInt(MCONTACT hContact, const char* szModule, const char* void HotkeyToName(TCHAR *buf, int size, BYTE shift, BYTE key); WORD GetHotkeyValue(INT_PTR idHotkey); -int AssertInsideScreen(RECT &rc); HBITMAP ConvertIconToBitmap(HICON hIcon, HIMAGELIST hIml, int iconId); diff --git a/src/mir_app/src/utils.cpp b/src/mir_app/src/utils.cpp index cebebc6e5f..2b96d5f4cf 100644 --- a/src/mir_app/src/utils.cpp +++ b/src/mir_app/src/utils.cpp @@ -325,99 +325,6 @@ static INT_PTR GetCountryList(WPARAM wParam, LPARAM lParam) ///////////////////////////////////////////////////////////////////////////////////////// -static INT_PTR SaveWindowPosition(WPARAM, LPARAM lParam) -{ - SAVEWINDOWPOS *swp = (SAVEWINDOWPOS*)lParam; - WINDOWPLACEMENT wp; - char szSettingName[64]; - - wp.length = sizeof(wp); - GetWindowPlacement(swp->hwnd, &wp); - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sx", swp->szNamePrefix); - db_set_dw(swp->hContact, swp->szModule, szSettingName, wp.rcNormalPosition.left); - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sy", swp->szNamePrefix); - db_set_dw(swp->hContact, swp->szModule, szSettingName, wp.rcNormalPosition.top); - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%swidth", swp->szNamePrefix); - db_set_dw(swp->hContact, swp->szModule, szSettingName, wp.rcNormalPosition.right-wp.rcNormalPosition.left); - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sheight", swp->szNamePrefix); - db_set_dw(swp->hContact, swp->szModule, szSettingName, wp.rcNormalPosition.bottom-wp.rcNormalPosition.top); - return 0; -} - -static INT_PTR svcAssertInsideScreen(WPARAM wParam, LPARAM) -{ - LPRECT rc = (LPRECT)wParam; - if (rc == NULL) - return -1; - - return AssertInsideScreen(*rc); -} - -int AssertInsideScreen(RECT &rc) -{ - RECT rcScreen; - SystemParametersInfo(SPI_GETWORKAREA, 0, &rcScreen, FALSE); - if (MonitorFromRect(&rc, MONITOR_DEFAULTTONULL)) - return 0; - - MONITORINFO mi = {0}; - HMONITOR hMonitor = MonitorFromRect(&rc, MONITOR_DEFAULTTONEAREST); - mi.cbSize = sizeof(mi); - if (GetMonitorInfo(hMonitor, &mi)) - rcScreen = mi.rcWork; - - if (rc.top >= rcScreen.bottom) - OffsetRect(&rc, 0, rcScreen.bottom - rc.bottom); - else if (rc.bottom <= rcScreen.top) - OffsetRect(&rc, 0, rcScreen.top - rc.top); - if (rc.left >= rcScreen.right) - OffsetRect(&rc, rcScreen.right - rc.right, 0); - else if (rc.right <= rcScreen.left) - OffsetRect(&rc, rcScreen.left - rc.left, 0); - - return 1; -} - -static INT_PTR RestoreWindowPosition(WPARAM wParam, LPARAM lParam) -{ - SAVEWINDOWPOS *swp = (SAVEWINDOWPOS*)lParam; - WINDOWPLACEMENT wp; - char szSettingName[64]; - int x, y; - - wp.length = sizeof(wp); - GetWindowPlacement(swp->hwnd, &wp); - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sx", swp->szNamePrefix); - x = db_get_dw(swp->hContact, swp->szModule, szSettingName, -1); - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sy", swp->szNamePrefix); - y = (int)db_get_dw(swp->hContact, swp->szModule, szSettingName, -1); - if (x == -1) return 1; - if (wParam&RWPF_NOSIZE) { - OffsetRect(&wp.rcNormalPosition, x-wp.rcNormalPosition.left, y-wp.rcNormalPosition.top); - } - else { - wp.rcNormalPosition.left = x; - wp.rcNormalPosition.top = y; - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%swidth", swp->szNamePrefix); - wp.rcNormalPosition.right = wp.rcNormalPosition.left+db_get_dw(swp->hContact, swp->szModule, szSettingName, -1); - mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sheight", swp->szNamePrefix); - wp.rcNormalPosition.bottom = wp.rcNormalPosition.top+db_get_dw(swp->hContact, swp->szModule, szSettingName, -1); - } - wp.flags = 0; - if (wParam & RWPF_HIDDEN) - wp.showCmd = SW_HIDE; - if (wParam & RWPF_NOACTIVATE) - wp.showCmd = SW_SHOWNOACTIVATE; - - if (!(wParam & RWPF_NOMOVE)) - AssertInsideScreen(wp.rcNormalPosition); - - SetWindowPlacement(swp->hwnd, &wp); - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// - static INT_PTR RestartMiranda(WPARAM wParam, LPARAM) { TCHAR mirandaPath[MAX_PATH], cmdLine[MAX_PATH]; @@ -465,9 +372,6 @@ int LoadUtilsModule(void) bModuleInitialized = TRUE; CreateServiceFunction(MS_UTILS_RESIZEDIALOG, ResizeDialog); - CreateServiceFunction(MS_UTILS_SAVEWINDOWPOSITION, SaveWindowPosition); - CreateServiceFunction(MS_UTILS_RESTOREWINDOWPOSITION, RestoreWindowPosition); - CreateServiceFunction(MS_UTILS_ASSERTINSIDESCREEN, svcAssertInsideScreen); CreateServiceFunction(MS_UTILS_GETCOUNTRYBYNUMBER, GetCountryByNumber); CreateServiceFunction(MS_UTILS_GETCOUNTRYBYISOCODE, GetCountryByISOCode); CreateServiceFunction(MS_UTILS_GETCOUNTRYLIST, GetCountryList); diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index 030e9378df..026c144ae2 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -1053,3 +1053,6 @@ WindowList_Destroy @1106 WindowList_Find @1107 WindowList_Remove @1108 ?SetSilent@CCtrlBase@@QAEXXZ @1109 NONAME +Utils_AssertInsideScreen @1110 +Utils_RestoreWindowPosition @1111 +Utils_SaveWindowPosition @1112 diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index b2139750cf..d777fb539f 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -1053,3 +1053,6 @@ WindowList_Destroy @1106 WindowList_Find @1107 WindowList_Remove @1108 ?SetSilent@CCtrlBase@@QEAAXXZ @1109 NONAME +Utils_AssertInsideScreen @1110 +Utils_RestoreWindowPosition @1111 +Utils_SaveWindowPosition @1112 diff --git a/src/mir_core/src/winutil.cpp b/src/mir_core/src/winutil.cpp new file mode 100644 index 0000000000..0dd0a2e897 --- /dev/null +++ b/src/mir_core/src/winutil.cpp @@ -0,0 +1,118 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (ñ) 2012-15 Miranda NG project (http://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_CORE_DLL(int) Utils_SaveWindowPosition(HWND hwnd, MCONTACT hContact, const char *szModule, const char *szNamePrefix) +{ + WINDOWPLACEMENT wp; + wp.length = sizeof(wp); + GetWindowPlacement(hwnd, &wp); + + char szSettingName[64]; + mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sx", szNamePrefix); + db_set_dw(hContact, szModule, szSettingName, wp.rcNormalPosition.left); + + mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sy", szNamePrefix); + db_set_dw(hContact, szModule, szSettingName, wp.rcNormalPosition.top); + + mir_snprintf(szSettingName, SIZEOF(szSettingName), "%swidth", szNamePrefix); + db_set_dw(hContact, szModule, szSettingName, wp.rcNormalPosition.right-wp.rcNormalPosition.left); + + mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sheight", szNamePrefix); + db_set_dw(hContact, szModule, szSettingName, wp.rcNormalPosition.bottom-wp.rcNormalPosition.top); + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +EXTERN_C MIR_CORE_DLL(int) Utils_RestoreWindowPosition(HWND hwnd, MCONTACT hContact, const char *szModule, const char *szNamePrefix, int flags) +{ + WINDOWPLACEMENT wp; + wp.length = sizeof(wp); + GetWindowPlacement(hwnd, &wp); + + char szSettingName[64]; + mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sx", szNamePrefix); + int x = db_get_dw(hContact, szModule, szSettingName, -1); + if (x == -1) + return 1; + + mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sy", szNamePrefix); + int y = (int)db_get_dw(hContact, szModule, szSettingName, -1); + + if (flags & RWPF_NOSIZE) + OffsetRect(&wp.rcNormalPosition, x-wp.rcNormalPosition.left, y-wp.rcNormalPosition.top); + else { + wp.rcNormalPosition.left = x; + wp.rcNormalPosition.top = y; + + mir_snprintf(szSettingName, SIZEOF(szSettingName), "%swidth", szNamePrefix); + wp.rcNormalPosition.right = wp.rcNormalPosition.left+db_get_dw(hContact, szModule, szSettingName, -1); + + mir_snprintf(szSettingName, SIZEOF(szSettingName), "%sheight", szNamePrefix); + wp.rcNormalPosition.bottom = wp.rcNormalPosition.top+db_get_dw(hContact, szModule, szSettingName, -1); + } + wp.flags = 0; + if (flags & RWPF_HIDDEN) + wp.showCmd = SW_HIDE; + if (flags & RWPF_NOACTIVATE) + wp.showCmd = SW_SHOWNOACTIVATE; + + if (!(flags & RWPF_NOMOVE)) + Utils_AssertInsideScreen(&wp.rcNormalPosition); + + SetWindowPlacement(hwnd, &wp); + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_CORE_DLL(int) Utils_AssertInsideScreen(RECT *rc) +{ + if (rc == NULL) + return -1; + + RECT rcScreen; + SystemParametersInfo(SPI_GETWORKAREA, 0, &rcScreen, FALSE); + if (MonitorFromRect(rc, MONITOR_DEFAULTTONULL)) + return 0; + + MONITORINFO mi = { 0 }; + HMONITOR hMonitor = MonitorFromRect(rc, MONITOR_DEFAULTTONEAREST); + mi.cbSize = sizeof(mi); + if (GetMonitorInfo(hMonitor, &mi)) + rcScreen = mi.rcWork; + + if (rc->top >= rcScreen.bottom) + OffsetRect(rc, 0, rcScreen.bottom - rc->bottom); + else if (rc->bottom <= rcScreen.top) + OffsetRect(rc, 0, rcScreen.top - rc->top); + if (rc->left >= rcScreen.right) + OffsetRect(rc, rcScreen.right - rc->right, 0); + else if (rc->right <= rcScreen.left) + OffsetRect(rc, rcScreen.left - rc->left, 0); + + return 1; +} -- cgit v1.2.3