UIScrollBar.cpp 31 KB

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