UIScrollBar.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065
  1. #include "stdafx.h"
  2. #include "UIScrollBar.h"
  3. namespace DuiLib {
  4. CScrollBarUI::CScrollBarUI() :
  5. m_bHorizontal(false),
  6. m_nRange(100),
  7. m_nScrollPos(0),
  8. m_nLineSize(8),
  9. m_pOwner(NULL),
  10. m_nLastScrollPos(0),
  11. m_nLastScrollOffset(0),
  12. m_nScrollRepeatDelay(0),
  13. m_dwButton1Color(0),
  14. m_uButton1State(0),
  15. m_dwButton2Color(0),
  16. m_uButton2State(0),
  17. m_dwThumbColor(0),
  18. m_uThumbState(0),
  19. m_bShowButton1(true),
  20. m_bShowButton2(true)
  21. {
  22. m_cxyFixed.cx = DEFAULT_SCROLLBAR_SIZE;
  23. ptLastMouse.x = ptLastMouse.y = 0;
  24. ::ZeroMemory(&m_rcThumb, sizeof(m_rcThumb));
  25. ::ZeroMemory(&m_rcButton1, sizeof(m_rcButton1));
  26. ::ZeroMemory(&m_rcButton2, sizeof(m_rcButton2));
  27. }
  28. LPCTSTR CScrollBarUI::GetClass() const
  29. {
  30. return _T("ScrollBarUI");
  31. }
  32. LPVOID CScrollBarUI::GetInterface(LPCTSTR pstrName)
  33. {
  34. if( _tcscmp(pstrName, DUI_CTR_SCROLLBAR) == 0 ) return static_cast<CScrollBarUI*>(this);
  35. return CControlUI::GetInterface(pstrName);
  36. }
  37. CContainerUI* CScrollBarUI::GetOwner() const
  38. {
  39. return m_pOwner;
  40. }
  41. void CScrollBarUI::SetOwner(CContainerUI* pOwner)
  42. {
  43. m_pOwner = pOwner;
  44. }
  45. void CScrollBarUI::SetVisible(bool bVisible)
  46. {
  47. if( m_bVisible == bVisible ) return;
  48. bool v = IsVisible();
  49. m_bVisible = bVisible;
  50. if( m_bFocused ) m_bFocused = false;
  51. }
  52. void CScrollBarUI::SetEnabled(bool bEnable)
  53. {
  54. CControlUI::SetEnabled(bEnable);
  55. if( !IsEnabled() ) {
  56. m_uButton1State = 0;
  57. m_uButton2State = 0;
  58. m_uThumbState = 0;
  59. }
  60. }
  61. void CScrollBarUI::SetFocus()
  62. {
  63. if( m_pOwner != NULL ) m_pOwner->SetFocus();
  64. else CControlUI::SetFocus();
  65. }
  66. bool CScrollBarUI::IsHorizontal()
  67. {
  68. return m_bHorizontal;
  69. }
  70. void CScrollBarUI::SetHorizontal(bool bHorizontal)
  71. {
  72. if( m_bHorizontal == bHorizontal ) return;
  73. m_bHorizontal = bHorizontal;
  74. if( m_bHorizontal ) {
  75. if( m_cxyFixed.cy == 0 ) {
  76. m_cxyFixed.cx = 0;
  77. m_cxyFixed.cy = DEFAULT_SCROLLBAR_SIZE;
  78. }
  79. }
  80. else {
  81. if( m_cxyFixed.cx == 0 ) {
  82. m_cxyFixed.cx = DEFAULT_SCROLLBAR_SIZE;
  83. m_cxyFixed.cy = 0;
  84. }
  85. }
  86. if( m_pOwner != NULL ) m_pOwner->NeedUpdate(); else NeedParentUpdate();
  87. }
  88. int CScrollBarUI::GetScrollRange() const
  89. {
  90. return m_nRange;
  91. }
  92. void CScrollBarUI::SetScrollRange(int nRange)
  93. {
  94. if( m_nRange == nRange ) return;
  95. m_nRange = nRange;
  96. if( m_nRange < 0 ) m_nRange = 0;
  97. if( m_nScrollPos > m_nRange ) m_nScrollPos = m_nRange;
  98. SetPos(m_rcItem, true);
  99. }
  100. int CScrollBarUI::GetScrollPos() const
  101. {
  102. return m_nScrollPos;
  103. }
  104. void CScrollBarUI::SetScrollPos(int nPos, bool bTriggerEvent)
  105. {
  106. if( m_nScrollPos == nPos ) return;
  107. int iOldScrollPos = m_nScrollPos;
  108. m_nScrollPos = nPos;
  109. if( m_nScrollPos < 0 ) m_nScrollPos = 0;
  110. if( m_nScrollPos > m_nRange ) m_nScrollPos = m_nRange;
  111. SetPos(m_rcItem, true);
  112. if(bTriggerEvent && m_pManager != NULL)
  113. m_pManager->SendNotify(this, DUI_MSGTYPE_SCROLL, m_nScrollPos, iOldScrollPos, true, false);
  114. }
  115. int CScrollBarUI::GetLineSize() const
  116. {
  117. return m_nLineSize;
  118. }
  119. void CScrollBarUI::SetLineSize(int nSize)
  120. {
  121. m_nLineSize = nSize;
  122. }
  123. bool CScrollBarUI::GetShowButton1()
  124. {
  125. return m_bShowButton1;
  126. }
  127. void CScrollBarUI::SetShowButton1(bool bShow)
  128. {
  129. m_bShowButton1 = bShow;
  130. SetPos(m_rcItem, true);
  131. }
  132. DWORD CScrollBarUI::GetButton1Color() const
  133. {
  134. return m_dwButton1Color;
  135. }
  136. void CScrollBarUI::SetButton1Color(DWORD dwColor)
  137. {
  138. if( m_dwButton1Color == dwColor ) return;
  139. m_dwButton1Color = dwColor;
  140. Invalidate();
  141. }
  142. LPCTSTR CScrollBarUI::GetButton1NormalImage()
  143. {
  144. return m_diButton1Normal.sDrawString;
  145. }
  146. void CScrollBarUI::SetButton1NormalImage(LPCTSTR pStrImage)
  147. {
  148. if( m_diButton1Normal.sDrawString == pStrImage && m_diButton1Normal.pImageInfo != NULL ) return;
  149. m_diButton1Normal.Clear();
  150. m_diButton1Normal.sDrawString = pStrImage;
  151. Invalidate();
  152. }
  153. LPCTSTR CScrollBarUI::GetButton1HotImage()
  154. {
  155. return m_diButton1Hot.sDrawString;
  156. }
  157. void CScrollBarUI::SetButton1HotImage(LPCTSTR pStrImage)
  158. {
  159. if( m_diButton1Hot.sDrawString == pStrImage && m_diButton1Hot.pImageInfo != NULL ) return;
  160. m_diButton1Hot.Clear();
  161. m_diButton1Hot.sDrawString = pStrImage;
  162. Invalidate();
  163. }
  164. LPCTSTR CScrollBarUI::GetButton1PushedImage()
  165. {
  166. return m_diButton1Pushed.sDrawString;
  167. }
  168. void CScrollBarUI::SetButton1PushedImage(LPCTSTR pStrImage)
  169. {
  170. if( m_diButton1Pushed.sDrawString == pStrImage && m_diButton1Pushed.pImageInfo != NULL ) return;
  171. m_diButton1Pushed.Clear();
  172. m_diButton1Pushed.sDrawString = pStrImage;
  173. Invalidate();
  174. }
  175. LPCTSTR CScrollBarUI::GetButton1DisabledImage()
  176. {
  177. return m_diButton1Disabled.sDrawString;
  178. }
  179. void CScrollBarUI::SetButton1DisabledImage(LPCTSTR pStrImage)
  180. {
  181. if( m_diButton1Disabled.sDrawString == pStrImage && m_diButton1Disabled.pImageInfo != NULL ) return;
  182. m_diButton1Disabled.Clear();
  183. m_diButton1Disabled.sDrawString = pStrImage;
  184. Invalidate();
  185. }
  186. bool CScrollBarUI::GetShowButton2()
  187. {
  188. return m_bShowButton2;
  189. }
  190. void CScrollBarUI::SetShowButton2(bool bShow)
  191. {
  192. m_bShowButton2 = bShow;
  193. SetPos(m_rcItem, true);
  194. }
  195. DWORD CScrollBarUI::GetButton2Color() const
  196. {
  197. return m_dwButton2Color;
  198. }
  199. void CScrollBarUI::SetButton2Color(DWORD dwColor)
  200. {
  201. if( m_dwButton2Color == dwColor ) return;
  202. m_dwButton2Color = dwColor;
  203. Invalidate();
  204. }
  205. LPCTSTR CScrollBarUI::GetButton2NormalImage()
  206. {
  207. return m_diButton2Normal.sDrawString;
  208. }
  209. void CScrollBarUI::SetButton2NormalImage(LPCTSTR pStrImage)
  210. {
  211. if( m_diButton2Normal.sDrawString == pStrImage && m_diButton2Normal.pImageInfo != NULL ) return;
  212. m_diButton2Normal.Clear();
  213. m_diButton2Normal.sDrawString = pStrImage;
  214. Invalidate();
  215. }
  216. LPCTSTR CScrollBarUI::GetButton2HotImage()
  217. {
  218. return m_diButton2Hot.sDrawString;
  219. }
  220. void CScrollBarUI::SetButton2HotImage(LPCTSTR pStrImage)
  221. {
  222. if( m_diButton2Hot.sDrawString == pStrImage && m_diButton2Hot.pImageInfo != NULL ) return;
  223. m_diButton2Hot.Clear();
  224. m_diButton2Hot.sDrawString = pStrImage;
  225. Invalidate();
  226. }
  227. LPCTSTR CScrollBarUI::GetButton2PushedImage()
  228. {
  229. return m_diButton2Pushed.sDrawString;
  230. }
  231. void CScrollBarUI::SetButton2PushedImage(LPCTSTR pStrImage)
  232. {
  233. if( m_diButton2Pushed.sDrawString == pStrImage && m_diButton2Pushed.pImageInfo != NULL ) return;
  234. m_diButton2Pushed.Clear();
  235. m_diButton2Pushed.sDrawString = pStrImage;
  236. Invalidate();
  237. }
  238. LPCTSTR CScrollBarUI::GetButton2DisabledImage()
  239. {
  240. return m_diButton2Disabled.sDrawString;
  241. }
  242. void CScrollBarUI::SetButton2DisabledImage(LPCTSTR pStrImage)
  243. {
  244. if( m_diButton2Disabled.sDrawString == pStrImage && m_diButton2Disabled.pImageInfo != NULL ) return;
  245. m_diButton2Disabled.Clear();
  246. m_diButton2Disabled.sDrawString = pStrImage;
  247. Invalidate();
  248. }
  249. DWORD CScrollBarUI::GetThumbColor() const
  250. {
  251. return m_dwThumbColor;
  252. }
  253. void CScrollBarUI::SetThumbColor(DWORD dwColor)
  254. {
  255. if( m_dwThumbColor == dwColor ) return;
  256. m_dwThumbColor = dwColor;
  257. Invalidate();
  258. }
  259. LPCTSTR CScrollBarUI::GetThumbNormalImage()
  260. {
  261. return m_diThumbNormal.sDrawString;
  262. }
  263. void CScrollBarUI::SetThumbNormalImage(LPCTSTR pStrImage)
  264. {
  265. if( m_diThumbNormal.sDrawString == pStrImage && m_diThumbNormal.pImageInfo != NULL ) return;
  266. m_diThumbNormal.Clear();
  267. m_diThumbNormal.sDrawString = pStrImage;
  268. Invalidate();
  269. }
  270. LPCTSTR CScrollBarUI::GetThumbHotImage()
  271. {
  272. return m_diThumbHot.sDrawString;
  273. }
  274. void CScrollBarUI::SetThumbHotImage(LPCTSTR pStrImage)
  275. {
  276. if( m_diThumbHot.sDrawString == pStrImage && m_diThumbHot.pImageInfo != NULL ) return;
  277. m_diThumbHot.Clear();
  278. m_diThumbHot.sDrawString = pStrImage;
  279. Invalidate();
  280. }
  281. LPCTSTR CScrollBarUI::GetThumbPushedImage()
  282. {
  283. return m_diThumbPushed.sDrawString;
  284. }
  285. void CScrollBarUI::SetThumbPushedImage(LPCTSTR pStrImage)
  286. {
  287. if( m_diThumbPushed.sDrawString == pStrImage && m_diThumbPushed.pImageInfo != NULL ) return;
  288. m_diThumbPushed.Clear();
  289. m_diThumbPushed.sDrawString = pStrImage;
  290. Invalidate();
  291. }
  292. LPCTSTR CScrollBarUI::GetThumbDisabledImage()
  293. {
  294. return m_diThumbDisabled.sDrawString;
  295. }
  296. void CScrollBarUI::SetThumbDisabledImage(LPCTSTR pStrImage)
  297. {
  298. if( m_diThumbDisabled.sDrawString == pStrImage && m_diThumbDisabled.pImageInfo != NULL ) return;
  299. m_diThumbDisabled.Clear();
  300. m_diThumbDisabled.sDrawString = pStrImage;
  301. Invalidate();
  302. }
  303. LPCTSTR CScrollBarUI::GetRailNormalImage()
  304. {
  305. return m_diRailNormal.sDrawString;
  306. }
  307. void CScrollBarUI::SetRailNormalImage(LPCTSTR pStrImage)
  308. {
  309. if( m_diRailNormal.sDrawString == pStrImage && m_diRailNormal.pImageInfo != NULL ) return;
  310. m_diRailNormal.Clear();
  311. m_diRailNormal.sDrawString = pStrImage;
  312. Invalidate();
  313. }
  314. LPCTSTR CScrollBarUI::GetRailHotImage()
  315. {
  316. return m_diRailHot.sDrawString;
  317. }
  318. void CScrollBarUI::SetRailHotImage(LPCTSTR pStrImage)
  319. {
  320. if( m_diRailHot.sDrawString == pStrImage && m_diRailHot.pImageInfo != NULL ) return;
  321. m_diRailHot.Clear();
  322. m_diRailHot.sDrawString = pStrImage;
  323. Invalidate();
  324. }
  325. LPCTSTR CScrollBarUI::GetRailPushedImage()
  326. {
  327. return m_diRailPushed.sDrawString;
  328. }
  329. void CScrollBarUI::SetRailPushedImage(LPCTSTR pStrImage)
  330. {
  331. if( m_diRailPushed.sDrawString == pStrImage && m_diRailPushed.pImageInfo != NULL ) return;
  332. m_diRailPushed.Clear();
  333. m_diRailPushed.sDrawString = pStrImage;
  334. Invalidate();
  335. }
  336. LPCTSTR CScrollBarUI::GetRailDisabledImage()
  337. {
  338. return m_diRailDisabled.sDrawString;
  339. }
  340. void CScrollBarUI::SetRailDisabledImage(LPCTSTR pStrImage)
  341. {
  342. if( m_diRailDisabled.sDrawString == pStrImage && m_diRailDisabled.pImageInfo != NULL ) return;
  343. m_diRailDisabled.Clear();
  344. m_diRailDisabled.sDrawString = pStrImage;
  345. Invalidate();
  346. }
  347. LPCTSTR CScrollBarUI::GetBkNormalImage()
  348. {
  349. return m_diBkNormal.sDrawString;
  350. }
  351. void CScrollBarUI::SetBkNormalImage(LPCTSTR pStrImage)
  352. {
  353. if( m_diBkNormal.sDrawString == pStrImage && m_diBkNormal.pImageInfo != NULL ) return;
  354. m_diBkNormal.Clear();
  355. m_diBkNormal.sDrawString = pStrImage;
  356. Invalidate();
  357. }
  358. LPCTSTR CScrollBarUI::GetBkHotImage()
  359. {
  360. return m_diBkHot.sDrawString;
  361. }
  362. void CScrollBarUI::SetBkHotImage(LPCTSTR pStrImage)
  363. {
  364. if( m_diBkHot.sDrawString == pStrImage && m_diBkHot.pImageInfo != NULL ) return;
  365. m_diBkHot.Clear();
  366. m_diBkHot.sDrawString = pStrImage;
  367. Invalidate();
  368. }
  369. LPCTSTR CScrollBarUI::GetBkPushedImage()
  370. {
  371. return m_diBkPushed.sDrawString;
  372. }
  373. void CScrollBarUI::SetBkPushedImage(LPCTSTR pStrImage)
  374. {
  375. if( m_diBkPushed.sDrawString == pStrImage && m_diBkPushed.pImageInfo != NULL ) return;
  376. m_diBkPushed.Clear();
  377. m_diBkPushed.sDrawString = pStrImage;
  378. Invalidate();
  379. }
  380. LPCTSTR CScrollBarUI::GetBkDisabledImage()
  381. {
  382. return m_diBkDisabled.sDrawString;
  383. }
  384. void CScrollBarUI::SetBkDisabledImage(LPCTSTR pStrImage)
  385. {
  386. if( m_diBkDisabled.sDrawString == pStrImage && m_diBkDisabled.pImageInfo != NULL ) return;
  387. m_diBkDisabled.Clear();
  388. m_diBkDisabled.sDrawString = pStrImage;
  389. Invalidate();
  390. }
  391. void CScrollBarUI::SetPos(RECT rc, bool bNeedInvalidate)
  392. {
  393. CControlUI::SetPos(rc, bNeedInvalidate);
  394. rc = m_rcItem;
  395. if( m_bHorizontal ) {
  396. int cx = rc.right - rc.left;
  397. if( m_bShowButton1 ) cx -= m_cxyFixed.cy;
  398. if( m_bShowButton2 ) cx -= m_cxyFixed.cy;
  399. if( cx > m_cxyFixed.cy ) {
  400. m_rcButton1.left = rc.left;
  401. m_rcButton1.top = rc.top;
  402. if( m_bShowButton1 ) {
  403. m_rcButton1.right = rc.left + m_cxyFixed.cy;
  404. m_rcButton1.bottom = rc.top + m_cxyFixed.cy;
  405. }
  406. else {
  407. m_rcButton1.right = m_rcButton1.left;
  408. m_rcButton1.bottom = m_rcButton1.top;
  409. }
  410. m_rcButton2.top = rc.top;
  411. m_rcButton2.right = rc.right;
  412. if( m_bShowButton2 ) {
  413. m_rcButton2.left = rc.right - m_cxyFixed.cy;
  414. m_rcButton2.bottom = rc.top + m_cxyFixed.cy;
  415. }
  416. else {
  417. m_rcButton2.left = m_rcButton2.right;
  418. m_rcButton2.bottom = m_rcButton2.top;
  419. }
  420. m_rcThumb.top = rc.top;
  421. m_rcThumb.bottom = rc.top + m_cxyFixed.cy;
  422. if( m_nRange > 0 ) {
  423. int cxThumb = cx * (rc.right - rc.left) / (m_nRange + rc.right - rc.left);
  424. if( cxThumb < m_cxyFixed.cy ) cxThumb = m_cxyFixed.cy;
  425. m_rcThumb.left = m_nScrollPos * (cx - cxThumb) / m_nRange + m_rcButton1.right;
  426. m_rcThumb.right = m_rcThumb.left + cxThumb;
  427. if( m_rcThumb.right > m_rcButton2.left ) {
  428. m_rcThumb.left = m_rcButton2.left - cxThumb;
  429. m_rcThumb.right = m_rcButton2.left;
  430. }
  431. }
  432. else {
  433. m_rcThumb.left = m_rcButton1.right;
  434. m_rcThumb.right = m_rcButton2.left;
  435. }
  436. }
  437. else {
  438. int cxButton = (rc.right - rc.left) / 2;
  439. if( cxButton > m_cxyFixed.cy ) cxButton = m_cxyFixed.cy;
  440. m_rcButton1.left = rc.left;
  441. m_rcButton1.top = rc.top;
  442. if( m_bShowButton1 ) {
  443. m_rcButton1.right = rc.left + cxButton;
  444. m_rcButton1.bottom = rc.top + m_cxyFixed.cy;
  445. }
  446. else {
  447. m_rcButton1.right = m_rcButton1.left;
  448. m_rcButton1.bottom = m_rcButton1.top;
  449. }
  450. m_rcButton2.top = rc.top;
  451. m_rcButton2.right = rc.right;
  452. if( m_bShowButton2 ) {
  453. m_rcButton2.left = rc.right - cxButton;
  454. m_rcButton2.bottom = rc.top + m_cxyFixed.cy;
  455. }
  456. else {
  457. m_rcButton2.left = m_rcButton2.right;
  458. m_rcButton2.bottom = m_rcButton2.top;
  459. }
  460. ::ZeroMemory(&m_rcThumb, sizeof(m_rcThumb));
  461. }
  462. }
  463. else {
  464. int cy = rc.bottom - rc.top;
  465. if( m_bShowButton1 ) cy -= m_cxyFixed.cx;
  466. if( m_bShowButton2 ) cy -= m_cxyFixed.cx;
  467. if( cy > m_cxyFixed.cx ) {
  468. m_rcButton1.left = rc.left;
  469. m_rcButton1.top = rc.top;
  470. if( m_bShowButton1 ) {
  471. m_rcButton1.right = rc.left + m_cxyFixed.cx;
  472. m_rcButton1.bottom = rc.top + m_cxyFixed.cx;
  473. }
  474. else {
  475. m_rcButton1.right = m_rcButton1.left;
  476. m_rcButton1.bottom = m_rcButton1.top;
  477. }
  478. m_rcButton2.left = rc.left;
  479. m_rcButton2.bottom = rc.bottom;
  480. if( m_bShowButton2 ) {
  481. m_rcButton2.top = rc.bottom - m_cxyFixed.cx;
  482. m_rcButton2.right = rc.left + m_cxyFixed.cx;
  483. }
  484. else {
  485. m_rcButton2.top = m_rcButton2.bottom;
  486. m_rcButton2.right = m_rcButton2.left;
  487. }
  488. m_rcThumb.left = rc.left;
  489. m_rcThumb.right = rc.left + m_cxyFixed.cx;
  490. if( m_nRange > 0 ) {
  491. int cyThumb = cy * (rc.bottom - rc.top) / (m_nRange + rc.bottom - rc.top);
  492. if( cyThumb < m_cxyFixed.cx ) cyThumb = m_cxyFixed.cx;
  493. m_rcThumb.top = m_nScrollPos * (cy - cyThumb) / m_nRange + m_rcButton1.bottom;
  494. m_rcThumb.bottom = m_rcThumb.top + cyThumb;
  495. if( m_rcThumb.bottom > m_rcButton2.top ) {
  496. m_rcThumb.top = m_rcButton2.top - cyThumb;
  497. m_rcThumb.bottom = m_rcButton2.top;
  498. }
  499. }
  500. else {
  501. m_rcThumb.top = m_rcButton1.bottom;
  502. m_rcThumb.bottom = m_rcButton2.top;
  503. }
  504. }
  505. else {
  506. int cyButton = (rc.bottom - rc.top) / 2;
  507. if( cyButton > m_cxyFixed.cx ) cyButton = m_cxyFixed.cx;
  508. m_rcButton1.left = rc.left;
  509. m_rcButton1.top = rc.top;
  510. if( m_bShowButton1 ) {
  511. m_rcButton1.right = rc.left + m_cxyFixed.cx;
  512. m_rcButton1.bottom = rc.top + cyButton;
  513. }
  514. else {
  515. m_rcButton1.right = m_rcButton1.left;
  516. m_rcButton1.bottom = m_rcButton1.top;
  517. }
  518. m_rcButton2.left = rc.left;
  519. m_rcButton2.bottom = rc.bottom;
  520. if( m_bShowButton2 ) {
  521. m_rcButton2.top = rc.bottom - cyButton;
  522. m_rcButton2.right = rc.left + m_cxyFixed.cx;
  523. }
  524. else {
  525. m_rcButton2.top = m_rcButton2.bottom;
  526. m_rcButton2.right = m_rcButton2.left;
  527. }
  528. ::ZeroMemory(&m_rcThumb, sizeof(m_rcThumb));
  529. }
  530. }
  531. }
  532. void CScrollBarUI::DoEvent(TEventUI& event)
  533. {
  534. if( !IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND ) {
  535. if( m_pOwner != NULL ) m_pOwner->DoEvent(event);
  536. else CControlUI::DoEvent(event);
  537. return;
  538. }
  539. if( event.Type == UIEVENT_SETFOCUS )
  540. {
  541. return;
  542. }
  543. if( event.Type == UIEVENT_KILLFOCUS )
  544. {
  545. return;
  546. }
  547. if( event.Type == UIEVENT_BUTTONDOWN || event.Type == UIEVENT_DBLCLICK )
  548. {
  549. if( !IsEnabled() ) return;
  550. m_nLastScrollOffset = 0;
  551. m_nScrollRepeatDelay = 0;
  552. m_pManager->SetTimer(this, DEFAULT_TIMERID, 50U);
  553. if( ::PtInRect(&m_rcButton1, event.ptMouse) ) {
  554. m_uButton1State |= UISTATE_PUSHED;
  555. if( !m_bHorizontal ) {
  556. if( m_pOwner != NULL ) m_pOwner->LineUp();
  557. else SetScrollPos(m_nScrollPos - m_nLineSize);
  558. }
  559. else {
  560. if( m_pOwner != NULL ) m_pOwner->LineLeft();
  561. else SetScrollPos(m_nScrollPos - m_nLineSize);
  562. }
  563. }
  564. else if( ::PtInRect(&m_rcButton2, event.ptMouse) ) {
  565. m_uButton2State |= UISTATE_PUSHED;
  566. if( !m_bHorizontal ) {
  567. if( m_pOwner != NULL ) m_pOwner->LineDown();
  568. else SetScrollPos(m_nScrollPos + m_nLineSize);
  569. }
  570. else {
  571. if( m_pOwner != NULL ) m_pOwner->LineRight();
  572. else SetScrollPos(m_nScrollPos + m_nLineSize);
  573. }
  574. }
  575. else if( ::PtInRect(&m_rcThumb, event.ptMouse) ) {
  576. m_uThumbState |= UISTATE_CAPTURED | UISTATE_PUSHED;
  577. ptLastMouse = event.ptMouse;
  578. m_nLastScrollPos = m_nScrollPos;
  579. }
  580. else {
  581. if( !m_bHorizontal ) {
  582. if( event.ptMouse.y < m_rcThumb.top ) {
  583. if( m_pOwner != NULL ) m_pOwner->PageUp();
  584. else SetScrollPos(m_nScrollPos + m_rcItem.top - m_rcItem.bottom);
  585. }
  586. else if ( event.ptMouse.y > m_rcThumb.bottom ){
  587. if( m_pOwner != NULL ) m_pOwner->PageDown();
  588. else SetScrollPos(m_nScrollPos - m_rcItem.top + m_rcItem.bottom);
  589. }
  590. }
  591. else {
  592. if( event.ptMouse.x < m_rcThumb.left ) {
  593. if( m_pOwner != NULL ) m_pOwner->PageLeft();
  594. else SetScrollPos(m_nScrollPos + m_rcItem.left - m_rcItem.right);
  595. }
  596. else if ( event.ptMouse.x > m_rcThumb.right ){
  597. if( m_pOwner != NULL ) m_pOwner->PageRight();
  598. else SetScrollPos(m_nScrollPos - m_rcItem.left + m_rcItem.right);
  599. }
  600. }
  601. }
  602. return;
  603. }
  604. if( event.Type == UIEVENT_BUTTONUP )
  605. {
  606. m_nScrollRepeatDelay = 0;
  607. m_nLastScrollOffset = 0;
  608. m_pManager->KillTimer(this, DEFAULT_TIMERID);
  609. if( (m_uThumbState & UISTATE_CAPTURED) != 0 ) {
  610. m_uThumbState &= ~( UISTATE_CAPTURED | UISTATE_PUSHED );
  611. Invalidate();
  612. }
  613. else if( (m_uButton1State & UISTATE_PUSHED) != 0 ) {
  614. m_uButton1State &= ~UISTATE_PUSHED;
  615. Invalidate();
  616. }
  617. else if( (m_uButton2State & UISTATE_PUSHED) != 0 ) {
  618. m_uButton2State &= ~UISTATE_PUSHED;
  619. Invalidate();
  620. }
  621. return;
  622. }
  623. if( event.Type == UIEVENT_MOUSEMOVE )
  624. {
  625. if( (m_uThumbState & UISTATE_CAPTURED) != 0 ) {
  626. if( !m_bHorizontal ) {
  627. int vRange = m_rcItem.bottom - m_rcItem.top - m_rcThumb.bottom + m_rcThumb.top - 2 * m_cxyFixed.cx;
  628. if (vRange != 0)
  629. m_nLastScrollOffset = (event.ptMouse.y - ptLastMouse.y) * m_nRange / vRange;
  630. }
  631. else {
  632. int hRange = m_rcItem.right - m_rcItem.left - m_rcThumb.right + m_rcThumb.left - 2 * m_cxyFixed.cy;
  633. if (hRange != 0)
  634. m_nLastScrollOffset = (event.ptMouse.x - ptLastMouse.x) * m_nRange / hRange;
  635. }
  636. }
  637. else {
  638. if( (m_uThumbState & UISTATE_HOT) != 0 ) {
  639. if( !::PtInRect(&m_rcThumb, event.ptMouse) ) {
  640. m_uThumbState &= ~UISTATE_HOT;
  641. Invalidate();
  642. }
  643. }
  644. else {
  645. if( !IsEnabled() ) return;
  646. if( ::PtInRect(&m_rcThumb, event.ptMouse) ) {
  647. m_uThumbState |= UISTATE_HOT;
  648. Invalidate();
  649. }
  650. }
  651. }
  652. return;
  653. }
  654. if( event.Type == UIEVENT_CONTEXTMENU )
  655. {
  656. return;
  657. }
  658. if( event.Type == UIEVENT_TIMER && event.wParam == DEFAULT_TIMERID )
  659. {
  660. ++m_nScrollRepeatDelay;
  661. if( (m_uThumbState & UISTATE_CAPTURED) != 0 ) {
  662. if( !m_bHorizontal ) {
  663. if( m_pOwner != NULL ) m_pOwner->SetScrollPos(CDuiSize(m_pOwner->GetScrollPos().cx, \
  664. m_nLastScrollPos + m_nLastScrollOffset));
  665. else SetScrollPos(m_nLastScrollPos + m_nLastScrollOffset);
  666. }
  667. else {
  668. if( m_pOwner != NULL ) m_pOwner->SetScrollPos(CDuiSize(m_nLastScrollPos + m_nLastScrollOffset, \
  669. m_pOwner->GetScrollPos().cy));
  670. else SetScrollPos(m_nLastScrollPos + m_nLastScrollOffset);
  671. }
  672. Invalidate();
  673. }
  674. else if( (m_uButton1State & UISTATE_PUSHED) != 0 ) {
  675. if( m_nScrollRepeatDelay <= 5 ) return;
  676. if( !m_bHorizontal ) {
  677. if( m_pOwner != NULL ) m_pOwner->LineUp();
  678. else SetScrollPos(m_nScrollPos - m_nLineSize);
  679. }
  680. else {
  681. if( m_pOwner != NULL ) m_pOwner->LineLeft();
  682. else SetScrollPos(m_nScrollPos - m_nLineSize);
  683. }
  684. }
  685. else if( (m_uButton2State & UISTATE_PUSHED) != 0 ) {
  686. if( m_nScrollRepeatDelay <= 5 ) return;
  687. if( !m_bHorizontal ) {
  688. if( m_pOwner != NULL ) m_pOwner->LineDown();
  689. else SetScrollPos(m_nScrollPos + m_nLineSize);
  690. }
  691. else {
  692. if( m_pOwner != NULL ) m_pOwner->LineRight();
  693. else SetScrollPos(m_nScrollPos + m_nLineSize);
  694. }
  695. }
  696. else {
  697. if( m_nScrollRepeatDelay <= 5 ) return;
  698. POINT pt = { 0 };
  699. ::GetCursorPos(&pt);
  700. ::ScreenToClient(m_pManager->GetPaintWindow(), &pt);
  701. if( !m_bHorizontal ) {
  702. if( pt.y < m_rcThumb.top ) {
  703. if( m_pOwner != NULL ) m_pOwner->PageUp();
  704. else SetScrollPos(m_nScrollPos + m_rcItem.top - m_rcItem.bottom);
  705. }
  706. else if ( pt.y > m_rcThumb.bottom ){
  707. if( m_pOwner != NULL ) m_pOwner->PageDown();
  708. else SetScrollPos(m_nScrollPos - m_rcItem.top + m_rcItem.bottom);
  709. }
  710. }
  711. else {
  712. if( pt.x < m_rcThumb.left ) {
  713. if( m_pOwner != NULL ) m_pOwner->PageLeft();
  714. else SetScrollPos(m_nScrollPos + m_rcItem.left - m_rcItem.right);
  715. }
  716. else if ( pt.x > m_rcThumb.right ){
  717. if( m_pOwner != NULL ) m_pOwner->PageRight();
  718. else SetScrollPos(m_nScrollPos - m_rcItem.left + m_rcItem.right);
  719. }
  720. }
  721. }
  722. return;
  723. }
  724. if( event.Type == UIEVENT_MOUSEENTER )
  725. {
  726. if( IsEnabled() ) {
  727. m_uButton1State |= UISTATE_HOT;
  728. m_uButton2State |= UISTATE_HOT;
  729. if( ::PtInRect(&m_rcThumb, event.ptMouse) ) m_uThumbState |= UISTATE_HOT;
  730. Invalidate();
  731. }
  732. return;
  733. }
  734. if( event.Type == UIEVENT_MOUSELEAVE )
  735. {
  736. if( IsEnabled() ) {
  737. m_uButton1State &= ~UISTATE_HOT;
  738. m_uButton2State &= ~UISTATE_HOT;
  739. m_uThumbState &= ~UISTATE_HOT;
  740. Invalidate();
  741. }
  742. return;
  743. }
  744. if( m_pOwner != NULL ) m_pOwner->DoEvent(event); else CControlUI::DoEvent(event);
  745. }
  746. void CScrollBarUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
  747. {
  748. if( _tcscmp(pstrName, _T("button1color")) == 0 ) {
  749. while( *pstrValue > _T('\0') && *pstrValue <= _T(' ') ) pstrValue = ::CharNext(pstrValue);
  750. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  751. LPTSTR pstr = NULL;
  752. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  753. SetButton1Color(clrColor);
  754. }
  755. else if( _tcscmp(pstrName, _T("button1normalimage")) == 0 ) SetButton1NormalImage(pstrValue);
  756. else if( _tcscmp(pstrName, _T("button1hotimage")) == 0 ) SetButton1HotImage(pstrValue);
  757. else if( _tcscmp(pstrName, _T("button1pushedimage")) == 0 ) SetButton1PushedImage(pstrValue);
  758. else if( _tcscmp(pstrName, _T("button1disabledimage")) == 0 ) SetButton1DisabledImage(pstrValue);
  759. else if( _tcscmp(pstrName, _T("button2color")) == 0 ) {
  760. while( *pstrValue > _T('\0') && *pstrValue <= _T(' ') ) pstrValue = ::CharNext(pstrValue);
  761. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  762. LPTSTR pstr = NULL;
  763. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  764. SetButton2Color(clrColor);
  765. }
  766. else if( _tcscmp(pstrName, _T("button2normalimage")) == 0 ) SetButton2NormalImage(pstrValue);
  767. else if( _tcscmp(pstrName, _T("button2hotimage")) == 0 ) SetButton2HotImage(pstrValue);
  768. else if( _tcscmp(pstrName, _T("button2pushedimage")) == 0 ) SetButton2PushedImage(pstrValue);
  769. else if( _tcscmp(pstrName, _T("button2disabledimage")) == 0 ) SetButton2DisabledImage(pstrValue);
  770. else if( _tcscmp(pstrName, _T("thumbcolor")) == 0 ) {
  771. while( *pstrValue > _T('\0') && *pstrValue <= _T(' ') ) pstrValue = ::CharNext(pstrValue);
  772. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  773. LPTSTR pstr = NULL;
  774. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  775. SetThumbColor(clrColor);
  776. }
  777. else if( _tcscmp(pstrName, _T("thumbnormalimage")) == 0 ) SetThumbNormalImage(pstrValue);
  778. else if( _tcscmp(pstrName, _T("thumbhotimage")) == 0 ) SetThumbHotImage(pstrValue);
  779. else if( _tcscmp(pstrName, _T("thumbpushedimage")) == 0 ) SetThumbPushedImage(pstrValue);
  780. else if( _tcscmp(pstrName, _T("thumbdisabledimage")) == 0 ) SetThumbDisabledImage(pstrValue);
  781. else if( _tcscmp(pstrName, _T("railnormalimage")) == 0 ) SetRailNormalImage(pstrValue);
  782. else if( _tcscmp(pstrName, _T("railhotimage")) == 0 ) SetRailHotImage(pstrValue);
  783. else if( _tcscmp(pstrName, _T("railpushedimage")) == 0 ) SetRailPushedImage(pstrValue);
  784. else if( _tcscmp(pstrName, _T("raildisabledimage")) == 0 ) SetRailDisabledImage(pstrValue);
  785. else if( _tcscmp(pstrName, _T("bknormalimage")) == 0 ) SetBkNormalImage(pstrValue);
  786. else if( _tcscmp(pstrName, _T("bkhotimage")) == 0 ) SetBkHotImage(pstrValue);
  787. else if( _tcscmp(pstrName, _T("bkpushedimage")) == 0 ) SetBkPushedImage(pstrValue);
  788. else if( _tcscmp(pstrName, _T("bkdisabledimage")) == 0 ) SetBkDisabledImage(pstrValue);
  789. else if( _tcscmp(pstrName, _T("hor")) == 0 ) SetHorizontal(_tcscmp(pstrValue, _T("true")) == 0);
  790. else if( _tcscmp(pstrName, _T("linesize")) == 0 ) SetLineSize(_ttoi(pstrValue));
  791. else if( _tcscmp(pstrName, _T("range")) == 0 ) SetScrollRange(_ttoi(pstrValue));
  792. else if( _tcscmp(pstrName, _T("value")) == 0 ) SetScrollPos(_ttoi(pstrValue));
  793. else if( _tcscmp(pstrName, _T("showbutton1")) == 0 ) SetShowButton1(_tcscmp(pstrValue, _T("true")) == 0);
  794. else if( _tcscmp(pstrName, _T("showbutton2")) == 0 ) SetShowButton2(_tcscmp(pstrValue, _T("true")) == 0);
  795. else CControlUI::SetAttribute(pstrName, pstrValue);
  796. }
  797. void CScrollBarUI::DoPaint(HDC hDC, const RECT& rcPaint)
  798. {
  799. if( !::IntersectRect(&m_rcPaint, &rcPaint, &m_rcItem) ) return;
  800. PaintBkColor(hDC);
  801. PaintBkImage(hDC);
  802. PaintBk(hDC);
  803. PaintButton1(hDC);
  804. PaintButton2(hDC);
  805. PaintThumb(hDC);
  806. PaintRail(hDC);
  807. PaintBorder(hDC);
  808. }
  809. void CScrollBarUI::PaintBk(HDC hDC)
  810. {
  811. if( !IsEnabled() ) m_uThumbState |= UISTATE_DISABLED;
  812. else m_uThumbState &= ~ UISTATE_DISABLED;
  813. if( (m_uThumbState & UISTATE_DISABLED) != 0 ) {
  814. if( DrawImage(hDC, m_diBkDisabled) ) return;
  815. }
  816. else if( (m_uThumbState & UISTATE_PUSHED) != 0 ) {
  817. if( DrawImage(hDC, m_diBkPushed) ) return;
  818. }
  819. else if( (m_uThumbState & UISTATE_HOT) != 0 ) {
  820. if( DrawImage(hDC, m_diBkHot) ) return;
  821. }
  822. if( DrawImage(hDC, m_diBkNormal) ) return;
  823. }
  824. void CScrollBarUI::PaintButton1(HDC hDC)
  825. {
  826. if( !m_bShowButton1 ) return;
  827. if( !IsEnabled() ) m_uButton1State |= UISTATE_DISABLED;
  828. else m_uButton1State &= ~ UISTATE_DISABLED;
  829. RECT rc = { 0 };
  830. rc.left = m_rcButton1.left - m_rcItem.left;
  831. rc.top = m_rcButton1.top - m_rcItem.top;
  832. rc.right = m_rcButton1.right - m_rcItem.left;
  833. rc.bottom = m_rcButton1.bottom - m_rcItem.top;
  834. if( m_dwButton1Color != 0 ) {
  835. if( m_dwButton1Color >= 0xFF000000 ) CRenderEngine::DrawColor(hDC, m_rcButton1, GetAdjustColor(m_dwButton1Color));
  836. else CRenderEngine::DrawColor(hDC, m_rcButton1, GetAdjustColor(m_dwButton1Color));
  837. }
  838. if( (m_uButton1State & UISTATE_DISABLED) != 0 ) {
  839. m_diButton1Disabled.rcDestOffset = rc;
  840. if( DrawImage(hDC, m_diButton1Disabled) ) return;
  841. }
  842. else if( (m_uButton1State & UISTATE_PUSHED) != 0 ) {
  843. m_diButton1Pushed.rcDestOffset = rc;
  844. if( DrawImage(hDC, m_diButton1Pushed) ) return;
  845. }
  846. else if( (m_uButton1State & UISTATE_HOT) != 0 ) {
  847. m_diButton1Hot.rcDestOffset = rc;
  848. if( DrawImage(hDC, m_diButton1Hot) ) return;
  849. }
  850. m_diButton1Normal.rcDestOffset = rc;
  851. if( DrawImage(hDC, m_diButton1Normal) ) return;
  852. }
  853. void CScrollBarUI::PaintButton2(HDC hDC)
  854. {
  855. if( !m_bShowButton2 ) return;
  856. if( !IsEnabled() ) m_uButton2State |= UISTATE_DISABLED;
  857. else m_uButton2State &= ~ UISTATE_DISABLED;
  858. RECT rc = { 0 };
  859. rc.left = m_rcButton2.left - m_rcItem.left;
  860. rc.top = m_rcButton2.top - m_rcItem.top;
  861. rc.right = m_rcButton2.right - m_rcItem.left;
  862. rc.bottom = m_rcButton2.bottom - m_rcItem.top;
  863. if( m_dwButton2Color != 0 ) {
  864. if( m_dwButton2Color >= 0xFF000000 ) CRenderEngine::DrawColor(hDC, m_rcButton2, GetAdjustColor(m_dwButton2Color));
  865. else CRenderEngine::DrawColor(hDC, m_rcButton2, GetAdjustColor(m_dwButton2Color));
  866. }
  867. if( (m_uButton2State & UISTATE_DISABLED) != 0 ) {
  868. m_diButton2Disabled.rcDestOffset = rc;
  869. if( DrawImage(hDC, m_diButton2Disabled) ) return;
  870. }
  871. else if( (m_uButton2State & UISTATE_PUSHED) != 0 ) {
  872. m_diButton2Pushed.rcDestOffset = rc;
  873. if( DrawImage(hDC, m_diButton2Pushed) ) return;
  874. }
  875. else if( (m_uButton2State & UISTATE_HOT) != 0 ) {
  876. m_diButton2Hot.rcDestOffset = rc;
  877. if( DrawImage(hDC, m_diButton2Hot) ) return;
  878. }
  879. m_diButton2Normal.rcDestOffset = rc;
  880. if( DrawImage(hDC, m_diButton2Normal) ) return;
  881. }
  882. void CScrollBarUI::PaintThumb(HDC hDC)
  883. {
  884. if( m_rcThumb.left == 0 && m_rcThumb.top == 0 && m_rcThumb.right == 0 && m_rcThumb.bottom == 0 ) return;
  885. if( !IsEnabled() ) m_uThumbState |= UISTATE_DISABLED;
  886. else m_uThumbState &= ~ UISTATE_DISABLED;
  887. RECT rc = { 0 };
  888. rc.left = m_rcThumb.left - m_rcItem.left;
  889. rc.top = m_rcThumb.top - m_rcItem.top;
  890. rc.right = m_rcThumb.right - m_rcItem.left;
  891. rc.bottom = m_rcThumb.bottom - m_rcItem.top;
  892. if( m_dwThumbColor != 0 ) {
  893. if( m_dwThumbColor >= 0xFF000000 ) CRenderEngine::DrawColor(hDC, m_rcThumb, GetAdjustColor(m_dwThumbColor));
  894. else CRenderEngine::DrawColor(hDC, m_rcThumb, GetAdjustColor(m_dwThumbColor));
  895. }
  896. if( (m_uThumbState & UISTATE_DISABLED) != 0 ) {
  897. m_diThumbDisabled.rcDestOffset = rc;
  898. if( DrawImage(hDC, m_diThumbDisabled) ) return;
  899. }
  900. else if( (m_uThumbState & UISTATE_PUSHED) != 0 ) {
  901. m_diThumbPushed.rcDestOffset = rc;
  902. if( DrawImage(hDC, m_diThumbPushed) ) return;
  903. }
  904. else if( (m_uThumbState & UISTATE_HOT) != 0 ) {
  905. m_diThumbHot.rcDestOffset = rc;
  906. if( DrawImage(hDC, m_diThumbHot) ) return;
  907. }
  908. m_diThumbNormal.rcDestOffset = rc;
  909. if( DrawImage(hDC, m_diThumbNormal) ) return;
  910. }
  911. void CScrollBarUI::PaintRail(HDC hDC)
  912. {
  913. if( m_rcThumb.left == 0 && m_rcThumb.top == 0 && m_rcThumb.right == 0 && m_rcThumb.bottom == 0 ) return;
  914. if( !IsEnabled() ) m_uThumbState |= UISTATE_DISABLED;
  915. else m_uThumbState &= ~ UISTATE_DISABLED;
  916. RECT rc = { 0 };
  917. if( !m_bHorizontal ) {
  918. rc.left = m_rcThumb.left - m_rcItem.left;
  919. rc.top = (m_rcThumb.top + m_rcThumb.bottom) / 2 - m_rcItem.top - m_cxyFixed.cx / 2;
  920. rc.right = m_rcThumb.right - m_rcItem.left;
  921. rc.bottom = (m_rcThumb.top + m_rcThumb.bottom) / 2 - m_rcItem.top + m_cxyFixed.cx - m_cxyFixed.cx / 2;
  922. }
  923. else {
  924. rc.left = (m_rcThumb.left + m_rcThumb.right) / 2 - m_rcItem.left - m_cxyFixed.cy / 2;
  925. rc.top = m_rcThumb.top - m_rcItem.top;
  926. rc.right = (m_rcThumb.left + m_rcThumb.right) / 2 - m_rcItem.left + m_cxyFixed.cy - m_cxyFixed.cy / 2;
  927. rc.bottom = m_rcThumb.bottom - m_rcItem.top;
  928. }
  929. if( (m_uThumbState & UISTATE_DISABLED) != 0 ) {
  930. m_diRailDisabled.rcDestOffset = rc;
  931. if( DrawImage(hDC, m_diRailDisabled) ) return;
  932. }
  933. else if( (m_uThumbState & UISTATE_PUSHED) != 0 ) {
  934. m_diRailPushed.rcDestOffset = rc;
  935. if( DrawImage(hDC, m_diRailPushed) ) return;
  936. }
  937. else if( (m_uThumbState & UISTATE_HOT) != 0 ) {
  938. m_diRailHot.rcDestOffset = rc;
  939. if( DrawImage(hDC, m_diRailHot) ) return;
  940. }
  941. m_diRailNormal.rcDestOffset = rc;
  942. if( DrawImage(hDC, m_diRailNormal) ) return;
  943. }
  944. } // namespace DuiLib