SPPPropertyGridInplaceButton.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /********************************************
  2. ** 工作室:S&P工作室
  3. ** 作者 :张东斌
  4. ** 日期 :2007年6月
  5. *********************************************/
  6. #include "stdafx.h"
  7. #include "SPVC80Helpers.h"
  8. #include "SPDrawHelpers.h"
  9. #include "SPPropertyGridInplaceEdit.h"
  10. #include "SPPropertyGridInplaceButton.h"
  11. #include "SPPropertyGridInplaceList.h"
  12. #include "SPPropertyGridItem.h"
  13. #include "SPPropertyGridInplaceButton.h"
  14. #include "SPPropertyGridInplaceEdit.h"
  15. #include "SPPropertyGrid.h"
  16. #include "SPPropertyGridPaintManager.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CXTColorPicker
  24. CSPPropertyGridInplaceButton::CSPPropertyGridInplaceButton() : m_bPressed( FALSE ) , m_bOver( FALSE ) , m_pGrid( 0 ) , m_pItem( 0 )
  25. {
  26. }
  27. CSPPropertyGridInplaceButton::~CSPPropertyGridInplaceButton()
  28. {
  29. }
  30. IMPLEMENT_DYNAMIC( CSPPropertyGridInplaceButton , CStatic )
  31. BEGIN_MESSAGE_MAP(CSPPropertyGridInplaceButton, CStatic)
  32. //{{AFX_MSG_MAP(CSPPropertyGridInplaceButton)
  33. ON_WM_PAINT()
  34. ON_WM_LBUTTONDOWN()
  35. ON_WM_LBUTTONUP()
  36. ON_WM_MOUSEMOVE()
  37. ON_WM_CAPTURECHANGED()
  38. ON_WM_SETFOCUS()
  39. ON_WM_KILLFOCUS()
  40. ON_WM_KEYDOWN()
  41. ON_WM_GETDLGCODE()
  42. ON_MESSAGE_VOID(WM_MOUSELEAVE, OnMouseLeave)
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. UINT CSPPropertyGridInplaceButton::OnGetDlgCode()
  46. {
  47. return DLGC_WANTALLKEYS;
  48. }
  49. void CSPPropertyGridInplaceButton::HideWindow()
  50. {
  51. if ( m_hWnd )
  52. {
  53. ShowWindow( SW_HIDE );
  54. }
  55. }
  56. void CSPPropertyGridInplaceButton::Create( CSPPropertyGridItem * pItem , CRect rect )
  57. {
  58. ASSERT( pItem && pItem->GetGrid() );
  59. int nWidth = GetSystemMetrics( SM_CXHTHUMB );
  60. m_pGrid = pItem->GetGrid();
  61. rect.left = rect.right - nWidth;
  62. rect.top -= 1;
  63. if ( !m_hWnd )
  64. {
  65. CStatic::Create( _T( "" ),SS_NOTIFY | WS_CHILD,rect,m_pGrid );
  66. }
  67. SetWindowPos( 0,rect.left,rect.top,rect.Width(),rect.Height(),SWP_NOZORDER | SWP_SHOWWINDOW );
  68. m_pItem = pItem;
  69. }
  70. /////////////////////////////////////////////////////////////////////////////
  71. // CSPPropertyGridInplaceButton message handlers
  72. void CSPPropertyGridInplaceButton::OnPaint()
  73. {
  74. CPaintDC dc ( this );
  75. CSPPropertyGridView * pView = ( CSPPropertyGridView * ) m_pGrid;
  76. if ( pView )
  77. {
  78. pView->m_pGrid->GetPaintManager()->FillInplaceButton( &dc,this );
  79. }
  80. }
  81. void CSPPropertyGridInplaceButton::OnLButtonDown( UINT , CPoint )
  82. {
  83. m_bOver = m_bPressed = TRUE;
  84. Invalidate( FALSE );
  85. SetCapture();
  86. }
  87. void CSPPropertyGridInplaceButton::OnLButtonUp( UINT nFlags , CPoint point )
  88. {
  89. if ( m_bPressed )
  90. {
  91. m_bPressed = FALSE;
  92. Invalidate( FALSE );
  93. ReleaseCapture();
  94. if ( m_bOver )
  95. m_pItem->OnInplaceButtonDown();
  96. }
  97. CStatic::OnLButtonUp( nFlags,point );
  98. }
  99. void CSPPropertyGridInplaceButton::OnMouseMove( UINT nFlags , CPoint point )
  100. {
  101. CSPClientRect rect ( this );
  102. if ( ( rect.PtInRect( point ) && !m_bOver ) || ( !rect.PtInRect( point ) && m_bOver ) )
  103. {
  104. m_bOver = rect.PtInRect( point );
  105. Invalidate( FALSE );
  106. if ( m_bOver )
  107. {
  108. TRACKMOUSEEVENT tme ={sizeof( TRACKMOUSEEVENT ), TME_LEAVE, m_hWnd};
  109. _TrackMouseEvent( &tme );
  110. }
  111. }
  112. CStatic::OnMouseMove( nFlags,point );
  113. }
  114. void CSPPropertyGridInplaceButton::OnMouseLeave()
  115. {
  116. //reset mouse vars
  117. OnMouseMove( 0,CPoint( -1,-1 ) );
  118. }
  119. void CSPPropertyGridInplaceButton::OnCaptureChanged( CWnd * pWnd )
  120. {
  121. m_bPressed = FALSE;
  122. Invalidate( FALSE );
  123. CStatic::OnCaptureChanged( pWnd );
  124. }
  125. void CSPPropertyGridInplaceButton::DestroyItem()
  126. {
  127. // reset variables to defaults.
  128. m_bPressed = FALSE;
  129. m_bOver = FALSE;
  130. m_pGrid = NULL;
  131. m_pItem = NULL;
  132. // destroy the window.
  133. //DestroyWindow( );
  134. if ( ::IsWindow( m_hWnd ) )
  135. {
  136. ShowWindow( SW_HIDE );
  137. }
  138. }
  139. void CSPPropertyGridInplaceButton::OnSetFocus( CWnd * pOldWnd )
  140. {
  141. CStatic::OnSetFocus( pOldWnd );
  142. Invalidate( FALSE );
  143. #ifdef SP_SITENOTIFY_ONFOCUS
  144. SP_SITENOTIFY_ONFOCUS( this,m_pGrid,TRUE )
  145. #endif
  146. }
  147. void CSPPropertyGridInplaceButton::OnKillFocus( CWnd * pNewWnd )
  148. {
  149. CStatic::OnKillFocus( pNewWnd );
  150. if ( m_pGrid )
  151. {
  152. m_pGrid->Invalidate( FALSE );
  153. }
  154. Invalidate( FALSE );
  155. #ifdef SP_SITENOTIFY_ONFOCUS
  156. SP_SITENOTIFY_ONFOCUS( this,m_pGrid,FALSE )
  157. #endif
  158. }
  159. void CSPPropertyGridInplaceButton::OnKeyDown( UINT nChar , UINT nRepCnt , UINT nFlags )
  160. {
  161. if ( m_pItem && ( nChar == VK_SPACE || nChar == VK_DOWN || nChar == VK_RETURN ) )
  162. {
  163. m_pItem->OnInplaceButtonDown();
  164. return;
  165. }
  166. if ( nChar == VK_TAB && m_pGrid )
  167. {
  168. ( ( CSPPropertyGrid * ) m_pGrid->GetParent() )->OnNavigate( SPGridUIInplaceButton,GetKeyState( VK_SHIFT ) >= 0,m_pItem );
  169. return;
  170. }
  171. CStatic::OnKeyDown( nChar,nRepCnt,nFlags );
  172. }