Skip to content

Commit

Permalink
Merge pull request ppescher#23 from irwir/updates
Browse files Browse the repository at this point in the history
Partial optimization of code
  • Loading branch information
ppescher authored Oct 5, 2019
2 parents 479320f + 81b604e commit 8831704
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 48 deletions.
4 changes: 2 additions & 2 deletions ResizableComboBox/Demo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ResizableLib", "..\ResizableLib\ResizableLib.vcxproj", "{C176053F-C799-4BF4-ABFA-125A4192CEB9}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo", "Demo.vcxproj", "{E90C0521-E036-49C5-BC3E-F27276C73726}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ResizableLib", "..\ResizableLib\ResizableLib.vcxproj", "{C176053F-C799-4BF4-ABFA-125A4192CEB9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug Static Unicode|x64 = Debug Static Unicode|x64
Expand Down
2 changes: 1 addition & 1 deletion ResizableLib/ResizableComboLBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ void CResizableComboLBox::ApplyLimitsToPos(WINDOWPOS* lpwndpos)

// back to window rect
rect = CRect(0, 0, 1, sizeClient.cy);
DWORD dwStyle = GetStyle();
const DWORD dwStyle = GetStyle();
::AdjustWindowRectEx(&rect, dwStyle, FALSE, GetExStyle());
lpwndpos->cy = rect.Height();
if (dwStyle & WS_HSCROLL)
Expand Down
3 changes: 2 additions & 1 deletion ResizableLib/ResizableLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,8 @@ void CResizableLayout::CalcNewChildPosition(const LAYOUTINFO& layout,
NeedsRefresh(layout, rectChild, rectNew) : layout.properties.bCachedNeedsRefresh;

// set flags
if (lpFlags) {
if (lpFlags)
{
*lpFlags = SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREPOSITION;
if (bRefresh)
*lpFlags |= SWP_NOCOPYBITS;
Expand Down
33 changes: 14 additions & 19 deletions ResizableLib/ResizableSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,6 @@ BOOL CResizableSheet::CalcSizeExtra(HWND /*hWndChild*/, const CSize& sizeChild,
if (!GetAnchorMargins(pTab->m_hWnd, sizeChild, rectMargins))
return FALSE;

// get margin caused by tabcontrol
CRect rectTabMargins(0,0,0,0);

// get tab position after resizing and calc page rect
CRect rectPage, rectSheet;
GetTotalClientRect(&rectSheet);
Expand All @@ -345,7 +342,7 @@ BOOL CResizableSheet::CalcSizeExtra(HWND /*hWndChild*/, const CSize& sizeChild,
return FALSE; // no page yet

// temporarily resize the tab control to calc page size
CRect rectSave;
CRect rectSave, rectTabMargins;
pTab->GetWindowRect(rectSave);
::MapWindowPoints(NULL, m_hWnd, (LPPOINT)&rectSave, 2);
pTab->SetRedraw(FALSE);
Expand All @@ -355,9 +352,9 @@ BOOL CResizableSheet::CalcSizeExtra(HWND /*hWndChild*/, const CSize& sizeChild,
pTab->SetRedraw(TRUE);

// add non-client size
::AdjustWindowRectEx(&rectTabMargins, GetStyle(), !(GetStyle() & WS_CHILD) &&
const DWORD dwStyle = GetStyle();
::AdjustWindowRectEx(&rectTabMargins, dwStyle, !(dwStyle & WS_CHILD) &&
::IsMenu(GetMenu()->GetSafeHmenu()), GetExStyle());

// compute extra size
sizeExtra = rectMargins.TopLeft() + rectMargins.BottomRight() +
rectTabMargins.Size();
Expand All @@ -371,22 +368,20 @@ void CResizableSheet::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
if (!GetTabControl())
return;

const int nCount = GetPageCount();
for (int idx = 0; idx < nCount; ++idx)
int idx = GetPageCount();
if (IsWizard()) // wizard mode
{
if (IsWizard()) // wizard mode
{
// use pre-calculated margins
CRect rectExtra(-CPoint(m_sizePageTL), -CPoint(m_sizePageBR));
// add non-client size
::AdjustWindowRectEx(&rectExtra, GetStyle(), !(GetStyle() & WS_CHILD) &&
::IsMenu(GetMenu()->GetSafeHmenu()), GetExStyle());
CRect rectExtra(-CPoint(m_sizePageTL), -CPoint(m_sizePageBR));
const DWORD dwStyle = GetStyle();
::AdjustWindowRectEx(&rectExtra, dwStyle, !(dwStyle & WS_CHILD) &&
::IsMenu(GetMenu()->GetSafeHmenu()), GetExStyle());
while (--idx >= 0)
ChainMinMaxInfo(lpMMI, *GetPage(idx), rectExtra.Size());
}
else // tab mode
{
}
else // tab mode
{
while (--idx >= 0)
ChainMinMaxInfoCB(lpMMI, *GetPage(idx));
}
}
}

Expand Down
41 changes: 16 additions & 25 deletions ResizableLib/ResizableSheetEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,6 @@ BOOL CResizableSheetEx::CalcSizeExtra(HWND /*hWndChild*/, const CSize& sizeChild
if (!GetAnchorMargins(pTab->m_hWnd, sizeChild, rectMargins))
return FALSE;

// get margin caused by tabcontrol
CRect rectTabMargins(0,0,0,0);

// get tab position after resizing and calc page rect
CRect rectPage, rectSheet;
GetTotalClientRect(&rectSheet);
Expand All @@ -491,7 +488,7 @@ BOOL CResizableSheetEx::CalcSizeExtra(HWND /*hWndChild*/, const CSize& sizeChild
return FALSE; // no page yet

// temporarily resize the tab control to calc page size
CRect rectSave;
CRect rectSave, rectTabMargins;
pTab->GetWindowRect(rectSave);
::MapWindowPoints(NULL, m_hWnd, (LPPOINT)&rectSave, 2);
pTab->SetRedraw(FALSE);
Expand All @@ -501,40 +498,36 @@ BOOL CResizableSheetEx::CalcSizeExtra(HWND /*hWndChild*/, const CSize& sizeChild
pTab->SetRedraw(TRUE);

// add non-client size
::AdjustWindowRectEx(&rectTabMargins, GetStyle(), !(GetStyle() & WS_CHILD) &&
const DWORD dwStyle = GetStyle();
::AdjustWindowRectEx(&rectTabMargins, dwStyle, !(dwStyle & WS_CHILD) &&
::IsMenu(GetMenu()->GetSafeHmenu()), GetExStyle());

// compute extra size
sizeExtra = rectMargins.TopLeft() + rectMargins.BottomRight() +
rectTabMargins.Size();
return TRUE;
}

void CResizableSheetEx::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
void CResizableSheetEx::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
MinMaxInfo(lpMMI);

if (!GetTabControl())
return;

const int nCount = GetPageCount();
for (int idx = 0; idx < nCount; ++idx)
int idx = GetPageCount();
if (!IsWizard() && !IsWizard97()) // tab mode
{
if (IsWizard()) // wizard mode
{
// use pre-calculated margins
CRect rectExtra(-CPoint(m_sizePageTL), -CPoint(m_sizePageBR));
// add non-client size
::AdjustWindowRectEx(&rectExtra, GetStyle(), !(GetStyle() & WS_CHILD) &&
::IsMenu(GetMenu()->GetSafeHmenu()), GetExStyle());
ChainMinMaxInfo(lpMMI, *GetPage(idx), rectExtra.Size());
}
else if (IsWizard97()) // wizard 97
while (--idx >= 0)
ChainMinMaxInfoCB(lpMMI, *GetPage(idx));
}
else // wizard mode
{
while (--idx >= 0)
{
// use pre-calculated margins
CRect rectExtra(-CPoint(m_sizePageTL), -CPoint(m_sizePageBR));

if (!(GetPage(idx)->m_psp.dwFlags & PSP_HIDEHEADER))
if (IsWizard97() && !(GetPage(idx)->m_psp.dwFlags & PSP_HIDEHEADER)) // wizard97 mode
{
// add header vertical offset
CRect rectLine, rectSheet;
Expand All @@ -543,15 +536,13 @@ void CResizableSheetEx::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)

rectExtra.top = -rectLine.bottom;
}

// add non-client size
::AdjustWindowRectEx(&rectExtra, GetStyle(), !(GetStyle() & WS_CHILD) &&
const DWORD dwStyle = GetStyle();
::AdjustWindowRectEx(&rectExtra, dwStyle, !(dwStyle & WS_CHILD) &&
::IsMenu(GetMenu()->GetSafeHmenu()), GetExStyle());
ChainMinMaxInfo(lpMMI, *GetPage(idx), rectExtra.Size());
}
else // tab mode
{
ChainMinMaxInfoCB(lpMMI, *GetPage(idx));
}
}
}

Expand Down

0 comments on commit 8831704

Please sign in to comment.