12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277 |
- #include "StdAfx.h"
- #include "UITreeView.h"
- #pragma warning( disable: 4251 )
- namespace DuiLib
- {
- IMPLEMENT_DUICONTROL(CTreeNodeUI)
- //************************************
- // 函数名称: CTreeNodeUI
- // 返回类型:
- // 参数信息: CTreeNodeUI * _ParentNode
- // 函数说明:
- //************************************
- CTreeNodeUI::CTreeNodeUI( CTreeNodeUI* _ParentNode /*= NULL*/ )
- {
- m_dwItemTextColor = 0x00000000;
- m_dwItemHotTextColor = 0;
- m_dwSelItemTextColor = 0;
- m_dwSelItemHotTextColor = 0;
- pTreeView = NULL;
- m_iTreeLavel = 0;
- m_bIsVisable = TRUE;
- m_bIsCheckBox = FALSE;
- pParentTreeNode = NULL;
- pHoriz = new CHorizontalLayoutUI();
- pFolderButton = new CCheckBoxUI();
- pDottedLine = new CLabelUI();
- pCheckBox = new CCheckBoxUI();
- pItemButton = new COptionUI();
- this->SetFixedHeight(18);
- this->SetFixedWidth(250);
- pFolderButton->SetFixedWidth(GetFixedHeight());
- pDottedLine->SetFixedWidth(2);
- pCheckBox->SetFixedWidth(GetFixedHeight());
- pItemButton->SetAttribute(_T("align"),_T("left"));
- pDottedLine->SetVisible(FALSE);
- pCheckBox->SetVisible(FALSE);
- pItemButton->SetMouseEnabled(FALSE);
- if(_ParentNode) {
- if (_tcsicmp(_ParentNode->GetClass(), _T("TreeNodeUI")) != 0) return;
- pDottedLine->SetVisible(_ParentNode->IsVisible());
- pDottedLine->SetFixedWidth(_ParentNode->GetDottedLine()->GetFixedWidth()+16);
- this->SetParentNode(_ParentNode);
- }
- pHoriz->SetChildVAlign(DT_VCENTER);
- pHoriz->Add(pDottedLine);
- pHoriz->Add(pFolderButton);
- pHoriz->Add(pCheckBox);
- pHoriz->Add(pItemButton);
- Add(pHoriz);
- }
-
- //************************************
- // 函数名称: ~CTreeNodeUI
- // 返回类型:
- // 参数信息: void
- // 函数说明:
- //************************************
- CTreeNodeUI::~CTreeNodeUI( void )
- {
- }
- //************************************
- // 函数名称: GetClass
- // 返回类型: LPCTSTR
- // 函数说明:
- //************************************
- LPCTSTR CTreeNodeUI::GetClass() const
- {
- return _T("TreeNodeUI");
- }
- //************************************
- // 函数名称: GetInterface
- // 返回类型: LPVOID
- // 参数信息: LPCTSTR pstrName
- // 函数说明:
- //************************************
- LPVOID CTreeNodeUI::GetInterface( LPCTSTR pstrName )
- {
- if( _tcsicmp(pstrName, _T("TreeNode")) == 0 )
- return static_cast<CTreeNodeUI*>(this);
- return CListContainerElementUI::GetInterface(pstrName);
- }
-
- //************************************
- // 函数名称: DoEvent
- // 返回类型: void
- // 参数信息: TEventUI & event
- // 函数说明:
- //************************************
- void CTreeNodeUI::DoEvent( TEventUI& event )
- {
- if( !IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND ) {
- if( m_pOwner != NULL ) m_pOwner->DoEvent(event);
- else CContainerUI::DoEvent(event);
- return;
- }
- CListContainerElementUI::DoEvent(event);
- if( event.Type == UIEVENT_DBLCLICK ) {
- if( IsEnabled() ) {
- m_pManager->SendNotify(this, DUI_MSGTYPE_TREEITEMDBCLICK);
- Invalidate();
- }
- return;
- }
- if( event.Type == UIEVENT_MOUSEENTER ) {
- if( IsEnabled()) {
- if(m_bSelected && GetSelItemHotTextColor())
- pItemButton->SetTextColor(GetSelItemHotTextColor());
- else
- pItemButton->SetTextColor(GetItemHotTextColor());
- }
- else
- pItemButton->SetTextColor(pItemButton->GetDisabledTextColor());
- return;
- }
- if( event.Type == UIEVENT_MOUSELEAVE ) {
- if( IsEnabled()) {
- if(m_bSelected && GetSelItemTextColor())
- pItemButton->SetTextColor(GetSelItemTextColor());
- else if(!m_bSelected)
- pItemButton->SetTextColor(GetItemTextColor());
- }
- else
- pItemButton->SetTextColor(pItemButton->GetDisabledTextColor());
- return;
- }
- }
- //************************************
- // 函数名称: Invalidate
- // 返回类型: void
- // 函数说明:
- //************************************
- void CTreeNodeUI::Invalidate()
- {
- if( !IsVisible() )
- return;
- if( GetParent() ) {
- CContainerUI* pParentContainer = static_cast<CContainerUI*>(GetParent()->GetInterface(_T("Container")));
- if( pParentContainer ) {
- RECT rc = pParentContainer->GetPos();
- RECT rcInset = pParentContainer->GetInset();
- rc.left += rcInset.left;
- rc.top += rcInset.top;
- rc.right -= rcInset.right;
- rc.bottom -= rcInset.bottom;
- CScrollBarUI* pVerticalScrollBar = pParentContainer->GetVerticalScrollBar();
- if( pVerticalScrollBar && pVerticalScrollBar->IsVisible() ) rc.right -= pVerticalScrollBar->GetFixedWidth();
- CScrollBarUI* pHorizontalScrollBar = pParentContainer->GetHorizontalScrollBar();
- if( pHorizontalScrollBar && pHorizontalScrollBar->IsVisible() ) rc.bottom -= pHorizontalScrollBar->GetFixedHeight();
- RECT invalidateRc = m_rcItem;
- if( !::IntersectRect(&invalidateRc, &m_rcItem, &rc) )
- return;
- CControlUI* pParent = GetParent();
- RECT rcTemp;
- RECT rcParent;
- while( pParent = pParent->GetParent() ) {
- rcTemp = invalidateRc;
- rcParent = pParent->GetPos();
- if( !::IntersectRect(&invalidateRc, &rcTemp, &rcParent) )
- return;
- }
- if( m_pManager != NULL ) m_pManager->Invalidate(invalidateRc);
- }
- else {
- CContainerUI::Invalidate();
- }
- }
- else {
- CContainerUI::Invalidate();
- }
- }
-
- //************************************
- // 函数名称: Select
- // 返回类型: bool
- // 参数信息: bool bSelect
- // 函数说明:
- //************************************
- bool CTreeNodeUI::Select( bool bSelect /*= true*/ )
- {
- bool nRet = CListContainerElementUI::Select(bSelect);
- if(m_bSelected)
- pItemButton->SetTextColor(GetSelItemTextColor());
- else
- pItemButton->SetTextColor(GetItemTextColor());
- return nRet;
- }
- bool CTreeNodeUI::SelectMulti(bool bSelect)
- {
- bool nRet = CListContainerElementUI::SelectMulti(bSelect);
- if(m_bSelected)
- pItemButton->SetTextColor(GetSelItemTextColor());
- else
- pItemButton->SetTextColor(GetItemTextColor());
- return nRet;
- }
- //************************************
- // 函数名称: Add
- // 返回类型: bool
- // 参数信息: CControlUI * _pTreeNodeUI
- // 函数说明: 通过节点对象添加节点
- //************************************
- bool CTreeNodeUI::Add( CControlUI* _pTreeNodeUI )
- {
- if (NULL != static_cast<CTreeNodeUI*>(_pTreeNodeUI->GetInterface(_T("TreeNode"))))
- return AddChildNode((CTreeNodeUI*)_pTreeNodeUI);
-
- return CListContainerElementUI::Add(_pTreeNodeUI);
- }
- //************************************
- // 函数名称: AddAt
- // 返回类型: bool
- // 参数信息: CControlUI * pControl
- // 参数信息: int iIndex 该参数仅针对当前节点下的兄弟索引,并非列表视图索引
- // 函数说明:
- //************************************
- bool CTreeNodeUI::AddAt( CControlUI* pControl, int iIndex )
- {
- if(NULL == static_cast<CTreeNodeUI*>(pControl->GetInterface(_T("TreeNode"))))
- return FALSE;
- CTreeNodeUI* pIndexNode = static_cast<CTreeNodeUI*>(mTreeNodes.GetAt(iIndex));
- if(!pIndexNode){
- if(!mTreeNodes.Add(pControl))
- return FALSE;
- }
- else if(pIndexNode && !mTreeNodes.InsertAt(iIndex,pControl))
- return FALSE;
- if(!pIndexNode && pTreeView && pTreeView->GetItemAt(GetTreeIndex()+1))
- pIndexNode = static_cast<CTreeNodeUI*>(pTreeView->GetItemAt(GetTreeIndex()+1)->GetInterface(_T("TreeNode")));
- pControl = CalLocation((CTreeNodeUI*)pControl);
- if(pTreeView && pIndexNode)
- return pTreeView->AddAt((CTreeNodeUI*)pControl,pIndexNode);
- else
- return pTreeView->Add((CTreeNodeUI*)pControl);
- return TRUE;
- }
- //************************************
- // 函数名称: Remove
- // 返回类型: bool
- // 参数信息: CControlUI * pControl
- // 函数说明:
- //************************************
- bool CTreeNodeUI::Remove( CControlUI* pControl )
- {
- return RemoveAt((CTreeNodeUI*)pControl);
- }
- //************************************
- // 函数名称: SetVisibleTag
- // 返回类型: void
- // 参数信息: bool _IsVisible
- // 函数说明:
- //************************************
- void CTreeNodeUI::SetVisibleTag( bool _IsVisible )
- {
- m_bIsVisable = _IsVisible;
- }
- //************************************
- // 函数名称: GetVisibleTag
- // 返回类型: bool
- // 函数说明:
- //************************************
- bool CTreeNodeUI::GetVisibleTag()
- {
- return m_bIsVisable;
- }
- //************************************
- // 函数名称: SetItemText
- // 返回类型: void
- // 参数信息: LPCTSTR pstrValue
- // 函数说明:
- //************************************
- void CTreeNodeUI::SetItemText( LPCTSTR pstrValue )
- {
- pItemButton->SetText(pstrValue);
- }
- //************************************
- // 函数名称: GetItemText
- // 返回类型: DuiLib::CDuiString
- // 函数说明:
- //************************************
- CDuiString CTreeNodeUI::GetItemText()
- {
- return pItemButton->GetText();
- }
- //************************************
- // 函数名称: CheckBoxSelected
- // 返回类型: void
- // 参数信息: bool _Selected
- // 函数说明:
- //************************************
- void CTreeNodeUI::CheckBoxSelected( bool _Selected )
- {
- pCheckBox->Selected(_Selected);
- }
- //************************************
- // 函数名称: IsCheckBoxSelected
- // 返回类型: bool
- // 函数说明:
- //************************************
- bool CTreeNodeUI::IsCheckBoxSelected() const
- {
- return pCheckBox->IsSelected();
- }
- //************************************
- // 函数名称: IsHasChild
- // 返回类型: bool
- // 函数说明:
- //************************************
- bool CTreeNodeUI::IsHasChild() const
- {
- return !mTreeNodes.IsEmpty();
- }
- long CTreeNodeUI::GetTreeLevel()
- {
- long level = 0;
- CTreeNodeUI* pParentNode = GetParentNode();
- while(pParentNode != NULL) {
- level++;
- pParentNode = pParentNode->GetParentNode();
- }
- return level;
- }
- //************************************
- // 函数名称: AddChildNode
- // 返回类型: bool
- // 参数信息: CTreeNodeUI * _pTreeNodeUI
- // 函数说明:
- //************************************
- bool CTreeNodeUI::AddChildNode( CTreeNodeUI* _pTreeNodeUI )
- {
- if (!_pTreeNodeUI)
- return FALSE;
- if (NULL == static_cast<CTreeNodeUI*>(_pTreeNodeUI->GetInterface(_T("TreeNode"))))
- return FALSE;
- _pTreeNodeUI = CalLocation(_pTreeNodeUI);
- bool nRet = TRUE;
- if(pTreeView){
- CTreeNodeUI* pNode = static_cast<CTreeNodeUI*>(mTreeNodes.GetAt(mTreeNodes.GetSize()-1));
- if(!pNode || !pNode->GetLastNode())
- nRet = pTreeView->AddAt(_pTreeNodeUI,GetTreeIndex()+1) >= 0;
- else nRet = pTreeView->AddAt(_pTreeNodeUI,pNode->GetLastNode()->GetTreeIndex()+1) >= 0;
- }
- if(nRet)
- mTreeNodes.Add(_pTreeNodeUI);
- return nRet;
- }
- //************************************
- // 函数名称: RemoveAt
- // 返回类型: bool
- // 参数信息: CTreeNodeUI * _pTreeNodeUI
- // 函数说明:
- //************************************
- bool CTreeNodeUI::RemoveAt( CTreeNodeUI* _pTreeNodeUI )
- {
- int nIndex = mTreeNodes.Find(_pTreeNodeUI);
- CTreeNodeUI* pNode = static_cast<CTreeNodeUI*>(mTreeNodes.GetAt(nIndex));
- if(pNode && pNode == _pTreeNodeUI)
- {
- while(pNode->IsHasChild())
- pNode->RemoveAt(static_cast<CTreeNodeUI*>(pNode->mTreeNodes.GetAt(0)));
- mTreeNodes.Remove(nIndex);
- if(pTreeView)
- pTreeView->Remove(_pTreeNodeUI);
- return TRUE;
- }
- return FALSE;
- }
- //************************************
- // 函数名称: SetParentNode
- // 返回类型: void
- // 参数信息: CTreeNodeUI * _pParentTreeNode
- // 函数说明:
- //************************************
- void CTreeNodeUI::SetParentNode( CTreeNodeUI* _pParentTreeNode )
- {
- pParentTreeNode = _pParentTreeNode;
- }
- //************************************
- // 函数名称: GetParentNode
- // 返回类型: CTreeNodeUI*
- // 函数说明:
- //************************************
- CTreeNodeUI* CTreeNodeUI::GetParentNode()
- {
- return pParentTreeNode;
- }
- //************************************
- // 函数名称: GetCountChild
- // 返回类型: long
- // 函数说明:
- //************************************
- long CTreeNodeUI::GetCountChild()
- {
- return mTreeNodes.GetSize();
- }
- //************************************
- // 函数名称: SetTreeView
- // 返回类型: void
- // 参数信息: CTreeViewUI * _CTreeViewUI
- // 函数说明:
- //************************************
- void CTreeNodeUI::SetTreeView( CTreeViewUI* _CTreeViewUI )
- {
- pTreeView = _CTreeViewUI;
- }
- //************************************
- // 函数名称: GetTreeView
- // 返回类型: CTreeViewUI*
- // 函数说明:
- //************************************
- CTreeViewUI* CTreeNodeUI::GetTreeView()
- {
- return pTreeView;
- }
- //************************************
- // 函数名称: SetAttribute
- // 返回类型: void
- // 参数信息: LPCTSTR pstrName
- // 参数信息: LPCTSTR pstrValue
- // 函数说明:
- //************************************
- void CTreeNodeUI::SetAttribute( LPCTSTR pstrName, LPCTSTR pstrValue )
- {
- if(_tcsicmp(pstrName, _T("text")) == 0 )
- pItemButton->SetText(pstrValue);
- else if(_tcsicmp(pstrName, _T("horizattr")) == 0 )
- pHoriz->ApplyAttributeList(pstrValue);
- else if(_tcsicmp(pstrName, _T("dotlineattr")) == 0 )
- pDottedLine->ApplyAttributeList(pstrValue);
- else if(_tcsicmp(pstrName, _T("folderattr")) == 0 )
- pFolderButton->ApplyAttributeList(pstrValue);
- else if(_tcsicmp(pstrName, _T("checkboxattr")) == 0 )
- pCheckBox->ApplyAttributeList(pstrValue);
- else if(_tcsicmp(pstrName, _T("itemattr")) == 0 )
- pItemButton->ApplyAttributeList(pstrValue);
- else if(_tcsicmp(pstrName, _T("itemtextcolor")) == 0 ){
- if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
- LPTSTR pstr = NULL;
- DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
- SetItemTextColor(clrColor);
- }
- else if(_tcsicmp(pstrName, _T("itemhottextcolor")) == 0 ){
- if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
- LPTSTR pstr = NULL;
- DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
- SetItemHotTextColor(clrColor);
- }
- else if(_tcsicmp(pstrName, _T("selitemtextcolor")) == 0 ){
- if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
- LPTSTR pstr = NULL;
- DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
- SetSelItemTextColor(clrColor);
- }
- else if(_tcsicmp(pstrName, _T("selitemhottextcolor")) == 0 ){
- if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
- LPTSTR pstr = NULL;
- DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
- SetSelItemHotTextColor(clrColor);
- }
- else CListContainerElementUI::SetAttribute(pstrName,pstrValue);
- }
- //************************************
- // 函数名称: GetTreeNodes
- // 返回类型: DuiLib::CStdPtrArray
- // 函数说明:
- //************************************
- CStdPtrArray CTreeNodeUI::GetTreeNodes()
- {
- return mTreeNodes;
- }
- //************************************
- // 函数名称: GetChildNode
- // 返回类型: CTreeNodeUI*
- // 参数信息: int _nIndex
- // 函数说明:
- //************************************
- CTreeNodeUI* CTreeNodeUI::GetChildNode( int _nIndex )
- {
- return static_cast<CTreeNodeUI*>(mTreeNodes.GetAt(_nIndex));
- }
- //************************************
- // 函数名称: SetVisibleFolderBtn
- // 返回类型: void
- // 参数信息: bool _IsVisibled
- // 函数说明:
- //************************************
- void CTreeNodeUI::SetVisibleFolderBtn( bool _IsVisibled )
- {
- pFolderButton->SetVisible(_IsVisibled);
- }
- //************************************
- // 函数名称: GetVisibleFolderBtn
- // 返回类型: bool
- // 函数说明:
- //************************************
- bool CTreeNodeUI::GetVisibleFolderBtn()
- {
- return pFolderButton->IsVisible();
- }
- //************************************
- // 函数名称: SetVisibleCheckBtn
- // 返回类型: void
- // 参数信息: bool _IsVisibled
- // 函数说明:
- //************************************
- void CTreeNodeUI::SetVisibleCheckBtn( bool _IsVisibled )
- {
- pCheckBox->SetVisible(_IsVisibled);
- }
- //************************************
- // 函数名称: GetVisibleCheckBtn
- // 返回类型: bool
- // 函数说明:
- //************************************
- bool CTreeNodeUI::GetVisibleCheckBtn()
- {
- return pCheckBox->IsVisible();
- }
-
- //************************************
- // 函数名称: GetNodeIndex
- // 返回类型: int
- // 函数说明: 取得全局树视图的索引
- //************************************
- int CTreeNodeUI::GetTreeIndex()
- {
- if(!pTreeView)
- return -1;
- for(int nIndex = 0;nIndex < pTreeView->GetCount();nIndex++){
- if(this == pTreeView->GetItemAt(nIndex))
- return nIndex;
- }
- return -1;
- }
-
- //************************************
- // 函数名称: GetNodeIndex
- // 返回类型: int
- // 函数说明: 取得相对于兄弟节点的当前索引
- //************************************
- int CTreeNodeUI::GetNodeIndex()
- {
- if(!GetParentNode() && !pTreeView)
- return -1;
- if(!GetParentNode() && pTreeView)
- return GetTreeIndex();
- return GetParentNode()->GetTreeNodes().Find(this);
- }
- //************************************
- // 函数名称: GetLastNode
- // 返回类型: CTreeNodeUI*
- // 函数说明:
- //************************************
- CTreeNodeUI* CTreeNodeUI::GetLastNode( )
- {
- if(!IsHasChild()) return this;
- CTreeNodeUI* nRetNode = NULL;
- for(int nIndex = 0;nIndex < GetTreeNodes().GetSize();nIndex++){
- CTreeNodeUI* pNode = static_cast<CTreeNodeUI*>(GetTreeNodes().GetAt(nIndex));
- if(!pNode) continue;
- if(pNode->IsHasChild())
- nRetNode = pNode->GetLastNode();
- else
- nRetNode = pNode;
- }
-
- return nRetNode;
- }
-
- //************************************
- // 函数名称: CalLocation
- // 返回类型: CTreeNodeUI*
- // 参数信息: CTreeNodeUI * _pTreeNodeUI
- // 函数说明: 缩进计算
- //************************************
- CTreeNodeUI* CTreeNodeUI::CalLocation( CTreeNodeUI* _pTreeNodeUI )
- {
- _pTreeNodeUI->GetDottedLine()->SetVisible(TRUE);
- _pTreeNodeUI->GetDottedLine()->SetFixedWidth(pDottedLine->GetFixedWidth()+16);
- _pTreeNodeUI->SetParentNode(this);
- _pTreeNodeUI->GetItemButton()->SetGroup(pItemButton->GetGroup());
- _pTreeNodeUI->SetTreeView(pTreeView);
- return _pTreeNodeUI;
- }
- //************************************
- // 函数名称: SetTextColor
- // 返回类型: void
- // 参数信息: DWORD _dwTextColor
- // 函数说明:
- //************************************
- void CTreeNodeUI::SetItemTextColor( DWORD _dwItemTextColor )
- {
- m_dwItemTextColor = _dwItemTextColor;
- pItemButton->SetTextColor(m_dwItemTextColor);
- }
- //************************************
- // 函数名称: GetTextColor
- // 返回类型: DWORD
- // 函数说明:
- //************************************
- DWORD CTreeNodeUI::GetItemTextColor() const
- {
- return m_dwItemTextColor;
- }
- //************************************
- // 函数名称: SetTextHotColor
- // 返回类型: void
- // 参数信息: DWORD _dwTextHotColor
- // 函数说明:
- //************************************
- void CTreeNodeUI::SetItemHotTextColor( DWORD _dwItemHotTextColor )
- {
- m_dwItemHotTextColor = _dwItemHotTextColor;
- Invalidate();
- }
- //************************************
- // 函数名称: GetTextHotColor
- // 返回类型: DWORD
- // 函数说明:
- //************************************
- DWORD CTreeNodeUI::GetItemHotTextColor() const
- {
- return m_dwItemHotTextColor;
- }
- //************************************
- // 函数名称: SetSelItemTextColor
- // 返回类型: void
- // 参数信息: DWORD _dwSelItemTextColor
- // 函数说明:
- //************************************
- void CTreeNodeUI::SetSelItemTextColor( DWORD _dwSelItemTextColor )
- {
- m_dwSelItemTextColor = _dwSelItemTextColor;
- Invalidate();
- }
- //************************************
- // 函数名称: GetSelItemTextColor
- // 返回类型: DWORD
- // 函数说明:
- //************************************
- DWORD CTreeNodeUI::GetSelItemTextColor() const
- {
- return m_dwSelItemTextColor;
- }
- //************************************
- // 函数名称: SetSelHotItemTextColor
- // 返回类型: void
- // 参数信息: DWORD _dwSelHotItemTextColor
- // 函数说明:
- //************************************
- void CTreeNodeUI::SetSelItemHotTextColor( DWORD _dwSelHotItemTextColor )
- {
- m_dwSelItemHotTextColor = _dwSelHotItemTextColor;
- Invalidate();
- }
- //************************************
- // 函数名称: GetSelHotItemTextColor
- // 返回类型: DWORD
- // 函数说明:
- //************************************
- DWORD CTreeNodeUI::GetSelItemHotTextColor() const
- {
- return m_dwSelItemHotTextColor;
- }
- /*****************************************************************************/
- /*****************************************************************************/
- /*****************************************************************************/
- IMPLEMENT_DUICONTROL(CTreeViewUI)
-
- //************************************
- // 函数名称: CTreeViewUI
- // 返回类型:
- // 参数信息: void
- // 函数说明:
- //************************************
- CTreeViewUI::CTreeViewUI( void ) : m_bVisibleFolderBtn(TRUE),m_bVisibleCheckBtn(FALSE),m_uItemMinWidth(0)
- {
- this->GetHeader()->SetVisible(FALSE);
- }
-
- //************************************
- // 函数名称: ~CTreeViewUI
- // 返回类型:
- // 参数信息: void
- // 函数说明:
- //************************************
- CTreeViewUI::~CTreeViewUI( void )
- {
-
- }
- //************************************
- // 函数名称: GetClass
- // 返回类型: LPCTSTR
- // 函数说明:
- //************************************
- LPCTSTR CTreeViewUI::GetClass() const
- {
- return _T("TreeViewUI");
- }
- UINT CTreeViewUI::GetListType()
- {
- return LT_TREE;
- }
- //************************************
- // 函数名称: GetInterface
- // 返回类型: LPVOID
- // 参数信息: LPCTSTR pstrName
- // 函数说明:
- //************************************
- LPVOID CTreeViewUI::GetInterface( LPCTSTR pstrName )
- {
- if( _tcsicmp(pstrName, _T("TreeView")) == 0 ) return static_cast<CTreeViewUI*>(this);
- return CListUI::GetInterface(pstrName);
- }
- //************************************
- // 函数名称: Add
- // 返回类型: bool
- // 参数信息: CTreeNodeUI * pControl
- // 函数说明:
- //************************************
- bool CTreeViewUI::Add( CTreeNodeUI* pControl )
- {
- if (!pControl) return false;
- if (NULL == static_cast<CTreeNodeUI*>(pControl->GetInterface(_T("TreeNode")))) return false;
- pControl->OnNotify += MakeDelegate(this,&CTreeViewUI::OnDBClickItem);
- pControl->GetFolderButton()->OnNotify += MakeDelegate(this,&CTreeViewUI::OnFolderChanged);
- pControl->GetCheckBox()->OnNotify += MakeDelegate(this,&CTreeViewUI::OnCheckBoxChanged);
- pControl->SetVisibleFolderBtn(m_bVisibleFolderBtn);
- pControl->SetVisibleCheckBtn(m_bVisibleCheckBtn);
- if(m_uItemMinWidth > 0)
- pControl->SetMinWidth(m_uItemMinWidth);
- CListUI::Add(pControl);
- int nLevel = pControl->GetTreeLevel();
- int nFolderWidth = pControl->GetFolderButton()->GetFixedWidth();
- if(nFolderWidth <= 0) nFolderWidth = 16;
- if(!pControl->GetFolderButton()->IsVisible()) nFolderWidth = 0;
- pControl->GetFolderButton()->SetPadding(CDuiRect(nLevel * nFolderWidth, 0, 0, 0));
- if(pControl->GetCountChild() > 0) {
- int nCount = pControl->GetCountChild();
- for(int nIndex = 0;nIndex < nCount;nIndex++) {
- CTreeNodeUI* pNode = pControl->GetChildNode(nIndex);
- if(pNode) Add(pNode);
- }
- }
- pControl->SetTreeView(this);
- return true;
- }
- //************************************
- // 函数名称: AddAt
- // 返回类型: long
- // 参数信息: CTreeNodeUI * pControl
- // 参数信息: int iIndex
- // 函数说明: 该方法不会将待插入的节点进行缩位处理,若打算插入的节点为非根节点,请使用AddAt(CTreeNodeUI* pControl,CTreeNodeUI* _IndexNode) 方法
- //************************************
- long CTreeViewUI::AddAt( CTreeNodeUI* pControl, int iIndex )
- {
- if (!pControl) return -1;
- if (NULL == static_cast<CTreeNodeUI*>(pControl->GetInterface(_T("TreeNode")))) return -1;
- pControl->OnNotify += MakeDelegate(this,&CTreeViewUI::OnDBClickItem);
- pControl->GetFolderButton()->OnNotify += MakeDelegate(this,&CTreeViewUI::OnFolderChanged);
- pControl->GetCheckBox()->OnNotify += MakeDelegate(this,&CTreeViewUI::OnCheckBoxChanged);
- pControl->SetVisibleFolderBtn(m_bVisibleFolderBtn);
- pControl->SetVisibleCheckBtn(m_bVisibleCheckBtn);
- if(m_uItemMinWidth > 0) {
- pControl->SetMinWidth(m_uItemMinWidth);
- }
- CListUI::AddAt(pControl, iIndex);
- int nLevel = pControl->GetTreeLevel();
- int nFolderWidth = pControl->GetFolderButton()->GetFixedWidth();
- if(nFolderWidth <= 0) nFolderWidth = 16;
- if(!pControl->GetFolderButton()->IsVisible()) nFolderWidth = 0;
- pControl->GetFolderButton()->SetPadding(CDuiRect(nLevel * nFolderWidth, 0, 0, 0));
- if(pControl->GetCountChild() > 0) {
- int nCount = pControl->GetCountChild();
- for(int nIndex = 0; nIndex < nCount; nIndex++) {
- CTreeNodeUI* pNode = pControl->GetChildNode(nIndex);
- if(pNode)
- return AddAt(pNode,iIndex+1);
- }
- }
- else {
- return iIndex + 1;
- }
- return -1;
- }
- //************************************
- // 函数名称: AddAt
- // 返回类型: bool
- // 参数信息: CTreeNodeUI * pControl
- // 参数信息: CTreeNodeUI * _IndexNode
- // 函数说明:
- //************************************
- bool CTreeViewUI::AddAt( CTreeNodeUI* pControl, CTreeNodeUI* _IndexNode )
- {
- if(!_IndexNode && !pControl)
- return false;
- int nItemIndex = -1;
- for(int nIndex = 0;nIndex < GetCount();nIndex++) {
- if(_IndexNode == GetItemAt(nIndex)) {
- nItemIndex = nIndex;
- break;
- }
- }
- if(nItemIndex == -1)
- return false;
- bool bRet = AddAt(pControl,nItemIndex) >= 0;
- if(bRet) {
- int nLevel = pControl->GetTreeLevel();
- int nFolderWidth = pControl->GetFolderButton()->GetFixedWidth();
- if(nFolderWidth <= 0) nFolderWidth = 16;
- if(!pControl->GetFolderButton()->IsVisible()) nFolderWidth = 0;
- pControl->GetFolderButton()->SetPadding(CDuiRect(nLevel * nFolderWidth, 0, 0, 0));
- }
- return bRet;
- }
- //************************************
- // 函数名称: Remove
- // 返回类型: bool
- // 参数信息: CTreeNodeUI * pControl
- // 函数说明: pControl 对象以及下的所有节点将被一并移除
- //************************************
- bool CTreeViewUI::Remove( CTreeNodeUI* pControl )
- {
- if(pControl->GetCountChild() > 0) {
- int nCount = pControl->GetCountChild();
- for(int nIndex = nCount - 1; nIndex >= 0; nIndex--) {
- CTreeNodeUI* pNode = pControl->GetChildNode(nIndex);
- if(pNode){
- pControl->Remove(pNode);
- }
- }
- }
- CListUI::Remove(pControl);
- return TRUE;
- }
- //************************************
- // 函数名称: RemoveAt
- // 返回类型: bool
- // 参数信息: int iIndex
- // 函数说明: iIndex 索引以及下的所有节点将被一并移除
- //************************************
- bool CTreeViewUI::RemoveAt( int iIndex )
- {
- CTreeNodeUI* pItem = (CTreeNodeUI*)GetItemAt(iIndex);
- Remove(pItem);
- return TRUE;
- }
- void CTreeViewUI::RemoveAll()
- {
- CListUI::RemoveAll();
- }
- //************************************
- // 函数名称: Notify
- // 返回类型: void
- // 参数信息: TNotifyUI & msg
- // 函数说明:
- //************************************
- void CTreeViewUI::Notify( TNotifyUI& msg )
- {
-
- }
-
- //************************************
- // 函数名称: OnCheckBoxChanged
- // 返回类型: bool
- // 参数信息: void * param
- // 函数说明:
- //************************************
- bool CTreeViewUI::OnCheckBoxChanged( void* param )
- {
- TNotifyUI* pMsg = (TNotifyUI*)param;
- if(pMsg->sType == DUI_MSGTYPE_SELECTCHANGED)
- {
- CCheckBoxUI* pCheckBox = (CCheckBoxUI*)pMsg->pSender;
- CTreeNodeUI* pItem = (CTreeNodeUI*)pCheckBox->GetParent()->GetParent();
- SetItemCheckBox(pCheckBox->GetCheck(),pItem);
- return TRUE;
- }
- return TRUE;
- }
-
- //************************************
- // 函数名称: OnFolderChanged
- // 返回类型: bool
- // 参数信息: void * param
- // 函数说明:
- //************************************
- bool CTreeViewUI::OnFolderChanged( void* param )
- {
- TNotifyUI* pMsg = (TNotifyUI*)param;
- if(pMsg->sType == DUI_MSGTYPE_SELECTCHANGED) {
- CCheckBoxUI* pFolder = (CCheckBoxUI*)pMsg->pSender;
- CTreeNodeUI* pItem = (CTreeNodeUI*)pFolder->GetParent()->GetParent();
- pItem->SetVisibleTag(!pFolder->GetCheck());
- SetItemExpand(!pFolder->GetCheck(),pItem);
- return TRUE;
- }
- return TRUE;
- }
-
- //************************************
- // 函数名称: OnDBClickItem
- // 返回类型: bool
- // 参数信息: void * param
- // 函数说明:
- //************************************
- bool CTreeViewUI::OnDBClickItem( void* param )
- {
- TNotifyUI* pMsg = (TNotifyUI*)param;
- if(_tcsicmp(pMsg->sType, DUI_MSGTYPE_TREEITEMDBCLICK) == 0) {
- CTreeNodeUI* pItem = static_cast<CTreeNodeUI*>(pMsg->pSender);
- CCheckBoxUI* pFolder = pItem->GetFolderButton();
- pFolder->Selected(!pFolder->IsSelected());
- pItem->SetVisibleTag(!pFolder->GetCheck());
- SetItemExpand(!pFolder->GetCheck(),pItem);
- return TRUE;
- }
- return FALSE;
- }
- //************************************
- // 函数名称: SetItemCheckBox
- // 返回类型: bool
- // 参数信息: bool _Selected
- // 参数信息: CTreeNodeUI * _TreeNode
- // 函数说明:
- //************************************
- bool CTreeViewUI::SetItemCheckBox( bool _Selected,CTreeNodeUI* _TreeNode /*= NULL*/ )
- {
- if(_TreeNode) {
- if(_TreeNode->GetCountChild() > 0) {
- int nCount = _TreeNode->GetCountChild();
- for(int nIndex = 0;nIndex < nCount;nIndex++) {
- CTreeNodeUI* pItem = _TreeNode->GetChildNode(nIndex);
- pItem->GetCheckBox()->Selected(_Selected);
- if(pItem->GetCountChild())
- SetItemCheckBox(_Selected,pItem);
- }
- }
- return TRUE;
- }
- else {
- int nIndex = 0;
- int nCount = GetCount();
- while(nIndex < nCount) {
- CTreeNodeUI* pItem = (CTreeNodeUI*)GetItemAt(nIndex);
- pItem->GetCheckBox()->Selected(_Selected);
- if(pItem->GetCountChild())
- SetItemCheckBox(_Selected,pItem);
- nIndex++;
- }
- return TRUE;
- }
- return FALSE;
- }
- //************************************
- // 函数名称: SetItemExpand
- // 返回类型: void
- // 参数信息: bool _Expanded
- // 参数信息: CTreeNodeUI * _TreeNode
- // 函数说明:
- //************************************
- void CTreeViewUI::SetItemExpand( bool _Expanded,CTreeNodeUI* _TreeNode /*= NULL*/ )
- {
- if(_TreeNode) {
- if(_TreeNode->GetCountChild() > 0) {
- int nCount = _TreeNode->GetCountChild();
- for(int nIndex = 0;nIndex < nCount;nIndex++) {
- CTreeNodeUI* pItem = _TreeNode->GetChildNode(nIndex);
- pItem->SetVisible(_Expanded);
- if(pItem->GetCountChild() && !pItem->GetFolderButton()->IsSelected()) {
- SetItemExpand(_Expanded,pItem);
- }
- }
- }
- }
- else {
- int nIndex = 0;
- int nCount = GetCount();
- while(nIndex < nCount) {
- CTreeNodeUI* pItem = (CTreeNodeUI*)GetItemAt(nIndex);
- pItem->GetFolderButton()->Selected(!_Expanded);
- if(pItem->GetCountChild() && !pItem->GetFolderButton()->IsSelected()) {
- SetItemExpand(_Expanded, pItem);
- }
- nIndex++;
- }
- }
- }
- //************************************
- // 函数名称: SetVisibleFolderBtn
- // 返回类型: void
- // 参数信息: bool _IsVisibled
- // 函数说明:
- //************************************
- void CTreeViewUI::SetVisibleFolderBtn( bool _IsVisibled )
- {
- m_bVisibleFolderBtn = _IsVisibled;
- int nCount = this->GetCount();
- for(int nIndex = 0; nIndex < nCount; nIndex++) {
- CTreeNodeUI* pItem = static_cast<CTreeNodeUI*>(this->GetItemAt(nIndex));
- pItem->GetFolderButton()->SetVisible(m_bVisibleFolderBtn);
- }
- }
- //************************************
- // 函数名称: GetVisibleFolderBtn
- // 返回类型: bool
- // 函数说明:
- //************************************
- bool CTreeViewUI::GetVisibleFolderBtn()
- {
- return m_bVisibleFolderBtn;
- }
- //************************************
- // 函数名称: SetVisibleCheckBtn
- // 返回类型: void
- // 参数信息: bool _IsVisibled
- // 函数说明:
- //************************************
- void CTreeViewUI::SetVisibleCheckBtn( bool _IsVisibled )
- {
- m_bVisibleCheckBtn = _IsVisibled;
- int nCount = this->GetCount();
- for(int nIndex = 0; nIndex < nCount; nIndex++) {
- CTreeNodeUI* pItem = static_cast<CTreeNodeUI*>(this->GetItemAt(nIndex));
- pItem->GetCheckBox()->SetVisible(m_bVisibleCheckBtn);
- }
- }
- //************************************
- // 函数名称: GetVisibleCheckBtn
- // 返回类型: bool
- // 函数说明:
- //************************************
- bool CTreeViewUI::GetVisibleCheckBtn()
- {
- return m_bVisibleCheckBtn;
- }
- //************************************
- // 函数名称: SetItemMinWidth
- // 返回类型: void
- // 参数信息: UINT _ItemMinWidth
- // 函数说明:
- //************************************
- void CTreeViewUI::SetItemMinWidth( UINT _ItemMinWidth )
- {
- m_uItemMinWidth = _ItemMinWidth;
- for(int nIndex = 0;nIndex < GetCount();nIndex++){
- CTreeNodeUI* pTreeNode = static_cast<CTreeNodeUI*>(GetItemAt(nIndex));
- if(pTreeNode) {
- pTreeNode->SetMinWidth(GetItemMinWidth());
- }
- }
- Invalidate();
- }
- //************************************
- // 函数名称: GetItemMinWidth
- // 返回类型: UINT
- // 函数说明:
- //************************************
- UINT CTreeViewUI::GetItemMinWidth()
- {
- return m_uItemMinWidth;
- }
-
- //************************************
- // 函数名称: SetItemTextColor
- // 返回类型: void
- // 参数信息: DWORD _dwItemTextColor
- // 函数说明:
- //************************************
- void CTreeViewUI::SetItemTextColor( DWORD _dwItemTextColor )
- {
- for(int nIndex = 0;nIndex < GetCount();nIndex++){
- CTreeNodeUI* pTreeNode = static_cast<CTreeNodeUI*>(GetItemAt(nIndex));
- if(pTreeNode) {
- pTreeNode->SetItemTextColor(_dwItemTextColor);
- }
- }
- }
- //************************************
- // 函数名称: SetItemHotTextColor
- // 返回类型: void
- // 参数信息: DWORD _dwItemHotTextColor
- // 函数说明:
- //************************************
- void CTreeViewUI::SetItemHotTextColor( DWORD _dwItemHotTextColor )
- {
- for(int nIndex = 0;nIndex < GetCount();nIndex++){
- CTreeNodeUI* pTreeNode = static_cast<CTreeNodeUI*>(GetItemAt(nIndex));
- if(pTreeNode) {
- pTreeNode->SetItemHotTextColor(_dwItemHotTextColor);
- }
- }
- }
- //************************************
- // 函数名称: SetSelItemTextColor
- // 返回类型: void
- // 参数信息: DWORD _dwSelItemTextColor
- // 函数说明:
- //************************************
- void CTreeViewUI::SetSelItemTextColor( DWORD _dwSelItemTextColor )
- {
- for(int nIndex = 0;nIndex < GetCount();nIndex++){
- CTreeNodeUI* pTreeNode = static_cast<CTreeNodeUI*>(GetItemAt(nIndex));
- if(pTreeNode) {
- pTreeNode->SetSelItemTextColor(_dwSelItemTextColor);
- }
- }
- }
-
- //************************************
- // 函数名称: SetSelItemHotTextColor
- // 返回类型: void
- // 参数信息: DWORD _dwSelHotItemTextColor
- // 函数说明:
- //************************************
- void CTreeViewUI::SetSelItemHotTextColor( DWORD _dwSelHotItemTextColor )
- {
- for(int nIndex = 0;nIndex < GetCount();nIndex++){
- CTreeNodeUI* pTreeNode = static_cast<CTreeNodeUI*>(GetItemAt(nIndex));
- if(pTreeNode) {
- pTreeNode->SetSelItemHotTextColor(_dwSelHotItemTextColor);
- }
- }
- }
- //************************************
- // 函数名称: SetAttribute
- // 返回类型: void
- // 参数信息: LPCTSTR pstrName
- // 参数信息: LPCTSTR pstrValue
- // 函数说明:
- //************************************
- void CTreeViewUI::SetAttribute( LPCTSTR pstrName, LPCTSTR pstrValue )
- {
- if(_tcsicmp(pstrName,_T("visiblefolderbtn")) == 0)
- SetVisibleFolderBtn(_tcsicmp(pstrValue,_T("TRUE")) == 0);
- else if(_tcsicmp(pstrName,_T("visiblecheckbtn")) == 0)
- SetVisibleCheckBtn(_tcsicmp(pstrValue,_T("TRUE")) == 0);
- else if(_tcsicmp(pstrName,_T("itemminwidth")) == 0)
- SetItemMinWidth(_ttoi(pstrValue));
- else if(_tcsicmp(pstrName, _T("itemtextcolor")) == 0 ){
- if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
- LPTSTR pstr = NULL;
- DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
- SetItemTextColor(clrColor);
- }
- else if(_tcsicmp(pstrName, _T("itemhottextcolor")) == 0 ){
- if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
- LPTSTR pstr = NULL;
- DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
- SetItemHotTextColor(clrColor);
- }
- else if(_tcsicmp(pstrName, _T("selitemtextcolor")) == 0 ){
- if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
- LPTSTR pstr = NULL;
- DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
- SetSelItemTextColor(clrColor);
- }
- else if(_tcsicmp(pstrName, _T("selitemhottextcolor")) == 0 ){
- if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
- LPTSTR pstr = NULL;
- DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
- SetSelItemHotTextColor(clrColor);
- }
- else CListUI::SetAttribute(pstrName,pstrValue);
- }
- }
|