Skip to content

Commit

Permalink
优化text、div、listctrl、grdictrl、treectrl控件的滚动条最大值得计算方法,使滚动块的长度计算更合理。
Browse files Browse the repository at this point in the history
  • Loading branch information
blueantst committed Jul 6, 2014
1 parent c08c33b commit fad659b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion DuiVision/source/DuiGridCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ BOOL CDuiGridCtrl::Load(TiXmlElement* pXmlElem, BOOL bLoadSubControl)

// 需要的总高度大于显示区高度才会显示滚动条
m_pControScrollV->SetVisible((m_vecRowInfo.size() * m_nRowHeight) > (m_rc.Height() - m_nHeaderHeight));
((CScrollV*)m_pControScrollV)->SetScrollMaxRange(m_vecRowInfo.size() * m_nRowHeight);

// 加载下层的cloumn节点信息
TiXmlElement* pColumnElem = NULL;
Expand Down Expand Up @@ -390,6 +391,7 @@ BOOL CDuiGridCtrl::InsertRow(int nItem, GridRowInfo &rowInfo)

// 需要的总高度大于显示区高度才会显示滚动条
m_pControScrollV->SetVisible((m_vecRowInfo.size() * m_nRowHeight) > (m_rc.Height() - m_nHeaderHeight));
((CScrollV*)m_pControScrollV)->SetScrollMaxRange(m_vecRowInfo.size() * m_nRowHeight);

UpdateControl(true);
return true;
Expand Down Expand Up @@ -693,6 +695,7 @@ void CDuiGridCtrl::SetControlRect(CRect rc)

// 需要的总高度大于显示区高度才会显示滚动条
m_pControScrollV->SetVisible((m_vecRowInfo.size() * m_nRowHeight) > (m_rc.Height() - m_nHeaderHeight));
((CScrollV*)m_pControScrollV)->SetScrollMaxRange(m_vecRowInfo.size() * m_nRowHeight);
}

// 判断指定的坐标位置是否在某一行中
Expand Down Expand Up @@ -1031,7 +1034,7 @@ void CDuiGridCtrl::DrawControl(CDC &dc, CRect rcUpdate)
int nCurPos = pScrollV->GetScrollCurrentPos(); // 当前top位置
int nMaxRange = pScrollV->GetScrollMaxRange();

m_nVirtualTop = nCurPos*(nHeightAll-m_rc.Height())/nMaxRange; // 当前滚动条位置对应的虚拟的top位置
m_nVirtualTop = (nMaxRange > 0) ? nCurPos*(nHeightAll-m_rc.Height())/nMaxRange : 0; // 当前滚动条位置对应的虚拟的top位置
m_nFirstViewRow = m_nVirtualTop / m_nRowHeight; // 显示的第一行序号
m_nLastViewRow = (m_nVirtualTop + m_rc.Height() - m_nHeaderHeight) / m_nRowHeight; // 显示的最后一行序号
if(m_nLastViewRow >= m_vecRowInfo.size())
Expand Down
5 changes: 4 additions & 1 deletion DuiVision/source/DuiListCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ BOOL CDuiListCtrl::Load(TiXmlElement* pXmlElem, BOOL bLoadSubControl)

// 需要的总高度大于显示区高度才会显示滚动条
m_pControScrollV->SetVisible((m_vecRowInfo.size() * m_nRowHeight) > m_rc.Height());
((CScrollV*)m_pControScrollV)->SetScrollMaxRange(m_vecRowInfo.size() * m_nRowHeight);

// 加载下层的row节点信息
TiXmlElement* pRowElem = NULL;
Expand Down Expand Up @@ -303,6 +304,7 @@ BOOL CDuiListCtrl::InsertItem(int nItem, ListRowInfo &rowInfo)

// 需要的总高度大于显示区高度才会显示滚动条
m_pControScrollV->SetVisible((m_vecRowInfo.size() * m_nRowHeight) > m_rc.Height());
((CScrollV*)m_pControScrollV)->SetScrollMaxRange(m_vecRowInfo.size() * m_nRowHeight);

UpdateControl(true);
return true;
Expand Down Expand Up @@ -446,6 +448,7 @@ void CDuiListCtrl::SetControlRect(CRect rc)

// 需要的总高度大于显示区高度才会显示滚动条
m_pControScrollV->SetVisible((m_vecRowInfo.size() * m_nRowHeight) > m_rc.Height());
((CScrollV*)m_pControScrollV)->SetScrollMaxRange(m_vecRowInfo.size() * m_nRowHeight);
}

