From e865872b4ef16b6e40cfe868843f1070fa3a239b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 21 Jun 2015 12:01:49 +0000 Subject: - resizer moved to mir_core, because it uses hard-coded windows structures; - MS_UTILS_RESIZEDIALOG replaced with a short call of Utils_ResizeDialog; - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@14295 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/mir_core/src/mir_core.def | 1 + src/mir_core/src/mir_core64.def | 1 + src/mir_core/src/resizer.cpp | 151 ++++++++++++++++++++++++++++++++++++++++ src/mir_core/src/ui_utils.cpp | 12 +--- 4 files changed, 155 insertions(+), 10 deletions(-) create mode 100644 src/mir_core/src/resizer.cpp (limited to 'src/mir_core') diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index de7e3dba81..a86369bacb 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -969,3 +969,4 @@ TimeZone_ToLocal @1126 TimeZone_ToString @1127 TimeZone_ToStringW @1128 TimeZone_UtcToLocal @1129 +Utils_ResizeDialog @1130 diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index d827389424..0bf6458503 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -969,3 +969,4 @@ TimeZone_ToLocal @1126 TimeZone_ToString @1127 TimeZone_ToStringW @1128 TimeZone_UtcToLocal @1129 +Utils_ResizeDialog @1130 diff --git a/src/mir_core/src/resizer.cpp b/src/mir_core/src/resizer.cpp new file mode 100644 index 0000000000..cd212fdb4a --- /dev/null +++ b/src/mir_core/src/resizer.cpp @@ -0,0 +1,151 @@ +/* + +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" + +#pragma pack(2) + +struct START_OF_DLGITEMTEMPLATEEX +{ + DWORD helpID; + DWORD exStyle; + DWORD style; + short x, y, cx, cy; + DWORD id; +}; + +struct START_OF_DLGTEMPLATEEX +{ + WORD dlgVer; + WORD signature; + DWORD helpID; + DWORD exStyle; + DWORD style; + WORD cDlgItems; + short x, y, cx, cy; +}; + +MIR_CORE_DLL(int) Utils_ResizeDialog(HWND hwndDlg, HINSTANCE hInstance, LPCSTR lpTemplate, DIALOGRESIZERPROC pfnResizer, LPARAM lParam) +{ + DLGTEMPLATE *pTemplate = (DLGTEMPLATE*)LockResource(LoadResource(hInstance, FindResourceA(hInstance, lpTemplate, MAKEINTRESOURCEA(5)))); + START_OF_DLGTEMPLATEEX *pTemplateEx = (START_OF_DLGTEMPLATEEX*)pTemplate; + int extendedDlg = pTemplateEx->signature == 0xFFFF; + if (extendedDlg && pTemplateEx->dlgVer != 1) + return 1; + + PWORD pWord = (extendedDlg) ? (PWORD)(pTemplateEx + 1) : (PWORD)(pTemplate + 1); + if (*pWord == 0xFFFF) pWord += 2; else while (*pWord++); // menu + if (*pWord == 0xFFFF) pWord += 2; else while (*pWord++); // class + while (*pWord++); // skip title + if (extendedDlg) { + if (pTemplateEx->style & DS_SETFONT) { + pWord += 3; // font size, weight, italic + while (*pWord++); // font name + } + } + else { + if (pTemplate->style & DS_SETFONT) { + pWord++; // font size + while (*pWord++); // font name + } + } + + UTILRESIZECONTROL urc; + urc.cbSize = sizeof(UTILRESIZECONTROL); + + RECT rc; + rc.left = 0; rc.top = 0; + if (extendedDlg) { + rc.right = pTemplateEx->cx; + rc.bottom = pTemplateEx->cy; + } + else { + rc.right = pTemplate->cx; + rc.bottom = pTemplate->cy; + } + + MapDialogRect(hwndDlg, &rc); + urc.dlgOriginalSize.cx = rc.right; urc.dlgOriginalSize.cy = rc.bottom; + GetClientRect(hwndDlg, &rc); + urc.dlgNewSize.cx = rc.right; urc.dlgNewSize.cy = rc.bottom; + + int itemCount = (extendedDlg) ? pTemplateEx->cDlgItems : pTemplate->cdit; + + HDWP hDwp = BeginDeferWindowPos(itemCount); + for (int i = 0; i < itemCount; i++) { + if ((UINT_PTR)pWord & 2) pWord++; //dword align + + if (extendedDlg) { + START_OF_DLGITEMTEMPLATEEX *pItemEx = (START_OF_DLGITEMTEMPLATEEX*)pWord; + pWord = (PWORD)(pItemEx + 1); + + urc.wId = pItemEx->id; + urc.rcItem.left = pItemEx->x; urc.rcItem.top = pItemEx->y; + urc.rcItem.right = urc.rcItem.left + pItemEx->cx; urc.rcItem.bottom = urc.rcItem.top + pItemEx->cy; + } + else { + DLGITEMTEMPLATE *pItem = (DLGITEMTEMPLATE*)pWord; + pWord = (PWORD)(pItem + 1); + + urc.wId = pItem->id; + urc.rcItem.left = pItem->x; urc.rcItem.top = pItem->y; + urc.rcItem.right = urc.rcItem.left + pItem->cx; urc.rcItem.bottom = urc.rcItem.top + pItem->cy; + } + if (*pWord == 0xFFFF) pWord += 2; else while (*pWord++); // menu + if (*pWord == 0xFFFF) pWord += 2; else while (*pWord++); // class + pWord += 1 + (1 + *pWord) / 2; //creation data + + if (urc.wId == 65535) // using this breaks the dwp, so just ignore it + continue; + + MapDialogRect(hwndDlg, &urc.rcItem); + int procResult = (pfnResizer)(hwndDlg, lParam, &urc); + if (procResult & RD_ANCHORX_RIGHT) { + urc.rcItem.left += urc.dlgNewSize.cx - urc.dlgOriginalSize.cx; + urc.rcItem.right += urc.dlgNewSize.cx - urc.dlgOriginalSize.cx; + } + else if (procResult & RD_ANCHORX_WIDTH) + urc.rcItem.right += urc.dlgNewSize.cx - urc.dlgOriginalSize.cx; + else if (procResult & RD_ANCHORX_CENTRE) { + urc.rcItem.left += (urc.dlgNewSize.cx - urc.dlgOriginalSize.cx) / 2; + urc.rcItem.right += (urc.dlgNewSize.cx - urc.dlgOriginalSize.cx) / 2; + } + if (procResult & RD_ANCHORY_BOTTOM) { + urc.rcItem.top += urc.dlgNewSize.cy - urc.dlgOriginalSize.cy; + urc.rcItem.bottom += urc.dlgNewSize.cy - urc.dlgOriginalSize.cy; + } + else if (procResult & RD_ANCHORY_HEIGHT) + urc.rcItem.bottom += urc.dlgNewSize.cy - urc.dlgOriginalSize.cy; + else if (procResult & RD_ANCHORY_CENTRE) { + urc.rcItem.top += (urc.dlgNewSize.cy - urc.dlgOriginalSize.cy) / 2; + urc.rcItem.bottom += (urc.dlgNewSize.cy - urc.dlgOriginalSize.cy) / 2; + } + + HWND hCtrl = GetDlgItem(hwndDlg, urc.wId); + if (hCtrl != NULL) + hDwp = DeferWindowPos(hDwp, hCtrl, 0, urc.rcItem.left, urc.rcItem.top, urc.rcItem.right - urc.rcItem.left, urc.rcItem.bottom - urc.rcItem.top, SWP_NOZORDER); + } + EndDeferWindowPos(hDwp); + return 0; +} diff --git a/src/mir_core/src/ui_utils.cpp b/src/mir_core/src/ui_utils.cpp index f786afe73a..8074461f26 100644 --- a/src/mir_core/src/ui_utils.cpp +++ b/src/mir_core/src/ui_utils.cpp @@ -189,16 +189,8 @@ INT_PTR CDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) return FALSE; case WM_SIZE: - if (m_forceResizable || (GetWindowLongPtr(m_hwnd, GWL_STYLE) & WS_SIZEBOX)) { - UTILRESIZEDIALOG urd; - urd.cbSize = sizeof(urd); - urd.hwndDlg = m_hwnd; - urd.hInstance = m_hInst; - urd.lpTemplate = MAKEINTRESOURCEA(m_idDialog); - urd.lParam = 0; - urd.pfnResizer = GlobalDlgResizer; - CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd); - } + if (m_forceResizable || (GetWindowLongPtr(m_hwnd, GWL_STYLE) & WS_SIZEBOX)) + Utils_ResizeDialog(m_hwnd, m_hInst, MAKEINTRESOURCEA(m_idDialog), GlobalDlgResizer); return TRUE; case WM_CLOSE: -- cgit v1.2.3