UIControl.cpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  1. #include "StdAfx.h"
  2. namespace DuiLib {
  3. CControlUI::CControlUI() :
  4. m_pManager(NULL),
  5. m_pParent(NULL),
  6. m_pCover(NULL),
  7. m_bUpdateNeeded(true),
  8. m_bMenuUsed(false),
  9. m_bAsyncNotify(false),
  10. m_bVisible(true),
  11. m_bInternVisible(true),
  12. m_bFocused(false),
  13. m_bEnabled(true),
  14. m_bMouseEnabled(true),
  15. m_bKeyboardEnabled(true),
  16. m_bFloat(false),
  17. m_bSetPos(false),
  18. m_chShortcut('\0'),
  19. m_pTag(NULL),
  20. m_dwBackColor(0),
  21. m_dwBackColor2(0),
  22. m_dwBackColor3(0),
  23. m_dwBorderColor(0),
  24. m_dwFocusBorderColor(0),
  25. m_bColorHSL(false),
  26. m_nBorderStyle(PS_SOLID),
  27. m_nTooltipWidth(300)
  28. {
  29. m_cXY.cx = m_cXY.cy = 0;
  30. m_cxyFixed.cx = m_cxyFixed.cy = 0;
  31. m_cxyMin.cx = m_cxyMin.cy = 0;
  32. m_cxyMax.cx = m_cxyMax.cy = 9999;
  33. m_cxyBorderRound.cx = m_cxyBorderRound.cy = 0;
  34. ::ZeroMemory(&m_rcPadding, sizeof(RECT));
  35. ::ZeroMemory(&m_rcItem, sizeof(RECT));
  36. ::ZeroMemory(&m_rcPaint, sizeof(RECT));
  37. ::ZeroMemory(&m_rcBorderSize,sizeof(RECT));
  38. m_piFloatPercent.left = m_piFloatPercent.top = m_piFloatPercent.right = m_piFloatPercent.bottom = 0.0f;
  39. }
  40. CControlUI::~CControlUI()
  41. {
  42. if( m_pCover != NULL ) {
  43. m_pCover->Delete();
  44. m_pCover = NULL;
  45. }
  46. RemoveAllCustomAttribute();
  47. if( OnDestroy ) OnDestroy(this);
  48. if( m_pManager != NULL ) m_pManager->ReapObjects(this);
  49. }
  50. void CControlUI::Delete()
  51. {
  52. if (m_pManager) m_pManager->RemoveMouseLeaveNeeded(this);
  53. delete this;
  54. }
  55. CDuiString CControlUI::GetName() const
  56. {
  57. return m_sName;
  58. }
  59. void CControlUI::SetName(LPCTSTR pstrName)
  60. {
  61. if (m_sName != pstrName) {
  62. m_sName = pstrName;
  63. if (m_pManager != NULL) m_pManager->RenameControl(this, pstrName);
  64. }
  65. }
  66. LPVOID CControlUI::GetInterface(LPCTSTR pstrName)
  67. {
  68. if( _tcscmp(pstrName, DUI_CTR_CONTROL) == 0 ) return this;
  69. return NULL;
  70. }
  71. LPCTSTR CControlUI::GetClass() const
  72. {
  73. return DUI_CTR_CONTROL;
  74. }
  75. UINT CControlUI::GetControlFlags() const
  76. {
  77. return 0;
  78. }
  79. HWND CControlUI::GetNativeWindow() const
  80. {
  81. return NULL;
  82. }
  83. bool CControlUI::Activate()
  84. {
  85. if( !IsVisible() ) return false;
  86. if( !IsEnabled() ) return false;
  87. return true;
  88. }
  89. CPaintManagerUI* CControlUI::GetManager() const
  90. {
  91. return m_pManager;
  92. }
  93. void CControlUI::SetManager(CPaintManagerUI* pManager, CControlUI* pParent, bool bInit)
  94. {
  95. if( m_pCover != NULL ) m_pCover->SetManager(pManager, this, bInit);
  96. m_pManager = pManager;
  97. m_pParent = pParent;
  98. if( bInit && m_pParent ) Init();
  99. }
  100. CControlUI* CControlUI::GetParent() const
  101. {
  102. return m_pParent;
  103. }
  104. CControlUI* CControlUI::GetCover() const
  105. {
  106. return m_pCover;
  107. }
  108. void CControlUI::SetCover(CControlUI *pControl)
  109. {
  110. if( m_pCover == pControl ) return;
  111. if( m_pCover != NULL ) m_pCover->Delete();
  112. m_pCover = pControl;
  113. if( m_pCover != NULL ) {
  114. m_pManager->InitControls(m_pCover, this);
  115. if( IsVisible() ) NeedUpdate();
  116. else pControl->SetInternVisible(false);
  117. }
  118. }
  119. CDuiString CControlUI::GetText() const
  120. {
  121. return m_sText;
  122. }
  123. void CControlUI::SetText(LPCTSTR pstrText)
  124. {
  125. if( m_sText == pstrText ) return;
  126. m_sText = pstrText;
  127. Invalidate();
  128. }
  129. DWORD CControlUI::GetBkColor() const
  130. {
  131. return m_dwBackColor;
  132. }
  133. void CControlUI::SetBkColor(DWORD dwBackColor)
  134. {
  135. if( m_dwBackColor == dwBackColor ) return;
  136. m_dwBackColor = dwBackColor;
  137. Invalidate();
  138. }
  139. DWORD CControlUI::GetBkColor2() const
  140. {
  141. return m_dwBackColor2;
  142. }
  143. void CControlUI::SetBkColor2(DWORD dwBackColor)
  144. {
  145. if( m_dwBackColor2 == dwBackColor ) return;
  146. m_dwBackColor2 = dwBackColor;
  147. Invalidate();
  148. }
  149. DWORD CControlUI::GetBkColor3() const
  150. {
  151. return m_dwBackColor3;
  152. }
  153. void CControlUI::SetBkColor3(DWORD dwBackColor)
  154. {
  155. if( m_dwBackColor3 == dwBackColor ) return;
  156. m_dwBackColor3 = dwBackColor;
  157. Invalidate();
  158. }
  159. LPCTSTR CControlUI::GetBkImage()
  160. {
  161. return m_diBk.sDrawString;
  162. }
  163. void CControlUI::SetBkImage(LPCTSTR pStrImage)
  164. {
  165. if( m_diBk.sDrawString == pStrImage && m_diBk.pImageInfo != NULL ) return;
  166. m_diBk.Clear();
  167. m_diBk.sDrawString = pStrImage;
  168. DrawImage(NULL, m_diBk);
  169. if( m_bFloat && m_cxyFixed.cx == 0 && m_cxyFixed.cy == 0 && m_diBk.pImageInfo ) {
  170. m_cxyFixed.cx = m_diBk.pImageInfo->nX;
  171. m_cxyFixed.cy = m_diBk.pImageInfo->nY;
  172. }
  173. Invalidate();
  174. }
  175. DWORD CControlUI::GetBorderColor() const
  176. {
  177. return m_dwBorderColor;
  178. }
  179. void CControlUI::SetBorderColor(DWORD dwBorderColor)
  180. {
  181. if( m_dwBorderColor == dwBorderColor ) return;
  182. m_dwBorderColor = dwBorderColor;
  183. Invalidate();
  184. }
  185. DWORD CControlUI::GetFocusBorderColor() const
  186. {
  187. return m_dwFocusBorderColor;
  188. }
  189. void CControlUI::SetFocusBorderColor(DWORD dwBorderColor)
  190. {
  191. if( m_dwFocusBorderColor == dwBorderColor ) return;
  192. m_dwFocusBorderColor = dwBorderColor;
  193. Invalidate();
  194. }
  195. bool CControlUI::IsColorHSL() const
  196. {
  197. return m_bColorHSL;
  198. }
  199. void CControlUI::SetColorHSL(bool bColorHSL)
  200. {
  201. if( m_bColorHSL == bColorHSL ) return;
  202. m_bColorHSL = bColorHSL;
  203. Invalidate();
  204. }
  205. RECT CControlUI::GetBorderSize() const
  206. {
  207. return m_rcBorderSize;
  208. }
  209. void CControlUI::SetBorderSize( RECT rc )
  210. {
  211. m_rcBorderSize = rc;
  212. Invalidate();
  213. }
  214. void CControlUI::SetBorderSize(int iSize)
  215. {
  216. m_rcBorderSize.left = m_rcBorderSize.top = m_rcBorderSize.right = m_rcBorderSize.bottom = iSize;
  217. Invalidate();
  218. }
  219. SIZE CControlUI::GetBorderRound() const
  220. {
  221. return m_cxyBorderRound;
  222. }
  223. void CControlUI::SetBorderRound(SIZE cxyRound)
  224. {
  225. m_cxyBorderRound = cxyRound;
  226. Invalidate();
  227. }
  228. bool CControlUI::DrawImage(HDC hDC, TDrawInfo& drawInfo)
  229. {
  230. return CRenderEngine::DrawImage(hDC, m_pManager, m_rcItem, m_rcPaint, drawInfo);
  231. }
  232. const RECT& CControlUI::GetPos() const
  233. {
  234. return m_rcItem;
  235. }
  236. RECT CControlUI::GetRelativePos() const
  237. {
  238. CControlUI* pParent = GetParent();
  239. if( pParent != NULL ) {
  240. RECT rcParentPos = pParent->GetPos();
  241. CDuiRect rcRelativePos(m_rcItem);
  242. rcRelativePos.Offset(-rcParentPos.left, -rcParentPos.top);
  243. return rcRelativePos;
  244. }
  245. else {
  246. return CDuiRect(0, 0, 0, 0);
  247. }
  248. }
  249. RECT CControlUI::GetClientPos() const
  250. {
  251. return m_rcItem;
  252. }
  253. void CControlUI::SetPos(RECT rc, bool bNeedInvalidate)
  254. {
  255. if( rc.right < rc.left ) rc.right = rc.left;
  256. if( rc.bottom < rc.top ) rc.bottom = rc.top;
  257. CDuiRect invalidateRc = m_rcItem;
  258. if( ::IsRectEmpty(&invalidateRc) ) invalidateRc = rc;
  259. if( m_bFloat ) {
  260. CControlUI* pParent = GetParent();
  261. if( pParent != NULL ) {
  262. RECT rcParentPos = pParent->GetPos();
  263. RECT rcCtrl = {rcParentPos.left + rc.left, rcParentPos.top + rc.top,
  264. rcParentPos.left + rc.right, rcParentPos.top + rc.bottom};
  265. m_rcItem = rcCtrl;
  266. LONG width = rcParentPos.right - rcParentPos.left;
  267. LONG height = rcParentPos.bottom - rcParentPos.top;
  268. RECT rcPercent = {(LONG)(width*m_piFloatPercent.left), (LONG)(height*m_piFloatPercent.top),
  269. (LONG)(width*m_piFloatPercent.right), (LONG)(height*m_piFloatPercent.bottom)};
  270. m_cXY.cx = rc.left - rcPercent.left;
  271. m_cXY.cy = rc.top - rcPercent.top;
  272. m_cxyFixed.cx = rc.right - rcPercent.right - m_cXY.cx;
  273. m_cxyFixed.cy = rc.bottom - rcPercent.bottom - m_cXY.cy;
  274. }
  275. }
  276. else {
  277. m_rcItem = rc;
  278. }
  279. if( m_pManager == NULL ) return;
  280. if( !m_bSetPos ) {
  281. m_bSetPos = true;
  282. if( OnSize ) OnSize(this);
  283. m_bSetPos = false;
  284. }
  285. m_bUpdateNeeded = false;
  286. if( bNeedInvalidate && IsVisible() ) {
  287. invalidateRc.Join(m_rcItem);
  288. CControlUI* pParent = this;
  289. RECT rcTemp;
  290. RECT rcParent;
  291. while( pParent = pParent->GetParent() ) {
  292. if( !pParent->IsVisible() ) return;
  293. rcTemp = invalidateRc;
  294. rcParent = pParent->GetPos();
  295. if( !::IntersectRect(&invalidateRc, &rcTemp, &rcParent) ) return;
  296. }
  297. m_pManager->Invalidate(invalidateRc);
  298. }
  299. if( m_pCover != NULL && m_pCover->IsVisible() ) {
  300. if( m_pCover->IsFloat() ) {
  301. SIZE szXY = m_pCover->GetFixedXY();
  302. SIZE sz = {m_pCover->GetFixedWidth(), m_pCover->GetFixedHeight()};
  303. TPercentInfo rcPercent = m_pCover->GetFloatPercent();
  304. LONG width = m_rcItem.right - m_rcItem.left;
  305. LONG height = m_rcItem.bottom - m_rcItem.top;
  306. RECT rcCtrl = { 0 };
  307. rcCtrl.left = (LONG)(width*rcPercent.left) + szXY.cx;
  308. rcCtrl.top = (LONG)(height*rcPercent.top) + szXY.cy;
  309. rcCtrl.right = (LONG)(width*rcPercent.right) + szXY.cx + sz.cx;
  310. rcCtrl.bottom = (LONG)(height*rcPercent.bottom) + szXY.cy + sz.cy;
  311. m_pCover->SetPos(rcCtrl, false);
  312. }
  313. else {
  314. SIZE sz = { rc.right - rc.left, rc.bottom - rc.top };
  315. if( sz.cx < m_pCover->GetMinWidth() ) sz.cx = m_pCover->GetMinWidth();
  316. if( sz.cx > m_pCover->GetMaxWidth() ) sz.cx = m_pCover->GetMaxWidth();
  317. if( sz.cy < m_pCover->GetMinHeight() ) sz.cy = m_pCover->GetMinHeight();
  318. if( sz.cy > m_pCover->GetMaxHeight() ) sz.cy = m_pCover->GetMaxHeight();
  319. RECT rcCtrl = { rc.left, rc.top, rc.left + sz.cx, rc.top + sz.cy };
  320. m_pCover->SetPos(rcCtrl, false);
  321. }
  322. }
  323. }
  324. void CControlUI::Move(SIZE szOffset, bool bNeedInvalidate)
  325. {
  326. CDuiRect invalidateRc = m_rcItem;
  327. m_rcItem.left += szOffset.cx;
  328. m_rcItem.top += szOffset.cy;
  329. m_rcItem.right += szOffset.cx;
  330. m_rcItem.bottom += szOffset.cy;
  331. if( bNeedInvalidate && m_pManager == NULL && IsVisible() ) {
  332. invalidateRc.Join(m_rcItem);
  333. CControlUI* pParent = this;
  334. RECT rcTemp;
  335. RECT rcParent;
  336. while( pParent = pParent->GetParent() ) {
  337. if( !pParent->IsVisible() ) return;
  338. rcTemp = invalidateRc;
  339. rcParent = pParent->GetPos();
  340. if( !::IntersectRect(&invalidateRc, &rcTemp, &rcParent) ) return;
  341. }
  342. m_pManager->Invalidate(invalidateRc);
  343. }
  344. if( m_pCover != NULL && m_pCover->IsVisible() ) m_pCover->Move(szOffset, false);
  345. }
  346. int CControlUI::GetWidth() const
  347. {
  348. return m_rcItem.right - m_rcItem.left;
  349. }
  350. int CControlUI::GetHeight() const
  351. {
  352. return m_rcItem.bottom - m_rcItem.top;
  353. }
  354. int CControlUI::GetX() const
  355. {
  356. return m_rcItem.left;
  357. }
  358. int CControlUI::GetY() const
  359. {
  360. return m_rcItem.top;
  361. }
  362. RECT CControlUI::GetPadding() const
  363. {
  364. return m_rcPadding;
  365. }
  366. void CControlUI::SetPadding(RECT rcPadding)
  367. {
  368. m_rcPadding = rcPadding;
  369. NeedParentUpdate();
  370. }
  371. SIZE CControlUI::GetFixedXY() const
  372. {
  373. return m_cXY;
  374. }
  375. void CControlUI::SetFixedXY(SIZE szXY)
  376. {
  377. m_cXY.cx = szXY.cx;
  378. m_cXY.cy = szXY.cy;
  379. NeedParentUpdate();
  380. }
  381. TPercentInfo CControlUI::GetFloatPercent() const
  382. {
  383. return m_piFloatPercent;
  384. }
  385. void CControlUI::SetFloatPercent(TPercentInfo piFloatPercent)
  386. {
  387. m_piFloatPercent = piFloatPercent;
  388. NeedParentUpdate();
  389. }
  390. int CControlUI::GetFixedWidth() const
  391. {
  392. return m_cxyFixed.cx;
  393. }
  394. void CControlUI::SetFixedWidth(int cx)
  395. {
  396. if( cx < 0 ) return;
  397. m_cxyFixed.cx = cx;
  398. NeedParentUpdate();
  399. }
  400. int CControlUI::GetFixedHeight() const
  401. {
  402. return m_cxyFixed.cy;
  403. }
  404. void CControlUI::SetFixedHeight(int cy)
  405. {
  406. if( cy < 0 ) return;
  407. m_cxyFixed.cy = cy;
  408. NeedParentUpdate();
  409. }
  410. int CControlUI::GetMinWidth() const
  411. {
  412. return m_cxyMin.cx;
  413. }
  414. void CControlUI::SetMinWidth(int cx)
  415. {
  416. if( m_cxyMin.cx == cx ) return;
  417. if( cx < 0 ) return;
  418. m_cxyMin.cx = cx;
  419. NeedParentUpdate();
  420. }
  421. int CControlUI::GetMaxWidth() const
  422. {
  423. if (m_cxyMax.cx < m_cxyMin.cx) return m_cxyMin.cx;
  424. return m_cxyMax.cx;
  425. }
  426. void CControlUI::SetMaxWidth(int cx)
  427. {
  428. if( m_cxyMax.cx == cx ) return;
  429. if( cx < 0 ) return;
  430. m_cxyMax.cx = cx;
  431. NeedParentUpdate();
  432. }
  433. int CControlUI::GetMinHeight() const
  434. {
  435. return m_cxyMin.cy;
  436. }
  437. void CControlUI::SetMinHeight(int cy)
  438. {
  439. if( m_cxyMin.cy == cy ) return;
  440. if( cy < 0 ) return;
  441. m_cxyMin.cy = cy;
  442. NeedParentUpdate();
  443. }
  444. int CControlUI::GetMaxHeight() const
  445. {
  446. if (m_cxyMax.cy < m_cxyMin.cy) return m_cxyMin.cy;
  447. return m_cxyMax.cy;
  448. }
  449. void CControlUI::SetMaxHeight(int cy)
  450. {
  451. if( m_cxyMax.cy == cy ) return;
  452. if( cy < 0 ) return;
  453. m_cxyMax.cy = cy;
  454. NeedParentUpdate();
  455. }
  456. CDuiString CControlUI::GetToolTip() const
  457. {
  458. return m_sToolTip;
  459. }
  460. void CControlUI::SetToolTip(LPCTSTR pstrText)
  461. {
  462. CDuiString strTemp(pstrText);
  463. strTemp.Replace(_T("<n>"),_T("\r\n"));
  464. m_sToolTip=strTemp;
  465. }
  466. void CControlUI::SetToolTipWidth( int nWidth )
  467. {
  468. m_nTooltipWidth=nWidth;
  469. }
  470. int CControlUI::GetToolTipWidth( void )
  471. {
  472. return m_nTooltipWidth;
  473. }
  474. TCHAR CControlUI::GetShortcut() const
  475. {
  476. return m_chShortcut;
  477. }
  478. void CControlUI::SetShortcut(TCHAR ch)
  479. {
  480. m_chShortcut = ch;
  481. }
  482. bool CControlUI::IsContextMenuUsed() const
  483. {
  484. return m_bMenuUsed;
  485. }
  486. void CControlUI::SetContextMenuUsed(bool bMenuUsed)
  487. {
  488. m_bMenuUsed = bMenuUsed;
  489. }
  490. const CDuiString& CControlUI::GetUserData()
  491. {
  492. return m_sUserData;
  493. }
  494. void CControlUI::SetUserData(LPCTSTR pstrText)
  495. {
  496. m_sUserData = pstrText;
  497. }
  498. UINT_PTR CControlUI::GetTag() const
  499. {
  500. return m_pTag;
  501. }
  502. void CControlUI::SetTag(UINT_PTR pTag)
  503. {
  504. m_pTag = pTag;
  505. }
  506. bool CControlUI::IsVisible() const
  507. {
  508. return m_bVisible && m_bInternVisible;
  509. }
  510. void CControlUI::SetVisible(bool bVisible)
  511. {
  512. if( m_bVisible == bVisible ) return;
  513. bool v = IsVisible();
  514. m_bVisible = bVisible;
  515. if( m_bFocused ) m_bFocused = false;
  516. if (!bVisible && m_pManager && m_pManager->GetFocus() == this) {
  517. m_pManager->SetFocus(NULL) ;
  518. }
  519. if( IsVisible() != v ) {
  520. NeedParentUpdate();
  521. }
  522. if( m_pCover != NULL ) m_pCover->SetInternVisible(IsVisible());
  523. }
  524. void CControlUI::SetInternVisible(bool bVisible)
  525. {
  526. m_bInternVisible = bVisible;
  527. if (!bVisible && m_pManager && m_pManager->GetFocus() == this) {
  528. m_pManager->SetFocus(NULL) ;
  529. }
  530. if( m_pCover != NULL ) m_pCover->SetInternVisible(IsVisible());
  531. }
  532. bool CControlUI::IsEnabled() const
  533. {
  534. return m_bEnabled;
  535. }
  536. void CControlUI::SetEnabled(bool bEnabled)
  537. {
  538. if( m_bEnabled == bEnabled ) return;
  539. m_bEnabled = bEnabled;
  540. Invalidate();
  541. }
  542. bool CControlUI::IsMouseEnabled() const
  543. {
  544. return m_bMouseEnabled;
  545. }
  546. void CControlUI::SetMouseEnabled(bool bEnabled)
  547. {
  548. m_bMouseEnabled = bEnabled;
  549. }
  550. bool CControlUI::IsKeyboardEnabled() const
  551. {
  552. return m_bKeyboardEnabled ;
  553. }
  554. void CControlUI::SetKeyboardEnabled(bool bEnabled)
  555. {
  556. m_bKeyboardEnabled = bEnabled ;
  557. }
  558. bool CControlUI::IsFocused() const
  559. {
  560. return m_bFocused;
  561. }
  562. void CControlUI::SetFocus()
  563. {
  564. if( m_pManager != NULL ) m_pManager->SetFocus(this, false);
  565. }
  566. bool CControlUI::IsFloat() const
  567. {
  568. return m_bFloat;
  569. }
  570. void CControlUI::SetFloat(bool bFloat)
  571. {
  572. if( m_bFloat == bFloat ) return;
  573. m_bFloat = bFloat;
  574. NeedParentUpdate();
  575. }
  576. void CControlUI::AddCustomAttribute(LPCTSTR pstrName, LPCTSTR pstrAttr)
  577. {
  578. if( pstrName == NULL || pstrName[0] == _T('\0') || pstrAttr == NULL || pstrAttr[0] == _T('\0') ) return;
  579. CDuiString* pCostomAttr = new CDuiString(pstrAttr);
  580. if (pCostomAttr != NULL) {
  581. if (m_mCustomAttrHash.Find(pstrName) == NULL)
  582. m_mCustomAttrHash.Set(pstrName, (LPVOID)pCostomAttr);
  583. else
  584. delete pCostomAttr;
  585. }
  586. }
  587. LPCTSTR CControlUI::GetCustomAttribute(LPCTSTR pstrName) const
  588. {
  589. if( pstrName == NULL || pstrName[0] == _T('\0') ) return NULL;
  590. CDuiString* pCostomAttr = static_cast<CDuiString*>(m_mCustomAttrHash.Find(pstrName));
  591. if( pCostomAttr ) return pCostomAttr->GetData();
  592. return NULL;
  593. }
  594. bool CControlUI::RemoveCustomAttribute(LPCTSTR pstrName)
  595. {
  596. if( pstrName == NULL || pstrName[0] == _T('\0') ) return NULL;
  597. CDuiString* pCostomAttr = static_cast<CDuiString*>(m_mCustomAttrHash.Find(pstrName));
  598. if( !pCostomAttr ) return false;
  599. delete pCostomAttr;
  600. return m_mCustomAttrHash.Remove(pstrName);
  601. }
  602. void CControlUI::RemoveAllCustomAttribute()
  603. {
  604. CDuiString* pCostomAttr;
  605. for( int i = 0; i< m_mCustomAttrHash.GetSize(); i++ ) {
  606. if(LPCTSTR key = m_mCustomAttrHash.GetAt(i)) {
  607. pCostomAttr = static_cast<CDuiString*>(m_mCustomAttrHash.Find(key));
  608. delete pCostomAttr;
  609. }
  610. }
  611. m_mCustomAttrHash.Resize();
  612. }
  613. CControlUI* CControlUI::FindControl(FINDCONTROLPROC Proc, LPVOID pData, UINT uFlags)
  614. {
  615. if( (uFlags & UIFIND_VISIBLE) != 0 && !IsVisible() ) return NULL;
  616. if( (uFlags & UIFIND_ENABLED) != 0 && !IsEnabled() ) return NULL;
  617. if( (uFlags & UIFIND_HITTEST) != 0 && (!::PtInRect(&m_rcItem, * static_cast<LPPOINT>(pData))) ) return NULL;
  618. if( (uFlags & UIFIND_UPDATETEST) != 0 && Proc(this, pData) != NULL ) return NULL;
  619. CControlUI* pResult = NULL;
  620. if( (uFlags & UIFIND_ME_FIRST) != 0 ) {
  621. if( (uFlags & UIFIND_HITTEST) == 0 || IsMouseEnabled() ) pResult = Proc(this, pData);
  622. }
  623. if( pResult == NULL && m_pCover != NULL ) {
  624. /*if( (uFlags & UIFIND_HITTEST) == 0 || true)*/ pResult = m_pCover->FindControl(Proc, pData, uFlags);
  625. }
  626. if( pResult == NULL && (uFlags & UIFIND_ME_FIRST) == 0 ) {
  627. if( (uFlags & UIFIND_HITTEST) == 0 || IsMouseEnabled() ) pResult = Proc(this, pData);
  628. }
  629. return pResult;
  630. }
  631. void CControlUI::Invalidate()
  632. {
  633. if( !IsVisible() ) return;
  634. RECT invalidateRc = m_rcItem;
  635. CControlUI* pParent = this;
  636. RECT rcTemp;
  637. RECT rcParent;
  638. while( pParent = pParent->GetParent() )
  639. {
  640. rcTemp = invalidateRc;
  641. rcParent = pParent->GetPos();
  642. if( !::IntersectRect(&invalidateRc, &rcTemp, &rcParent) )
  643. {
  644. return;
  645. }
  646. }
  647. if( m_pManager != NULL ) m_pManager->Invalidate(invalidateRc);
  648. }
  649. bool CControlUI::IsUpdateNeeded() const
  650. {
  651. return m_bUpdateNeeded;
  652. }
  653. void CControlUI::NeedUpdate()
  654. {
  655. if( !IsVisible() ) return;
  656. m_bUpdateNeeded = true;
  657. Invalidate();
  658. if( m_pManager != NULL ) m_pManager->NeedUpdate();
  659. }
  660. void CControlUI::NeedParentUpdate()
  661. {
  662. if( GetParent() ) {
  663. GetParent()->NeedUpdate();
  664. GetParent()->Invalidate();
  665. }
  666. else {
  667. NeedUpdate();
  668. }
  669. if( m_pManager != NULL ) m_pManager->NeedUpdate();
  670. }
  671. DWORD CControlUI::GetAdjustColor(DWORD dwColor)
  672. {
  673. if( !m_bColorHSL ) return dwColor;
  674. short H, S, L;
  675. CPaintManagerUI::GetHSL(&H, &S, &L);
  676. return CRenderEngine::AdjustColor(dwColor, H, S, L);
  677. }
  678. void CControlUI::Init()
  679. {
  680. DoInit();
  681. if( OnInit ) OnInit(this);
  682. }
  683. void CControlUI::DoInit()
  684. {
  685. }
  686. void CControlUI::Event(TEventUI& event)
  687. {
  688. if( OnEvent(&event) ) DoEvent(event);
  689. }
  690. void CControlUI::DoEvent(TEventUI& event)
  691. {
  692. if( event.Type == UIEVENT_SETCURSOR )
  693. {
  694. ::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));
  695. return;
  696. }
  697. if( event.Type == UIEVENT_SETFOCUS )
  698. {
  699. m_bFocused = true;
  700. Invalidate();
  701. return;
  702. }
  703. if( event.Type == UIEVENT_KILLFOCUS )
  704. {
  705. m_bFocused = false;
  706. Invalidate();
  707. return;
  708. }
  709. if( event.Type == UIEVENT_TIMER )
  710. {
  711. m_pManager->SendNotify(this, DUI_MSGTYPE_TIMER, event.wParam, event.lParam);
  712. return;
  713. }
  714. if( event.Type == UIEVENT_CONTEXTMENU )
  715. {
  716. if( IsContextMenuUsed() ) {
  717. m_pManager->SendNotify(this, DUI_MSGTYPE_MENU, event.wParam, event.lParam);
  718. return;
  719. }
  720. }
  721. if( m_pParent != NULL ) m_pParent->DoEvent(event);
  722. }
  723. void CControlUI::SetVirtualWnd(LPCTSTR pstrValue)
  724. {
  725. m_sVirtualWnd = pstrValue;
  726. m_pManager->UsedVirtualWnd(true);
  727. }
  728. CDuiString CControlUI::GetVirtualWnd() const
  729. {
  730. CDuiString str;
  731. if( !m_sVirtualWnd.IsEmpty() ){
  732. str = m_sVirtualWnd;
  733. }
  734. else{
  735. CControlUI* pParent = GetParent();
  736. if( pParent != NULL){
  737. str = pParent->GetVirtualWnd();
  738. }
  739. else{
  740. str = _T("");
  741. }
  742. }
  743. return str;
  744. }
  745. CDuiString CControlUI::GetAttribute(LPCTSTR pstrName)
  746. {
  747. return _T("");
  748. }
  749. void CControlUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
  750. {
  751. if( _tcscmp(pstrName, _T("pos")) == 0 ) {
  752. RECT rcPos = { 0 };
  753. LPTSTR pstr = NULL;
  754. rcPos.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  755. rcPos.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  756. rcPos.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  757. rcPos.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  758. SIZE szXY = {rcPos.left, rcPos.top};
  759. SetFixedXY(szXY);
  760. //ASSERT(rcPos.right - rcPos.left >= 0);
  761. //ASSERT(rcPos.bottom - rcPos.top >= 0);
  762. SetFixedWidth(rcPos.right - rcPos.left);
  763. SetFixedHeight(rcPos.bottom - rcPos.top);
  764. }
  765. else if( _tcscmp(pstrName, _T("padding")) == 0 ) {
  766. RECT rcPadding = { 0 };
  767. LPTSTR pstr = NULL;
  768. rcPadding.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  769. rcPadding.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  770. rcPadding.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  771. rcPadding.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  772. SetPadding(rcPadding);
  773. }
  774. else if( _tcscmp(pstrName, _T("bkcolor")) == 0 || _tcscmp(pstrName, _T("bkcolor1")) == 0 ) {
  775. while( *pstrValue > _T('\0') && *pstrValue <= _T(' ') ) pstrValue = ::CharNext(pstrValue);
  776. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  777. LPTSTR pstr = NULL;
  778. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  779. SetBkColor(clrColor);
  780. }
  781. else if( _tcscmp(pstrName, _T("bkcolor2")) == 0 ) {
  782. while( *pstrValue > _T('\0') && *pstrValue <= _T(' ') ) pstrValue = ::CharNext(pstrValue);
  783. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  784. LPTSTR pstr = NULL;
  785. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  786. SetBkColor2(clrColor);
  787. }
  788. else if( _tcscmp(pstrName, _T("bkcolor3")) == 0 ) {
  789. while( *pstrValue > _T('\0') && *pstrValue <= _T(' ') ) pstrValue = ::CharNext(pstrValue);
  790. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  791. LPTSTR pstr = NULL;
  792. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  793. SetBkColor3(clrColor);
  794. }
  795. else if( _tcscmp(pstrName, _T("bordercolor")) == 0 ) {
  796. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  797. LPTSTR pstr = NULL;
  798. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  799. SetBorderColor(clrColor);
  800. }
  801. else if( _tcscmp(pstrName, _T("focusbordercolor")) == 0 ) {
  802. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  803. LPTSTR pstr = NULL;
  804. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  805. SetFocusBorderColor(clrColor);
  806. }
  807. else if( _tcscmp(pstrName, _T("colorhsl")) == 0 ) SetColorHSL(_tcscmp(pstrValue, _T("true")) == 0);
  808. else if( _tcscmp(pstrName, _T("bordersize")) == 0 ) {
  809. CDuiString nValue = pstrValue;
  810. if(nValue.Find(',') < 0)
  811. {
  812. SetBorderSize(_ttoi(pstrValue));
  813. }
  814. else
  815. {
  816. RECT rcBorder = { 0 };
  817. LPTSTR pstr = NULL;
  818. rcBorder.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  819. rcBorder.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  820. rcBorder.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  821. rcBorder.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  822. SetBorderSize(rcBorder);
  823. }
  824. }
  825. else if( _tcscmp(pstrName, _T("borderstyle")) == 0 ) SetBorderStyle(_ttoi(pstrValue));
  826. else if( _tcscmp(pstrName, _T("borderround")) == 0 ) {
  827. SIZE cxyRound = { 0 };
  828. LPTSTR pstr = NULL;
  829. cxyRound.cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  830. cxyRound.cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  831. SetBorderRound(cxyRound);
  832. }
  833. else if( _tcscmp(pstrName, _T("bkimage")) == 0 ) SetBkImage(pstrValue);
  834. else if( _tcscmp(pstrName, _T("width")) == 0 ) SetFixedWidth(_ttoi(pstrValue));
  835. else if( _tcscmp(pstrName, _T("height")) == 0 ) SetFixedHeight(_ttoi(pstrValue));
  836. else if( _tcscmp(pstrName, _T("minwidth")) == 0 ) SetMinWidth(_ttoi(pstrValue));
  837. else if( _tcscmp(pstrName, _T("minheight")) == 0 ) SetMinHeight(_ttoi(pstrValue));
  838. else if( _tcscmp(pstrName, _T("maxwidth")) == 0 ) SetMaxWidth(_ttoi(pstrValue));
  839. else if( _tcscmp(pstrName, _T("maxheight")) == 0 ) SetMaxHeight(_ttoi(pstrValue));
  840. else if( _tcscmp(pstrName, _T("name")) == 0 ) SetName(pstrValue);
  841. else if( _tcscmp(pstrName, _T("text")) == 0 ) SetText(pstrValue);
  842. else if( _tcscmp(pstrName, _T("tooltip")) == 0 ) SetToolTip(pstrValue);
  843. else if( _tcscmp(pstrName, _T("userdata")) == 0 ) SetUserData(pstrValue);
  844. else if( _tcscmp(pstrName, _T("tag")) == 0 ) SetTag(_ttoi(pstrValue));
  845. else if( _tcscmp(pstrName, _T("enabled")) == 0 ) SetEnabled(_tcscmp(pstrValue, _T("true")) == 0);
  846. else if( _tcscmp(pstrName, _T("mouse")) == 0 ) SetMouseEnabled(_tcscmp(pstrValue, _T("true")) == 0);
  847. else if( _tcscmp(pstrName, _T("keyboard")) == 0 ) SetKeyboardEnabled(_tcscmp(pstrValue, _T("true")) == 0);
  848. else if( _tcscmp(pstrName, _T("visible")) == 0 ) SetVisible(_tcscmp(pstrValue, _T("true")) == 0);
  849. else if( _tcscmp(pstrName, _T("float")) == 0 ) {
  850. CDuiString nValue = pstrValue;
  851. if(nValue.Find(',') < 0) {
  852. SetFloat(_tcscmp(pstrValue, _T("true")) == 0);
  853. }
  854. else {
  855. TPercentInfo piFloatPercent = { 0 };
  856. LPTSTR pstr = NULL;
  857. piFloatPercent.left = _tcstod(pstrValue, &pstr); ASSERT(pstr);
  858. piFloatPercent.top = _tcstod(pstr + 1, &pstr); ASSERT(pstr);
  859. piFloatPercent.right = _tcstod(pstr + 1, &pstr); ASSERT(pstr);
  860. piFloatPercent.bottom = _tcstod(pstr + 1, &pstr); ASSERT(pstr);
  861. SetFloatPercent(piFloatPercent);
  862. SetFloat(true);
  863. }
  864. }
  865. else if( _tcscmp(pstrName, _T("shortcut")) == 0 ) SetShortcut(pstrValue[0]);
  866. else if( _tcscmp(pstrName, _T("menu")) == 0 ) SetContextMenuUsed(_tcscmp(pstrValue, _T("true")) == 0);
  867. else if( _tcscmp(pstrName, _T("virtualwnd")) == 0 ) SetVirtualWnd(pstrValue);
  868. else {
  869. AddCustomAttribute(pstrName, pstrValue);
  870. }
  871. }
  872. CDuiString CControlUI::GetAttributeList(bool bIgnoreDefault)
  873. {
  874. return _T("");
  875. }
  876. void CControlUI::SetAttributeList(LPCTSTR pstrList)
  877. {
  878. CDuiString sItem;
  879. CDuiString sValue;
  880. while( *pstrList != _T('\0') ) {
  881. sItem.Empty();
  882. sValue.Empty();
  883. while( *pstrList != _T('\0') && *pstrList != _T('=') ) {
  884. LPTSTR pstrTemp = ::CharNext(pstrList);
  885. while( pstrList < pstrTemp) {
  886. sItem += *pstrList++;
  887. }
  888. }
  889. ASSERT( *pstrList == _T('=') );
  890. if( *pstrList++ != _T('=') ) return;
  891. ASSERT( *pstrList == _T('\"') );
  892. if( *pstrList++ != _T('\"') ) return;
  893. while( *pstrList != _T('\0') && *pstrList != _T('\"') ) {
  894. LPTSTR pstrTemp = ::CharNext(pstrList);
  895. while( pstrList < pstrTemp) {
  896. sValue += *pstrList++;
  897. }
  898. }
  899. ASSERT( *pstrList == _T('\"') );
  900. if( *pstrList++ != _T('\"') ) return;
  901. SetAttribute(sItem, sValue);
  902. if( *pstrList++ != _T(' ') ) return;
  903. }
  904. }
  905. SIZE CControlUI::EstimateSize(SIZE szAvailable)
  906. {
  907. return m_cxyFixed;
  908. }
  909. bool CControlUI::Paint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl)
  910. {
  911. if (pStopControl == this) return false;
  912. if( !::IntersectRect(&m_rcPaint, &rcPaint, &m_rcItem) ) return true;
  913. if( OnPaint ) {
  914. if( !OnPaint(this) ) return true;
  915. }
  916. if (!DoPaint(hDC, rcPaint, pStopControl)) return false;
  917. if( m_pCover != NULL ) return m_pCover->Paint(hDC, rcPaint);
  918. return true;
  919. }
  920. bool CControlUI::DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl)
  921. {
  922. // 绘制循序:背景颜色->背景图->状态图->文本->边框
  923. if( m_cxyBorderRound.cx > 0 || m_cxyBorderRound.cy > 0 ) {
  924. CRenderClip roundClip;
  925. CRenderClip::GenerateRoundClip(hDC, m_rcPaint, m_rcItem, m_cxyBorderRound.cx, m_cxyBorderRound.cy, roundClip);
  926. PaintBkColor(hDC);
  927. PaintBkImage(hDC);
  928. PaintStatusImage(hDC);
  929. PaintText(hDC);
  930. PaintBorder(hDC);
  931. }
  932. else {
  933. PaintBkColor(hDC);
  934. PaintBkImage(hDC);
  935. PaintStatusImage(hDC);
  936. PaintText(hDC);
  937. PaintBorder(hDC);
  938. }
  939. return true;
  940. }
  941. void CControlUI::PaintBkColor(HDC hDC)
  942. {
  943. if( m_dwBackColor != 0 ) {
  944. if( m_dwBackColor2 != 0 ) {
  945. if( m_dwBackColor3 != 0 ) {
  946. RECT rc = m_rcItem;
  947. rc.bottom = (rc.bottom + rc.top) / 2;
  948. CRenderEngine::DrawGradient(hDC, rc, GetAdjustColor(m_dwBackColor), GetAdjustColor(m_dwBackColor2), true, 8);
  949. rc.top = rc.bottom;
  950. rc.bottom = m_rcItem.bottom;
  951. CRenderEngine::DrawGradient(hDC, rc, GetAdjustColor(m_dwBackColor2), GetAdjustColor(m_dwBackColor3), true, 8);
  952. }
  953. else
  954. CRenderEngine::DrawGradient(hDC, m_rcItem, GetAdjustColor(m_dwBackColor), GetAdjustColor(m_dwBackColor2), true, 16);
  955. }
  956. else if( m_dwBackColor >= 0xFF000000 ) CRenderEngine::DrawColor(hDC, m_rcPaint, GetAdjustColor(m_dwBackColor));
  957. else CRenderEngine::DrawColor(hDC, m_rcItem, GetAdjustColor(m_dwBackColor));
  958. }
  959. }
  960. void CControlUI::PaintBkImage(HDC hDC)
  961. {
  962. DrawImage(hDC, m_diBk);
  963. }
  964. void CControlUI::PaintStatusImage(HDC hDC)
  965. {
  966. return;
  967. }
  968. void CControlUI::PaintText(HDC hDC)
  969. {
  970. return;
  971. }
  972. void CControlUI::PaintBorder(HDC hDC)
  973. {
  974. if(m_rcBorderSize.left > 0 && (m_dwBorderColor != 0 || m_dwFocusBorderColor != 0)) {
  975. if( m_cxyBorderRound.cx > 0 || m_cxyBorderRound.cy > 0 )//画圆角边框
  976. {
  977. if (IsFocused() && m_dwFocusBorderColor != 0)
  978. CRenderEngine::DrawRoundRect(hDC, m_rcItem, m_rcBorderSize.left, m_cxyBorderRound.cx, m_cxyBorderRound.cy, GetAdjustColor(m_dwFocusBorderColor), m_nBorderStyle);
  979. else
  980. CRenderEngine::DrawRoundRect(hDC, m_rcItem, m_rcBorderSize.left, m_cxyBorderRound.cx, m_cxyBorderRound.cy, GetAdjustColor(m_dwBorderColor), m_nBorderStyle);
  981. }
  982. else {
  983. if (m_rcBorderSize.right == m_rcBorderSize.left && m_rcBorderSize.top == m_rcBorderSize.left && m_rcBorderSize.bottom == m_rcBorderSize.left) {
  984. if (IsFocused() && m_dwFocusBorderColor != 0)
  985. CRenderEngine::DrawRect(hDC, m_rcItem, m_rcBorderSize.left, GetAdjustColor(m_dwFocusBorderColor), m_nBorderStyle);
  986. else
  987. CRenderEngine::DrawRect(hDC, m_rcItem, m_rcBorderSize.left, GetAdjustColor(m_dwBorderColor), m_nBorderStyle);
  988. }
  989. else {
  990. RECT rcBorder;
  991. if(m_rcBorderSize.left > 0){
  992. rcBorder = m_rcItem;
  993. rcBorder.left += m_rcBorderSize.left / 2;
  994. rcBorder.right = rcBorder.left;
  995. if (IsFocused() && m_dwFocusBorderColor != 0)
  996. CRenderEngine::DrawLine(hDC,rcBorder,m_rcBorderSize.left,GetAdjustColor(m_dwFocusBorderColor),m_nBorderStyle);
  997. else
  998. CRenderEngine::DrawLine(hDC,rcBorder,m_rcBorderSize.left,GetAdjustColor(m_dwBorderColor),m_nBorderStyle);
  999. }
  1000. if(m_rcBorderSize.top > 0) {
  1001. rcBorder = m_rcItem;
  1002. rcBorder.top += m_rcBorderSize.top / 2;
  1003. rcBorder.bottom = rcBorder.top;
  1004. rcBorder.left += m_rcBorderSize.left;
  1005. rcBorder.right -= m_rcBorderSize.right;
  1006. if (IsFocused() && m_dwFocusBorderColor != 0)
  1007. CRenderEngine::DrawLine(hDC,rcBorder,m_rcBorderSize.top,GetAdjustColor(m_dwFocusBorderColor),m_nBorderStyle);
  1008. else
  1009. CRenderEngine::DrawLine(hDC,rcBorder,m_rcBorderSize.top,GetAdjustColor(m_dwBorderColor),m_nBorderStyle);
  1010. }
  1011. if(m_rcBorderSize.right > 0) {
  1012. rcBorder = m_rcItem;
  1013. rcBorder.left = m_rcItem.right - m_rcBorderSize.right / 2;
  1014. rcBorder.right = rcBorder.left;
  1015. if (IsFocused() && m_dwFocusBorderColor != 0)
  1016. CRenderEngine::DrawLine(hDC,rcBorder,m_rcBorderSize.right,GetAdjustColor(m_dwFocusBorderColor),m_nBorderStyle);
  1017. else
  1018. CRenderEngine::DrawLine(hDC,rcBorder,m_rcBorderSize.right,GetAdjustColor(m_dwBorderColor),m_nBorderStyle);
  1019. }
  1020. if(m_rcBorderSize.bottom > 0) {
  1021. rcBorder = m_rcItem;
  1022. rcBorder.top = m_rcItem.bottom - m_rcBorderSize.bottom / 2;
  1023. rcBorder.bottom = rcBorder.top;
  1024. rcBorder.left += m_rcBorderSize.left;
  1025. rcBorder.right -= m_rcBorderSize.right;
  1026. if (IsFocused() && m_dwFocusBorderColor != 0)
  1027. CRenderEngine::DrawLine(hDC,rcBorder,m_rcBorderSize.bottom,GetAdjustColor(m_dwFocusBorderColor),m_nBorderStyle);
  1028. else
  1029. CRenderEngine::DrawLine(hDC,rcBorder,m_rcBorderSize.bottom,GetAdjustColor(m_dwBorderColor),m_nBorderStyle);
  1030. }
  1031. }
  1032. }
  1033. }
  1034. }
  1035. void CControlUI::DoPostPaint(HDC hDC, const RECT& rcPaint)
  1036. {
  1037. if( OnPostPaint ) OnPostPaint(this);
  1038. }
  1039. int CControlUI::GetBorderStyle() const
  1040. {
  1041. return m_nBorderStyle;
  1042. }
  1043. void CControlUI::SetBorderStyle( int nStyle )
  1044. {
  1045. m_nBorderStyle = nStyle;
  1046. Invalidate();
  1047. }
  1048. } // namespace DuiLib