UIDlgBuilder.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. #include "StdAfx.h"
  2. namespace DuiLib {
  3. CDialogBuilder::CDialogBuilder() : m_pCallback(NULL), m_pstrtype(NULL)
  4. {
  5. }
  6. CControlUI* CDialogBuilder::Create(STRINGorID xml, LPCTSTR type, IDialogBuilderCallback* pCallback,
  7. CPaintManagerUI* pManager, CControlUI* pParent)
  8. {
  9. //资源ID为0-65535,两个字节;字符串指针为4个字节
  10. //字符串以<开头认为是XML字符串,否则认为是XML文件
  11. if( HIWORD(xml.m_lpstr) != NULL ) {
  12. if( *(xml.m_lpstr) == _T('<') ) {
  13. if( !m_xml.Load(xml.m_lpstr) ) return NULL;
  14. }
  15. else {
  16. if( !m_xml.LoadFromFile(xml.m_lpstr) ) return NULL;
  17. }
  18. }
  19. else {
  20. HRSRC hResource = ::FindResource(CPaintManagerUI::GetResourceDll(), xml.m_lpstr, type);
  21. if( hResource == NULL ) return NULL;
  22. HGLOBAL hGlobal = ::LoadResource(CPaintManagerUI::GetResourceDll(), hResource);
  23. if( hGlobal == NULL ) {
  24. FreeResource(hResource);
  25. return NULL;
  26. }
  27. m_pCallback = pCallback;
  28. if( !m_xml.LoadFromMem((BYTE*)::LockResource(hGlobal), ::SizeofResource(CPaintManagerUI::GetResourceDll(), hResource) )) return NULL;
  29. ::FreeResource(hResource);
  30. m_pstrtype = type;
  31. }
  32. return Create(pCallback, pManager, pParent);
  33. }
  34. CControlUI* CDialogBuilder::Create(IDialogBuilderCallback* pCallback, CPaintManagerUI* pManager, CControlUI* pParent)
  35. {
  36. m_pCallback = pCallback;
  37. CMarkupNode root = m_xml.GetRoot();
  38. if( !root.IsValid() ) return NULL;
  39. if( pManager ) {
  40. LPCTSTR pstrClass = NULL;
  41. int nAttributes = 0;
  42. LPCTSTR pstrName = NULL;
  43. LPCTSTR pstrValue = NULL;
  44. LPTSTR pstr = NULL;
  45. for( CMarkupNode node = root.GetChild() ; node.IsValid(); node = node.GetSibling() ) {
  46. pstrClass = node.GetName();
  47. if( _tcsicmp(pstrClass, _T("Image")) == 0 ) {
  48. nAttributes = node.GetAttributeCount();
  49. LPCTSTR pImageName = NULL;
  50. LPCTSTR pImageResType = NULL;
  51. DWORD mask = 0;
  52. bool shared = false;
  53. for( int i = 0; i < nAttributes; i++ ) {
  54. pstrName = node.GetAttributeName(i);
  55. pstrValue = node.GetAttributeValue(i);
  56. if( _tcsicmp(pstrName, _T("name")) == 0 ) {
  57. pImageName = pstrValue;
  58. }
  59. else if( _tcsicmp(pstrName, _T("restype")) == 0 ) {
  60. pImageResType = pstrValue;
  61. }
  62. else if( _tcsicmp(pstrName, _T("mask")) == 0 ) {
  63. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  64. mask = _tcstoul(pstrValue, &pstr, 16);
  65. }
  66. else if( _tcsicmp(pstrName, _T("shared")) == 0 ) {
  67. shared = (_tcsicmp(pstrValue, _T("true")) == 0);
  68. }
  69. }
  70. if( pImageName ) pManager->AddImage(pImageName, pImageResType, mask, shared);
  71. }
  72. else if( _tcsicmp(pstrClass, _T("Font")) == 0 ) {
  73. nAttributes = node.GetAttributeCount();
  74. int id = -1;
  75. LPCTSTR pFontName = NULL;
  76. int size = 12;
  77. bool bold = false;
  78. bool underline = false;
  79. bool italic = false;
  80. bool defaultfont = false;
  81. bool shared = false;
  82. for( int i = 0; i < nAttributes; i++ ) {
  83. pstrName = node.GetAttributeName(i);
  84. pstrValue = node.GetAttributeValue(i);
  85. if( _tcsicmp(pstrName, _T("id")) == 0 ) {
  86. id = _tcstol(pstrValue, &pstr, 10);
  87. }
  88. else if( _tcsicmp(pstrName, _T("name")) == 0 ) {
  89. pFontName = pstrValue;
  90. }
  91. else if( _tcsicmp(pstrName, _T("size")) == 0 ) {
  92. size = _tcstol(pstrValue, &pstr, 10);
  93. }
  94. else if( _tcsicmp(pstrName, _T("bold")) == 0 ) {
  95. bold = (_tcsicmp(pstrValue, _T("true")) == 0);
  96. }
  97. else if( _tcsicmp(pstrName, _T("underline")) == 0 ) {
  98. underline = (_tcsicmp(pstrValue, _T("true")) == 0);
  99. }
  100. else if( _tcsicmp(pstrName, _T("italic")) == 0 ) {
  101. italic = (_tcsicmp(pstrValue, _T("true")) == 0);
  102. }
  103. else if( _tcsicmp(pstrName, _T("default")) == 0 ) {
  104. defaultfont = (_tcsicmp(pstrValue, _T("true")) == 0);
  105. }
  106. else if( _tcsicmp(pstrName, _T("shared")) == 0 ) {
  107. shared = (_tcsicmp(pstrValue, _T("true")) == 0);
  108. }
  109. }
  110. if( id >= 0 && pFontName ) {
  111. pManager->AddFont(id, pFontName, size, bold, underline, italic, shared);
  112. if( defaultfont ) pManager->SetDefaultFont(pFontName, size, bold, underline, italic, shared);
  113. }
  114. }
  115. else if( _tcsicmp(pstrClass, _T("Default")) == 0 ) {
  116. nAttributes = node.GetAttributeCount();
  117. LPCTSTR pControlName = NULL;
  118. LPCTSTR pControlValue = NULL;
  119. bool shared = false;
  120. for( int i = 0; i < nAttributes; i++ ) {
  121. pstrName = node.GetAttributeName(i);
  122. pstrValue = node.GetAttributeValue(i);
  123. if( _tcsicmp(pstrName, _T("name")) == 0 ) {
  124. pControlName = pstrValue;
  125. }
  126. else if( _tcsicmp(pstrName, _T("value")) == 0 ) {
  127. pControlValue = pstrValue;
  128. }
  129. else if( _tcsicmp(pstrName, _T("shared")) == 0 ) {
  130. shared = (_tcsicmp(pstrValue, _T("true")) == 0);
  131. }
  132. }
  133. if( pControlName ) {
  134. pManager->AddDefaultAttributeList(pControlName, pControlValue, shared);
  135. }
  136. }
  137. else if( _tcsicmp(pstrClass, _T("MultiLanguage")) == 0 ) {
  138. nAttributes = node.GetAttributeCount();
  139. int id = -1;
  140. LPCTSTR pMultiLanguage = NULL;
  141. for( int i = 0; i < nAttributes; i++ ) {
  142. pstrName = node.GetAttributeName(i);
  143. pstrValue = node.GetAttributeValue(i);
  144. if( _tcsicmp(pstrName, _T("id")) == 0 ) {
  145. id = _tcstol(pstrValue, &pstr, 10);
  146. }
  147. else if( _tcsicmp(pstrName, _T("value")) == 0 ) {
  148. pMultiLanguage = pstrValue;
  149. }
  150. }
  151. if (id >= 0 && pMultiLanguage ) {
  152. pManager->AddMultiLanguageString(id, pMultiLanguage);
  153. }
  154. }
  155. }
  156. pstrClass = root.GetName();
  157. if( _tcsicmp(pstrClass, _T("Window")) == 0 ) {
  158. if( pManager->GetPaintWindow() ) {
  159. int nAttributes = root.GetAttributeCount();
  160. for( int i = 0; i < nAttributes; i++ ) {
  161. pstrName = root.GetAttributeName(i);
  162. pstrValue = root.GetAttributeValue(i);
  163. if( _tcsicmp(pstrName, _T("size")) == 0 ) {
  164. LPTSTR pstr = NULL;
  165. int cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  166. int cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  167. pManager->SetInitSize(cx, cy);
  168. }
  169. else if( _tcsicmp(pstrName, _T("sizebox")) == 0 ) {
  170. RECT rcSizeBox = { 0 };
  171. LPTSTR pstr = NULL;
  172. rcSizeBox.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  173. rcSizeBox.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  174. rcSizeBox.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  175. rcSizeBox.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  176. pManager->SetSizeBox(rcSizeBox);
  177. }
  178. else if( _tcsicmp(pstrName, _T("caption")) == 0 ) {
  179. RECT rcCaption = { 0 };
  180. LPTSTR pstr = NULL;
  181. rcCaption.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  182. rcCaption.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  183. rcCaption.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  184. rcCaption.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  185. pManager->SetCaptionRect(rcCaption);
  186. }
  187. else if( _tcsicmp(pstrName, _T("roundcorner")) == 0 ) {
  188. LPTSTR pstr = NULL;
  189. int cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  190. int cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  191. pManager->SetRoundCorner(cx, cy);
  192. }
  193. else if( _tcsicmp(pstrName, _T("mininfo")) == 0 ) {
  194. LPTSTR pstr = NULL;
  195. int cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  196. int cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  197. pManager->SetMinInfo(cx, cy);
  198. }
  199. else if( _tcsicmp(pstrName, _T("maxinfo")) == 0 ) {
  200. LPTSTR pstr = NULL;
  201. int cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  202. int cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  203. pManager->SetMaxInfo(cx, cy);
  204. }
  205. else if( _tcsicmp(pstrName, _T("showdirty")) == 0 ) {
  206. pManager->SetShowUpdateRect(_tcsicmp(pstrValue, _T("true")) == 0);
  207. }
  208. else if( _tcsicmp(pstrName, _T("alpha")) == 0 ) {
  209. pManager->SetOpacity(_ttoi(pstrValue));
  210. }
  211. else if( _tcscmp(pstrName, _T("layeredopacity")) == 0 ) {
  212. pManager->SetLayeredOpacity(_ttoi(pstrValue));
  213. }
  214. else if( _tcscmp(pstrName, _T("layeredimage")) == 0 ) {
  215. pManager->SetLayered(true);
  216. pManager->SetLayeredImage(pstrValue);
  217. }
  218. else if( _tcsicmp(pstrName, _T("disabledfontcolor")) == 0 ) {
  219. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  220. LPTSTR pstr = NULL;
  221. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  222. pManager->SetDefaultDisabledColor(clrColor);
  223. }
  224. else if( _tcsicmp(pstrName, _T("defaultfontcolor")) == 0 ) {
  225. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  226. LPTSTR pstr = NULL;
  227. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  228. pManager->SetDefaultFontColor(clrColor);
  229. }
  230. else if( _tcsicmp(pstrName, _T("linkfontcolor")) == 0 ) {
  231. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  232. LPTSTR pstr = NULL;
  233. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  234. pManager->SetDefaultLinkFontColor(clrColor);
  235. }
  236. else if( _tcsicmp(pstrName, _T("linkhoverfontcolor")) == 0 ) {
  237. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  238. LPTSTR pstr = NULL;
  239. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  240. pManager->SetDefaultLinkHoverFontColor(clrColor);
  241. }
  242. else if( _tcsicmp(pstrName, _T("selectedcolor")) == 0 ) {
  243. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  244. LPTSTR pstr = NULL;
  245. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  246. pManager->SetDefaultSelectedBkColor(clrColor);
  247. }
  248. //-----------------------------add--------------------------------;
  249. else if( _tcscmp(pstrName, _T("shadowsize")) == 0 ) {
  250. pManager->GetShadow()->SetSize(_ttoi(pstrValue));
  251. }
  252. else if( _tcscmp(pstrName, _T("shadowsharpness")) == 0 ) {
  253. pManager->GetShadow()->SetSharpness(_ttoi(pstrValue));
  254. }
  255. else if( _tcscmp(pstrName, _T("shadowdarkness")) == 0 ) {
  256. pManager->GetShadow()->SetDarkness(_ttoi(pstrValue));
  257. }
  258. else if( _tcscmp(pstrName, _T("shadowposition")) == 0 ) {
  259. LPTSTR pstr = NULL;
  260. int cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  261. int cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  262. pManager->GetShadow()->SetPosition(cx, cy);
  263. }
  264. else if( _tcscmp(pstrName, _T("shadowcolor")) == 0 ) {
  265. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  266. LPTSTR pstr = NULL;
  267. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  268. pManager->GetShadow()->SetColor(clrColor);
  269. }
  270. else if( _tcscmp(pstrName, _T("shadowcorner")) == 0 ) {
  271. RECT rcCorner = { 0 };
  272. LPTSTR pstr = NULL;
  273. rcCorner.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  274. rcCorner.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  275. rcCorner.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  276. rcCorner.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  277. pManager->GetShadow()->SetShadowCorner(rcCorner);
  278. }
  279. else if( _tcscmp(pstrName, _T("shadowimage")) == 0 ) {
  280. pManager->GetShadow()->SetImage(pstrValue);
  281. }
  282. else if( _tcscmp(pstrName, _T("showshadow")) == 0 ) {
  283. pManager->GetShadow()->ShowShadow(_tcscmp(pstrValue, _T("true")) == 0);
  284. }
  285. else if(_tcscmp (pstrName, _T ("shadow")) == 0)
  286. {
  287. pManager->GetShadow ()->SetImage (pstrValue);
  288. pManager->GetShadow ()->SetShadowCorner (RECT{23, 13, 23, 33});
  289. pManager->GetShadow ()->ShowShadow (true);
  290. }
  291. //-------------------------------------------------------------------------------
  292. else
  293. pManager->AddWindowCustomAttribute(pstrName, pstrValue);
  294. }
  295. }
  296. }
  297. }
  298. return _Parse(&root, pParent, pManager);
  299. }
  300. CMarkup* CDialogBuilder::GetMarkup()
  301. {
  302. return &m_xml;
  303. }
  304. void CDialogBuilder::GetLastErrorMessage(LPTSTR pstrMessage, SIZE_T cchMax) const
  305. {
  306. return m_xml.GetLastErrorMessage(pstrMessage, cchMax);
  307. }
  308. void CDialogBuilder::GetLastErrorLocation(LPTSTR pstrSource, SIZE_T cchMax) const
  309. {
  310. return m_xml.GetLastErrorLocation(pstrSource, cchMax);
  311. }
  312. void CDialogBuilder::SetOwnerBuilder (IDialogBuilderCallback* pCallback)
  313. {
  314. m_pCallback = pCallback;
  315. }
  316. CControlUI* CDialogBuilder::_Parse (CMarkupNode* pRoot, CControlUI* pParent, CPaintManagerUI* pManager)
  317. {
  318. IContainerUI* pContainer = NULL;
  319. CControlUI* pReturn = NULL;
  320. for( CMarkupNode node = pRoot->GetChild() ; node.IsValid(); node = node.GetSibling() ) {
  321. LPCTSTR pstrClass = node.GetName();
  322. if( _tcsicmp(pstrClass, _T("Image")) == 0 || _tcsicmp(pstrClass, _T("Font")) == 0 \
  323. || _tcsicmp(pstrClass, _T("Default")) == 0
  324. || _tcsicmp(pstrClass, _T("MultiLanguage")) == 0 ) continue;
  325. CControlUI* pControl = NULL;
  326. if( _tcsicmp(pstrClass, _T("Include")) == 0 ) {
  327. if( !node.HasAttributes() ) continue;
  328. int count = 1;
  329. LPTSTR pstr = NULL;
  330. TCHAR szValue[500] = { 0 };
  331. SIZE_T cchLen = lengthof(szValue) - 1;
  332. if ( node.GetAttributeValue(_T("count"), szValue, cchLen) )
  333. count = _tcstol(szValue, &pstr, 10);
  334. cchLen = lengthof(szValue) - 1;
  335. if ( !node.GetAttributeValue(_T("source"), szValue, cchLen) ) continue;
  336. for ( int i = 0; i < count; i++ ) {
  337. CDialogBuilder builder;
  338. if( m_pstrtype != NULL ) { // 使用资源dll,从资源中读取
  339. WORD id = (WORD)_tcstol(szValue, &pstr, 10);
  340. pControl = builder.Create((UINT)id, m_pstrtype, m_pCallback, pManager, pParent);
  341. }
  342. else {
  343. pControl = builder.Create((LPCTSTR)szValue, (UINT)0, m_pCallback, pManager, pParent);
  344. }
  345. }
  346. continue;
  347. }
  348. //树控件XML解析
  349. else if( _tcsicmp(pstrClass, _T("TreeNode")) == 0 ) {
  350. CTreeNodeUI* pParentNode = static_cast<CTreeNodeUI*>(pParent->GetInterface(_T("TreeNode")));
  351. CTreeNodeUI* pNode = new CTreeNodeUI();
  352. if(pParentNode){
  353. if(!pParentNode->Add(pNode)){
  354. delete pNode;
  355. continue;
  356. }
  357. }
  358. // 若有控件默认配置先初始化默认属性
  359. if( pManager ) {
  360. pNode->SetManager(pManager, NULL, false);
  361. LPCTSTR pDefaultAttributes = pManager->GetDefaultAttributeList(pstrClass);
  362. if( pDefaultAttributes ) {
  363. pNode->ApplyAttributeList(pDefaultAttributes);
  364. }
  365. }
  366. // 解析所有属性并覆盖默认属性
  367. if( node.HasAttributes() ) {
  368. TCHAR szValue[500] = { 0 };
  369. SIZE_T cchLen = lengthof(szValue) - 1;
  370. // Set ordinary attributes
  371. int nAttributes = node.GetAttributeCount();
  372. for( int i = 0; i < nAttributes; i++ ) {
  373. pNode->SetAttribute(node.GetAttributeName(i), node.GetAttributeValue(i));
  374. }
  375. }
  376. //检索子节点及附加控件
  377. if(node.HasChildren()){
  378. CControlUI* pSubControl = _Parse(&node,pNode,pManager);
  379. if(pSubControl && _tcsicmp(pSubControl->GetClass(),_T("TreeNodeUI")) != 0)
  380. {
  381. // pSubControl->SetFixedWidth(30);
  382. // CHorizontalLayoutUI* pHorz = pNode->GetTreeNodeHoriznotal();
  383. // pHorz->Add(new CEditUI());
  384. // continue;
  385. }
  386. }
  387. if(!pParentNode){
  388. CTreeViewUI* pTreeView = static_cast<CTreeViewUI*>(pParent->GetInterface(_T("TreeView")));
  389. ASSERT(pTreeView);
  390. if( pTreeView == NULL ) return NULL;
  391. if( !pTreeView->Add(pNode) ) {
  392. delete pNode;
  393. continue;
  394. }
  395. }
  396. continue;
  397. }
  398. else {
  399. #ifdef _DEBUG
  400. DUITRACE(_T("Create Control: %s"), pstrClass);
  401. #endif
  402. SIZE_T cchLen = _tcslen(pstrClass);
  403. switch( cchLen ) {
  404. case 4:
  405. if( _tcsicmp(pstrClass, DUI_CTR_EDIT) == 0 ) pControl = new CEditUI;
  406. else if( _tcsicmp(pstrClass, DUI_CTR_LIST) == 0 ) pControl = new CListUI;
  407. else if( _tcsicmp(pstrClass, DUI_CTR_TEXT) == 0 ) pControl = new CTextUI;
  408. break;
  409. case 5:
  410. if( _tcsicmp(pstrClass, DUI_CTR_COMBO) == 0 ) pControl = new CComboUI;
  411. else if( _tcsicmp(pstrClass, DUI_CTR_LABEL) == 0 ) pControl = new CLabelUI;
  412. //else if( _tcsicmp(pstrClass, DUI_CTR_FLASH) == 0 ) pControl = new CFlashUI;
  413. break;
  414. case 6:
  415. if( _tcsicmp(pstrClass, DUI_CTR_BUTTON) == 0 ) pControl = new CButtonUI;
  416. else if( _tcsicmp(pstrClass, DUI_CTR_OPTION) == 0 ) pControl = new COptionUI;
  417. else if( _tcsicmp(pstrClass, DUI_CTR_SLIDER) == 0 ) pControl = new CSliderUI;
  418. break;
  419. case 7:
  420. if( _tcsicmp(pstrClass, DUI_CTR_CONTROL) == 0 ) pControl = new CControlUI;
  421. else if( _tcsicmp(pstrClass, DUI_CTR_ACTIVEX) == 0 ) pControl = new CActiveXUI;
  422. else if (_tcscmp(pstrClass, DUI_CTR_GIFANIM) == 0) pControl = new CGifAnimUI;
  423. break;
  424. case 8:
  425. if( _tcsicmp(pstrClass, DUI_CTR_PROGRESS) == 0 ) pControl = new CProgressUI;
  426. else if( _tcsicmp(pstrClass, DUI_CTR_RICHEDIT) == 0 ) pControl = new CRichEditUI;
  427. else if( _tcsicmp(pstrClass, DUI_CTR_CHECKBOX) == 0 ) pControl = new CCheckBoxUI;
  428. else if( _tcsicmp(pstrClass, DUI_CTR_DATETIME) == 0 ) pControl = new CDateTimeUI;
  429. else if( _tcsicmp(pstrClass, DUI_CTR_TREEVIEW) == 0 ) pControl = new CTreeViewUI;
  430. break;
  431. case 9:
  432. if( _tcsicmp(pstrClass, DUI_CTR_CONTAINER) == 0 ) pControl = new CContainerUI;
  433. else if( _tcsicmp(pstrClass, DUI_CTR_TABLAYOUT) == 0 ) pControl = new CTabLayoutUI;
  434. else if( _tcsicmp(pstrClass, DUI_CTR_SCROLLBAR) == 0 ) pControl = new CScrollBarUI;
  435. break;
  436. case 10:
  437. if( _tcsicmp(pstrClass, DUI_CTR_LISTHEADER) == 0 ) pControl = new CListHeaderUI;
  438. else if( _tcsicmp(pstrClass, DUI_CTR_TILELAYOUT) == 0 ) pControl = new CTileLayoutUI;
  439. else if( _tcsicmp(pstrClass, DUI_CTR_WEBBROWSER) == 0 ) pControl = new CWebBrowserUI;
  440. break;
  441. case 11:
  442. if (_tcsicmp(pstrClass, DUI_CTR_CHILDLAYOUT) == 0) pControl = new CChildLayoutUI(m_pCallback);
  443. break;
  444. case 14:
  445. if( _tcsicmp(pstrClass, DUI_CTR_VERTICALLAYOUT) == 0 ) pControl = new CVerticalLayoutUI;
  446. else if( _tcsicmp(pstrClass, DUI_CTR_LISTHEADERITEM) == 0 ) pControl = new CListHeaderItemUI;
  447. break;
  448. case 15:
  449. if( _tcsicmp(pstrClass, DUI_CTR_LISTTEXTELEMENT) == 0 ) pControl = new CListTextElementUI;
  450. break;
  451. case 16:
  452. if( _tcsicmp(pstrClass, DUI_CTR_HORIZONTALLAYOUT) == 0 ) pControl = new CHorizontalLayoutUI;
  453. else if( _tcsicmp(pstrClass, DUI_CTR_LISTLABELELEMENT) == 0 ) pControl = new CListLabelElementUI;
  454. break;
  455. case 20:
  456. if( _tcsicmp(pstrClass, DUI_CTR_LISTCONTAINERELEMENT) == 0 ) pControl = new CListContainerElementUI;
  457. break;
  458. default:
  459. //if (m_pCallback!=nullptr)
  460. //{
  461. // pControl = m_pCallback->CreateControl (pstrClass);
  462. //}
  463. break;
  464. }
  465. // User-supplied control factory
  466. if( pControl == NULL ) {
  467. CStdPtrArray* pPlugins = CPaintManagerUI::GetPlugins();
  468. LPCREATECONTROL lpCreateControl = NULL;
  469. for( int i = 0; i < pPlugins->GetSize(); ++i ) {
  470. lpCreateControl = (LPCREATECONTROL)pPlugins->GetAt(i);
  471. if( lpCreateControl != NULL ) {
  472. pControl = lpCreateControl(pstrClass);
  473. if( pControl != NULL ) break;
  474. }
  475. }
  476. }
  477. if( pControl == NULL && m_pCallback != NULL ) {
  478. pControl = m_pCallback->CreateControl(pstrClass);
  479. }
  480. }
  481. #ifndef _DEBUG
  482. ASSERT(pControl);
  483. #endif // _DEBUG
  484. if( pControl == NULL )
  485. {
  486. #ifdef _DEBUG
  487. DUITRACE(_T("Unknow Control:%s"),pstrClass);
  488. #else
  489. continue;
  490. #endif
  491. }
  492. // Add children
  493. if( node.HasChildren() ) {
  494. _Parse(&node, pControl, pManager);
  495. }
  496. // Attach to parent
  497. // 因为某些属性和父窗口相关,比如selected,必须先Add到父窗口
  498. if( pParent != NULL ) {
  499. CTreeNodeUI* pContainerNode = static_cast<CTreeNodeUI*>(pParent->GetInterface(_T("TreeNode")));
  500. if(pContainerNode)
  501. pContainerNode->GetTreeNodeHoriznotal()->Add(pControl);
  502. else
  503. {
  504. if( pContainer == NULL ) pContainer = static_cast<IContainerUI*>(pParent->GetInterface(_T("IContainer")));
  505. ASSERT(pContainer);
  506. if( pContainer == NULL ) return NULL;
  507. if( !pContainer->Add(pControl) ) {
  508. delete pControl;
  509. continue;
  510. }
  511. }
  512. }
  513. // Init default attributes
  514. if( pManager ) {
  515. pControl->SetManager(pManager, NULL, false);
  516. LPCTSTR pDefaultAttributes = pManager->GetDefaultAttributeList(pstrClass);
  517. if( pDefaultAttributes ) {
  518. pControl->ApplyAttributeList(pDefaultAttributes);
  519. }
  520. }
  521. // Process attributes
  522. if( node.HasAttributes() ) {
  523. TCHAR szValue[500] = { 0 };
  524. SIZE_T cchLen = lengthof(szValue) - 1;
  525. // Set ordinary attributes
  526. int nAttributes = node.GetAttributeCount();
  527. for( int i = 0; i < nAttributes; i++ ) {
  528. pControl->SetAttribute(node.GetAttributeName(i), node.GetAttributeValue(i));
  529. }
  530. }
  531. if( pManager ) {
  532. pControl->SetManager(NULL, NULL, false);
  533. }
  534. // Return first item
  535. if( pReturn == NULL ) pReturn = pControl;
  536. }
  537. return pReturn;
  538. }
  539. } // namespace DuiLib