UIControl.cpp 30 KB

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