Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass objects by constant reference instead of passing by value. #5

Merged
merged 1 commit into from
Dec 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 30 additions & 34 deletions ResizableLib/ResizableComboBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ void CResizableComboBox::InitHorizontalExtent()
CString str;

m_iExtent = 0;
int n = GetCount();
const int n = GetCount();
for (int i=0; i<n; i++)
{
GetLBText(i, str);
int cx = dc.GetTextExtent(str).cx;
const int cx = dc.GetTextExtent(str).cx;
if (cx > m_iExtent)
m_iExtent = cx;
}
Expand All @@ -133,7 +133,7 @@ void CResizableComboBox::UpdateHorizontalExtent(LPCTSTR szText)
CClientDC dc(this);
CFont* pOldFont = dc.SelectObject(GetFont());

int cx = dc.GetTextExtent(szText, static_cast<int>(_tcslen(szText))).cx;
const int cx = dc.GetTextExtent(szText, static_cast<int>(_tcslen(szText))).cx;
if (cx > m_iExtent)
{
m_iExtent = cx;
Expand All @@ -160,23 +160,20 @@ void CResizableComboBox::PreSubclassWindow()

int CResizableComboBox::MakeIntegralHeight(const int height)
{
int inth = height; // integral height (result)
int availh = height; // available height
int n = GetCount();

DWORD dwStyle = GetStyle();
const int n = GetCount();

if (!m_bIntegralHeight || n == 0)
return inth;
if (!m_bIntegralHeight || n <= 0)
return height;

if (dwStyle & CBS_OWNERDRAWVARIABLE)
int availh = height; // available height
if (GetStyle() & CBS_OWNERDRAWVARIABLE)
{
inth = 0; // try to reach availh by integral steps
int inth = 0; // try to reach availh by integral steps
int i;
// use items below the first visible
for (i=GetTopIndex(); availh>0 && i<n; i++)
{
int h = GetItemHeight(i);
const int h = GetItemHeight(i);
if (h == CB_ERR)
break;

Expand All @@ -186,7 +183,7 @@ int CResizableComboBox::MakeIntegralHeight(const int height)
// to fill the remaining height, use items above
for (i=GetTopIndex()-1; availh>0 && i>=0; i--)
{
int h = GetItemHeight(i);
const int h = GetItemHeight(i);
if (h == CB_ERR)
break;

Expand All @@ -199,29 +196,28 @@ int CResizableComboBox::MakeIntegralHeight(const int height)
if (!m_bClipMaxHeight) // it can be higher than all the items
{
// to fill the remaining height, use last item
int h = GetItemHeight(n-1);
if (h != CB_ERR)
{
const int h = GetItemHeight(n-1);
if (h > 0)
inth += availh - availh % h;
}
}

return inth;
}
else

// every item has the same height (take the first)
int h = GetItemHeight(0);
if (h > 0)
{
// every item has the same height (take the first)
int h = GetItemHeight(0);
if (h != CB_ERR && n != CB_ERR)
{
int rows = availh / h;
// can't be higher than all the items
if (m_bClipMaxHeight && rows > n)
rows = n;
inth = rows * h;
// scroll into view
if (n - rows < GetTopIndex())
SetTopIndex(n-rows);
}
int rows = availh / h;
// can't be higher than all the items
if (m_bClipMaxHeight && rows > n)
rows = n;
// scroll into view
if (n - rows < GetTopIndex())
SetTopIndex(n-rows);

return rows * h;
}

return inth;
}
return height;
}
7 changes: 3 additions & 4 deletions ResizableLib/ResizableFormView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void CResizableFormView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);

CWnd* pParent = GetParentFrame();
const CWnd* pParent = GetParentFrame();

// hide size grip when parent is maximized
if (pParent->IsZoomed())
Expand All @@ -92,15 +92,14 @@ void CResizableFormView::OnSize(UINT nType, int cx, int cy)
ShowSizeGrip(&m_dwGripTempState, GHR_MAXIMIZED);

// hide size grip when there are scrollbars
CSize size = GetTotalSize();
const CSize size = GetTotalSize();
if ((cx < size.cx || cy < size.cy) && (m_nMapMode >= 0))
HideSizeGrip(&m_dwGripTempState, GHR_SCROLLBAR);
else
ShowSizeGrip(&m_dwGripTempState, GHR_SCROLLBAR);

// hide size grip when the parent frame window is not resizable
// or the form is not bottom-right aligned (e.g. there's a statusbar)
DWORD dwStyle = pParent->GetStyle();
CRect rect, rectChild;
GetWindowRect(rect);

Expand All @@ -116,7 +115,7 @@ void CResizableFormView::OnSize(UINT nType, int cx, int cy)
break;
}
}
if ((dwStyle & WS_THICKFRAME) && bCanResize)
if ((pParent->GetStyle() & WS_THICKFRAME) && bCanResize)
ShowSizeGrip(&m_dwGripTempState, GHR_ALIGNMENT);
else
HideSizeGrip(&m_dwGripTempState, GHR_ALIGNMENT);
Expand Down
38 changes: 16 additions & 22 deletions ResizableLib/ResizableLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ void CResizableLayout::ArrangeLayout() const
// common vars
UINT uFlags;
CRect rectParent, rectChild;
INT_PTR count = m_listLayout.GetCount() + m_listLayoutCB.GetCount();
const INT_PTR count = m_listLayout.GetCount() + m_listLayoutCB.GetCount();

