home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / VC / MFC / SRC / OLEBAR.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-30  |  4.9 KB  |  197 lines

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