home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC / src / ctlnownd.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  11.6 KB  |  480 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_CORE1_SEG
  14. #pragma code_seg(AFXCTL_CORE1_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. // CWindowlessDC - used by COleControl::GetDC and COleControl::ReleaseDC
  26.  
  27. class CWindowlessDC : public CDC
  28. {
  29.     DECLARE_DYNAMIC(CWindowlessDC)
  30. public:
  31.     CWindowlessDC(HDC hDC, CPoint& pointOrigin);
  32.     HDC Detach();
  33. protected:
  34.     CPoint m_pointOrigin;
  35. };
  36.  
  37. IMPLEMENT_DYNAMIC(CWindowlessDC, CDC)
  38.  
  39. CWindowlessDC::CWindowlessDC(HDC hDC, CPoint& pointOrigin)
  40. {
  41.     m_hDC = m_hAttribDC = hDC;
  42.     m_pointOrigin =  GetViewportOrg();
  43. #if !defined(_WIN32_WCE_NO_GDITRANSFORM)
  44.     SetViewportOrg(m_pointOrigin + pointOrigin);
  45. #endif // _WIN32_WCE_NO_GDITRANSFORM
  46. }
  47.  
  48. HDC CWindowlessDC::Detach()
  49. {
  50. #if !defined(_WIN32_WCE_NO_GDITRANSFORM)
  51.     SetViewportOrg(m_pointOrigin);
  52. #endif // _WIN32_WCE_NO_GDITRANSFORM
  53.     HDC hDC = m_hDC;
  54.     m_hDC = m_hAttribDC = NULL;
  55.     return hDC;
  56. }
  57.  
  58. /////////////////////////////////////////////////////////////////////////////
  59. // Overridables used with the various windowless interfaces
  60.  
  61. void COleControl::GetClientOffset(long* pdxOffset, long* pdyOffset) const
  62. {
  63.     int nOffset = (m_sBorderStyle == 1) + (2 * (m_sAppearance == 1));
  64.  
  65.     if (nOffset > 0)
  66.     {
  67.         *pdxOffset = nOffset * WCE_FCTN(GetSystemMetrics)(SM_CXBORDER);
  68.         *pdyOffset = nOffset * WCE_FCTN(GetSystemMetrics)(SM_CYBORDER);
  69.     }
  70.     else
  71.     {
  72.         *pdxOffset = *pdyOffset = 0;
  73.     }
  74. }
  75.  
  76. UINT COleControl::ParentToClient(LPCRECT lprcBounds, LPPOINT pPoint,
  77.     BOOL bHitTest) const
  78. {
  79.     long dxOffset;
  80.     long dyOffset;
  81.     GetClientOffset(&dxOffset, &dyOffset);
  82.  
  83.     UINT nHitTest = HTNOWHERE;
  84.  
  85.     if (bHitTest && ::PtInRect(lprcBounds, *pPoint))
  86.     {
  87.         if (dxOffset > 0)
  88.         {
  89.             CRect rectClient(lprcBounds);
  90.             rectClient.InflateRect(-dxOffset, -dyOffset);
  91.             nHitTest = rectClient.PtInRect(*pPoint) ? HTCLIENT : HTBORDER;
  92.         }
  93.         else
  94.         {
  95.             nHitTest = HTCLIENT;
  96.         }
  97.     }
  98.  
  99.     pPoint->x -= lprcBounds->left + dxOffset;
  100.     pPoint->y -= lprcBounds->top  + dyOffset;
  101.  
  102.     return nHitTest;
  103. }
  104.  
  105. void COleControl::ClientToParent(LPCRECT lprcBounds, LPPOINT pPoint) const
  106. {
  107.     long dxOffset;
  108.     long dyOffset;
  109.     GetClientOffset(&dxOffset, &dyOffset);
  110.     pPoint->x += lprcBounds->left + dxOffset;
  111.     pPoint->y += lprcBounds->top  + dyOffset;
  112. }
  113.  
  114. /////////////////////////////////////////////////////////////////////////////
  115. // Overridables for IPointerInactive methods
  116.  
  117. DWORD COleControl::GetActivationPolicy()
  118. {
  119.     return 0;
  120. }
  121.  
  122. #if !defined(_WIN32_WCE_NO_CURSOR) 
  123. BOOL COleControl::OnInactiveSetCursor(LPCRECT lprcBounds, long x, long y,
  124.     DWORD dwMouseMsg, BOOL bSetAlways)
  125. {
  126.     CPoint point(x, y);
  127.     UINT nHitTest = ParentToClient(lprcBounds, &point, TRUE);
  128.  
  129.     LRESULT lResult = 0;
  130.     OnWndMsg(WM_SETCURSOR, nHitTest, dwMouseMsg, &lResult);
  131.  
  132.     if (bSetAlways && ! lResult)
  133.         ::SetCursor(::WCE_FCTN(LoadCursor)(NULL, IDC_ARROW));
  134.  
  135.     return bSetAlways || lResult;
  136. }
  137. #endif // _WIN32_WCE_NO_CURSOR
  138.  
  139. void COleControl::OnInactiveMouseMove(LPCRECT lprcBounds, long x, long y,
  140.     DWORD dwKeyState)
  141. {
  142.     CPoint point(x, y);
  143.     ParentToClient(lprcBounds, &point);
  144.     OnWndMsg(WM_MOUSEMOVE, dwKeyState, MAKELONG(point.x, point.y), NULL);
  145. }
  146.  
  147. /////////////////////////////////////////////////////////////////////////////
  148. // COleControl::XPointerInactive
  149.  
  150. STDMETHODIMP_(ULONG) COleControl::XPointerInactive::AddRef()
  151. {
  152.     METHOD_PROLOGUE_EX_(COleControl, PointerInactive)
  153.     return (ULONG)pThis->ExternalAddRef();
  154. }
  155.  
  156. STDMETHODIMP_(ULONG) COleControl::XPointerInactive::Release()
  157. {
  158.     METHOD_PROLOGUE_EX_(COleControl, PointerInactive)
  159.     return (ULONG)pThis->ExternalRelease();
  160. }
  161.  
  162. STDMETHODIMP COleControl::XPointerInactive::QueryInterface(
  163.     REFIID iid, LPVOID* ppvObj)
  164. {
  165.     METHOD_PROLOGUE_EX_(COleControl, PointerInactive)
  166.     return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
  167. }
  168.  
  169. STDMETHODIMP COleControl::XPointerInactive::GetActivationPolicy(
  170.    DWORD* pdwPolicy)
  171. {
  172.     METHOD_PROLOGUE_EX_(COleControl, PointerInactive)
  173.     *pdwPolicy = pThis->GetActivationPolicy();
  174.     return S_OK;
  175. }
  176.  
  177. STDMETHODIMP COleControl::XPointerInactive::OnInactiveSetCursor(
  178.     LPCRECT lprcBounds, long x, long y, DWORD dwMouseMsg, BOOL bSetAlways)
  179. {
  180.     METHOD_PROLOGUE_EX_(COleControl, PointerInactive)
  181. #if !defined(_WIN32_WCE_NO_CURSOR) 
  182.     return pThis->OnInactiveSetCursor(lprcBounds, x, y, dwMouseMsg, bSetAlways) ?
  183.         S_OK : S_FALSE;
  184. #else // _WIN32_WCE_NO_CURSOR
  185.     return S_OK;
  186. #endif // _WIN32_WCE_NO_CURSOR
  187. }
  188.  
  189. STDMETHODIMP COleControl::XPointerInactive::OnInactiveMouseMove(
  190.     LPCRECT lprcBounds, long x, long y, DWORD dwKeyState)
  191. {
  192.     METHOD_PROLOGUE_EX_(COleControl, PointerInactive)
  193.     pThis->OnInactiveMouseMove(lprcBounds, x, y, dwKeyState);
  194.     return S_OK;
  195. }
  196.  
  197. /////////////////////////////////////////////////////////////////////////////
  198. // Overridables for IOleInPlaceObjectWindowless methods
  199.  
  200. BOOL COleControl::OnWindowlessMessage(UINT msg, WPARAM wParam, LPARAM lParam,
  201.     LRESULT* plResult)
  202. {
  203.     if ((msg >= WM_MOUSEFIRST && msg <= WM_MOUSELAST) || WCE_IF(0,(msg == WM_CONTEXTMENU)))
  204.     {
  205.         CPoint point(LOWORD(lParam), HIWORD(lParam));
  206.         ParentToClient(m_rcPos, &point, FALSE);
  207.         lParam = MAKELONG(point.x, point.y);
  208.     }
  209.  
  210.     return OnWndMsg(msg, wParam, lParam, plResult);
  211. }
  212.  
  213. IDropTarget* COleControl::GetWindowlessDropTarget()
  214. {
  215.     return NULL;
  216. }
  217.  
  218. /////////////////////////////////////////////////////////////////////////////
  219. // COleControl::XOleInPlaceObject (IOleInPlaceObjectWindowless methods)
  220.  
  221. STDMETHODIMP COleControl::XOleInPlaceObject::OnWindowMessage(UINT msg,
  222.     WPARAM wParam, LPARAM lParam, LRESULT* plResult)
  223. {
  224.     METHOD_PROLOGUE_EX_(COleControl, OleInPlaceObject)
  225.     return pThis->OnWindowlessMessage(msg, wParam, lParam, plResult) ?
  226.         S_OK : S_FALSE;
  227. }
  228.  
  229. STDMETHODIMP COleControl::XOleInPlaceObject::GetDropTarget(
  230.     IDropTarget** ppDropTarget)
  231. {
  232.     METHOD_PROLOGUE_EX_(COleControl, OleInPlaceObject)
  233.  
  234.     *ppDropTarget = pThis->GetWindowlessDropTarget();
  235.     return (*ppDropTarget != NULL) ? S_OK : E_NOTIMPL;
  236. }
  237.  
  238. /////////////////////////////////////////////////////////////////////////////
  239. // Cover functions for IOleInPlaceSiteWindowless methods
  240.  
  241. CWnd* COleControl::SetCapture()
  242. {
  243.     ASSERT((m_hWnd != NULL) || (m_bInPlaceSiteWndless && m_bInPlaceActive));
  244.  
  245.     if (m_bInPlaceSiteWndless && m_bInPlaceActive)
  246.     {
  247.         CWnd* pWndPrev = GetCapture();
  248.         m_pInPlaceSiteWndless->SetCapture(TRUE);
  249.         return pWndPrev;
  250.     }
  251.     else
  252.     {
  253.         return CWnd::SetCapture();
  254.     }
  255. }
  256.  
  257. BOOL COleControl::ReleaseCapture()
  258. {
  259.     ASSERT((m_hWnd != NULL) || (m_bInPlaceSiteWndless && m_bInPlaceActive));
  260.  
  261.     if (m_bInPlaceSiteWndless && m_bInPlaceActive)
  262.         return (m_pInPlaceSiteWndless->SetCapture(FALSE) == S_OK);
  263.     else
  264.         return ::ReleaseCapture();
  265. }
  266.  
  267. CWnd* COleControl::GetCapture()
  268. {
  269.     ASSERT((m_hWnd != NULL) || (m_bInPlaceSiteWndless && m_bInPlaceActive));
  270.  
  271.     if (m_bInPlaceSiteWndless && m_bInPlaceActive)
  272.     {
  273.         return (m_pInPlaceSiteWndless->GetCapture() == S_OK) ?
  274.             this : NULL;
  275.     }
  276.     else
  277.     {
  278.         return CWnd::GetCapture();
  279.     }
  280. }
  281.  
  282. CWnd* COleControl::SetFocus()
  283. {
  284.     ASSERT((m_hWnd != NULL) || (m_bInPlaceSiteWndless && m_bInPlaceActive));
  285.  
  286.     if (m_bInPlaceSiteWndless && m_bInPlaceActive)
  287.     {
  288.         CWnd* pWndPrev = GetFocus();
  289.         m_pInPlaceSiteWndless->SetFocus(TRUE);
  290.         return pWndPrev;
  291.     }
  292.     else
  293.     {
  294.         return CWnd::SetFocus();
  295.     }
  296. }
  297.  
  298. CWnd* COleControl::GetFocus()
  299. {
  300.     ASSERT((m_hWnd != NULL) || (m_bInPlaceSiteWndless && m_bInPlaceActive));
  301.  
  302.     if (m_bInPlaceSiteWndless && m_bInPlaceActive)
  303.     {
  304.         return (m_pInPlaceSiteWndless->GetFocus() == S_OK) ?
  305.             this : NULL;
  306.     }
  307.     else
  308.     {
  309.         return CWnd::GetFocus();
  310.     }
  311. }
  312.  
  313. CDC* COleControl::GetDC(LPCRECT lprcRect, DWORD dwFlags)
  314. {
  315.     ASSERT((m_hWnd != NULL) || (m_bInPlaceSiteWndless && m_bInPlaceActive));
  316.  
  317.     if (m_bInPlaceSiteWndless && m_bInPlaceActive)
  318.     {
  319.         CPoint point(0, 0);
  320.         ClientToParent(m_rcPos, &point);
  321.         CRect rect;
  322.         if (lprcRect != NULL)
  323.         {
  324.             rect.CopyRect(lprcRect);
  325.             rect.OffsetRect(point);
  326.             lprcRect = ▭
  327.         }
  328.  
  329.         HDC hDC;
  330.         if (FAILED(m_pInPlaceSiteWndless->GetDC(lprcRect, dwFlags, &hDC)))
  331.             return NULL;
  332.  
  333.         CDC* pDC = NULL;
  334.         TRY
  335.         {
  336.             pDC = new CWindowlessDC(hDC, point);
  337.         }
  338.         CATCH_ALL(e)
  339.         {
  340.             m_pInPlaceSiteWndless->ReleaseDC(hDC);
  341.         }
  342.         END_CATCH_ALL
  343.  
  344.         return pDC;
  345.     }
  346.     else
  347.     {
  348.         // NOTE: can only use non-default values for these parameters when
  349.         // activated windowless.
  350.         ASSERT(lprcRect == NULL);
  351.         ASSERT(dwFlags == OLEDC_PAINTBKGND);
  352.         return CWnd::GetDC();
  353.     }
  354. }
  355.  
  356. BOOL COleControl::ReleaseDC(CDC* pDC)
  357. {
  358.     ASSERT((m_hWnd != NULL) || (m_bInPlaceSiteWndless && m_bInPlaceActive));
  359.  
  360.     if (m_bInPlaceSiteWndless && m_bInPlaceActive)
  361.     {
  362.         CWindowlessDC* pWindowlessDC = DYNAMIC_DOWNCAST(CWindowlessDC, pDC);
  363.         ASSERT(pWindowlessDC != NULL);
  364.         HDC hDC = pWindowlessDC->Detach();
  365.         delete pWindowlessDC;
  366.         return m_pInPlaceSiteWndless->ReleaseDC(hDC);
  367.     }
  368.     else
  369.     {
  370.         return CWnd::ReleaseDC(pDC);
  371.     }
  372. }
  373.  
  374. void COleControl::InvalidateRgn(CRgn* pRgn, BOOL bErase)
  375. {
  376.     ASSERT((m_hWnd != NULL) || (m_bInPlaceSiteWndless && m_bInPlaceActive));
  377.  
  378.     if (m_bInPlaceSiteWndless && m_bInPlaceActive)
  379.     {
  380.         CRgn rgn;
  381.         if (pRgn != NULL)
  382.         {
  383.             CPoint point(0, 0);
  384.             ClientToParent(m_rcPos, &point);
  385.             rgn.CopyRgn(pRgn);
  386.             rgn.OffsetRgn(point);
  387.         }
  388.         m_pInPlaceSiteWndless->InvalidateRgn(rgn, bErase);
  389.     }
  390.     else
  391.     {
  392.         CWnd::InvalidateRgn(pRgn, bErase);
  393.     }
  394. }
  395.  
  396. void COleControl::ScrollWindow(int xAmount, int yAmount, LPCRECT lpRect,
  397.     LPCRECT lpClipRect)
  398. {
  399.     ASSERT((m_hWnd != NULL) || (m_bInPlaceSiteWndless && m_bInPlaceActive));
  400.  
  401.     if (m_bInPlaceSiteWndless && m_bInPlaceActive)
  402.     {
  403.         if (lpRect != NULL || lpClipRect != NULL)
  404.         {
  405.             CPoint point(0, 0);
  406.             ClientToParent(m_rcPos, &point);
  407.             CRect rect;
  408.             CRect rectClip;
  409.             if (lpRect != NULL)
  410.             {
  411.                 rect.CopyRect(lpRect);
  412.                 rect.OffsetRect(point);
  413.                 lpRect = ▭
  414.             }
  415.             if (lpClipRect != NULL)
  416.             {
  417.                 rectClip.CopyRect(lpClipRect);
  418.                 rectClip.OffsetRect(point);
  419.                 lpClipRect = &rectClip;
  420.             }
  421.         }
  422.  
  423.         m_pInPlaceSiteWndless->ScrollRect(xAmount, yAmount, lpRect, lpClipRect);
  424.     }
  425.     else
  426.     {
  427.         CWnd::ScrollWindow(xAmount, yAmount, lpRect, lpClipRect);
  428.     }
  429. }
  430.  
  431. BOOL COleControl::ClipCaretRect(LPRECT lpRect)
  432. {
  433.     BOOL bNotEmpty = FALSE;
  434.  
  435.     if (m_bInPlaceSiteWndless && m_bInPlaceActive)
  436.     {
  437.         CPoint point(0, 0);
  438.         ClientToParent(m_rcPos, &point);
  439.         CRect rect(lpRect);
  440.         rect.OffsetRect(point);
  441.         bNotEmpty = (m_pInPlaceSiteWndless->AdjustRect(rect) == S_OK);
  442.         rect.OffsetRect(-point.x, -point.y);
  443.     }
  444.  
  445.     return bNotEmpty;
  446. }
  447.  
  448. /////////////////////////////////////////////////////////////////////////////
  449. // Helper functions for windowless controls
  450.  
  451. void COleControl::GetClientRect(LPRECT lpRect) const
  452. {
  453.     ASSERT((m_hWnd != NULL) || (m_bInPlaceSiteWndless && m_bInPlaceActive));
  454.  
  455.     if (m_bInPlaceSiteWndless && m_bInPlaceActive)
  456.     {
  457.         long dxOffset;
  458.         long dyOffset;
  459.         GetClientOffset(&dxOffset, &dyOffset);
  460.         ::CopyRect(lpRect, m_rcPos);
  461.         ::InflateRect(lpRect, -dxOffset, -dyOffset);
  462.  
  463. #ifdef _DEBUG
  464.         CPoint point(0, 0);
  465.         ClientToParent(m_rcPos, &point);
  466.         ASSERT(point.x == lpRect->left && point.y == lpRect->top);
  467. #endif
  468.  
  469.         ::OffsetRect(lpRect, -lpRect->left, -lpRect->top);
  470.     }
  471.     else if (m_hWnd != NULL)
  472.     {
  473.         CWnd::GetClientRect(lpRect);
  474.     }
  475.     else
  476.     {
  477.         ::SetRectEmpty(lpRect);
  478.     }
  479. }
  480.