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.

271 lines
7.1 KiB

  1. // minifwnd.cpp : Defines the behaviors for the CMiniFrmWnd class.
  2. //
  3. #include "stdafx.h"
  4. #include "global.h"
  5. #include "pbrush.h"
  6. #include "pbrusfrm.h"
  7. #include "pbrusvw.h"
  8. #include "docking.h"
  9. #include "minifwnd.h"
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static CHAR BASED_CODE THIS_FILE[] = __FILE__;
  13. #endif
  14. IMPLEMENT_DYNAMIC( CMiniFrmWnd, CFrameWnd )
  15. #include "memtrace.h"
  16. /***************************************************************************/
  17. BEGIN_MESSAGE_MAP( CMiniFrmWnd, CFrameWnd )
  18. ON_WM_NCLBUTTONDOWN()
  19. ON_WM_LBUTTONUP()
  20. ON_WM_RBUTTONDOWN()
  21. ON_WM_KEYDOWN()
  22. ON_WM_CREATE()
  23. ON_WM_SYSCOMMAND()
  24. ON_WM_MOVE()
  25. ON_WM_NCACTIVATE()
  26. ON_MESSAGE(WM_HELPHITTEST, OnHelpHitTest)
  27. ON_MESSAGE(WM_MOVING, OnMoving)
  28. END_MESSAGE_MAP()
  29. static CString NEAR szClass;
  30. /***************************************************************************/
  31. CMiniFrmWnd::CMiniFrmWnd()
  32. {
  33. if (szClass.IsEmpty())
  34. {
  35. // NOTE: we create this brush for use in WNDCLASS.hbrBackground.
  36. // We intentionally don't delete it. It will be deleted by Windows
  37. // when the class gets deleted (after app termination).
  38. // HBRUSH hbrGrayBack = ::CreateSolidBrush( ::GetSysColor( COLOR_BTNTEXT ) );
  39. szClass = AfxRegisterWndClass( CS_DBLCLKS, ::LoadCursor( NULL, IDC_ARROW ),
  40. (HBRUSH)(COLOR_BTNFACE + 1)/* hbrGrayBack */, NULL );
  41. }
  42. m_Dockable = CPBView::unknown;
  43. m_pDocking = NULL;
  44. }
  45. /***************************************************************************/
  46. BOOL CMiniFrmWnd::Create( const TCHAR FAR* lpWindowName, DWORD dwStyle,
  47. const RECT& rect, CWnd* pParentWnd )
  48. {
  49. return CFrameWnd::Create( szClass, lpWindowName,
  50. dwStyle | WS_POPUPWINDOW | WS_CAPTION,
  51. rect, pParentWnd, NULL,
  52. WS_EX_TOOLWINDOW | WS_EX_WINDOWEDGE, NULL );
  53. }
  54. /***************************************************************************/
  55. void CMiniFrmWnd::OnNcLButtonDown( UINT nHitTest, CPoint pt )
  56. {
  57. if (nHitTest == HTCAPTION
  58. && m_Dockable != CPBView::unknown)
  59. {
  60. m_pDocking = new CDocking;
  61. ASSERT( m_pDocking );
  62. if (m_pDocking)
  63. {
  64. CRect rect;
  65. GetWindowRect( &rect );
  66. if (! m_pDocking->Create( pt, rect, FALSE, m_Dockable ))
  67. {
  68. delete m_pDocking;
  69. m_pDocking = NULL;
  70. }
  71. }
  72. }
  73. CFrameWnd::OnNcLButtonDown( nHitTest, pt );
  74. }
  75. /***************************************************************************/
  76. void CMiniFrmWnd::OnLButtonUp( UINT nFlags, CPoint pt )
  77. {
  78. CFrameWnd::OnLButtonUp( nFlags, pt );
  79. }
  80. /***************************************************************************/
  81. int CMiniFrmWnd::OnCreate( LPCREATESTRUCT lpCreateStruct )
  82. {
  83. CMenu* pMenu = GetSystemMenu(FALSE);
  84. if (pMenu != NULL)
  85. {
  86. pMenu->RemoveMenu( 7, MF_BYPOSITION);
  87. pMenu->RemoveMenu( 5, MF_BYPOSITION);
  88. pMenu->RemoveMenu(SC_RESTORE , MF_BYCOMMAND);
  89. pMenu->RemoveMenu(SC_MINIMIZE, MF_BYCOMMAND);
  90. pMenu->RemoveMenu(SC_MAXIMIZE, MF_BYCOMMAND);
  91. pMenu->RemoveMenu(SC_TASKLIST, MF_BYCOMMAND);
  92. }
  93. return CFrameWnd::OnCreate(lpCreateStruct);
  94. }
  95. /***************************************************************************/
  96. BOOL CMiniFrmWnd::OnCommand(UINT wParam, LONG lParam)
  97. {
  98. if (LOWORD(lParam) == 0 && wParam >= SC_SIZE)
  99. {
  100. PostMessage(WM_SYSCOMMAND, wParam, lParam);
  101. return TRUE;
  102. }
  103. return CFrameWnd::OnCommand(wParam, lParam);
  104. }
  105. /***************************************************************************/
  106. void CMiniFrmWnd::OnSysCommand(UINT nID, LONG lParam)
  107. {
  108. switch (nID & 0xfff0)
  109. {
  110. case SC_PREVWINDOW:
  111. case SC_NEXTWINDOW:
  112. if (LOWORD( lParam ) == VK_F6)
  113. {
  114. GetParent()->SetFocus();
  115. return;
  116. }
  117. break;
  118. case SC_KEYMENU:
  119. if (LOWORD(lParam) != TEXT('-'))
  120. {
  121. GetParent()->SetActiveWindow();
  122. GetParent()->SendMessage( WM_SYSCOMMAND, nID, lParam );
  123. SetActiveWindow();
  124. }
  125. return;
  126. }
  127. CFrameWnd::OnSysCommand( nID, lParam );
  128. }
  129. /***************************************************************************/
  130. LRESULT CMiniFrmWnd::OnHelpHitTest( WPARAM, LPARAM )
  131. {
  132. ASSERT( GetHelpOffset() );
  133. return HID_BASE_RESOURCE + GetHelpOffset();
  134. }
  135. /******************************************************************************/
  136. void CMiniFrmWnd::OnRButtonDown( UINT nFlags, CPoint point )
  137. {
  138. if (m_pDocking)
  139. PostMessage( WM_COMMAND, VK_ESCAPE );
  140. CFrameWnd::OnRButtonDown( nFlags, point );
  141. }
  142. /******************************************************************************/
  143. void CMiniFrmWnd::OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags )
  144. {
  145. if (nChar == VK_ESCAPE && m_pDocking)
  146. CancelDrag();
  147. CFrameWnd::OnKeyDown( nChar, nRepCnt, nFlags );
  148. }
  149. /***************************************************************************/
  150. void CMiniFrmWnd::CancelDrag()
  151. {
  152. m_pDocking->Clear();
  153. delete m_pDocking;
  154. m_pDocking = NULL;
  155. }
  156. /******************************************************************************/
  157. LRESULT CMiniFrmWnd::OnMoving( WPARAM, LPARAM lprc )
  158. {
  159. LRESULT lResult = 0;
  160. if (m_pDocking)
  161. {
  162. CPoint pt;
  163. CRect rect( (LPRECT)lprc );
  164. GetCursorPos( &pt );
  165. m_pDocking->Move( pt, rect );
  166. *((LPRECT)lprc) = rect;
  167. }
  168. return lResult;
  169. }
  170. /******************************************************************************/
  171. void CMiniFrmWnd::OnMove( int x, int y )
  172. {
  173. CFrameWnd::OnMove( x, y );
  174. if (! m_pDocking)
  175. return;
  176. CRect rect;
  177. BOOL bDocked = m_pDocking->Clear( &rect );
  178. delete m_pDocking;
  179. m_pDocking = NULL;
  180. CPBView* pView = (CPBView*)((CFrameWnd*)AfxGetMainWnd())->GetActiveView();
  181. if (pView == NULL || ! pView->IsKindOf( RUNTIME_CLASS( CPBView ) ))
  182. return;
  183. if (! bDocked)
  184. {
  185. pView->SetFloatPos( m_Dockable, rect );
  186. return;
  187. }
  188. }
  189. /******************************************************************************/
  190. BOOL CMiniFrmWnd::OnNcActivate(BOOL bActive)
  191. {
  192. //
  193. // Work-around MFC bug - CMiniFrmWnd inherits from CFrameWnd,
  194. // so it inherits the intentional bug in CFrameWnd::OnActivate
  195. // MFC's CMiniFrameWnd has this hack, so does CMiniFrmWnd now...
  196. //
  197. if (m_nFlags & WF_KEEPMINIACTIVE)
  198. {
  199. return FALSE;
  200. }
  201. return CFrameWnd::OnNcActivate(bActive);
  202. }
  203. /******************************************************************************/