From 9c8409da79196441817709b590cc5152936afc56 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 23 Dec 2016 20:18:42 +0300 Subject: minor code cleaning --- plugins/Scriver/src/globals.h | 1 - plugins/Scriver/src/msgs.h | 1 - plugins/Scriver/src/msgwindow.cpp | 99 ++++++++++++++++++++------------------- 3 files changed, 51 insertions(+), 50 deletions(-) (limited to 'plugins/Scriver/src') diff --git a/plugins/Scriver/src/globals.h b/plugins/Scriver/src/globals.h index bf78d0b259..a396493a4a 100644 --- a/plugins/Scriver/src/globals.h +++ b/plugins/Scriver/src/globals.h @@ -126,7 +126,6 @@ void ReleaseIcons(); void LoadGlobalIcons(); HICON GetCachedIcon(const char *name); void RegisterFontServiceFonts(); -int ScriverRestoreWindowPosition(HWND hwnd, MCONTACT hContact, const char *szModule, const char *szNamePrefix, int flags, int showCmd); int ImageList_AddIcon_Ex(HIMAGELIST hIml, int id); int ImageList_AddIcon_Ex2(HIMAGELIST hIml, HICON hIcon); diff --git a/plugins/Scriver/src/msgs.h b/plugins/Scriver/src/msgs.h index a4e6d42553..2a2ba4411c 100644 --- a/plugins/Scriver/src/msgs.h +++ b/plugins/Scriver/src/msgs.h @@ -215,7 +215,6 @@ struct CREOleCallback2 : public CREOleCallback STDMETHOD(QueryAcceptData) (LPDATAOBJECT lpdataobj, CLIPFORMAT FAR *lpcfFormat, DWORD reco, BOOL fReally, HGLOBAL hMetaPict); }; -INT_PTR CALLBACK DlgProcParentWindow(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK ErrorDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); int DbEventIsShown(DBEVENTINFO &dbei); diff --git a/plugins/Scriver/src/msgwindow.cpp b/plugins/Scriver/src/msgwindow.cpp index eea70544f1..9c18edc424 100644 --- a/plugins/Scriver/src/msgwindow.cpp +++ b/plugins/Scriver/src/msgwindow.cpp @@ -489,16 +489,17 @@ LRESULT CALLBACK TabCtrlProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) UpdateWindow(hwnd); } else if (thinfo.flags == TCHT_NOWHERE) { - TCITEM tci; - POINT pt; - NewMessageWindowLParam newData = { 0 }; dat->destTab = -1; + + TCITEM tci; tci.mask = TCIF_PARAM; TabCtrl_GetItem(hwnd, dat->srcTab, &tci); MessageWindowTabData *mwtd = (MessageWindowTabData *)tci.lParam; if (mwtd != NULL) { HWND hChild = mwtd->hwnd; MCONTACT hContact = mwtd->hContact; + + POINT pt; GetCursorPos(&pt); HWND hParent = WindowFromPoint(pt); while (GetParent(hParent) != NULL) @@ -507,19 +508,22 @@ LRESULT CALLBACK TabCtrlProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) hParent = WindowList_Find(g_dat.hParentWindowList, (UINT_PTR)hParent); if ((hParent != NULL && hParent != GetParent(hwnd)) || (hParent == NULL && mwtd->parent->childrenCount > 1 && (GetKeyState(VK_CONTROL) & 0x8000))) { if (hParent == NULL) { - RECT rc, rcDesktop; - newData.hContact = hContact; - hParent = (HWND)CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_MSGWIN), NULL, DlgProcParentWindow, (LPARAM)&newData); + hParent = GetParentWindow(hContact, FALSE); + + RECT rc; GetWindowRect(hParent, &rc); + rc.right = (rc.right - rc.left); rc.bottom = (rc.bottom - rc.top); rc.left = pt.x - rc.right / 2; rc.top = pt.y - rc.bottom / 2; HMONITOR hMonitor = MonitorFromRect(&rc, MONITOR_DEFAULTTONEAREST); + MONITORINFO mi; mi.cbSize = sizeof(mi); GetMonitorInfo(hMonitor, &mi); - rcDesktop = mi.rcWork; + + RECT rcDesktop = mi.rcWork; if (rc.left < rcDesktop.left) rc.left = rcDesktop.left; if (rc.top < rcDesktop.top) @@ -586,8 +590,7 @@ LRESULT CALLBACK TabCtrlProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) } else SendMessage(hwnd, WM_LBUTTONDOWN, dat->clickWParam, dat->clickLParam); - dat->bDragged = FALSE; - dat->bDragging = FALSE; + dat->bDragged = dat->bDragging = FALSE; dat->destTab = -1; ReleaseCapture(); } @@ -678,7 +681,45 @@ __forceinline void UnsubclassTabCtrl(HWND hwnd) ///////////////////////////////////////////////////////////////////////////////////////// -INT_PTR CALLBACK DlgProcParentWindow(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +static int ScriverRestoreWindowPosition(HWND hwnd, MCONTACT hContact, const char *szModule, const char *szNamePrefix, int flags, int showCmd) +{ + WINDOWPLACEMENT wp; + wp.length = sizeof(wp); + GetWindowPlacement(hwnd, &wp); + + char szSettingName[64]; + mir_snprintf(szSettingName, "%sx", szNamePrefix); + int x = db_get_dw(hContact, szModule, szSettingName, -1); + mir_snprintf(szSettingName, "%sy", szNamePrefix); + int y = db_get_dw(hContact, szModule, szSettingName, -1); + if (x == -1) + return 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, "%swidth", szNamePrefix); + wp.rcNormalPosition.right = wp.rcNormalPosition.left + db_get_dw(hContact, szModule, szSettingName, -1); + mir_snprintf(szSettingName, "%sheight", szNamePrefix); + wp.rcNormalPosition.bottom = wp.rcNormalPosition.top + db_get_dw(hContact, szModule, szSettingName, -1); + } + wp.flags = 0; + wp.showCmd = showCmd; + + HMONITOR hMonitor = MonitorFromRect(&wp.rcNormalPosition, MONITOR_DEFAULTTONEAREST); + MONITORINFO mi; + mi.cbSize = sizeof(mi); + GetMonitorInfo(hMonitor, &mi); + RECT rcDesktop = mi.rcWork; + if (wp.rcNormalPosition.left > rcDesktop.right || wp.rcNormalPosition.top > rcDesktop.bottom || + wp.rcNormalPosition.right < rcDesktop.left || wp.rcNormalPosition.bottom < rcDesktop.top) return 1; + SetWindowPlacement(hwnd, &wp); + return 0; +} + +static INT_PTR CALLBACK DlgProcParentWindow(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { ParentWindowData *dat = (ParentWindowData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); if (!dat && msg != WM_INITDIALOG) @@ -1450,44 +1491,6 @@ static void DrawTab(ParentWindowData *dat, HWND hwnd, WPARAM, LPARAM lParam) } } -int ScriverRestoreWindowPosition(HWND hwnd, MCONTACT hContact, const char *szModule, const char *szNamePrefix, int flags, int showCmd) -{ - WINDOWPLACEMENT wp; - wp.length = sizeof(wp); - GetWindowPlacement(hwnd, &wp); - - char szSettingName[64]; - mir_snprintf(szSettingName, "%sx", szNamePrefix); - int x = db_get_dw(hContact, szModule, szSettingName, -1); - mir_snprintf(szSettingName, "%sy", szNamePrefix); - int y = db_get_dw(hContact, szModule, szSettingName, -1); - if (x == -1) - return 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, "%swidth", szNamePrefix); - wp.rcNormalPosition.right = wp.rcNormalPosition.left + db_get_dw(hContact, szModule, szSettingName, -1); - mir_snprintf(szSettingName, "%sheight", szNamePrefix); - wp.rcNormalPosition.bottom = wp.rcNormalPosition.top + db_get_dw(hContact, szModule, szSettingName, -1); - } - wp.flags = 0; - wp.showCmd = showCmd; - - HMONITOR hMonitor = MonitorFromRect(&wp.rcNormalPosition, MONITOR_DEFAULTTONEAREST); - MONITORINFO mi; - mi.cbSize = sizeof(mi); - GetMonitorInfo(hMonitor, &mi); - RECT rcDesktop = mi.rcWork; - if (wp.rcNormalPosition.left > rcDesktop.right || wp.rcNormalPosition.top > rcDesktop.bottom || - wp.rcNormalPosition.right < rcDesktop.left || wp.rcNormalPosition.bottom < rcDesktop.top) return 1; - SetWindowPlacement(hwnd, &wp); - return 0; -} - HWND GetParentWindow(MCONTACT hContact, BOOL bChat) { NewMessageWindowLParam newData = { 0 }; -- cgit v1.2.3