UIButton.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. #include "StdAfx.h"
  2. #include "UIButton.h"
  3. namespace DuiLib
  4. {
  5. IMPLEMENT_DUICONTROL(CButtonUI)
  6. CButtonUI::CButtonUI()
  7. : m_uButtonState(0)
  8. , m_iHotFont(-1)
  9. , m_iPushedFont(-1)
  10. , m_iFocusedFont(-1)
  11. , m_dwHotTextColor(0)
  12. , m_dwPushedTextColor(0)
  13. , m_dwFocusedTextColor(0)
  14. , m_dwHotBkColor(0)
  15. , m_dwPushedBkColor(0)
  16. , m_dwDisabledBkColor(0)
  17. , m_dwHotBorderColor(0)
  18. , m_dwPushedBorderColor(0)
  19. , m_dwDisabledBorderColor(0)
  20. , m_iBindTabIndex(-1)
  21. , m_nStateCount(0)
  22. {
  23. m_uTextStyle = DT_SINGLELINE | DT_VCENTER | DT_CENTER;
  24. }
  25. LPCTSTR CButtonUI::GetClass() const
  26. {
  27. return _T("ButtonUI");
  28. }
  29. LPVOID CButtonUI::GetInterface(LPCTSTR pstrName)
  30. {
  31. if( _tcsicmp(pstrName, DUI_CTR_BUTTON) == 0 ) return static_cast<CButtonUI*>(this);
  32. return CLabelUI::GetInterface(pstrName);
  33. }
  34. UINT CButtonUI::GetControlFlags() const
  35. {
  36. return (IsKeyboardEnabled() ? UIFLAG_TABSTOP : 0) | (IsEnabled() ? UIFLAG_SETCURSOR : 0);
  37. }
  38. void CButtonUI::DoEvent(TEventUI& event)
  39. {
  40. if( !IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND ) {
  41. if( m_pParent != NULL ) m_pParent->DoEvent(event);
  42. else CLabelUI::DoEvent(event);
  43. return;
  44. }
  45. if( event.Type == UIEVENT_SETFOCUS )
  46. {
  47. Invalidate();
  48. }
  49. if( event.Type == UIEVENT_KILLFOCUS )
  50. {
  51. Invalidate();
  52. }
  53. if( event.Type == UIEVENT_KEYDOWN )
  54. {
  55. if (IsKeyboardEnabled()) {
  56. if( event.chKey == VK_SPACE || event.chKey == VK_RETURN ) {
  57. Activate();
  58. return;
  59. }
  60. }
  61. }
  62. if( event.Type == UIEVENT_BUTTONDOWN || event.Type == UIEVENT_DBLCLICK)
  63. {
  64. if( ::PtInRect(&m_rcItem, event.ptMouse) && IsEnabled() ) {
  65. m_uButtonState |= UISTATE_PUSHED | UISTATE_CAPTURED;
  66. Invalidate();
  67. if(IsRichEvent()) m_pManager->SendNotify(this, DUI_MSGTYPE_BUTTONDOWN);
  68. }
  69. return;
  70. }
  71. if( event.Type == UIEVENT_MOUSEMOVE )
  72. {
  73. if ((m_uButtonState & UISTATE_CAPTURED) != 0)
  74. {
  75. if (::PtInRect(&m_rcItem, event.ptMouse))
  76. m_uButtonState |= UISTATE_PUSHED;
  77. else m_uButtonState &= ~UISTATE_PUSHED;
  78. Invalidate();
  79. }
  80. return;
  81. }
  82. if( event.Type == UIEVENT_BUTTONUP)
  83. {
  84. if( (m_uButtonState & UISTATE_CAPTURED) != 0 ) {
  85. m_uButtonState &= ~(UISTATE_PUSHED | UISTATE_CAPTURED);
  86. Invalidate();
  87. if( ::PtInRect(&m_rcItem, event.ptMouse) ) Activate();
  88. }
  89. return;
  90. }
  91. if( event.Type == UIEVENT_CONTEXTMENU )
  92. {
  93. if( IsContextMenuUsed() ) {
  94. m_pManager->SendNotify(this, DUI_MSGTYPE_MENU, event.wParam, event.lParam);
  95. }
  96. return;
  97. }
  98. if( event.Type == UIEVENT_MOUSEENTER )
  99. {
  100. if( IsEnabled() ) {
  101. m_uButtonState |= UISTATE_HOT;
  102. Invalidate();
  103. if(IsRichEvent()) m_pManager->SendNotify(this, DUI_MSGTYPE_MOUSEENTER);
  104. }
  105. }
  106. if( event.Type == UIEVENT_MOUSELEAVE )
  107. {
  108. if( IsEnabled() ) {
  109. m_uButtonState &= ~UISTATE_HOT;
  110. Invalidate();
  111. if(IsRichEvent()) m_pManager->SendNotify(this, DUI_MSGTYPE_MOUSELEAVE);
  112. }
  113. }
  114. CLabelUI::DoEvent(event);
  115. }
  116. bool CButtonUI::Activate()
  117. {
  118. if( !CControlUI::Activate() ) return false;
  119. if( m_pManager != NULL )
  120. {
  121. m_pManager->SendNotify(this, DUI_MSGTYPE_CLICK);
  122. BindTriggerTabSel();
  123. }
  124. return true;
  125. }
  126. void CButtonUI::SetEnabled(bool bEnable)
  127. {
  128. CControlUI::SetEnabled(bEnable);
  129. if (!IsEnabled()) {
  130. m_uButtonState |= UISTATE_DISABLED;
  131. }
  132. else {
  133. m_uButtonState &= ~UISTATE_DISABLED;
  134. }
  135. }
  136. void CButtonUI::SetHotFont(int index)
  137. {
  138. m_iHotFont = index;
  139. Invalidate();
  140. }
  141. int CButtonUI::GetHotFont() const
  142. {
  143. return m_iHotFont;
  144. }
  145. void CButtonUI::SetPushedFont(int index)
  146. {
  147. m_iPushedFont = index;
  148. Invalidate();
  149. }
  150. int CButtonUI::GetPushedFont() const
  151. {
  152. return m_iPushedFont;
  153. }
  154. void CButtonUI::SetFocusedFont(int index)
  155. {
  156. m_iFocusedFont = index;
  157. Invalidate();
  158. }
  159. int CButtonUI::GetFocusedFont() const
  160. {
  161. return m_iFocusedFont;
  162. }
  163. void CButtonUI::SetHotBkColor( DWORD dwColor )
  164. {
  165. m_dwHotBkColor = dwColor;
  166. Invalidate();
  167. }
  168. DWORD CButtonUI::GetHotBkColor() const
  169. {
  170. return m_dwHotBkColor;
  171. }
  172. void CButtonUI::SetPushedBkColor( DWORD dwColor )
  173. {
  174. m_dwPushedBkColor = dwColor;
  175. Invalidate();
  176. }
  177. DWORD CButtonUI::GetPushedBkColor() const
  178. {
  179. return m_dwPushedBkColor;
  180. }
  181. void CButtonUI::SetDisabledBkColor( DWORD dwColor )
  182. {
  183. m_dwDisabledBkColor = dwColor;
  184. Invalidate();
  185. }
  186. DWORD CButtonUI::GetDisabledBkColor() const
  187. {
  188. return m_dwDisabledBkColor;
  189. }
  190. void CButtonUI::SetHotTextColor(DWORD dwColor)
  191. {
  192. m_dwHotTextColor = dwColor;
  193. }
  194. DWORD CButtonUI::GetHotTextColor() const
  195. {
  196. return m_dwHotTextColor;
  197. }
  198. void CButtonUI::SetPushedTextColor(DWORD dwColor)
  199. {
  200. m_dwPushedTextColor = dwColor;
  201. }
  202. DWORD CButtonUI::GetPushedTextColor() const
  203. {
  204. return m_dwPushedTextColor;
  205. }
  206. void CButtonUI::SetFocusedTextColor(DWORD dwColor)
  207. {
  208. m_dwFocusedTextColor = dwColor;
  209. }
  210. DWORD CButtonUI::GetFocusedTextColor() const
  211. {
  212. return m_dwFocusedTextColor;
  213. }
  214. void CButtonUI::SetHotBorderColor(DWORD dwColor)
  215. {
  216. if (m_dwHotBorderColor == dwColor) return;
  217. m_dwHotBorderColor = dwColor;
  218. Invalidate();
  219. }
  220. DWORD CButtonUI::GetHotBorderColor() const
  221. {
  222. return m_dwHotBorderColor;
  223. }
  224. void CButtonUI::SetPushedBorderColor(DWORD dwColor)
  225. {
  226. if (m_dwPushedBorderColor == dwColor) return;
  227. m_dwPushedBorderColor = dwColor;
  228. Invalidate();
  229. }
  230. DWORD CButtonUI::GetPushedBorderColor() const
  231. {
  232. return m_dwPushedBorderColor;
  233. }
  234. void CButtonUI::SetDisabledBorderColor(DWORD dwColor)
  235. {
  236. if (m_dwDisabledBorderColor == dwColor) return;
  237. m_dwDisabledBorderColor = dwColor;
  238. Invalidate();
  239. }
  240. DWORD CButtonUI::GetDisabledBorderColor() const
  241. {
  242. return m_dwDisabledBorderColor;
  243. }
  244. LPCTSTR CButtonUI::GetNormalImage()
  245. {
  246. return m_sNormalImage;
  247. }
  248. void CButtonUI::SetNormalImage(LPCTSTR pStrImage)
  249. {
  250. m_sNormalImage = pStrImage;
  251. Invalidate();
  252. }
  253. LPCTSTR CButtonUI::GetHotImage()
  254. {
  255. return m_sHotImage;
  256. }
  257. void CButtonUI::SetHotImage(LPCTSTR pStrImage)
  258. {
  259. m_sHotImage = pStrImage;
  260. Invalidate();
  261. }
  262. LPCTSTR CButtonUI::GetPushedImage()
  263. {
  264. return m_sPushedImage;
  265. }
  266. void CButtonUI::SetPushedImage(LPCTSTR pStrImage)
  267. {
  268. m_sPushedImage = pStrImage;
  269. Invalidate();
  270. }
  271. LPCTSTR CButtonUI::GetFocusedImage()
  272. {
  273. return m_sFocusedImage;
  274. }
  275. void CButtonUI::SetFocusedImage(LPCTSTR pStrImage)
  276. {
  277. m_sFocusedImage = pStrImage;
  278. Invalidate();
  279. }
  280. LPCTSTR CButtonUI::GetDisabledImage()
  281. {
  282. return m_sDisabledImage;
  283. }
  284. void CButtonUI::SetDisabledImage(LPCTSTR pStrImage)
  285. {
  286. m_sDisabledImage = pStrImage;
  287. Invalidate();
  288. }
  289. LPCTSTR CButtonUI::GetHotForeImage()
  290. {
  291. return m_sHotForeImage;
  292. }
  293. void CButtonUI::SetHotForeImage( LPCTSTR pStrImage )
  294. {
  295. m_sHotForeImage = pStrImage;
  296. Invalidate();
  297. }
  298. LPCTSTR CButtonUI::GetPushedForeImage()
  299. {
  300. return m_sPushedForeImage;
  301. }
  302. void CButtonUI::SetPushedForeImage(LPCTSTR pStrImage)
  303. {
  304. m_sPushedForeImage = pStrImage;
  305. Invalidate();
  306. }
  307. void CButtonUI::SetStateCount(int nCount)
  308. {
  309. m_nStateCount = nCount;
  310. Invalidate();
  311. }
  312. int CButtonUI::GetStateCount() const
  313. {
  314. return m_nStateCount;
  315. }
  316. LPCTSTR CButtonUI::GetStateImage()
  317. {
  318. return m_sStateImage;
  319. }
  320. void CButtonUI::SetStateImage( LPCTSTR pStrImage )
  321. {
  322. m_sNormalImage.Empty();
  323. m_sStateImage = pStrImage;
  324. Invalidate();
  325. }
  326. void CButtonUI::BindTabIndex(int _BindTabIndex )
  327. {
  328. if( _BindTabIndex >= 0)
  329. m_iBindTabIndex = _BindTabIndex;
  330. }
  331. void CButtonUI::BindTabLayoutName( LPCTSTR _TabLayoutName )
  332. {
  333. if(_TabLayoutName)
  334. m_sBindTabLayoutName = _TabLayoutName;
  335. }
  336. void CButtonUI::BindTriggerTabSel( int _SetSelectIndex /*= -1*/ )
  337. {
  338. LPCTSTR pstrName = GetBindTabLayoutName();
  339. if(pstrName == NULL || (GetBindTabLayoutIndex() < 0 && _SetSelectIndex < 0))
  340. return;
  341. CTabLayoutUI* pTabLayout = static_cast<CTabLayoutUI*>(GetManager()->FindControl(pstrName));
  342. if(!pTabLayout) return;
  343. pTabLayout->SelectItem(_SetSelectIndex >=0?_SetSelectIndex:GetBindTabLayoutIndex());
  344. }
  345. void CButtonUI::RemoveBindTabIndex()
  346. {
  347. m_iBindTabIndex = -1;
  348. m_sBindTabLayoutName.Empty();
  349. }
  350. int CButtonUI::GetBindTabLayoutIndex()
  351. {
  352. return m_iBindTabIndex;
  353. }
  354. LPCTSTR CButtonUI::GetBindTabLayoutName()
  355. {
  356. return m_sBindTabLayoutName;
  357. }
  358. void CButtonUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
  359. {
  360. if( _tcsicmp(pstrName, _T("normalimage")) == 0 ) SetNormalImage(pstrValue);
  361. else if( _tcsicmp(pstrName, _T("hotimage")) == 0 ) SetHotImage(pstrValue);
  362. else if( _tcsicmp(pstrName, _T("pushedimage")) == 0 ) SetPushedImage(pstrValue);
  363. else if( _tcsicmp(pstrName, _T("focusedimage")) == 0 ) SetFocusedImage(pstrValue);
  364. else if( _tcsicmp(pstrName, _T("disabledimage")) == 0 ) SetDisabledImage(pstrValue);
  365. else if (_tcsicmp(pstrName, _T("hotforeimage")) == 0) SetHotForeImage(pstrValue);
  366. else if (_tcsicmp(pstrName, _T("pushedforeimage")) == 0) SetPushedForeImage(pstrValue);
  367. else if( _tcsicmp(pstrName, _T("stateimage")) == 0 ) SetStateImage(pstrValue);
  368. else if( _tcsicmp(pstrName, _T("statecount")) == 0 ) SetStateCount(_ttoi(pstrValue));
  369. else if( _tcsicmp(pstrName, _T("bindtabindex")) == 0 ) BindTabIndex(_ttoi(pstrValue));
  370. else if( _tcsicmp(pstrName, _T("bindtablayoutname")) == 0 ) BindTabLayoutName(pstrValue);
  371. else if( _tcsicmp(pstrName, _T("hotbkcolor")) == 0 )
  372. {
  373. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  374. LPTSTR pstr = NULL;
  375. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  376. SetHotBkColor(clrColor);
  377. }
  378. else if( _tcsicmp(pstrName, _T("pushedbkcolor")) == 0 )
  379. {
  380. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  381. LPTSTR pstr = NULL;
  382. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  383. SetPushedBkColor(clrColor);
  384. }
  385. else if( _tcsicmp(pstrName, _T("disabledbkcolor")) == 0 )
  386. {
  387. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  388. LPTSTR pstr = NULL;
  389. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  390. SetDisabledBkColor(clrColor);
  391. }
  392. else if( _tcsicmp(pstrName, _T("hottextcolor")) == 0 )
  393. {
  394. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  395. LPTSTR pstr = NULL;
  396. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  397. SetHotTextColor(clrColor);
  398. }
  399. else if( _tcsicmp(pstrName, _T("pushedtextcolor")) == 0 )
  400. {
  401. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  402. LPTSTR pstr = NULL;
  403. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  404. SetPushedTextColor(clrColor);
  405. }
  406. else if( _tcsicmp(pstrName, _T("focusedtextcolor")) == 0 )
  407. {
  408. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  409. LPTSTR pstr = NULL;
  410. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  411. SetFocusedTextColor(clrColor);
  412. }
  413. else if (_tcscmp(pstrName, _T("hotbordercolor")) == 0)
  414. {
  415. if (*pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  416. LPTSTR pstr = NULL;
  417. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  418. SetHotBorderColor(clrColor);
  419. }
  420. else if (_tcscmp(pstrName, _T("pushedbordercolor")) == 0)
  421. {
  422. if (*pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  423. LPTSTR pstr = NULL;
  424. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  425. SetPushedBorderColor(clrColor);
  426. }
  427. else if (_tcscmp(pstrName, _T("disabledbordercolor")) == 0)
  428. {
  429. if (*pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  430. LPTSTR pstr = NULL;
  431. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  432. SetDisabledBorderColor(clrColor);
  433. }
  434. else if( _tcsicmp(pstrName, _T("hotfont")) == 0 ) SetHotFont(_ttoi(pstrValue));
  435. else if( _tcsicmp(pstrName, _T("pushedfont")) == 0 ) SetPushedFont(_ttoi(pstrValue));
  436. else if( _tcsicmp(pstrName, _T("focuedfont")) == 0 ) SetFocusedFont(_ttoi(pstrValue));
  437. else CLabelUI::SetAttribute(pstrName, pstrValue);
  438. }
  439. void CButtonUI::PaintText(HDC hDC)
  440. {
  441. if( IsFocused() ) m_uButtonState |= UISTATE_FOCUSED;
  442. else m_uButtonState &= ~ UISTATE_FOCUSED;
  443. if( !IsEnabled() ) m_uButtonState |= UISTATE_DISABLED;
  444. else m_uButtonState &= ~ UISTATE_DISABLED;
  445. if( m_dwTextColor == 0 ) m_dwTextColor = m_pManager->GetDefaultFontColor();
  446. if( m_dwDisabledTextColor == 0 ) m_dwDisabledTextColor = m_pManager->GetDefaultDisabledColor();
  447. CDuiString sText = GetText();
  448. if( sText.IsEmpty() ) return;
  449. RECT m_rcTextPadding = CButtonUI::m_rcTextPadding;
  450. GetManager()->GetDPIObj()->Scale(&m_rcTextPadding);
  451. int nLinks = 0;
  452. RECT rc = m_rcItem;
  453. rc.left += m_rcTextPadding.left;
  454. rc.right -= m_rcTextPadding.right;
  455. rc.top += m_rcTextPadding.top;
  456. rc.bottom -= m_rcTextPadding.bottom;
  457. DWORD clrColor = IsEnabled()?m_dwTextColor:m_dwDisabledTextColor;
  458. if( ((m_uButtonState & UISTATE_PUSHED) != 0) && (GetPushedTextColor() != 0) )
  459. clrColor = GetPushedTextColor();
  460. else if( ((m_uButtonState & UISTATE_HOT) != 0) && (GetHotTextColor() != 0) )
  461. clrColor = GetHotTextColor();
  462. else if( ((m_uButtonState & UISTATE_FOCUSED) != 0) && (GetFocusedTextColor() != 0) )
  463. clrColor = GetFocusedTextColor();
  464. int iFont = GetFont();
  465. if( ((m_uButtonState & UISTATE_PUSHED) != 0) && (GetPushedFont() != -1) )
  466. iFont = GetPushedFont();
  467. else if( ((m_uButtonState & UISTATE_HOT) != 0) && (GetHotFont() != -1) )
  468. iFont = GetHotFont();
  469. else if( ((m_uButtonState & UISTATE_FOCUSED) != 0) && (GetFocusedFont() != -1) )
  470. iFont = GetFocusedFont();
  471. if( m_bShowHtml )
  472. CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, sText, clrColor, \
  473. NULL, NULL, nLinks, iFont, m_uTextStyle);
  474. else
  475. CRenderEngine::DrawText(hDC, m_pManager, rc, sText, clrColor, \
  476. iFont, m_uTextStyle);
  477. }
  478. void CButtonUI::PaintBkColor(HDC hDC)
  479. {
  480. if( (m_uButtonState & UISTATE_DISABLED) != 0 ) {
  481. if(m_dwDisabledBkColor != 0) {
  482. CRenderEngine::DrawColor(hDC, m_rcPaint, GetAdjustColor(m_dwDisabledBkColor));
  483. return;
  484. }
  485. }
  486. else if( (m_uButtonState & UISTATE_PUSHED) != 0 ) {
  487. if(m_dwPushedBkColor != 0) {
  488. CRenderEngine::DrawColor(hDC, m_rcPaint, GetAdjustColor(m_dwPushedBkColor));
  489. return;
  490. }
  491. }
  492. else if( (m_uButtonState & UISTATE_HOT) != 0 ) {
  493. if(m_dwHotBkColor != 0) {
  494. CRenderEngine::DrawColor(hDC, m_rcPaint, GetAdjustColor(m_dwHotBkColor));
  495. return;
  496. }
  497. }
  498. return CControlUI::PaintBkColor(hDC);
  499. }
  500. void CButtonUI::PaintStatusImage(HDC hDC)
  501. {
  502. if(!m_sStateImage.IsEmpty() && m_nStateCount > 0)
  503. {
  504. TDrawInfo info;
  505. info.Parse(m_sStateImage, _T(""), m_pManager);
  506. const TImageInfo* pImage = m_pManager->GetImageEx(info.sImageName, info.sResType, info.dwMask, info.bHSL, info.bGdiplus);
  507. if(m_sNormalImage.IsEmpty() && pImage != NULL)
  508. {
  509. SIZE szImage = {pImage->nX, pImage->nY};
  510. SIZE szStatus = {pImage->nX / m_nStateCount, pImage->nY};
  511. if( szImage.cx > 0 && szImage.cy > 0 )
  512. {
  513. RECT rcSrc = {0, 0, szImage.cx, szImage.cy};
  514. if(m_nStateCount > 0) {
  515. int iLeft = rcSrc.left + 0 * szStatus.cx;
  516. int iRight = iLeft + szStatus.cx;
  517. int iTop = rcSrc.top;
  518. int iBottom = iTop + szStatus.cy;
  519. m_sNormalImage.Format(_T("res='%s' restype='%s' dest='%d,%d,%d,%d' source='%d,%d,%d,%d'"), info.sImageName.GetData(), info.sResType.GetData(), info.rcDest.left, info.rcDest.top, info.rcDest.right, info.rcDest.bottom, iLeft, iTop, iRight, iBottom);
  520. }
  521. if(m_nStateCount > 1) {
  522. int iLeft = rcSrc.left + 1 * szStatus.cx;
  523. int iRight = iLeft + szStatus.cx;
  524. int iTop = rcSrc.top;
  525. int iBottom = iTop + szStatus.cy;
  526. m_sHotImage.Format(_T("res='%s' restype='%s' dest='%d,%d,%d,%d' source='%d,%d,%d,%d'"), info.sImageName.GetData(), info.sResType.GetData(), info.rcDest.left, info.rcDest.top, info.rcDest.right, info.rcDest.bottom, iLeft, iTop, iRight, iBottom);
  527. m_sPushedImage.Format(_T("res='%s' restype='%s' dest='%d,%d,%d,%d' source='%d,%d,%d,%d'"), info.sImageName.GetData(), info.sResType.GetData(), info.rcDest.left, info.rcDest.top, info.rcDest.right, info.rcDest.bottom, iLeft, iTop, iRight, iBottom);
  528. }
  529. if(m_nStateCount > 2) {
  530. int iLeft = rcSrc.left + 2 * szStatus.cx;
  531. int iRight = iLeft + szStatus.cx;
  532. int iTop = rcSrc.top;
  533. int iBottom = iTop + szStatus.cy;
  534. m_sPushedImage.Format(_T("res='%s' restype='%s' dest='%d,%d,%d,%d' source='%d,%d,%d,%d'"), info.sImageName.GetData(), info.sResType.GetData(), info.rcDest.left, info.rcDest.top, info.rcDest.right, info.rcDest.bottom, iLeft, iTop, iRight, iBottom);
  535. }
  536. if(m_nStateCount > 3) {
  537. int iLeft = rcSrc.left + 3 * szStatus.cx;
  538. int iRight = iLeft + szStatus.cx;
  539. int iTop = rcSrc.top;
  540. int iBottom = iTop + szStatus.cy;
  541. m_sDisabledImage.Format(_T("res='%s' restype='%s' dest='%d,%d,%d,%d' source='%d,%d,%d,%d'"), info.sImageName.GetData(), info.sResType.GetData(), info.rcDest.left, info.rcDest.top, info.rcDest.right, info.rcDest.bottom, iLeft, iTop, iRight, iBottom);
  542. }
  543. }
  544. }
  545. }
  546. if( IsFocused() ) m_uButtonState |= UISTATE_FOCUSED;
  547. else m_uButtonState &= ~ UISTATE_FOCUSED;
  548. if( !IsEnabled() ) m_uButtonState |= UISTATE_DISABLED;
  549. else m_uButtonState &= ~ UISTATE_DISABLED;
  550. if(!::IsWindowEnabled(m_pManager->GetPaintWindow())) {
  551. m_uButtonState &= UISTATE_DISABLED;
  552. }
  553. if( (m_uButtonState & UISTATE_DISABLED) != 0 ) {
  554. if( !m_sDisabledImage.IsEmpty() ) {
  555. if( !DrawImage(hDC, (LPCTSTR)m_sDisabledImage) ) {}
  556. else return;
  557. }
  558. }
  559. else if( (m_uButtonState & UISTATE_PUSHED) != 0 ) {
  560. if( !m_sPushedImage.IsEmpty() ) {
  561. if( !DrawImage(hDC, (LPCTSTR)m_sPushedImage) ) {}
  562. else return;
  563. }
  564. }
  565. else if( (m_uButtonState & UISTATE_HOT) != 0 ) {
  566. if( !m_sHotImage.IsEmpty() ) {
  567. if( !DrawImage(hDC, (LPCTSTR)m_sHotImage) ) {}
  568. else return;
  569. }
  570. }
  571. else if( (m_uButtonState & UISTATE_FOCUSED) != 0 ) {
  572. if( !m_sFocusedImage.IsEmpty() ) {
  573. if( !DrawImage(hDC, (LPCTSTR)m_sFocusedImage) ) {}
  574. else return;
  575. }
  576. }
  577. if( !m_sNormalImage.IsEmpty() ) {
  578. if( !DrawImage(hDC, (LPCTSTR)m_sNormalImage) ) {}
  579. }
  580. }
  581. void CButtonUI::PaintBorder(HDC hDC)
  582. {
  583. if ((m_uButtonState & UISTATE_DISABLED) != 0) {
  584. if (m_dwDisabledBorderColor != 0) {
  585. DrawBorder(hDC, m_rcItem, GetAdjustColor(m_dwDisabledBorderColor), m_nBorderSize, m_rcBorderSize, m_cxyBorderRound, m_nBorderStyle);
  586. return;
  587. }
  588. }
  589. else if ((m_uButtonState & UISTATE_PUSHED) != 0) {
  590. if (m_dwPushedBorderColor != 0) {
  591. DrawBorder(hDC, m_rcItem, GetAdjustColor(m_dwPushedBorderColor), m_nBorderSize, m_rcBorderSize, m_cxyBorderRound, m_nBorderStyle);
  592. return;
  593. }
  594. }
  595. else if ((m_uButtonState & UISTATE_HOT) != 0) {
  596. if (m_dwHotBorderColor != 0) {
  597. DrawBorder(hDC, m_rcItem, GetAdjustColor(m_dwHotBorderColor), m_nBorderSize, m_rcBorderSize, m_cxyBorderRound, m_nBorderStyle);
  598. return;
  599. }
  600. }
  601. return CControlUI::PaintBorder(hDC);
  602. }
  603. void CButtonUI::PaintForeImage(HDC hDC)
  604. {
  605. if( (m_uButtonState & UISTATE_PUSHED) != 0 ) {
  606. if( !m_sPushedForeImage.IsEmpty() ) {
  607. if( !DrawImage(hDC, (LPCTSTR)m_sPushedForeImage) ) {}
  608. else return;
  609. }
  610. }
  611. else if( (m_uButtonState & UISTATE_HOT) != 0 ) {
  612. if( !m_sHotForeImage.IsEmpty() ) {
  613. if( !DrawImage(hDC, (LPCTSTR)m_sHotForeImage) ) {}
  614. else return;
  615. }
  616. }
  617. if(!m_sForeImage.IsEmpty() ) {
  618. if( !DrawImage(hDC, (LPCTSTR)m_sForeImage) ) {}
  619. }
  620. }
  621. void CButtonUI::DrawBorder(HDC hDC, const RECT& rcItem, const DWORD& dwBorderColor, const int& nBorderSize, const RECT& rcBorderSize, const SIZE& cxyBorderRound, const int& nBorderStyle)
  622. {
  623. if (dwBorderColor != 0) {
  624. //ť­Ô˛˝Çąßżň
  625. if (nBorderSize > 0 && (cxyBorderRound.cx > 0 || cxyBorderRound.cy > 0)) {
  626. CRenderEngine::DrawRoundRect(hDC, rcItem, nBorderSize, cxyBorderRound.cx, cxyBorderRound.cy, GetAdjustColor(dwBorderColor), nBorderStyle);
  627. }
  628. else {
  629. if (rcBorderSize.left > 0 || rcBorderSize.top > 0 || rcBorderSize.right > 0 || rcBorderSize.bottom > 0) {
  630. RECT rcBorder;
  631. if (rcBorderSize.left > 0) {
  632. rcBorder = rcItem;
  633. rcBorder.right = rcBorder.left;
  634. CRenderEngine::DrawLine(hDC, rcBorder, rcBorderSize.left, GetAdjustColor(dwBorderColor), nBorderStyle);
  635. }
  636. if (rcBorderSize.top > 0) {
  637. rcBorder = rcItem;
  638. rcBorder.bottom = rcBorder.top;
  639. CRenderEngine::DrawLine(hDC, rcBorder, rcBorderSize.top, GetAdjustColor(dwBorderColor), nBorderStyle);
  640. }
  641. if (rcBorderSize.right > 0) {
  642. rcBorder = rcItem;
  643. rcBorder.right -= 1;
  644. rcBorder.left = rcBorder.right;
  645. CRenderEngine::DrawLine(hDC, rcBorder, rcBorderSize.right, GetAdjustColor(dwBorderColor), nBorderStyle);
  646. }
  647. if (rcBorderSize.bottom > 0) {
  648. rcBorder = rcItem;
  649. rcBorder.bottom -= 1;
  650. rcBorder.top = rcBorder.bottom;
  651. CRenderEngine::DrawLine(hDC, rcBorder, rcBorderSize.bottom, GetAdjustColor(dwBorderColor), nBorderStyle);
  652. }
  653. }
  654. else if (nBorderSize > 0) {
  655. CRenderEngine::DrawRect(hDC, rcItem, nBorderSize, GetAdjustColor(dwBorderColor), nBorderStyle);
  656. }
  657. }
  658. }
  659. }
  660. }