UIDlgBuilder.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. #include "StdAfx.h"
  2. namespace DuiLib {
  3. CDialogBuilder::CDialogBuilder() : m_pCallback(NULL), m_pstrtype(NULL)
  4. {
  5. m_instance = NULL;
  6. }
  7. CControlUI* CDialogBuilder::Create(STRINGorID xml, LPCTSTR type, IDialogBuilderCallback* pCallback,
  8. CPaintManagerUI* pManager, CControlUI* pParent)
  9. {
  10. //资源ID为0-65535,两个字节;字符串指针为4个字节
  11. //字符串以<开头认为是XML字符串,否则认为是XML文件
  12. if(HIWORD(xml.m_lpstr) != NULL && *(xml.m_lpstr) != _T('<')) {
  13. LPCTSTR xmlpath = CResourceManager::GetInstance()->GetXmlPath(xml.m_lpstr);
  14. if (xmlpath != NULL) {
  15. xml = xmlpath;
  16. }
  17. }
  18. if( HIWORD(xml.m_lpstr) != NULL ) {
  19. if( *(xml.m_lpstr) == _T('<') ) {
  20. if( !m_xml.Load(xml.m_lpstr) ) return NULL;
  21. }
  22. else {
  23. if( !m_xml.LoadFromFile(xml.m_lpstr) ) return NULL;
  24. }
  25. }
  26. else {
  27. HINSTANCE dll_instence = NULL;
  28. if (m_instance)
  29. {
  30. dll_instence = m_instance;
  31. }
  32. else
  33. {
  34. dll_instence = CPaintManagerUI::GetResourceDll();
  35. }
  36. HRSRC hResource = ::FindResource(dll_instence, xml.m_lpstr, type);
  37. if( hResource == NULL ) return NULL;
  38. HGLOBAL hGlobal = ::LoadResource(dll_instence, hResource);
  39. if( hGlobal == NULL ) {
  40. FreeResource(hResource);
  41. return NULL;
  42. }
  43. m_pCallback = pCallback;
  44. if( !m_xml.LoadFromMem((BYTE*)::LockResource(hGlobal), ::SizeofResource(dll_instence, hResource) )) return NULL;
  45. ::FreeResource(hGlobal);
  46. m_pstrtype = type;
  47. }
  48. return Create(pCallback, pManager, pParent);
  49. }
  50. CControlUI* CDialogBuilder::Create(IDialogBuilderCallback* pCallback, CPaintManagerUI* pManager, CControlUI* pParent)
  51. {
  52. m_pCallback = pCallback;
  53. CMarkupNode root = m_xml.GetRoot();
  54. if( !root.IsValid() ) return NULL;
  55. if( pManager ) {
  56. LPCTSTR pstrClass = NULL;
  57. int nAttributes = 0;
  58. LPCTSTR pstrName = NULL;
  59. LPCTSTR pstrValue = NULL;
  60. LPTSTR pstr = NULL;
  61. for( CMarkupNode node = root.GetChild() ; node.IsValid(); node = node.GetSibling() ) {
  62. pstrClass = node.GetName();
  63. if( _tcsicmp(pstrClass, _T("Image")) == 0 ) {
  64. nAttributes = node.GetAttributeCount();
  65. LPCTSTR pImageName = NULL;
  66. LPCTSTR pImageResType = NULL;
  67. bool shared = false;
  68. DWORD mask = 0;
  69. for( int i = 0; i < nAttributes; i++ ) {
  70. pstrName = node.GetAttributeName(i);
  71. pstrValue = node.GetAttributeValue(i);
  72. if( _tcsicmp(pstrName, _T("name")) == 0 ) {
  73. pImageName = pstrValue;
  74. }
  75. else if( _tcsicmp(pstrName, _T("restype")) == 0 ) {
  76. pImageResType = pstrValue;
  77. }
  78. else if( _tcsicmp(pstrName, _T("mask")) == 0 ) {
  79. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  80. mask = _tcstoul(pstrValue, &pstr, 16);
  81. }
  82. else if( _tcsicmp(pstrName, _T("shared")) == 0 ) {
  83. shared = (_tcsicmp(pstrValue, _T("true")) == 0);
  84. }
  85. }
  86. if( pImageName ) pManager->AddImage(pImageName, pImageResType, mask, false, shared);
  87. }
  88. else if( _tcsicmp(pstrClass, _T("Font")) == 0 ) {
  89. nAttributes = node.GetAttributeCount();
  90. int id = -1;
  91. LPCTSTR pFontName = NULL;
  92. int size = 12;
  93. bool bold = false;
  94. bool underline = false;
  95. bool italic = false;
  96. bool defaultfont = false;
  97. bool shared = false;
  98. bool strikeout = false;
  99. for( int i = 0; i < nAttributes; i++ ) {
  100. pstrName = node.GetAttributeName(i);
  101. pstrValue = node.GetAttributeValue(i);
  102. if( _tcsicmp(pstrName, _T("id")) == 0 ) {
  103. id = _tcstol(pstrValue, &pstr, 10);
  104. }
  105. else if( _tcsicmp(pstrName, _T("name")) == 0 ) {
  106. pFontName = pstrValue;
  107. }
  108. else if( _tcsicmp(pstrName, _T("size")) == 0 ) {
  109. size = _tcstol(pstrValue, &pstr, 10);
  110. }
  111. else if( _tcsicmp(pstrName, _T("bold")) == 0 ) {
  112. bold = (_tcsicmp(pstrValue, _T("true")) == 0);
  113. }
  114. else if( _tcsicmp(pstrName, _T("underline")) == 0 ) {
  115. underline = (_tcsicmp(pstrValue, _T("true")) == 0);
  116. }
  117. else if( _tcsicmp(pstrName, _T("italic")) == 0 ) {
  118. italic = (_tcsicmp(pstrValue, _T("true")) == 0);
  119. }
  120. else if (_tcsicmp(pstrName, _T("strikeout")) == 0) {
  121. strikeout = (_tcsicmp(pstrValue, _T("true")) == 0);
  122. }
  123. else if( _tcsicmp(pstrName, _T("default")) == 0 ) {
  124. defaultfont = (_tcsicmp(pstrValue, _T("true")) == 0);
  125. }
  126. else if( _tcsicmp(pstrName, _T("shared")) == 0 ) {
  127. shared = (_tcsicmp(pstrValue, _T("true")) == 0);
  128. }
  129. }
  130. if( id >= 0 ) {
  131. pManager->AddFont(id, pFontName, size, bold, underline, italic, strikeout, shared);
  132. if( defaultfont ) pManager->SetDefaultFont(pFontName, size, bold, underline, italic, strikeout, shared);
  133. }
  134. }
  135. else if( _tcsicmp(pstrClass, _T("Default")) == 0 ) {
  136. nAttributes = node.GetAttributeCount();
  137. LPCTSTR pControlName = NULL;
  138. LPCTSTR pControlValue = NULL;
  139. bool shared = false;
  140. for( int i = 0; i < nAttributes; i++ ) {
  141. pstrName = node.GetAttributeName(i);
  142. pstrValue = node.GetAttributeValue(i);
  143. if( _tcsicmp(pstrName, _T("name")) == 0 ) {
  144. pControlName = pstrValue;
  145. }
  146. else if( _tcsicmp(pstrName, _T("value")) == 0 ) {
  147. pControlValue = pstrValue;
  148. }
  149. else if( _tcsicmp(pstrName, _T("shared")) == 0 ) {
  150. shared = (_tcsicmp(pstrValue, _T("true")) == 0);
  151. }
  152. }
  153. if( pControlName ) {
  154. pManager->AddDefaultAttributeList(pControlName, pControlValue, shared);
  155. }
  156. }
  157. else if( _tcsicmp(pstrClass, _T("Style")) == 0 ) {
  158. nAttributes = node.GetAttributeCount();
  159. LPCTSTR pName = NULL;
  160. LPCTSTR pStyle = NULL;
  161. bool shared = false;
  162. for( int i = 0; i < nAttributes; i++ ) {
  163. pstrName = node.GetAttributeName(i);
  164. pstrValue = node.GetAttributeValue(i);
  165. if( _tcsicmp(pstrName, _T("name")) == 0 ) {
  166. pName = pstrValue;
  167. }
  168. else if( _tcsicmp(pstrName, _T("value")) == 0 ) {
  169. pStyle = pstrValue;
  170. }
  171. else if( _tcsicmp(pstrName, _T("shared")) == 0 ) {
  172. shared = (_tcsicmp(pstrValue, _T("true")) == 0);
  173. }
  174. }
  175. if( pName ) {
  176. pManager->AddStyle(pName, pStyle, shared);
  177. }
  178. }
  179. else if (_tcsicmp(pstrClass, _T("Import")) == 0) {
  180. nAttributes = node.GetAttributeCount();
  181. LPCTSTR pstrPath = NULL;
  182. for (int i = 0; i < nAttributes; i++) {
  183. pstrName = node.GetAttributeName(i);
  184. pstrValue = node.GetAttributeValue(i);
  185. if (_tcsicmp(pstrName, _T("fontfile")) == 0) {
  186. pstrPath = pstrValue;
  187. }
  188. }
  189. if (pstrPath) {
  190. pManager->AddFontArray(pstrPath);
  191. }
  192. }
  193. }
  194. pstrClass = root.GetName();
  195. if( _tcsicmp(pstrClass, _T("Window")) == 0 ) {
  196. if( pManager->GetPaintWindow() ) {
  197. int nAttributes = root.GetAttributeCount();
  198. for( int i = 0; i < nAttributes; i++ ) {
  199. pstrName = root.GetAttributeName(i);
  200. pstrValue = root.GetAttributeValue(i);
  201. if( _tcsicmp(pstrName, _T("size")) == 0 ) {
  202. LPTSTR pstr = NULL;
  203. int cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  204. int cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  205. pManager->SetInitSize(pManager->GetDPIObj()->Scale(cx), pManager->GetDPIObj()->Scale(cy));
  206. }
  207. else if( _tcsicmp(pstrName, _T("sizebox")) == 0 ) {
  208. RECT rcSizeBox = { 0 };
  209. LPTSTR pstr = NULL;
  210. rcSizeBox.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  211. rcSizeBox.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  212. rcSizeBox.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  213. rcSizeBox.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  214. pManager->SetSizeBox(rcSizeBox);
  215. }
  216. else if( _tcsicmp(pstrName, _T("caption")) == 0 ) {
  217. RECT rcCaption = { 0 };
  218. LPTSTR pstr = NULL;
  219. rcCaption.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  220. rcCaption.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  221. rcCaption.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  222. rcCaption.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  223. pManager->SetCaptionRect(rcCaption);
  224. }
  225. else if( _tcsicmp(pstrName, _T("roundcorner")) == 0 ) {
  226. LPTSTR pstr = NULL;
  227. int cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  228. int cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  229. pManager->SetRoundCorner(cx, cy);
  230. }
  231. else if( _tcsicmp(pstrName, _T("mininfo")) == 0 ) {
  232. LPTSTR pstr = NULL;
  233. int cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  234. int cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  235. pManager->SetMinInfo(cx, cy);
  236. }
  237. else if( _tcsicmp(pstrName, _T("maxinfo")) == 0 ) {
  238. LPTSTR pstr = NULL;
  239. int cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  240. int cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  241. pManager->SetMaxInfo(cx, cy);
  242. }
  243. else if( _tcsicmp(pstrName, _T("showdirty")) == 0 ) {
  244. pManager->SetShowUpdateRect(_tcsicmp(pstrValue, _T("true")) == 0);
  245. }
  246. else if( _tcsicmp(pstrName, _T("opacity")) == 0 || _tcsicmp(pstrName, _T("alpha")) == 0 ) {
  247. pManager->SetOpacity(_ttoi(pstrValue));
  248. }
  249. else if( _tcscmp(pstrName, _T("layeredopacity")) == 0 ) {
  250. pManager->SetLayeredOpacity(_ttoi(pstrValue));
  251. }
  252. else if( _tcscmp(pstrName, _T("layered")) == 0 || _tcscmp(pstrName, _T("bktrans")) == 0) {
  253. pManager->SetLayered(_tcsicmp(pstrValue, _T("true")) == 0);
  254. }
  255. else if( _tcscmp(pstrName, _T("layeredimage")) == 0 ) {
  256. pManager->SetLayered(true);
  257. pManager->SetLayeredImage(pstrValue);
  258. }
  259. else if( _tcscmp(pstrName, _T("noactivate")) == 0 ) {
  260. pManager->SetNoActivate(_tcsicmp(pstrValue, _T("true")) == 0);
  261. }
  262. else if( _tcsicmp(pstrName, _T("disabledfontcolor")) == 0 ) {
  263. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  264. LPTSTR pstr = NULL;
  265. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  266. pManager->SetDefaultDisabledColor(clrColor);
  267. }
  268. else if( _tcsicmp(pstrName, _T("defaultfontcolor")) == 0 ) {
  269. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  270. LPTSTR pstr = NULL;
  271. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  272. pManager->SetDefaultFontColor(clrColor);
  273. }
  274. else if( _tcsicmp(pstrName, _T("linkfontcolor")) == 0 ) {
  275. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  276. LPTSTR pstr = NULL;
  277. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  278. pManager->SetDefaultLinkFontColor(clrColor);
  279. }
  280. else if( _tcsicmp(pstrName, _T("linkhoverfontcolor")) == 0 ) {
  281. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  282. LPTSTR pstr = NULL;
  283. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  284. pManager->SetDefaultLinkHoverFontColor(clrColor);
  285. }
  286. else if( _tcsicmp(pstrName, _T("selectedcolor")) == 0 ) {
  287. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  288. LPTSTR pstr = NULL;
  289. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  290. pManager->SetDefaultSelectedBkColor(clrColor);
  291. }
  292. else if( _tcsicmp(pstrName, _T("shadowsize")) == 0 ) {
  293. pManager->GetShadow()->SetSize(_ttoi(pstrValue));
  294. }
  295. else if( _tcsicmp(pstrName, _T("shadowsharpness")) == 0 ) {
  296. pManager->GetShadow()->SetSharpness(_ttoi(pstrValue));
  297. }
  298. else if( _tcsicmp(pstrName, _T("shadowdarkness")) == 0 ) {
  299. pManager->GetShadow()->SetDarkness(_ttoi(pstrValue));
  300. }
  301. else if( _tcsicmp(pstrName, _T("shadowposition")) == 0 ) {
  302. LPTSTR pstr = NULL;
  303. int cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  304. int cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  305. pManager->GetShadow()->SetPosition(cx, cy);
  306. }
  307. else if( _tcsicmp(pstrName, _T("shadowcolor")) == 0 ) {
  308. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  309. LPTSTR pstr = NULL;
  310. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  311. pManager->GetShadow()->SetColor(clrColor);
  312. }
  313. else if( _tcsicmp(pstrName, _T("shadowcorner")) == 0 ) {
  314. RECT rcCorner = { 0 };
  315. LPTSTR pstr = NULL;
  316. rcCorner.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  317. rcCorner.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  318. rcCorner.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  319. rcCorner.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  320. pManager->GetShadow()->SetShadowCorner(rcCorner);
  321. }
  322. else if( _tcsicmp(pstrName, _T("shadowimage")) == 0 ) {
  323. pManager->GetShadow()->SetImage(pstrValue);
  324. }
  325. else if( _tcsicmp(pstrName, _T("showshadow")) == 0 ) {
  326. pManager->GetShadow()->ShowShadow(_tcsicmp(pstrValue, _T("true")) == 0);
  327. }
  328. else if( _tcsicmp(pstrName, _T("gdiplustext")) == 0 ) {
  329. pManager->SetUseGdiplusText(_tcsicmp(pstrValue, _T("true")) == 0);
  330. }
  331. else if( _tcsicmp(pstrName, _T("textrenderinghint")) == 0 ) {
  332. pManager->SetGdiplusTextRenderingHint(_ttoi(pstrValue));
  333. }
  334. else if( _tcsicmp(pstrName, _T("tooltiphovertime")) == 0 ) {
  335. pManager->SetHoverTime(_ttoi(pstrValue));
  336. }
  337. }
  338. }
  339. }
  340. }
  341. return _Parse(&root, pParent, pManager);
  342. }
  343. CMarkup* CDialogBuilder::GetMarkup()
  344. {
  345. return &m_xml;
  346. }
  347. void CDialogBuilder::GetLastErrorMessage(LPTSTR pstrMessage, SIZE_T cchMax) const
  348. {
  349. return m_xml.GetLastErrorMessage(pstrMessage, cchMax);
  350. }
  351. void CDialogBuilder::GetLastErrorLocation(LPTSTR pstrSource, SIZE_T cchMax) const
  352. {
  353. return m_xml.GetLastErrorLocation(pstrSource, cchMax);
  354. }
  355. CControlUI* CDialogBuilder::_Parse(CMarkupNode* pRoot, CControlUI* pParent, CPaintManagerUI* pManager)
  356. {
  357. IContainerUI* pContainer = NULL;
  358. CControlUI* pReturn = NULL;
  359. for( CMarkupNode node = pRoot->GetChild() ; node.IsValid(); node = node.GetSibling() ) {
  360. LPCTSTR pstrClass = node.GetName();
  361. if( _tcsicmp(pstrClass, _T("Image")) == 0 || _tcsicmp(pstrClass, _T("Font")) == 0 \
  362. || _tcsicmp(pstrClass, _T("Default")) == 0 || _tcsicmp(pstrClass, _T("Style")) == 0 ) continue;
  363. CControlUI* pControl = NULL;
  364. if (_tcsicmp(pstrClass, _T("Import")) == 0) continue;
  365. if( _tcsicmp(pstrClass, _T("Include")) == 0 ) {
  366. if( !node.HasAttributes() ) continue;
  367. int count = 1;
  368. LPTSTR pstr = NULL;
  369. TCHAR szValue[500] = { 0 };
  370. SIZE_T cchLen = lengthof(szValue) - 1;
  371. if ( node.GetAttributeValue(_T("count"), szValue, cchLen) )
  372. count = _tcstol(szValue, &pstr, 10);
  373. cchLen = lengthof(szValue) - 1;
  374. if ( !node.GetAttributeValue(_T("source"), szValue, cchLen) ) continue;
  375. for ( int i = 0; i < count; i++ ) {
  376. CDialogBuilder builder;
  377. if( m_pstrtype != NULL ) { // 使用资源dll,从资源中读取
  378. WORD id = (WORD)_tcstol(szValue, &pstr, 10);
  379. pControl = builder.Create((UINT)id, m_pstrtype, m_pCallback, pManager, pParent);
  380. }
  381. else {
  382. pControl = builder.Create((LPCTSTR)szValue, (UINT)0, m_pCallback, pManager, pParent);
  383. }
  384. }
  385. continue;
  386. }
  387. else {
  388. CDuiString strClass;
  389. strClass.Format(_T("C%sUI"), pstrClass);
  390. pControl = dynamic_cast<CControlUI*>(CControlFactory::GetInstance()->CreateControl(strClass));
  391. // 检查插件
  392. if( pControl == NULL ) {
  393. CStdPtrArray* pPlugins = CPaintManagerUI::GetPlugins();
  394. LPCREATECONTROL lpCreateControl = NULL;
  395. for( int i = 0; i < pPlugins->GetSize(); ++i ) {
  396. lpCreateControl = (LPCREATECONTROL)pPlugins->GetAt(i);
  397. if( lpCreateControl != NULL ) {
  398. pControl = lpCreateControl(pstrClass);
  399. if( pControl != NULL ) break;
  400. }
  401. }
  402. }
  403. // 回掉创建
  404. if( pControl == NULL && m_pCallback != NULL ) {
  405. pControl = m_pCallback->CreateControl(pstrClass);
  406. }
  407. }
  408. if( pControl == NULL ) {
  409. #ifdef _DEBUG
  410. DUITRACE(_T("未知控件:%s"), pstrClass);
  411. #else
  412. continue;
  413. #endif
  414. }
  415. // Add children
  416. if( node.HasChildren() ) {
  417. _Parse(&node, pControl, pManager);
  418. }
  419. // Attach to parent
  420. // 因为某些属性和父窗口相关,比如selected,必须先Add到父窗口
  421. CTreeViewUI* pTreeView = NULL;
  422. if( pParent != NULL && pControl != NULL ) {
  423. CTreeNodeUI* pParentTreeNode = static_cast<CTreeNodeUI*>(pParent->GetInterface(_T("TreeNode")));
  424. CTreeNodeUI* pTreeNode = static_cast<CTreeNodeUI*>(pControl->GetInterface(_T("TreeNode")));
  425. pTreeView = static_cast<CTreeViewUI*>(pParent->GetInterface(_T("TreeView")));
  426. // TreeNode子节点
  427. if(pTreeNode != NULL) {
  428. if(pParentTreeNode) {
  429. pTreeView = pParentTreeNode->GetTreeView();
  430. if(!pParentTreeNode->Add(pTreeNode)) {
  431. delete pTreeNode;
  432. pTreeNode = NULL;
  433. continue;
  434. }
  435. }
  436. else {
  437. if(pTreeView != NULL) {
  438. if(!pTreeView->Add(pTreeNode)) {
  439. delete pTreeNode;
  440. pTreeNode = NULL;
  441. continue;
  442. }
  443. }
  444. }
  445. }
  446. // TreeNode子控件
  447. else if(pParentTreeNode != NULL) {
  448. pParentTreeNode->GetTreeNodeHoriznotal()->Add(pControl);
  449. }
  450. // 普通控件
  451. else {
  452. if( pContainer == NULL ) pContainer = static_cast<IContainerUI*>(pParent->GetInterface(_T("IContainer")));
  453. ASSERT(pContainer);
  454. if( pContainer == NULL ) return NULL;
  455. if( !pContainer->Add(pControl) ) {
  456. delete pControl;
  457. continue;
  458. }
  459. }
  460. }
  461. if( pControl == NULL ) continue;
  462. // Init default attributes
  463. if( pManager ) {
  464. if(pTreeView != NULL) {
  465. pControl->SetManager(pManager, pTreeView, true);
  466. }
  467. else {
  468. pControl->SetManager(pManager, NULL, false);
  469. }
  470. LPCTSTR pDefaultAttributes = pManager->GetDefaultAttributeList(pstrClass);
  471. if( pDefaultAttributes ) {
  472. pControl->ApplyAttributeList(pDefaultAttributes);
  473. }
  474. }
  475. // Process attributes
  476. if( node.HasAttributes() ) {
  477. // Set ordinary attributes
  478. int nAttributes = node.GetAttributeCount();
  479. for( int i = 0; i < nAttributes; i++ ) {
  480. pControl->SetAttribute(node.GetAttributeName(i), node.GetAttributeValue(i));
  481. }
  482. }
  483. if( pManager ) {
  484. if(pTreeView == NULL) {
  485. pControl->SetManager(NULL, NULL, false);
  486. }
  487. }
  488. // Return first item
  489. if( pReturn == NULL ) pReturn = pControl;
  490. }
  491. return pReturn;
  492. }
  493. } // namespace DuiLib