Skip to content

Commit

Permalink
1、Combo支持异形
Browse files Browse the repository at this point in the history
2、修正滚动条区域计算问题
  • Loading branch information
qdtroy committed Apr 11, 2019
1 parent 01c5484 commit 31a709c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 31 deletions.
50 changes: 32 additions & 18 deletions DuiLib/Control/UICombo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ namespace DuiLib {

void CComboWnd::Notify(TNotifyUI& msg)
{
if (msg.sType == _T("windowinit")) {
if (msg.sType == _T("windowinit"))
{
EnsureVisible(m_iOldSel);
}
else if(msg.sType == _T("click")) {
Expand All @@ -47,8 +48,6 @@ namespace DuiLib {
}
pCtrl = pCtrl->GetParent();
}

if( m_pOwner->GetManager() != NULL ) m_pOwner->GetManager()->SendNotify(msg.pSender, DUI_MSGTYPE_CLICK, 0, 0);
}
}

Expand All @@ -61,14 +60,15 @@ namespace DuiLib {

// Position the popup window in absolute space
SIZE szDrop = m_pOwner->GetDropBoxSize();
RECT rcInset = m_pOwner->GetDropBoxInset();
RECT rcOwner = pOwner->GetPos();
RECT rc = rcOwner;
rc.top = rc.bottom; // 父窗口left、bottom位置作为弹出窗口起点
rc.bottom = rc.top + szDrop.cy; // 计算弹出窗口高度
if( szDrop.cx > 0 ) rc.right = rc.left + szDrop.cx; // 计算弹出窗口宽度

SIZE szAvailable = { rc.right - rc.left, rc.bottom - rc.top };
int cyFixed = 0;
int cyFixed = rcInset.top;
for( int it = 0; it < pOwner->GetCount(); it++ ) {
CControlUI* pControl = static_cast<CControlUI*>(pOwner->GetItemAt(it));
if( !pControl->IsVisible() ) continue;
Expand Down Expand Up @@ -138,6 +138,7 @@ namespace DuiLib {
if( uMsg == WM_CREATE ) {
m_pm.SetForceUseSharedRes(true);
m_pm.Init(m_hWnd);
m_pm.SetLayered(true);
// The trick is to add the items to the new container. Their owner gets
// reassigned by this operation - which is why it is important to reassign
// the items back to the righfull owner/manager when the window closes.
Expand All @@ -158,10 +159,8 @@ namespace DuiLib {
m_pLayout->Add(static_cast<CControlUI*>(m_pOwner->GetItemAt(i)));
}
CShadowUI *pShadow = m_pOwner->GetManager()->GetShadow();
if(pShadow != NULL && m_pOwner != NULL) {
pShadow->CopyShadow(m_pm.GetShadow());
m_pm.GetShadow()->ShowShadow(m_pOwner->IsShowShadow());
}
pShadow->CopyShadow(m_pm.GetShadow());
m_pm.GetShadow()->ShowShadow(m_pOwner->IsShowShadow());
m_pm.AttachDialog(m_pLayout);
m_pm.AddNotifier(this);
return 0;
Expand Down Expand Up @@ -232,9 +231,8 @@ namespace DuiLib {

void CComboWnd::EnsureVisible(int iIndex)
{
int nCurSel = m_pOwner->GetCurSel();
if( nCurSel < 0 ) return;
m_pLayout->FindSelectable(nCurSel, false);
if( m_pOwner->GetCurSel() < 0 ) return;
m_pLayout->FindSelectable(m_pOwner->GetCurSel(), false);
RECT rcItem = m_pLayout->GetItemAt(iIndex)->GetPos();
RECT rcList = m_pLayout->GetPos();
CScrollBarUI* pHorizontalScrollBar = m_pLayout->GetHorizontalScrollBar();
Expand All @@ -257,6 +255,7 @@ namespace DuiLib {
#if(_WIN32_WINNT >= 0x0501)
UINT CComboWnd::GetClassStyle() const
{
return __super::GetClassStyle();
if(m_pOwner->IsShowShadow()) {
return __super::GetClassStyle();

Expand All @@ -281,6 +280,7 @@ namespace DuiLib {
{
m_szDropBox = CDuiSize(0, 150);
::ZeroMemory(&m_rcTextPadding, sizeof(m_rcTextPadding));
::ZeroMemory(&m_rcDropBox, sizeof(m_rcDropBox));

m_ListInfo.nColumns = 0;
m_ListInfo.nFont = -1;
Expand Down Expand Up @@ -594,13 +594,9 @@ namespace DuiLib {

CDuiString CComboUI::GetText() const
{
if( m_iCurSel < 0 || m_iCurSel >= m_items.GetSize()) {
return __super::GetText();
}
else {
CControlUI* pControl = static_cast<CControlUI*>(m_items[m_iCurSel]);
return pControl->GetText();
}
if( m_iCurSel < 0 ) return _T("");
CControlUI* pControl = static_cast<CControlUI*>(m_items[m_iCurSel]);
return pControl->GetText();
}

void CComboUI::SetEnabled(bool bEnable)
Expand Down Expand Up @@ -629,6 +625,15 @@ namespace DuiLib {
m_szDropBox = szDropBox;
}

RECT CComboUI::GetDropBoxInset() const
{
return m_rcDropBox;
}

void CComboUI::SetDropBoxInset(RECT rcDropBox)
{
m_rcDropBox = rcDropBox;
}
void CComboUI::SetTextStyle(UINT uStyle)
{
m_uTextStyle = uStyle;
Expand Down Expand Up @@ -1051,6 +1056,15 @@ namespace DuiLib {
szDropBoxSize.cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
SetDropBoxSize(szDropBoxSize);
}
else if( _tcsicmp(pstrName, _T("dropboxinset")) == 0 ) {
RECT rcTextPadding = { 0 };
LPTSTR pstr = NULL;
rcTextPadding.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
rcTextPadding.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
rcTextPadding.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
rcTextPadding.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
SetDropBoxInset(rcTextPadding);
}
else if( _tcsicmp(pstrName, _T("itemfont")) == 0 ) SetItemFont(_ttoi(pstrValue));
else if( _tcsicmp(pstrName, _T("itemalign")) == 0 ) {
if( _tcsstr(pstrValue, _T("left")) != NULL ) {
Expand Down
3 changes: 3 additions & 0 deletions DuiLib/Control/UICombo.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace DuiLib {
void SetDropBoxAttributeList(LPCTSTR pstrList);
SIZE GetDropBoxSize() const;
void SetDropBoxSize(SIZE szDropBox);
RECT GetDropBoxInset() const;
void SetDropBoxInset(RECT szDropBox);

UINT GetListType();
TListInfoUI* GetListInfo();
Expand Down Expand Up @@ -133,6 +135,7 @@ namespace DuiLib {
bool m_bShowShadow;
CDuiString m_sDropBoxAttributes;
SIZE m_szDropBox;
RECT m_rcDropBox;
UINT m_uButtonState;

CDuiString m_sNormalImage;
Expand Down
19 changes: 10 additions & 9 deletions DuiLib/Control/UIList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2319,15 +2319,16 @@ namespace DuiLib {
}

if( cXY.cx == 0 && m_pManager != NULL ) {
RECT rcText = { 0, 0, 9999, cXY.cy };
if( pInfo->bShowHtml ) {
int nLinks = 0;
CRenderEngine::DrawHtmlText(m_pManager->GetPaintDC(), m_pManager, rcText, sText, 0, NULL, NULL, nLinks, pInfo->nFont, DT_SINGLELINE | DT_CALCRECT | pInfo->uTextStyle & ~DT_RIGHT & ~DT_CENTER);
}
else {
CRenderEngine::DrawText(m_pManager->GetPaintDC(), m_pManager, rcText, sText, 0, pInfo->nFont, DT_SINGLELINE | DT_CALCRECT | pInfo->uTextStyle & ~DT_RIGHT & ~DT_CENTER);
}
cXY.cx = rcText.right - rcText.left + pInfo->rcTextPadding.left + pInfo->rcTextPadding.right;
//RECT rcText = { 0, 0, 9999, cXY.cy };
//if( pInfo->bShowHtml ) {
// int nLinks = 0;
// CRenderEngine::DrawHtmlText(m_pManager->GetPaintDC(), m_pManager, rcText, sText, 0, NULL, NULL, nLinks, pInfo->nFont, DT_SINGLELINE | DT_CALCRECT | pInfo->uTextStyle & ~DT_RIGHT & ~DT_CENTER);
//}
//else {
// CRenderEngine::DrawText(m_pManager->GetPaintDC(), m_pManager, rcText, sText, 0, pInfo->nFont, DT_SINGLELINE | DT_CALCRECT | pInfo->uTextStyle & ~DT_RIGHT & ~DT_CENTER);
//}
//cXY.cx = rcText.right - rcText.left + pInfo->rcTextPadding.left + pInfo->rcTextPadding.right;
cXY.cx = szAvailable.cx;
}

return cXY;
Expand Down
2 changes: 1 addition & 1 deletion DuiLib/Control/UIScrollBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace DuiLib
{
IMPLEMENT_DUICONTROL(CScrollBarUI)

CScrollBarUI::CScrollBarUI() : m_bHorizontal(false), m_nRange(100), m_nScrollPos(0), m_nLineSize(8),
CScrollBarUI::CScrollBarUI() : m_bHorizontal(false), m_nRange(0), m_nScrollPos(0), m_nLineSize(8),
m_pOwner(NULL), m_nLastScrollPos(0), m_nLastScrollOffset(0), m_nScrollRepeatDelay(0), m_uButton1State(0), \
m_uButton2State(0), m_uThumbState(0), m_bShowButton1(true), m_bShowButton2(true)
{
Expand Down
6 changes: 3 additions & 3 deletions bin/skin/duidemo/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@
<HorizontalLayout height="60" childvalign="vcenter">
<Label text="Combo控件" textcolor="#FF000000" glowsize="0" font="font13" width="80"/>
<HorizontalLayout height="23" childpadding="12">
<Combo name="font_type" font="3" width="200" style="combo_style" itemfont="0" cursor="hand" showshadow="true" textcolor="#FFFFFFFF" dropbox="hscrollbar=&quot;true&quot;" float="true" pos="300,0,400,23">
<ListLabelElement text="微软雅黑" selected="true" height="23" />
<Combo name="font_type" font="3" width="200" style="combo_style" itemfont="0" cursor="hand" showshadow="true" textcolor="#FFFFFFFF" dropbox="hscrollbar=&quot;true&quot;" float="false" pos1="300,0,400,23">
<ListLabelElement text="微软雅黑" selected="true" height="23" width="200"/>
<ListLabelElement text="宋体" height="23" />
<ListLabelElement text="黑体" height="23" />
<ListLabelElement text="幼圆" height="23" />
Expand All @@ -129,7 +129,7 @@
</ListContainerElement>
</Combo>

<ComboBox name="test" float="true" pos="100,2,0,0" width="230" height="25" bkcolor="#FFEA679F" bordersize="1" bordercolor="0xFFFF0000" vscrollbar="true" hscrollbar="true" >
<ComboBox name="test" float="false" pos="100,2,0,0" width="230" height="25" bkcolor="#FFEA679F" bordersize="1" bordercolor="0xFFFF0000" vscrollbar="true" hscrollbar="true" >
<ListLabelElement text="11111111111111" selected="true"/>
<ListLabelElement text="22222222222222"/>
<ListLabelElement text="33333333333333"/>
Expand Down

0 comments on commit 31a709c

Please sign in to comment.