diff --git a/Demos/duidemo/duidemo.cpp b/Demos/duidemo/duidemo.cpp index 88d1622f..c85e8299 100644 --- a/Demos/duidemo/duidemo.cpp +++ b/Demos/duidemo/duidemo.cpp @@ -50,9 +50,9 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*l if( pFrame == NULL ) return 0; pFrame->Create(NULL, _T("duilib例子演示"), UI_WNDSTYLE_FRAME, 0L, 0, 0, 800, 572); pFrame->CenterWindow(); - ::ShowWindow(*pFrame, SW_SHOW); - - CPaintManagerUI::MessageLoop(); + pFrame->ShowModal(); + //::ShowWindow(*pFrame, SW_SHOW); + //CPaintManagerUI::MessageLoop(); ::CoUninitialize(); return 0; diff --git a/DuiLib.suo b/DuiLib.suo index 064c18f8..48e221e6 100644 Binary files a/DuiLib.suo and b/DuiLib.suo differ diff --git a/DuiLib/Core/UIContainer.cpp b/DuiLib/Core/UIContainer.cpp index 24a95789..2dc5a05b 100644 --- a/DuiLib/Core/UIContainer.cpp +++ b/DuiLib/Core/UIContainer.cpp @@ -14,7 +14,8 @@ namespace DuiLib m_bMouseChildEnabled(true), m_pVerticalScrollBar(NULL), m_pHorizontalScrollBar(NULL), - m_bScrollProcess(false), + m_bHScrollProcess(false), + m_bVScrollProcess(false), m_nScrollStepSize(0) { ::ZeroMemory(&m_rcInset, sizeof(m_rcInset)); @@ -784,7 +785,7 @@ namespace DuiLib void CContainerUI::ProcessScrollBar(RECT rc, int cxRequired, int cyRequired) { - if( m_pHorizontalScrollBar != NULL && m_pHorizontalScrollBar->IsVisible() ) { + /*if( m_pHorizontalScrollBar != NULL && m_pHorizontalScrollBar->IsVisible() ) { RECT rcScrollBarPos = { rc.left, rc.bottom, rc.right, rc.bottom + m_pHorizontalScrollBar->GetFixedHeight()}; m_pHorizontalScrollBar->SetPos(rcScrollBarPos); } @@ -827,6 +828,94 @@ namespace DuiLib SetPos(m_rcItem); } } + }*/ + // heliangbao + while (m_pHorizontalScrollBar) + { + if (cxRequired > rc.right - rc.left && !m_pHorizontalScrollBar->IsVisible()) + { + m_pHorizontalScrollBar->SetVisible(true); + m_pHorizontalScrollBar->SetScrollRange(cxRequired - (rc.right - rc.left)); + m_pHorizontalScrollBar->SetScrollPos(0); + m_bHScrollProcess = true; + SetPos(m_rcItem); + m_bHScrollProcess = false; + break; + } + + // No scrollbar required + if (!m_pHorizontalScrollBar->IsVisible()) break; + + // Scroll not needed anymore? + int cxScroll = cxRequired - (rc.right - rc.left); + if (cxScroll <= 0 && !m_bHScrollProcess) + { + m_pHorizontalScrollBar->SetVisible(false); + m_pHorizontalScrollBar->SetScrollPos(0); + m_pHorizontalScrollBar->SetScrollRange(0); + SetPos(m_rcItem); + } + else + { + RECT rcScrollBarPos = { rc.left, rc.bottom, rc.right, rc.bottom + m_pHorizontalScrollBar->GetFixedHeight() }; + m_pHorizontalScrollBar->SetPos(rcScrollBarPos); + + if (m_pHorizontalScrollBar->GetScrollRange() != cxScroll) { + int iScrollPos = m_pHorizontalScrollBar->GetScrollPos(); + m_pHorizontalScrollBar->SetScrollRange(::abs(cxScroll)); + if (m_pHorizontalScrollBar->GetScrollRange() == 0) { + m_pHorizontalScrollBar->SetVisible(false); + m_pHorizontalScrollBar->SetScrollPos(0); + } + if (iScrollPos > m_pHorizontalScrollBar->GetScrollPos()) { + SetPos(m_rcItem); + } + } + } + break; + } + + while (m_pVerticalScrollBar && !m_bHScrollProcess) + { + if (cyRequired > rc.bottom - rc.top && !m_pVerticalScrollBar->IsVisible()) { + m_pVerticalScrollBar->SetVisible(true); + m_pVerticalScrollBar->SetScrollRange(cyRequired - (rc.bottom - rc.top)); + m_pVerticalScrollBar->SetScrollPos(0); + m_bVScrollProcess = true; + SetPos(m_rcItem); + m_bVScrollProcess = false; + break; + } + + // No scrollbar required + if (!m_pVerticalScrollBar->IsVisible()) break; + + // Scroll not needed anymore? + int cyScroll = cyRequired - (rc.bottom - rc.top); + if (cyScroll <= 0 && !m_bVScrollProcess) { + m_pVerticalScrollBar->SetVisible(false); + m_pVerticalScrollBar->SetScrollPos(0); + m_pVerticalScrollBar->SetScrollRange(0); + SetPos(m_rcItem); + } + else + { + RECT rcScrollBarPos = { rc.right, rc.top, rc.right + m_pVerticalScrollBar->GetFixedWidth(), rc.bottom }; + m_pVerticalScrollBar->SetPos(rcScrollBarPos); + + if (m_pVerticalScrollBar->GetScrollRange() != cyScroll) { + int iScrollPos = m_pVerticalScrollBar->GetScrollPos(); + m_pVerticalScrollBar->SetScrollRange(::abs(cyScroll)); + if (m_pVerticalScrollBar->GetScrollRange() == 0) { + m_pVerticalScrollBar->SetVisible(false); + m_pVerticalScrollBar->SetScrollPos(0); + } + if (iScrollPos > m_pVerticalScrollBar->GetScrollPos()) { + SetPos(m_rcItem); + } + } + } + break; } } diff --git a/DuiLib/Core/UIContainer.h b/DuiLib/Core/UIContainer.h index 454198c0..ed02eee0 100644 --- a/DuiLib/Core/UIContainer.h +++ b/DuiLib/Core/UIContainer.h @@ -116,7 +116,8 @@ class UILIB_API CContainerUI : public CControlUI, public IContainerUI bool m_bAutoDestroy; bool m_bDelayedDestroy; bool m_bMouseChildEnabled; - bool m_bScrollProcess; // 防止SetPos循环调用 + bool m_bHScrollProcess; // 防止SetPos循环调用 + bool m_bVScrollProcess; // 防止SetPos循环调用 int m_nScrollStepSize; CScrollBarUI* m_pVerticalScrollBar; diff --git a/DuiLib/Layout/UIHorizontalLayout.cpp b/DuiLib/Layout/UIHorizontalLayout.cpp index 0a2ca548..fd872568 100644 --- a/DuiLib/Layout/UIHorizontalLayout.cpp +++ b/DuiLib/Layout/UIHorizontalLayout.cpp @@ -28,6 +28,7 @@ namespace DuiLib void CHorizontalLayoutUI::SetPos(RECT rc, bool bNeedInvalidate) { + // heliangbao CControlUI::SetPos(rc, bNeedInvalidate); rc = m_rcItem; @@ -36,19 +37,18 @@ namespace DuiLib rc.top += m_rcInset.top; rc.right -= m_rcInset.right; rc.bottom -= m_rcInset.bottom; + if (m_pVerticalScrollBar && m_pVerticalScrollBar->IsVisible()) rc.right -= m_pVerticalScrollBar->GetFixedWidth(); + if (m_pHorizontalScrollBar && m_pHorizontalScrollBar->IsVisible()) rc.bottom -= m_pHorizontalScrollBar->GetFixedHeight(); if( m_items.GetSize() == 0) { ProcessScrollBar(rc, 0, 0); return; } - if( m_pVerticalScrollBar && m_pVerticalScrollBar->IsVisible() ) rc.right -= m_pVerticalScrollBar->GetFixedWidth(); - if( m_pHorizontalScrollBar && m_pHorizontalScrollBar->IsVisible() ) rc.bottom -= m_pHorizontalScrollBar->GetFixedHeight(); - // Determine the width of elements that are sizeable SIZE szAvailable = { rc.right - rc.left, rc.bottom - rc.top }; - if( m_pHorizontalScrollBar && m_pHorizontalScrollBar->IsVisible() ) - szAvailable.cx += m_pHorizontalScrollBar->GetScrollRange(); + //if( m_pHorizontalScrollBar && m_pHorizontalScrollBar->IsVisible() ) + //szAvailable.cx += m_pHorizontalScrollBar->GetScrollRange(); int nAdjustables = 0; int cxFixed = 0; @@ -70,11 +70,17 @@ namespace DuiLib } cxFixed += (nEstimateNum - 1) * m_iChildPadding; - int cxExpand = 0; + // Place elements int cxNeeded = 0; + int cyNeeded = 0; + int cxExpand = 0; if( nAdjustables > 0 ) cxExpand = MAX(0, (szAvailable.cx - cxFixed) / nAdjustables); // Position the elements SIZE szRemaining = szAvailable; + int iPosY = rc.top; + if (m_pVerticalScrollBar && m_pVerticalScrollBar->IsVisible()) { + iPosY -= m_pVerticalScrollBar->GetScrollPos(); + } int iPosX = rc.left; if( m_pHorizontalScrollBar && m_pHorizontalScrollBar->IsVisible() ) { iPosX -= m_pHorizontalScrollBar->GetScrollPos(); @@ -88,6 +94,7 @@ namespace DuiLib SetFloatPos(it2); continue; } + RECT rcPadding = pControl->GetPadding(); szRemaining.cx -= rcPadding.left; SIZE sz = pControl->EstimateSize(szRemaining); @@ -104,49 +111,29 @@ namespace DuiLib else { if( sz.cx < pControl->GetMinWidth() ) sz.cx = pControl->GetMinWidth(); if( sz.cx > pControl->GetMaxWidth() ) sz.cx = pControl->GetMaxWidth(); - // cxFixedRemaining -= sz.cx + rcPadding.left + rcPadding.right ; } // cxFixedRemaining -= m_iChildPadding; sz.cy = pControl->GetFixedHeight(); - if( sz.cy == 0 ) sz.cy = rc.bottom - rc.top - rcPadding.top - rcPadding.bottom; + if( sz.cy == 0 ) sz.cy = szAvailable.cy - rcPadding.top - rcPadding.bottom; if( sz.cy < 0 ) sz.cy = 0; if( sz.cy < pControl->GetMinHeight() ) sz.cy = pControl->GetMinHeight(); if( sz.cy > pControl->GetMaxHeight() ) sz.cy = pControl->GetMaxHeight(); - RECT rcCtrl = { iPosX + rcPadding.left, rc.top + rcPadding.top, iPosX + sz.cx + rcPadding.left , rc.top + rcPadding.top + sz.cy}; + RECT rcCtrl = { iPosX + rcPadding.left, iPosY + rcPadding.top, iPosX + rcPadding.left + sz.cx, iPosY + rcPadding.top + sz.cy }; pControl->SetPos(rcCtrl); + iPosX += sz.cx + m_iChildPadding + rcPadding.left + rcPadding.right; cxNeeded += sz.cx + rcPadding.left + rcPadding.right; + cyNeeded = ((sz.cy + rcPadding.top + rcPadding.bottom) > cyNeeded) ? (sz.cy + rcPadding.top + rcPadding.bottom) : cyNeeded; szRemaining.cx -= sz.cx + m_iChildPadding + rcPadding.right; } cxNeeded += (nEstimateNum - 1) * m_iChildPadding; -//reddrain - if( m_pHorizontalScrollBar != NULL ) { - if( cxNeeded > rc.right - rc.left ) { - if( m_pHorizontalScrollBar->IsVisible() ) { - m_pHorizontalScrollBar->SetScrollRange(cxNeeded - (rc.right - rc.left)); - } - else { - m_pHorizontalScrollBar->SetVisible(true); - m_pHorizontalScrollBar->SetScrollRange(cxNeeded - (rc.right - rc.left)); - m_pHorizontalScrollBar->SetScrollPos(0); - rc.bottom -= m_pHorizontalScrollBar->GetFixedHeight(); - } - } - else { - if( m_pHorizontalScrollBar->IsVisible() ) { - m_pHorizontalScrollBar->SetVisible(false); - m_pHorizontalScrollBar->SetScrollRange(0); - m_pHorizontalScrollBar->SetScrollPos(0); - rc.bottom += m_pHorizontalScrollBar->GetFixedHeight(); - } - } - } - ProcessScrollBar(rc, cxNeeded, 0); + // Process the scrollbar + ProcessScrollBar(rc, cxNeeded, cyNeeded); } void CHorizontalLayoutUI::DoPostPaint(HDC hDC, const RECT& rcPaint) diff --git a/DuiLib/Layout/UIVerticalLayout.cpp b/DuiLib/Layout/UIVerticalLayout.cpp index 3463af31..4c6f5977 100644 --- a/DuiLib/Layout/UIVerticalLayout.cpp +++ b/DuiLib/Layout/UIVerticalLayout.cpp @@ -28,6 +28,7 @@ namespace DuiLib void CVerticalLayoutUI::SetPos(RECT rc, bool bNeedInvalidate) { + // heliangbao CControlUI::SetPos(rc, bNeedInvalidate); rc = m_rcItem; @@ -46,8 +47,8 @@ namespace DuiLib // Determine the minimum size SIZE szAvailable = { rc.right - rc.left, rc.bottom - rc.top }; - if( m_pHorizontalScrollBar && m_pHorizontalScrollBar->IsVisible() ) - szAvailable.cx += m_pHorizontalScrollBar->GetScrollRange(); + //if( m_pHorizontalScrollBar && m_pHorizontalScrollBar->IsVisible() ) + //szAvailable.cx += m_pHorizontalScrollBar->GetScrollRange(); int nAdjustables = 0; int cyFixed = 0; @@ -70,6 +71,7 @@ namespace DuiLib cyFixed += (nEstimateNum - 1) * m_iChildPadding; // Place elements + int cxNeeded = 0; int cyNeeded = 0; int cyExpand = 0; if( nAdjustables > 0 ) cyExpand = MAX(0, (szAvailable.cy - cyFixed) / nAdjustables); @@ -120,17 +122,18 @@ namespace DuiLib if( sz.cx < pControl->GetMinWidth() ) sz.cx = pControl->GetMinWidth(); if( sz.cx > pControl->GetMaxWidth() ) sz.cx = pControl->GetMaxWidth(); - RECT rcCtrl = { iPosX + rcPadding.left, iPosY + rcPadding.top, iPosX + rcPadding.left + sz.cx, iPosY + sz.cy + rcPadding.top }; + RECT rcCtrl = { iPosX + rcPadding.left, iPosY + rcPadding.top, iPosX + rcPadding.left + sz.cx, iPosY + rcPadding.top + sz.cy }; pControl->SetPos(rcCtrl); iPosY += sz.cy + m_iChildPadding + rcPadding.top + rcPadding.bottom; + cxNeeded = ((sz.cx + rcPadding.left + rcPadding.right) > cxNeeded) ? (sz.cx + rcPadding.left + rcPadding.right) : cxNeeded; cyNeeded += sz.cy + rcPadding.top + rcPadding.bottom; szRemaining.cy -= sz.cy + m_iChildPadding + rcPadding.bottom; } cyNeeded += (nEstimateNum - 1) * m_iChildPadding; // Process the scrollbar - ProcessScrollBar(rc, 0, cyNeeded); + ProcessScrollBar(rc, cxNeeded, cyNeeded); } void CVerticalLayoutUI::DoPostPaint(HDC hDC, const RECT& rcPaint) diff --git a/Lib/DuiLibA_d.lib b/Lib/DuiLibA_d.lib new file mode 100644 index 00000000..139fc52e Binary files /dev/null and b/Lib/DuiLibA_d.lib differ diff --git a/Lib/DuiLib_d.lib b/Lib/DuiLib_d.lib new file mode 100644 index 00000000..99400d85 Binary files /dev/null and b/Lib/DuiLib_d.lib differ diff --git a/Temp/duidemo/Debug/duidemo.res b/Temp/duidemo/Debug/duidemo.res new file mode 100644 index 00000000..3aa5ea7a Binary files /dev/null and b/Temp/duidemo/Debug/duidemo.res differ diff --git a/Temp/duidemo/Debug/duidemo_d.exe.embed.manifest.res b/Temp/duidemo/Debug/duidemo_d.exe.embed.manifest.res new file mode 100644 index 00000000..59111fd1 Binary files /dev/null and b/Temp/duidemo/Debug/duidemo_d.exe.embed.manifest.res differ diff --git a/Temp/duidemo/Debug/duidemo_d_manifest.rc b/Temp/duidemo/Debug/duidemo_d_manifest.rc new file mode 100644 index 00000000..b04b59f3 Binary files /dev/null and b/Temp/duidemo/Debug/duidemo_d_manifest.rc differ diff --git a/Temp/duidemo/DebugA/duidemo.res b/Temp/duidemo/DebugA/duidemo.res new file mode 100644 index 00000000..3aa5ea7a Binary files /dev/null and b/Temp/duidemo/DebugA/duidemo.res differ diff --git a/Temp/duidemo/DebugA/duidemo_d.exe.embed.manifest.res b/Temp/duidemo/DebugA/duidemo_d.exe.embed.manifest.res new file mode 100644 index 00000000..59111fd1 Binary files /dev/null and b/Temp/duidemo/DebugA/duidemo_d.exe.embed.manifest.res differ diff --git a/Temp/duidemo/DebugA/duidemo_d_manifest.rc b/Temp/duidemo/DebugA/duidemo_d_manifest.rc new file mode 100644 index 00000000..2bee02d5 Binary files /dev/null and b/Temp/duidemo/DebugA/duidemo_d_manifest.rc differ