diff --git a/Demos/duidemo/MainWnd.h b/Demos/duidemo/MainWnd.h index 1e0e927f..bbd34a48 100644 --- a/Demos/duidemo/MainWnd.h +++ b/Demos/duidemo/MainWnd.h @@ -24,7 +24,7 @@ class CDemoFrame : public WindowImplBase, public CWebBrowserEventHandler, public CWebBrowserUI* pBrowser2 = static_cast(m_PaintManager.FindControl(_T("oneclick_browser2"))); pBrowser2->SetWebBrowserEventHandler(this); pBrowser1->NavigateUrl(_T("http://blog.csdn.net/duisharp")); - pBrowser2->NavigateUrl(_T("http://www.2345.com/?kms656067418")); + pBrowser2->NavigateUrl(_T("https://github.com/duisharp/DuiLib_Ultimate")); CComboUI* pFontSize = static_cast(m_PaintManager.FindControl(_T("font_size"))); if(pFontSize) @@ -35,6 +35,17 @@ class CDemoFrame : public WindowImplBase, public CWebBrowserEventHandler, public pElement->SetFixedWidth(120); pFontSize->Add(pElement); } + + CListUI* pList = static_cast(m_PaintManager.FindControl(_T("listview"))); + for(int i = 0; i < 20; i++) + { + CListTextElementUI* pItem = new CListTextElementUI(); + pItem->SetFixedHeight(30); + pList->Add(pItem); + pItem->SetText(0, _T("张三")); + pItem->SetText(1, _T("1000")); + pItem->SetText(2, _T("100")); + } } virtual BOOL Receive(SkinChangedParam param) diff --git a/DuiLib/Control/UILabel.cpp b/DuiLib/Control/UILabel.cpp index 48e38277..2ffb66bb 100644 --- a/DuiLib/Control/UILabel.cpp +++ b/DuiLib/Control/UILabel.cpp @@ -4,54 +4,17 @@ #include namespace DuiLib { - - //Color _MakeRGB(int a, Color cl) - //{ - // return Color(a, cl.GetR(), cl.GetG(), cl.GetB()); - //} - - //Color _MakeRGB(int r, int g, int b) - //{ - // return Color(255, r, g, b); - //} - - CLabelUI::CLabelUI() : m_uTextStyle(DT_VCENTER), m_dwTextColor(0), + CLabelUI::CLabelUI() : m_uTextStyle(DT_VCENTER | DT_SINGLELINE), m_dwTextColor(0), m_dwDisabledTextColor(0), m_iFont(-1), m_bShowHtml(false), - - m_EnableEffect(false), - m_gdiplusToken(0), - //m_TextRenderingHintAntiAlias(TextRenderingHintSystemDefault), - m_TransShadow(60), - m_TransText(168), - m_TransShadow1(60), - m_TransText1(168), - m_hAlign(DT_LEFT), - m_vAlign(DT_CENTER), - m_dwTextColor1(-1), - m_dwTextShadowColorA(0xff000000), - m_dwTextShadowColorB(-1), - m_GradientAngle(0), - m_EnabledStroke(false), - m_TransStroke(255), - m_dwStrokeColor(0), - m_bAutoCalcWidth(false), - m_EnabledShadow(false), - m_GradientLength(0) + m_bAutoCalcWidth(false) { - //m_ShadowOffset.X = 0.0f; - //m_ShadowOffset.Y = 0.0f; - //m_ShadowOffset.Width = 0.0f; - //m_ShadowOffset.Height = 0.0f; - //GdiplusStartup( &m_gdiplusToken,&m_gdiplusStartupInput, NULL); - ::ZeroMemory(&m_rcTextPadding, sizeof(m_rcTextPadding)); } CLabelUI::~CLabelUI() { - // GdiplusShutdown( m_gdiplusToken ); } LPCTSTR CLabelUI::GetClass() const @@ -135,10 +98,8 @@ namespace DuiLib SIZE CLabelUI::EstimateSize(SIZE szAvailable) { - if (m_bAutoCalcWidth) - { + if (m_bAutoCalcWidth) { RECT rcText = {0}; - CRenderEngine::DrawText(m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, m_dwTextColor, m_iFont, DT_CALCRECT | m_uTextStyle); m_cxyFixed.cx = rcText.right - rcText.left + m_rcTextPadding.left + m_rcTextPadding.right; } @@ -203,6 +164,16 @@ namespace DuiLib else if( _tcscmp(pstrName, _T("endellipsis")) == 0 ) { if( _tcscmp(pstrValue, _T("true")) == 0 ) m_uTextStyle |= DT_END_ELLIPSIS; else m_uTextStyle &= ~DT_END_ELLIPSIS; + } + else if( _tcscmp(pstrName, _T("wordbreak")) == 0 ) { + if( _tcscmp(pstrValue, _T("true")) == 0 ) { + m_uTextStyle &= ~DT_SINGLELINE; + m_uTextStyle |= DT_WORDBREAK | DT_EDITCONTROL; + } + else { + m_uTextStyle &= ~DT_WORDBREAK & ~DT_EDITCONTROL; + m_uTextStyle |= DT_SINGLELINE; + } } else if( _tcscmp(pstrName, _T("font")) == 0 ) SetFont(_ttoi(pstrValue)); else if( _tcscmp(pstrName, _T("textcolor")) == 0 ) { @@ -227,48 +198,6 @@ namespace DuiLib SetTextPadding(rcTextPadding); } else if( _tcscmp(pstrName, _T("showhtml")) == 0 ) SetShowHtml(_tcscmp(pstrValue, _T("true")) == 0); - - else if( _tcscmp(pstrName, _T("enabledeffect")) == 0 ) SetEnabledEffect(_tcscmp(pstrValue, _T("true")) == 0); - //else if( _tcscmp(pstrName, _T("rhaa")) == 0 ) SetTextRenderingHintAntiAlias(_ttoi(pstrValue)); - else if( _tcscmp(pstrName, _T("transshadow")) == 0 ) SetTransShadow(_ttoi(pstrValue)); - else if( _tcscmp(pstrName, _T("transtext")) == 0 ) SetTransText(_ttoi(pstrValue)); - else if( _tcscmp(pstrName, _T("transshadow1")) == 0 ) SetTransShadow1(_ttoi(pstrValue)); - else if( _tcscmp(pstrName, _T("transtext1")) == 0 ) SetTransText1(_ttoi(pstrValue)); - else if( _tcscmp(pstrName, _T("gradientangle")) == 0 ) SetGradientAngle(_ttoi(pstrValue)); - else if( _tcscmp(pstrName, _T("enabledstroke")) == 0 ) SetEnabledStroke(_tcscmp(pstrValue, _T("true")) == 0); - else if( _tcscmp(pstrName, _T("enabledshadow")) == 0 ) SetEnabledShadow(_tcscmp(pstrValue, _T("true")) == 0); - else if( _tcscmp(pstrName, _T("transstroke")) == 0 ) SetTransStroke(_ttoi(pstrValue)); - else if( _tcscmp(pstrName, _T("gradientlength")) == 0 ) SetGradientLength(_ttoi(pstrValue)); - else if( _tcscmp(pstrName, _T("shadowoffset")) == 0 ){ - LPTSTR pstr = NULL; - int offsetx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr); - int offsety = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr); - SetShadowOffset(offsetx,offsety); - } - else if( _tcscmp(pstrName, _T("textcolor1")) == 0 ) { - if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue); - LPTSTR pstr = NULL; - DWORD clrColor = _tcstoul(pstrValue, &pstr, 16); - SetTextColor1(clrColor); - } - else if( _tcscmp(pstrName, _T("textshadowcolora")) == 0 ) { - if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue); - LPTSTR pstr = NULL; - DWORD clrColor = _tcstoul(pstrValue, &pstr, 16); - SetTextShadowColorA(clrColor); - } - else if( _tcscmp(pstrName, _T("textshadowcolorb")) == 0 ) { - if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue); - LPTSTR pstr = NULL; - DWORD clrColor = _tcstoul(pstrValue, &pstr, 16); - SetTextShadowColorB(clrColor); - } - else if( _tcscmp(pstrName, _T("strokecolor")) == 0 ) { - if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue); - LPTSTR pstr = NULL; - DWORD clrColor = _tcstoul(pstrValue, &pstr, 16); - SetStrokeColor(clrColor); - } else if( _tcscmp(pstrName, _T("autocalcwidth")) == 0 ) { SetAutoCalcWidth(_tcscmp(pstrValue, _T("true")) == 0); } @@ -286,102 +215,24 @@ namespace DuiLib rc.top += m_rcTextPadding.top; rc.bottom -= m_rcTextPadding.bottom; - if(!GetEnabledEffect()) - { - if( m_sText.IsEmpty() ) return; - int nLinks = 0; - if( IsEnabled() ) { - if( m_bShowHtml ) - CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwTextColor, \ - NULL, NULL, nLinks, DT_SINGLELINE | m_uTextStyle); - else - CRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwTextColor, \ - m_iFont, DT_SINGLELINE | m_uTextStyle); - } - else { - if( m_bShowHtml ) - CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, \ - NULL, NULL, nLinks, DT_SINGLELINE | m_uTextStyle); - else - CRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, \ - m_iFont, DT_SINGLELINE | m_uTextStyle); - } + if( m_sText.IsEmpty() ) return; + int nLinks = 0; + if( IsEnabled() ) { + if( m_bShowHtml ) + CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwTextColor, \ + NULL, NULL, nLinks, DT_SINGLELINE | m_uTextStyle); + else + CRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwTextColor, \ + m_iFont, m_uTextStyle); } - else - { - //不使用GDI+,不使用特效 - ASSERT(FALSE); + else { + if( m_bShowHtml ) + CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, \ + NULL, NULL, nLinks, DT_SINGLELINE | m_uTextStyle); + else + CRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, \ + m_iFont, m_uTextStyle); } - // else - // { - // Font nFont(hDC,m_pManager->GetFont(GetFont())); - // - // Graphics nGraphics(hDC); - // nGraphics.SetTextRenderingHint(m_TextRenderingHintAntiAlias); - // - // StringFormat format; - // format.SetAlignment((StringAlignment)m_hAlign); - // format.SetLineAlignment((StringAlignment)m_vAlign); - // - // RectF nRc((float)rc.left,(float)rc.top,(float)rc.right-rc.left,(float)rc.bottom-rc.top); - // RectF nShadowRc = nRc; - // nShadowRc.X += m_ShadowOffset.X; - // nShadowRc.Y += m_ShadowOffset.Y; - // - // int nGradientLength = GetGradientLength(); - // - // if(nGradientLength == 0) - // nGradientLength = (rc.bottom-rc.top); - // - // LinearGradientBrush nLineGrBrushA(Point(GetGradientAngle(), 0),Point(0,nGradientLength),_MakeRGB(GetTransShadow(),GetTextShadowColorA()),_MakeRGB(GetTransShadow1(),GetTextShadowColorB() == -1?GetTextShadowColorA():GetTextShadowColorB())); - // LinearGradientBrush nLineGrBrushB(Point(GetGradientAngle(), 0),Point(0,nGradientLength),_MakeRGB(GetTransText(),GetTextColor()),_MakeRGB(GetTransText1(),GetTextColor1() == -1?GetTextColor():GetTextColor1())); - // - // if(GetEnabledStroke() && GetStrokeColor() > 0) - // { - // LinearGradientBrush nLineGrBrushStroke(Point(GetGradientAngle(),0),Point(0,rc.bottom-rc.top+2),_MakeRGB(GetTransStroke(),GetStrokeColor()),_MakeRGB(GetTransStroke(),GetStrokeColor())); - // - //#ifdef _UNICODE - // nRc.Offset(-1,0); - // nGraphics.DrawString(m_TextValue,m_TextValue.GetLength(),&nFont,nRc,&format,&nLineGrBrushStroke); - // nRc.Offset(2,0); - // nGraphics.DrawString(m_TextValue,m_TextValue.GetLength(),&nFont,nRc,&format,&nLineGrBrushStroke); - // nRc.Offset(-1,-1); - // nGraphics.DrawString(m_TextValue,m_TextValue.GetLength(),&nFont,nRc,&format,&nLineGrBrushStroke); - // nRc.Offset(0,2); - // nGraphics.DrawString(m_TextValue,m_TextValue.GetLength(),&nFont,nRc,&format,&nLineGrBrushStroke); - // nRc.Offset(0,-1); - //#else - // USES_CONVERSION; - // wstring mTextValue = A2W(m_TextValue.GetData()); - // - // nRc.Offset(-1,0); - // nGraphics.DrawString(mTextValue.c_str(),mTextValue.length(),&nFont,nRc,&format,&nLineGrBrushStroke); - // nRc.Offset(2,0); - // nGraphics.DrawString(mTextValue.c_str(),mTextValue.length(),&nFont,nRc,&format,&nLineGrBrushStroke); - // nRc.Offset(-1,-1); - // nGraphics.DrawString(mTextValue.c_str(),mTextValue.length(),&nFont,nRc,&format,&nLineGrBrushStroke); - // nRc.Offset(0,2); - // nGraphics.DrawString(mTextValue.c_str(),mTextValue.length(),&nFont,nRc,&format,&nLineGrBrushStroke); - // nRc.Offset(0,-1); - //#endif - // - // } - //#ifdef _UNICODE - // if(GetEnabledShadow() && (GetTextShadowColorA() > 0 || GetTextShadowColorB() > 0)) - // nGraphics.DrawString(m_TextValue,m_TextValue.GetLength(),&nFont,nShadowRc,&format,&nLineGrBrushA); - // - // nGraphics.DrawString(m_TextValue,m_TextValue.GetLength(),&nFont,nRc,&format,&nLineGrBrushB); - //#else - // USES_CONVERSION; - // wstring mTextValue = A2W(m_TextValue.GetData()); - // - // if(GetEnabledShadow() && (GetTextShadowColorA() > 0 || GetTextShadowColorB() > 0)) - // nGraphics.DrawString(mTextValue.c_str(),mTextValue.length(),&nFont,nShadowRc,&format,&nLineGrBrushA); - // - // nGraphics.DrawString(mTextValue.c_str(),mTextValue.length(),&nFont,nRc,&format,&nLineGrBrushB); - //#endif - // - // } } bool CLabelUI::GetAutoCalcWidth() const @@ -394,197 +245,10 @@ namespace DuiLib m_bAutoCalcWidth = bAutoCalcWidth; } - void CLabelUI::SetTransShadow( int _TransShadow ) - { - m_TransShadow = _TransShadow; - } - - int CLabelUI::GetTransShadow() - { - return m_TransShadow; - } - - //void CLabelUI::SetTextRenderingHintAntiAlias( int _TextRenderingHintAntiAlias ) - //{ - // if(_TextRenderingHintAntiAlias < 0 || _TextRenderingHintAntiAlias > 5) - // _TextRenderingHintAntiAlias = 0; - // m_TextRenderingHintAntiAlias = (TextRenderingHint)_TextRenderingHintAntiAlias; - //} - - //int CLabelUI::GetTextRenderingHintAntiAlias() - //{ - // return m_TextRenderingHintAntiAlias; - //} - - void CLabelUI::SetShadowOffset( int _offset,int _angle ) - { - if(_angle > 180 || _angle < -180) - return; - - RECT rc = m_rcItem; - - if(_angle >= 0 && _angle <= 180) - rc.top -= _offset; - else if(_angle > -180 && _angle < 0) - rc.top += _offset; - - if(_angle > -90 && _angle <= 90) - rc.left -= _offset; - else if( _angle > 90 || _angle < -90) - rc.left += _offset; - - //m_ShadowOffset.X = (float)rc.top; - //m_ShadowOffset.Y = (float)rc.left; - } - - //RectF CLabelUI::GetShadowOffset() - //{ - // return m_ShadowOffset; - //} - void CLabelUI::SetText( LPCTSTR pstrText ) { - if(!GetEnabledEffect()) + if(!m_bAutoCalcWidth) return CControlUI::SetText(pstrText); - - m_TextValue = pstrText; - } - - CDuiString CLabelUI::GetText() const - { - if(!m_EnableEffect) - return CControlUI::GetText(); - return m_TextValue; - } - - void CLabelUI::SetEnabledEffect( bool _EnabledEffect ) - { - m_EnableEffect = _EnabledEffect; - } - - bool CLabelUI::GetEnabledEffect() - { - return m_EnableEffect; - } - - void CLabelUI::SetTextColor1( DWORD _TextColor1 ) - { - m_dwTextColor1 = _TextColor1; - } - - DWORD CLabelUI::GetTextColor1() - { - return m_dwTextColor1; + else this->NeedParentUpdate(); } - - void CLabelUI::SetTextShadowColorA( DWORD _TextShadowColorA ) - { - m_dwTextShadowColorA = _TextShadowColorA; - } - - DWORD CLabelUI::GetTextShadowColorA() - { - return m_dwTextShadowColorA; - } - - void CLabelUI::SetTextShadowColorB( DWORD _TextShadowColorB ) - { - m_dwTextShadowColorB = _TextShadowColorB; - } - - DWORD CLabelUI::GetTextShadowColorB() - { - return m_dwTextShadowColorB; - } - - void CLabelUI::SetTransText( int _TransText ) - { - m_TransText = _TransText; - } - - int CLabelUI::GetTransText() - { - return m_TransText; - } - - void CLabelUI::SetTransShadow1( int _TransShadow ) - { - m_TransShadow1 = _TransShadow; - } - - int CLabelUI::GetTransShadow1() - { - return m_TransShadow1; - } - - void CLabelUI::SetTransText1( int _TransText ) - { - m_TransText1 = _TransText; - } - - int CLabelUI::GetTransText1() - { - return m_TransText1; - } - - void CLabelUI::SetGradientAngle( int _SetGradientAngle ) - { - m_GradientAngle = _SetGradientAngle; - } - - int CLabelUI::GetGradientAngle() - { - return m_GradientAngle; - } - - void CLabelUI::SetEnabledStroke( bool _EnabledStroke ) - { - m_EnabledStroke = _EnabledStroke; - } - - bool CLabelUI::GetEnabledStroke() - { - return m_EnabledStroke; - } - - void CLabelUI::SetTransStroke( int _TransStroke ) - { - m_TransStroke = _TransStroke; - } - - int CLabelUI::GetTransStroke() - { - return m_TransStroke; - } - - void CLabelUI::SetStrokeColor( DWORD _StrokeColor ) - { - m_dwStrokeColor = _StrokeColor; - } - - DWORD CLabelUI::GetStrokeColor() - { - return m_dwStrokeColor; - } - - void CLabelUI::SetEnabledShadow( bool _EnabledShadowe ) - { - m_EnabledShadow = _EnabledShadowe; - } - - bool CLabelUI::GetEnabledShadow() - { - return m_EnabledShadow; - } - - void CLabelUI::SetGradientLength( int _GradientLength ) - { - m_GradientLength = _GradientLength; - } - - int CLabelUI::GetGradientLength() - { - return m_GradientLength; - } - } \ No newline at end of file diff --git a/DuiLib/Control/UILabel.h b/DuiLib/Control/UILabel.h index d1548f1e..ace359fd 100644 --- a/DuiLib/Control/UILabel.h +++ b/DuiLib/Control/UILabel.h @@ -35,38 +35,7 @@ namespace DuiLib virtual bool GetAutoCalcWidth() const; virtual void SetAutoCalcWidth(bool bAutoCalcWidth); - - void SetEnabledEffect(bool _EnabledEffect); - bool GetEnabledEffect(); - void SetText(LPCTSTR pstrText); - CDuiString GetText() const; - void SetTransShadow(int _TransShadow); - int GetTransShadow(); - void SetTransShadow1(int _TransShadow); - int GetTransShadow1(); - void SetTransText(int _TransText); - int GetTransText(); - void SetTransText1(int _TransText); - int GetTransText1(); - void SetTransStroke(int _TransStroke); - int GetTransStroke(); - void SetGradientLength(int _GradientLength); - int GetGradientLength(); - void SetShadowOffset(int _offset,int _angle); - void SetTextColor1(DWORD _TextColor1); - DWORD GetTextColor1(); - void SetTextShadowColorA(DWORD _TextShadowColorA); - DWORD GetTextShadowColorA(); - void SetTextShadowColorB(DWORD _TextShadowColorB); - DWORD GetTextShadowColorB(); - void SetStrokeColor(DWORD _StrokeColor); - DWORD GetStrokeColor(); - void SetGradientAngle(int _SetGradientAngle); - int GetGradientAngle(); - void SetEnabledStroke(bool _EnabledStroke); - bool GetEnabledStroke(); - void SetEnabledShadow(bool _EnabledShadowe); - bool GetEnabledShadow(); + void SetText(LPCTSTR pstrText); protected: DWORD m_dwTextColor; @@ -76,27 +45,6 @@ namespace DuiLib RECT m_rcTextPadding; bool m_bShowHtml; bool m_bAutoCalcWidth; - - int m_hAlign; - int m_vAlign; - int m_TransShadow; - int m_TransShadow1; - int m_TransText; - int m_TransText1; - int m_TransStroke; - int m_GradientLength; - int m_GradientAngle; - bool m_EnableEffect; - bool m_EnabledStroke; - bool m_EnabledShadow; - DWORD m_dwTextColor1; - DWORD m_dwTextShadowColorA; - DWORD m_dwTextShadowColorB; - DWORD m_dwStrokeColor; - - CDuiString m_TextValue; - ULONG_PTR m_gdiplusToken; - }; } diff --git a/DuiLib/Control/UIList.cpp b/DuiLib/Control/UIList.cpp index ba400f8d..c7327318 100644 --- a/DuiLib/Control/UIList.cpp +++ b/DuiLib/Control/UIList.cpp @@ -796,9 +796,9 @@ SIZE CListUI::GetScrollRange() const return m_pList->GetScrollRange(); } -void CListUI::SetScrollPos(SIZE szPos) +void CListUI::SetScrollPos(SIZE szPos, bool bMsg) { - m_pList->SetScrollPos(szPos); + m_pList->SetScrollPos(szPos, bMsg); } void CListUI::LineUp() @@ -934,7 +934,7 @@ int __cdecl CListBodyUI::ItemComareFunc(const void *item1, const void *item2) return m_pCompareFunc((UINT_PTR)pControl1, (UINT_PTR)pControl2, m_compareData); } -void CListBodyUI::SetScrollPos(SIZE szPos) +void CListBodyUI::SetScrollPos(SIZE szPos, bool bMsg) { int cx = 0; int cy = 0; @@ -951,6 +951,22 @@ void CListBodyUI::SetScrollPos(SIZE szPos) } if( cx == 0 && cy == 0 ) return; + + RECT rcPos; + for( int it2 = 0; it2 < m_items.GetSize(); it2++ ) { + CControlUI* pControl = static_cast(m_items[it2]); + if( !pControl->IsVisible() ) continue; + if( pControl->IsFloat() ) continue; + + rcPos = pControl->GetPos(); + rcPos.left -= cx; + rcPos.right -= cx; + rcPos.top -= cy; + rcPos.bottom -= cy; + pControl->SetPos(rcPos); + } + + Invalidate(); if( cx != 0 && m_pOwner ) { CListHeaderUI* pHeader = m_pOwner->GetHeader(); @@ -981,23 +997,6 @@ void CListBodyUI::SetScrollPos(SIZE szPos) } } - RECT rcPos; - for( int it2 = 0; it2 < m_items.GetSize(); it2++ ) { - CControlUI* pControl = static_cast(m_items[it2]); - if( !pControl->IsVisible() ) continue; - if( pControl->IsFloat() ) continue; - - rcPos = pControl->GetPos(); - rcPos.left -= cx; - rcPos.right -= cx; - rcPos.top -= cy; - rcPos.bottom -= cy; - pControl->SetPos(rcPos); - } - - Invalidate(); - - } void CListBodyUI::SetPos(RECT rc, bool bNeedInvalidate) @@ -1144,11 +1143,11 @@ void CListBodyUI::DoEvent(TEventUI& event) { if( !IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND ) { if( m_pOwner != NULL ) m_pOwner->DoEvent(event); - else CControlUI::DoEvent(event); + else CVerticalLayoutUI::DoEvent(event); return; } - if( m_pOwner != NULL ) m_pOwner->DoEvent(event); else CControlUI::DoEvent(event); + CVerticalLayoutUI::DoEvent(event); } ///////////////////////////////////////////////////////////////////////////////////// diff --git a/DuiLib/Control/UIList.h b/DuiLib/Control/UIList.h index 517dd4b4..3ff1389a 100644 --- a/DuiLib/Control/UIList.h +++ b/DuiLib/Control/UIList.h @@ -177,7 +177,7 @@ class UILIB_API CListUI : public CVerticalLayoutUI, public IListUI SIZE GetScrollPos() const; SIZE GetScrollRange() const; - void SetScrollPos(SIZE szPos); + void SetScrollPos(SIZE szPos, bool bMsg = true); void LineUp(); void LineDown(); void PageUp(); @@ -215,7 +215,7 @@ class UILIB_API CListBodyUI : public CVerticalLayoutUI public: CListBodyUI(CListUI* pOwner); - void SetScrollPos(SIZE szPos); + void SetScrollPos(SIZE szPos, bool bMsg = true); void SetPos(RECT rc, bool bNeedInvalidate = true); void DoEvent(TEventUI& event); BOOL SortItems(PULVCompareFunc pfnCompare, UINT_PTR dwData); diff --git a/DuiLib/Core/UIContainer.cpp b/DuiLib/Core/UIContainer.cpp index 2dc5a05b..56529449 100644 --- a/DuiLib/Core/UIContainer.cpp +++ b/DuiLib/Core/UIContainer.cpp @@ -14,8 +14,6 @@ namespace DuiLib m_bMouseChildEnabled(true), m_pVerticalScrollBar(NULL), m_pHorizontalScrollBar(NULL), - m_bHScrollProcess(false), - m_bVScrollProcess(false), m_nScrollStepSize(0) { ::ZeroMemory(&m_rcInset, sizeof(m_rcInset)); @@ -785,61 +783,16 @@ namespace DuiLib void CContainerUI::ProcessScrollBar(RECT rc, int cxRequired, int cyRequired) { - /*if( m_pHorizontalScrollBar != NULL && m_pHorizontalScrollBar->IsVisible() ) { - RECT rcScrollBarPos = { rc.left, rc.bottom, rc.right, rc.bottom + m_pHorizontalScrollBar->GetFixedHeight()}; - m_pHorizontalScrollBar->SetPos(rcScrollBarPos); - } - - if( m_pVerticalScrollBar == NULL ) return; - - 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_bScrollProcess = true; - SetPos(m_rcItem); - m_bScrollProcess = false; - return; - } - // No scrollbar required - if( !m_pVerticalScrollBar->IsVisible() ) return; - - // Scroll not needed anymore? - int cyScroll = cyRequired - (rc.bottom - rc.top); - if( cyScroll <= 0 && !m_bScrollProcess) { - 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); - } - } - }*/ - // heliangbao + // by 冰下海 2015/08/16 while (m_pHorizontalScrollBar) { + // Scroll needed 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; } @@ -848,7 +801,7 @@ namespace DuiLib // Scroll not needed anymore? int cxScroll = cxRequired - (rc.right - rc.left); - if (cxScroll <= 0 && !m_bHScrollProcess) + if (cxScroll <= 0) { m_pHorizontalScrollBar->SetVisible(false); m_pHorizontalScrollBar->SetScrollPos(0); @@ -860,14 +813,12 @@ namespace DuiLib RECT rcScrollBarPos = { rc.left, rc.bottom, rc.right, rc.bottom + m_pHorizontalScrollBar->GetFixedHeight() }; m_pHorizontalScrollBar->SetPos(rcScrollBarPos); - if (m_pHorizontalScrollBar->GetScrollRange() != cxScroll) { + 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()) { + m_pHorizontalScrollBar->SetScrollRange(::abs(cxScroll)); // if scrollpos>range then scrollpos=range + if(iScrollPos > m_pHorizontalScrollBar->GetScrollPos()) + { SetPos(m_rcItem); } } @@ -875,15 +826,15 @@ namespace DuiLib break; } - while (m_pVerticalScrollBar && !m_bHScrollProcess) + while (m_pVerticalScrollBar) { - if (cyRequired > rc.bottom - rc.top && !m_pVerticalScrollBar->IsVisible()) { + // Scroll needed + 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; } @@ -892,27 +843,25 @@ namespace DuiLib // Scroll not needed anymore? int cyScroll = cyRequired - (rc.bottom - rc.top); - if (cyScroll <= 0 && !m_bVScrollProcess) { + if (cyScroll <= 0) + { m_pVerticalScrollBar->SetVisible(false); m_pVerticalScrollBar->SetScrollPos(0); m_pVerticalScrollBar->SetScrollRange(0); SetPos(m_rcItem); + break; } - else + + RECT rcScrollBarPos = { rc.right, rc.top, rc.right + m_pVerticalScrollBar->GetFixedWidth(), rc.bottom }; + m_pVerticalScrollBar->SetPos(rcScrollBarPos); + + if (m_pVerticalScrollBar->GetScrollRange() != cyScroll) { - 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); - } + int iScrollPos = m_pVerticalScrollBar->GetScrollPos(); + m_pVerticalScrollBar->SetScrollRange(::abs(cyScroll)); // if scrollpos>range then scrollpos=range + if(iScrollPos > m_pVerticalScrollBar->GetScrollPos()) + { + SetPos(m_rcItem); } } break; diff --git a/DuiLib/Core/UIContainer.h b/DuiLib/Core/UIContainer.h index ed02eee0..ea00a82d 100644 --- a/DuiLib/Core/UIContainer.h +++ b/DuiLib/Core/UIContainer.h @@ -116,8 +116,6 @@ class UILIB_API CContainerUI : public CControlUI, public IContainerUI bool m_bAutoDestroy; bool m_bDelayedDestroy; bool m_bMouseChildEnabled; - bool m_bHScrollProcess; // 防止SetPos循环调用 - bool m_bVScrollProcess; // 防止SetPos循环调用 int m_nScrollStepSize; CScrollBarUI* m_pVerticalScrollBar; diff --git a/DuiLib/Core/UIControl.cpp b/DuiLib/Core/UIControl.cpp index ca8ab8a8..ae4581c1 100644 --- a/DuiLib/Core/UIControl.cpp +++ b/DuiLib/Core/UIControl.cpp @@ -740,6 +740,7 @@ void CControlUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue) } else if( _tcscmp(pstrName, _T("float")) == 0 ) { CDuiString nValue = pstrValue; + // 动态计算相对比例 if(nValue.Find(',') < 0) { SetFloat(_tcscmp(pstrValue, _T("true")) == 0); } diff --git a/bin/skin/duidemo/gifani.gif b/bin/skin/duidemo/gifani.gif new file mode 100644 index 00000000..d6bfc614 Binary files /dev/null and b/bin/skin/duidemo/gifani.gif differ diff --git a/bin/skin/duidemo/main.xml b/bin/skin/duidemo/main.xml index dc1250ad..04af1b06 100644 --- a/bin/skin/duidemo/main.xml +++ b/bin/skin/duidemo/main.xml @@ -3,18 +3,20 @@ - + - + - +