if (count <= 0)
return;
Expand Down Expand Up @@ -293,7 +293,7 @@ void CResizableLayout::ClipChildWindow(const LAYOUTINFO& layout,
}

// get the clipping property
BOOL bClipping = layout.properties.bAskClipping ?
const BOOL bClipping = layout.properties.bAskClipping ?
LikesClipping(layout) : layout.properties.bCachedLikesClipping;

// modify region accordingly
Expand All @@ -317,7 +317,7 @@ void CResizableLayout::ClipChildWindow(const LAYOUTINFO& layout,
*/
void CResizableLayout::GetClippingRegion(CRgn* pRegion) const
{
CWnd* pWnd = GetResizableWnd();
const CWnd* pWnd = GetResizableWnd();

// System's default clipping area is screen's size,
// not enough for max track size, for example:
Expand All @@ -334,26 +334,22 @@ void CResizableLayout::GetClippingRegion(CRgn* pRegion) const
pRegion->CreateRectRgnIndirect(&rect);

// clip only anchored controls
LAYOUTINFO layout;
POSITION pos = m_listLayout.GetHeadPosition();
while (pos != NULL)

for (POSITION pos = m_listLayout.GetHeadPosition(); pos != NULL;)
{
// get layout info
layout = m_listLayout.GetNext(pos);
LAYOUTINFO layout = m_listLayout.GetNext(pos);

if (::IsWindowVisible(layout.hWnd))
ClipChildWindow(layout, pRegion);
}
pos = m_listLayoutCB.GetHeadPosition();
while (pos != NULL)

for (POSITION pos = m_listLayoutCB.GetHeadPosition(); pos != NULL;)
{
// get layout info
layout = m_listLayoutCB.GetNext(pos);
LAYOUTINFO layout = m_listLayoutCB.GetNext(pos);
// request data
if (!ArrangeLayoutCallback(layout))
continue;

if (::IsWindowVisible(layout.hWnd))
if (ArrangeLayoutCallback(layout) && ::IsWindowVisible(layout.hWnd))
ClipChildWindow(layout, pRegion);
}
//! @todo Has XP changed this??? It doesn't seem correct anymore!
Expand Down Expand Up @@ -405,8 +401,8 @@ BOOL CResizableLayout::ClipChildren(const CDC* pDC, BOOL bUndo)
}
#endif

HDC hDC = pDC->GetSafeHdc();
HWND hWnd = GetResizableWnd()->GetSafeHwnd();
const HDC hDC = pDC->GetSafeHdc();
const HWND hWnd = GetResizableWnd()->GetSafeHwnd();

// Some controls (such as transparent toolbars and standard controls
// with XP theme enabled) send a WM_ERASEBKGND msg to the parent
Expand Down Expand Up @@ -490,8 +486,8 @@ BOOL CResizableLayout::NeedsRefresh(const LAYOUTINFO& layout,
return refresh.bNeedsRefresh;
}

int nDiffWidth = (rectNew.Width() - rectOld.Width());
int nDiffHeight = (rectNew.Height() - rectOld.Height());
const int nDiffWidth = (rectNew.Width() - rectOld.Width());
const int nDiffHeight = (rectNew.Height() - rectOld.Height());

// is the same size?
if (nDiffWidth == 0 && nDiffHeight == 0)
Expand Down Expand Up @@ -543,9 +539,7 @@ BOOL CResizableLayout::NeedsRefresh(const LAYOUTINFO& layout,

// window classes that don't redraw client area correctly
// when the hor scroll pos changes due to a resizing
BOOL bHScroll = FALSE;
if (0 == lstrcmp(layout.sWndClass, WC_LISTBOX))
bHScroll = TRUE;
const BOOL bHScroll = (0 == lstrcmp(layout.sWndClass, WC_LISTBOX));

// fix for horizontally scrollable windows, if wider
if (bHScroll && (nDiffWidth > 0))
Expand Down Expand Up @@ -665,7 +659,7 @@ BOOL CResizableLayout::LikesClipping(const LAYOUTINFO& layout) const
void CResizableLayout::CalcNewChildPosition(const LAYOUTINFO& layout,
const CRect &rectParent, CRect &rectChild, UINT *lpFlags) const
{
CWnd* pParent = GetResizableWnd();
const CWnd* pParent = GetResizableWnd();

::GetWindowRect(layout.hWnd, &rectChild);
::MapWindowPoints(NULL, pParent->m_hWnd, (LPPOINT)&rectChild, 2);
Expand Down
44 changes: 4 additions & 40 deletions ResizableLib/ResizableLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -400,26 +400,8 @@
</Bscmake>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="ResizableComboBox.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static Unicode|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Unicode|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Static Unicode|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Static|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Unicode|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="ResizableComboLBox.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static Unicode|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Unicode|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Static Unicode|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Static|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Unicode|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="ResizableComboBox.cpp" />
<ClCompile Include="ResizableComboLBox.cpp" />
<ClCompile Include="ResizableDialog.cpp" />
<ClCompile Include="ResizableFormView.cpp" />
<ClCompile Include="ResizableFrame.cpp" />
Expand Down Expand Up @@ -451,26 +433,8 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="Docs\refman.h" />
<CustomBuild Include="ResizableComboBox.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static Unicode|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Unicode|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Static Unicode|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Static|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Unicode|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</CustomBuild>
<CustomBuild Include="ResizableComboLBox.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static Unicode|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Static|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Unicode|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Static Unicode|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Static|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Unicode|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</CustomBuild>
<ClInclude Include="ResizableComboBox.h" />
<ClInclude Include="ResizableComboLBox.h" />
<ClInclude Include="ResizableDialog.h" />
<ClInclude Include="ResizableFormView.h" />
<ClInclude Include="ResizableFrame.h" />
Expand Down
8 changes: 4 additions & 4 deletions ResizableLib/ResizableMinMax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void CResizableMinMax::MinMaxInfo(LPMINMAXINFO lpMMI) const
}
}

void CResizableMinMax::ChainMinMaxInfo(LPMINMAXINFO lpMMI, CWnd* pParentFrame, CWnd* pWnd)
void CResizableMinMax::ChainMinMaxInfo(LPMINMAXINFO lpMMI, CWnd* pParentFrame, const CWnd* pWnd)
{
// get the extra size from child to parent
CRect rectClient, rectWnd;
Expand All @@ -69,12 +69,12 @@ void CResizableMinMax::ChainMinMaxInfo(LPMINMAXINFO lpMMI, CWnd* pParentFrame, C
pParentFrame->GetWindowRect(rectWnd);
pParentFrame->RepositionBars(0, 0xFFFF,
AFX_IDW_PANE_FIRST, CWnd::reposQuery, rectClient);
CSize sizeExtra = rectWnd.Size() - rectClient.Size();
const CSize sizeExtra = rectWnd.Size() - rectClient.Size();

ChainMinMaxInfo(lpMMI, pWnd->GetSafeHwnd(), sizeExtra);
}

void CResizableMinMax::ChainMinMaxInfo(LPMINMAXINFO lpMMI, HWND hWndChild, CSize sizeExtra)
void CResizableMinMax::ChainMinMaxInfo(LPMINMAXINFO lpMMI, HWND hWndChild, const CSize& sizeExtra)
{
// ask the child window for track size
MINMAXINFO mmiChild = *lpMMI;
Expand Down Expand Up @@ -106,7 +106,7 @@ void CResizableMinMax::ChainMinMaxInfo(LPMINMAXINFO lpMMI, HWND hWndChild, CSize
}
}

BOOL CResizableMinMax::CalcSizeExtra(HWND /*hWndChild*/, CSize /*sizeChild*/, CSize& /*sizeExtra*/)
BOOL CResizableMinMax::CalcSizeExtra(HWND /*hWndChild*/, const CSize& /*sizeChild*/, CSize& /*sizeExtra*/)
{
// should be overridden if you use ChainMinMaxInfoCB
ASSERT(FALSE);
Expand Down
8 changes: 4 additions & 4 deletions ResizableLib/ResizableMinMax.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ class CResizableMinMax

protected:
void MinMaxInfo(LPMINMAXINFO lpMMI) const;
static void ChainMinMaxInfo(LPMINMAXINFO lpMMI, CWnd* pParentFrame, CWnd* pWnd);
static void ChainMinMaxInfo(LPMINMAXINFO lpMMI, CWnd* pParentFrame, const CWnd* pWnd);

static void ChainMinMaxInfo(LPMINMAXINFO lpMMI, HWND hWndChild, CSize sizeExtra);
static void ChainMinMaxInfo(LPMINMAXINFO lpMMI, HWND hWndChild, const CSize& sizeExtra);

static void ChainMinMaxInfo(LPMINMAXINFO lpMMI, CWnd* pParentWnd, UINT nID, CSize sizeExtra)
static void ChainMinMaxInfo(LPMINMAXINFO lpMMI, const CWnd* pParentWnd, UINT nID, const CSize& sizeExtra)
{
ChainMinMaxInfo(lpMMI,
::GetDlgItem(pParentWnd->GetSafeHwnd(), nID), sizeExtra);
}

void ChainMinMaxInfoCB(LPMINMAXINFO lpMMI, HWND hWndChild);
virtual BOOL CalcSizeExtra(HWND hWndChild, CSize sizeChild, CSize& sizeExtra);
virtual BOOL CalcSizeExtra(HWND hWndChild, const CSize& sizeChild, CSize& sizeExtra);

void ResetAllRects();

Expand Down
Loading