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.

186 lines
4.6 KiB

  1. // docking.cpp : implementation of the CDocking class
  2. //
  3. #include "stdafx.h"
  4. #include "pbrush.h"
  5. #include "pbrusfrm.h"
  6. #include "pbrusvw.h"
  7. #include "minifwnd.h"
  8. #include "imgwell.h"
  9. #include "toolbox.h"
  10. #include "imgcolor.h"
  11. #include "docking.h"
  12. #ifdef _DEBUG
  13. #undef THIS_FILE
  14. static CHAR BASED_CODE THIS_FILE[] = __FILE__;
  15. #endif
  16. IMPLEMENT_DYNAMIC( CDocking, CObject )
  17. #include "memtrace.h"
  18. /***************************************************************************/
  19. // CDocking implementation
  20. CDocking::CDocking()
  21. {
  22. m_bStarted = FALSE;
  23. m_bDocking = FALSE;
  24. m_iDockingX = ::GetSystemMetrics( SM_CXICON );
  25. m_iDockingY = ::GetSystemMetrics( SM_CYICON );
  26. m_iDockingX += m_iDockingX / 2;
  27. m_iDockingY += m_iDockingY / 2;
  28. }
  29. /***************************************************************************/
  30. BOOL CDocking::Create( CPoint ptDrop, CRect& rectCurrent, BOOL bDocked, CPBView::DOCKERS tool )
  31. {
  32. ASSERT( ! m_bStarted );
  33. m_Tool = tool;
  34. m_bDocked = bDocked;
  35. m_ptLast = ptDrop;
  36. m_bDocking = ! bDocked;
  37. CRect rectTool;
  38. CRect rect = rectCurrent;
  39. CSize size = rectCurrent.Size();
  40. if (bDocked)
  41. {
  42. switch (tool)
  43. {
  44. case CPBView::toolbox:
  45. case CPBView::colorbox:
  46. rect.InflateRect( theApp.m_cxBorder, theApp.m_cyBorder );
  47. break;
  48. }
  49. rect.bottom += theApp.m_cyCaption;
  50. m_rectDocked = rectCurrent;
  51. m_rectFree = rect;
  52. }
  53. else
  54. {
  55. switch (tool)
  56. {
  57. case CPBView::toolbox:
  58. g_pImgToolWnd->GetWindowRect( &rectTool );
  59. rect.right = rect.left + rectTool.Width();
  60. rect.bottom = rect.top + rectTool.Height();
  61. break;
  62. case CPBView::colorbox:
  63. g_pImgColorsWnd->GetWindowRect( &rectTool );
  64. rect.right = rect.left + rectTool.Width();
  65. rect.bottom = rect.top + rectTool.Height();
  66. break;
  67. }
  68. m_rectDocked = rect;
  69. m_rectFree = rectCurrent;
  70. }
  71. CPBView* pView = (CPBView*)(((CFrameWnd*)AfxGetMainWnd())->GetActiveView());
  72. ASSERT( pView != NULL );
  73. if (pView != NULL && pView->IsKindOf( RUNTIME_CLASS( CPBView ) ))
  74. {
  75. m_ptDocking = pView->GetDockedPos( tool, size );
  76. m_bStarted = DrawFocusRect();
  77. m_rectDockingPort.SetRect( m_ptDocking.x - m_iDockingX,
  78. m_ptDocking.y - m_iDockingY,
  79. m_ptDocking.x + m_iDockingX,
  80. m_ptDocking.y + m_iDockingY );
  81. }
  82. return m_bStarted;
  83. }
  84. /***************************************************************************/
  85. BOOL CDocking::Move( CPoint ptNew, CRect& rectFrame )
  86. {
  87. Move( ptNew );
  88. rectFrame = m_bDocked? m_rectDocked: m_rectFree;
  89. return m_bDocked;
  90. }
  91. /***************************************************************************/
  92. void CDocking::Move( CPoint ptNew )
  93. {
  94. ASSERT( m_bStarted );
  95. if (DrawFocusRect())
  96. {
  97. CPoint pt = ptNew - m_ptLast;
  98. m_rectDocked.OffsetRect( pt );
  99. m_rectFree.OffsetRect( pt );
  100. pt = m_bDocked? m_rectDocked.TopLeft(): m_rectFree.TopLeft();
  101. m_bDocked = m_rectDockingPort.PtInRect( pt );
  102. m_ptLast = ptNew;
  103. DrawFocusRect();
  104. }
  105. }
  106. /***************************************************************************/
  107. BOOL CDocking::Clear( CRect* prectLast )
  108. {
  109. ASSERT( m_bStarted );
  110. DrawFocusRect();
  111. m_bStarted = FALSE;
  112. if (prectLast)
  113. *prectLast = m_bDocked? m_rectDocked: m_rectFree;
  114. if (!m_bDocked)
  115. {
  116. CPBView* pView = (CPBView*)(((CFrameWnd*)AfxGetMainWnd())->GetActiveView());
  117. if (pView != NULL && pView->IsKindOf( RUNTIME_CLASS( CPBView ) ))
  118. pView->SetFloatPos( m_Tool, m_rectFree );
  119. }
  120. return m_bDocked;
  121. }
  122. /***************************************************************************/
  123. BOOL CDocking::DrawFocusRect()
  124. {
  125. if (m_bDocking)
  126. return TRUE;
  127. BOOL bReturn = FALSE;
  128. HDC hdc = ::GetDC( NULL );
  129. if (hdc)
  130. {
  131. ::DrawFocusRect( hdc, (m_bDocked? &m_rectDocked: &m_rectFree) );
  132. ::ReleaseDC( NULL, hdc );
  133. bReturn = TRUE;
  134. }
  135. return bReturn;
  136. }
  137. /***************************************************************************/