UITreeView.cpp 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  1. #include "StdAfx.h"
  2. #include "UITreeView.h"
  3. #pragma warning( disable: 4251 )
  4. namespace DuiLib
  5. {
  6. IMPLEMENT_DUICONTROL(CTreeNodeUI)
  7. //************************************
  8. // 函数名称: CTreeNodeUI
  9. // 返回类型:
  10. // 参数信息: CTreeNodeUI * _ParentNode
  11. // 函数说明:
  12. //************************************
  13. CTreeNodeUI::CTreeNodeUI( CTreeNodeUI* _ParentNode /*= NULL*/ )
  14. {
  15. m_dwItemTextColor = 0x00000000;
  16. m_dwItemHotTextColor = 0;
  17. m_dwSelItemTextColor = 0;
  18. m_dwSelItemHotTextColor = 0;
  19. pTreeView = NULL;
  20. m_iTreeLavel = 0;
  21. m_bIsVisable = TRUE;
  22. m_bIsCheckBox = FALSE;
  23. pParentTreeNode = NULL;
  24. pHoriz = new CHorizontalLayoutUI();
  25. pFolderButton = new CCheckBoxUI();
  26. pDottedLine = new CLabelUI();
  27. pCheckBox = new CCheckBoxUI();
  28. pItemButton = new COptionUI();
  29. this->SetFixedHeight(18);
  30. this->SetFixedWidth(250);
  31. pFolderButton->SetFixedWidth(GetFixedHeight());
  32. pDottedLine->SetFixedWidth(2);
  33. pCheckBox->SetFixedWidth(GetFixedHeight());
  34. pItemButton->SetAttribute(_T("align"),_T("left"));
  35. pDottedLine->SetVisible(FALSE);
  36. pCheckBox->SetVisible(FALSE);
  37. pItemButton->SetMouseEnabled(FALSE);
  38. if(_ParentNode) {
  39. if (_tcsicmp(_ParentNode->GetClass(), _T("TreeNodeUI")) != 0) return;
  40. pDottedLine->SetVisible(_ParentNode->IsVisible());
  41. pDottedLine->SetFixedWidth(_ParentNode->GetDottedLine()->GetFixedWidth()+16);
  42. this->SetParentNode(_ParentNode);
  43. }
  44. pHoriz->SetChildVAlign(DT_VCENTER);
  45. pHoriz->Add(pDottedLine);
  46. pHoriz->Add(pFolderButton);
  47. pHoriz->Add(pCheckBox);
  48. pHoriz->Add(pItemButton);
  49. Add(pHoriz);
  50. }
  51. //************************************
  52. // 函数名称: ~CTreeNodeUI
  53. // 返回类型:
  54. // 参数信息: void
  55. // 函数说明:
  56. //************************************
  57. CTreeNodeUI::~CTreeNodeUI( void )
  58. {
  59. }
  60. //************************************
  61. // 函数名称: GetClass
  62. // 返回类型: LPCTSTR
  63. // 函数说明:
  64. //************************************
  65. LPCTSTR CTreeNodeUI::GetClass() const
  66. {
  67. return _T("TreeNodeUI");
  68. }
  69. //************************************
  70. // 函数名称: GetInterface
  71. // 返回类型: LPVOID
  72. // 参数信息: LPCTSTR pstrName
  73. // 函数说明:
  74. //************************************
  75. LPVOID CTreeNodeUI::GetInterface( LPCTSTR pstrName )
  76. {
  77. if( _tcsicmp(pstrName, _T("TreeNode")) == 0 )
  78. return static_cast<CTreeNodeUI*>(this);
  79. return CListContainerElementUI::GetInterface(pstrName);
  80. }
  81. //************************************
  82. // 函数名称: DoEvent
  83. // 返回类型: void
  84. // 参数信息: TEventUI & event
  85. // 函数说明:
  86. //************************************
  87. void CTreeNodeUI::DoEvent( TEventUI& event )
  88. {
  89. if( !IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND ) {
  90. if( m_pOwner != NULL ) m_pOwner->DoEvent(event);
  91. else CContainerUI::DoEvent(event);
  92. return;
  93. }
  94. CListContainerElementUI::DoEvent(event);
  95. if( event.Type == UIEVENT_DBLCLICK ) {
  96. if( IsEnabled() ) {
  97. m_pManager->SendNotify(this, DUI_MSGTYPE_TREEITEMDBCLICK);
  98. Invalidate();
  99. }
  100. return;
  101. }
  102. if( event.Type == UIEVENT_MOUSEENTER ) {
  103. if( IsEnabled()) {
  104. if(m_bSelected && GetSelItemHotTextColor())
  105. pItemButton->SetTextColor(GetSelItemHotTextColor());
  106. else
  107. pItemButton->SetTextColor(GetItemHotTextColor());
  108. }
  109. else
  110. pItemButton->SetTextColor(pItemButton->GetDisabledTextColor());
  111. return;
  112. }
  113. if( event.Type == UIEVENT_MOUSELEAVE ) {
  114. if( IsEnabled()) {
  115. if(m_bSelected && GetSelItemTextColor())
  116. pItemButton->SetTextColor(GetSelItemTextColor());
  117. else if(!m_bSelected)
  118. pItemButton->SetTextColor(GetItemTextColor());
  119. }
  120. else
  121. pItemButton->SetTextColor(pItemButton->GetDisabledTextColor());
  122. return;
  123. }
  124. }
  125. //************************************
  126. // 函数名称: Invalidate
  127. // 返回类型: void
  128. // 函数说明:
  129. //************************************
  130. void CTreeNodeUI::Invalidate()
  131. {
  132. if( !IsVisible() )
  133. return;
  134. if( GetParent() ) {
  135. CContainerUI* pParentContainer = static_cast<CContainerUI*>(GetParent()->GetInterface(_T("Container")));
  136. if( pParentContainer ) {
  137. RECT rc = pParentContainer->GetPos();
  138. RECT rcInset = pParentContainer->GetInset();
  139. rc.left += rcInset.left;
  140. rc.top += rcInset.top;
  141. rc.right -= rcInset.right;
  142. rc.bottom -= rcInset.bottom;
  143. CScrollBarUI* pVerticalScrollBar = pParentContainer->GetVerticalScrollBar();
  144. if( pVerticalScrollBar && pVerticalScrollBar->IsVisible() ) rc.right -= pVerticalScrollBar->GetFixedWidth();
  145. CScrollBarUI* pHorizontalScrollBar = pParentContainer->GetHorizontalScrollBar();
  146. if( pHorizontalScrollBar && pHorizontalScrollBar->IsVisible() ) rc.bottom -= pHorizontalScrollBar->GetFixedHeight();
  147. RECT invalidateRc = m_rcItem;
  148. if( !::IntersectRect(&invalidateRc, &m_rcItem, &rc) )
  149. return;
  150. CControlUI* pParent = GetParent();
  151. RECT rcTemp;
  152. RECT rcParent;
  153. while( pParent = pParent->GetParent() ) {
  154. rcTemp = invalidateRc;
  155. rcParent = pParent->GetPos();
  156. if( !::IntersectRect(&invalidateRc, &rcTemp, &rcParent) )
  157. return;
  158. }
  159. if( m_pManager != NULL ) m_pManager->Invalidate(invalidateRc);
  160. }
  161. else {
  162. CContainerUI::Invalidate();
  163. }
  164. }
  165. else {
  166. CContainerUI::Invalidate();
  167. }
  168. }
  169. //************************************
  170. // 函数名称: Select
  171. // 返回类型: bool
  172. // 参数信息: bool bSelect
  173. // 函数说明:
  174. //************************************
  175. bool CTreeNodeUI::Select( bool bSelect /*= true*/ )
  176. {
  177. bool nRet = CListContainerElementUI::Select(bSelect);
  178. if(m_bSelected)
  179. pItemButton->SetTextColor(GetSelItemTextColor());
  180. else
  181. pItemButton->SetTextColor(GetItemTextColor());
  182. return nRet;
  183. }
  184. bool CTreeNodeUI::SelectMulti(bool bSelect)
  185. {
  186. bool nRet = CListContainerElementUI::SelectMulti(bSelect);
  187. if(m_bSelected)
  188. pItemButton->SetTextColor(GetSelItemTextColor());
  189. else
  190. pItemButton->SetTextColor(GetItemTextColor());
  191. return nRet;
  192. }
  193. //************************************
  194. // 函数名称: Add
  195. // 返回类型: bool
  196. // 参数信息: CControlUI * _pTreeNodeUI
  197. // 函数说明: 通过节点对象添加节点
  198. //************************************
  199. bool CTreeNodeUI::Add( CControlUI* _pTreeNodeUI )
  200. {
  201. if (NULL != static_cast<CTreeNodeUI*>(_pTreeNodeUI->GetInterface(_T("TreeNode"))))
  202. return AddChildNode((CTreeNodeUI*)_pTreeNodeUI);
  203. return CListContainerElementUI::Add(_pTreeNodeUI);
  204. }
  205. //************************************
  206. // 函数名称: AddAt
  207. // 返回类型: bool
  208. // 参数信息: CControlUI * pControl
  209. // 参数信息: int iIndex 该参数仅针对当前节点下的兄弟索引,并非列表视图索引
  210. // 函数说明:
  211. //************************************
  212. bool CTreeNodeUI::AddAt( CControlUI* pControl, int iIndex )
  213. {
  214. if(NULL == static_cast<CTreeNodeUI*>(pControl->GetInterface(_T("TreeNode"))))
  215. return FALSE;
  216. CTreeNodeUI* pIndexNode = static_cast<CTreeNodeUI*>(mTreeNodes.GetAt(iIndex));
  217. if(!pIndexNode){
  218. if(!mTreeNodes.Add(pControl))
  219. return FALSE;
  220. }
  221. else if(pIndexNode && !mTreeNodes.InsertAt(iIndex,pControl))
  222. return FALSE;
  223. if(!pIndexNode && pTreeView && pTreeView->GetItemAt(GetTreeIndex()+1))
  224. pIndexNode = static_cast<CTreeNodeUI*>(pTreeView->GetItemAt(GetTreeIndex()+1)->GetInterface(_T("TreeNode")));
  225. pControl = CalLocation((CTreeNodeUI*)pControl);
  226. if(pTreeView && pIndexNode)
  227. return pTreeView->AddAt((CTreeNodeUI*)pControl,pIndexNode);
  228. else
  229. return pTreeView->Add((CTreeNodeUI*)pControl);
  230. return TRUE;
  231. }
  232. //************************************
  233. // 函数名称: Remove
  234. // 返回类型: bool
  235. // 参数信息: CControlUI * pControl
  236. // 函数说明:
  237. //************************************
  238. bool CTreeNodeUI::Remove( CControlUI* pControl )
  239. {
  240. return RemoveAt((CTreeNodeUI*)pControl);
  241. }
  242. //************************************
  243. // 函数名称: SetVisibleTag
  244. // 返回类型: void
  245. // 参数信息: bool _IsVisible
  246. // 函数说明:
  247. //************************************
  248. void CTreeNodeUI::SetVisibleTag( bool _IsVisible )
  249. {
  250. m_bIsVisable = _IsVisible;
  251. }
  252. //************************************
  253. // 函数名称: GetVisibleTag
  254. // 返回类型: bool
  255. // 函数说明:
  256. //************************************
  257. bool CTreeNodeUI::GetVisibleTag()
  258. {
  259. return m_bIsVisable;
  260. }
  261. //************************************
  262. // 函数名称: SetItemText
  263. // 返回类型: void
  264. // 参数信息: LPCTSTR pstrValue
  265. // 函数说明:
  266. //************************************
  267. void CTreeNodeUI::SetItemText( LPCTSTR pstrValue )
  268. {
  269. pItemButton->SetText(pstrValue);
  270. }
  271. //************************************
  272. // 函数名称: GetItemText
  273. // 返回类型: DuiLib::CDuiString
  274. // 函数说明:
  275. //************************************
  276. CDuiString CTreeNodeUI::GetItemText()
  277. {
  278. return pItemButton->GetText();
  279. }
  280. //************************************
  281. // 函数名称: CheckBoxSelected
  282. // 返回类型: void
  283. // 参数信息: bool _Selected
  284. // 函数说明:
  285. //************************************
  286. void CTreeNodeUI::CheckBoxSelected( bool _Selected )
  287. {
  288. pCheckBox->Selected(_Selected);
  289. }
  290. //************************************
  291. // 函数名称: IsCheckBoxSelected
  292. // 返回类型: bool
  293. // 函数说明:
  294. //************************************
  295. bool CTreeNodeUI::IsCheckBoxSelected() const
  296. {
  297. return pCheckBox->IsSelected();
  298. }
  299. //************************************
  300. // 函数名称: IsHasChild
  301. // 返回类型: bool
  302. // 函数说明:
  303. //************************************
  304. bool CTreeNodeUI::IsHasChild() const
  305. {
  306. return !mTreeNodes.IsEmpty();
  307. }
  308. long CTreeNodeUI::GetTreeLevel()
  309. {
  310. long level = 0;
  311. CTreeNodeUI* pParentNode = GetParentNode();
  312. while(pParentNode != NULL) {
  313. level++;
  314. pParentNode = pParentNode->GetParentNode();
  315. }
  316. return level;
  317. }
  318. //************************************
  319. // 函数名称: AddChildNode
  320. // 返回类型: bool
  321. // 参数信息: CTreeNodeUI * _pTreeNodeUI
  322. // 函数说明:
  323. //************************************
  324. bool CTreeNodeUI::AddChildNode( CTreeNodeUI* _pTreeNodeUI )
  325. {
  326. if (!_pTreeNodeUI)
  327. return FALSE;
  328. if (NULL == static_cast<CTreeNodeUI*>(_pTreeNodeUI->GetInterface(_T("TreeNode"))))
  329. return FALSE;
  330. _pTreeNodeUI = CalLocation(_pTreeNodeUI);
  331. bool nRet = TRUE;
  332. if(pTreeView){
  333. CTreeNodeUI* pNode = static_cast<CTreeNodeUI*>(mTreeNodes.GetAt(mTreeNodes.GetSize()-1));
  334. if(!pNode || !pNode->GetLastNode())
  335. nRet = pTreeView->AddAt(_pTreeNodeUI,GetTreeIndex()+1) >= 0;
  336. else nRet = pTreeView->AddAt(_pTreeNodeUI,pNode->GetLastNode()->GetTreeIndex()+1) >= 0;
  337. }
  338. if(nRet)
  339. mTreeNodes.Add(_pTreeNodeUI);
  340. return nRet;
  341. }
  342. //************************************
  343. // 函数名称: RemoveAt
  344. // 返回类型: bool
  345. // 参数信息: CTreeNodeUI * _pTreeNodeUI
  346. // 函数说明:
  347. //************************************
  348. bool CTreeNodeUI::RemoveAt( CTreeNodeUI* _pTreeNodeUI )
  349. {
  350. int nIndex = mTreeNodes.Find(_pTreeNodeUI);
  351. CTreeNodeUI* pNode = static_cast<CTreeNodeUI*>(mTreeNodes.GetAt(nIndex));
  352. if(pNode && pNode == _pTreeNodeUI)
  353. {
  354. while(pNode->IsHasChild())
  355. pNode->RemoveAt(static_cast<CTreeNodeUI*>(pNode->mTreeNodes.GetAt(0)));
  356. mTreeNodes.Remove(nIndex);
  357. if(pTreeView)
  358. pTreeView->Remove(_pTreeNodeUI);
  359. return TRUE;
  360. }
  361. return FALSE;
  362. }
  363. //************************************
  364. // 函数名称: SetParentNode
  365. // 返回类型: void
  366. // 参数信息: CTreeNodeUI * _pParentTreeNode
  367. // 函数说明:
  368. //************************************
  369. void CTreeNodeUI::SetParentNode( CTreeNodeUI* _pParentTreeNode )
  370. {
  371. pParentTreeNode = _pParentTreeNode;
  372. }
  373. //************************************
  374. // 函数名称: GetParentNode
  375. // 返回类型: CTreeNodeUI*
  376. // 函数说明:
  377. //************************************
  378. CTreeNodeUI* CTreeNodeUI::GetParentNode()
  379. {
  380. return pParentTreeNode;
  381. }
  382. //************************************
  383. // 函数名称: GetCountChild
  384. // 返回类型: long
  385. // 函数说明:
  386. //************************************
  387. long CTreeNodeUI::GetCountChild()
  388. {
  389. return mTreeNodes.GetSize();
  390. }
  391. //************************************
  392. // 函数名称: SetTreeView
  393. // 返回类型: void
  394. // 参数信息: CTreeViewUI * _CTreeViewUI
  395. // 函数说明:
  396. //************************************
  397. void CTreeNodeUI::SetTreeView( CTreeViewUI* _CTreeViewUI )
  398. {
  399. pTreeView = _CTreeViewUI;
  400. }
  401. //************************************
  402. // 函数名称: GetTreeView
  403. // 返回类型: CTreeViewUI*
  404. // 函数说明:
  405. //************************************
  406. CTreeViewUI* CTreeNodeUI::GetTreeView()
  407. {
  408. return pTreeView;
  409. }
  410. //************************************
  411. // 函数名称: SetAttribute
  412. // 返回类型: void
  413. // 参数信息: LPCTSTR pstrName
  414. // 参数信息: LPCTSTR pstrValue
  415. // 函数说明:
  416. //************************************
  417. void CTreeNodeUI::SetAttribute( LPCTSTR pstrName, LPCTSTR pstrValue )
  418. {
  419. if(_tcsicmp(pstrName, _T("text")) == 0 )
  420. pItemButton->SetText(pstrValue);
  421. else if(_tcsicmp(pstrName, _T("horizattr")) == 0 )
  422. pHoriz->ApplyAttributeList(pstrValue);
  423. else if(_tcsicmp(pstrName, _T("dotlineattr")) == 0 )
  424. pDottedLine->ApplyAttributeList(pstrValue);
  425. else if(_tcsicmp(pstrName, _T("folderattr")) == 0 )
  426. pFolderButton->ApplyAttributeList(pstrValue);
  427. else if(_tcsicmp(pstrName, _T("checkboxattr")) == 0 )
  428. pCheckBox->ApplyAttributeList(pstrValue);
  429. else if(_tcsicmp(pstrName, _T("itemattr")) == 0 )
  430. pItemButton->ApplyAttributeList(pstrValue);
  431. else if(_tcsicmp(pstrName, _T("itemtextcolor")) == 0 ){
  432. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  433. LPTSTR pstr = NULL;
  434. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  435. SetItemTextColor(clrColor);
  436. }
  437. else if(_tcsicmp(pstrName, _T("itemhottextcolor")) == 0 ){
  438. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  439. LPTSTR pstr = NULL;
  440. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  441. SetItemHotTextColor(clrColor);
  442. }
  443. else if(_tcsicmp(pstrName, _T("selitemtextcolor")) == 0 ){
  444. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  445. LPTSTR pstr = NULL;
  446. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  447. SetSelItemTextColor(clrColor);
  448. }
  449. else if(_tcsicmp(pstrName, _T("selitemhottextcolor")) == 0 ){
  450. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  451. LPTSTR pstr = NULL;
  452. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  453. SetSelItemHotTextColor(clrColor);
  454. }
  455. else CListContainerElementUI::SetAttribute(pstrName,pstrValue);
  456. }
  457. //************************************
  458. // 函数名称: GetTreeNodes
  459. // 返回类型: DuiLib::CStdPtrArray
  460. // 函数说明:
  461. //************************************
  462. CStdPtrArray CTreeNodeUI::GetTreeNodes()
  463. {
  464. return mTreeNodes;
  465. }
  466. //************************************
  467. // 函数名称: GetChildNode
  468. // 返回类型: CTreeNodeUI*
  469. // 参数信息: int _nIndex
  470. // 函数说明:
  471. //************************************
  472. CTreeNodeUI* CTreeNodeUI::GetChildNode( int _nIndex )
  473. {
  474. return static_cast<CTreeNodeUI*>(mTreeNodes.GetAt(_nIndex));
  475. }
  476. //************************************
  477. // 函数名称: SetVisibleFolderBtn
  478. // 返回类型: void
  479. // 参数信息: bool _IsVisibled
  480. // 函数说明:
  481. //************************************
  482. void CTreeNodeUI::SetVisibleFolderBtn( bool _IsVisibled )
  483. {
  484. pFolderButton->SetVisible(_IsVisibled);
  485. }
  486. //************************************
  487. // 函数名称: GetVisibleFolderBtn
  488. // 返回类型: bool
  489. // 函数说明:
  490. //************************************
  491. bool CTreeNodeUI::GetVisibleFolderBtn()
  492. {
  493. return pFolderButton->IsVisible();
  494. }
  495. //************************************
  496. // 函数名称: SetVisibleCheckBtn
  497. // 返回类型: void
  498. // 参数信息: bool _IsVisibled
  499. // 函数说明:
  500. //************************************
  501. void CTreeNodeUI::SetVisibleCheckBtn( bool _IsVisibled )
  502. {
  503. pCheckBox->SetVisible(_IsVisibled);
  504. }
  505. //************************************
  506. // 函数名称: GetVisibleCheckBtn
  507. // 返回类型: bool
  508. // 函数说明:
  509. //************************************
  510. bool CTreeNodeUI::GetVisibleCheckBtn()
  511. {
  512. return pCheckBox->IsVisible();
  513. }
  514. //************************************
  515. // 函数名称: GetNodeIndex
  516. // 返回类型: int
  517. // 函数说明: 取得全局树视图的索引
  518. //************************************
  519. int CTreeNodeUI::GetTreeIndex()
  520. {
  521. if(!pTreeView)
  522. return -1;
  523. for(int nIndex = 0;nIndex < pTreeView->GetCount();nIndex++){
  524. if(this == pTreeView->GetItemAt(nIndex))
  525. return nIndex;
  526. }
  527. return -1;
  528. }
  529. //************************************
  530. // 函数名称: GetNodeIndex
  531. // 返回类型: int
  532. // 函数说明: 取得相对于兄弟节点的当前索引
  533. //************************************
  534. int CTreeNodeUI::GetNodeIndex()
  535. {
  536. if(!GetParentNode() && !pTreeView)
  537. return -1;
  538. if(!GetParentNode() && pTreeView)
  539. return GetTreeIndex();
  540. return GetParentNode()->GetTreeNodes().Find(this);
  541. }
  542. //************************************
  543. // 函数名称: GetLastNode
  544. // 返回类型: CTreeNodeUI*
  545. // 函数说明:
  546. //************************************
  547. CTreeNodeUI* CTreeNodeUI::GetLastNode( )
  548. {
  549. if(!IsHasChild()) return this;
  550. CTreeNodeUI* nRetNode = NULL;
  551. for(int nIndex = 0;nIndex < GetTreeNodes().GetSize();nIndex++){
  552. CTreeNodeUI* pNode = static_cast<CTreeNodeUI*>(GetTreeNodes().GetAt(nIndex));
  553. if(!pNode) continue;
  554. if(pNode->IsHasChild())
  555. nRetNode = pNode->GetLastNode();
  556. else
  557. nRetNode = pNode;
  558. }
  559. return nRetNode;
  560. }
  561. //************************************
  562. // 函数名称: CalLocation
  563. // 返回类型: CTreeNodeUI*
  564. // 参数信息: CTreeNodeUI * _pTreeNodeUI
  565. // 函数说明: 缩进计算
  566. //************************************
  567. CTreeNodeUI* CTreeNodeUI::CalLocation( CTreeNodeUI* _pTreeNodeUI )
  568. {
  569. _pTreeNodeUI->GetDottedLine()->SetVisible(TRUE);
  570. _pTreeNodeUI->GetDottedLine()->SetFixedWidth(pDottedLine->GetFixedWidth()+16);
  571. _pTreeNodeUI->SetParentNode(this);
  572. _pTreeNodeUI->GetItemButton()->SetGroup(pItemButton->GetGroup());
  573. _pTreeNodeUI->SetTreeView(pTreeView);
  574. return _pTreeNodeUI;
  575. }
  576. //************************************
  577. // 函数名称: SetTextColor
  578. // 返回类型: void
  579. // 参数信息: DWORD _dwTextColor
  580. // 函数说明:
  581. //************************************
  582. void CTreeNodeUI::SetItemTextColor( DWORD _dwItemTextColor )
  583. {
  584. m_dwItemTextColor = _dwItemTextColor;
  585. pItemButton->SetTextColor(m_dwItemTextColor);
  586. }
  587. //************************************
  588. // 函数名称: GetTextColor
  589. // 返回类型: DWORD
  590. // 函数说明:
  591. //************************************
  592. DWORD CTreeNodeUI::GetItemTextColor() const
  593. {
  594. return m_dwItemTextColor;
  595. }
  596. //************************************
  597. // 函数名称: SetTextHotColor
  598. // 返回类型: void
  599. // 参数信息: DWORD _dwTextHotColor
  600. // 函数说明:
  601. //************************************
  602. void CTreeNodeUI::SetItemHotTextColor( DWORD _dwItemHotTextColor )
  603. {
  604. m_dwItemHotTextColor = _dwItemHotTextColor;
  605. Invalidate();
  606. }
  607. //************************************
  608. // 函数名称: GetTextHotColor
  609. // 返回类型: DWORD
  610. // 函数说明:
  611. //************************************
  612. DWORD CTreeNodeUI::GetItemHotTextColor() const
  613. {
  614. return m_dwItemHotTextColor;
  615. }
  616. //************************************
  617. // 函数名称: SetSelItemTextColor
  618. // 返回类型: void
  619. // 参数信息: DWORD _dwSelItemTextColor
  620. // 函数说明:
  621. //************************************
  622. void CTreeNodeUI::SetSelItemTextColor( DWORD _dwSelItemTextColor )
  623. {
  624. m_dwSelItemTextColor = _dwSelItemTextColor;
  625. Invalidate();
  626. }
  627. //************************************
  628. // 函数名称: GetSelItemTextColor
  629. // 返回类型: DWORD
  630. // 函数说明:
  631. //************************************
  632. DWORD CTreeNodeUI::GetSelItemTextColor() const
  633. {
  634. return m_dwSelItemTextColor;
  635. }
  636. //************************************
  637. // 函数名称: SetSelHotItemTextColor
  638. // 返回类型: void
  639. // 参数信息: DWORD _dwSelHotItemTextColor
  640. // 函数说明:
  641. //************************************
  642. void CTreeNodeUI::SetSelItemHotTextColor( DWORD _dwSelHotItemTextColor )
  643. {
  644. m_dwSelItemHotTextColor = _dwSelHotItemTextColor;
  645. Invalidate();
  646. }
  647. //************************************
  648. // 函数名称: GetSelHotItemTextColor
  649. // 返回类型: DWORD
  650. // 函数说明:
  651. //************************************
  652. DWORD CTreeNodeUI::GetSelItemHotTextColor() const
  653. {
  654. return m_dwSelItemHotTextColor;
  655. }
  656. /*****************************************************************************/
  657. /*****************************************************************************/
  658. /*****************************************************************************/
  659. IMPLEMENT_DUICONTROL(CTreeViewUI)
  660. //************************************
  661. // 函数名称: CTreeViewUI
  662. // 返回类型:
  663. // 参数信息: void
  664. // 函数说明:
  665. //************************************
  666. CTreeViewUI::CTreeViewUI( void ) : m_bVisibleFolderBtn(TRUE),m_bVisibleCheckBtn(FALSE),m_uItemMinWidth(0)
  667. {
  668. this->GetHeader()->SetVisible(FALSE);
  669. }
  670. //************************************
  671. // 函数名称: ~CTreeViewUI
  672. // 返回类型:
  673. // 参数信息: void
  674. // 函数说明:
  675. //************************************
  676. CTreeViewUI::~CTreeViewUI( void )
  677. {
  678. }
  679. //************************************
  680. // 函数名称: GetClass
  681. // 返回类型: LPCTSTR
  682. // 函数说明:
  683. //************************************
  684. LPCTSTR CTreeViewUI::GetClass() const
  685. {
  686. return _T("TreeViewUI");
  687. }
  688. UINT CTreeViewUI::GetListType()
  689. {
  690. return LT_TREE;
  691. }
  692. //************************************
  693. // 函数名称: GetInterface
  694. // 返回类型: LPVOID
  695. // 参数信息: LPCTSTR pstrName
  696. // 函数说明:
  697. //************************************
  698. LPVOID CTreeViewUI::GetInterface( LPCTSTR pstrName )
  699. {
  700. if( _tcsicmp(pstrName, _T("TreeView")) == 0 ) return static_cast<CTreeViewUI*>(this);
  701. return CListUI::GetInterface(pstrName);
  702. }
  703. //************************************
  704. // 函数名称: Add
  705. // 返回类型: bool
  706. // 参数信息: CTreeNodeUI * pControl
  707. // 函数说明:
  708. //************************************
  709. bool CTreeViewUI::Add( CTreeNodeUI* pControl )
  710. {
  711. if (!pControl) return false;
  712. if (NULL == static_cast<CTreeNodeUI*>(pControl->GetInterface(_T("TreeNode")))) return false;
  713. pControl->OnNotify += MakeDelegate(this,&CTreeViewUI::OnDBClickItem);
  714. pControl->GetFolderButton()->OnNotify += MakeDelegate(this,&CTreeViewUI::OnFolderChanged);
  715. pControl->GetCheckBox()->OnNotify += MakeDelegate(this,&CTreeViewUI::OnCheckBoxChanged);
  716. pControl->SetVisibleFolderBtn(m_bVisibleFolderBtn);
  717. pControl->SetVisibleCheckBtn(m_bVisibleCheckBtn);
  718. if(m_uItemMinWidth > 0)
  719. pControl->SetMinWidth(m_uItemMinWidth);
  720. CListUI::Add(pControl);
  721. int nLevel = pControl->GetTreeLevel();
  722. int nFolderWidth = pControl->GetFolderButton()->GetFixedWidth();
  723. if(nFolderWidth <= 0) nFolderWidth = 16;
  724. if(!pControl->GetFolderButton()->IsVisible()) nFolderWidth = 0;
  725. pControl->GetFolderButton()->SetPadding(CDuiRect(nLevel * nFolderWidth, 0, 0, 0));
  726. if(pControl->GetCountChild() > 0) {
  727. int nCount = pControl->GetCountChild();
  728. for(int nIndex = 0;nIndex < nCount;nIndex++) {
  729. CTreeNodeUI* pNode = pControl->GetChildNode(nIndex);
  730. if(pNode) Add(pNode);
  731. }
  732. }
  733. pControl->SetTreeView(this);
  734. return true;
  735. }
  736. //************************************
  737. // 函数名称: AddAt
  738. // 返回类型: long
  739. // 参数信息: CTreeNodeUI * pControl
  740. // 参数信息: int iIndex
  741. // 函数说明: 该方法不会将待插入的节点进行缩位处理,若打算插入的节点为非根节点,请使用AddAt(CTreeNodeUI* pControl,CTreeNodeUI* _IndexNode) 方法
  742. //************************************
  743. long CTreeViewUI::AddAt( CTreeNodeUI* pControl, int iIndex )
  744. {
  745. if (!pControl) return -1;
  746. if (NULL == static_cast<CTreeNodeUI*>(pControl->GetInterface(_T("TreeNode")))) return -1;
  747. pControl->OnNotify += MakeDelegate(this,&CTreeViewUI::OnDBClickItem);
  748. pControl->GetFolderButton()->OnNotify += MakeDelegate(this,&CTreeViewUI::OnFolderChanged);
  749. pControl->GetCheckBox()->OnNotify += MakeDelegate(this,&CTreeViewUI::OnCheckBoxChanged);
  750. pControl->SetVisibleFolderBtn(m_bVisibleFolderBtn);
  751. pControl->SetVisibleCheckBtn(m_bVisibleCheckBtn);
  752. if(m_uItemMinWidth > 0) {
  753. pControl->SetMinWidth(m_uItemMinWidth);
  754. }
  755. CListUI::AddAt(pControl, iIndex);
  756. int nLevel = pControl->GetTreeLevel();
  757. int nFolderWidth = pControl->GetFolderButton()->GetFixedWidth();
  758. if(nFolderWidth <= 0) nFolderWidth = 16;
  759. if(!pControl->GetFolderButton()->IsVisible()) nFolderWidth = 0;
  760. pControl->GetFolderButton()->SetPadding(CDuiRect(nLevel * nFolderWidth, 0, 0, 0));
  761. if(pControl->GetCountChild() > 0) {
  762. int nCount = pControl->GetCountChild();
  763. for(int nIndex = 0; nIndex < nCount; nIndex++) {
  764. CTreeNodeUI* pNode = pControl->GetChildNode(nIndex);
  765. if(pNode)
  766. return AddAt(pNode,iIndex+1);
  767. }
  768. }
  769. else {
  770. return iIndex + 1;
  771. }
  772. return -1;
  773. }
  774. //************************************
  775. // 函数名称: AddAt
  776. // 返回类型: bool
  777. // 参数信息: CTreeNodeUI * pControl
  778. // 参数信息: CTreeNodeUI * _IndexNode
  779. // 函数说明:
  780. //************************************
  781. bool CTreeViewUI::AddAt( CTreeNodeUI* pControl, CTreeNodeUI* _IndexNode )
  782. {
  783. if(!_IndexNode && !pControl)
  784. return false;
  785. int nItemIndex = -1;
  786. for(int nIndex = 0;nIndex < GetCount();nIndex++) {
  787. if(_IndexNode == GetItemAt(nIndex)) {
  788. nItemIndex = nIndex;
  789. break;
  790. }
  791. }
  792. if(nItemIndex == -1)
  793. return false;
  794. bool bRet = AddAt(pControl,nItemIndex) >= 0;
  795. if(bRet) {
  796. int nLevel = pControl->GetTreeLevel();
  797. int nFolderWidth = pControl->GetFolderButton()->GetFixedWidth();
  798. if(nFolderWidth <= 0) nFolderWidth = 16;
  799. if(!pControl->GetFolderButton()->IsVisible()) nFolderWidth = 0;
  800. pControl->GetFolderButton()->SetPadding(CDuiRect(nLevel * nFolderWidth, 0, 0, 0));
  801. }
  802. return bRet;
  803. }
  804. //************************************
  805. // 函数名称: Remove
  806. // 返回类型: bool
  807. // 参数信息: CTreeNodeUI * pControl
  808. // 函数说明: pControl 对象以及下的所有节点将被一并移除
  809. //************************************
  810. bool CTreeViewUI::Remove( CTreeNodeUI* pControl )
  811. {
  812. if(pControl->GetCountChild() > 0) {
  813. int nCount = pControl->GetCountChild();
  814. for(int nIndex = nCount - 1; nIndex >= 0; nIndex--) {
  815. CTreeNodeUI* pNode = pControl->GetChildNode(nIndex);
  816. if(pNode){
  817. pControl->Remove(pNode);
  818. }
  819. }
  820. }
  821. CListUI::Remove(pControl);
  822. return TRUE;
  823. }
  824. //************************************
  825. // 函数名称: RemoveAt
  826. // 返回类型: bool
  827. // 参数信息: int iIndex
  828. // 函数说明: iIndex 索引以及下的所有节点将被一并移除
  829. //************************************
  830. bool CTreeViewUI::RemoveAt( int iIndex )
  831. {
  832. CTreeNodeUI* pItem = (CTreeNodeUI*)GetItemAt(iIndex);
  833. Remove(pItem);
  834. return TRUE;
  835. }
  836. void CTreeViewUI::RemoveAll()
  837. {
  838. CListUI::RemoveAll();
  839. }
  840. //************************************
  841. // 函数名称: Notify
  842. // 返回类型: void
  843. // 参数信息: TNotifyUI & msg
  844. // 函数说明:
  845. //************************************
  846. void CTreeViewUI::Notify( TNotifyUI& msg )
  847. {
  848. }
  849. //************************************
  850. // 函数名称: OnCheckBoxChanged
  851. // 返回类型: bool
  852. // 参数信息: void * param
  853. // 函数说明:
  854. //************************************
  855. bool CTreeViewUI::OnCheckBoxChanged( void* param )
  856. {
  857. TNotifyUI* pMsg = (TNotifyUI*)param;
  858. if(pMsg->sType == DUI_MSGTYPE_SELECTCHANGED)
  859. {
  860. CCheckBoxUI* pCheckBox = (CCheckBoxUI*)pMsg->pSender;
  861. CTreeNodeUI* pItem = (CTreeNodeUI*)pCheckBox->GetParent()->GetParent();
  862. SetItemCheckBox(pCheckBox->GetCheck(),pItem);
  863. return TRUE;
  864. }
  865. return TRUE;
  866. }
  867. //************************************
  868. // 函数名称: OnFolderChanged
  869. // 返回类型: bool
  870. // 参数信息: void * param
  871. // 函数说明:
  872. //************************************
  873. bool CTreeViewUI::OnFolderChanged( void* param )
  874. {
  875. TNotifyUI* pMsg = (TNotifyUI*)param;
  876. if(pMsg->sType == DUI_MSGTYPE_SELECTCHANGED) {
  877. CCheckBoxUI* pFolder = (CCheckBoxUI*)pMsg->pSender;
  878. CTreeNodeUI* pItem = (CTreeNodeUI*)pFolder->GetParent()->GetParent();
  879. pItem->SetVisibleTag(!pFolder->GetCheck());
  880. SetItemExpand(!pFolder->GetCheck(),pItem);
  881. return TRUE;
  882. }
  883. return TRUE;
  884. }
  885. //************************************
  886. // 函数名称: OnDBClickItem
  887. // 返回类型: bool
  888. // 参数信息: void * param
  889. // 函数说明:
  890. //************************************
  891. bool CTreeViewUI::OnDBClickItem( void* param )
  892. {
  893. TNotifyUI* pMsg = (TNotifyUI*)param;
  894. if(_tcsicmp(pMsg->sType, DUI_MSGTYPE_TREEITEMDBCLICK) == 0) {
  895. CTreeNodeUI* pItem = static_cast<CTreeNodeUI*>(pMsg->pSender);
  896. CCheckBoxUI* pFolder = pItem->GetFolderButton();
  897. pFolder->Selected(!pFolder->IsSelected());
  898. pItem->SetVisibleTag(!pFolder->GetCheck());
  899. SetItemExpand(!pFolder->GetCheck(),pItem);
  900. return TRUE;
  901. }
  902. return FALSE;
  903. }
  904. //************************************
  905. // 函数名称: SetItemCheckBox
  906. // 返回类型: bool
  907. // 参数信息: bool _Selected
  908. // 参数信息: CTreeNodeUI * _TreeNode
  909. // 函数说明:
  910. //************************************
  911. bool CTreeViewUI::SetItemCheckBox( bool _Selected,CTreeNodeUI* _TreeNode /*= NULL*/ )
  912. {
  913. if(_TreeNode) {
  914. if(_TreeNode->GetCountChild() > 0) {
  915. int nCount = _TreeNode->GetCountChild();
  916. for(int nIndex = 0;nIndex < nCount;nIndex++) {
  917. CTreeNodeUI* pItem = _TreeNode->GetChildNode(nIndex);
  918. pItem->GetCheckBox()->Selected(_Selected);
  919. if(pItem->GetCountChild())
  920. SetItemCheckBox(_Selected,pItem);
  921. }
  922. }
  923. return TRUE;
  924. }
  925. else {
  926. int nIndex = 0;
  927. int nCount = GetCount();
  928. while(nIndex < nCount) {
  929. CTreeNodeUI* pItem = (CTreeNodeUI*)GetItemAt(nIndex);
  930. pItem->GetCheckBox()->Selected(_Selected);
  931. if(pItem->GetCountChild())
  932. SetItemCheckBox(_Selected,pItem);
  933. nIndex++;
  934. }
  935. return TRUE;
  936. }
  937. return FALSE;
  938. }
  939. //************************************
  940. // 函数名称: SetItemExpand
  941. // 返回类型: void
  942. // 参数信息: bool _Expanded
  943. // 参数信息: CTreeNodeUI * _TreeNode
  944. // 函数说明:
  945. //************************************
  946. void CTreeViewUI::SetItemExpand( bool _Expanded,CTreeNodeUI* _TreeNode /*= NULL*/ )
  947. {
  948. if(_TreeNode) {
  949. if(_TreeNode->GetCountChild() > 0) {
  950. int nCount = _TreeNode->GetCountChild();
  951. for(int nIndex = 0;nIndex < nCount;nIndex++) {
  952. CTreeNodeUI* pItem = _TreeNode->GetChildNode(nIndex);
  953. pItem->SetVisible(_Expanded);
  954. if(pItem->GetCountChild() && !pItem->GetFolderButton()->IsSelected()) {
  955. SetItemExpand(_Expanded,pItem);
  956. }
  957. }
  958. }
  959. }
  960. else {
  961. int nIndex = 0;
  962. int nCount = GetCount();
  963. while(nIndex < nCount) {
  964. CTreeNodeUI* pItem = (CTreeNodeUI*)GetItemAt(nIndex);
  965. pItem->GetFolderButton()->Selected(!_Expanded);
  966. if(pItem->GetCountChild() && !pItem->GetFolderButton()->IsSelected()) {
  967. SetItemExpand(_Expanded, pItem);
  968. }
  969. nIndex++;
  970. }
  971. }
  972. }
  973. //************************************
  974. // 函数名称: SetVisibleFolderBtn
  975. // 返回类型: void
  976. // 参数信息: bool _IsVisibled
  977. // 函数说明:
  978. //************************************
  979. void CTreeViewUI::SetVisibleFolderBtn( bool _IsVisibled )
  980. {
  981. m_bVisibleFolderBtn = _IsVisibled;
  982. int nCount = this->GetCount();
  983. for(int nIndex = 0; nIndex < nCount; nIndex++) {
  984. CTreeNodeUI* pItem = static_cast<CTreeNodeUI*>(this->GetItemAt(nIndex));
  985. pItem->GetFolderButton()->SetVisible(m_bVisibleFolderBtn);
  986. }
  987. }
  988. //************************************
  989. // 函数名称: GetVisibleFolderBtn
  990. // 返回类型: bool
  991. // 函数说明:
  992. //************************************
  993. bool CTreeViewUI::GetVisibleFolderBtn()
  994. {
  995. return m_bVisibleFolderBtn;
  996. }
  997. //************************************
  998. // 函数名称: SetVisibleCheckBtn
  999. // 返回类型: void
  1000. // 参数信息: bool _IsVisibled
  1001. // 函数说明:
  1002. //************************************
  1003. void CTreeViewUI::SetVisibleCheckBtn( bool _IsVisibled )
  1004. {
  1005. m_bVisibleCheckBtn = _IsVisibled;
  1006. int nCount = this->GetCount();
  1007. for(int nIndex = 0; nIndex < nCount; nIndex++) {
  1008. CTreeNodeUI* pItem = static_cast<CTreeNodeUI*>(this->GetItemAt(nIndex));
  1009. pItem->GetCheckBox()->SetVisible(m_bVisibleCheckBtn);
  1010. }
  1011. }
  1012. //************************************
  1013. // 函数名称: GetVisibleCheckBtn
  1014. // 返回类型: bool
  1015. // 函数说明:
  1016. //************************************
  1017. bool CTreeViewUI::GetVisibleCheckBtn()
  1018. {
  1019. return m_bVisibleCheckBtn;
  1020. }
  1021. //************************************
  1022. // 函数名称: SetItemMinWidth
  1023. // 返回类型: void
  1024. // 参数信息: UINT _ItemMinWidth
  1025. // 函数说明:
  1026. //************************************
  1027. void CTreeViewUI::SetItemMinWidth( UINT _ItemMinWidth )
  1028. {
  1029. m_uItemMinWidth = _ItemMinWidth;
  1030. for(int nIndex = 0;nIndex < GetCount();nIndex++){
  1031. CTreeNodeUI* pTreeNode = static_cast<CTreeNodeUI*>(GetItemAt(nIndex));
  1032. if(pTreeNode) {
  1033. pTreeNode->SetMinWidth(GetItemMinWidth());
  1034. }
  1035. }
  1036. Invalidate();
  1037. }
  1038. //************************************
  1039. // 函数名称: GetItemMinWidth
  1040. // 返回类型: UINT
  1041. // 函数说明:
  1042. //************************************
  1043. UINT CTreeViewUI::GetItemMinWidth()
  1044. {
  1045. return m_uItemMinWidth;
  1046. }
  1047. //************************************
  1048. // 函数名称: SetItemTextColor
  1049. // 返回类型: void
  1050. // 参数信息: DWORD _dwItemTextColor
  1051. // 函数说明:
  1052. //************************************
  1053. void CTreeViewUI::SetItemTextColor( DWORD _dwItemTextColor )
  1054. {
  1055. for(int nIndex = 0;nIndex < GetCount();nIndex++){
  1056. CTreeNodeUI* pTreeNode = static_cast<CTreeNodeUI*>(GetItemAt(nIndex));
  1057. if(pTreeNode) {
  1058. pTreeNode->SetItemTextColor(_dwItemTextColor);
  1059. }
  1060. }
  1061. }
  1062. //************************************
  1063. // 函数名称: SetItemHotTextColor
  1064. // 返回类型: void
  1065. // 参数信息: DWORD _dwItemHotTextColor
  1066. // 函数说明:
  1067. //************************************
  1068. void CTreeViewUI::SetItemHotTextColor( DWORD _dwItemHotTextColor )
  1069. {
  1070. for(int nIndex = 0;nIndex < GetCount();nIndex++){
  1071. CTreeNodeUI* pTreeNode = static_cast<CTreeNodeUI*>(GetItemAt(nIndex));
  1072. if(pTreeNode) {
  1073. pTreeNode->SetItemHotTextColor(_dwItemHotTextColor);
  1074. }
  1075. }
  1076. }
  1077. //************************************
  1078. // 函数名称: SetSelItemTextColor
  1079. // 返回类型: void
  1080. // 参数信息: DWORD _dwSelItemTextColor
  1081. // 函数说明:
  1082. //************************************
  1083. void CTreeViewUI::SetSelItemTextColor( DWORD _dwSelItemTextColor )
  1084. {
  1085. for(int nIndex = 0;nIndex < GetCount();nIndex++){
  1086. CTreeNodeUI* pTreeNode = static_cast<CTreeNodeUI*>(GetItemAt(nIndex));
  1087. if(pTreeNode) {
  1088. pTreeNode->SetSelItemTextColor(_dwSelItemTextColor);
  1089. }
  1090. }
  1091. }
  1092. //************************************
  1093. // 函数名称: SetSelItemHotTextColor
  1094. // 返回类型: void
  1095. // 参数信息: DWORD _dwSelHotItemTextColor
  1096. // 函数说明:
  1097. //************************************
  1098. void CTreeViewUI::SetSelItemHotTextColor( DWORD _dwSelHotItemTextColor )
  1099. {
  1100. for(int nIndex = 0;nIndex < GetCount();nIndex++){
  1101. CTreeNodeUI* pTreeNode = static_cast<CTreeNodeUI*>(GetItemAt(nIndex));
  1102. if(pTreeNode) {
  1103. pTreeNode->SetSelItemHotTextColor(_dwSelHotItemTextColor);
  1104. }
  1105. }
  1106. }
  1107. //************************************
  1108. // 函数名称: SetAttribute
  1109. // 返回类型: void
  1110. // 参数信息: LPCTSTR pstrName
  1111. // 参数信息: LPCTSTR pstrValue
  1112. // 函数说明:
  1113. //************************************
  1114. void CTreeViewUI::SetAttribute( LPCTSTR pstrName, LPCTSTR pstrValue )
  1115. {
  1116. if(_tcsicmp(pstrName,_T("visiblefolderbtn")) == 0)
  1117. SetVisibleFolderBtn(_tcsicmp(pstrValue,_T("TRUE")) == 0);
  1118. else if(_tcsicmp(pstrName,_T("visiblecheckbtn")) == 0)
  1119. SetVisibleCheckBtn(_tcsicmp(pstrValue,_T("TRUE")) == 0);
  1120. else if(_tcsicmp(pstrName,_T("itemminwidth")) == 0)
  1121. SetItemMinWidth(_ttoi(pstrValue));
  1122. else if(_tcsicmp(pstrName, _T("itemtextcolor")) == 0 ){
  1123. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  1124. LPTSTR pstr = NULL;
  1125. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  1126. SetItemTextColor(clrColor);
  1127. }
  1128. else if(_tcsicmp(pstrName, _T("itemhottextcolor")) == 0 ){
  1129. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  1130. LPTSTR pstr = NULL;
  1131. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  1132. SetItemHotTextColor(clrColor);
  1133. }
  1134. else if(_tcsicmp(pstrName, _T("selitemtextcolor")) == 0 ){
  1135. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  1136. LPTSTR pstr = NULL;
  1137. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  1138. SetSelItemTextColor(clrColor);
  1139. }
  1140. else if(_tcsicmp(pstrName, _T("selitemhottextcolor")) == 0 ){
  1141. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  1142. LPTSTR pstr = NULL;
  1143. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  1144. SetSelItemHotTextColor(clrColor);
  1145. }
  1146. else CListUI::SetAttribute(pstrName,pstrValue);
  1147. }
  1148. }