DropScrollBar.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /////////////////////////////////////////////////////////////////////////////
  2. // DropScrollBar.cpp : implementation file
  3. //
  4. // CAdvComboBox Control
  5. // Version: 2.1
  6. // Date: September 2002
  7. // Author: Mathias Tunared
  8. // Email: Mathias@inorbit.com
  9. // Copyright (c) 2002. All Rights Reserved.
  10. //
  11. // This code, in compiled form or as source code, may be redistributed
  12. // unmodified PROVIDING it is not sold for profit without the authors
  13. // written consent, and providing that this notice and the authors name
  14. // and all copyright notices remains intact.
  15. //
  16. // This file is provided "as is" with no expressed or implied warranty.
  17. // The author accepts no liability for any damage/loss of business that
  18. // this product may cause.
  19. //
  20. /////////////////////////////////////////////////////////////////////////////
  21. #include "stdafx.h"
  22. #include "DropScrollBar.h"
  23. #include "DropListBox.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CDropScrollBar
  31. CDropScrollBar::CDropScrollBar() :
  32. m_pListBox( 0 )
  33. {
  34. }
  35. CDropScrollBar::~CDropScrollBar()
  36. {
  37. }
  38. BEGIN_MESSAGE_MAP(CDropScrollBar, CScrollBar)
  39. //{{AFX_MSG_MAP(CDropScrollBar)
  40. ON_WM_MOUSEMOVE()
  41. ON_WM_VSCROLL_REFLECT()
  42. ON_WM_LBUTTONDOWN()
  43. //}}AFX_MSG_MAP
  44. ON_MESSAGE( WM_VRC_SETCAPTURE, OnSetCapture )
  45. ON_MESSAGE( WM_VRC_RELEASECAPTURE, OnReleaseCapture )
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CDropScrollBar message handlers
  49. void CDropScrollBar::OnMouseMove(UINT nFlags, CPoint point)
  50. {
  51. // Is mouse within listbox
  52. CRect rcClient;
  53. GetClientRect( rcClient );
  54. if( !rcClient.PtInRect( point ) )
  55. {
  56. ReleaseCapture();
  57. GetParent()->SendMessage( WM_VRC_SETCAPTURE );
  58. }
  59. CScrollBar::OnMouseMove(nFlags, point);
  60. }
  61. LONG CDropScrollBar::OnSetCapture( WPARAM /*wParam*/, LPARAM /*lParam*/ )
  62. {
  63. SetCapture();
  64. return FALSE;
  65. }
  66. LONG CDropScrollBar::OnReleaseCapture( WPARAM /*wParam*/, LPARAM /*lParam*/ )
  67. {
  68. ReleaseCapture();
  69. return FALSE;
  70. }
  71. void CDropScrollBar::VScroll(UINT nSBCode, UINT nPos)
  72. {
  73. if( !m_pListBox )
  74. return;
  75. SCROLLINFO info;
  76. info.cbSize = sizeof(SCROLLINFO);
  77. if( !GetScrollInfo( &info, SIF_ALL|SIF_DISABLENOSCROLL ) )
  78. return;
  79. switch( nSBCode )
  80. {
  81. case SB_BOTTOM: // Scroll to bottom.
  82. break;
  83. case SB_ENDSCROLL: // End scroll.
  84. //+++
  85. ReleaseCapture();
  86. GetParent()->PostMessage( WM_VRC_SETCAPTURE );
  87. break;
  88. case SB_LINEDOWN: // Scroll one line down.
  89. info.nPos++;
  90. if( info.nPos > info.nMax )
  91. info.nPos = info.nMax;
  92. m_pListBox->SetTopIdx( info.nPos );
  93. break;
  94. case SB_LINEUP: // Scroll one line up.
  95. info.nPos--;
  96. if( info.nPos < info.nMin )
  97. info.nPos = info.nMin;
  98. m_pListBox->SetTopIdx( info.nPos );
  99. break;
  100. case SB_PAGEDOWN: // Scroll one page down.
  101. info.nPos += info.nPage;
  102. if( info.nPos > info.nMax )
  103. info.nPos = info.nMax;
  104. m_pListBox->SetTopIdx( info.nPos );
  105. break;
  106. case SB_PAGEUP: // Scroll one page up.
  107. info.nPos -= info.nPage;
  108. if( info.nPos < info.nMin )
  109. info.nPos = info.nMin;
  110. m_pListBox->SetTopIdx( info.nPos );
  111. break;
  112. case SB_THUMBPOSITION: // Scroll to the absolute position. The current position is provided in nPos.
  113. info.nPos = nPos;
  114. m_pListBox->SetTopIdx( info.nPos );
  115. break;
  116. case SB_THUMBTRACK: // Drag scroll box to specified position. The current position is provided in nPos.
  117. info.nPos = nPos;
  118. m_pListBox->SetTopIdx( info.nPos );
  119. break;
  120. case SB_TOP: // Scroll to top.
  121. break;
  122. }
  123. SetScrollInfo( &info );
  124. }
  125. void CDropScrollBar::SetListBox( CDropListBox* pListBox )
  126. {
  127. ASSERT( pListBox != NULL );
  128. m_pListBox = pListBox;
  129. int nTop = m_pListBox->GetTopIndex();
  130. int nBottom = m_pListBox->GetBottomIndex();
  131. SCROLLINFO info;
  132. info.cbSize = sizeof(SCROLLINFO);
  133. info.fMask = SIF_ALL | SIF_DISABLENOSCROLL;
  134. info.nMax = m_pListBox->GetCount()-1;
  135. info.nMin = 0;
  136. info.nPage = nBottom - nTop;
  137. info.nPos = 0;
  138. info.nTrackPos = 0;
  139. SetScrollInfo( &info );
  140. }
  141. void CDropScrollBar::OnLButtonDown(UINT nFlags, CPoint point)
  142. {
  143. CRect rc;
  144. GetClientRect( &rc );
  145. if( !rc.PtInRect( point ) )
  146. {
  147. ReleaseCapture();
  148. GetParent()->SendMessage( WM_VRC_SETCAPTURE );
  149. }
  150. CScrollBar::OnLButtonDown(nFlags, point);
  151. }