Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5927 lines
155 KiB

  1. //
  2. // cuiobj.cpp
  3. // = ui object library =
  4. //
  5. #include "private.h"
  6. #include "delay.h"
  7. #include "cuiobj.h"
  8. #include "cuiwnd.h"
  9. #include "cuitip.h"
  10. #include "cmydc.h"
  11. #include "cuiutil.h"
  12. #include "cuitheme.h"
  13. #define SCROLLTHUMBHEIGHT_MIN 6
  14. /* G E T S C R O L L D E L A Y */
  15. /*------------------------------------------------------------------------------
  16. Get delay time to start auto scroll (while the scroll button down)
  17. The time is in milli-second
  18. ------------------------------------------------------------------------------*/
  19. __inline UINT GetScrollDelay( void )
  20. {
  21. return (GetDoubleClickTime() * 4 / 5);
  22. }
  23. /* G E T S C R O L L S P E E D */
  24. /*------------------------------------------------------------------------------
  25. Get repeat time in auto scroll (while the scroll button down)
  26. The time is in milli-second
  27. ------------------------------------------------------------------------------*/
  28. __inline UINT GetScrollSpeed( void )
  29. {
  30. return (GetScrollDelay() / 8);
  31. }
  32. /*=============================================================================*/
  33. /* */
  34. /* C U I F O B J E C T */
  35. /* */
  36. /*=============================================================================*/
  37. /* C U I F O B J E C T */
  38. /*------------------------------------------------------------------------------
  39. Constructor of CUIFObject
  40. ------------------------------------------------------------------------------*/
  41. CUIFObject::CUIFObject( CUIFObject *pParent, DWORD dwID, const RECT *prc, DWORD dwStyle )
  42. {
  43. m_pParent = pParent;
  44. m_dwID = dwID;
  45. m_dwStyle = dwStyle;
  46. ::SetRect( &m_rc, 0, 0, 0, 0 );
  47. if (prc != NULL) {
  48. m_rc = *prc;
  49. }
  50. m_pUIWnd = NULL;
  51. if (m_pParent != NULL) {
  52. m_pUIWnd = pParent->GetUIWnd();
  53. }
  54. m_pUIFScheme = NULL;
  55. if (m_pParent != NULL) {
  56. m_pUIFScheme = pParent->GetUIFScheme();
  57. }
  58. m_fEnabled = TRUE;
  59. m_fVisible = TRUE;
  60. m_hFont = (HFONT)GetStockObject( DEFAULT_GUI_FONT );
  61. m_fUseCustomFont = FALSE;
  62. m_pwchToolTip = NULL;
  63. m_pointPreferredSize.x=m_pointPreferredSize.y=-1;
  64. #if defined(_DEBUG) || defined(DEBUG)
  65. m_fInitialized = FALSE;
  66. #endif /* DEBUG */
  67. }
  68. /* ~ C U I F O B J E C T */
  69. /*------------------------------------------------------------------------------
  70. Destructor of CUIFObject
  71. ------------------------------------------------------------------------------*/
  72. CUIFObject::~CUIFObject( void )
  73. {
  74. CUIFObject *pUIObj;
  75. #if defined(_DEBUG) || defined(DEBUG)
  76. Assert( m_fInitialized );
  77. #endif /* DEBUG */
  78. // dispose buffer
  79. if (m_pUIWnd != NULL) {
  80. CUIFToolTip *pTipWnd = m_pUIWnd->GetToolTipWnd();
  81. if (pTipWnd && (this == pTipWnd->GetCurrentObj()))
  82. pTipWnd->ClearCurrentObj();
  83. }
  84. if (m_pwchToolTip != NULL) {
  85. delete m_pwchToolTip;
  86. }
  87. // delete children
  88. while (pUIObj = m_ChildList.GetLast()) {
  89. m_ChildList.Remove( pUIObj );
  90. delete pUIObj;
  91. }
  92. // to clear capture/timer/pointed status call RemoveUIObj of UIFrameWindow
  93. if (m_pUIWnd != NULL) {
  94. m_pUIWnd->RemoveUIObj( this );
  95. }
  96. }
  97. /* I N I T I A L I Z E */
  98. /*------------------------------------------------------------------------------
  99. Inititalize the object
  100. Returns TRUE when succeed to initialize, FALSE when failed.
  101. This function MUST be called when create a object.
  102. ------------------------------------------------------------------------------*/
  103. CUIFObject *CUIFObject::Initialize( void )
  104. {
  105. #if defined(_DEBUG) || defined(DEBUG)
  106. Assert( !m_fInitialized );
  107. m_fInitialized = TRUE;
  108. #endif /* DEBUG */
  109. return this;
  110. }
  111. /* C A L L O N P A I N T */
  112. /*------------------------------------------------------------------------------
  113. ------------------------------------------------------------------------------*/
  114. void CUIFObject::CallOnPaint( void )
  115. {
  116. if (m_pUIWnd != NULL) {
  117. m_pUIWnd->UpdateUI(&GetRectRef());
  118. }
  119. }
  120. /* O N P A I N T */
  121. /*------------------------------------------------------------------------------
  122. Paint procedure of button object
  123. ------------------------------------------------------------------------------*/
  124. void CUIFObject::OnPaint( HDC hDC )
  125. {
  126. BOOL fDefault = TRUE;
  127. if ((GetUIWnd()->GetStyle() & UIWINDOW_WHISTLERLOOK) != 0) {
  128. fDefault = !OnPaintTheme( hDC );
  129. }
  130. if (fDefault) {
  131. OnPaintNoTheme( hDC );
  132. }
  133. }
  134. /* S T A R T C A P T U R E */
  135. /*------------------------------------------------------------------------------
  136. Start capturing mouse
  137. ------------------------------------------------------------------------------*/
  138. void CUIFObject::StartCapture( void )
  139. {
  140. if (m_pUIWnd != NULL) {
  141. m_pUIWnd->SetCaptureObject( this );
  142. }
  143. }
  144. /* E N D C A P T U R E */
  145. /*------------------------------------------------------------------------------
  146. End capturing mouse
  147. ------------------------------------------------------------------------------*/
  148. void CUIFObject::EndCapture( void )
  149. {
  150. if (m_pUIWnd != NULL) {
  151. m_pUIWnd->SetCaptureObject( NULL );
  152. }
  153. }
  154. /* S T A R T T I M E R */
  155. /*------------------------------------------------------------------------------
  156. Make timer
  157. ------------------------------------------------------------------------------*/
  158. void CUIFObject::StartTimer( UINT uElapse )
  159. {
  160. if (m_pUIWnd != NULL) {
  161. m_pUIWnd->SetTimerObject( this, uElapse );
  162. }
  163. }
  164. /* E N D T I M E R */
  165. /*------------------------------------------------------------------------------
  166. Kill timer
  167. ------------------------------------------------------------------------------*/
  168. void CUIFObject::EndTimer( void )
  169. {
  170. if (m_pUIWnd != NULL) {
  171. m_pUIWnd->SetTimerObject( NULL );
  172. }
  173. }
  174. /* I S C A P T U R E */
  175. /*------------------------------------------------------------------------------
  176. Check if the object is capturing mouse
  177. ------------------------------------------------------------------------------*/
  178. BOOL CUIFObject::IsCapture( void )
  179. {
  180. if (m_pUIWnd != NULL) {
  181. return (m_pUIWnd->GetCaptureObject() == this);
  182. }
  183. return FALSE;
  184. }
  185. /* I S T I M E R */
  186. /*------------------------------------------------------------------------------
  187. Check if the object has timer
  188. ------------------------------------------------------------------------------*/
  189. BOOL CUIFObject::IsTimer( void )
  190. {
  191. if (m_pUIWnd != NULL) {
  192. return (m_pUIWnd->GetTimerObject() == this);
  193. }
  194. return FALSE;
  195. }
  196. /* G E T R E C T */
  197. /*------------------------------------------------------------------------------
  198. Get rectangle of object
  199. ------------------------------------------------------------------------------*/
  200. void CUIFObject::GetRect( RECT *prc )
  201. {
  202. *prc = GetRectRef();
  203. }
  204. /* S E T R E C T */
  205. /*------------------------------------------------------------------------------
  206. Set rectangle of object
  207. ------------------------------------------------------------------------------*/
  208. void CUIFObject::SetRect( const RECT *prc )
  209. {
  210. Assert(PtrToInt(prc));
  211. m_rc = *prc;
  212. if (m_pUIWnd != NULL) {
  213. m_pUIWnd->OnObjectMoved( this );
  214. }
  215. CallOnPaint();
  216. }
  217. /* P T I N O B J E C T */
  218. /*------------------------------------------------------------------------------
  219. Check if point is in the object
  220. ------------------------------------------------------------------------------*/
  221. BOOL CUIFObject::PtInObject( POINT pt )
  222. {
  223. return m_fVisible && PtInRect( &GetRectRef(), pt );
  224. }
  225. /* E N A B L E */
  226. /*------------------------------------------------------------------------------
  227. Enable/disable object
  228. ------------------------------------------------------------------------------*/
  229. void CUIFObject::Enable( BOOL fEnable )
  230. {
  231. if (m_fEnabled != fEnable) {
  232. int nChild;
  233. int i;
  234. m_fEnabled = fEnable;
  235. // enable/disable all children
  236. nChild = m_ChildList.GetCount();
  237. for (i = 0; i < nChild; i++) {
  238. CUIFObject *pUIObj = m_ChildList.Get( i );
  239. Assert( pUIObj != NULL );
  240. pUIObj->Enable( fEnable );
  241. }
  242. CallOnPaint();
  243. }
  244. }
  245. /* S H O W */
  246. /*------------------------------------------------------------------------------
  247. Show/hide object
  248. ------------------------------------------------------------------------------*/
  249. void CUIFObject::Show( BOOL fShow )
  250. {
  251. if (m_fVisible != fShow) {
  252. int nChild;
  253. int i;
  254. m_fVisible = fShow;
  255. // show/hide all children
  256. nChild = m_ChildList.GetCount();
  257. for (i = 0; i < nChild; i++) {
  258. CUIFObject *pUIObj = m_ChildList.Get( i );
  259. Assert( pUIObj != NULL );
  260. pUIObj->Show( fShow );
  261. }
  262. // let parent paint the object when it's hidden
  263. if (!m_fVisible) {
  264. if (m_pParent != NULL) {
  265. m_pParent->CallOnPaint();
  266. }
  267. }
  268. else {
  269. CallOnPaint();
  270. }
  271. }
  272. }
  273. /* S E T F O N T */
  274. /*------------------------------------------------------------------------------
  275. Set font
  276. ------------------------------------------------------------------------------*/
  277. void CUIFObject::SetFontToThis( HFONT hFont )
  278. {
  279. if (hFont == NULL) {
  280. hFont = (HFONT)GetStockObject( DEFAULT_GUI_FONT );
  281. m_fUseCustomFont = FALSE;
  282. } else {
  283. m_fUseCustomFont = TRUE;
  284. }
  285. m_hFont = hFont;
  286. }
  287. /* S E T F O N T */
  288. /*------------------------------------------------------------------------------
  289. Set font
  290. ------------------------------------------------------------------------------*/
  291. void CUIFObject::SetFont( HFONT hFont )
  292. {
  293. int nChild;
  294. int i;
  295. SetFontToThis(hFont);
  296. // set font to all children
  297. nChild = m_ChildList.GetCount();
  298. for (i = 0; i < nChild; i++) {
  299. CUIFObject *pUIObj = m_ChildList.Get( i );
  300. Assert( pUIObj != NULL );
  301. pUIObj->SetFont( hFont );
  302. }
  303. CallOnPaint();
  304. }
  305. /* S E T S T Y L E */
  306. /*------------------------------------------------------------------------------
  307. Set the style of object
  308. ------------------------------------------------------------------------------*/
  309. void CUIFObject::SetStyle( DWORD dwStyle )
  310. {
  311. m_dwStyle = dwStyle;
  312. }
  313. /* P A I N T O B J E C T */
  314. /*------------------------------------------------------------------------------
  315. Paint object
  316. NOTE: Paint itself at first (actual paint is done in OnPaint()), and then
  317. paint all children if exist.
  318. ------------------------------------------------------------------------------*/
  319. void CUIFObject::PaintObject( HDC hDC, const RECT *prcUpdate )
  320. {
  321. int nChild;
  322. int i;
  323. if (prcUpdate == NULL) {
  324. prcUpdate = &GetRectRef();
  325. }
  326. if (m_fVisible) {
  327. // paint itself at first
  328. OnPaint( hDC );
  329. // paint all children
  330. nChild = m_ChildList.GetCount();
  331. for (i = 0; i < nChild; i++) {
  332. CUIFObject *pUIObj = m_ChildList.Get( i );
  333. RECT rcDest;
  334. Assert( pUIObj != NULL );
  335. if (IntersectRect( &rcDest, prcUpdate, &pUIObj->GetRectRef() )) {
  336. pUIObj->PaintObject( hDC, &rcDest );
  337. }
  338. }
  339. }
  340. }
  341. /* A D D U I O B J */
  342. /*------------------------------------------------------------------------------
  343. Add child UI object
  344. ------------------------------------------------------------------------------*/
  345. void CUIFObject::AddUIObj( CUIFObject *pUIObj )
  346. {
  347. Assert( pUIObj != NULL );
  348. Assert( pUIObj->FInitialized() );
  349. if (m_ChildList.Add( pUIObj )) {
  350. CallOnPaint();
  351. }
  352. }
  353. /* R E M O V E U I O B J */
  354. /*------------------------------------------------------------------------------
  355. Remove child UI object
  356. ------------------------------------------------------------------------------*/
  357. void CUIFObject::RemoveUIObj( CUIFObject *pUIObj )
  358. {
  359. Assert( pUIObj != NULL );
  360. if (m_ChildList.Remove( pUIObj )) {
  361. CallOnPaint();
  362. }
  363. }
  364. /* O B J E C T F R O M P O I N T */
  365. /*------------------------------------------------------------------------------
  366. Get UI object from point
  367. Returns UI object which is under of the point. If no UI object found,
  368. returns NULL.
  369. ------------------------------------------------------------------------------*/
  370. CUIFObject *CUIFObject::ObjectFromPoint( POINT pt )
  371. {
  372. CUIFObject *pUIObjFromPoint = NULL;
  373. if (PtInObject( pt )) {
  374. int nChild;
  375. int i;
  376. pUIObjFromPoint = this;
  377. nChild = m_ChildList.GetCount();
  378. for (i = 0; i < nChild; i++) {
  379. CUIFObject *pUIObj = m_ChildList.Get( i );
  380. CUIFObject *pUIObjFromPointChild = NULL;
  381. Assert( pUIObj != NULL );
  382. pUIObjFromPointChild = pUIObj->ObjectFromPoint( pt );
  383. if (pUIObjFromPointChild != NULL) {
  384. pUIObjFromPoint = pUIObjFromPointChild;
  385. }
  386. }
  387. }
  388. return pUIObjFromPoint;
  389. }
  390. /* O N O B J E C T N O T I F Y */
  391. /*------------------------------------------------------------------------------
  392. Default handler: Send notification to the parent object
  393. This allows for heirarchies of objects administrated from the top.
  394. ------------------------------------------------------------------------------*/
  395. LRESULT CUIFObject::OnObjectNotify( CUIFObject *pUIObj, DWORD dwCode, LPARAM lParam )
  396. {
  397. LRESULT lResult = 0;
  398. if (m_pParent != NULL) {
  399. lResult = m_pParent->OnObjectNotify( pUIObj, dwCode, lParam );
  400. }
  401. return lResult;
  402. }
  403. /* S E T T O O L T I P */
  404. /*------------------------------------------------------------------------------
  405. ------------------------------------------------------------------------------*/
  406. void CUIFObject::SetToolTip( LPCWSTR pwchToolTip )
  407. {
  408. if (m_pwchToolTip != NULL) {
  409. delete m_pwchToolTip;
  410. m_pwchToolTip = NULL;
  411. }
  412. if (pwchToolTip != NULL) {
  413. m_pwchToolTip = new WCHAR[ StrLenW( pwchToolTip ) + 1 ];
  414. if (m_pwchToolTip)
  415. StrCpyW( m_pwchToolTip, pwchToolTip );
  416. }
  417. }
  418. /* G E T T O O L T I P */
  419. /*------------------------------------------------------------------------------
  420. ------------------------------------------------------------------------------*/
  421. LPCWSTR CUIFObject::GetToolTip( void )
  422. {
  423. return m_pwchToolTip;
  424. }
  425. /* N O T I F Y C O M M A N D */
  426. /*------------------------------------------------------------------------------
  427. Send notification to the parent object
  428. ------------------------------------------------------------------------------*/
  429. LRESULT CUIFObject::NotifyCommand( DWORD dwCode, LPARAM lParam )
  430. {
  431. LRESULT lResult = 0;
  432. if (m_pParent != NULL) {
  433. lResult = m_pParent->OnObjectNotify( this, dwCode, lParam );
  434. }
  435. return lResult;
  436. }
  437. /* G E T F O N T H E I G H T */
  438. /*------------------------------------------------------------------------------
  439. Get the height of font set to the object
  440. ------------------------------------------------------------------------------*/
  441. int CUIFObject::GetFontHeight( void )
  442. {
  443. HDC hDC;
  444. HFONT hFontOld;
  445. TEXTMETRIC tm;
  446. hDC = GetDC( m_pUIWnd->GetWnd() );
  447. hFontOld = (HFONT)SelectObject( hDC, m_hFont );
  448. GetTextMetrics( hDC, &tm );
  449. SelectObject( hDC, hFontOld );
  450. ReleaseDC( m_pUIWnd->GetWnd(), hDC );
  451. return tm.tmHeight + tm.tmExternalLeading;
  452. }
  453. /* G E T U I F C O L O R */
  454. /*------------------------------------------------------------------------------
  455. ------------------------------------------------------------------------------*/
  456. COLORREF CUIFObject::GetUIFColor( UIFCOLOR iCol )
  457. {
  458. return (m_pUIFScheme != NULL) ? m_pUIFScheme->GetColor( iCol ) : RGB( 0, 0, 0 );
  459. }
  460. /* G E T U I F B R U S H */
  461. /*------------------------------------------------------------------------------
  462. ------------------------------------------------------------------------------*/
  463. HBRUSH CUIFObject::GetUIFBrush( UIFCOLOR iCol )
  464. {
  465. return (m_pUIFScheme != NULL) ? m_pUIFScheme->GetBrush( iCol ) : NULL;
  466. }
  467. /* D E T A C H W N D O B J */
  468. /*------------------------------------------------------------------------------
  469. ------------------------------------------------------------------------------*/
  470. void CUIFObject::DetachWndObj( void )
  471. {
  472. if (m_pUIWnd != NULL) {
  473. CUIFToolTip *pTipWnd = m_pUIWnd->GetToolTipWnd();
  474. if (pTipWnd && (this == pTipWnd->GetCurrentObj()))
  475. pTipWnd->ClearCurrentObj();
  476. m_pUIWnd->RemoveUIObj( this );
  477. }
  478. m_pUIWnd = NULL;
  479. }
  480. /* C L E A R W N D O B J */
  481. /*------------------------------------------------------------------------------
  482. ------------------------------------------------------------------------------*/
  483. void CUIFObject::ClearWndObj( void )
  484. {
  485. int i;
  486. m_pUIWnd = NULL;
  487. for (i = 0; i < m_ChildList.GetCount(); i ++)
  488. {
  489. CUIFObject *pObj;
  490. pObj = m_ChildList.Get(i);
  491. if (pObj)
  492. pObj->ClearWndObj();
  493. }
  494. }
  495. /* O N T H E M E C H A N G E D
  496. /*------------------------------------------------------------------------------
  497. ------------------------------------------------------------------------------*/
  498. void CUIFObject::ClearTheme( void )
  499. {
  500. int i;
  501. CloseThemeData();
  502. for (i = 0; i < m_ChildList.GetCount(); i ++)
  503. {
  504. CUIFObject *pObj;
  505. pObj = m_ChildList.Get(i);
  506. if (pObj)
  507. pObj->ClearTheme();
  508. }
  509. }
  510. /* O N T H E M E C H A N G E D
  511. /*------------------------------------------------------------------------------
  512. ------------------------------------------------------------------------------*/
  513. void CUIFObject::SetScheme(CUIFScheme *pUIFScheme)
  514. {
  515. int i;
  516. m_pUIFScheme = pUIFScheme;;
  517. for (i = 0; i < m_ChildList.GetCount(); i ++)
  518. {
  519. CUIFObject *pObj;
  520. pObj = m_ChildList.Get(i);
  521. if (pObj)
  522. pObj->SetScheme(pUIFScheme);
  523. }
  524. }
  525. /* I S R T L */
  526. /*------------------------------------------------------------------------------
  527. ------------------------------------------------------------------------------*/
  528. BOOL CUIFObject::IsRTL()
  529. {
  530. if (!m_pUIWnd)
  531. return FALSE;
  532. if (!m_pUIWnd->FHasStyle( UIWINDOW_LAYOUTRTL ))
  533. return FALSE;
  534. return TRUE;
  535. }
  536. /*=============================================================================*/
  537. /* */
  538. /* C U I F B O R D E R */
  539. /* */
  540. /*=============================================================================*/
  541. /* C U I F B O R D E R */
  542. /*------------------------------------------------------------------------------
  543. Constructor of CUIFBorder
  544. ------------------------------------------------------------------------------*/
  545. CUIFBorder::CUIFBorder( CUIFObject *pParent, DWORD dwID, const RECT *prc, DWORD dwStyle ) : CUIFObject( pParent, dwID, prc, dwStyle )
  546. {
  547. }
  548. /* ~ C U I F B O R D E R */
  549. /*------------------------------------------------------------------------------
  550. Destructor of CUIFBorder
  551. ------------------------------------------------------------------------------*/
  552. CUIFBorder::~CUIFBorder( void )
  553. {
  554. }
  555. /* O N P A I N T */
  556. /*------------------------------------------------------------------------------
  557. Paint procedure of border object
  558. ------------------------------------------------------------------------------*/
  559. void CUIFBorder::OnPaint( HDC hDC )
  560. {
  561. RECT rc = GetRectRef();
  562. switch (m_dwStyle & UIBORDER_DIRMASK) {
  563. default:
  564. case UIBORDER_HORZ: {
  565. DrawEdge( hDC, &rc, EDGE_ETCHED, BF_TOP );
  566. break;
  567. }
  568. case UIBORDER_VERT: {
  569. DrawEdge( hDC, &rc, EDGE_ETCHED, BF_LEFT );
  570. break;
  571. }
  572. }
  573. }
  574. /*=============================================================================*/
  575. /* */
  576. /* C U I F S T A T I C */
  577. /* */
  578. /*=============================================================================*/
  579. /* C U I F S T A T I C */
  580. /*------------------------------------------------------------------------------
  581. Constructor of CUIFStatic
  582. ------------------------------------------------------------------------------*/
  583. CUIFStatic::CUIFStatic( CUIFObject *pParent, DWORD dwID, const RECT *prc, DWORD dwStyle ) : CUIFObject( pParent, dwID, prc, dwStyle )
  584. {
  585. m_pwchText = NULL;
  586. }
  587. /* ~ C U I F S T A T I C */
  588. /*------------------------------------------------------------------------------
  589. Destructor of CUIFStatic
  590. ------------------------------------------------------------------------------*/
  591. CUIFStatic::~CUIFStatic( void )
  592. {
  593. if (m_pwchText != NULL) {
  594. delete m_pwchText;
  595. }
  596. }
  597. /* S E T T E X T */
  598. /*------------------------------------------------------------------------------
  599. Set text to display
  600. ------------------------------------------------------------------------------*/
  601. void CUIFStatic::SetText( LPCWSTR pwchText )
  602. {
  603. if (m_pwchText != NULL) {
  604. delete m_pwchText;
  605. m_pwchText = NULL;
  606. }
  607. if (pwchText != NULL) {
  608. int cwch = StrLenW( pwchText ) + 1;
  609. m_pwchText = new WCHAR[ cwch ];
  610. if (m_pwchText)
  611. MemCopy( m_pwchText, pwchText, cwch * sizeof(WCHAR) );
  612. }
  613. // update window
  614. CallOnPaint();
  615. }
  616. /* G E T T E X T */
  617. /*------------------------------------------------------------------------------
  618. Get text
  619. ------------------------------------------------------------------------------*/
  620. int CUIFStatic::GetText( LPWSTR pwchBuf, int cwchBuf )
  621. {
  622. int cwchText = (m_pwchText == NULL) ? 0 : StrLenW(m_pwchText);
  623. if (cwchBuf <= 0) {
  624. // return text length in cwch (not including null-terminater)
  625. return cwchText;
  626. }
  627. else if (pwchBuf == NULL) {
  628. // return error code
  629. return (-1);
  630. }
  631. if (0 < cwchText) {
  632. cwchText = min( cwchText, cwchBuf-1 );
  633. MemCopy( pwchBuf, m_pwchText, cwchText * sizeof(WCHAR) );
  634. *(pwchBuf + cwchText) = L'\0'; // always null terminate
  635. }
  636. return cwchText;
  637. }
  638. /* O N P A I N T */
  639. /*------------------------------------------------------------------------------
  640. Paint procedure of static object
  641. ------------------------------------------------------------------------------*/
  642. void CUIFStatic::OnPaint( HDC hDC )
  643. {
  644. HFONT hFontOld;
  645. int xAlign;
  646. int yAlign;
  647. SIZE size;
  648. int cwch;
  649. if (m_pwchText == NULL) {
  650. return;
  651. }
  652. cwch = StrLenW(m_pwchText);
  653. // prepare objects
  654. hFontOld= (HFONT)SelectObject( hDC, GetFont() );
  655. // calc alignment
  656. GetTextExtentPointW( hDC, m_pwchText, cwch, &size );
  657. switch (m_dwStyle & UISTATIC_HALIGNMASK) {
  658. case UISTATIC_LEFT:
  659. default: {
  660. xAlign = 0;
  661. break;
  662. }
  663. case UISTATIC_CENTER: {
  664. xAlign = (GetRectRef().right - GetRectRef().left - size.cx) / 2;
  665. break;
  666. }
  667. case UISTATIC_RIGHT: {
  668. xAlign = GetRectRef().right - GetRectRef().left - size.cx;
  669. break;
  670. }
  671. }
  672. switch (m_dwStyle & UISTATIC_VALIGNMASK) {
  673. case UISTATIC_TOP:
  674. default: {
  675. yAlign = 0;
  676. break;
  677. }
  678. case UISTATIC_VCENTER: {
  679. yAlign = (GetRectRef().bottom - GetRectRef().top - size.cy) / 2;
  680. break;
  681. }
  682. case UISTATIC_BOTTOM: {
  683. yAlign = GetRectRef().bottom - GetRectRef().top - size.cy;
  684. break;
  685. }
  686. }
  687. // draw
  688. SetBkMode( hDC, TRANSPARENT );
  689. if (IsEnabled()) {
  690. SetTextColor( hDC, GetSysColor(COLOR_BTNTEXT) );
  691. CUIExtTextOut( hDC,
  692. GetRectRef().left + xAlign,
  693. GetRectRef().top + yAlign,
  694. ETO_CLIPPED,
  695. &GetRectRef(),
  696. m_pwchText,
  697. cwch,
  698. NULL );
  699. }
  700. else {
  701. SetTextColor( hDC, GetSysColor(COLOR_3DHIGHLIGHT) );
  702. CUIExtTextOut( hDC,
  703. GetRectRef().left + xAlign + 1,
  704. GetRectRef().top + yAlign + 1,
  705. ETO_CLIPPED,
  706. &GetRectRef(),
  707. m_pwchText,
  708. cwch,
  709. NULL );
  710. SetTextColor( hDC, GetSysColor(COLOR_3DSHADOW) );
  711. CUIExtTextOut( hDC,
  712. GetRectRef().left + xAlign,
  713. GetRectRef().top + yAlign,
  714. ETO_CLIPPED,
  715. &GetRectRef(),
  716. m_pwchText,
  717. cwch,
  718. NULL );
  719. }
  720. // restore objects
  721. SelectObject( hDC, hFontOld);
  722. }
  723. /*=============================================================================*/
  724. /* */
  725. /* C U I F B U T T O N */
  726. /* */
  727. /*=============================================================================*/
  728. /* C U I F B U T T O N */
  729. /*------------------------------------------------------------------------------
  730. Constructor of CUIFButton
  731. ------------------------------------------------------------------------------*/
  732. CUIFButton::CUIFButton( CUIFObject *pParent, DWORD dwID, const RECT *prc, DWORD dwStyle ) : CUIFObject( pParent, dwID, prc, dwStyle )
  733. {
  734. m_dwStatus = UIBUTTON_NORMAL;
  735. m_fToggled = FALSE;
  736. m_hIcon = NULL;
  737. m_hBmp = NULL;
  738. m_hBmpMask = NULL;
  739. m_pwchText = NULL;
  740. }
  741. /* ~ C U I F B U T T O N */
  742. /*------------------------------------------------------------------------------
  743. Destructor of CUIFButton
  744. ------------------------------------------------------------------------------*/
  745. CUIFButton::~CUIFButton( void )
  746. {
  747. if (m_pwchText != NULL) {
  748. delete m_pwchText;
  749. }
  750. }
  751. /* O N P A I N T */
  752. /*------------------------------------------------------------------------------
  753. Paint procedure of button object
  754. ------------------------------------------------------------------------------*/
  755. void CUIFButton::OnPaintNoTheme( HDC hDC )
  756. {
  757. BOOL fDownFace;
  758. // erase face at first
  759. FillRect( hDC, &GetRectRef(), (HBRUSH)(COLOR_3DFACE + 1) );
  760. #ifndef UNDER_CE
  761. if (m_fToggled && (m_dwStatus == UIBUTTON_NORMAL || m_dwStatus == UIBUTTON_DOWNOUT)) {
  762. RECT rc;
  763. HBRUSH hBrush;
  764. COLORREF colTextOld;
  765. COLORREF colBackOld;
  766. hBrush = CreateDitherBrush();
  767. if (hBrush)
  768. {
  769. colTextOld = SetTextColor( hDC, GetSysColor(COLOR_3DFACE) );
  770. colBackOld = SetBkColor( hDC, GetSysColor(COLOR_3DHILIGHT) );
  771. rc = GetRectRef();
  772. InflateRect( &rc, -2, -2 );
  773. FillRect( hDC, &rc, hBrush );
  774. SetTextColor( hDC, colTextOld );
  775. SetBkColor( hDC, colBackOld );
  776. DeleteObject( hBrush );
  777. }
  778. }
  779. #endif /* !UNDER_CE */
  780. // draw face
  781. fDownFace = m_fToggled || (m_dwStatus == UIBUTTON_DOWN);
  782. if (m_hBmp != NULL) {
  783. DrawBitmapProc( hDC, &GetRectRef(), fDownFace );
  784. }
  785. else if (m_hIcon != NULL) {
  786. DrawIconProc( hDC, &GetRectRef(), fDownFace );
  787. }
  788. else {
  789. DrawTextProc( hDC, &GetRectRef(), fDownFace );
  790. }
  791. // draw button edge
  792. if (m_fToggled) {
  793. DrawEdgeProc( hDC, &GetRectRef(), TRUE );
  794. }
  795. else {
  796. switch (m_dwStatus) {
  797. case UIBUTTON_DOWN: {
  798. DrawEdgeProc( hDC, &GetRectRef(), TRUE );
  799. break;
  800. }
  801. case UIBUTTON_HOVER:
  802. case UIBUTTON_DOWNOUT: {
  803. DrawEdgeProc( hDC, &GetRectRef(), FALSE );
  804. break;
  805. }
  806. }
  807. }
  808. }
  809. /* O N L B U T T O N D O W N */
  810. /*------------------------------------------------------------------------------
  811. ------------------------------------------------------------------------------*/
  812. void CUIFButton::OnLButtonDown( POINT pt )
  813. {
  814. SetStatus( UIBUTTON_DOWN );
  815. StartCapture();
  816. switch (m_dwStyle & UIBUTTON_TYPEMASK) {
  817. default:
  818. case UIBUTTON_PUSH: {
  819. break;
  820. }
  821. case UIBUTTON_TOGGLE: {
  822. break;
  823. }
  824. case UIBUTTON_PUSHDOWN: {
  825. NotifyCommand( UIBUTTON_PRESSED, 0 );
  826. break;
  827. }
  828. }
  829. }
  830. /* O N L B U T T O N U P */
  831. /*------------------------------------------------------------------------------
  832. ------------------------------------------------------------------------------*/
  833. void CUIFButton::OnLButtonUp( POINT pt )
  834. {
  835. BOOL fCaptured = IsCapture();
  836. if (fCaptured) {
  837. EndCapture();
  838. }
  839. switch (m_dwStyle & UIBUTTON_TYPEMASK) {
  840. default:
  841. case UIBUTTON_PUSH: {
  842. if (PtInObject( pt )) {
  843. SetStatus( UIBUTTON_HOVER );
  844. NotifyCommand( UIBUTTON_PRESSED, 0 );
  845. }
  846. else {
  847. SetStatus( UIBUTTON_NORMAL );
  848. }
  849. break;
  850. }
  851. case UIBUTTON_TOGGLE: {
  852. if (PtInObject( pt )) {
  853. SetStatus( UIBUTTON_HOVER );
  854. if (fCaptured) {
  855. m_fToggled = !m_fToggled;
  856. NotifyCommand( UIBUTTON_PRESSED, 0 );
  857. }
  858. }
  859. else {
  860. SetStatus( UIBUTTON_NORMAL );
  861. }
  862. break;
  863. }
  864. case UIBUTTON_PUSHDOWN: {
  865. SetStatus( UIBUTTON_NORMAL );
  866. break;
  867. }
  868. }
  869. }
  870. /* O N M O U S E I N */
  871. /*------------------------------------------------------------------------------
  872. ------------------------------------------------------------------------------*/
  873. void CUIFButton::OnMouseIn( POINT pt )
  874. {
  875. switch (m_dwStyle & UIBUTTON_TYPEMASK) {
  876. default:
  877. case UIBUTTON_PUSH: {
  878. SetStatus( IsCapture() ? UIBUTTON_DOWN : UIBUTTON_HOVER );
  879. break;
  880. }
  881. case UIBUTTON_TOGGLE: {
  882. SetStatus( IsCapture() ? UIBUTTON_DOWN : UIBUTTON_HOVER );
  883. break;
  884. }
  885. case UIBUTTON_PUSHDOWN: {
  886. SetStatus( IsCapture() ? UIBUTTON_NORMAL : UIBUTTON_HOVER );
  887. break;
  888. }
  889. }
  890. }
  891. /* O N M O U S E O U T */
  892. /*------------------------------------------------------------------------------
  893. ------------------------------------------------------------------------------*/
  894. void CUIFButton::OnMouseOut( POINT pt )
  895. {
  896. switch (m_dwStyle & UIBUTTON_TYPEMASK) {
  897. default:
  898. case UIBUTTON_PUSH: {
  899. SetStatus( IsCapture() ? UIBUTTON_DOWNOUT : UIBUTTON_NORMAL );
  900. break;
  901. }
  902. case UIBUTTON_TOGGLE: {
  903. SetStatus( IsCapture() ? UIBUTTON_DOWNOUT : UIBUTTON_NORMAL );
  904. break;
  905. }
  906. case UIBUTTON_PUSHDOWN: {
  907. SetStatus( UIBUTTON_NORMAL );
  908. break;
  909. }
  910. }
  911. }
  912. /* E N A B L E */
  913. /*------------------------------------------------------------------------------
  914. ------------------------------------------------------------------------------*/
  915. void CUIFButton::Enable( BOOL fEnable )
  916. {
  917. CUIFObject::Enable( fEnable );
  918. if (!IsEnabled()) {
  919. SetStatus( UIBUTTON_NORMAL );
  920. if (IsCapture()) {
  921. EndCapture();
  922. }
  923. }
  924. }
  925. /* D R A W E D G E P R O C */
  926. /*------------------------------------------------------------------------------
  927. Draw button edge
  928. ------------------------------------------------------------------------------*/
  929. void CUIFButton::DrawEdgeProc( HDC hDC, const RECT *prc, BOOL fDown )
  930. {
  931. RECT rc = *prc;
  932. DrawEdge( hDC, &rc, fDown ? BDR_SUNKENOUTER : BDR_RAISEDINNER, BF_RECT );
  933. }
  934. /* S E T T E X T */
  935. /*------------------------------------------------------------------------------
  936. Set text of button face
  937. ------------------------------------------------------------------------------*/
  938. void CUIFButton::SetText( LPCWSTR psz )
  939. {
  940. if (m_pwchText != NULL) {
  941. delete m_pwchText;
  942. m_pwchText = NULL;
  943. }
  944. //
  945. // init size;
  946. //
  947. MemSet(&m_sizeText, 0, sizeof(SIZE));
  948. if (psz != NULL)
  949. {
  950. int cwch = StrLenW( psz ) + 1;
  951. m_pwchText = new WCHAR[ cwch ];
  952. if (!m_pwchText)
  953. return;
  954. MemCopy( m_pwchText, psz, cwch * sizeof(WCHAR) );
  955. GetTextSize( m_pwchText, &m_sizeText );
  956. }
  957. // update window
  958. CallOnPaint();
  959. }
  960. /* S E T I C O N */
  961. /*------------------------------------------------------------------------------
  962. Set icon of button face
  963. ------------------------------------------------------------------------------*/
  964. void CUIFButton::SetIcon( HICON hIcon )
  965. {
  966. m_hIcon = hIcon;
  967. if (m_hIcon)
  968. GetIconSize(m_hIcon, &m_sizeIcon);
  969. else
  970. MemSet(&m_sizeIcon, 0, sizeof(SIZE));
  971. CallOnPaint();
  972. }
  973. /* S E T I C O N */
  974. /*------------------------------------------------------------------------------
  975. Set icon of button face
  976. ------------------------------------------------------------------------------*/
  977. void CUIFButton::SetIcon( LPCTSTR lpszResName )
  978. {
  979. SetIcon( LoadIcon( m_pUIWnd->GetInstance(), lpszResName ) );
  980. }
  981. /* S E T B I T M A P */
  982. /*------------------------------------------------------------------------------
  983. Set bitmap of button face
  984. ------------------------------------------------------------------------------*/
  985. void CUIFButton::SetBitmap( HBITMAP hBmp )
  986. {
  987. m_hBmp = hBmp;
  988. if (m_hBmp)
  989. GetBitmapSize(m_hBmp, &m_sizeBmp);
  990. else
  991. MemSet(&m_sizeBmp, 0, sizeof(SIZE));
  992. CallOnPaint();
  993. }
  994. /* S E T B I T M A P */
  995. /*------------------------------------------------------------------------------
  996. Set bitmap of button face
  997. ------------------------------------------------------------------------------*/
  998. void CUIFButton::SetBitmap( LPCTSTR lpszResName )
  999. {
  1000. SetBitmap( LoadBitmap( m_pUIWnd->GetInstance(), lpszResName ) );
  1001. }
  1002. /* S E T B I T M A P M A S K */
  1003. /*------------------------------------------------------------------------------
  1004. Set bitmap of button face
  1005. ------------------------------------------------------------------------------*/
  1006. void CUIFButton::SetBitmapMask( HBITMAP hBmp )
  1007. {
  1008. m_hBmpMask = hBmp;
  1009. CallOnPaint();
  1010. }
  1011. /* S E T B I T M A P */
  1012. /*------------------------------------------------------------------------------
  1013. Set bitmap of button face
  1014. ------------------------------------------------------------------------------*/
  1015. void CUIFButton::SetBitmapMask( LPCTSTR lpszResName )
  1016. {
  1017. SetBitmapMask( LoadBitmap( m_pUIWnd->GetInstance(), lpszResName ) );
  1018. }
  1019. /* D R A W T E X T P R O C */
  1020. /*------------------------------------------------------------------------------
  1021. Draw text on button face
  1022. ------------------------------------------------------------------------------*/
  1023. void CUIFButton::DrawTextProc( HDC hDC, const RECT *prc, BOOL fDown )
  1024. {
  1025. int nDownPad = fDown ? 1 : 0;
  1026. int xAlign;
  1027. int yAlign;
  1028. SIZE size;
  1029. HFONT hFontOld;
  1030. //
  1031. if (m_pwchText == NULL) {
  1032. return;
  1033. }
  1034. //
  1035. hFontOld = (HFONT)SelectObject( hDC, GetFont() );
  1036. // calc text width
  1037. CUIGetTextExtentPoint32( hDC, m_pwchText, StrLenW(m_pwchText), &size );
  1038. switch (m_dwStyle & UIBUTTON_HALIGNMASK) {
  1039. case UIBUTTON_LEFT:
  1040. default: {
  1041. xAlign = 0;
  1042. break;
  1043. }
  1044. case UIBUTTON_CENTER: {
  1045. xAlign = (GetRectRef().right - GetRectRef().left - size.cx) / 2;
  1046. break;
  1047. }
  1048. case UIBUTTON_RIGHT: {
  1049. xAlign = GetRectRef().right - GetRectRef().left - size.cx;
  1050. break;
  1051. }
  1052. }
  1053. switch (m_dwStyle & UIBUTTON_VALIGNMASK) {
  1054. case UIBUTTON_TOP:
  1055. default: {
  1056. yAlign = 0;
  1057. break;
  1058. }
  1059. case UIBUTTON_VCENTER: {
  1060. yAlign = (GetRectRef().bottom - GetRectRef().top - size.cy) / 2;
  1061. break;
  1062. }
  1063. case UIBUTTON_BOTTOM: {
  1064. yAlign = GetRectRef().bottom - GetRectRef().top - size.cy;
  1065. break;
  1066. }
  1067. }
  1068. //
  1069. SetBkMode( hDC, TRANSPARENT );
  1070. if (IsEnabled()) {
  1071. SetTextColor( hDC, GetSysColor(COLOR_BTNTEXT) );
  1072. CUIExtTextOut( hDC,
  1073. prc->left + xAlign + nDownPad,
  1074. prc->top + yAlign + nDownPad,
  1075. ETO_CLIPPED,
  1076. prc,
  1077. m_pwchText,
  1078. StrLenW(m_pwchText),
  1079. NULL );
  1080. }
  1081. else {
  1082. SetTextColor( hDC, GetSysColor(COLOR_3DHIGHLIGHT) );
  1083. CUIExtTextOut( hDC,
  1084. prc->left + xAlign + nDownPad + 1,
  1085. prc->top + yAlign + nDownPad + 1,
  1086. ETO_CLIPPED,
  1087. prc,
  1088. m_pwchText,
  1089. StrLenW(m_pwchText),
  1090. NULL );
  1091. SetTextColor( hDC, GetSysColor(COLOR_3DSHADOW) );
  1092. CUIExtTextOut( hDC,
  1093. prc->left + xAlign + nDownPad,
  1094. prc->top + yAlign + nDownPad,
  1095. ETO_CLIPPED,
  1096. prc,
  1097. m_pwchText,
  1098. StrLenW(m_pwchText),
  1099. NULL );
  1100. }
  1101. SelectObject( hDC, hFontOld );
  1102. }
  1103. /* D R A W I C O N P R O C */
  1104. /*------------------------------------------------------------------------------
  1105. Draw icon on button face
  1106. ------------------------------------------------------------------------------*/
  1107. void CUIFButton::DrawIconProc( HDC hDC, const RECT *prc, BOOL fDown )
  1108. {
  1109. Assert(hDC && prc && m_hIcon);
  1110. const int nDownPad = fDown ? 1 : 0;
  1111. const int nWidth = prc->right - prc->left;
  1112. const int nHeight= prc->bottom - prc->top;
  1113. const RECT rc = {0, 0, nWidth, nHeight};
  1114. HDC hDCMem = NULL;
  1115. HBITMAP hBmpOld;
  1116. HBITMAP hBmp = NULL;
  1117. // prepare memory dc
  1118. hDCMem = CreateCompatibleDC( hDC );
  1119. if (!hDCMem)
  1120. goto Exit;
  1121. hBmp = CreateCompatibleBitmap( hDC, nWidth, nHeight );
  1122. if (!hBmp)
  1123. goto Exit;
  1124. hBmpOld = (HBITMAP)SelectObject( hDCMem, hBmp );
  1125. // clear background
  1126. if (IsEnabled()) {
  1127. BitBlt( hDCMem, rc.left, rc.top, nWidth, nHeight, hDC, prc->left, prc->top, SRCCOPY );
  1128. }
  1129. else {
  1130. FillRect( hDCMem, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH) );
  1131. }
  1132. // paint icon into memory dc
  1133. if (m_dwStyle & UIBUTTON_FITIMAGE) {
  1134. DrawIconEx( hDCMem,
  1135. 2 + nDownPad,
  1136. 2 + nDownPad,
  1137. m_hIcon,
  1138. nWidth - 4,
  1139. nHeight - 4,
  1140. 0,
  1141. NULL,
  1142. DI_NORMAL );
  1143. }
  1144. else {
  1145. DrawIconEx( hDCMem,
  1146. (nWidth - 16) / 2 + nDownPad,
  1147. (nHeight - 16) / 2 + nDownPad,
  1148. m_hIcon,
  1149. 16,
  1150. 16,
  1151. 0,
  1152. NULL,
  1153. DI_NORMAL );
  1154. }
  1155. SelectObject( hDCMem, hBmpOld);
  1156. CUIDrawState( hDC,
  1157. NULL,
  1158. NULL,
  1159. (LPARAM)hBmp,
  1160. 0, // we don't pass a WPARAM in this case.
  1161. prc->left,
  1162. prc->top,
  1163. nWidth,
  1164. nHeight,
  1165. DST_BITMAP | (IsEnabled() ? 0 : (DSS_DISABLED | DSS_MONO)) );
  1166. Exit:
  1167. if (hBmp)
  1168. DeleteObject( hBmp );
  1169. if (hDCMem)
  1170. DeleteDC( hDCMem );
  1171. }
  1172. /* D R A W B I T M A P P R O C */
  1173. /*------------------------------------------------------------------------------
  1174. Draw bitmap on button face
  1175. ------------------------------------------------------------------------------*/
  1176. void CUIFButton::DrawBitmapProc( HDC hDC, const RECT *prc, BOOL fDown )
  1177. {
  1178. const int nDownPad = fDown ? 1 : 0;
  1179. const int nWidth = GetRectRef().right - GetRectRef().left;
  1180. const int nHeight= GetRectRef().bottom - GetRectRef().top;
  1181. if (!m_hBmpMask)
  1182. {
  1183. CUIDrawState( hDC,
  1184. NULL,
  1185. NULL,
  1186. (LPARAM)m_hBmp,
  1187. 0,
  1188. prc->left + nDownPad,
  1189. prc->top + nDownPad,
  1190. nWidth - nDownPad,
  1191. nHeight - nDownPad,
  1192. DST_BITMAP | (IsEnabled() ? 0 : DSS_DISABLED | DSS_MONO) );
  1193. }
  1194. else
  1195. {
  1196. HBITMAP hBmp = CreateMaskBmp(&GetRectRef(),
  1197. m_hBmp,
  1198. m_hBmpMask,
  1199. (HBRUSH)(COLOR_3DFACE + 1) , 0, 0);
  1200. CUIDrawState( hDC,
  1201. NULL,
  1202. NULL,
  1203. (LPARAM)hBmp,
  1204. 0,
  1205. prc->left + nDownPad,
  1206. prc->top + nDownPad,
  1207. nWidth - nDownPad,
  1208. nHeight - nDownPad,
  1209. DST_BITMAP | (IsEnabled() ? 0 : DSS_DISABLED | DSS_MONO) );
  1210. DeleteObject(hBmp);
  1211. }
  1212. }
  1213. /* S E T S T A T U S */
  1214. /*------------------------------------------------------------------------------
  1215. Set button status
  1216. ------------------------------------------------------------------------------*/
  1217. void CUIFButton::SetStatus( DWORD dwStatus )
  1218. {
  1219. if (dwStatus != m_dwStatus) {
  1220. m_dwStatus = dwStatus;
  1221. CallOnPaint();
  1222. }
  1223. }
  1224. /* G E T T O G G L E S T A T E */
  1225. /*------------------------------------------------------------------------------
  1226. Get toggle status
  1227. Returns TRUE when the button has been toggled.
  1228. ------------------------------------------------------------------------------*/
  1229. BOOL CUIFButton::GetToggleState( void )
  1230. {
  1231. return m_fToggled;
  1232. }
  1233. /* S E T T O G G L E S T A T E */
  1234. /*------------------------------------------------------------------------------
  1235. Set toggle status
  1236. ------------------------------------------------------------------------------*/
  1237. void CUIFButton::SetToggleState( BOOL fToggle )
  1238. {
  1239. if ((m_dwStyle & UIBUTTON_TYPEMASK) == UIBUTTON_TOGGLE && m_fToggled != fToggle) {
  1240. m_fToggled = fToggle;
  1241. CallOnPaint();
  1242. }
  1243. }
  1244. /* G E T T E X T S I Z E */
  1245. /*------------------------------------------------------------------------------
  1246. calc text width
  1247. ------------------------------------------------------------------------------*/
  1248. void CUIFButton::GetTextSize( LPCWSTR pwch, SIZE *psize )
  1249. {
  1250. HDC hDC = GetDC( NULL );
  1251. HFONT hFontOld = (HFONT)SelectObject( hDC, GetFont() );
  1252. Assert( pwch != NULL );
  1253. if (!m_fUseCustomFont && SUCCEEDED(EnsureThemeData(m_pUIWnd->GetWnd())))
  1254. {
  1255. RECT rcText;
  1256. GetThemeTextExtent( hDC,0 , pwch, StrLenW(pwch),0, NULL, &rcText);
  1257. psize->cx = rcText.right;
  1258. psize->cy = rcText.bottom;
  1259. }
  1260. else
  1261. {
  1262. CUIGetTextExtentPoint32( hDC, pwch, StrLenW(pwch), psize );
  1263. }
  1264. //
  1265. // swap width and height
  1266. //
  1267. if (IsVertical())
  1268. {
  1269. int nTemp = psize->cx;
  1270. psize->cx = psize->cy;
  1271. psize->cy = nTemp;
  1272. }
  1273. SelectObject( hDC, hFontOld );
  1274. ReleaseDC( NULL, hDC );
  1275. }
  1276. /* G E T I C O N S I Z E */
  1277. /*------------------------------------------------------------------------------
  1278. get icon size
  1279. ------------------------------------------------------------------------------*/
  1280. void CUIFButton::GetIconSize( HICON hIcon, SIZE *psize )
  1281. {
  1282. ICONINFO IconInfo;
  1283. BITMAP bmp;
  1284. Assert( hIcon != NULL );
  1285. if (GetIconInfo( hIcon, &IconInfo ))
  1286. {
  1287. GetObject( IconInfo.hbmColor, sizeof(bmp), &bmp );
  1288. DeleteObject( IconInfo.hbmColor );
  1289. DeleteObject( IconInfo.hbmMask );
  1290. psize->cx = bmp.bmWidth;
  1291. psize->cy = bmp.bmHeight;
  1292. }
  1293. else
  1294. {
  1295. psize->cx = GetSystemMetrics(SM_CXSMICON);
  1296. psize->cy = GetSystemMetrics(SM_CYSMICON);
  1297. }
  1298. }
  1299. /* G E T B I T M A P S I Z E */
  1300. /*------------------------------------------------------------------------------
  1301. get bitmap size
  1302. ------------------------------------------------------------------------------*/
  1303. void CUIFButton::GetBitmapSize( HBITMAP hBmp, SIZE *psize )
  1304. {
  1305. BITMAP bmp;
  1306. Assert( hBmp != NULL );
  1307. GetObject( hBmp, sizeof(bmp), &bmp );
  1308. psize->cx = bmp.bmWidth;
  1309. psize->cy = bmp.bmHeight;
  1310. }
  1311. /*=============================================================================*/
  1312. /* */
  1313. /* C U I F B U T T O N 2 */
  1314. /* */
  1315. /*=============================================================================*/
  1316. /* C U I F B U T T O N 2 */
  1317. /*------------------------------------------------------------------------------
  1318. Constructor of CUIFButton2
  1319. ------------------------------------------------------------------------------*/
  1320. CUIFButton2::CUIFButton2( CUIFObject *pParent, DWORD dwID, const RECT *prc, DWORD dwStyle ) : CUIFButton( pParent, dwID, prc, dwStyle )
  1321. {
  1322. SetActiveTheme(L"TOOLBAR", TP_BUTTON, 0);
  1323. }
  1324. /* ~ C U I F B U T T O N 2 */
  1325. /*------------------------------------------------------------------------------
  1326. Destructor of CUIFButton2
  1327. ------------------------------------------------------------------------------*/
  1328. CUIFButton2::~CUIFButton2( void )
  1329. {
  1330. CloseThemeData();
  1331. }
  1332. /*------------------------------------------------------------------------------
  1333. MakeDrawFlag
  1334. ------------------------------------------------------------------------------*/
  1335. DWORD CUIFButton2::MakeDrawFlag()
  1336. {
  1337. DWORD dwState = 0;
  1338. // make draw flag
  1339. dwState |= (m_fToggled) ? UIFDCS_SELECTED : 0;
  1340. switch (m_dwStatus) {
  1341. case UIBUTTON_DOWN: {
  1342. dwState |= UIFDCS_MOUSEDOWN;
  1343. break;
  1344. }
  1345. case UIBUTTON_HOVER:
  1346. case UIBUTTON_DOWNOUT: {
  1347. dwState |= UIFDCS_MOUSEOVER;
  1348. break;
  1349. }
  1350. }
  1351. dwState |= IsEnabled() ? 0 : UIFDCS_DISABLED;
  1352. return dwState;
  1353. }
  1354. /* O N P A I N T */
  1355. /*------------------------------------------------------------------------------
  1356. Paint procedure of button object
  1357. ------------------------------------------------------------------------------*/
  1358. BOOL CUIFButton2::OnPaintTheme( HDC hDC )
  1359. {
  1360. DWORD dwState = 0;
  1361. BOOL fRet = FALSE;
  1362. SIZE sizeText = {0};
  1363. SIZE sizeImage = {0};
  1364. SIZE sizeFace = {0};
  1365. SIZE offset = {0};
  1366. RECT rcText = {0};
  1367. RECT rcImage = {0};
  1368. RECT rcFace = {0};
  1369. RECT rcContent = {0};
  1370. HFONT hFontOld = NULL;
  1371. DWORD dwTextFlag = 0;
  1372. // make draw flag
  1373. dwState = MakeDrawFlag();
  1374. if (!CUIIsThemeActive()) {
  1375. goto Exit;
  1376. }
  1377. if (FAILED(EnsureThemeData( GetUIWnd()->GetWnd())))
  1378. goto Exit;
  1379. hFontOld = (HFONT)SelectObject( hDC, GetFont() );
  1380. int iStateID;
  1381. if (!IsEnabled()) {
  1382. iStateID = TS_DISABLED;
  1383. }
  1384. else if (GetToggleState()) {
  1385. iStateID = TS_CHECKED;
  1386. }
  1387. else if (m_dwStatus == UIBUTTON_DOWN) {
  1388. iStateID = TS_PRESSED;
  1389. }
  1390. else if (m_dwStatus == UIBUTTON_HOVER) {
  1391. iStateID = TS_HOT;
  1392. }
  1393. else {
  1394. iStateID = TS_NORMAL;
  1395. }
  1396. // if (FAILED(GetThemeBackgroundContentRect(hDC, iStateID, &GetRectRef(), &rcContent )))
  1397. // goto Exit;
  1398. rcContent = GetRectRef();
  1399. // calc face size
  1400. if (m_pwchText != NULL) {
  1401. sizeText = m_sizeText;
  1402. }
  1403. if (m_hIcon != NULL) {
  1404. sizeImage = m_sizeIcon;
  1405. }
  1406. else if (m_hBmp != NULL ) {
  1407. sizeImage = m_sizeBmp;
  1408. }
  1409. // alignment
  1410. if (!IsVertical())
  1411. {
  1412. sizeFace.cx = sizeText.cx + sizeImage.cx + ((sizeText.cx != 0 && sizeImage.cx != 0) ? 2 : 0);
  1413. sizeFace.cy = max( sizeText.cy, sizeImage.cy );
  1414. }
  1415. else
  1416. {
  1417. sizeFace.cy = sizeText.cy + sizeImage.cy + ((sizeText.cy != 0 && sizeImage.cy != 0) ? 2 : 0);
  1418. sizeFace.cx = max( sizeText.cx, sizeImage.cx );
  1419. }
  1420. switch (GetStyleBits( UIBUTTON_HALIGNMASK )) {
  1421. case UIBUTTON_LEFT:
  1422. default: {
  1423. rcFace.left = rcContent.left + 2;
  1424. rcFace.right = rcFace.left + sizeFace.cx;
  1425. dwTextFlag = DT_LEFT;
  1426. break;
  1427. }
  1428. case UIBUTTON_CENTER: {
  1429. rcFace.left = (rcContent.right + rcContent.left - sizeFace.cx) / 2;
  1430. rcFace.right = rcFace.left + sizeFace.cx;
  1431. dwTextFlag = DT_CENTER;
  1432. break;
  1433. }
  1434. case UIBUTTON_RIGHT: {
  1435. rcFace.left = rcContent.right - 2 - sizeText.cx;
  1436. rcFace.right = rcFace.left + sizeFace.cx;
  1437. dwTextFlag = DT_RIGHT;
  1438. break;
  1439. }
  1440. }
  1441. switch (GetStyleBits( UIBUTTON_VALIGNMASK )) {
  1442. case UIBUTTON_TOP:
  1443. default: {
  1444. rcFace.top = rcContent.top + 2;
  1445. rcFace.bottom = rcFace.top + sizeFace.cy;
  1446. dwTextFlag = DT_TOP;
  1447. break;
  1448. }
  1449. case UIBUTTON_VCENTER: {
  1450. rcFace.top = (rcContent.bottom + rcContent.top - sizeFace.cy) / 2;
  1451. rcFace.bottom = rcFace.top + sizeFace.cy;
  1452. dwTextFlag = DT_VCENTER;
  1453. break;
  1454. }
  1455. case UIBUTTON_BOTTOM: {
  1456. rcFace.top = rcContent.bottom - 2 - sizeFace.cy;
  1457. rcFace.bottom = rcFace.top + sizeFace.cy;
  1458. dwTextFlag = DT_BOTTOM;
  1459. break;
  1460. }
  1461. }
  1462. if (!IsVertical())
  1463. {
  1464. rcImage.left = rcFace.left;
  1465. rcImage.top = (rcFace.bottom + rcFace.top - sizeImage.cy) / 2;
  1466. rcImage.right = rcImage.left + sizeImage.cx;
  1467. rcImage.bottom = rcImage.top + sizeImage.cy;
  1468. rcText.left = rcFace.right - sizeText.cx;
  1469. rcText.top = (rcFace.bottom + rcFace.top - sizeText.cy) / 2;
  1470. rcText.right = rcText.left + sizeText.cx;
  1471. rcText.bottom = rcText.top + sizeText.cy;
  1472. }
  1473. else
  1474. {
  1475. rcImage.left = (rcFace.right + rcFace.left - sizeImage.cx) / 2;
  1476. rcImage.top = rcFace.top;
  1477. rcImage.right = rcImage.left + sizeImage.cx;
  1478. rcImage.bottom = rcImage.top + sizeImage.cy;
  1479. rcText.left = (rcFace.right + rcFace.left - sizeText.cx) / 2;
  1480. rcText.top = rcFace.bottom - sizeText.cy;
  1481. rcText.right = rcText.left + sizeText.cx;
  1482. rcText.bottom = rcText.top + sizeText.cy;
  1483. }
  1484. if (FAILED(DrawThemeBackground(hDC, iStateID, &GetRectRef(), 0 )))
  1485. goto Exit;
  1486. if (m_pwchText != NULL)
  1487. {
  1488. int cwch = StrLenW(m_pwchText);
  1489. //
  1490. // DrawtThemeText() uses the font from theme so
  1491. // marlett font won't be used....
  1492. // We need to draw the text when a font is set.
  1493. //
  1494. if (m_fUseCustomFont)
  1495. {
  1496. COLORREF col;
  1497. int xText;
  1498. int yText;
  1499. if (FAILED(GetThemeColor(iStateID, TMT_TEXTCOLOR, &col)))
  1500. {
  1501. col = GetSysColor(COLOR_WINDOWTEXT);
  1502. }
  1503. COLORREF colTextOld = GetTextColor( hDC );
  1504. int iBkModeOld = SetBkMode( hDC, TRANSPARENT );
  1505. xText = IsVertical() ? rcText.right : rcText.left;
  1506. yText = rcText.top;
  1507. //
  1508. // we want to calc the marging correctly for theme.
  1509. // but somehow MSUTB's langbar is corrupted.
  1510. //
  1511. if (IsRTL())
  1512. xText -= 2;
  1513. #if 0
  1514. MARGINS marginsItem = {0};
  1515. GetThemeMargins(NULL, iStateID, TMT_CONTENTMARGINS,
  1516. NULL, &marginsItem);
  1517. xText += marginsItem.cxLeftWidth;
  1518. yText += marginsItem.cxRightWidth;
  1519. #endif
  1520. SetTextColor( hDC, col);
  1521. CUIExtTextOut( hDC,
  1522. xText,
  1523. yText,
  1524. ETO_CLIPPED,
  1525. &rcText,
  1526. m_pwchText,
  1527. cwch,
  1528. NULL );
  1529. SetTextColor( hDC, colTextOld );
  1530. SetBkMode( hDC, iBkModeOld );
  1531. }
  1532. else
  1533. {
  1534. if (FAILED(DrawThemeText(hDC,
  1535. iStateID,
  1536. m_pwchText,
  1537. cwch,
  1538. dwTextFlag,
  1539. 0,
  1540. &rcText)))
  1541. goto Exit;
  1542. }
  1543. }
  1544. if (m_hIcon != NULL)
  1545. {
  1546. if (FAILED(DrawThemeIcon(hDC,
  1547. iStateID,
  1548. &rcImage,
  1549. m_hIcon.GetImageList(IsRTL()),
  1550. m_hIcon.GetImageListId() )))
  1551. goto Exit;
  1552. }
  1553. else if (m_hBmp != NULL)
  1554. {
  1555. //
  1556. // Draw Bitmap by ourselves.
  1557. //
  1558. DrawMaskBmpOnDC(hDC, &rcImage, m_hBmp, m_hBmpMask);
  1559. }
  1560. if (hFontOld)
  1561. SelectObject( hDC, hFontOld );
  1562. fRet = TRUE;
  1563. Exit:
  1564. return fRet;
  1565. }
  1566. /* O N P A I N T D E F */
  1567. /*------------------------------------------------------------------------------
  1568. Paint procedure of button object
  1569. ------------------------------------------------------------------------------*/
  1570. void CUIFButton2::OnPaintNoTheme( HDC hDC )
  1571. {
  1572. DWORD dwState = 0;
  1573. HDC hDCMem = NULL;
  1574. HBITMAP hBmpMem = NULL;
  1575. HBITMAP hBmpOld;
  1576. SIZE size;
  1577. RECT rc;
  1578. SIZE sizeText = {0};
  1579. SIZE sizeImage = {0};
  1580. SIZE sizeFace = {0};
  1581. SIZE offset = {0};
  1582. RECT rcText = {0};
  1583. RECT rcImage = {0};
  1584. RECT rcFace = {0};
  1585. HFONT hFontOld;
  1586. if (!m_pUIFScheme)
  1587. return;
  1588. // make draw flag
  1589. dwState = MakeDrawFlag();
  1590. // prepare memory dc
  1591. size.cx = GetRectRef().right - GetRectRef().left;
  1592. size.cy = GetRectRef().bottom - GetRectRef().top;
  1593. hDCMem = CreateCompatibleDC( hDC );
  1594. if (!hDCMem)
  1595. goto Exit;
  1596. hBmpMem = CreateCompatibleBitmap( hDC, size.cx, size.cy );
  1597. if (!hBmpMem)
  1598. goto Exit;
  1599. hBmpOld = (HBITMAP)SelectObject( hDCMem, hBmpMem );
  1600. ::SetRect( &rc, 0, 0, size.cx, size.cy );
  1601. hFontOld = (HFONT)SelectObject( hDCMem, GetFont() );
  1602. // calc face size
  1603. if (m_pwchText != NULL) {
  1604. sizeText = m_sizeText;
  1605. }
  1606. if (m_hIcon != NULL) {
  1607. sizeImage = m_sizeIcon;
  1608. }
  1609. else if (m_hBmp != NULL ) {
  1610. sizeImage = m_sizeBmp;
  1611. }
  1612. // alignment
  1613. if (!IsVertical())
  1614. {
  1615. sizeFace.cx = sizeText.cx + sizeImage.cx + ((sizeText.cx != 0 && sizeImage.cx != 0) ? 2 : 0);
  1616. sizeFace.cy = max( sizeText.cy, sizeImage.cy );
  1617. }
  1618. else
  1619. {
  1620. sizeFace.cy = sizeText.cy + sizeImage.cy + ((sizeText.cy != 0 && sizeImage.cy != 0) ? 2 : 0);
  1621. sizeFace.cx = max( sizeText.cx, sizeImage.cx );
  1622. }
  1623. switch (GetStyleBits( UIBUTTON_HALIGNMASK )) {
  1624. case UIBUTTON_LEFT:
  1625. default: {
  1626. rcFace.left = rc.left + 2;
  1627. rcFace.right = rcFace.left + sizeFace.cx;
  1628. break;
  1629. }
  1630. case UIBUTTON_CENTER: {
  1631. rcFace.left = (rc.right + rc.left - sizeFace.cx) / 2;
  1632. rcFace.right = rcFace.left + sizeFace.cx;
  1633. break;
  1634. }
  1635. case UIBUTTON_RIGHT: {
  1636. rcFace.left = rc.right - 2 - sizeText.cx;
  1637. rcFace.right = rcFace.left + sizeFace.cx;
  1638. break;
  1639. }
  1640. }
  1641. switch (GetStyleBits( UIBUTTON_VALIGNMASK )) {
  1642. case UIBUTTON_TOP:
  1643. default: {
  1644. rcFace.top = rc.top + 2;
  1645. rcFace.bottom = rcFace.top + sizeFace.cy;
  1646. break;
  1647. }
  1648. case UIBUTTON_VCENTER: {
  1649. rcFace.top = (rc.bottom + rc.top - sizeFace.cy) / 2;
  1650. rcFace.bottom = rcFace.top + sizeFace.cy;
  1651. break;
  1652. }
  1653. case UIBUTTON_BOTTOM: {
  1654. rcFace.top = rc.bottom - 2 - sizeFace.cy;
  1655. rcFace.bottom = rcFace.top + sizeFace.cy;
  1656. break;
  1657. }
  1658. }
  1659. m_pUIFScheme->GetCtrlFaceOffset( GetDCF(), dwState, &offset );
  1660. OffsetRect( &rcFace, offset.cx, offset.cy );
  1661. if (!IsVertical())
  1662. {
  1663. rcImage.left = rcFace.left;
  1664. rcImage.top = (rcFace.bottom + rcFace.top - sizeImage.cy) / 2;
  1665. rcImage.right = rcImage.left + sizeImage.cx;
  1666. rcImage.bottom = rcImage.top + sizeImage.cy;
  1667. rcText.left = rcFace.right - sizeText.cx;
  1668. rcText.top = (rcFace.bottom + rcFace.top - sizeText.cy) / 2;
  1669. rcText.right = rcText.left + sizeText.cx;
  1670. rcText.bottom = rcText.top + sizeText.cy;
  1671. }
  1672. else
  1673. {
  1674. rcImage.left = (rcFace.right + rcFace.left - sizeImage.cx) / 2;
  1675. rcImage.top = rcFace.top;
  1676. rcImage.right = rcImage.left + sizeImage.cx;
  1677. rcImage.bottom = rcImage.top + sizeImage.cy;
  1678. rcText.left = (rcFace.right + rcFace.left - sizeText.cx) / 2;
  1679. rcText.top = rcFace.bottom - sizeText.cy;
  1680. rcText.right = rcText.left + sizeText.cx;
  1681. rcText.bottom = rcText.top + sizeText.cy;
  1682. }
  1683. if (IsRTL())
  1684. m_pUIFScheme->SetLayout(LAYOUT_RTL);
  1685. // paint background
  1686. m_pUIFScheme->DrawCtrlBkgd( hDCMem, &rc, GetDCF(), dwState );
  1687. // paint face
  1688. if (m_pwchText != NULL) {
  1689. m_pUIFScheme->DrawCtrlText( hDCMem, &rcText, m_pwchText, -1, dwState , IsVertical());
  1690. }
  1691. if (m_hIcon!= NULL) {
  1692. m_pUIFScheme->DrawCtrlIcon( hDCMem, &rcImage, m_hIcon, dwState, &m_sizeIcon );
  1693. }
  1694. else if (m_hBmp != NULL) {
  1695. m_pUIFScheme->DrawCtrlBitmap( hDCMem, &rcImage, m_hBmp, m_hBmpMask, dwState );
  1696. }
  1697. if (IsRTL())
  1698. m_pUIFScheme->SetLayout(0);
  1699. // draw button edge
  1700. m_pUIFScheme->DrawCtrlEdge( hDCMem, &rc, GetDCF(), dwState );
  1701. //
  1702. BitBlt( hDC, GetRectRef().left, GetRectRef().top, size.cx, size.cy, hDCMem, 0, 0, SRCCOPY );
  1703. SelectObject( hDCMem, hFontOld );
  1704. SelectObject( hDCMem, hBmpOld );
  1705. Exit:
  1706. if (hBmpMem)
  1707. DeleteObject( hBmpMem );
  1708. if (hDCMem)
  1709. DeleteDC( hDCMem );
  1710. }
  1711. /*=============================================================================*/
  1712. /* */
  1713. /* C U I F S C R O L L */
  1714. /* */
  1715. /*=============================================================================*/
  1716. //
  1717. // CUIFScrollButton
  1718. //
  1719. /* C U I F S C R O L L B U T T O N */
  1720. /*------------------------------------------------------------------------------
  1721. Constructor of CUIFScrollButton
  1722. ------------------------------------------------------------------------------*/
  1723. CUIFScrollButton::CUIFScrollButton( CUIFScroll *pUIScroll, const RECT *prc, DWORD dwStyle ) : CUIFButton( pUIScroll, 0, prc, dwStyle )
  1724. {
  1725. }
  1726. /* ~ C U I F S C R O L L B U T T O N */
  1727. /*------------------------------------------------------------------------------
  1728. Destructor of CUIFScrollButton
  1729. ------------------------------------------------------------------------------*/
  1730. CUIFScrollButton::~CUIFScrollButton( void )
  1731. {
  1732. }
  1733. /* O N L B U T T O N D O W N */
  1734. /*------------------------------------------------------------------------------
  1735. ------------------------------------------------------------------------------*/
  1736. void CUIFScrollButton::OnLButtonDown( POINT pt )
  1737. {
  1738. CUIFButton::OnLButtonDown( pt );
  1739. // scroll one item
  1740. NotifyCommand( UISCROLLBUTTON_PRESSED, 0 );
  1741. // create time to auto-repeat
  1742. StartTimer( GetScrollDelay() );
  1743. }
  1744. /* O N L B U T T O N U P */
  1745. /*------------------------------------------------------------------------------
  1746. ------------------------------------------------------------------------------*/
  1747. void CUIFScrollButton::OnLButtonUp( POINT pt )
  1748. {
  1749. CUIFButton::OnLButtonUp( pt );
  1750. // stop auto-repeat
  1751. if (IsTimer()) {
  1752. EndTimer();
  1753. }
  1754. }
  1755. /* O N M O U S E I N */
  1756. /*------------------------------------------------------------------------------
  1757. ------------------------------------------------------------------------------*/
  1758. void CUIFScrollButton::OnMouseIn( POINT pt )
  1759. {
  1760. CUIFButton::OnMouseIn( pt );
  1761. if (IsCapture()) {
  1762. // scroll one item when mouse is in
  1763. NotifyCommand( UISCROLLBUTTON_PRESSED, 0 );
  1764. // create timer to auto-repeat again
  1765. StartTimer( GetScrollSpeed() );
  1766. }
  1767. }
  1768. /* O N M O U S E O U T */
  1769. /*------------------------------------------------------------------------------
  1770. ------------------------------------------------------------------------------*/
  1771. void CUIFScrollButton::OnMouseOut( POINT pt )
  1772. {
  1773. CUIFButton::OnMouseOut( pt );
  1774. // kill timer to prevent from auto-repeat
  1775. if (IsTimer()) {
  1776. EndTimer();
  1777. }
  1778. }
  1779. /* O N P A I N T */
  1780. /*------------------------------------------------------------------------------
  1781. Paint procedure of scroll button object
  1782. ------------------------------------------------------------------------------*/
  1783. void CUIFScrollButton::OnPaint( HDC hDC )
  1784. {
  1785. RECT rc = GetRectRef();
  1786. UINT uState = 0;
  1787. switch (m_dwStyle & UISCROLLBUTTON_DIRMASK) {
  1788. case UISCROLLBUTTON_LEFT: {
  1789. uState = DFCS_SCROLLLEFT;
  1790. break;
  1791. }
  1792. case UISCROLLBUTTON_UP: {
  1793. uState = DFCS_SCROLLUP;
  1794. break;
  1795. }
  1796. case UISCROLLBUTTON_RIGHT: {
  1797. uState = DFCS_SCROLLRIGHT;
  1798. break;
  1799. }
  1800. case UISCROLLBUTTON_DOWN: {
  1801. uState = DFCS_SCROLLDOWN;
  1802. break;
  1803. }
  1804. }
  1805. uState |= ((m_dwStatus == UIBUTTON_DOWN) ? DFCS_PUSHED | DFCS_FLAT : 0);
  1806. uState |= ((!IsEnabled()) ? DFCS_INACTIVE : 0);
  1807. DrawFrameControl( hDC, &rc, DFC_SCROLL, uState );
  1808. }
  1809. /* O N T I M E R */
  1810. /*------------------------------------------------------------------------------
  1811. ------------------------------------------------------------------------------*/
  1812. void CUIFScrollButton::OnTimer( void )
  1813. {
  1814. POINT pt;
  1815. StartTimer( GetScrollSpeed() );
  1816. GetCursorPos( &pt );
  1817. ScreenToClient( m_pUIWnd->GetWnd(), &pt );
  1818. if (PtInObject( pt )) {
  1819. NotifyCommand( UISCROLLBUTTON_PRESSED, 0 );
  1820. }
  1821. }
  1822. //
  1823. // CUIFScrollThumb
  1824. //
  1825. /* C U I F S C R O L L T H U M B */
  1826. /*------------------------------------------------------------------------------
  1827. Constructor of CUIFScrollThumb
  1828. ------------------------------------------------------------------------------*/
  1829. CUIFScrollThumb::CUIFScrollThumb( CUIFScroll *pUIScroll, const RECT *prc, DWORD dwStyle ) : CUIFObject( pUIScroll, 0 /* no id */, prc, dwStyle )
  1830. {
  1831. }
  1832. /* ~ C U I F S C R O L L T H U M B */
  1833. /*------------------------------------------------------------------------------
  1834. Destructor of CUIFScrollThumb
  1835. ------------------------------------------------------------------------------*/
  1836. CUIFScrollThumb::~CUIFScrollThumb( void )
  1837. {
  1838. }
  1839. /* O N P A I N T */
  1840. /*------------------------------------------------------------------------------
  1841. Paint procedure of scroll thumb object
  1842. ------------------------------------------------------------------------------*/
  1843. void CUIFScrollThumb::OnPaint(HDC hDC)
  1844. {
  1845. RECT rc = GetRectRef();
  1846. if (!IsEnabled()) {
  1847. return;
  1848. }
  1849. FillRect( hDC, &rc, (HBRUSH)(COLOR_3DFACE + 1) );
  1850. DrawEdge( hDC, &rc, EDGE_RAISED, BF_RECT );
  1851. }
  1852. /* O N L B U T T O N D O W N */
  1853. /*------------------------------------------------------------------------------
  1854. ------------------------------------------------------------------------------*/
  1855. void CUIFScrollThumb::OnLButtonDown( POINT pt )
  1856. {
  1857. if (IsEnabled()) {
  1858. StartCapture();
  1859. m_ptDragOrg = pt;
  1860. m_ptDrag.x = pt.x - GetRectRef().left;
  1861. m_ptDrag.y = pt.y - GetRectRef().top;
  1862. }
  1863. }
  1864. /* O N L B U T T O N U P */
  1865. /*------------------------------------------------------------------------------
  1866. ------------------------------------------------------------------------------*/
  1867. void CUIFScrollThumb::OnLButtonUp( POINT pt )
  1868. {
  1869. if (IsCapture()) {
  1870. EndCapture();
  1871. DragProc( pt, TRUE /* end of dragging */ );
  1872. }
  1873. }
  1874. /* O N M O U S E M O V E */
  1875. /*------------------------------------------------------------------------------
  1876. ------------------------------------------------------------------------------*/
  1877. void CUIFScrollThumb::OnMouseMove( POINT pt )
  1878. {
  1879. if (IsCapture()) {
  1880. DragProc( pt, FALSE /* still dragging */ );
  1881. }
  1882. }
  1883. /* S E T S C R O L L A R E A */
  1884. /*------------------------------------------------------------------------------
  1885. Set scroll area
  1886. ------------------------------------------------------------------------------*/
  1887. void CUIFScrollThumb::SetScrollArea( RECT *prc )
  1888. {
  1889. m_rcScrollArea = *prc;
  1890. }
  1891. /* D R A G P R O C */
  1892. /*------------------------------------------------------------------------------
  1893. Handle mouse message while dragging
  1894. Move the thumb and notify to the parent object (Scroll).
  1895. ------------------------------------------------------------------------------*/
  1896. void CUIFScrollThumb::DragProc( POINT pt, BOOL fEndDrag )
  1897. {
  1898. RECT rcValid;
  1899. // get valid drag area (TEMP code)
  1900. m_pParent->GetRect( &rcValid );
  1901. InflateRect( &rcValid, 64, 64 );
  1902. // check if drag point is valid
  1903. if (!PtInRect( &rcValid, pt )) {
  1904. RECT rc;
  1905. // back to original position
  1906. rc.left = m_ptDragOrg.x - m_ptDrag.x;
  1907. rc.top = m_ptDragOrg.y - m_ptDrag.y;
  1908. rc.right = rc.left + (GetRectRef().right - GetRectRef().left);
  1909. rc.bottom = rc.top + (GetRectRef().bottom - GetRectRef().top);
  1910. // move myself and notify to parent
  1911. SetRect( &rc );
  1912. NotifyCommand( UISCROLLTHUMB_MOVED, 0 );
  1913. }
  1914. else {
  1915. RECT rc;
  1916. // calc new thumb position
  1917. rc.left = pt.x - m_ptDrag.x;
  1918. rc.top = pt.y - m_ptDrag.y;
  1919. rc.right = rc.left + (GetRectRef().right - GetRectRef().left);
  1920. rc.bottom = rc.top + (GetRectRef().bottom - GetRectRef().top);
  1921. // adjust thumb position
  1922. if (rc.top < m_rcScrollArea.top) {
  1923. rc.bottom += (m_rcScrollArea.top - rc.top);
  1924. rc.top += (m_rcScrollArea.top - rc.top);
  1925. }
  1926. else if (m_rcScrollArea.bottom < rc.bottom) {
  1927. rc.top += (m_rcScrollArea.bottom - rc.bottom);
  1928. rc.bottom += (m_rcScrollArea.bottom - rc.bottom);
  1929. }
  1930. if (rc.left < m_rcScrollArea.left) {
  1931. rc.right += (m_rcScrollArea.left - rc.left);
  1932. rc.left += (m_rcScrollArea.left - rc.left);
  1933. }
  1934. else if (m_rcScrollArea.right < rc.right) {
  1935. rc.left += (m_rcScrollArea.right - rc.right);
  1936. rc.right += (m_rcScrollArea.right - rc.right);
  1937. }
  1938. // move myself and notify to parent
  1939. SetRect( &rc );
  1940. NotifyCommand( fEndDrag ? UISCROLLTHUMB_MOVED : UISCROLLTHUMB_MOVING, 0 );
  1941. }
  1942. }
  1943. //
  1944. // CUIFScroll
  1945. //
  1946. /* C U I F S C R O L L */
  1947. /*------------------------------------------------------------------------------
  1948. Constructor of CUIFScroll
  1949. ------------------------------------------------------------------------------*/
  1950. CUIFScroll::CUIFScroll( CUIFObject *pParent, DWORD dwID, const RECT *prc, DWORD dwStyle ) : CUIFObject( pParent, dwID, prc, dwStyle )
  1951. {
  1952. m_ScrollInfo.nMax = 0;
  1953. m_ScrollInfo.nPage = 0;
  1954. m_ScrollInfo.nPos = 0;
  1955. m_fScrollPage = FALSE;
  1956. m_dwScrollDir = UISCROLL_NONE;
  1957. // get metrics
  1958. GetMetrics();
  1959. }
  1960. /* ~ C U I F S C R O L L */
  1961. /*------------------------------------------------------------------------------
  1962. Destructor of CUIFScroll
  1963. ------------------------------------------------------------------------------*/
  1964. CUIFScroll::~CUIFScroll( void )
  1965. {
  1966. }
  1967. /* I N I T I A L I Z E */
  1968. /*------------------------------------------------------------------------------
  1969. Intialize scroll object
  1970. ------------------------------------------------------------------------------*/
  1971. CUIFObject *CUIFScroll::Initialize( void )
  1972. {
  1973. RECT rc;
  1974. // create child objects
  1975. GetBtnUpRect( &rc );
  1976. m_pBtnUp = new CUIFScrollButton( this, &rc, GetScrollUpBtnStyle() );
  1977. if (m_pBtnUp)
  1978. {
  1979. m_pBtnUp->Initialize();
  1980. AddUIObj( m_pBtnUp );
  1981. }
  1982. GetBtnDnRect( &rc );
  1983. m_pBtnDn = new CUIFScrollButton( this, &rc, GetScrollDnBtnStyle() );
  1984. if (m_pBtnDn)
  1985. {
  1986. m_pBtnDn->Initialize();
  1987. AddUIObj( m_pBtnDn );
  1988. }
  1989. GetThumbRect( &rc );
  1990. m_pThumb = new CUIFScrollThumb( this, &rc, GetScrollThumbStyle() );
  1991. if (m_pThumb)
  1992. {
  1993. m_pThumb->Initialize();
  1994. AddUIObj( m_pThumb );
  1995. //
  1996. GetScrollArea( &rc );
  1997. m_pThumb->SetScrollArea( &rc );
  1998. }
  1999. //
  2000. return CUIFObject::Initialize();
  2001. }
  2002. /* O N P A I N T */
  2003. /*------------------------------------------------------------------------------
  2004. Paint procedure of scroll object
  2005. ------------------------------------------------------------------------------*/
  2006. void CUIFScroll::OnPaint( HDC hDC )
  2007. {
  2008. HBRUSH hBrush;
  2009. // paint scroll bar back
  2010. hBrush = (HBRUSH)DefWindowProc( m_pUIWnd->GetWnd(), WM_CTLCOLORSCROLLBAR, (WPARAM)hDC, (LPARAM)m_pUIWnd->GetWnd() );
  2011. if (hBrush == NULL) {
  2012. // never happen? just in case...
  2013. hBrush = GetSysColorBrush(COLOR_SCROLLBAR);
  2014. }
  2015. FillRect( hDC, &GetRectRef(), hBrush );
  2016. DeleteObject( hBrush );
  2017. // paint scroll area
  2018. if (m_fScrollPage) {
  2019. RECT rc;
  2020. switch (m_dwScrollDir) {
  2021. case UISCROLL_PAGEUP: {
  2022. GetPageUpArea( &rc );
  2023. break;
  2024. }
  2025. case UISCROLL_PAGEDOWN: {
  2026. GetPageDnArea( &rc );
  2027. break;
  2028. }
  2029. }
  2030. InvertRect( hDC, &rc );
  2031. }
  2032. }
  2033. /* O N L B U T T O N D O W N */
  2034. /*------------------------------------------------------------------------------
  2035. ------------------------------------------------------------------------------*/
  2036. void CUIFScroll::OnLButtonDown( POINT pt )
  2037. {
  2038. if (!m_pThumb->IsVisible()) {
  2039. return;
  2040. }
  2041. StartCapture();
  2042. if (PtInPageUpArea( pt )) {
  2043. StartTimer( GetScrollDelay() );
  2044. m_fScrollPage = TRUE;
  2045. m_dwScrollDir = UISCROLL_PAGEUP;
  2046. ShiftPage( -1 );
  2047. }
  2048. else if (PtInPageDnArea( pt )) {
  2049. StartTimer( GetScrollDelay() );
  2050. m_fScrollPage = TRUE;
  2051. m_dwScrollDir = UISCROLL_PAGEDOWN;
  2052. ShiftPage( +1 );
  2053. }
  2054. else {
  2055. Assert( FALSE );
  2056. }
  2057. CallOnPaint();
  2058. }
  2059. /* O N L B U T T O N U P */
  2060. /*------------------------------------------------------------------------------
  2061. ------------------------------------------------------------------------------*/
  2062. void CUIFScroll::OnLButtonUp( POINT pt )
  2063. {
  2064. if (IsCapture()) {
  2065. EndCapture();
  2066. }
  2067. if (IsTimer()) {
  2068. EndTimer();
  2069. }
  2070. m_fScrollPage = FALSE;
  2071. m_dwScrollDir = UISCROLL_NONE;
  2072. CallOnPaint();
  2073. }
  2074. /* O N M O U S E I N */
  2075. /*------------------------------------------------------------------------------
  2076. ------------------------------------------------------------------------------*/
  2077. void CUIFScroll::OnMouseIn( POINT pt )
  2078. {
  2079. if (IsCapture()) {
  2080. switch (m_dwScrollDir) {
  2081. case UISCROLL_PAGEUP: {
  2082. if (PtInPageUpArea( pt )) {
  2083. StartTimer( GetScrollSpeed() );
  2084. m_fScrollPage = TRUE;
  2085. ShiftPage( -1 );
  2086. CallOnPaint();
  2087. }
  2088. break;
  2089. }
  2090. case UISCROLL_PAGEDOWN: {
  2091. if (PtInPageDnArea( pt )) {
  2092. StartTimer( GetScrollSpeed() );
  2093. m_fScrollPage = TRUE;
  2094. ShiftPage( +1 );
  2095. CallOnPaint();
  2096. }
  2097. break;
  2098. }
  2099. }
  2100. }
  2101. }
  2102. /* O N M O U S E O U T */
  2103. /*------------------------------------------------------------------------------
  2104. ------------------------------------------------------------------------------*/
  2105. void CUIFScroll::OnMouseOut( POINT pt )
  2106. {
  2107. m_fScrollPage = FALSE;
  2108. if (IsTimer()) {
  2109. EndTimer();
  2110. }
  2111. CallOnPaint();
  2112. }
  2113. /* S E T R E C T */
  2114. /*------------------------------------------------------------------------------
  2115. ------------------------------------------------------------------------------*/
  2116. void CUIFScroll::SetRect( const RECT *prc )
  2117. {
  2118. RECT rc;
  2119. BOOL fThumbVisible;
  2120. CUIFObject::SetRect( prc );
  2121. // adjist child object poisition
  2122. GetBtnUpRect( &rc );
  2123. m_pBtnUp->SetRect( &rc );
  2124. GetBtnDnRect( &rc );
  2125. m_pBtnDn->SetRect( &rc );
  2126. GetScrollArea( &rc );
  2127. m_pThumb->SetScrollArea( &rc );
  2128. fThumbVisible = GetThumbRect( &rc );
  2129. m_pThumb->SetRect( &rc );
  2130. m_pThumb->Show( IsVisible() && fThumbVisible );
  2131. }
  2132. /* S E T S T Y L E */
  2133. /*------------------------------------------------------------------------------
  2134. ------------------------------------------------------------------------------*/
  2135. void CUIFScroll::SetStyle( DWORD dwStyle )
  2136. {
  2137. RECT rc;
  2138. BOOL fThumbVisible;
  2139. CUIFObject::SetStyle( dwStyle );
  2140. //
  2141. GetMetrics();
  2142. // update child object style
  2143. m_pBtnUp->SetStyle( GetScrollUpBtnStyle() );
  2144. m_pBtnDn->SetStyle( GetScrollDnBtnStyle() );
  2145. m_pThumb->SetStyle( GetScrollThumbStyle() );
  2146. // update child object poisition
  2147. GetBtnUpRect( &rc );
  2148. m_pBtnUp->SetRect( &rc );
  2149. GetBtnDnRect( &rc );
  2150. m_pBtnDn->SetRect( &rc );
  2151. GetScrollArea( &rc );
  2152. m_pThumb->SetScrollArea( &rc );
  2153. fThumbVisible = GetThumbRect( &rc );
  2154. m_pThumb->SetRect( &rc );
  2155. m_pThumb->Show( IsVisible() && fThumbVisible );
  2156. }
  2157. /* S H O W */
  2158. /*------------------------------------------------------------------------------
  2159. show/hide scroll bar
  2160. ------------------------------------------------------------------------------*/
  2161. void CUIFScroll::Show( BOOL fShow )
  2162. {
  2163. if (m_fVisible != fShow) {
  2164. RECT rcThumb;
  2165. BOOL fThumbVisible;
  2166. m_fVisible = fShow;
  2167. fThumbVisible = GetThumbRect( &rcThumb );
  2168. m_pBtnUp->Show( fShow );
  2169. m_pBtnDn->Show( fShow );
  2170. m_pThumb->Show( fShow && fThumbVisible );
  2171. // let parent paint the object when it's hidden
  2172. if (!m_fVisible) {
  2173. if (m_pParent != NULL) {
  2174. m_pParent->CallOnPaint();
  2175. }
  2176. }
  2177. else {
  2178. CallOnPaint();
  2179. }
  2180. }
  2181. }
  2182. /* O N T I M E R */
  2183. /*------------------------------------------------------------------------------
  2184. ------------------------------------------------------------------------------*/
  2185. void CUIFScroll::OnTimer( void )
  2186. {
  2187. POINT pt;
  2188. StartTimer( GetScrollSpeed() );
  2189. GetCursorPos( &pt );
  2190. ScreenToClient( m_pUIWnd->GetWnd(), &pt );
  2191. switch (m_dwScrollDir) {
  2192. case UISCROLL_PAGEUP: {
  2193. if (PtInPageUpArea( pt )) {
  2194. ShiftPage( -1 );
  2195. }
  2196. break;
  2197. }
  2198. case UISCROLL_PAGEDOWN: {
  2199. if (PtInPageDnArea( pt )) {
  2200. ShiftPage( +1 );
  2201. }
  2202. break;
  2203. }
  2204. }
  2205. }
  2206. /* S E T S C R O L L I N F O */
  2207. /*------------------------------------------------------------------------------
  2208. Set scrollbar info
  2209. ------------------------------------------------------------------------------*/
  2210. void CUIFScroll::SetScrollInfo( UIFSCROLLINFO *pScrollInfo )
  2211. {
  2212. BOOL fEnable;
  2213. Assert( pScrollInfo != NULL );
  2214. m_ScrollInfo.nMax = pScrollInfo->nMax;
  2215. m_ScrollInfo.nPage = pScrollInfo->nPage;
  2216. // disable when cannot scroll
  2217. fEnable = (m_ScrollInfo.nMax > m_ScrollInfo.nPage);
  2218. Enable( fEnable );
  2219. m_pBtnUp->Enable( fEnable );
  2220. m_pBtnDn->Enable( fEnable );
  2221. m_pThumb->Enable( fEnable );
  2222. // clear scrolling page info
  2223. m_fScrollPage = FALSE;
  2224. m_dwScrollDir = UISCROLL_NONE;
  2225. //
  2226. SetCurPos( pScrollInfo->nPos, TRUE /* adjust thumb position */ );
  2227. }
  2228. /* G E T S C R O L L I N F O */
  2229. /*------------------------------------------------------------------------------
  2230. Get scrollbar info
  2231. ------------------------------------------------------------------------------*/
  2232. void CUIFScroll::GetScrollInfo( UIFSCROLLINFO *pScrollInfo )
  2233. {
  2234. Assert( pScrollInfo != NULL );
  2235. *pScrollInfo = m_ScrollInfo;
  2236. }
  2237. /* G E T T H U M B R E C T */
  2238. /*------------------------------------------------------------------------------
  2239. ------------------------------------------------------------------------------*/
  2240. BOOL CUIFScroll::GetThumbRect( RECT *prc )
  2241. {
  2242. RECT rcScroll;
  2243. BOOL fVisible;
  2244. // return FALSE when thumb is invisible
  2245. if (m_ScrollInfo.nMax <= 0 ||
  2246. m_ScrollInfo.nPage <= 0 ||
  2247. m_ScrollInfo.nMax <= m_ScrollInfo.nPage) {
  2248. ::SetRect( prc, 0, 0, 0, 0 );
  2249. return FALSE;
  2250. }
  2251. // calc thumb rect from current position
  2252. GetScrollArea( &rcScroll );
  2253. switch (m_dwStyle & UISCROLL_DIRMASK) {
  2254. default:
  2255. case UISCROLL_VERTTB: {
  2256. int nThumbHeight = (rcScroll.bottom - rcScroll.top) * m_ScrollInfo.nPage / m_ScrollInfo.nMax;
  2257. nThumbHeight = max( SCROLLTHUMBHEIGHT_MIN, nThumbHeight );
  2258. fVisible = (nThumbHeight <= (rcScroll.bottom - rcScroll.top));
  2259. prc->left = GetRectRef().left;
  2260. prc->top = rcScroll.top + (rcScroll.bottom - rcScroll.top - nThumbHeight) * m_ScrollInfo.nPos / (m_ScrollInfo.nMax - m_ScrollInfo.nPage);
  2261. prc->right = GetRectRef().right;
  2262. prc->bottom = prc->top + nThumbHeight;
  2263. break;
  2264. }
  2265. case UISCROLL_VERTBT: {
  2266. int nThumbHeight = (rcScroll.bottom - rcScroll.top) * m_ScrollInfo.nPage / m_ScrollInfo.nMax;
  2267. nThumbHeight = max( SCROLLTHUMBHEIGHT_MIN, nThumbHeight );
  2268. fVisible = (nThumbHeight <= (rcScroll.bottom - rcScroll.top));
  2269. prc->left = GetRectRef().left;
  2270. prc->top = rcScroll.bottom - (rcScroll.bottom - rcScroll.top - nThumbHeight) * m_ScrollInfo.nPos / (m_ScrollInfo.nMax - m_ScrollInfo.nPage) - nThumbHeight;
  2271. prc->right = GetRectRef().right;
  2272. prc->bottom = prc->top + nThumbHeight;
  2273. break;
  2274. }
  2275. case UISCROLL_HORZLR: {
  2276. int nThumbWidth = (rcScroll.right - rcScroll.left) * m_ScrollInfo.nPage / m_ScrollInfo.nMax;
  2277. nThumbWidth = max( SCROLLTHUMBHEIGHT_MIN, nThumbWidth );
  2278. fVisible = (nThumbWidth <= (rcScroll.right - rcScroll.left));
  2279. prc->left = rcScroll.left + (rcScroll.right - rcScroll.left - nThumbWidth) * m_ScrollInfo.nPos / (m_ScrollInfo.nMax - m_ScrollInfo.nPage);
  2280. prc->top = GetRectRef().top;
  2281. prc->right = prc->left + nThumbWidth;
  2282. prc->bottom = GetRectRef().bottom;
  2283. break;
  2284. }
  2285. case UISCROLL_HORZRL: {
  2286. int nThumbWidth = (rcScroll.right - rcScroll.left) * m_ScrollInfo.nPage / m_ScrollInfo.nMax;
  2287. nThumbWidth = max( SCROLLTHUMBHEIGHT_MIN, nThumbWidth );
  2288. fVisible = (nThumbWidth <= (rcScroll.right - rcScroll.left));
  2289. prc->left = rcScroll.right - (rcScroll.right - rcScroll.left - nThumbWidth) * m_ScrollInfo.nPos / (m_ScrollInfo.nMax - m_ScrollInfo.nPage) - nThumbWidth;
  2290. prc->top = GetRectRef().top;
  2291. prc->right = prc->left + nThumbWidth;
  2292. prc->bottom = GetRectRef().bottom;
  2293. break;
  2294. }
  2295. }
  2296. return fVisible;
  2297. }
  2298. /* G E T B T N U P R E C T */
  2299. /*------------------------------------------------------------------------------
  2300. ------------------------------------------------------------------------------*/
  2301. BOOL CUIFScroll::GetBtnUpRect( RECT *prc )
  2302. {
  2303. switch (m_dwStyle & UISCROLL_DIRMASK) {
  2304. default:
  2305. case UISCROLL_VERTTB: {
  2306. prc->left = GetRectRef().left;
  2307. prc->top = GetRectRef().top;
  2308. prc->right = GetRectRef().right;
  2309. prc->bottom = GetRectRef().top + min( m_sizeScrollBtn.cy, (GetRectRef().bottom - GetRectRef().top)/2 );
  2310. break;
  2311. }
  2312. case UISCROLL_VERTBT: {
  2313. prc->left = GetRectRef().left;
  2314. prc->top = GetRectRef().bottom - min( m_sizeScrollBtn.cy, (GetRectRef().bottom - GetRectRef().top)/2 );
  2315. prc->right = GetRectRef().right;
  2316. prc->bottom = GetRectRef().bottom;
  2317. break;
  2318. }
  2319. case UISCROLL_HORZLR: {
  2320. prc->left = GetRectRef().left;
  2321. prc->top = GetRectRef().top;
  2322. prc->right = GetRectRef().left + min( m_sizeScrollBtn.cx, (GetRectRef().right - GetRectRef().left)/2 );
  2323. prc->bottom = GetRectRef().bottom;
  2324. break;
  2325. }
  2326. case UISCROLL_HORZRL: {
  2327. prc->left = GetRectRef().right - min( m_sizeScrollBtn.cx, (GetRectRef().right - GetRectRef().left)/2 );
  2328. prc->top = GetRectRef().top;
  2329. prc->right = GetRectRef().right;
  2330. prc->bottom = GetRectRef().bottom;
  2331. break;
  2332. }
  2333. }
  2334. return TRUE;
  2335. }
  2336. /* G E T B T N D N R E C T */
  2337. /*------------------------------------------------------------------------------
  2338. ------------------------------------------------------------------------------*/
  2339. BOOL CUIFScroll::GetBtnDnRect( RECT *prc )
  2340. {
  2341. switch (m_dwStyle & UISCROLL_DIRMASK) {
  2342. default:
  2343. case UISCROLL_VERTTB: {
  2344. prc->left = GetRectRef().left;
  2345. prc->top = GetRectRef().bottom - min( m_sizeScrollBtn.cy, (GetRectRef().bottom - GetRectRef().top)/2 );
  2346. prc->right = GetRectRef().right;
  2347. prc->bottom = GetRectRef().bottom;
  2348. break;
  2349. }
  2350. case UISCROLL_VERTBT: {
  2351. prc->left = GetRectRef().left;
  2352. prc->top = GetRectRef().top;
  2353. prc->right = GetRectRef().right;
  2354. prc->bottom = GetRectRef().top + min( m_sizeScrollBtn.cy, (GetRectRef().bottom - GetRectRef().top)/2 );
  2355. break;
  2356. }
  2357. case UISCROLL_HORZLR: {
  2358. prc->left = GetRectRef().right - min( m_sizeScrollBtn.cx, (GetRectRef().right - GetRectRef().left)/2 );
  2359. prc->top = GetRectRef().top;
  2360. prc->right = GetRectRef().right;
  2361. prc->bottom = GetRectRef().bottom;
  2362. break;
  2363. }
  2364. case UISCROLL_HORZRL: {
  2365. prc->left = GetRectRef().left;
  2366. prc->top = GetRectRef().top;
  2367. prc->right = GetRectRef().left + min( m_sizeScrollBtn.cx, (GetRectRef().right - GetRectRef().left)/2 );
  2368. prc->bottom = GetRectRef().bottom;
  2369. break;
  2370. }
  2371. }
  2372. return TRUE;
  2373. }
  2374. /* O N O B J E C T N O T I F Y */
  2375. /*------------------------------------------------------------------------------
  2376. ------------------------------------------------------------------------------*/
  2377. LRESULT CUIFScroll::OnObjectNotify( CUIFObject *pUIObj, DWORD dwCommand, LPARAM lParam )
  2378. {
  2379. if (pUIObj == m_pBtnUp) {
  2380. switch (dwCommand) {
  2381. case UISCROLLBUTTON_PRESSED: {
  2382. if (NotifyCommand( UISCROLLNOTIFY_SCROLLLN, -1 ) == 0) {
  2383. ShiftLine( -1 );
  2384. }
  2385. break;
  2386. }
  2387. }
  2388. }
  2389. else if (pUIObj == m_pBtnDn) {
  2390. switch (dwCommand) {
  2391. case UISCROLLBUTTON_PRESSED: {
  2392. if (NotifyCommand( UISCROLLNOTIFY_SCROLLLN, +1 ) == 0) {
  2393. ShiftLine( +1 );
  2394. }
  2395. break;
  2396. }
  2397. }
  2398. }
  2399. else if (pUIObj == m_pThumb) {
  2400. switch (dwCommand) {
  2401. case UISCROLLTHUMB_MOVING:
  2402. case UISCROLLTHUMB_MOVED: {
  2403. RECT rcThumb;
  2404. RECT rcScroll;
  2405. int nPos;
  2406. int nPosMax;
  2407. int ptThumb;
  2408. int ptMax;
  2409. m_pThumb->GetRect( &rcThumb );
  2410. GetScrollArea( &rcScroll );
  2411. nPosMax = m_ScrollInfo.nMax - m_ScrollInfo.nPage;
  2412. switch (m_dwStyle & UISCROLL_DIRMASK) {
  2413. default:
  2414. case UISCROLL_VERTTB: {
  2415. ptThumb = rcThumb.top - rcScroll.top;
  2416. ptMax = (rcScroll.bottom - rcScroll.top) - (rcThumb.bottom - rcThumb.top);
  2417. break;
  2418. }
  2419. case UISCROLL_VERTBT: {
  2420. ptThumb = rcScroll.bottom - rcThumb.bottom;
  2421. ptMax = (rcScroll.bottom - rcScroll.top) - (rcThumb.bottom - rcThumb.top);
  2422. break;
  2423. }
  2424. case UISCROLL_HORZLR: {
  2425. ptThumb = rcThumb.left - rcScroll.left;
  2426. ptMax = (rcScroll.right - rcScroll.left) - (rcThumb.right - rcThumb.left);
  2427. break;
  2428. }
  2429. case UISCROLL_HORZRL: {
  2430. ptThumb = rcScroll.right - rcThumb.right;
  2431. ptMax = (rcScroll.right - rcScroll.left) - (rcThumb.right - rcThumb.left);
  2432. break;
  2433. }
  2434. }
  2435. Assert( (0 <= ptThumb) && (ptThumb <= ptMax) );
  2436. if (ptMax == 0) {
  2437. nPos = 0;
  2438. }
  2439. else {
  2440. nPos = (ptThumb * nPosMax + ptMax/2) / ptMax;
  2441. nPos = max( nPos, 0 );
  2442. nPos = min( nPos, nPosMax );
  2443. }
  2444. SetCurPos( nPos, (dwCommand == UISCROLLTHUMB_MOVED) /* adjust thumb position */ );
  2445. break;
  2446. }
  2447. } /* of switch */
  2448. }
  2449. return 0;
  2450. }
  2451. /* S E T C U R P O S */
  2452. /*------------------------------------------------------------------------------
  2453. Set current page position
  2454. ------------------------------------------------------------------------------*/
  2455. void CUIFScroll::SetCurPos( int nPos, BOOL fAdjustThumbPos )
  2456. {
  2457. int nPosMax = (m_ScrollInfo.nMax <= m_ScrollInfo.nPage) ? 0 : m_ScrollInfo.nMax - m_ScrollInfo.nPage;
  2458. // set position
  2459. nPosMax = m_ScrollInfo.nMax - m_ScrollInfo.nPage;
  2460. nPos = min( nPos, nPosMax );
  2461. nPos = max( nPos, 0 );
  2462. m_ScrollInfo.nPos = nPos;
  2463. // set thumb position
  2464. if (fAdjustThumbPos) {
  2465. RECT rcThumb;
  2466. BOOL fThumbVisible;
  2467. fThumbVisible = GetThumbRect( &rcThumb );
  2468. m_pThumb->SetRect( &rcThumb );
  2469. m_pThumb->Show( IsVisible() && fThumbVisible );
  2470. }
  2471. if (IsVisible()) {
  2472. CallOnPaint();
  2473. }
  2474. // notify scroll to parent
  2475. NotifyCommand( UISCROLLNOTIFY_SCROLLED, m_ScrollInfo.nPos );
  2476. }
  2477. /* G E T S C R O L L A R E A */
  2478. /*------------------------------------------------------------------------------
  2479. ------------------------------------------------------------------------------*/
  2480. void CUIFScroll::GetScrollArea( RECT *prc )
  2481. {
  2482. RECT rcBtnUp;
  2483. RECT rcBtnDn;
  2484. Assert( prc != NULL );
  2485. GetBtnUpRect( &rcBtnUp );
  2486. GetBtnDnRect( &rcBtnDn );
  2487. switch (m_dwStyle & UISCROLL_DIRMASK) {
  2488. default:
  2489. case UISCROLL_VERTTB: {
  2490. prc->left = GetRectRef().left;
  2491. prc->top = GetRectRef().top + (rcBtnUp.bottom - rcBtnUp.top);
  2492. prc->right = GetRectRef().right;
  2493. prc->bottom = GetRectRef().bottom - (rcBtnDn.bottom - rcBtnDn.top);
  2494. break;
  2495. }
  2496. case UISCROLL_VERTBT: {
  2497. prc->left = GetRectRef().left;
  2498. prc->top = GetRectRef().top + (rcBtnDn.bottom - rcBtnDn.top);
  2499. prc->right = GetRectRef().right;
  2500. prc->bottom = GetRectRef().bottom - (rcBtnUp.bottom - rcBtnUp.top);
  2501. break;
  2502. }
  2503. case UISCROLL_HORZLR: {
  2504. prc->left = GetRectRef().left + (rcBtnUp.bottom - rcBtnUp.top);
  2505. prc->top = GetRectRef().top;
  2506. prc->right = GetRectRef().right - (rcBtnDn.bottom - rcBtnDn.top);
  2507. prc->bottom = GetRectRef().bottom;
  2508. break;
  2509. }
  2510. case UISCROLL_HORZRL: {
  2511. prc->left = GetRectRef().left + (rcBtnDn.bottom - rcBtnDn.top);
  2512. prc->top = GetRectRef().top;
  2513. prc->right = GetRectRef().right - (rcBtnUp.bottom - rcBtnUp.top);
  2514. prc->bottom = GetRectRef().bottom;
  2515. break;
  2516. }
  2517. }
  2518. }
  2519. /* G E T P A G E U P A R E A */
  2520. /*------------------------------------------------------------------------------
  2521. ------------------------------------------------------------------------------*/
  2522. void CUIFScroll::GetPageUpArea( RECT *prc )
  2523. {
  2524. RECT rcThumb;
  2525. RECT rcBtnUp;
  2526. Assert( prc != NULL );
  2527. m_pThumb->GetRect( &rcThumb );
  2528. GetBtnUpRect( &rcBtnUp );
  2529. switch (m_dwStyle & UISCROLL_DIRMASK) {
  2530. default:
  2531. case UISCROLL_VERTTB: {
  2532. prc->left = GetRectRef().left;
  2533. prc->top = GetRectRef().top + (rcBtnUp.bottom - rcBtnUp.top);
  2534. prc->right = GetRectRef().right;
  2535. prc->bottom = rcThumb.top;
  2536. break;
  2537. }
  2538. case UISCROLL_VERTBT: {
  2539. prc->left = GetRectRef().left;
  2540. prc->top = rcThumb.bottom;
  2541. prc->right = GetRectRef().right;
  2542. prc->bottom = GetRectRef().bottom - (rcBtnUp.bottom - rcBtnUp.top);
  2543. break;
  2544. }
  2545. case UISCROLL_HORZLR: {
  2546. prc->left = GetRectRef().left + (rcBtnUp.bottom - rcBtnUp.top);
  2547. prc->top = GetRectRef().top;;
  2548. prc->right = rcThumb.left;
  2549. prc->bottom = GetRectRef().bottom;;
  2550. break;
  2551. }
  2552. case UISCROLL_HORZRL: {
  2553. prc->left = rcThumb.right;
  2554. prc->top = GetRectRef().top;
  2555. prc->right = GetRectRef().right - (rcBtnUp.bottom - rcBtnUp.top);
  2556. prc->bottom = GetRectRef().bottom;;
  2557. break;
  2558. }
  2559. }
  2560. }
  2561. /* G E T P A G E D N A R E A */
  2562. /*------------------------------------------------------------------------------
  2563. ------------------------------------------------------------------------------*/
  2564. void CUIFScroll::GetPageDnArea( RECT *prc )
  2565. {
  2566. RECT rcThumb;
  2567. RECT rcBtnDn;
  2568. Assert( prc != NULL );
  2569. m_pThumb->GetRect( &rcThumb );
  2570. GetBtnDnRect( &rcBtnDn );
  2571. switch (m_dwStyle & UISCROLL_DIRMASK) {
  2572. default:
  2573. case UISCROLL_VERTTB: {
  2574. prc->left = GetRectRef().left;
  2575. prc->top = rcThumb.bottom;
  2576. prc->right = GetRectRef().right;
  2577. prc->bottom = GetRectRef().bottom - (rcBtnDn.bottom - rcBtnDn.top);
  2578. break;
  2579. }
  2580. case UISCROLL_VERTBT: {
  2581. prc->left = GetRectRef().left;
  2582. prc->top = GetRectRef().top + (rcBtnDn.bottom - rcBtnDn.top);
  2583. prc->right = GetRectRef().right;
  2584. prc->bottom = rcThumb.top;
  2585. break;
  2586. }
  2587. case UISCROLL_HORZLR: {
  2588. prc->left = rcThumb.right;
  2589. prc->top = GetRectRef().top;
  2590. prc->right = GetRectRef().right - (rcBtnDn.bottom - rcBtnDn.top);
  2591. prc->bottom = GetRectRef().bottom;;
  2592. break;
  2593. }
  2594. case UISCROLL_HORZRL: {
  2595. prc->left = GetRectRef().left + (rcBtnDn.bottom - rcBtnDn.top) ;
  2596. prc->top = GetRectRef().top;
  2597. prc->right = rcThumb.left;
  2598. prc->bottom = GetRectRef().bottom;;
  2599. break;
  2600. }
  2601. }
  2602. }
  2603. /* G E T S C R O L L T H U M B S T Y L E */
  2604. /*------------------------------------------------------------------------------
  2605. Get style of scroll thumb
  2606. ------------------------------------------------------------------------------*/
  2607. DWORD CUIFScroll::GetScrollThumbStyle( void )
  2608. {
  2609. return 0;
  2610. }
  2611. /* G E T S C R O L L U P B T N S T Y L E */
  2612. /*------------------------------------------------------------------------------
  2613. Get style of scroll up button
  2614. ------------------------------------------------------------------------------*/
  2615. DWORD CUIFScroll::GetScrollUpBtnStyle( void )
  2616. {
  2617. DWORD dwStyle = 0;
  2618. switch (m_dwStyle & UISCROLL_DIRMASK) {
  2619. default:
  2620. case UISCROLL_VERTTB: {
  2621. dwStyle = UISCROLLBUTTON_UP;
  2622. break;
  2623. }
  2624. case UISCROLL_VERTBT: {
  2625. dwStyle = UISCROLLBUTTON_DOWN;
  2626. break;
  2627. }
  2628. case UISCROLL_HORZLR: {
  2629. dwStyle = UISCROLLBUTTON_LEFT;
  2630. break;
  2631. }
  2632. case UISCROLL_HORZRL: {
  2633. dwStyle = UISCROLLBUTTON_RIGHT;
  2634. break;
  2635. }
  2636. }
  2637. return dwStyle;
  2638. }
  2639. /* G E T S C R O L L D N B T N S T Y L E */
  2640. /*------------------------------------------------------------------------------
  2641. Get style of scroll down button
  2642. ------------------------------------------------------------------------------*/
  2643. DWORD CUIFScroll::GetScrollDnBtnStyle( void )
  2644. {
  2645. DWORD dwStyle = 0;
  2646. switch (m_dwStyle & UISCROLL_DIRMASK) {
  2647. default:
  2648. case UISCROLL_VERTTB: {
  2649. dwStyle = UISCROLLBUTTON_DOWN;
  2650. break;
  2651. }
  2652. case UISCROLL_VERTBT: {
  2653. dwStyle = UISCROLLBUTTON_UP;
  2654. break;
  2655. }
  2656. case UISCROLL_HORZLR: {
  2657. dwStyle = UISCROLLBUTTON_RIGHT;
  2658. break;
  2659. }
  2660. case UISCROLL_HORZRL: {
  2661. dwStyle = UISCROLLBUTTON_LEFT;
  2662. break;
  2663. }
  2664. }
  2665. return dwStyle;
  2666. }
  2667. /* G E T M E T R I C S */
  2668. /*------------------------------------------------------------------------------
  2669. ------------------------------------------------------------------------------*/
  2670. void CUIFScroll::GetMetrics( void )
  2671. {
  2672. switch (m_dwStyle & UISCROLL_DIRMASK) {
  2673. default:
  2674. case UISCROLL_VERTTB:
  2675. case UISCROLL_VERTBT: {
  2676. m_sizeScrollBtn.cx = GetSystemMetrics( SM_CXVSCROLL );
  2677. m_sizeScrollBtn.cy = GetSystemMetrics( SM_CYVSCROLL );
  2678. break;
  2679. }
  2680. case UISCROLL_HORZLR:
  2681. case UISCROLL_HORZRL: {
  2682. m_sizeScrollBtn.cx = GetSystemMetrics( SM_CXHSCROLL );
  2683. m_sizeScrollBtn.cy = GetSystemMetrics( SM_CYHSCROLL );
  2684. break;
  2685. }
  2686. }
  2687. }
  2688. /*=============================================================================*/
  2689. /* */
  2690. /* C U I F L I S T B A S E */
  2691. /* */
  2692. /*=============================================================================*/
  2693. //
  2694. // CUIFListBase
  2695. //
  2696. /* C U I F L I S T B A S E */
  2697. /*------------------------------------------------------------------------------
  2698. Constructor of CUIFListBase
  2699. ------------------------------------------------------------------------------*/
  2700. CUIFListBase::CUIFListBase( CUIFObject *pParent, DWORD dwID, const RECT *prc, DWORD dwStyle ) : CUIFObject( pParent, dwID, prc, dwStyle )
  2701. {
  2702. m_nItem = 0;
  2703. m_nLineHeight = GetFontHeight();
  2704. m_nItemVisible = 0;
  2705. m_iItemTop = 0;
  2706. m_iItemSelect = 0;
  2707. }
  2708. /* ~ C U I F L I S T B A S E */
  2709. /*------------------------------------------------------------------------------
  2710. Destructor of CUIFListBase
  2711. ------------------------------------------------------------------------------*/
  2712. CUIFListBase::~CUIFListBase( void )
  2713. {
  2714. CListItemBase *pItem;
  2715. while ((pItem = m_listItem.GetFirst()) != NULL) {
  2716. m_listItem.Remove(pItem);
  2717. delete pItem;
  2718. m_nItem--;
  2719. }
  2720. Assert( m_nItem == 0 );
  2721. }
  2722. /* I N I T I A L I Z E */
  2723. /*------------------------------------------------------------------------------
  2724. Initialize list object
  2725. ------------------------------------------------------------------------------*/
  2726. CUIFObject *CUIFListBase::Initialize( void )
  2727. {
  2728. RECT rcScroll;
  2729. // create scrollbar
  2730. GetScrollBarRect( &rcScroll );
  2731. m_pUIScroll = CreateScrollBarObj( this, 0, &rcScroll, GetScrollBarStyle() );
  2732. m_pUIScroll->Initialize();
  2733. AddUIObj( m_pUIScroll );
  2734. // calc visible item count
  2735. CalcVisibleCount();
  2736. // initialize scrollbar
  2737. UpdateScrollBar();
  2738. //
  2739. return CUIFObject::Initialize();
  2740. }
  2741. /* O N P A I N T */
  2742. /*------------------------------------------------------------------------------
  2743. Paint procedure of list object
  2744. ------------------------------------------------------------------------------*/
  2745. void CUIFListBase::OnPaint( HDC hDC )
  2746. {
  2747. int iLine;
  2748. HFONT hFontOld = (HFONT)SelectObject( hDC, m_hFont );
  2749. for (iLine = 0; iLine < m_nItemVisible + 1; iLine++) {
  2750. CListItemBase *pItem;
  2751. int iItem = m_iItemTop + iLine;
  2752. RECT rc;
  2753. pItem = GetItem( iItem );
  2754. if (pItem != NULL) {
  2755. GetLineRect( iLine, &rc );
  2756. if (!IsRectEmpty( &rc )) {
  2757. PaintItemProc( hDC, &rc, pItem, (iItem == m_iItemSelect) );
  2758. }
  2759. }
  2760. }
  2761. SelectObject( hDC, hFontOld );
  2762. }
  2763. /* O N L B U T T O N D O W N */
  2764. /*------------------------------------------------------------------------------
  2765. ------------------------------------------------------------------------------*/
  2766. void CUIFListBase::OnLButtonDown( POINT pt )
  2767. {
  2768. int iItemSelNew = ListItemFromPoint( pt );
  2769. if (iItemSelNew != -1) {
  2770. SetSelection( iItemSelNew, TRUE );
  2771. }
  2772. StartCapture();
  2773. StartTimer( 100 ); // TEMP
  2774. }
  2775. /* O N L B U T T O N U P */
  2776. /*------------------------------------------------------------------------------
  2777. ------------------------------------------------------------------------------*/
  2778. void CUIFListBase::OnLButtonUp( POINT pt )
  2779. {
  2780. BOOL fSelected = FALSE;
  2781. if (IsCapture()) {
  2782. int iItemSelNew = ListItemFromPoint( pt );
  2783. if (iItemSelNew != -1) {
  2784. SetSelection( iItemSelNew, TRUE );
  2785. }
  2786. EndCapture();
  2787. fSelected = (PtInObject( pt ) && iItemSelNew != -1);
  2788. }
  2789. if (IsTimer()) {
  2790. EndTimer();
  2791. }
  2792. // notify
  2793. if (fSelected) {
  2794. NotifyCommand( UILIST_SELECTED, m_iItemSelect );
  2795. }
  2796. }
  2797. /* O N M O U S E M O V E */
  2798. /*------------------------------------------------------------------------------
  2799. ------------------------------------------------------------------------------*/
  2800. void CUIFListBase::OnMouseMove( POINT pt )
  2801. {
  2802. if (IsCapture()) {
  2803. int iItemSelNew = ListItemFromPoint( pt );
  2804. if (iItemSelNew != -1) {
  2805. SetSelection( iItemSelNew, TRUE );
  2806. }
  2807. }
  2808. }
  2809. /* O N T I M E R */
  2810. /*------------------------------------------------------------------------------
  2811. ------------------------------------------------------------------------------*/
  2812. void CUIFListBase::OnTimer( void )
  2813. {
  2814. POINT pt;
  2815. if (!IsCapture()) {
  2816. return;
  2817. }
  2818. GetCursorPos( &pt );
  2819. ScreenToClient( m_pUIWnd->GetWnd(), &pt );
  2820. if (!PtInObject( pt )) {
  2821. switch (m_dwStyle & UILIST_DIRMASK) {
  2822. default:
  2823. case UILIST_HORZTB: {
  2824. if (pt.y < GetRectRef().top) {
  2825. // scroll up
  2826. SetSelection( m_iItemSelect - 1, TRUE );
  2827. }
  2828. else if (GetRectRef().bottom <= pt.y) {
  2829. // scroll down
  2830. SetSelection( m_iItemSelect + 1, TRUE );
  2831. }
  2832. break;
  2833. }
  2834. case UILIST_HORZBT: {
  2835. if (pt.y < GetRectRef().top) {
  2836. // scroll down
  2837. SetSelection( m_iItemSelect + 1, TRUE );
  2838. }
  2839. else if (GetRectRef().bottom <= pt.y) {
  2840. // scroll up
  2841. SetSelection( m_iItemSelect - 1, TRUE );
  2842. }
  2843. break;
  2844. }
  2845. case UILIST_VERTLR: {
  2846. if (GetRectRef().right <= pt.x) {
  2847. // scroll down
  2848. SetSelection( m_iItemSelect + 1, TRUE );
  2849. }
  2850. else if (pt.x < GetRectRef().left) {
  2851. // scroll up
  2852. SetSelection( m_iItemSelect - 1, TRUE );
  2853. }
  2854. break;
  2855. }
  2856. case UILIST_VERTRL: {
  2857. if (GetRectRef().right <= pt.x) {
  2858. // scroll up
  2859. SetSelection( m_iItemSelect - 1, TRUE );
  2860. }
  2861. else if (pt.x < GetRectRef().left) {
  2862. // scroll down
  2863. SetSelection( m_iItemSelect + 1, TRUE );
  2864. }
  2865. break;
  2866. }
  2867. }
  2868. }
  2869. }
  2870. /* S E T R E C T */
  2871. /*------------------------------------------------------------------------------
  2872. ------------------------------------------------------------------------------*/
  2873. void CUIFListBase::SetRect( const RECT *prc )
  2874. {
  2875. RECT rcScroll;
  2876. CUIFObject::SetRect( prc );
  2877. // set scrollbar position
  2878. GetScrollBarRect( &rcScroll );
  2879. m_pUIScroll->SetRect( &rcScroll );
  2880. // calc visible item count
  2881. CalcVisibleCount();
  2882. // update scrollbar
  2883. UpdateScrollBar();
  2884. }
  2885. /* S E T S T Y L E */
  2886. /*------------------------------------------------------------------------------
  2887. ------------------------------------------------------------------------------*/
  2888. void CUIFListBase::SetStyle( DWORD dwStyle )
  2889. {
  2890. RECT rcScroll;
  2891. CUIFObject::SetStyle( dwStyle );
  2892. // change scroll bar style either
  2893. m_pUIScroll->SetStyle( GetScrollBarStyle() );
  2894. // set scrollbar position
  2895. GetScrollBarRect( &rcScroll );
  2896. m_pUIScroll->SetRect( &rcScroll );
  2897. // calc visible item count
  2898. CalcVisibleCount();
  2899. // update scrollbar
  2900. UpdateScrollBar();
  2901. }
  2902. /* O N O B J E C T N O T I F Y */
  2903. /*------------------------------------------------------------------------------
  2904. ------------------------------------------------------------------------------*/
  2905. LRESULT CUIFListBase::OnObjectNotify( CUIFObject *pUIObj, DWORD dwCommand, LPARAM lParam )
  2906. {
  2907. LRESULT lResult = 0;
  2908. if (pUIObj == m_pUIScroll) {
  2909. switch (dwCommand) {
  2910. case UISCROLLNOTIFY_SCROLLED: {
  2911. int nCur = (int)lParam;
  2912. int iItemTop;
  2913. if ((m_dwStyle & UILIST_VARIABLEHEIGHT) == 0) {
  2914. // fixed height
  2915. iItemTop = nCur;
  2916. }
  2917. else {
  2918. int nItemPos = 0;
  2919. int nItemHeight;
  2920. // variable height
  2921. for (iItemTop = 0; iItemTop < m_nItem; iItemTop++) {
  2922. nItemHeight = GetItemHeight( iItemTop );
  2923. if (nCur < nItemPos + nItemHeight/2) {
  2924. break;
  2925. }
  2926. nItemPos += nItemHeight;
  2927. }
  2928. }
  2929. SetTop( iItemTop, FALSE );
  2930. break;
  2931. }
  2932. case UISCROLLNOTIFY_SCROLLLN: {
  2933. SetTop((int)(GetTop() + lParam), TRUE );
  2934. lResult = 1; /* processed */
  2935. break;
  2936. }
  2937. }
  2938. }
  2939. return lResult;
  2940. }
  2941. /* A D D I T E M */
  2942. /*------------------------------------------------------------------------------
  2943. ------------------------------------------------------------------------------*/
  2944. int CUIFListBase::AddItem( CListItemBase *pItem )
  2945. {
  2946. int iItem = m_nItem;
  2947. // add to list
  2948. //
  2949. // -1 is error code for CUIFList::AddString()
  2950. //
  2951. if (!m_listItem.Add( pItem ))
  2952. return -1;
  2953. m_nItem++;
  2954. // calc visible item count
  2955. if ((m_dwStyle & UILIST_VARIABLEHEIGHT) != 0) {
  2956. CalcVisibleCount();
  2957. }
  2958. // update scrollbar
  2959. UpdateScrollBar();
  2960. // update window
  2961. CallOnPaint();
  2962. return iItem;
  2963. }
  2964. /* G E T C O U N T */
  2965. /*------------------------------------------------------------------------------
  2966. ------------------------------------------------------------------------------*/
  2967. int CUIFListBase::GetCount( void )
  2968. {
  2969. return m_nItem;
  2970. }
  2971. /* G E T I T E M */
  2972. /*------------------------------------------------------------------------------
  2973. ------------------------------------------------------------------------------*/
  2974. CListItemBase *CUIFListBase::GetItem( int iItem )
  2975. {
  2976. if (0 <= iItem && iItem < m_nItem) {
  2977. return m_listItem.Get( iItem );
  2978. }
  2979. return NULL;
  2980. }
  2981. /* D E L I T E M */
  2982. /*------------------------------------------------------------------------------
  2983. ------------------------------------------------------------------------------*/
  2984. void CUIFListBase::DelItem( int iItem )
  2985. {
  2986. CListItemBase *pItem;
  2987. pItem = GetItem( iItem );
  2988. if (pItem != NULL) {
  2989. // delete item
  2990. m_listItem.Remove(pItem);
  2991. delete pItem;
  2992. m_nItem--;
  2993. // calc visible item count
  2994. if ((m_dwStyle & UILIST_VARIABLEHEIGHT) != 0) {
  2995. CalcVisibleCount();
  2996. }
  2997. // update scrollbar
  2998. UpdateScrollBar();
  2999. // update window
  3000. CallOnPaint();
  3001. }
  3002. }
  3003. /* D E L A L L I T E M */
  3004. /*------------------------------------------------------------------------------
  3005. ------------------------------------------------------------------------------*/
  3006. void CUIFListBase::DelAllItem( void )
  3007. {
  3008. CListItemBase *pItem;
  3009. while ((pItem = m_listItem.GetFirst()) != NULL) {
  3010. m_listItem.Remove(pItem);
  3011. delete pItem;
  3012. m_nItem--;
  3013. }
  3014. Assert( m_nItem == 0 );
  3015. m_iItemTop = 0;
  3016. m_iItemSelect = 0;
  3017. // calc visible item count
  3018. if ((m_dwStyle & UILIST_VARIABLEHEIGHT) != 0) {
  3019. CalcVisibleCount();
  3020. }
  3021. // update scrollbar
  3022. UpdateScrollBar();
  3023. // update window
  3024. CallOnPaint();
  3025. }
  3026. /* S E T S E L E C T I O N */
  3027. /*------------------------------------------------------------------------------
  3028. ------------------------------------------------------------------------------*/
  3029. void CUIFListBase::SetSelection( int iSelection, BOOL fRedraw )
  3030. {
  3031. BOOL fNotify;
  3032. if (iSelection < -1 || m_nItem <= iSelection) {
  3033. return;
  3034. }
  3035. fNotify = (iSelection != m_iItemSelect) && iSelection != -1 && m_iItemSelect != -1;
  3036. m_iItemSelect = iSelection;
  3037. // make the selection visible always
  3038. int iItemTop = GetTop();
  3039. int iItemBottom = GetBottom();
  3040. if (m_iItemSelect < iItemTop) {
  3041. SetTop( m_iItemSelect, TRUE );
  3042. }
  3043. else if (iItemBottom < m_iItemSelect) {
  3044. if ((m_dwStyle & UILIST_VARIABLEHEIGHT) == 0) {
  3045. // fixed height
  3046. SetTop( m_iItemSelect - m_nItemVisible + 1, TRUE );
  3047. }
  3048. else {
  3049. int nHeight = GetListHeight();
  3050. int nItemShift;
  3051. int ptBottom;
  3052. int i;
  3053. // variable height
  3054. ptBottom = 0;
  3055. for (i = iItemTop; i <= m_iItemSelect; i++) {
  3056. ptBottom += GetItemHeight( i );
  3057. }
  3058. // find number of items to shift
  3059. nItemShift = 0;
  3060. while (nHeight < ptBottom && (iItemTop + nItemShift) < m_iItemSelect) {
  3061. ptBottom -= GetItemHeight( iItemTop + nItemShift );
  3062. nItemShift++;
  3063. }
  3064. // set new top
  3065. SetTop( iItemTop + nItemShift, TRUE );
  3066. }
  3067. }
  3068. if (fRedraw) {
  3069. CallOnPaint();
  3070. }
  3071. if (fNotify) {
  3072. NotifyCommand( UILIST_SELCHANGED, m_iItemSelect );
  3073. }
  3074. }
  3075. /* C L E A R S E L E C T I O N */
  3076. /*------------------------------------------------------------------------------
  3077. ------------------------------------------------------------------------------*/
  3078. void CUIFListBase::ClearSelection( BOOL fRedraw )
  3079. {
  3080. if (m_iItemSelect != -1) {
  3081. m_iItemSelect = -1;
  3082. if (fRedraw) {
  3083. CallOnPaint();
  3084. }
  3085. NotifyCommand( UILIST_SELCHANGED, m_iItemSelect );
  3086. }
  3087. }
  3088. /* S E T L I N E H E I G H T */
  3089. /*------------------------------------------------------------------------------
  3090. ------------------------------------------------------------------------------*/
  3091. void CUIFListBase::SetLineHeight( int nLineHeight )
  3092. {
  3093. m_nLineHeight = nLineHeight;
  3094. // calc visible item count
  3095. CalcVisibleCount();
  3096. // update scrollbar
  3097. UpdateScrollBar();
  3098. // update window
  3099. CallOnPaint();
  3100. }
  3101. /* S E T T O P */
  3102. /*------------------------------------------------------------------------------
  3103. ------------------------------------------------------------------------------*/
  3104. void CUIFListBase::SetTop( int nTop, BOOL fSetScrollPos )
  3105. {
  3106. nTop = min( nTop, m_nItem );
  3107. nTop = max( nTop, 0 );
  3108. if (m_iItemTop != nTop) {
  3109. m_iItemTop = nTop;
  3110. // calc visible count
  3111. if ((m_dwStyle & UILIST_VARIABLEHEIGHT) != 0) {
  3112. CalcVisibleCount();
  3113. }
  3114. CallOnPaint();
  3115. if (fSetScrollPos) {
  3116. // update scrollbar
  3117. UpdateScrollBar();
  3118. }
  3119. }
  3120. }
  3121. /* G E T S E L E C T I O N */
  3122. /*------------------------------------------------------------------------------
  3123. ------------------------------------------------------------------------------*/
  3124. int CUIFListBase::GetSelection( void )
  3125. {
  3126. return m_iItemSelect;
  3127. }
  3128. /* G E T L I N E H E I G H T */
  3129. /*------------------------------------------------------------------------------
  3130. ------------------------------------------------------------------------------*/
  3131. int CUIFListBase::GetLineHeight( void )
  3132. {
  3133. return m_nLineHeight;
  3134. }
  3135. /* G E T T O P */
  3136. /*------------------------------------------------------------------------------
  3137. ------------------------------------------------------------------------------*/
  3138. int CUIFListBase::GetTop( void )
  3139. {
  3140. return m_iItemTop;
  3141. }
  3142. /* G E T B O T T O M */
  3143. /*------------------------------------------------------------------------------
  3144. ------------------------------------------------------------------------------*/
  3145. int CUIFListBase::GetBottom( void )
  3146. {
  3147. return m_iItemTop + m_nItemVisible - 1;
  3148. }
  3149. /* G E T V I S I B L E C O U N T */
  3150. /*------------------------------------------------------------------------------
  3151. ------------------------------------------------------------------------------*/
  3152. int CUIFListBase::GetVisibleCount( void )
  3153. {
  3154. return m_nItemVisible;
  3155. }
  3156. /* G E T I T E M H E I G H T */
  3157. /*------------------------------------------------------------------------------
  3158. (only called in UILIST_VARIABLEHEIGHT)
  3159. ------------------------------------------------------------------------------*/
  3160. int CUIFListBase::GetItemHeight( int iItem )
  3161. {
  3162. return m_nLineHeight;
  3163. }
  3164. /* G E T L I S T H E I G H T */
  3165. /*------------------------------------------------------------------------------
  3166. ------------------------------------------------------------------------------*/
  3167. int CUIFListBase::GetListHeight( void )
  3168. {
  3169. int nHeight;
  3170. switch (m_dwStyle & UILIST_DIRMASK) {
  3171. default:
  3172. case UILIST_HORZTB:
  3173. case UILIST_HORZBT: {
  3174. nHeight = GetRectRef().bottom - GetRectRef().top;
  3175. break;
  3176. }
  3177. case UILIST_VERTLR:
  3178. case UILIST_VERTRL: {
  3179. nHeight = GetRectRef().right - GetRectRef().left;
  3180. break;
  3181. }
  3182. }
  3183. return nHeight;
  3184. }
  3185. /* G E T L I N E R E C T */
  3186. /*------------------------------------------------------------------------------
  3187. ------------------------------------------------------------------------------*/
  3188. void CUIFListBase::GetLineRect( int iLine, RECT *prc )
  3189. {
  3190. int pxyItem = 0;
  3191. int cxyItem = 0;
  3192. if ((m_dwStyle & UILIST_VARIABLEHEIGHT) == 0) {
  3193. // fixed height
  3194. cxyItem = GetLineHeight();
  3195. pxyItem = iLine * cxyItem;
  3196. }
  3197. else {
  3198. int i;
  3199. // variable height
  3200. for (i = 0; i <= iLine; i++) {
  3201. pxyItem += cxyItem;
  3202. cxyItem = GetItemHeight( m_iItemTop + i );
  3203. }
  3204. }
  3205. switch (m_dwStyle & UILIST_DIRMASK) {
  3206. default:
  3207. case UILIST_HORZTB: {
  3208. prc->left = GetRectRef().left;
  3209. prc->top = GetRectRef().top + pxyItem;
  3210. prc->right = GetRectRef().right;
  3211. prc->bottom = GetRectRef().top + (pxyItem + cxyItem);
  3212. break;
  3213. }
  3214. case UILIST_HORZBT: {
  3215. prc->left = GetRectRef().left;
  3216. prc->top = GetRectRef().bottom - (pxyItem + cxyItem);
  3217. prc->right = GetRectRef().right;
  3218. prc->bottom = GetRectRef().bottom - pxyItem;
  3219. break;
  3220. }
  3221. case UILIST_VERTLR: {
  3222. prc->left = GetRectRef().left + pxyItem;
  3223. prc->top = GetRectRef().top;
  3224. prc->right = GetRectRef().left + (pxyItem + cxyItem);
  3225. prc->bottom = GetRectRef().bottom;
  3226. break;
  3227. }
  3228. case UILIST_VERTRL: {
  3229. prc->left = GetRectRef().right - (pxyItem + cxyItem);
  3230. prc->top = GetRectRef().top;
  3231. prc->right = GetRectRef().right - pxyItem;
  3232. prc->bottom = GetRectRef().bottom;
  3233. break;
  3234. }
  3235. }
  3236. // exclude scrollbar
  3237. if (m_pUIScroll != NULL && m_pUIScroll->IsVisible()) {
  3238. RECT rcScroll;
  3239. m_pUIScroll->GetRect( &rcScroll );
  3240. switch (m_dwStyle & UILIST_DIRMASK) {
  3241. default:
  3242. case UILIST_HORZTB:
  3243. case UILIST_HORZBT: {
  3244. prc->right = min( prc->right, rcScroll.left );
  3245. break;
  3246. }
  3247. case UILIST_VERTLR:
  3248. case UILIST_VERTRL: {
  3249. prc->bottom = max( prc->bottom, rcScroll.top );
  3250. break;
  3251. }
  3252. }
  3253. }
  3254. // clip
  3255. IntersectRect( prc, prc, &GetRectRef() );
  3256. }
  3257. /* G E T S C R O L L B A R R E C T */
  3258. /*------------------------------------------------------------------------------
  3259. Get scrollbar position
  3260. ------------------------------------------------------------------------------*/
  3261. void CUIFListBase::GetScrollBarRect( RECT *prc )
  3262. {
  3263. Assert( prc != NULL );
  3264. switch (m_dwStyle & UILIST_DIRMASK) {
  3265. default:
  3266. case UILIST_HORZTB:
  3267. case UILIST_HORZBT: {
  3268. prc->left = GetRectRef().right - GetSystemMetrics(SM_CXVSCROLL);
  3269. prc->top = GetRectRef().top;
  3270. prc->right = GetRectRef().right;
  3271. prc->bottom = GetRectRef().bottom;
  3272. break;
  3273. }
  3274. case UILIST_VERTLR:
  3275. case UILIST_VERTRL: {
  3276. prc->left = GetRectRef().left;
  3277. prc->top = GetRectRef().bottom - GetSystemMetrics(SM_CYHSCROLL);
  3278. prc->right = GetRectRef().right;
  3279. prc->bottom = GetRectRef().bottom;
  3280. break;
  3281. }
  3282. }
  3283. }
  3284. /* G E T S C R O L L B A R S T Y L E */
  3285. /*------------------------------------------------------------------------------
  3286. Get scrollbar style
  3287. ------------------------------------------------------------------------------*/
  3288. DWORD CUIFListBase::GetScrollBarStyle( void )
  3289. {
  3290. DWORD dwScrollStyle;
  3291. switch (m_dwStyle & UILIST_DIRMASK) {
  3292. default:
  3293. case UILIST_HORZTB: {
  3294. dwScrollStyle = UISCROLL_VERTTB;
  3295. break;
  3296. }
  3297. case UILIST_HORZBT: {
  3298. dwScrollStyle = UISCROLL_VERTBT;
  3299. break;
  3300. }
  3301. case UILIST_VERTLR: {
  3302. dwScrollStyle = UISCROLL_HORZLR;
  3303. break;
  3304. }
  3305. case UILIST_VERTRL: {
  3306. dwScrollStyle = UISCROLL_HORZRL;
  3307. break;
  3308. }
  3309. }
  3310. return dwScrollStyle;
  3311. }
  3312. /* C R E A T E S C R O L L B A R O B J */
  3313. /*------------------------------------------------------------------------------
  3314. ------------------------------------------------------------------------------*/
  3315. CUIFScroll *CUIFListBase::CreateScrollBarObj( CUIFObject *pParent, DWORD dwID, RECT *prc, DWORD dwStyle )
  3316. {
  3317. return new CUIFScroll( pParent, dwID, prc, dwStyle );
  3318. }
  3319. /* P A I N T I T E M P R O C */
  3320. /*------------------------------------------------------------------------------
  3321. ------------------------------------------------------------------------------*/
  3322. void CUIFListBase::PaintItemProc( HDC hDC, RECT *prc, CListItemBase *pItem, BOOL fSelected )
  3323. {
  3324. COLORREF colText;
  3325. COLORREF colBack;
  3326. Assert( pItem != NULL );
  3327. // set color
  3328. if (fSelected) {
  3329. colText = GetSysColor(COLOR_HIGHLIGHTTEXT);
  3330. colBack = GetSysColor(COLOR_HIGHLIGHT);
  3331. }
  3332. else {
  3333. colText = GetSysColor(COLOR_WINDOWTEXT);
  3334. colBack = GetSysColor(COLOR_3DFACE);
  3335. }
  3336. SetTextColor( hDC, colText );
  3337. SetBkColor( hDC, colBack );
  3338. //
  3339. CUIExtTextOut( hDC, prc->left, prc->top, ETO_OPAQUE | ETO_CLIPPED, prc, L"", 0, NULL );
  3340. }
  3341. /* L I S T I T E M F R O M P O I N T */
  3342. /*------------------------------------------------------------------------------
  3343. ------------------------------------------------------------------------------*/
  3344. int CUIFListBase::ListItemFromPoint( POINT pt )
  3345. {
  3346. if (PtInObject( pt )) {
  3347. int iLine;
  3348. RECT rc;
  3349. for (iLine = 0; iLine < m_nItemVisible + 1; iLine++) {
  3350. if (m_nItem <= m_iItemTop + iLine) {
  3351. break;
  3352. }
  3353. GetLineRect( iLine, &rc );
  3354. if (PtInRect( &rc, pt )) {
  3355. return iLine + m_iItemTop;
  3356. }
  3357. }
  3358. }
  3359. return (-1);
  3360. }
  3361. /* C A L C V I S I B L E C O U N T */
  3362. /*------------------------------------------------------------------------------
  3363. Calculate number of visible item
  3364. ------------------------------------------------------------------------------*/
  3365. void CUIFListBase::CalcVisibleCount( void )
  3366. {
  3367. int nHeight = GetListHeight();
  3368. if ((m_dwStyle & UILIST_VARIABLEHEIGHT) == 0) {
  3369. // fixed height
  3370. if (m_nLineHeight <= 0) {
  3371. m_nItemVisible = 0;
  3372. }
  3373. else {
  3374. m_nItemVisible = nHeight / m_nLineHeight;
  3375. }
  3376. }
  3377. else {
  3378. // variable height
  3379. if (0 < m_nItem) {
  3380. int i = m_iItemTop;
  3381. // count visible item
  3382. m_nItemVisible = 0;
  3383. while (0 < nHeight && i < m_nItem) {
  3384. nHeight -= GetItemHeight( i );
  3385. m_nItemVisible++;
  3386. i++;
  3387. }
  3388. // adjustment
  3389. if (0 < nHeight && m_nItemVisible == 0) {
  3390. // at least, one item is visible
  3391. m_nItemVisible = 1;
  3392. }
  3393. else if (nHeight < 0 && 1 < m_nItemVisible) {
  3394. // exclude last item if clipped
  3395. m_nItemVisible--;
  3396. }
  3397. }
  3398. else {
  3399. m_nItemVisible = 0;
  3400. }
  3401. }
  3402. }
  3403. /* U P D A T E S C R O L L B A R */
  3404. /*------------------------------------------------------------------------------
  3405. Update scrollbar range and visible status
  3406. ------------------------------------------------------------------------------*/
  3407. void CUIFListBase::UpdateScrollBar( void )
  3408. {
  3409. UIFSCROLLINFO ScrollInfo;
  3410. Assert( m_pUIScroll != NULL );
  3411. // set scroll range/current pos
  3412. if ((m_dwStyle & UILIST_VARIABLEHEIGHT) == 0) {
  3413. // fixed height
  3414. ScrollInfo.nMax = m_nItem;
  3415. ScrollInfo.nPage = m_nItemVisible;
  3416. ScrollInfo.nPos = m_iItemTop;
  3417. }
  3418. else {
  3419. int nTotal = 0;
  3420. int nTop = 0;
  3421. int nVisible = 0;
  3422. int i;
  3423. // variable height
  3424. nVisible = GetListHeight();
  3425. for (i = 0; i < m_nItem; i++) {
  3426. int nItemHeight = GetItemHeight( i );
  3427. if (i < m_iItemTop) {
  3428. nTop += nItemHeight;
  3429. }
  3430. nTotal += nItemHeight;
  3431. }
  3432. // adjust gap at the end of list
  3433. if (nVisible < nTotal) {
  3434. int nLastPage = 0;
  3435. for (i = m_nItem-1; 0 <= i; i--) {
  3436. int nItemHeight = GetItemHeight( i );
  3437. if (nVisible < nLastPage + nItemHeight) {
  3438. break;
  3439. }
  3440. nLastPage += nItemHeight;
  3441. }
  3442. if (0 < nLastPage && nLastPage < nVisible) {
  3443. nTotal += (nVisible - nLastPage);
  3444. }
  3445. }
  3446. ScrollInfo.nMax = nTotal;
  3447. ScrollInfo.nPage = nVisible;
  3448. ScrollInfo.nPos = nTop;
  3449. }
  3450. m_pUIScroll->SetScrollInfo( &ScrollInfo );
  3451. // show/hide scroll bar
  3452. if ((m_dwStyle & UILIST_DISABLENOSCROLL) == 0) {
  3453. m_pUIScroll->Show( ScrollInfo.nPage < ScrollInfo.nMax );
  3454. }
  3455. }
  3456. /*=============================================================================*/
  3457. /* */
  3458. /* C U I F L I S T */
  3459. /* */
  3460. /*=============================================================================*/
  3461. //
  3462. // CListItem
  3463. //
  3464. class CListItem : public CListItemBase
  3465. {
  3466. public:
  3467. CListItem( WCHAR *psz, int nId )
  3468. {
  3469. m_pwch = NULL;
  3470. m_nId = nId;
  3471. m_dwData = 0;
  3472. if (psz != NULL) {
  3473. m_pwch = new WCHAR[ StrLenW(psz) + 1 ];
  3474. if (m_pwch != NULL) {
  3475. StrCpyW( m_pwch, psz );
  3476. }
  3477. }
  3478. }
  3479. virtual ~CListItem( void )
  3480. {
  3481. if (m_pwch != NULL) {
  3482. delete m_pwch;
  3483. }
  3484. }
  3485. __inline LPCWSTR GetString( void )
  3486. {
  3487. return m_pwch;
  3488. }
  3489. __inline int GetID( void )
  3490. {
  3491. return m_nId;
  3492. }
  3493. __inline void SetData( DWORD dwData )
  3494. {
  3495. m_dwData = dwData;
  3496. }
  3497. __inline DWORD GetData( void )
  3498. {
  3499. return m_dwData;
  3500. }
  3501. protected:
  3502. WCHAR *m_pwch;
  3503. int m_nId;
  3504. DWORD m_dwData;
  3505. };
  3506. //
  3507. // CUIFList
  3508. //
  3509. /* C U I F L I S T */
  3510. /*------------------------------------------------------------------------------
  3511. Constructor of CUIFList
  3512. ------------------------------------------------------------------------------*/
  3513. CUIFList::CUIFList( CUIFObject *pParent, DWORD dwID, const RECT *prc, DWORD dwStyle ) : CUIFListBase( pParent, dwID, prc, dwStyle )
  3514. {
  3515. }
  3516. /* ~ C U I F L I S T */
  3517. /*------------------------------------------------------------------------------
  3518. Destructor of CUIFList
  3519. ------------------------------------------------------------------------------*/
  3520. CUIFList::~CUIFList( void )
  3521. {
  3522. }
  3523. /* A D D S T R I N G */
  3524. /*------------------------------------------------------------------------------
  3525. ------------------------------------------------------------------------------*/
  3526. int CUIFList::AddString( WCHAR *psz )
  3527. {
  3528. CListItem *pItem = new CListItem( psz, GetCount() );
  3529. if (!pItem)
  3530. {
  3531. //
  3532. // is it ok to return -1?
  3533. //
  3534. return -1;
  3535. }
  3536. return AddItem( pItem );
  3537. }
  3538. /* G E T S T R I N G */
  3539. /*------------------------------------------------------------------------------
  3540. ------------------------------------------------------------------------------*/
  3541. LPCWSTR CUIFList::GetString( int nID )
  3542. {
  3543. int iItem = ItemFromID( nID );
  3544. CListItem *pItem;
  3545. pItem = (CListItem *)GetItem( iItem );
  3546. if (pItem != NULL) {
  3547. return pItem->GetString();
  3548. }
  3549. return NULL;
  3550. }
  3551. /* D E L E T E S T R I N G */
  3552. /*------------------------------------------------------------------------------
  3553. ------------------------------------------------------------------------------*/
  3554. void CUIFList::DeleteString( int nID )
  3555. {
  3556. int iItem = ItemFromID( nID );
  3557. if (iItem != -1) {
  3558. DelItem( iItem );
  3559. }
  3560. }
  3561. /* D E L E T E A L L S T R I N G */
  3562. /*------------------------------------------------------------------------------
  3563. ------------------------------------------------------------------------------*/
  3564. void CUIFList::DeleteAllString( void )
  3565. {
  3566. DelAllItem();
  3567. }
  3568. /* S E T P R I V A T E D A T A */
  3569. /*------------------------------------------------------------------------------
  3570. ------------------------------------------------------------------------------*/
  3571. void CUIFList::SetPrivateData( int nID, DWORD dw )
  3572. {
  3573. int iItem = ItemFromID( nID );
  3574. CListItem *pItem;
  3575. pItem = (CListItem *)GetItem( iItem );
  3576. if (pItem != NULL) {
  3577. pItem->SetData( dw );
  3578. }
  3579. }
  3580. /* G E T P R I V A T E D A T A */
  3581. /*------------------------------------------------------------------------------
  3582. ------------------------------------------------------------------------------*/
  3583. DWORD CUIFList::GetPrivateData( int nID )
  3584. {
  3585. int iItem = ItemFromID( nID );
  3586. CListItem *pItem;
  3587. pItem = (CListItem *)GetItem( iItem );
  3588. if (pItem != NULL) {
  3589. return pItem->GetData();
  3590. }
  3591. return 0;
  3592. }
  3593. /* I T E M F R O M I D */
  3594. /*------------------------------------------------------------------------------
  3595. ------------------------------------------------------------------------------*/
  3596. int CUIFList::ItemFromID( int iID )
  3597. {
  3598. int nItem;
  3599. int i;
  3600. nItem = GetCount();
  3601. for (i = 0; i < nItem; i++) {
  3602. CListItem *pItem = (CListItem *)GetItem( i );
  3603. if (iID == pItem->GetID()) {
  3604. return i;
  3605. }
  3606. }
  3607. return -1;
  3608. }
  3609. /* P A I N T I T E M P R O C */
  3610. /*------------------------------------------------------------------------------
  3611. ------------------------------------------------------------------------------*/
  3612. void CUIFList::PaintItemProc( HDC hDC, RECT *prc, CListItemBase *pItem, BOOL fSelected )
  3613. {
  3614. CListItem *pListItem = (CListItem *)pItem;
  3615. COLORREF colText;
  3616. COLORREF colBack;
  3617. LPCWSTR pwch;
  3618. SIZE size;
  3619. POINT ptOrg;
  3620. Assert( pListItem != NULL );
  3621. pwch = pListItem->GetString();
  3622. if (pwch == NULL) {
  3623. return;
  3624. }
  3625. // set color
  3626. if (fSelected) {
  3627. colText = GetSysColor(COLOR_HIGHLIGHTTEXT);
  3628. colBack = GetSysColor(COLOR_HIGHLIGHT);
  3629. }
  3630. else {
  3631. colText = GetSysColor(COLOR_WINDOWTEXT);
  3632. colBack = GetSysColor(COLOR_3DFACE);
  3633. }
  3634. SetTextColor( hDC, colText );
  3635. SetBkColor( hDC, colBack );
  3636. // calc origin
  3637. GetTextExtentPointW( hDC, pwch, StrLenW(pwch), &size );
  3638. switch (m_dwStyle & UILIST_DIRMASK) {
  3639. default:
  3640. case UILIST_HORZTB: {
  3641. ptOrg.x = prc->left;
  3642. ptOrg.y = (prc->bottom + prc->top - size.cy) / 2;
  3643. break;
  3644. }
  3645. case UILIST_HORZBT: {
  3646. ptOrg.x = prc->right;
  3647. ptOrg.y = (prc->bottom + prc->top + size.cy) / 2;
  3648. break;
  3649. }
  3650. case UILIST_VERTLR: {
  3651. ptOrg.x = (prc->right + prc->left - size.cy) / 2;
  3652. ptOrg.y = prc->bottom;
  3653. break;
  3654. }
  3655. case UILIST_VERTRL: {
  3656. ptOrg.x = (prc->right + prc->left + size.cy) / 2;
  3657. ptOrg.y = prc->top;
  3658. break;
  3659. }
  3660. }
  3661. CUIExtTextOut( hDC, ptOrg.x, ptOrg.y, ETO_OPAQUE | ETO_CLIPPED, prc, pwch, StrLenW(pwch), NULL );
  3662. }
  3663. /*=============================================================================*/
  3664. /* */
  3665. /* C U I F G R I P P E R */
  3666. /* */
  3667. /*=============================================================================*/
  3668. /* C U I F G R I P P E R */
  3669. /*------------------------------------------------------------------------------
  3670. Constructor of CUIFGripper
  3671. ------------------------------------------------------------------------------*/
  3672. CUIFGripper::CUIFGripper( CUIFObject *pParent, const RECT *prc, DWORD dwStyle ) : CUIFObject( pParent, 0, prc, dwStyle )
  3673. {
  3674. if (IsVertical())
  3675. SetActiveTheme(L"REBAR", RP_GRIPPERVERT);
  3676. else
  3677. SetActiveTheme(L"REBAR", RP_GRIPPER);
  3678. }
  3679. /* ~ C U I F G R I P P E R */
  3680. /*------------------------------------------------------------------------------
  3681. Destructor of CUIFGripper
  3682. ------------------------------------------------------------------------------*/
  3683. CUIFGripper::~CUIFGripper( void )
  3684. {
  3685. }
  3686. /* O N P A I N T T H E M E */
  3687. /*------------------------------------------------------------------------------
  3688. Paint procedure of gripper object
  3689. ------------------------------------------------------------------------------*/
  3690. void CUIFGripper::SetStyle( DWORD dwStyle )
  3691. {
  3692. CUIFObject::SetStyle(dwStyle);
  3693. if (IsVertical())
  3694. SetActiveTheme(L"REBAR", RP_GRIPPERVERT);
  3695. else
  3696. SetActiveTheme(L"REBAR", RP_GRIPPER);
  3697. }
  3698. /* O N P A I N T T H E M E */
  3699. /*------------------------------------------------------------------------------
  3700. Paint procedure of gripper object
  3701. ------------------------------------------------------------------------------*/
  3702. BOOL CUIFGripper::OnPaintTheme( HDC hDC )
  3703. {
  3704. BOOL fRet = FALSE;
  3705. int iStateID;
  3706. RECT rc;
  3707. iStateID = TS_NORMAL;
  3708. if (FAILED(EnsureThemeData( GetUIWnd()->GetWnd())))
  3709. goto Exit;
  3710. rc = GetRectRef();
  3711. if (!IsVertical())
  3712. {
  3713. rc.left += CUI_GRIPPER_THEME_MARGIN;
  3714. rc.right -= CUI_GRIPPER_THEME_MARGIN;
  3715. }
  3716. else
  3717. {
  3718. rc.top += CUI_GRIPPER_THEME_MARGIN;
  3719. rc.bottom -= CUI_GRIPPER_THEME_MARGIN;
  3720. }
  3721. if (FAILED(DrawThemeBackground(hDC, iStateID, &rc, 0 )))
  3722. goto Exit;
  3723. fRet = TRUE;
  3724. Exit:
  3725. return fRet;
  3726. }
  3727. /* O N P A I N T */
  3728. /*------------------------------------------------------------------------------
  3729. Paint procedure of gripper object
  3730. ------------------------------------------------------------------------------*/
  3731. void CUIFGripper::OnPaintNoTheme( HDC hDC )
  3732. {
  3733. CUIFWindow *pWnd = GetUIWnd();
  3734. CUIFScheme *pUIFScheme = pWnd->GetUIFScheme();
  3735. if (pUIFScheme)
  3736. {
  3737. pUIFScheme->DrawDragHandle(hDC, &GetRectRef(), IsVertical());
  3738. }
  3739. else
  3740. {
  3741. RECT rc;
  3742. if (!IsVertical())
  3743. {
  3744. ::SetRect(&rc,
  3745. GetRectRef().left + 1,
  3746. GetRectRef().top,
  3747. GetRectRef().left + 4,
  3748. GetRectRef().bottom);
  3749. }
  3750. else
  3751. {
  3752. ::SetRect(&rc,
  3753. GetRectRef().left,
  3754. GetRectRef().top + 1,
  3755. GetRectRef().right,
  3756. GetRectRef().top + 4);
  3757. }
  3758. DrawEdge(hDC, &rc, BDR_RAISEDINNER, BF_RECT);
  3759. }
  3760. }
  3761. /* O N S E T C U R S O R */
  3762. /*------------------------------------------------------------------------------
  3763. ------------------------------------------------------------------------------*/
  3764. BOOL CUIFGripper::OnSetCursor( UINT uMsg, POINT pt )
  3765. {
  3766. SetCursor(LoadCursor(NULL, IDC_SIZEALL));
  3767. return TRUE;
  3768. }
  3769. /* O N L B U T T O N D O W N */
  3770. /*------------------------------------------------------------------------------
  3771. ------------------------------------------------------------------------------*/
  3772. void CUIFGripper::OnLButtonDown( POINT pt )
  3773. {
  3774. RECT rc;
  3775. StartCapture();
  3776. _ptCur = pt;
  3777. ClientToScreen(m_pUIWnd->GetWnd(), &_ptCur);
  3778. GetWindowRect(m_pUIWnd->GetWnd(), &rc);
  3779. _ptCur.x -= rc.left;
  3780. _ptCur.y -= rc.top;
  3781. }
  3782. /* O N L B U T T O N U P */
  3783. /*------------------------------------------------------------------------------
  3784. ------------------------------------------------------------------------------*/
  3785. void CUIFGripper::OnLButtonUp( POINT pt )
  3786. {
  3787. if (IsCapture())
  3788. {
  3789. EndCapture();
  3790. }
  3791. }
  3792. /* O N M O U S E M O V E */
  3793. /*------------------------------------------------------------------------------
  3794. ------------------------------------------------------------------------------*/
  3795. void CUIFGripper::OnMouseMove( POINT pt )
  3796. {
  3797. if (IsCapture())
  3798. {
  3799. POINT ptCursor;
  3800. GetCursorPos(&ptCursor);
  3801. m_pUIWnd->Move(ptCursor.x - _ptCur.x, ptCursor.y - _ptCur.y, -1, -1);
  3802. }
  3803. }
  3804. /*=============================================================================*/
  3805. /* */
  3806. /* C U I F W N D F R A M E */
  3807. /* */
  3808. /*=============================================================================*/
  3809. /* C U I F W N D F R A M E */
  3810. /*------------------------------------------------------------------------------
  3811. Constructor of CUIFWndFrame
  3812. ------------------------------------------------------------------------------*/
  3813. CUIFWndFrame::CUIFWndFrame( CUIFObject *pParent, const RECT *prc, DWORD dwStyle ) : CUIFObject( pParent, 0, prc, dwStyle )
  3814. {
  3815. SetActiveTheme(L"WINDOW", WP_FRAMELEFT);
  3816. m_dwHTResizing = 0;
  3817. m_cxFrame = 0;
  3818. m_cyFrame = 0;
  3819. if (GetUIFScheme())
  3820. {
  3821. switch (GetStyle() & UIWNDFRAME_STYLEMASK) {
  3822. default:
  3823. case UIWNDFRAME_THIN: {
  3824. m_cxFrame = GetUIFScheme()->CxWndBorder();
  3825. m_cyFrame = GetUIFScheme()->CxWndBorder();
  3826. break;
  3827. }
  3828. case UIWNDFRAME_THICK:
  3829. case UIWNDFRAME_ROUNDTHICK: {
  3830. m_cxFrame = GetUIFScheme()->CxSizeFrame();
  3831. m_cyFrame = GetUIFScheme()->CySizeFrame();
  3832. break;
  3833. }
  3834. }
  3835. }
  3836. m_cxMin = GetSystemMetrics( SM_CXMIN );
  3837. m_cyMin = GetSystemMetrics( SM_CYMIN );
  3838. }
  3839. /* ~ C U I F W N D F R A M E */
  3840. /*------------------------------------------------------------------------------
  3841. Destructor of CUIFWndFrame
  3842. ------------------------------------------------------------------------------*/
  3843. CUIFWndFrame::~CUIFWndFrame( void )
  3844. {
  3845. }
  3846. /* O N P A I N T */
  3847. /*------------------------------------------------------------------------------
  3848. Paint procedure of wnd frame object
  3849. ------------------------------------------------------------------------------*/
  3850. BOOL CUIFWndFrame::OnPaintTheme( HDC hDC )
  3851. {
  3852. BOOL fRet = FALSE;
  3853. if (FAILED(EnsureThemeData(m_pUIWnd->GetWnd())))
  3854. goto Exit;
  3855. //
  3856. // DrawThemebackground() does not draw caption.
  3857. // so we draw the frame with 4 lines by DrawThemeLine().
  3858. //
  3859. // if (FAILED(DrawThemeBackground(hDC, FS_ACTIVE, &GetRectRef(), 0 )))
  3860. // goto Exit;
  3861. RECT rc;
  3862. //
  3863. // draw left side
  3864. //
  3865. rc = GetRectRef();
  3866. rc.right = m_cxFrame;
  3867. if (FAILED(DrawThemeEdge(hDC, 0, &rc, EDGE_RAISED, BF_LEFT )))
  3868. goto Exit;
  3869. //
  3870. // draw right side
  3871. //
  3872. rc = GetRectRef();
  3873. rc.left = rc.right - m_cxFrame;
  3874. if (FAILED(DrawThemeEdge(hDC, 0, &rc, EDGE_SUNKEN, BF_RIGHT )))
  3875. goto Exit;
  3876. //
  3877. // draw top side
  3878. //
  3879. rc = GetRectRef();
  3880. rc.bottom = m_cyFrame;
  3881. if (FAILED(DrawThemeEdge(hDC, 0, &rc, EDGE_RAISED, BF_TOP )))
  3882. goto Exit;
  3883. //
  3884. // draw bottom side
  3885. //
  3886. rc = GetRectRef();
  3887. rc.top = rc.bottom - m_cyFrame;
  3888. if (FAILED(DrawThemeEdge(hDC, 0, &rc, EDGE_SUNKEN, BF_BOTTOM )))
  3889. goto Exit;
  3890. fRet = TRUE;
  3891. Exit:
  3892. return fRet;
  3893. }
  3894. /* O N P A I N T */
  3895. /*------------------------------------------------------------------------------
  3896. Paint procedure of wnd frame object
  3897. ------------------------------------------------------------------------------*/
  3898. void CUIFWndFrame::OnPaintNoTheme( HDC hDC )
  3899. {
  3900. if (!GetUIFScheme())
  3901. return;
  3902. DWORD dwFlag = 0;
  3903. switch (GetStyle() & UIWNDFRAME_STYLEMASK) {
  3904. default:
  3905. case UIWNDFRAME_THIN: {
  3906. dwFlag = UIFDWF_THIN;
  3907. break;
  3908. }
  3909. case UIWNDFRAME_THICK: {
  3910. dwFlag = UIFDWF_THICK;
  3911. break;
  3912. }
  3913. case UIWNDFRAME_ROUNDTHICK: {
  3914. dwFlag = UIFDWF_ROUNDTHICK;
  3915. break;
  3916. }
  3917. }
  3918. GetUIFScheme()->DrawWndFrame( hDC, &GetRectRef(), dwFlag, m_cxFrame, m_cyFrame );
  3919. }
  3920. /* O N S E T C U R S O R */
  3921. /*------------------------------------------------------------------------------
  3922. ------------------------------------------------------------------------------*/
  3923. BOOL CUIFWndFrame::OnSetCursor( UINT uMsg, POINT pt )
  3924. {
  3925. DWORD dw;
  3926. LPCTSTR idc = NULL;
  3927. if (IsCapture()) {
  3928. dw = m_dwHTResizing;
  3929. }
  3930. else {
  3931. dw = HitTest( pt ) & GetStyle();
  3932. }
  3933. if (dw == (UIWNDFRAME_RESIZELEFT | UIWNDFRAME_RESIZETOP)) {
  3934. idc = IDC_SIZENWSE;
  3935. }
  3936. else if (dw == (UIWNDFRAME_RESIZELEFT | UIWNDFRAME_RESIZEBOTTOM)) {
  3937. idc = IDC_SIZENESW;
  3938. }
  3939. else if (dw == (UIWNDFRAME_RESIZERIGHT | UIWNDFRAME_RESIZETOP)) {
  3940. idc = IDC_SIZENESW;
  3941. }
  3942. else if (dw == (UIWNDFRAME_RESIZERIGHT | UIWNDFRAME_RESIZEBOTTOM)) {
  3943. idc = IDC_SIZENWSE;
  3944. }
  3945. else if (dw == UIWNDFRAME_RESIZELEFT) {
  3946. idc = IDC_SIZEWE;
  3947. }
  3948. else if (dw == UIWNDFRAME_RESIZETOP) {
  3949. idc = IDC_SIZENS;
  3950. }
  3951. else if (dw == UIWNDFRAME_RESIZERIGHT) {
  3952. idc = IDC_SIZEWE;
  3953. }
  3954. else if (dw == UIWNDFRAME_RESIZEBOTTOM) {
  3955. idc = IDC_SIZENS;
  3956. }
  3957. if (idc != NULL) {
  3958. SetCursor( LoadCursor( NULL, idc ) );
  3959. return TRUE;
  3960. }
  3961. return FALSE;
  3962. }
  3963. /* O N L B U T T O N D O W N */
  3964. /*------------------------------------------------------------------------------
  3965. ------------------------------------------------------------------------------*/
  3966. void CUIFWndFrame::OnLButtonDown( POINT pt )
  3967. {
  3968. DWORD dwHT;
  3969. dwHT = HitTest( pt ) & GetStyle();
  3970. if (dwHT != 0) {
  3971. ClientToScreen( m_pUIWnd->GetWnd(), &pt );
  3972. m_ptDrag = pt;
  3973. m_dwHTResizing = dwHT;
  3974. GetWindowRect( m_pUIWnd->GetWnd(), &m_rcOrg );
  3975. StartCapture();
  3976. }
  3977. }
  3978. /* O N L B U T T O N U P */
  3979. /*------------------------------------------------------------------------------
  3980. ------------------------------------------------------------------------------*/
  3981. void CUIFWndFrame::OnLButtonUp( POINT pt )
  3982. {
  3983. if (IsCapture()) {
  3984. EndCapture();
  3985. }
  3986. }
  3987. /* O N M O U S E M O V E */
  3988. /*------------------------------------------------------------------------------
  3989. ------------------------------------------------------------------------------*/
  3990. void CUIFWndFrame::OnMouseMove( POINT pt )
  3991. {
  3992. if (IsCapture()) {
  3993. RECT rc = m_rcOrg;
  3994. ClientToScreen( m_pUIWnd->GetWnd(), &pt );
  3995. if (m_dwHTResizing & UIWNDFRAME_RESIZELEFT) {
  3996. rc.left = m_rcOrg.left + (pt.x - m_ptDrag.x);
  3997. }
  3998. if (m_dwHTResizing & UIWNDFRAME_RESIZETOP) {
  3999. rc.top = m_rcOrg.top + (pt.y - m_ptDrag.y);
  4000. }
  4001. if (m_dwHTResizing & UIWNDFRAME_RESIZERIGHT) {
  4002. rc.right = m_rcOrg.right + (pt.x - m_ptDrag.x);
  4003. rc.right = max( rc.right, rc.left + m_cxMin );
  4004. }
  4005. if (m_dwHTResizing & UIWNDFRAME_RESIZEBOTTOM) {
  4006. rc.bottom = m_rcOrg.bottom + (pt.y - m_ptDrag.y);
  4007. rc.bottom = max( rc.bottom, rc.top + m_cyMin );
  4008. }
  4009. m_pUIWnd->Move( rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top );
  4010. }
  4011. }
  4012. /* G E T I N T E R N A L R E C T */
  4013. /*------------------------------------------------------------------------------
  4014. ------------------------------------------------------------------------------*/
  4015. void CUIFWndFrame::GetInternalRect( RECT *prc )
  4016. {
  4017. Assert( prc != NULL );
  4018. *prc = GetRectRef();
  4019. prc->left = prc->left + m_cxFrame;
  4020. prc->top = prc->top + m_cyFrame;
  4021. prc->right = prc->right - m_cxFrame;
  4022. prc->bottom = prc->bottom - m_cyFrame;
  4023. }
  4024. /* H I T T E S T */
  4025. /*------------------------------------------------------------------------------
  4026. ------------------------------------------------------------------------------*/
  4027. DWORD CUIFWndFrame::HitTest( POINT pt )
  4028. {
  4029. DWORD dwHT = 0;
  4030. dwHT |= (GetRectRef().left <= pt.x && pt.x < GetRectRef().left + m_cxFrame) ? UIWNDFRAME_RESIZELEFT : 0;
  4031. dwHT |= (GetRectRef().top <= pt.y && pt.y < GetRectRef().top + m_cyFrame) ? UIWNDFRAME_RESIZETOP : 0;
  4032. dwHT |= (GetRectRef().right - m_cxFrame <= pt.x && pt.x < GetRectRef().right ) ? UIWNDFRAME_RESIZERIGHT : 0;
  4033. dwHT |= (GetRectRef().bottom - m_cyFrame <= pt.y && pt.y < GetRectRef().bottom) ? UIWNDFRAME_RESIZEBOTTOM : 0;
  4034. return dwHT;
  4035. }
  4036. /* G E T F R A M E S I Z E */
  4037. /*------------------------------------------------------------------------------
  4038. ------------------------------------------------------------------------------*/
  4039. void CUIFWndFrame::GetFrameSize( SIZE *psize )
  4040. {
  4041. Assert( psize != NULL );
  4042. psize->cx = m_cxFrame;
  4043. psize->cy = m_cyFrame;
  4044. }
  4045. /* S E T F R A M E S I Z E */
  4046. /*------------------------------------------------------------------------------
  4047. ------------------------------------------------------------------------------*/
  4048. void CUIFWndFrame::SetFrameSize( SIZE *psize )
  4049. {
  4050. Assert( psize != NULL );
  4051. m_cxFrame = psize->cx;
  4052. m_cyFrame = psize->cy;
  4053. CallOnPaint();
  4054. }
  4055. /* G E T M I N I M U M S I Z E */
  4056. /*------------------------------------------------------------------------------
  4057. ------------------------------------------------------------------------------*/
  4058. void CUIFWndFrame::GetMinimumSize( SIZE *psize )
  4059. {
  4060. Assert( psize != NULL );
  4061. psize->cx = m_cxMin;
  4062. psize->cy = m_cyMin;
  4063. }
  4064. /* S E T M I N I M U M S I Z E */
  4065. /*------------------------------------------------------------------------------
  4066. ------------------------------------------------------------------------------*/
  4067. void CUIFWndFrame::SetMinimumSize( SIZE *psize )
  4068. {
  4069. Assert( psize != NULL );
  4070. if (psize->cx != -1) {
  4071. m_cxMin = psize->cx;
  4072. }
  4073. if (psize->cy != -1) {
  4074. m_cyMin = psize->cy;
  4075. }
  4076. }
  4077. /*=============================================================================*/
  4078. /* */
  4079. /* C U I F W N D C A P T I O N */
  4080. /* */
  4081. /*=============================================================================*/
  4082. /* C U I F W N D C A P T I O N */
  4083. /*------------------------------------------------------------------------------
  4084. ------------------------------------------------------------------------------*/
  4085. CUIFWndCaption::CUIFWndCaption( CUIFObject *pParent, DWORD dwID, const RECT *prc, DWORD dwStyle ) : CUIFStatic( pParent, dwID, prc, dwStyle )
  4086. {
  4087. }
  4088. /* ~ C U I F W N D C A P T I O N */
  4089. /*------------------------------------------------------------------------------
  4090. ------------------------------------------------------------------------------*/
  4091. CUIFWndCaption::~CUIFWndCaption( void )
  4092. {
  4093. }
  4094. /* O N P A I N T */
  4095. /*------------------------------------------------------------------------------
  4096. ------------------------------------------------------------------------------*/
  4097. void CUIFWndCaption::OnPaint( HDC hDC )
  4098. {
  4099. HFONT hFontOld;
  4100. COLORREF colTextOld;
  4101. int iBkModeOld;
  4102. int xAlign;
  4103. int yAlign;
  4104. SIZE size;
  4105. int cwch;
  4106. UIFCOLOR colBkgnd;
  4107. UIFCOLOR colText;
  4108. //
  4109. if (FHasStyle( UIWNDCAPTION_ACTIVE )) {
  4110. colBkgnd = UIFCOLOR_ACTIVECAPTIONBKGND;
  4111. colText = UIFCOLOR_ACTIVECAPTIONTEXT;
  4112. }
  4113. else {
  4114. colBkgnd = UIFCOLOR_INACTIVECAPTIONBKGND;
  4115. colText = UIFCOLOR_INACTIVECAPTIONTEXT;
  4116. }
  4117. // background
  4118. FillRect( hDC, &GetRectRef(), GetUIFBrush( colBkgnd ) );
  4119. // caption text
  4120. if (m_pwchText == NULL) {
  4121. return;
  4122. }
  4123. // prepare objects
  4124. hFontOld= (HFONT)SelectObject( hDC, GetFont() );
  4125. colTextOld = SetTextColor( hDC, GetUIFColor( colText ) );
  4126. iBkModeOld = SetBkMode( hDC, TRANSPARENT );
  4127. // calc alignment
  4128. cwch = StrLenW(m_pwchText);
  4129. GetTextExtentPointW( hDC, m_pwchText, cwch, &size );
  4130. xAlign = 8;
  4131. yAlign = (GetRectRef().bottom - GetRectRef().top - size.cy) / 2;
  4132. // draw
  4133. CUIExtTextOut( hDC,
  4134. GetRectRef().left + xAlign,
  4135. GetRectRef().top + yAlign,
  4136. ETO_CLIPPED,
  4137. &GetRectRef(),
  4138. m_pwchText,
  4139. cwch,
  4140. NULL );
  4141. // restore objects
  4142. SelectObject( hDC, hFontOld );
  4143. SetTextColor( hDC, colTextOld );
  4144. SetBkMode( hDC, iBkModeOld );
  4145. }
  4146. /* O N L B U T T O N D O W N */
  4147. /*------------------------------------------------------------------------------
  4148. ------------------------------------------------------------------------------*/
  4149. void CUIFWndCaption::OnLButtonDown( POINT pt )
  4150. {
  4151. RECT rc;
  4152. if (!FHasStyle( UIWNDCAPTION_MOVABLE )) {
  4153. return;
  4154. }
  4155. StartCapture();
  4156. SetCursor( LoadCursor( NULL, IDC_SIZEALL ) );
  4157. m_ptDrag = pt;
  4158. ClientToScreen( m_pUIWnd->GetWnd(), &m_ptDrag );
  4159. GetWindowRect( m_pUIWnd->GetWnd(), &rc );
  4160. m_ptDrag.x -= rc.left;
  4161. m_ptDrag.y -= rc.top;
  4162. }
  4163. /* O N L B U T T O N U P */
  4164. /*------------------------------------------------------------------------------
  4165. ------------------------------------------------------------------------------*/
  4166. void CUIFWndCaption::OnLButtonUp( POINT pt )
  4167. {
  4168. if (IsCapture()) {
  4169. EndCapture();
  4170. SetCursor( LoadCursor( NULL, IDC_ARROW ) );
  4171. }
  4172. }
  4173. /* O N M O U S E M O V E */
  4174. /*------------------------------------------------------------------------------
  4175. ------------------------------------------------------------------------------*/
  4176. void CUIFWndCaption::OnMouseMove( POINT pt )
  4177. {
  4178. if (IsCapture()) {
  4179. POINT ptCursor;
  4180. GetCursorPos( &ptCursor );
  4181. m_pUIWnd->Move( ptCursor.x - m_ptDrag.x, ptCursor.y - m_ptDrag.y, -1, -1 );
  4182. }
  4183. }
  4184. /* O N S E T C U R S O R */
  4185. /*------------------------------------------------------------------------------
  4186. ------------------------------------------------------------------------------*/
  4187. BOOL CUIFWndCaption::OnSetCursor( UINT uMsg, POINT pt )
  4188. {
  4189. if (IsCapture()) {
  4190. SetCursor( LoadCursor( NULL, IDC_SIZEALL ) );
  4191. }
  4192. else {
  4193. SetCursor( LoadCursor( NULL, IDC_ARROW ) );
  4194. }
  4195. return TRUE;
  4196. }
  4197. /*=============================================================================*/
  4198. /* */
  4199. /* C U I F C A P T I O N B U T T O N */
  4200. /* */
  4201. /*=============================================================================*/
  4202. /* C U I F C A P T I O N B U T T O N */
  4203. /*------------------------------------------------------------------------------
  4204. ------------------------------------------------------------------------------*/
  4205. CUIFCaptionButton::CUIFCaptionButton( CUIFObject *pParent, DWORD dwID, const RECT *prc, DWORD dwStyle ) : CUIFButton2( pParent, dwID, prc, dwStyle )
  4206. {
  4207. }
  4208. /* ~ C U I F C A P T I O N B U T T O N */
  4209. /*------------------------------------------------------------------------------
  4210. ------------------------------------------------------------------------------*/
  4211. CUIFCaptionButton::~CUIFCaptionButton( void )
  4212. {
  4213. }
  4214. /* O N P A I N T */
  4215. /*------------------------------------------------------------------------------
  4216. ------------------------------------------------------------------------------*/
  4217. void CUIFCaptionButton::OnPaint( HDC hDC )
  4218. {
  4219. DWORD dwState = 0;
  4220. HDC hDCMem;
  4221. HBITMAP hBmpMem;
  4222. HBITMAP hBmpOld;
  4223. SIZE size;
  4224. RECT rc;
  4225. SIZE sizeText = {0};
  4226. SIZE sizeImage = {0};
  4227. SIZE sizeFace = {0};
  4228. SIZE offset = {0};
  4229. RECT rcText = {0};
  4230. RECT rcImage = {0};
  4231. RECT rcFace = {0};
  4232. HFONT hFontOld;
  4233. if (!m_pUIFScheme)
  4234. return;
  4235. // make draw flag
  4236. dwState |= (m_fToggled) ? UIFDCS_SELECTED : 0;
  4237. switch (m_dwStatus) {
  4238. case UIBUTTON_DOWN: {
  4239. dwState |= UIFDCS_MOUSEDOWN;
  4240. break;
  4241. }
  4242. case UIBUTTON_HOVER:
  4243. case UIBUTTON_DOWNOUT: {
  4244. dwState |= UIFDCS_MOUSEOVER;
  4245. break;
  4246. }
  4247. }
  4248. dwState |= IsEnabled() ? 0 : UIFDCS_DISABLED;
  4249. dwState |= (FHasStyle( UICAPTIONBUTTON_ACTIVE ) ? UIFDCS_ACTIVE : UIFDCS_INACTIVE);
  4250. // prepare memory dc
  4251. size.cx = GetRectRef().right - GetRectRef().left;
  4252. size.cy = GetRectRef().bottom - GetRectRef().top;
  4253. hDCMem = CreateCompatibleDC( hDC );
  4254. hBmpMem = CreateCompatibleBitmap( hDC, size.cx, size.cy );
  4255. hBmpOld = (HBITMAP)SelectObject( hDCMem, hBmpMem );
  4256. BitBlt( hDCMem, 0, 0, size.cx, size.cy, hDC, GetRectRef().left, GetRectRef().top, SRCCOPY );
  4257. ::SetRect( &rc, 0, 0, size.cx, size.cy );
  4258. hFontOld = (HFONT)SelectObject( hDCMem, GetFont() );
  4259. // calc face size
  4260. if (m_pwchText != NULL) {
  4261. sizeText = m_sizeText;
  4262. }
  4263. if (m_hIcon != NULL) {
  4264. sizeImage = m_sizeIcon;
  4265. }
  4266. else if (m_hBmp != NULL ) {
  4267. sizeImage = m_sizeBmp;
  4268. }
  4269. // alignment
  4270. sizeFace.cx = sizeText.cx + sizeImage.cx + ((sizeText.cx != 0 && sizeImage.cx != 0) ? 2 : 0);
  4271. sizeFace.cy = max( sizeText.cy, sizeImage.cy );
  4272. switch (GetStyleBits( UIBUTTON_HALIGNMASK )) {
  4273. case UIBUTTON_LEFT:
  4274. default: {
  4275. rcFace.left = rc.left + 2;
  4276. rcFace.right = rcFace.left + sizeFace.cx;
  4277. break;
  4278. }
  4279. case UIBUTTON_CENTER: {
  4280. rcFace.left = (rc.right + rc.left - sizeFace.cx) / 2;
  4281. rcFace.right = rcFace.left + sizeFace.cx;
  4282. break;
  4283. }
  4284. case UIBUTTON_RIGHT: {
  4285. rcFace.left = rc.right - 2 - sizeText.cx;
  4286. rcFace.right = rcFace.left + sizeFace.cx;
  4287. break;
  4288. }
  4289. }
  4290. switch (GetStyleBits( UIBUTTON_VALIGNMASK )) {
  4291. case UIBUTTON_TOP:
  4292. default: {
  4293. rcFace.top = rc.top + 2;
  4294. rcFace.bottom = rcFace.top + sizeFace.cy;
  4295. break;
  4296. }
  4297. case UIBUTTON_VCENTER: {
  4298. rcFace.top = (rc.bottom + rc.top - sizeFace.cy) / 2;
  4299. rcFace.bottom = rcFace.top + sizeFace.cy;
  4300. break;
  4301. }
  4302. case UIBUTTON_BOTTOM: {
  4303. rcFace.top = rc.bottom - 2 - sizeFace.cy;
  4304. rcFace.bottom = rcFace.top + sizeFace.cy;
  4305. break;
  4306. }
  4307. }
  4308. m_pUIFScheme->GetCtrlFaceOffset( UIFDCF_CAPTIONBUTTON, dwState, &offset );
  4309. OffsetRect( &rcFace, offset.cx, offset.cy );
  4310. rcImage.left = rcFace.left;
  4311. rcImage.top = (rcFace.bottom + rcFace.top - sizeImage.cy) / 2;
  4312. rcImage.right = rcImage.left + sizeImage.cx;
  4313. rcImage.bottom = rcImage.top + sizeImage.cy;
  4314. rcText.left = rcFace.right - sizeText.cx;
  4315. rcText.top = (rcFace.bottom + rcFace.top - sizeText.cy) / 2;
  4316. rcText.right = rcText.left + sizeText.cx;
  4317. rcText.bottom = rcText.top + sizeText.cy;
  4318. // paint background
  4319. m_pUIFScheme->DrawFrameCtrlBkgd( hDCMem, &rc, UIFDCF_CAPTIONBUTTON, dwState );
  4320. // paint face
  4321. if (m_hIcon!= NULL) {
  4322. m_pUIFScheme->DrawFrameCtrlIcon( hDCMem, &rcImage, m_hIcon, dwState, &m_sizeIcon);
  4323. }
  4324. else if (m_hBmp != NULL) {
  4325. m_pUIFScheme->DrawFrameCtrlBitmap( hDCMem, &rcImage, m_hBmp, m_hBmpMask, dwState );
  4326. }
  4327. // draw button edge
  4328. m_pUIFScheme->DrawFrameCtrlEdge( hDCMem, &rc, UIFDCF_CAPTIONBUTTON, dwState );
  4329. //
  4330. BitBlt( hDC, GetRectRef().left, GetRectRef().top, size.cx, size.cy, hDCMem, 0, 0, SRCCOPY );
  4331. SelectObject( hDCMem, hFontOld );
  4332. SelectObject( hDCMem, hBmpOld );
  4333. DeleteObject( hBmpMem );
  4334. DeleteDC( hDCMem );
  4335. }