// 判断指定的坐标位置是否在某一行中
Expand Down Expand Up @@ -786,7 +789,7 @@ void CDuiListCtrl::DrawControl(CDC &dc, CRect rcUpdate)
int nCurPos = pScrollV->GetScrollCurrentPos(); // 当前top位置
int nMaxRange = pScrollV->GetScrollMaxRange();

m_nVirtualTop = nCurPos*(nHeightAll-m_rc.Height())/nMaxRange; // 当前滚动条位置对应的虚拟的top位置
m_nVirtualTop = (nMaxRange > 0) ? nCurPos*(nHeightAll-m_rc.Height())/nMaxRange : 0; // 当前滚动条位置对应的虚拟的top位置
m_nFirstViewRow = m_nVirtualTop / m_nRowHeight; // 显示的第一行序号
m_nLastViewRow = (m_nVirtualTop + m_rc.Height()) / m_nRowHeight; // 显示的最后一行序号
if(m_nLastViewRow >= m_vecRowInfo.size())
Expand Down
1 change: 1 addition & 0 deletions DuiVision/source/DuiText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ int CDuiText::GetVirtualHeight()

// 滚动条只有在需要的总高度大于文本框的高度时候才会显示
m_pControScrollV->SetVisible(size.Height > m_rc.Height());
((CScrollV*)m_pControScrollV)->SetScrollMaxRange(size.Height);

return size.Height;
}
Expand Down
3 changes: 2 additions & 1 deletion DuiVision/source/DuiTreeCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,7 @@ void CDuiTreeCtrl::RefreshNodeRows()

// 需要的总高度大于显示区高度才会显示滚动条
m_pControScrollV->SetVisible((nVisibleRows * m_nRowHeight) > m_rc.Height());
((CScrollV*)m_pControScrollV)->SetScrollMaxRange(nVisibleRows * m_nRowHeight);

UpdateControl(true);
}
Expand Down Expand Up @@ -1494,7 +1495,7 @@ void CDuiTreeCtrl::DrawControl(CDC &dc, CRect rcUpdate)
int nCurPos = pScrollV->GetScrollCurrentPos(); // 当前top位置
int nMaxRange = pScrollV->GetScrollMaxRange();

m_nVirtualTop = nCurPos*(nHeightAll-m_rc.Height())/nMaxRange; // 当前滚动条位置对应的虚拟的top位置
m_nVirtualTop = (nMaxRange > 0) ? nCurPos*(nHeightAll-m_rc.Height())/nMaxRange : 0; // 当前滚动条位置对应的虚拟的top位置
if(m_nVirtualTop < 0)
{
m_nVirtualTop = 0;
Expand Down
3 changes: 3 additions & 0 deletions DuiVision/source/Panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ void CDuiPanel::InitUI(CRect rcClient, TiXmlElement* pNode)

// 需要的总高度大于显示区高度才会显示滚动条
m_pControScrollV->SetVisible(m_nVirtualHeight > m_rc.Height());
((CScrollV*)m_pControScrollV)->SetScrollMaxRange(m_nVirtualHeight);
}

m_bInit = true;
Expand All @@ -230,6 +231,7 @@ void CDuiPanel::CalcVirtualHeight()

// 需要的总高度大于显示区高度才会显示滚动条
m_pControScrollV->SetVisible(m_nVirtualHeight > m_rc.Height());
((CScrollV*)m_pControScrollV)->SetScrollMaxRange(m_nVirtualHeight);
}

void CDuiPanel::SetControlRect(CRect rc)
Expand Down Expand Up @@ -262,6 +264,7 @@ void CDuiPanel::SetControlRect(CRect rc)

// 需要的总高度大于显示区高度才会显示滚动条
m_pControScrollV->SetVisible(m_nVirtualHeight > m_rc.Height());
((CScrollV*)m_pControScrollV)->SetScrollMaxRange(m_nVirtualHeight);
}

// 重载设置控件可见性的函数,需要调用子控件的函数
Expand Down
2 changes: 1 addition & 1 deletion bin/xml/duivision/dlg_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<text pos="170,50,600,80" crtext="000000" crmark="904000" font="bigbig" title="DUI界面库介绍" mask="DUI" />

<text crtext="808080" img-scroll="skin:IDB_SCROLL_V" pos="170,90,680,375"
<text crtext="808080" img-scroll="skin:IDB_SCROLL_V" pos="170,90,-30,-10"
title="DuiVision界面库是参考了仿PC管家程序、金山界面库、DuiEngine等多个基于DirectUI的界面库开发的。
DirectUI技术一般是指将所有的界面控件都绘制在一个窗口上,这些控件的逻辑和绘图方式都必须自己进行编写和封装,而不是使用Windows控件,所以这些控件都是无句柄的。
DirectUI技术需要解决的主要问题如下:
Expand Down

0 comments on commit fad659b

Please sign in to comment.