UIControl.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425
  1. #include "StdAfx.h"
  2. namespace DuiLib {
  3. IMPLEMENT_DUICONTROL(CControlUI)
  4. CControlUI::CControlUI()
  5. :m_pManager(NULL),
  6. m_pParent(NULL),
  7. m_bUpdateNeeded(true),
  8. m_bMenuUsed(false),
  9. m_bVisible(true),
  10. m_bInternVisible(true),
  11. m_bFocused(false),
  12. m_bEnabled(true),
  13. m_bMouseEnabled(true),
  14. m_bKeyboardEnabled(true),
  15. m_bFloat(false),
  16. m_uFloatAlign(0),
  17. m_bSetPos(false),
  18. m_bRichEvent(false),
  19. m_bDragEnabled(false),
  20. m_bDropEnabled(false),
  21. m_bResourceText(false),
  22. m_chShortcut('\0'),
  23. m_pTag(NULL),
  24. m_dwBackColor(0),
  25. m_dwBackColor2(0),
  26. m_dwBackColor3(0),
  27. m_dwForeColor(0),
  28. m_dwBorderColor(0),
  29. m_dwFocusBorderColor(0),
  30. m_bColorHSL(false),
  31. m_nBorderSize(0),
  32. m_nBorderStyle(PS_SOLID),
  33. m_nTooltipWidth(300),
  34. m_wCursor(0),
  35. m_instance(NULL)
  36. {
  37. m_cXY.cx = m_cXY.cy = 0;
  38. m_cxyFixed.cx = m_cxyFixed.cy = 0;
  39. m_cxyMin.cx = m_cxyMin.cy = 0;
  40. m_cxyMax.cx = m_cxyMax.cy = 9999;
  41. m_cxyBorderRound.cx = m_cxyBorderRound.cy = 0;
  42. ::ZeroMemory(&m_rcPadding, sizeof(RECT));
  43. ::ZeroMemory(&m_rcItem, sizeof(RECT));
  44. ::ZeroMemory(&m_rcPaint, sizeof(RECT));
  45. ::ZeroMemory(&m_rcBorderSize,sizeof(RECT));
  46. m_piFloatPercent.left = m_piFloatPercent.top = m_piFloatPercent.right = m_piFloatPercent.bottom = 0.0f;
  47. }
  48. CControlUI::~CControlUI()
  49. {
  50. if( OnDestroy ) OnDestroy(this);
  51. RemoveAllCustomAttribute();
  52. if( m_pManager != NULL ) m_pManager->ReapObjects(this);
  53. }
  54. CDuiString CControlUI::GetName() const
  55. {
  56. return m_sName;
  57. }
  58. void CControlUI::SetName(LPCTSTR pstrName)
  59. {
  60. m_sName = pstrName;
  61. }
  62. LPVOID CControlUI::GetInterface(LPCTSTR pstrName)
  63. {
  64. if( _tcsicmp(pstrName, DUI_CTR_CONTROL) == 0 ) return this;
  65. return NULL;
  66. }
  67. LPCTSTR CControlUI::GetClass() const
  68. {
  69. return _T("ControlUI");
  70. }
  71. UINT CControlUI::GetControlFlags() const
  72. {
  73. return 0;
  74. }
  75. bool CControlUI::Activate()
  76. {
  77. if( !IsVisible() ) return false;
  78. if( !IsEnabled() ) return false;
  79. return true;
  80. }
  81. CPaintManagerUI* CControlUI::GetManager() const
  82. {
  83. return m_pManager;
  84. }
  85. void CControlUI::SetManager(CPaintManagerUI* pManager, CControlUI* pParent, bool bInit)
  86. {
  87. m_pManager = pManager;
  88. m_pParent = pParent;
  89. if( bInit && m_pParent ) Init();
  90. }
  91. CControlUI* CControlUI::GetParent() const
  92. {
  93. return m_pParent;
  94. }
  95. bool CControlUI::SetTimer(UINT nTimerID, UINT nElapse)
  96. {
  97. if(m_pManager == NULL) return false;
  98. return m_pManager->SetTimer(this, nTimerID, nElapse);
  99. }
  100. void CControlUI::KillTimer(UINT nTimerID)
  101. {
  102. if(m_pManager == NULL) return;
  103. m_pManager->KillTimer(this, nTimerID);
  104. }
  105. CDuiString CControlUI::GetText() const
  106. {
  107. if (!IsResourceText()) return m_sText;
  108. return CResourceManager::GetInstance()->GetText(m_sText);
  109. }
  110. void CControlUI::SetText(LPCTSTR pstrText)
  111. {
  112. if( m_sText == pstrText ) return;
  113. m_sText = pstrText;
  114. // 解析xml换行符
  115. m_sText.Replace(_T("{\\n}"), _T("\n"));
  116. Invalidate();
  117. }
  118. bool CControlUI::IsResourceText() const
  119. {
  120. return m_bResourceText;
  121. }
  122. void CControlUI::SetResourceText(bool bResource)
  123. {
  124. if( m_bResourceText == bResource ) return;
  125. m_bResourceText = bResource;
  126. Invalidate();
  127. }
  128. bool CControlUI::IsDragEnabled() const
  129. {
  130. return m_bDragEnabled;
  131. }
  132. void CControlUI::SetDragEnable(bool bDrag)
  133. {
  134. m_bDragEnabled = bDrag;
  135. }
  136. bool CControlUI::IsDropEnabled() const
  137. {
  138. return m_bDropEnabled;
  139. }
  140. void CControlUI::SetDropEnable(bool bDrop)
  141. {
  142. m_bDropEnabled = bDrop;
  143. }
  144. bool CControlUI::IsRichEvent() const
  145. {
  146. return m_bRichEvent;
  147. }
  148. void CControlUI::SetRichEvent(bool bEnable)
  149. {
  150. m_bRichEvent = bEnable;
  151. }
  152. LPCTSTR CControlUI::GetGradient()
  153. {
  154. return m_sGradient;
  155. }
  156. void CControlUI::SetGradient(LPCTSTR pStrImage)
  157. {
  158. if( m_sGradient == pStrImage ) return;
  159. m_sGradient = pStrImage;
  160. Invalidate();
  161. }
  162. DWORD CControlUI::GetBkColor() const
  163. {
  164. return m_dwBackColor;
  165. }
  166. void CControlUI::SetBkColor(DWORD dwBackColor)
  167. {
  168. if( m_dwBackColor == dwBackColor ) return;
  169. m_dwBackColor = dwBackColor;
  170. Invalidate();
  171. }
  172. DWORD CControlUI::GetBkColor2() const
  173. {
  174. return m_dwBackColor2;
  175. }
  176. void CControlUI::SetBkColor2(DWORD dwBackColor)
  177. {
  178. if( m_dwBackColor2 == dwBackColor ) return;
  179. m_dwBackColor2 = dwBackColor;
  180. Invalidate();
  181. }
  182. DWORD CControlUI::GetBkColor3() const
  183. {
  184. return m_dwBackColor3;
  185. }
  186. void CControlUI::SetBkColor3(DWORD dwBackColor)
  187. {
  188. if( m_dwBackColor3 == dwBackColor ) return;
  189. m_dwBackColor3 = dwBackColor;
  190. Invalidate();
  191. }
  192. DWORD CControlUI::GetForeColor() const
  193. {
  194. return m_dwForeColor;
  195. }
  196. void CControlUI::SetForeColor(DWORD dwForeColor)
  197. {
  198. if( m_dwForeColor == dwForeColor ) return;
  199. m_dwForeColor = dwForeColor;
  200. Invalidate();
  201. }
  202. LPCTSTR CControlUI::GetBkImage()
  203. {
  204. return m_sBkImage;
  205. }
  206. void CControlUI::SetBkImage(LPCTSTR pStrImage)
  207. {
  208. if( m_sBkImage == pStrImage ) return;
  209. m_sBkImage = pStrImage;
  210. Invalidate();
  211. }
  212. LPCTSTR CControlUI::GetForeImage() const
  213. {
  214. return m_sForeImage;
  215. }
  216. void CControlUI::SetForeImage(LPCTSTR pStrImage)
  217. {
  218. if( m_sForeImage == pStrImage ) return;
  219. m_sForeImage = pStrImage;
  220. Invalidate();
  221. }
  222. DWORD CControlUI::GetBorderColor() const
  223. {
  224. return m_dwBorderColor;
  225. }
  226. void CControlUI::SetBorderColor(DWORD dwBorderColor)
  227. {
  228. if( m_dwBorderColor == dwBorderColor ) return;
  229. m_dwBorderColor = dwBorderColor;
  230. Invalidate();
  231. }
  232. DWORD CControlUI::GetFocusBorderColor() const
  233. {
  234. return m_dwFocusBorderColor;
  235. }
  236. void CControlUI::SetFocusBorderColor(DWORD dwBorderColor)
  237. {
  238. if( m_dwFocusBorderColor == dwBorderColor ) return;
  239. m_dwFocusBorderColor = dwBorderColor;
  240. Invalidate();
  241. }
  242. bool CControlUI::IsColorHSL() const
  243. {
  244. return m_bColorHSL;
  245. }
  246. void CControlUI::SetColorHSL(bool bColorHSL)
  247. {
  248. if( m_bColorHSL == bColorHSL ) return;
  249. m_bColorHSL = bColorHSL;
  250. Invalidate();
  251. }
  252. int CControlUI::GetBorderSize() const
  253. {
  254. if(m_pManager != NULL) return m_pManager->GetDPIObj()->Scale(m_nBorderSize);
  255. return m_nBorderSize;
  256. }
  257. void CControlUI::SetBorderSize(int nSize)
  258. {
  259. if( m_nBorderSize == nSize ) return;
  260. m_nBorderSize = nSize;
  261. Invalidate();
  262. }
  263. RECT CControlUI::GetBorderRectSize() const
  264. {
  265. RECT rcBorderSize = m_rcBorderSize;
  266. if(m_pManager != NULL) m_pManager->GetDPIObj()->Scale(&rcBorderSize);
  267. return rcBorderSize;
  268. }
  269. void CControlUI::SetBorderSize( RECT rc )
  270. {
  271. m_rcBorderSize = rc;
  272. Invalidate();
  273. }
  274. SIZE CControlUI::GetBorderRound() const
  275. {
  276. SIZE cxyBorderRound = m_cxyBorderRound;
  277. if(m_pManager != NULL) m_pManager->GetDPIObj()->Scale(&cxyBorderRound);
  278. return cxyBorderRound;
  279. }
  280. void CControlUI::SetBorderRound(SIZE cxyRound)
  281. {
  282. m_cxyBorderRound = cxyRound;
  283. Invalidate();
  284. }
  285. bool CControlUI::DrawImage(HDC hDC, LPCTSTR pStrImage, LPCTSTR pStrModify)
  286. {
  287. return CRenderEngine::DrawImageString(hDC, m_pManager, m_rcItem, m_rcPaint, pStrImage, pStrModify, m_instance);
  288. }
  289. const RECT& CControlUI::GetPos() const
  290. {
  291. return m_rcItem;
  292. }
  293. RECT CControlUI::GetRelativePos() const
  294. {
  295. CControlUI* pParent = GetParent();
  296. if( pParent != NULL ) {
  297. RECT rcParentPos = pParent->GetPos();
  298. CDuiRect rcRelativePos(m_rcItem);
  299. rcRelativePos.Offset(-rcParentPos.left, -rcParentPos.top);
  300. return rcRelativePos;
  301. }
  302. else {
  303. return CDuiRect(0, 0, 0, 0);
  304. }
  305. }
  306. RECT CControlUI::GetClientPos() const
  307. {
  308. return m_rcItem;
  309. }
  310. void CControlUI::SetPos(RECT rc, bool bNeedInvalidate)
  311. {
  312. if( rc.right < rc.left ) rc.right = rc.left;
  313. if( rc.bottom < rc.top ) rc.bottom = rc.top;
  314. CDuiRect invalidateRc = m_rcItem;
  315. if( ::IsRectEmpty(&invalidateRc) ) invalidateRc = rc;
  316. m_rcItem = rc;
  317. if( m_pManager == NULL ) return;
  318. if( !m_bSetPos ) {
  319. m_bSetPos = true;
  320. if( OnSize ) OnSize(this);
  321. m_bSetPos = false;
  322. }
  323. m_bUpdateNeeded = false;
  324. if( bNeedInvalidate && IsVisible() ) {
  325. invalidateRc.Join(m_rcItem);
  326. CControlUI* pParent = this;
  327. RECT rcTemp;
  328. RECT rcParent;
  329. while( pParent = pParent->GetParent() ) {
  330. if( !pParent->IsVisible() ) return;
  331. rcTemp = invalidateRc;
  332. rcParent = pParent->GetPos();
  333. if( !::IntersectRect(&invalidateRc, &rcTemp, &rcParent) ) return;
  334. }
  335. m_pManager->Invalidate(invalidateRc);
  336. }
  337. }
  338. void CControlUI::Move(SIZE szOffset, bool bNeedInvalidate)
  339. {
  340. m_cXY.cx += szOffset.cx;
  341. m_cXY.cy += szOffset.cy;
  342. NeedParentUpdate();
  343. }
  344. int CControlUI::GetWidth() const
  345. {
  346. return m_rcItem.right - m_rcItem.left;
  347. }
  348. int CControlUI::GetHeight() const
  349. {
  350. return m_rcItem.bottom - m_rcItem.top;
  351. }
  352. int CControlUI::GetX() const
  353. {
  354. return m_rcItem.left;
  355. }
  356. int CControlUI::GetY() const
  357. {
  358. return m_rcItem.top;
  359. }
  360. RECT CControlUI::GetPadding() const
  361. {
  362. RECT rcPadding = m_rcPadding;
  363. if(m_pManager != NULL) m_pManager->GetDPIObj()->Scale(&rcPadding);
  364. return rcPadding;
  365. }
  366. void CControlUI::SetPadding(RECT rcPadding)
  367. {
  368. m_rcPadding = rcPadding;
  369. NeedParentUpdate();
  370. }
  371. SIZE CControlUI::GetFixedXY() const
  372. {
  373. SIZE cXY = m_cXY;
  374. if(m_pManager != NULL) m_pManager->GetDPIObj()->Scale(&cXY);
  375. return cXY;
  376. }
  377. void CControlUI::SetFixedXY(SIZE szXY)
  378. {
  379. m_cXY.cx = szXY.cx;
  380. m_cXY.cy = szXY.cy;
  381. NeedParentUpdate();
  382. }
  383. SIZE CControlUI::GetFixedSize() const
  384. {
  385. SIZE cxyFixed = m_cxyFixed;
  386. if(m_pManager != NULL) m_pManager->GetDPIObj()->Scale(&cxyFixed);
  387. return cxyFixed;
  388. }
  389. int CControlUI::GetFixedWidth() const
  390. {
  391. SIZE cxyFixed = m_cxyFixed;
  392. if(m_pManager != NULL) m_pManager->GetDPIObj()->Scale(&cxyFixed);
  393. return cxyFixed.cx;
  394. }
  395. void CControlUI::SetFixedWidth(int cx)
  396. {
  397. if( cx < 0 ) return;
  398. m_cxyFixed.cx = cx;
  399. NeedParentUpdate();
  400. }
  401. int CControlUI::GetFixedHeight() const
  402. {
  403. SIZE cxyFixed = m_cxyFixed;
  404. if(m_pManager != NULL) m_pManager->GetDPIObj()->Scale(&cxyFixed);
  405. return cxyFixed.cy;
  406. }
  407. void CControlUI::SetFixedHeight(int cy)
  408. {
  409. if( cy < 0 ) return;
  410. m_cxyFixed.cy = cy;
  411. NeedParentUpdate();
  412. }
  413. int CControlUI::GetMinWidth() const
  414. {
  415. SIZE cxyMin = m_cxyMin;
  416. if(m_pManager != NULL) m_pManager->GetDPIObj()->Scale(&cxyMin);
  417. return cxyMin.cx;
  418. }
  419. void CControlUI::SetMinWidth(int cx)
  420. {
  421. if( m_cxyMin.cx == cx ) return;
  422. if( cx < 0 ) return;
  423. m_cxyMin.cx = cx;
  424. NeedParentUpdate();
  425. }
  426. int CControlUI::GetMaxWidth() const
  427. {
  428. SIZE cxyMax = m_cxyMax;
  429. if(m_pManager != NULL) m_pManager->GetDPIObj()->Scale(&cxyMax);
  430. return cxyMax.cx;
  431. }
  432. void CControlUI::SetMaxWidth(int cx)
  433. {
  434. if( m_cxyMax.cx == cx ) return;
  435. if( cx < 0 ) return;
  436. m_cxyMax.cx = cx;
  437. NeedParentUpdate();
  438. }
  439. int CControlUI::GetMinHeight() const
  440. {
  441. SIZE cxyMin = m_cxyMin;
  442. if(m_pManager != NULL) m_pManager->GetDPIObj()->Scale(&cxyMin);
  443. return cxyMin.cy;
  444. }
  445. void CControlUI::SetMinHeight(int cy)
  446. {
  447. if( m_cxyMin.cy == cy ) return;
  448. if( cy < 0 ) return;
  449. m_cxyMin.cy = cy;
  450. NeedParentUpdate();
  451. }
  452. int CControlUI::GetMaxHeight() const
  453. {
  454. SIZE cxyMax = m_cxyMax;
  455. if(m_pManager != NULL) m_pManager->GetDPIObj()->Scale(&cxyMax);
  456. return cxyMax.cy;
  457. }
  458. void CControlUI::SetMaxHeight(int cy)
  459. {
  460. if( m_cxyMax.cy == cy ) return;
  461. if( cy < 0 ) return;
  462. m_cxyMax.cy = cy;
  463. NeedParentUpdate();
  464. }
  465. TPercentInfo CControlUI::GetFloatPercent() const
  466. {
  467. return m_piFloatPercent;
  468. }
  469. void CControlUI::SetFloatPercent(TPercentInfo piFloatPercent)
  470. {
  471. m_piFloatPercent = piFloatPercent;
  472. NeedParentUpdate();
  473. }
  474. void CControlUI::SetFloatAlign(UINT uAlign)
  475. {
  476. m_uFloatAlign = uAlign;
  477. NeedParentUpdate();
  478. }
  479. UINT CControlUI::GetFloatAlign() const
  480. {
  481. return m_uFloatAlign;
  482. }
  483. CDuiString CControlUI::GetToolTip() const
  484. {
  485. if (!IsResourceText()) return m_sToolTip;
  486. return CResourceManager::GetInstance()->GetText(m_sToolTip);
  487. }
  488. void CControlUI::SetToolTip(LPCTSTR pstrText)
  489. {
  490. CDuiString strTemp(pstrText);
  491. strTemp.Replace(_T("<n>"),_T("\r\n"));
  492. m_sToolTip = strTemp;
  493. }
  494. void CControlUI::SetToolTipWidth( int nWidth )
  495. {
  496. m_nTooltipWidth = nWidth;
  497. }
  498. int CControlUI::GetToolTipWidth( void )
  499. {
  500. if(m_pManager != NULL) return m_pManager->GetDPIObj()->Scale(m_nTooltipWidth);
  501. return m_nTooltipWidth;
  502. }
  503. WORD CControlUI::GetCursor()
  504. {
  505. return m_wCursor;
  506. }
  507. void CControlUI::SetCursor(WORD wCursor)
  508. {
  509. m_wCursor = wCursor;
  510. Invalidate();
  511. }
  512. TCHAR CControlUI::GetShortcut() const
  513. {
  514. return m_chShortcut;
  515. }
  516. void CControlUI::SetShortcut(TCHAR ch)
  517. {
  518. m_chShortcut = ch;
  519. }
  520. bool CControlUI::IsContextMenuUsed() const
  521. {
  522. return m_bMenuUsed;
  523. }
  524. void CControlUI::SetContextMenuUsed(bool bMenuUsed)
  525. {
  526. m_bMenuUsed = bMenuUsed;
  527. }
  528. const CDuiString& CControlUI::GetUserData()
  529. {
  530. return m_sUserData;
  531. }
  532. void CControlUI::SetUserData(LPCTSTR pstrText)
  533. {
  534. m_sUserData = pstrText;
  535. }
  536. UINT_PTR CControlUI::GetTag() const
  537. {
  538. return m_pTag;
  539. }
  540. void CControlUI::SetTag(UINT_PTR pTag)
  541. {
  542. m_pTag = pTag;
  543. }
  544. bool CControlUI::IsVisible() const
  545. {
  546. return m_bVisible && m_bInternVisible;
  547. }
  548. void CControlUI::SetVisible(bool bVisible)
  549. {
  550. if( m_bVisible == bVisible ) return;
  551. bool v = IsVisible();
  552. m_bVisible = bVisible;
  553. if( m_bFocused ) m_bFocused = false;
  554. if (!bVisible && m_pManager && m_pManager->GetFocus() == this) {
  555. m_pManager->SetFocus(NULL) ;
  556. }
  557. if( IsVisible() != v ) {
  558. NeedParentUpdate();
  559. }
  560. }
  561. void CControlUI::SetInternVisible(bool bVisible)
  562. {
  563. m_bInternVisible = bVisible;
  564. if (!bVisible && m_pManager && m_pManager->GetFocus() == this) {
  565. m_pManager->SetFocus(NULL) ;
  566. }
  567. }
  568. bool CControlUI::IsEnabled() const
  569. {
  570. return m_bEnabled;
  571. }
  572. void CControlUI::SetEnabled(bool bEnabled)
  573. {
  574. if( m_bEnabled == bEnabled ) return;
  575. m_bEnabled = bEnabled;
  576. Invalidate();
  577. }
  578. bool CControlUI::IsMouseEnabled() const
  579. {
  580. return m_bMouseEnabled;
  581. }
  582. void CControlUI::SetMouseEnabled(bool bEnabled)
  583. {
  584. m_bMouseEnabled = bEnabled;
  585. }
  586. bool CControlUI::IsKeyboardEnabled() const
  587. {
  588. return m_bKeyboardEnabled ;
  589. }
  590. void CControlUI::SetKeyboardEnabled(bool bEnabled)
  591. {
  592. m_bKeyboardEnabled = bEnabled ;
  593. }
  594. bool CControlUI::IsFocused() const
  595. {
  596. return m_bFocused;
  597. }
  598. void CControlUI::SetFocus()
  599. {
  600. if( m_pManager != NULL ) m_pManager->SetFocus(this);
  601. }
  602. bool CControlUI::IsFloat() const
  603. {
  604. return m_bFloat;
  605. }
  606. void CControlUI::SetFloat(bool bFloat)
  607. {
  608. if( m_bFloat == bFloat ) return;
  609. m_bFloat = bFloat;
  610. NeedParentUpdate();
  611. }
  612. CControlUI* CControlUI::FindControl(FINDCONTROLPROC Proc, LPVOID pData, UINT uFlags)
  613. {
  614. if( (uFlags & UIFIND_VISIBLE) != 0 && !IsVisible() ) return NULL;
  615. if( (uFlags & UIFIND_ENABLED) != 0 && !IsEnabled() ) return NULL;
  616. if( (uFlags & UIFIND_HITTEST) != 0 && (!m_bMouseEnabled || !::PtInRect(&m_rcItem, * static_cast<LPPOINT>(pData))) ) return NULL;
  617. return Proc(this, pData);
  618. }
  619. void CControlUI::Invalidate()
  620. {
  621. if( !IsVisible() ) return;
  622. RECT invalidateRc = m_rcItem;
  623. CControlUI* pParent = this;
  624. RECT rcTemp;
  625. RECT rcParent;
  626. while( pParent = pParent->GetParent() )
  627. {
  628. rcTemp = invalidateRc;
  629. rcParent = pParent->GetPos();
  630. if( !::IntersectRect(&invalidateRc, &rcTemp, &rcParent) )
  631. {
  632. return;
  633. }
  634. }
  635. if( m_pManager != NULL ) m_pManager->Invalidate(invalidateRc);
  636. }
  637. bool CControlUI::IsUpdateNeeded() const
  638. {
  639. return m_bUpdateNeeded;
  640. }
  641. void CControlUI::NeedUpdate()
  642. {
  643. if( !IsVisible() ) return;
  644. m_bUpdateNeeded = true;
  645. Invalidate();
  646. if( m_pManager != NULL ) m_pManager->NeedUpdate();
  647. }
  648. void CControlUI::NeedParentUpdate()
  649. {
  650. if( GetParent() ) {
  651. GetParent()->NeedUpdate();
  652. GetParent()->Invalidate();
  653. }
  654. else {
  655. NeedUpdate();
  656. }
  657. if( m_pManager != NULL ) m_pManager->NeedUpdate();
  658. }
  659. DWORD CControlUI::GetAdjustColor(DWORD dwColor)
  660. {
  661. if( !m_bColorHSL ) return dwColor;
  662. short H, S, L;
  663. CPaintManagerUI::GetHSL(&H, &S, &L);
  664. return CRenderEngine::AdjustColor(dwColor, H, S, L);
  665. }
  666. void CControlUI::Init()
  667. {
  668. DoInit();
  669. if( OnInit ) OnInit(this);
  670. }
  671. void CControlUI::DoInit()
  672. {
  673. }
  674. void CControlUI::Event(TEventUI& event)
  675. {
  676. if( OnEvent(&event) ) DoEvent(event);
  677. }
  678. void CControlUI::DoEvent(TEventUI& event)
  679. {
  680. if( event.Type == UIEVENT_SETCURSOR ) {
  681. if( GetCursor() ) {
  682. ::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(GetCursor())));
  683. }
  684. else {
  685. ::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));
  686. }
  687. return;
  688. }
  689. if( event.Type == UIEVENT_SETFOCUS )
  690. {
  691. m_bFocused = true;
  692. Invalidate();
  693. return;
  694. }
  695. if( event.Type == UIEVENT_KILLFOCUS )
  696. {
  697. m_bFocused = false;
  698. Invalidate();
  699. return;
  700. }
  701. if( event.Type == UIEVENT_TIMER )
  702. {
  703. m_pManager->SendNotify(this, DUI_MSGTYPE_TIMER, event.wParam, event.lParam);
  704. return;
  705. }
  706. if( event.Type == UIEVENT_CONTEXTMENU )
  707. {
  708. if( IsContextMenuUsed() ) {
  709. m_pManager->SendNotify(this, DUI_MSGTYPE_MENU, event.wParam, event.lParam);
  710. return;
  711. }
  712. }
  713. if( m_pParent != NULL ) m_pParent->DoEvent(event);
  714. }
  715. void CControlUI::SetVirtualWnd(LPCTSTR pstrValue)
  716. {
  717. m_sVirtualWnd = pstrValue;
  718. m_pManager->UsedVirtualWnd(true);
  719. }
  720. CDuiString CControlUI::GetVirtualWnd() const
  721. {
  722. CDuiString str;
  723. if( !m_sVirtualWnd.IsEmpty() ){
  724. str = m_sVirtualWnd;
  725. }
  726. else{
  727. CControlUI* pParent = GetParent();
  728. if( pParent != NULL){
  729. str = pParent->GetVirtualWnd();
  730. }
  731. else{
  732. str = _T("");
  733. }
  734. }
  735. return str;
  736. }
  737. void CControlUI::AddCustomAttribute(LPCTSTR pstrName, LPCTSTR pstrAttr)
  738. {
  739. if( pstrName == NULL || pstrName[0] == _T('\0') || pstrAttr == NULL || pstrAttr[0] == _T('\0') ) return;
  740. if (m_mCustomAttrHash.Find(pstrName) == NULL) {
  741. CDuiString* pCostomAttr = new CDuiString(pstrAttr);
  742. if (pCostomAttr != NULL) {
  743. m_mCustomAttrHash.Set(pstrName, (LPVOID)pCostomAttr);
  744. }
  745. }
  746. }
  747. LPCTSTR CControlUI::GetCustomAttribute(LPCTSTR pstrName) const
  748. {
  749. if( pstrName == NULL || pstrName[0] == _T('\0') ) return NULL;
  750. CDuiString* pCostomAttr = static_cast<CDuiString*>(m_mCustomAttrHash.Find(pstrName));
  751. if( pCostomAttr ) return pCostomAttr->GetData();
  752. return NULL;
  753. }
  754. bool CControlUI::RemoveCustomAttribute(LPCTSTR pstrName)
  755. {
  756. if( pstrName == NULL || pstrName[0] == _T('\0') ) return NULL;
  757. CDuiString* pCostomAttr = static_cast<CDuiString*>(m_mCustomAttrHash.Find(pstrName));
  758. if( !pCostomAttr ) return false;
  759. delete pCostomAttr;
  760. return m_mCustomAttrHash.Remove(pstrName);
  761. }
  762. void CControlUI::RemoveAllCustomAttribute()
  763. {
  764. CDuiString* pCostomAttr;
  765. for( int i = 0; i< m_mCustomAttrHash.GetSize(); i++ ) {
  766. if(LPCTSTR key = m_mCustomAttrHash.GetAt(i)) {
  767. pCostomAttr = static_cast<CDuiString*>(m_mCustomAttrHash.Find(key));
  768. delete pCostomAttr;
  769. }
  770. }
  771. m_mCustomAttrHash.Resize();
  772. }
  773. void CControlUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
  774. {
  775. // 样式表
  776. if(m_pManager != NULL && _tcsicmp(pstrName, _T("style")) == 0) {
  777. LPCTSTR pStyle = m_pManager->GetStyle(pstrValue);
  778. if( pStyle != NULL) {
  779. ApplyAttributeList(pStyle);
  780. return;
  781. }
  782. }
  783. // 属性
  784. if( _tcsicmp(pstrName, _T("innerstyle")) == 0 ) {
  785. ApplyAttributeList(pstrValue);
  786. }
  787. else if( _tcsicmp(pstrName, _T("pos")) == 0 ) {
  788. RECT rcPos = { 0 };
  789. LPTSTR pstr = NULL;
  790. rcPos.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  791. rcPos.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  792. rcPos.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  793. rcPos.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  794. SIZE szXY = {rcPos.left >= 0 ? rcPos.left : rcPos.right, rcPos.top >= 0 ? rcPos.top : rcPos.bottom};
  795. SetFixedXY(szXY);
  796. SetFixedWidth(abs(rcPos.right - rcPos.left));
  797. SetFixedHeight(abs(rcPos.bottom - rcPos.top));
  798. }
  799. else if( _tcsicmp(pstrName, _T("float")) == 0 ) {
  800. CDuiString nValue = pstrValue;
  801. // 动态计算相对比例
  802. if(nValue.Find(',') < 0) {
  803. SetFloat(_tcsicmp(pstrValue, _T("true")) == 0);
  804. }
  805. else {
  806. TPercentInfo piFloatPercent = { 0 };
  807. LPTSTR pstr = NULL;
  808. piFloatPercent.left = _tcstod(pstrValue, &pstr); ASSERT(pstr);
  809. piFloatPercent.top = _tcstod(pstr + 1, &pstr); ASSERT(pstr);
  810. piFloatPercent.right = _tcstod(pstr + 1, &pstr); ASSERT(pstr);
  811. piFloatPercent.bottom = _tcstod(pstr + 1, &pstr); ASSERT(pstr);
  812. SetFloatPercent(piFloatPercent);
  813. SetFloat(true);
  814. }
  815. }
  816. else if( _tcsicmp(pstrName, _T("floatalign")) == 0) {
  817. UINT uAlign = GetFloatAlign();
  818. // 解析文字属性
  819. while( *pstrValue != _T('\0') ) {
  820. CDuiString sValue;
  821. while( *pstrValue == _T(',') || *pstrValue == _T(' ') ) pstrValue = ::CharNext(pstrValue);
  822. while( *pstrValue != _T('\0') && *pstrValue != _T(',') && *pstrValue != _T(' ') ) {
  823. LPTSTR pstrTemp = ::CharNext(pstrValue);
  824. while( pstrValue < pstrTemp) {
  825. sValue += *pstrValue++;
  826. }
  827. }
  828. if(sValue.CompareNoCase(_T("null")) == 0) {
  829. uAlign = 0;
  830. }
  831. if( sValue.CompareNoCase(_T("left")) == 0 ) {
  832. uAlign &= ~(DT_CENTER | DT_RIGHT);
  833. uAlign |= DT_LEFT;
  834. }
  835. else if( sValue.CompareNoCase(_T("center")) == 0 ) {
  836. uAlign &= ~(DT_LEFT | DT_RIGHT);
  837. uAlign |= DT_CENTER;
  838. }
  839. else if( sValue.CompareNoCase(_T("right")) == 0 ) {
  840. uAlign &= ~(DT_LEFT | DT_CENTER);
  841. uAlign |= DT_RIGHT;
  842. }
  843. else if( sValue.CompareNoCase(_T("top")) == 0 ) {
  844. uAlign &= ~(DT_BOTTOM | DT_VCENTER);
  845. uAlign |= DT_TOP;
  846. }
  847. else if( sValue.CompareNoCase(_T("vcenter")) == 0 ) {
  848. uAlign &= ~(DT_TOP | DT_BOTTOM);
  849. uAlign |= DT_VCENTER;
  850. }
  851. else if( sValue.CompareNoCase(_T("bottom")) == 0 ) {
  852. uAlign &= ~(DT_TOP | DT_VCENTER);
  853. uAlign |= DT_BOTTOM;
  854. }
  855. }
  856. SetFloatAlign(uAlign);
  857. }
  858. else if( _tcsicmp(pstrName, _T("padding")) == 0 ) {
  859. RECT rcPadding = { 0 };
  860. LPTSTR pstr = NULL;
  861. rcPadding.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  862. rcPadding.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  863. rcPadding.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  864. rcPadding.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  865. SetPadding(rcPadding);
  866. }
  867. else if( _tcsicmp(pstrName, _T("gradient")) == 0 ) SetGradient(pstrValue);
  868. else if( _tcsicmp(pstrName, _T("bkcolor")) == 0 || _tcsicmp(pstrName, _T("bkcolor1")) == 0 ) {
  869. while( *pstrValue > _T('\0') && *pstrValue <= _T(' ') ) pstrValue = ::CharNext(pstrValue);
  870. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  871. LPTSTR pstr = NULL;
  872. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  873. SetBkColor(clrColor);
  874. }
  875. else if( _tcsicmp(pstrName, _T("bkcolor2")) == 0 ) {
  876. while( *pstrValue > _T('\0') && *pstrValue <= _T(' ') ) pstrValue = ::CharNext(pstrValue);
  877. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  878. LPTSTR pstr = NULL;
  879. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  880. SetBkColor2(clrColor);
  881. }
  882. else if( _tcsicmp(pstrName, _T("bkcolor3")) == 0 ) {
  883. while( *pstrValue > _T('\0') && *pstrValue <= _T(' ') ) pstrValue = ::CharNext(pstrValue);
  884. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  885. LPTSTR pstr = NULL;
  886. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  887. SetBkColor3(clrColor);
  888. }
  889. else if( _tcsicmp(pstrName, _T("forecolor")) == 0 ) {
  890. while( *pstrValue > _T('\0') && *pstrValue <= _T(' ') ) pstrValue = ::CharNext(pstrValue);
  891. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  892. LPTSTR pstr = NULL;
  893. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  894. SetForeColor(clrColor);
  895. }
  896. else if( _tcsicmp(pstrName, _T("bordercolor")) == 0 ) {
  897. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  898. LPTSTR pstr = NULL;
  899. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  900. SetBorderColor(clrColor);
  901. }
  902. else if( _tcsicmp(pstrName, _T("focusbordercolor")) == 0 ) {
  903. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  904. LPTSTR pstr = NULL;
  905. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  906. SetFocusBorderColor(clrColor);
  907. }
  908. else if( _tcsicmp(pstrName, _T("colorhsl")) == 0 ) SetColorHSL(_tcsicmp(pstrValue, _T("true")) == 0);
  909. else if( _tcsicmp(pstrName, _T("bordersize")) == 0 ) {
  910. CDuiString nValue = pstrValue;
  911. if(nValue.Find(',') < 0) {
  912. SetBorderSize(_ttoi(pstrValue));
  913. RECT rcPadding = {0};
  914. SetBorderSize(rcPadding);
  915. }
  916. else {
  917. RECT rcPadding = { 0 };
  918. LPTSTR pstr = NULL;
  919. rcPadding.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  920. rcPadding.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  921. rcPadding.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  922. rcPadding.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  923. SetBorderSize(rcPadding);
  924. }
  925. }
  926. else if( _tcsicmp(pstrName, _T("leftbordersize")) == 0 ) SetLeftBorderSize(_ttoi(pstrValue));
  927. else if( _tcsicmp(pstrName, _T("topbordersize")) == 0 ) SetTopBorderSize(_ttoi(pstrValue));
  928. else if( _tcsicmp(pstrName, _T("rightbordersize")) == 0 ) SetRightBorderSize(_ttoi(pstrValue));
  929. else if( _tcsicmp(pstrName, _T("bottombordersize")) == 0 ) SetBottomBorderSize(_ttoi(pstrValue));
  930. else if( _tcsicmp(pstrName, _T("borderstyle")) == 0 ) SetBorderStyle(_ttoi(pstrValue));
  931. else if( _tcsicmp(pstrName, _T("borderround")) == 0 ) {
  932. SIZE cxyRound = { 0 };
  933. LPTSTR pstr = NULL;
  934. cxyRound.cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  935. cxyRound.cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  936. SetBorderRound(cxyRound);
  937. }
  938. else if( _tcsicmp(pstrName, _T("bkimage")) == 0 ) SetBkImage(pstrValue);
  939. else if( _tcsicmp(pstrName, _T("foreimage")) == 0 ) SetForeImage(pstrValue);
  940. else if( _tcsicmp(pstrName, _T("width")) == 0 ) SetFixedWidth(_ttoi(pstrValue));
  941. else if( _tcsicmp(pstrName, _T("height")) == 0 ) SetFixedHeight(_ttoi(pstrValue));
  942. else if( _tcsicmp(pstrName, _T("minwidth")) == 0 ) SetMinWidth(_ttoi(pstrValue));
  943. else if( _tcsicmp(pstrName, _T("minheight")) == 0 ) SetMinHeight(_ttoi(pstrValue));
  944. else if( _tcsicmp(pstrName, _T("maxwidth")) == 0 ) SetMaxWidth(_ttoi(pstrValue));
  945. else if( _tcsicmp(pstrName, _T("maxheight")) == 0 ) SetMaxHeight(_ttoi(pstrValue));
  946. else if( _tcsicmp(pstrName, _T("name")) == 0 ) SetName(pstrValue);
  947. else if( _tcsicmp(pstrName, _T("drag")) == 0 ) SetDragEnable(_tcsicmp(pstrValue, _T("true")) == 0);
  948. else if( _tcsicmp(pstrName, _T("drop")) == 0 ) SetDropEnable(_tcsicmp(pstrValue, _T("true")) == 0);
  949. else if( _tcsicmp(pstrName, _T("resourcetext")) == 0 ) SetResourceText(_tcsicmp(pstrValue, _T("true")) == 0);
  950. else if( _tcsicmp(pstrName, _T("richevent")) == 0 ) SetRichEvent(_tcsicmp(pstrValue, _T("true")) == 0);
  951. else if( _tcsicmp(pstrName, _T("text")) == 0 ) SetText(pstrValue);
  952. else if( _tcsicmp(pstrName, _T("tooltip")) == 0 ) SetToolTip(pstrValue);
  953. else if( _tcsicmp(pstrName, _T("userdata")) == 0 ) SetUserData(pstrValue);
  954. else if( _tcsicmp(pstrName, _T("enabled")) == 0 ) SetEnabled(_tcsicmp(pstrValue, _T("true")) == 0);
  955. else if( _tcsicmp(pstrName, _T("mouse")) == 0 ) SetMouseEnabled(_tcsicmp(pstrValue, _T("true")) == 0);
  956. else if( _tcsicmp(pstrName, _T("keyboard")) == 0 ) SetKeyboardEnabled(_tcsicmp(pstrValue, _T("true")) == 0);
  957. else if( _tcsicmp(pstrName, _T("visible")) == 0 ) SetVisible(_tcsicmp(pstrValue, _T("true")) == 0);
  958. else if( _tcsicmp(pstrName, _T("float")) == 0 ) SetFloat(_tcsicmp(pstrValue, _T("true")) == 0);
  959. else if( _tcsicmp(pstrName, _T("shortcut")) == 0 ) SetShortcut(pstrValue[0]);
  960. else if( _tcsicmp(pstrName, _T("menu")) == 0 ) SetContextMenuUsed(_tcsicmp(pstrValue, _T("true")) == 0);
  961. else if( _tcsicmp(pstrName, _T("cursor")) == 0 && pstrValue) {
  962. if( _tcsicmp(pstrValue, _T("arrow")) == 0 ) SetCursor(DUI_ARROW);
  963. else if( _tcsicmp(pstrValue, _T("ibeam")) == 0 ) SetCursor(DUI_IBEAM);
  964. else if( _tcsicmp(pstrValue, _T("wait")) == 0 ) SetCursor(DUI_WAIT);
  965. else if( _tcsicmp(pstrValue, _T("cross")) == 0 ) SetCursor(DUI_CROSS);
  966. else if( _tcsicmp(pstrValue, _T("uparrow")) == 0 ) SetCursor(DUI_UPARROW);
  967. else if( _tcsicmp(pstrValue, _T("size")) == 0 ) SetCursor(DUI_SIZE);
  968. else if( _tcsicmp(pstrValue, _T("icon")) == 0 ) SetCursor(DUI_ICON);
  969. else if( _tcsicmp(pstrValue, _T("sizenwse")) == 0 ) SetCursor(DUI_SIZENWSE);
  970. else if( _tcsicmp(pstrValue, _T("sizenesw")) == 0 ) SetCursor(DUI_SIZENESW);
  971. else if( _tcsicmp(pstrValue, _T("sizewe")) == 0 ) SetCursor(DUI_SIZEWE);
  972. else if( _tcsicmp(pstrValue, _T("sizens")) == 0 ) SetCursor(DUI_SIZENS);
  973. else if( _tcsicmp(pstrValue, _T("sizeall")) == 0 ) SetCursor(DUI_SIZEALL);
  974. else if( _tcsicmp(pstrValue, _T("no")) == 0 ) SetCursor(DUI_NO);
  975. else if( _tcsicmp(pstrValue, _T("hand")) == 0 ) SetCursor(DUI_HAND);
  976. }
  977. else if( _tcsicmp(pstrName, _T("virtualwnd")) == 0 ) SetVirtualWnd(pstrValue);
  978. else {
  979. AddCustomAttribute(pstrName, pstrValue);
  980. }
  981. }
  982. CControlUI* CControlUI::ApplyAttributeList(LPCTSTR pstrValue)
  983. {
  984. // 解析样式表
  985. if(m_pManager != NULL) {
  986. LPCTSTR pStyle = m_pManager->GetStyle(pstrValue);
  987. if( pStyle != NULL) {
  988. return ApplyAttributeList(pStyle);
  989. }
  990. }
  991. CDuiString sXmlData = pstrValue;
  992. sXmlData.Replace(_T("&quot;"), _T("\""));
  993. sXmlData.Replace(_T("\r"), _T(" "));
  994. sXmlData.Replace(_T("\n"), _T(" "));
  995. sXmlData.Replace(_T("\t"), _T(" "));
  996. sXmlData.Trim();
  997. LPCTSTR pstrList = sXmlData.GetData();
  998. // 解析样式属性
  999. CDuiString sItem;
  1000. CDuiString sValue;
  1001. while( *pstrList != _T('\0') ) {
  1002. sItem.Empty();
  1003. sValue.Empty();
  1004. while (*pstrList != _T('\0') && (*pstrList == _T(' ')) )
  1005. {
  1006. pstrList++;
  1007. }
  1008. while( *pstrList != _T('\0') && *pstrList != _T('=') ) {
  1009. LPTSTR pstrTemp = ::CharNext(pstrList);
  1010. while( pstrList < pstrTemp) {
  1011. sItem += *pstrList++;
  1012. }
  1013. }
  1014. ASSERT( *pstrList == _T('=') );
  1015. if( *pstrList++ != _T('=') ) return this;
  1016. ASSERT( *pstrList == _T('\"') );
  1017. if( *pstrList++ != _T('\"') ) return this;
  1018. while( *pstrList != _T('\0') && *pstrList != _T('\"') ) {
  1019. LPTSTR pstrTemp = ::CharNext(pstrList);
  1020. while( pstrList < pstrTemp) {
  1021. sValue += *pstrList++;
  1022. }
  1023. }
  1024. ASSERT( *pstrList == _T('\"') );
  1025. if( *pstrList++ != _T('\"') ) return this;
  1026. SetAttribute(sItem, sValue);
  1027. if( *pstrList != _T(' ') && *pstrList != _T(',') )
  1028. {
  1029. return this;
  1030. }else
  1031. {
  1032. ++pstrList;
  1033. }
  1034. }
  1035. return this;
  1036. }
  1037. SIZE CControlUI::EstimateSize(SIZE szAvailable)
  1038. {
  1039. if(m_pManager != NULL)
  1040. return m_pManager->GetDPIObj()->Scale(m_cxyFixed);
  1041. return m_cxyFixed;
  1042. }
  1043. bool CControlUI::Paint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl)
  1044. {
  1045. if (pStopControl == this) return false;
  1046. if( !::IntersectRect(&m_rcPaint, &rcPaint, &m_rcItem) ) return true;
  1047. if (!DoPaint(hDC, m_rcPaint, pStopControl)) return false;
  1048. return true;
  1049. }
  1050. bool CControlUI::DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl)
  1051. {
  1052. // 绘制循序:背景颜色->背景图->状态图->文本->边框
  1053. SIZE cxyBorderRound = GetBorderRound();
  1054. RECT rcBorderSize = GetBorderRectSize();
  1055. if( cxyBorderRound.cx > 0 || cxyBorderRound.cy > 0 ) {
  1056. CRenderClip roundClip;
  1057. CRenderClip::GenerateRoundClip(hDC, m_rcPaint, m_rcItem, cxyBorderRound.cx, cxyBorderRound.cy, roundClip);
  1058. PaintBkColor(hDC);
  1059. PaintBkImage(hDC);
  1060. PaintStatusImage(hDC);
  1061. PaintForeColor(hDC);
  1062. PaintForeImage(hDC);
  1063. PaintText(hDC);
  1064. PaintBorder(hDC);
  1065. }
  1066. else {
  1067. PaintBkColor(hDC);
  1068. PaintBkImage(hDC);
  1069. PaintStatusImage(hDC);
  1070. PaintForeColor(hDC);
  1071. PaintForeImage(hDC);
  1072. PaintText(hDC);
  1073. PaintBorder(hDC);
  1074. }
  1075. return true;
  1076. }
  1077. void CControlUI::PaintBkColor(HDC hDC)
  1078. {
  1079. if( m_dwBackColor != 0 ) {
  1080. bool bVer = (m_sGradient.CompareNoCase(_T("hor")) != 0);
  1081. if( m_dwBackColor2 != 0 ) {
  1082. if( m_dwBackColor3 != 0 ) {
  1083. RECT rc = m_rcItem;
  1084. rc.bottom = (rc.bottom + rc.top) / 2;
  1085. CRenderEngine::DrawGradient(hDC, rc, GetAdjustColor(m_dwBackColor), GetAdjustColor(m_dwBackColor2), bVer, 8);
  1086. rc.top = rc.bottom;
  1087. rc.bottom = m_rcItem.bottom;
  1088. CRenderEngine::DrawGradient(hDC, rc, GetAdjustColor(m_dwBackColor2), GetAdjustColor(m_dwBackColor3), bVer, 8);
  1089. }
  1090. else {
  1091. CRenderEngine::DrawGradient(hDC, m_rcItem, GetAdjustColor(m_dwBackColor), GetAdjustColor(m_dwBackColor2), bVer, 16);
  1092. }
  1093. }
  1094. else if( m_dwBackColor >= 0xFF000000 ) CRenderEngine::DrawColor(hDC, m_rcPaint, GetAdjustColor(m_dwBackColor));
  1095. else CRenderEngine::DrawColor(hDC, m_rcItem, GetAdjustColor(m_dwBackColor));
  1096. }
  1097. }
  1098. void CControlUI::PaintBkImage(HDC hDC)
  1099. {
  1100. if( m_sBkImage.IsEmpty() ) return;
  1101. if( !DrawImage(hDC, (LPCTSTR)m_sBkImage) ) {}
  1102. }
  1103. void CControlUI::PaintStatusImage(HDC hDC)
  1104. {
  1105. return;
  1106. }
  1107. void CControlUI::PaintForeColor(HDC hDC)
  1108. {
  1109. CRenderEngine::DrawColor(hDC, m_rcItem, GetAdjustColor(m_dwForeColor));
  1110. }
  1111. void CControlUI::PaintForeImage(HDC hDC)
  1112. {
  1113. if( m_sForeImage.IsEmpty() ) return;
  1114. DrawImage(hDC, (LPCTSTR)m_sForeImage);
  1115. }
  1116. void CControlUI::PaintText(HDC hDC)
  1117. {
  1118. return;
  1119. }
  1120. void CControlUI::PaintBorder(HDC hDC)
  1121. {
  1122. int nBorderSize = GetBorderSize();
  1123. SIZE cxyBorderRound = GetBorderRound();
  1124. RECT rcBorderSize = GetBorderRectSize();
  1125. if(m_dwBorderColor != 0 || m_dwFocusBorderColor != 0) {
  1126. //画圆角边框
  1127. if(nBorderSize > 0 && ( cxyBorderRound.cx > 0 || cxyBorderRound.cy > 0 )) {
  1128. if (IsFocused() && m_dwFocusBorderColor != 0)
  1129. CRenderEngine::DrawRoundRect(hDC, m_rcItem, nBorderSize, cxyBorderRound.cx, cxyBorderRound.cy, GetAdjustColor(m_dwFocusBorderColor), m_nBorderStyle);
  1130. else
  1131. CRenderEngine::DrawRoundRect(hDC, m_rcItem, nBorderSize, cxyBorderRound.cx, cxyBorderRound.cy, GetAdjustColor(m_dwBorderColor), m_nBorderStyle);
  1132. }
  1133. else {
  1134. if (IsFocused() && m_dwFocusBorderColor != 0 && nBorderSize > 0) {
  1135. CRenderEngine::DrawRect(hDC, m_rcItem, nBorderSize, GetAdjustColor(m_dwFocusBorderColor), m_nBorderStyle);
  1136. }
  1137. else if(rcBorderSize.left > 0 || rcBorderSize.top > 0 || rcBorderSize.right > 0 || rcBorderSize.bottom > 0) {
  1138. RECT rcBorder;
  1139. if(rcBorderSize.left > 0){
  1140. rcBorder = m_rcItem;
  1141. rcBorder.right = rcBorder.left;
  1142. CRenderEngine::DrawLine(hDC,rcBorder,rcBorderSize.left,GetAdjustColor(m_dwBorderColor),m_nBorderStyle);
  1143. }
  1144. if(rcBorderSize.top > 0){
  1145. rcBorder = m_rcItem;
  1146. rcBorder.bottom = rcBorder.top;
  1147. CRenderEngine::DrawLine(hDC,rcBorder,rcBorderSize.top,GetAdjustColor(m_dwBorderColor),m_nBorderStyle);
  1148. }
  1149. if(rcBorderSize.right > 0){
  1150. rcBorder = m_rcItem;
  1151. rcBorder.right -= 1;
  1152. rcBorder.left = rcBorder.right;
  1153. CRenderEngine::DrawLine(hDC,rcBorder,rcBorderSize.right,GetAdjustColor(m_dwBorderColor),m_nBorderStyle);
  1154. }
  1155. if(rcBorderSize.bottom > 0){
  1156. rcBorder = m_rcItem;
  1157. rcBorder.bottom -= 1;
  1158. rcBorder.top = rcBorder.bottom;
  1159. CRenderEngine::DrawLine(hDC,rcBorder,rcBorderSize.bottom,GetAdjustColor(m_dwBorderColor),m_nBorderStyle);
  1160. }
  1161. }
  1162. else if(nBorderSize > 0) {
  1163. CRenderEngine::DrawRect(hDC, m_rcItem, nBorderSize, GetAdjustColor(m_dwBorderColor), m_nBorderStyle);
  1164. }
  1165. }
  1166. }
  1167. }
  1168. void CControlUI::DoPostPaint(HDC hDC, const RECT& rcPaint)
  1169. {
  1170. return;
  1171. }
  1172. int CControlUI::GetLeftBorderSize() const
  1173. {
  1174. RECT rcBorderSize = m_rcBorderSize;
  1175. if(m_pManager != NULL) m_pManager->GetDPIObj()->Scale(&rcBorderSize);
  1176. return rcBorderSize.left;
  1177. }
  1178. void CControlUI::SetLeftBorderSize( int nSize )
  1179. {
  1180. m_rcBorderSize.left = nSize;
  1181. Invalidate();
  1182. }
  1183. int CControlUI::GetTopBorderSize() const
  1184. {
  1185. RECT rcBorderSize = m_rcBorderSize;
  1186. if(m_pManager != NULL) m_pManager->GetDPIObj()->Scale(&rcBorderSize);
  1187. return rcBorderSize.top;
  1188. }
  1189. void CControlUI::SetTopBorderSize( int nSize )
  1190. {
  1191. m_rcBorderSize.top = nSize;
  1192. Invalidate();
  1193. }
  1194. int CControlUI::GetRightBorderSize() const
  1195. {
  1196. RECT rcBorderSize = m_rcBorderSize;
  1197. if(m_pManager != NULL) m_pManager->GetDPIObj()->Scale(&rcBorderSize);
  1198. return rcBorderSize.right;
  1199. }
  1200. void CControlUI::SetRightBorderSize( int nSize )
  1201. {
  1202. m_rcBorderSize.right = nSize;
  1203. Invalidate();
  1204. }
  1205. int CControlUI::GetBottomBorderSize() const
  1206. {
  1207. RECT rcBorderSize = m_rcBorderSize;
  1208. if(m_pManager != NULL) m_pManager->GetDPIObj()->Scale(&rcBorderSize);
  1209. return rcBorderSize.bottom;
  1210. }
  1211. void CControlUI::SetBottomBorderSize( int nSize )
  1212. {
  1213. m_rcBorderSize.bottom = nSize;
  1214. Invalidate();
  1215. }
  1216. int CControlUI::GetBorderStyle() const
  1217. {
  1218. return m_nBorderStyle;
  1219. }
  1220. void CControlUI::SetBorderStyle( int nStyle )
  1221. {
  1222. m_nBorderStyle = nStyle;
  1223. Invalidate();
  1224. }
  1225. } // namespace DuiLib