olebar.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #include "stdafx.h"
  11. #ifdef AFX_OLE4_SEG
  12. #pragma code_seg(AFX_OLE4_SEG)
  13. #endif
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. #define new DEBUG_NEW
  19. /////////////////////////////////////////////////////////////////////////////
  20. // COleResizeBar
  21. COleResizeBar::COleResizeBar()
  22. {
  23. // setup the state flags to do resize handles outside with hatched border
  24. m_tracker.m_nStyle =
  25. CRectTracker::hatchedBorder|CRectTracker::resizeOutside|
  26. CRectTracker::solidLine;
  27. // the actual rectangle is updated in COleResizeBar::OnSize
  28. }
  29. COleResizeBar::~COleResizeBar()
  30. {
  31. }
  32. BOOL COleResizeBar::Create(CWnd* pParentWnd, DWORD dwStyle, UINT nID)
  33. {
  34. ASSERT_VALID(this);
  35. if (pParentWnd != NULL)
  36. ASSERT_VALID(pParentWnd); // must have a parent
  37. // force WS_CLIPSIBLINGS (avoids SetWindowPos bugs)
  38. dwStyle |= WS_CLIPSIBLINGS;
  39. VERIFY(AfxDeferRegisterClass(AFX_WNDCONTROLBAR_REG));
  40. // create the HWND
  41. CRect rect;
  42. rect.SetRectEmpty();
  43. // Note: Parent must resize itself for control bar to be resized
  44. return CWnd::Create(AFX_WNDCONTROLBAR, NULL, dwStyle, rect, pParentWnd, nID);
  45. }
  46. /////////////////////////////////////////////////////////////////////////////
  47. // COleResizeBar message handling
  48. BEGIN_MESSAGE_MAP(COleResizeBar, CControlBar)
  49. //{{AFX_MSG_MAP(COleResizeBar)
  50. ON_WM_ERASEBKGND()
  51. ON_WM_PAINT()
  52. ON_WM_SIZE()
  53. ON_WM_SETCURSOR()
  54. ON_WM_LBUTTONDOWN()
  55. ON_MESSAGE(WM_SIZEPARENT, OnSizeParent)
  56. //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58. BOOL COleResizeBar::OnEraseBkgnd(CDC*)
  59. {
  60. return TRUE; // no erasing necessary
  61. }
  62. void COleResizeBar::OnPaint()
  63. {
  64. CPaintDC dc(this);
  65. // always use the same brush origin
  66. CRect rect;
  67. GetWindowRect(&rect);
  68. dc.SetBrushOrg(rect.left & 7, rect.top & 7);
  69. // draw it
  70. m_tracker.Draw(&dc);
  71. }
  72. void COleResizeBar::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
  73. {
  74. GetClientRect(&m_tracker.m_rect);
  75. int nHandleSize = m_tracker.m_nHandleSize;
  76. m_tracker.m_rect.InflateRect(-nHandleSize, -nHandleSize);
  77. }
  78. BOOL COleResizeBar::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  79. {
  80. // hit-test the tracker -- we only care about hits on handles
  81. CPoint point;
  82. ::GetCursorPos(&point);
  83. ScreenToClient(&point);
  84. int hit = m_tracker.HitTest(point);
  85. if (hit < 0)
  86. return CControlBar::OnSetCursor(pWnd, nHitTest, message);
  87. // let the tracker handle setting the cursor
  88. return m_tracker.SetCursor(pWnd, nHitTest);
  89. }
  90. void COleResizeBar::OnLButtonDown(UINT /*nFlags*/, CPoint point)
  91. {
  92. // track to parent of the parent
  93. CWnd* pFrameWnd = GetParentFrame();
  94. ASSERT_VALID(pFrameWnd);
  95. CWnd* pParent = pFrameWnd->GetParent();
  96. pFrameWnd->UpdateWindow(); // update ourselves
  97. // limit tracking to parent client rectangle
  98. if (pParent != NULL)
  99. {
  100. pParent->UpdateWindow(); // always update before tracking
  101. // clip cursor to parent window
  102. CRect rect;
  103. pParent->GetClientRect(&rect);
  104. pParent->ClientToScreen(&rect);
  105. ::ClipCursor(&rect);
  106. }
  107. // save the rect, track, then restore
  108. CRect rectSave = m_tracker.m_rect;
  109. BOOL bNotify = m_tracker.Track(this, point, FALSE, pParent);
  110. CRect rectNew = m_tracker.m_rect;
  111. m_tracker.m_rect = rectSave;
  112. // allow full mouse movement again
  113. ::ClipCursor(NULL);
  114. // notify owner window if tracker changed
  115. if (bNotify)
  116. {
  117. CWnd* pOwner = GetOwner();
  118. ASSERT_VALID(pOwner);
  119. // convert relative to parent coordinates
  120. ClientToScreen(&rectNew);
  121. pOwner->ScreenToClient(&rectNew);
  122. // send notification to owner
  123. pOwner->SendMessage(WM_SIZECHILD, (WPARAM)_AfxGetDlgCtrlID(m_hWnd),
  124. (LPARAM)(LPCRECT)&rectNew);
  125. }
  126. }
  127. LRESULT COleResizeBar::OnSizeParent(WPARAM, LPARAM lParam)
  128. {
  129. AFX_SIZEPARENTPARAMS* lpLayout = (AFX_SIZEPARENTPARAMS*)lParam;
  130. // only resize the window if doing layout and not just rect query
  131. if (lpLayout->hDWP != NULL)
  132. AfxRepositionWindow(lpLayout, m_hWnd, &lpLayout->rect);
  133. // always adjust the rectangle after the resize
  134. int nHandleSize = m_tracker.m_nHandleSize;
  135. ::InflateRect(&lpLayout->rect, -nHandleSize, -nHandleSize);
  136. return 0;
  137. }
  138. void COleResizeBar::OnUpdateCmdUI(CFrameWnd* /*pTarget*/,
  139. BOOL /*bDisableIfNoHndler*/)
  140. {
  141. // just do nothing
  142. }
  143. #ifdef AFX_INIT_SEG
  144. #pragma code_seg(AFX_INIT_SEG)
  145. #endif
  146. IMPLEMENT_DYNAMIC(COleResizeBar, CControlBar)
  147. /////////////////////////////////////////////////////////////////////////////