home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC / src / ctltrack.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  9.5 KB  |  353 lines

  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.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef AFXCTL_CORE2_SEG
  14. #pragma code_seg(AFXCTL_CORE2_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. AFX_STATIC_DATA const int _afxResizeStyle = 
  25.     CRectTracker::resizeInside | CRectTracker::resizeOutside;
  26.  
  27. AFX_STATIC void AFXAPI _AfxOffsetTrackerRect(CRect& rect, CWnd* pWnd)
  28. {
  29.     DWORD dwStyle = pWnd->GetStyle();
  30.     DWORD dwExStyle = pWnd->GetExStyle();
  31.  
  32.     int nBorders = ((dwStyle & WS_BORDER) != 0) +
  33.         ((dwExStyle & WS_EX_CLIENTEDGE) != 0) * 2;
  34.  
  35.     int dx = -nBorders * WCE_FCTN(GetSystemMetrics)(SM_CXBORDER);
  36.     int dy = -nBorders * WCE_FCTN(GetSystemMetrics)(SM_CYBORDER);
  37.  
  38.     if (dwExStyle & WS_EX_LEFTSCROLLBAR)
  39.         dx -= WCE_FCTN(GetSystemMetrics)(SM_CXVSCROLL);
  40.  
  41.     rect.OffsetRect(dx - rect.left, dy - rect.top);
  42. }
  43.  
  44. /////////////////////////////////////////////////////////////////////////////
  45. // COleControl::CreateTracker - Creates tracker for UIActive control
  46.  
  47. void COleControl::CreateTracker(BOOL bHandles, BOOL bHatching)
  48. {
  49.     CreateTracker(bHandles, bHatching, NULL);
  50. }
  51.  
  52. void COleControl::CreateTracker(BOOL bHandles, BOOL bHatching, LPCRECT prcClip)
  53. {
  54.     ASSERT(bHandles || bHatching);
  55. #ifdef _AFXDLL
  56.     ASSERT(!m_bOpen);
  57. #endif
  58.     ASSERT(m_bUIActive);
  59.     ASSERT(m_pRectTracker == NULL);
  60.  
  61.     UINT nStyle = 0;
  62.     if (bHandles)
  63.         nStyle |= CRectTracker::resizeOutside;
  64.     if (bHatching)
  65.         nStyle |= CRectTracker::hatchedBorder;
  66.  
  67.     ASSERT(nStyle != 0);
  68.  
  69.     TRY
  70.     {
  71.         // Create the tracker.
  72.         CRect rectTmp = m_rcPos;
  73.         _AfxOffsetTrackerRect(rectTmp, this);
  74.         m_pRectTracker = new CControlRectTracker(rectTmp, nStyle);
  75.  
  76.         // Reset the window sizes, reflecting the tracker
  77.         if (prcClip != NULL)
  78.             m_pRectTracker->m_rectClip = *prcClip;
  79.         else
  80.             prcClip = m_rcPos;
  81.         OnSetObjectRects(m_rcPos, prcClip);
  82.     }
  83.     CATCH (CException, e)
  84.     {
  85.         // If anything went wrong, just continue without the tracker.
  86.         if (m_pRectTracker != NULL)
  87.         {
  88.             delete m_pRectTracker;
  89.             m_pRectTracker = NULL;
  90.         }
  91.     }
  92.     END_CATCH
  93. }
  94.  
  95. /////////////////////////////////////////////////////////////////////////////
  96. // COleControl::DestroyTracker - destroys tracker when control UIDeactivates
  97.  
  98. void COleControl::DestroyTracker()
  99. {
  100. #ifdef _AFXDLL
  101.     ASSERT(!m_bOpen);
  102. #endif
  103.     ASSERT(m_bUIActive);
  104.  
  105.     if (m_pRectTracker == NULL)
  106.         return;
  107.  
  108.     // Destroy the tracker.
  109.     CRect rectClip = m_pRectTracker->m_rectClip;
  110.     delete m_pRectTracker;
  111.     m_pRectTracker = NULL;
  112.  
  113.     // Reset the position based on no tracker present
  114.     OnSetObjectRects(m_rcPos, rectClip);
  115. }
  116.  
  117. /////////////////////////////////////////////////////////////////////////////
  118. // COleControl::OnNcPaint - handler for WM_NCPAINT message
  119.  
  120. #if !defined(_WIN32_WCE)
  121. void COleControl::OnNcPaint()
  122. {
  123. #ifdef _AFXDLL
  124.     if (m_bOpen || m_pRectTracker == NULL)
  125. #else
  126.     if (m_pRectTracker == NULL)
  127. #endif
  128.     {
  129.         Default();
  130.         return;
  131.     }
  132.  
  133.     DWORD dwStyle = GetStyle();
  134.     DWORD dwExStyle = GetExStyle();
  135.     DWORD dwScrollStyle = dwStyle & (WS_HSCROLL | WS_VSCROLL);
  136.  
  137.     // Paint scrollbars, if any.
  138.     if (dwScrollStyle != 0)
  139.         Default();
  140.  
  141.     UINT nHandleSize = m_pRectTracker->m_nHandleSize - 1;
  142.     CWindowDC dc(this);
  143.  
  144.     // Convert client coords to window coords, draw tracker, and convert back.
  145.     CRect& rectTrack = m_pRectTracker->m_rect;
  146.     int dx = rectTrack.left - nHandleSize;
  147.     int dy = rectTrack.top - nHandleSize;
  148.     rectTrack.OffsetRect(-dx, -dy);
  149.     CRect rc = rectTrack;
  150.     m_pRectTracker->Draw(&dc);
  151.     m_pRectTracker->m_rect.OffsetRect(dx, dy);
  152.  
  153.     // Draw border, if any.
  154.     _AfxDrawBorders(&dc, rc, (dwStyle & WS_BORDER),
  155.         (dwExStyle & WS_EX_CLIENTEDGE));
  156.  
  157.     if (dwScrollStyle == (WS_HSCROLL | WS_VSCROLL))
  158.     {
  159.         // Workaround for Windows bug:
  160.         // Draw the corner between the scrollbars
  161.  
  162.         int cxVScroll = WCE_FCTN(GetSystemMetrics)(SM_CXVSCROLL);
  163.  
  164.         if (dwExStyle & WS_EX_LEFTSCROLLBAR)    // Middle East Windows only
  165.             rc.right = rc.left + cxVScroll;
  166.         else
  167.             rc.left = rc.right - cxVScroll;
  168.  
  169.         rc.top = rc.bottom - WCE_FCTN(GetSystemMetrics)(SM_CYVSCROLL);
  170.  
  171.         CBrush brushGUI(GetSysColor(COLOR_3DFACE));
  172.         dc.FillRect(rc, &brushGUI);
  173.     }
  174. }
  175.  
  176. /////////////////////////////////////////////////////////////////////////////
  177. // COleControl::OnNcCalcSize - handler for WM_NCCALCSIZE message
  178.  
  179. void COleControl::OnNcCalcSize(BOOL, NCCALCSIZE_PARAMS* lpParams)
  180. {
  181.     Default();
  182.  
  183. #ifdef _AFXDLL
  184.     if (m_bOpen || m_pRectTracker == NULL)
  185. #else
  186.     if (m_pRectTracker == NULL)
  187. #endif
  188.         return;
  189.  
  190.     // Adjust client rect to make room for tracker.
  191.     UINT nHandleSize = m_pRectTracker->m_nHandleSize - 1;
  192.     ::InflateRect(lpParams->rgrc, -(int)nHandleSize, -(int)nHandleSize);
  193.  
  194.     m_pRectTracker->m_rect = m_rcPos;
  195.     _AfxOffsetTrackerRect(m_pRectTracker->m_rect, this);
  196. }
  197.  
  198. /////////////////////////////////////////////////////////////////////////////
  199. // COleControl::OnNcHitTest - handler for WM_NCHITTEST message
  200.  
  201. UINT COleControl::OnNcHitTest(CPoint point)
  202. {
  203. #ifdef _AFXDLL
  204.     if (m_bOpen || m_pRectTracker == NULL ||
  205. #else
  206.     if (m_pRectTracker == NULL ||
  207. #endif
  208.         !(m_pRectTracker->m_nStyle & _afxResizeStyle))
  209.     {
  210.         return (UINT)Default();
  211.     }
  212.  
  213.     UINT nHitCode = (UINT)Default();
  214.  
  215.     // Check for scrollbar or sizebox hit.
  216.     if ((nHitCode == HTHSCROLL) || (nHitCode == HTVSCROLL) ||
  217.         (nHitCode == HTSIZE))
  218.     {
  219.         return nHitCode;
  220.     }
  221.  
  222.     // Check for client area hit.
  223.     CPoint pointClient(point);
  224.     ScreenToClient(&pointClient);
  225.     CRect rect;
  226.     GetClientRect(rect);
  227.     if (rect.PtInRect(pointClient))
  228.         return HTCLIENT;
  229.  
  230.     // Check for border hit.
  231.     UINT nHandleSize = m_pRectTracker->m_nHandleSize - 1;
  232.     GetWindowRect(rect);
  233.     rect.InflateRect(-(int)nHandleSize, -(int)nHandleSize);
  234.     if (rect.PtInRect(point))
  235.         return HTBORDER;
  236.  
  237.     // If tracker detects a hit, return HTBORDER; otherwise HTNOWHERE.
  238.     nHitCode = m_pRectTracker->HitTest(pointClient);
  239.     return (nHitCode == CRectTracker::hitNothing) ? HTNOWHERE : HTBORDER;
  240. }
  241.  
  242. /////////////////////////////////////////////////////////////////////////////
  243. // COleControl::OnNcLButtonDown - handler for WM_NCLBUTTONDOWN message
  244.  
  245. void COleControl::OnNcLButtonDown(UINT nHitTest, CPoint point)
  246. {
  247. #ifdef _AFXDLL
  248.     if (m_bOpen || m_pRectTracker == NULL ||
  249. #else
  250.     if (m_pRectTracker == NULL ||
  251. #endif
  252.         !(m_pRectTracker->m_nStyle & _afxResizeStyle) ||
  253.         (nHitTest == HTHSCROLL) || (nHitTest == HTVSCROLL))
  254.     {
  255.         Default();
  256.         return;
  257.     }
  258.  
  259.     ScreenToClient(&point);
  260.  
  261.     // Setup a (semi-)permanent CWnd for the control's parent window
  262.     CRect rectBefore = m_pRectTracker->m_rect;
  263.     CWnd* pWndClip = CWnd::FromHandle(::GetParent(GetOuterWindow()->m_hWnd));
  264.  
  265.     // Move or resize the tracker.
  266.     BOOL bTrack = m_pRectTracker->Track(this, point, FALSE, pWndClip);
  267.  
  268.     if (bTrack)
  269.     {
  270.         ASSERT(m_pInPlaceSite);
  271.  
  272.         CRect rectAfter = m_pRectTracker->m_rect;
  273.         if (rectBefore != rectAfter)
  274.         {
  275.             // If rectangle changed, adjust the tracker's rectangle and move
  276.             // the control.
  277.             m_pRectTracker->m_rect.OffsetRect(-m_pRectTracker->m_rect.left,
  278.                 -m_pRectTracker->m_rect.top);
  279.             CWnd* pWndOuter = GetOuterWindow();
  280.             CWnd* pWndParent = pWndOuter->GetParent();
  281.             CRect rectWindow;
  282.             CRect rectParent;
  283.             pWndOuter->GetWindowRect(rectWindow);
  284.             pWndParent->GetClientRect(rectParent);
  285.             pWndParent->ClientToScreen(rectParent);
  286.          int nBorderWidth = GetBorderStyle()*GetSystemMetrics( SM_CXBORDER );
  287.          int nBorderHeight = GetBorderStyle()*GetSystemMetrics( SM_CYBORDER );
  288.             UINT nHandleSize = m_pRectTracker->m_nHandleSize - 1;
  289.             rectAfter.OffsetRect(rectWindow.left - rectParent.left +
  290.                 nHandleSize + nBorderWidth, rectWindow.top - rectParent.top + 
  291.             nHandleSize + nBorderHeight);
  292.  
  293.             // Update the control's extents.
  294.             SIZEL szlPixels;
  295.             SIZEL szlHimetric;
  296.             szlPixels.cx = (long)rectAfter.Width();
  297.             szlPixels.cy = (long)rectAfter.Height();
  298.             _AfxXformSizeInPixelsToHimetric(NULL, &szlPixels, &szlHimetric);
  299.             if ((m_cxExtent != szlHimetric.cx) ||
  300.                 (m_cyExtent != szlHimetric.cy))
  301.             {
  302.                 m_cxExtent = szlHimetric.cx;
  303.                 m_cyExtent = szlHimetric.cy;
  304.                 SetModifiedFlag();
  305.             }
  306.  
  307.             // Move/resize the control's window.
  308.             m_pInPlaceSite->OnPosRectChange(rectAfter);
  309.         }
  310.     }
  311. }
  312. #endif // _WIN32_WCE
  313.  
  314. #if !defined(_WIN32_WCE_NO_CURSOR)
  315. /////////////////////////////////////////////////////////////////////////////
  316. // COleControl::OnSetCursor - handler for WM_SETCURSOR message
  317.  
  318. BOOL COleControl::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT)
  319. {
  320. #ifdef _AFXDLL
  321.     if (m_bOpen || m_pRectTracker == NULL ||
  322. #else
  323.     if (m_pRectTracker == NULL ||
  324. #endif
  325.         !(m_pRectTracker->m_nStyle & _afxResizeStyle))
  326.     {
  327.         return (BOOL)Default();
  328.     }
  329.  
  330.     if ((nHitTest == HTCLIENT) || (nHitTest == HTHSCROLL) ||
  331.         (nHitTest == HTVSCROLL) || (nHitTest == HTSIZE))
  332.     {
  333.         // In client area: use default cursor or arrow.
  334.         if (!Default())
  335.             ::SetCursor(::WCE_FCTN(LoadCursor)(NULL, IDC_ARROW));
  336.     }
  337.     else
  338.     {
  339.         // In non-client area: use tracker-supplied cursor.
  340.         m_pRectTracker->SetCursor(pWnd, HTCLIENT);
  341.     }
  342.  
  343.     return TRUE;
  344. }
  345. #endif // _WIN32_WCE_NO_CURSOR
  346.  
  347. /////////////////////////////////////////////////////////////////////////////
  348. // Force any extra compiler-generated code into AFX_INIT_SEG
  349.  
  350. #ifdef AFX_INIT_SEG
  351. #pragma code_seg(AFX_INIT_SEG)
  352. #endif
  353.