From b35bd197611cd151433feb95f3d5f1e6c82d0163 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Mon, 6 Aug 2018 21:16:06 +0200 Subject: [PATCH] High DPI fixes for splitters and dialog resising Based on TortoiseSVN rev. 28321, 28329 and 28330. Signed-off-by: Sven Strickroth --- src/TortoiseProc/CommitDlg.cpp | 5 +-- src/TortoiseProc/ImportPatchDlg.cpp | 5 +-- src/TortoiseProc/LogDlg.cpp | 22 +++++++----- src/TortoiseProc/RepositoryBrowser.cpp | 62 ++++++++++++++++++++-------------- 4 files changed, 56 insertions(+), 38 deletions(-) diff --git a/src/TortoiseProc/CommitDlg.cpp b/src/TortoiseProc/CommitDlg.cpp index a5814095d..9c6dcf8ff 100644 --- a/src/TortoiseProc/CommitDlg.cpp +++ b/src/TortoiseProc/CommitDlg.cpp @@ -39,6 +39,7 @@ #include "BstrSafeVector.h" #include "StringUtils.h" #include "FileTextLines.h" +#include "DPIAware.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -434,7 +435,7 @@ BOOL CCommitDlg::OnInitDialog() m_wndSplitter.GetWindowRect(&rectSplitter); ScreenToClient(&rectSplitter); int delta = yPos - rectSplitter.top; - if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30)) + if ((rcLogMsg.bottom + delta > rcLogMsg.top) && (rcLogMsg.bottom + delta < rcFileList.bottom - CDPIAware::Instance().ScaleY(30))) { m_wndSplitter.SetWindowPos(nullptr, rectSplitter.left, yPos, 0, 0, SWP_NOSIZE); DoSize(delta); @@ -2415,7 +2416,7 @@ void CCommitDlg::SetSplitterRange() m_ListCtrl.GetWindowRect(rcMiddle); ScreenToClient(rcMiddle); if (rcMiddle.Height() && rcMiddle.Width()) - m_wndSplitter.SetRange(rcTop.top + 100, rcMiddle.bottom - 80); + m_wndSplitter.SetRange(rcTop.top + CDPIAware::Instance().ScaleY(120), rcMiddle.bottom - CDPIAware::Instance().ScaleY(80)); } } diff --git a/src/TortoiseProc/ImportPatchDlg.cpp b/src/TortoiseProc/ImportPatchDlg.cpp index 84a6a3cc4..1580de8e2 100644 --- a/src/TortoiseProc/ImportPatchDlg.cpp +++ b/src/TortoiseProc/ImportPatchDlg.cpp @@ -27,6 +27,7 @@ #include "AppUtils.h" #include "SmartHandle.h" #include "LoglistCommonResource.h" +#include "DPIAware.h" // CImportPatchDlg dialog @@ -91,7 +92,7 @@ void CImportPatchDlg::SetSplitterRange() m_ctrlTabCtrl.GetWindowRect(rcMiddle); ScreenToClient(rcMiddle); if (rcMiddle.Height() && rcMiddle.Width()) - m_wndSplitter.SetRange(rcTop.top+160, rcMiddle.bottom-160); + m_wndSplitter.SetRange(rcTop.top + CDPIAware::Instance().ScaleY(160), rcMiddle.bottom - CDPIAware::Instance().ScaleY(160)); } } @@ -191,7 +192,7 @@ BOOL CImportPatchDlg::OnInitDialog() m_wndSplitter.GetWindowRect(&rectSplitter); ScreenToClient(&rectSplitter); int delta = yPos - rectSplitter.top; - if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30)) + if ((rcLogMsg.bottom + delta > rcLogMsg.top) && (rcLogMsg.bottom + delta < rcFileList.bottom - CDPIAware::Instance().ScaleY(30))) { m_wndSplitter.SetWindowPos(nullptr, 0, yPos, 0, 0, SWP_NOSIZE); DoSize(delta); diff --git a/src/TortoiseProc/LogDlg.cpp b/src/TortoiseProc/LogDlg.cpp index 27dd8b2cd..1ce3b3145 100644 --- a/src/TortoiseProc/LogDlg.cpp +++ b/src/TortoiseProc/LogDlg.cpp @@ -31,6 +31,10 @@ #include "SmartHandle.h" #include "LogOrdering.h" #include "ClipboardHelper.h" +#include "DPIAware.h" + +#define MIN_CTRL_HEIGHT (CDPIAware::Instance().ScaleY(20)) +#define MIN_SPLITTER_HEIGHT (CDPIAware::Instance().ScaleY(10)) #define WM_TGIT_REFRESH_SELECTION (WM_APP + 1) @@ -403,27 +407,27 @@ BOOL CLogDlg::OnInitDialog() ScreenToClient(&rcLogList); m_ChangedFileListCtrl.GetWindowRect(&rcChgMsg); ScreenToClient(&rcChgMsg); - if (yPos1 && ((LONG)yPos1 < rcDlg.bottom - 185)) + if (yPos1 && ((LONG)yPos1 < rcDlg.bottom - CDPIAware::Instance().ScaleY(185))) { RECT rectSplitter; m_wndSplitter1.GetWindowRect(&rectSplitter); ScreenToClient(&rectSplitter); int delta = yPos1 - rectSplitter.top; - if ((rcLogList.bottom + delta > rcLogList.top)&&(rcLogList.bottom + delta < rcChgMsg.bottom - 30)) + if ((rcLogList.bottom + delta > rcLogList.top) && (rcLogList.bottom + delta < rcChgMsg.bottom - CDPIAware::Instance().ScaleY(30))) { m_wndSplitter1.SetWindowPos(nullptr, rectSplitter.left, yPos1, 0, 0, SWP_NOSIZE); DoSizeV1(delta); } } - if (yPos2 && ((LONG)yPos2 < rcDlg.bottom - 153)) + if (yPos2 && ((LONG)yPos2 < rcDlg.bottom - CDPIAware::Instance().ScaleY(153))) { RECT rectSplitter; m_wndSplitter2.GetWindowRect(&rectSplitter); ScreenToClient(&rectSplitter); int delta = yPos2 - rectSplitter.top; - if ((rcChgMsg.top + delta < rcChgMsg.bottom)&&(rcChgMsg.top + delta > rcLogList.top + 30)) + if ((rcChgMsg.top + delta < rcChgMsg.bottom) && (rcChgMsg.top + delta > rcLogList.top + CDPIAware::Instance().ScaleY(30))) { m_wndSplitter2.SetWindowPos(nullptr, rectSplitter.left, yPos2, 0, 0, SWP_NOSIZE); DoSizeV2(delta); @@ -1988,7 +1992,7 @@ void CLogDlg::DoSizeV1(int delta) CRect messageViewRect; GetDlgItem(IDC_MSGVIEW)->GetClientRect(messageViewRect); - int messageViewDelta = max(-delta, 20 - messageViewRect.Height()); + int messageViewDelta = max(-delta, CDPIAware::Instance().ScaleY(20) - messageViewRect.Height()); int changeFileListDelta = -delta - messageViewDelta; // set new sizes & positions @@ -2022,7 +2026,7 @@ void CLogDlg::DoSizeV2(int delta) CRect messageViewRect; GetDlgItem(IDC_MSGVIEW)->GetClientRect(messageViewRect); - int messageViewDelta = max(delta, 20 - messageViewRect.Height()); + int messageViewDelta = max(delta, CDPIAware::Instance().ScaleY(20) - messageViewRect.Height()); int logListDelta = delta - messageViewDelta; // set new sizes & positions @@ -2124,7 +2128,7 @@ void CLogDlg::AdjustMinSize() SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_ChgOrigRect.Height()-m_LogListOrigRect.Height()-m_MsgViewOrigRect.Height() - + rcLogMsg.Height() + abs(rcChgListView.Height() - rcLogList.Height()) + 60)); + + rcLogMsg.Height() + abs(rcChgListView.Height() - rcLogList.Height()) + 2 * (MIN_CTRL_HEIGHT + MIN_SPLITTER_HEIGHT))); } LRESULT CLogDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) @@ -2157,8 +2161,8 @@ void CLogDlg::SetSplitterRange() CRect rcBottom; m_ChangedFileListCtrl.GetWindowRect(rcBottom); ScreenToClient(rcBottom); - m_wndSplitter1.SetRange(rcTop.top + 20, rcBottom.bottom - 50); - m_wndSplitter2.SetRange(rcTop.top + 50, rcBottom.bottom - 20); + m_wndSplitter1.SetRange(rcTop.top + MIN_CTRL_HEIGHT, rcBottom.bottom - (2 * MIN_CTRL_HEIGHT + MIN_SPLITTER_HEIGHT)); + m_wndSplitter2.SetRange(rcTop.top + (2 * MIN_CTRL_HEIGHT + MIN_SPLITTER_HEIGHT), rcBottom.bottom - MIN_CTRL_HEIGHT); } } diff --git a/src/TortoiseProc/RepositoryBrowser.cpp b/src/TortoiseProc/RepositoryBrowser.cpp index e56692d45..b020d0b60 100644 --- a/src/TortoiseProc/RepositoryBrowser.cpp +++ b/src/TortoiseProc/RepositoryBrowser.cpp @@ -36,6 +36,7 @@ #include "DragDropImpl.h" #include "GitDataObject.h" #include "TempFile.h" +#include "DPIAware.h" #define OVERLAY_EXTERNAL 1 #define OVERLAY_EXECUTABLE 2 @@ -260,7 +261,7 @@ BOOL CRepositoryBrowser::OnInitDialog() GetDlgItem(IDC_REPOTREE)->GetClientRect(&rc); xPos = rc.right - rc.left; } - HandleDividerMove(CPoint(xPos + 20, 10), false); + HandleDividerMove(CPoint(xPos + CDPIAware::Instance().ScaleX(20), CDPIAware::Instance().ScaleY(10)), false); CString sWindowTitle; GetWindowText(sWindowTitle); @@ -991,26 +992,29 @@ void CRepositoryBrowser::HandleDividerMove(CPoint point, bool bDraw) GetClientRect(&rect); ClientToScreen(&rect); + auto minWidth = CDPIAware::Instance().ScaleX(REPOBROWSER_CTRL_MIN_WIDTH); CPoint point2 = point; - if (point2.x < treelist.left + REPOBROWSER_CTRL_MIN_WIDTH) - point2.x = treelist.left + REPOBROWSER_CTRL_MIN_WIDTH; - if (point2.x > treelist.right - REPOBROWSER_CTRL_MIN_WIDTH) - point2.x = treelist.right - REPOBROWSER_CTRL_MIN_WIDTH; + if (point2.x < treelist.left + minWidth) + point2.x = treelist.left + minWidth; + if (point2.x > treelist.right - minWidth) + point2.x = treelist.right - minWidth; point.x -= rect.left; point.y -= treelist.top; OffsetRect(&treelist, -treelist.left, -treelist.top); - if (point.x < treelist.left+REPOBROWSER_CTRL_MIN_WIDTH) - point.x = treelist.left+REPOBROWSER_CTRL_MIN_WIDTH; - if (point.x > treelist.right-REPOBROWSER_CTRL_MIN_WIDTH) - point.x = treelist.right-REPOBROWSER_CTRL_MIN_WIDTH; + if (point.x < treelist.left + minWidth) + point.x = treelist.left + minWidth; + if (point.x > treelist.right - minWidth) + point.x = treelist.right - minWidth; + + auto divWidth = CDPIAware::Instance().ScaleX(2); if (bDraw) { CDC * pDC = GetDC(); - DrawXorBar(pDC, oldx + 2, treelistclient.top, 4, treelistclient.bottom - treelistclient.top - 2); + DrawXorBar(pDC, oldx - divWidth, treelistclient.top, 2 * divWidth, treelistclient.bottom - treelistclient.top - CDPIAware::Instance().ScaleY(2)); ReleaseDC(pDC); } @@ -1019,12 +1023,12 @@ void CRepositoryBrowser::HandleDividerMove(CPoint point, bool bDraw) //position the child controls GetDlgItem(IDC_REPOTREE)->GetWindowRect(&treelist); - treelist.right = point2.x - 2; + treelist.right = point2.x - divWidth; ScreenToClient(&treelist); RemoveAnchor(IDC_REPOTREE); GetDlgItem(IDC_REPOTREE)->MoveWindow(&treelist); GetDlgItem(IDC_REPOLIST)->GetWindowRect(&treelist); - treelist.left = point2.x + 2; + treelist.left = point2.x + divWidth; ScreenToClient(&treelist); RemoveAnchor(IDC_REPOLIST); GetDlgItem(IDC_REPOLIST)->MoveWindow(&treelist); @@ -1057,10 +1061,11 @@ void CRepositoryBrowser::OnMouseMove(UINT nFlags, CPoint point) //same for the window coordinates - make them relative to 0,0 OffsetRect(&treelist, -treelist.left, -treelist.top); - if (point.x < treelist.left + REPOBROWSER_CTRL_MIN_WIDTH) - point.x = treelist.left + REPOBROWSER_CTRL_MIN_WIDTH; - if (point.x > treelist.right - REPOBROWSER_CTRL_MIN_WIDTH) - point.x = treelist.right - REPOBROWSER_CTRL_MIN_WIDTH; + auto minWidth = CDPIAware::Instance().ScaleX(REPOBROWSER_CTRL_MIN_WIDTH); + if (point.x < treelist.left + minWidth) + point.x = treelist.left + minWidth; + if (point.x > treelist.right - minWidth) + point.x = treelist.right - minWidth; if ((nFlags & MK_LBUTTON) && (point.x != oldx)) { @@ -1068,8 +1073,10 @@ void CRepositoryBrowser::OnMouseMove(UINT nFlags, CPoint point) if (pDC) { - DrawXorBar(pDC, oldx + 2, treelistclient.top, 4, treelistclient.bottom - treelistclient.top - 2); - DrawXorBar(pDC, point.x + 2, treelistclient.top, 4, treelistclient.bottom - treelistclient.top - 2); + auto divWidth = CDPIAware::Instance().ScaleX(2); + auto divHeight = CDPIAware::Instance().ScaleY(2); + DrawXorBar(pDC, oldx - divWidth, treelistclient.top, 2 * divWidth, treelistclient.bottom - treelistclient.top - divHeight); + DrawXorBar(pDC, point.x - divWidth, treelistclient.top, 2 * divWidth, treelistclient.bottom - treelistclient.top - divHeight); ReleaseDC(pDC); } @@ -1103,22 +1110,26 @@ void CRepositoryBrowser::OnLButtonDown(UINT nFlags, CPoint point) //same for the window coordinates - make them relative to 0,0 OffsetRect(&treelist, -treelist.left, -treelist.top); - if (point.x < treelist.left + REPOBROWSER_CTRL_MIN_WIDTH) + auto minWidth = CDPIAware::Instance().ScaleX(REPOBROWSER_CTRL_MIN_WIDTH); + + if (point.x < treelist.left + minWidth) return CStandAloneDialogTmpl < CResizableDialog>::OnLButtonDown(nFlags, point); - if (point.x > treelist.right - 3) + if (point.x > treelist.right - CDPIAware::Instance().ScaleX(3)) return CStandAloneDialogTmpl < CResizableDialog>::OnLButtonDown(nFlags, point); - if (point.x > treelist.right - REPOBROWSER_CTRL_MIN_WIDTH) - point.x = treelist.right - REPOBROWSER_CTRL_MIN_WIDTH; + if (point.x > treelist.right - minWidth) + point.x = treelist.right - minWidth; - if ((point.y < treelist.top + 3) || (point.y > treelist.bottom - 3)) + auto divHeight = CDPIAware::Instance().ScaleY(3); + if ((point.y < treelist.top + divHeight) || (point.y > treelist.bottom - divHeight)) return CStandAloneDialogTmpl::OnLButtonDown(nFlags, point); bDragMode = true; SetCapture(); + auto divWidth = CDPIAware::Instance().ScaleX(2); CDC * pDC = GetDC(); - DrawXorBar(pDC, point.x + 2, treelistclient.top, 4, treelistclient.bottom - treelistclient.top - 2); + DrawXorBar(pDC, point.x - divWidth, treelistclient.top, 2 * divWidth, treelistclient.bottom - treelistclient.top - CDPIAware::Instance().ScaleY(2)); ReleaseDC(pDC); oldx = point.x; @@ -1186,7 +1197,8 @@ BOOL CRepositoryBrowser::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) ClientToScreen(&pt); // are we right of the tree control? GetDlgItem(IDC_REPOTREE)->GetWindowRect(&rect); - if ((pt.x > rect.right) && (pt.y >= rect.top + 3) && (pt.y <= rect.bottom - 3)) + auto divHeight = CDPIAware::Instance().ScaleY(3); + if ((pt.x > rect.right) && (pt.y >= rect.top + divHeight) && (pt.y <= rect.bottom - divHeight)) { // but left of the list control? GetDlgItem(IDC_REPOLIST)->GetWindowRect(&rect); -- 2.11.4.GIT