home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / activexcontrol / basectl / framewrk / ctlocx96.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-05  |  8.6 KB  |  294 lines

  1. //=--------------------------------------------------------------------------=
  2. // CtlOcx96.H
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1995-1997 Microsoft Corporation.  All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. // implementation of the OCX 96 interfaces that don't quite fit in to the
  13. // categories covered by embedding, persistence, and ctlmisc.cpp
  14. //
  15. //
  16. #include "IPServer.H"
  17.  
  18. #include "CtrlObj.H"
  19. #include "Globals.H"
  20.  
  21.  
  22. //=--------------------------------------------------------------------------=
  23. // COleControl::GetActivationPolicy    [IPointerInactive]
  24. //=--------------------------------------------------------------------------=
  25. // returns the present activation policy for this object.  for non-subclassed
  26. // windows controls, this means we can put off in-place activation for quite
  27. // a while.
  28. //
  29. // Parameters:
  30. //    DWORD *        - [out] activation policy
  31. //
  32. // Output:
  33. //    HRESULT
  34. //
  35. // Notes:
  36. //
  37. STDMETHODIMP COleControl::GetActivationPolicy
  38. (
  39.     DWORD *pdwPolicy
  40. )
  41. {
  42.     CHECK_POINTER(pdwPolicy);
  43.  
  44.     // just get the policy in the global structure describing this control.
  45.     //
  46.     *pdwPolicy = ACTIVATIONPOLICYOFCONTROL(m_ObjectType);
  47.     return S_OK;
  48. }
  49.  
  50. //=--------------------------------------------------------------------------=
  51. // COleControl::OnInactiveMouseMove    [IPointerInactive]
  52. //=--------------------------------------------------------------------------=
  53. // indicates to an inactive oobject that the mouse pointer has moved over the
  54. // object.
  55. //
  56. // Parameters:
  57. //    LPCRECT            - [in]
  58. //    long               - [in]
  59. //    long               - [in]
  60. //    DWORD              - [in]
  61. //
  62. // Output:
  63. //    HRESULT
  64. //
  65. // Notes:
  66. //
  67. STDMETHODIMP COleControl::OnInactiveMouseMove
  68. (
  69.     LPCRECT pRectBounds,
  70.     long    x,
  71.     long    y,
  72.     DWORD   dwMouseMsg
  73. )
  74. {
  75.     // OVERRIDE: end control writers should just override this if they want
  76.     // to have a control that is never in-place active.
  77.     //
  78.     return S_OK;
  79. }
  80.     
  81. //=--------------------------------------------------------------------------=
  82. // COleControl::OnInactiveSetCursor    [IPointerInactive]
  83. //=--------------------------------------------------------------------------=
  84. // called by the container for the inactive object under the mouse pointer on
  85. // recept of a WM_SETCURSOR message.
  86. //
  87. // Parameters:
  88. //    LPCRECT            - [in]
  89. //    long               - [in]
  90. //    long               - [in]
  91. //    DWORD              - [in]
  92. //    BOOL               - [in]
  93. //
  94. // Output:
  95. //    HRESULT
  96. //
  97. // Notes:
  98. //
  99. STDMETHODIMP COleControl::OnInactiveSetCursor
  100. (
  101.     LPCRECT pRectBounds,
  102.     long    x,
  103.     long    y,
  104.     DWORD   dwMouseMsg,
  105.     BOOL    fSetAlways
  106. )
  107. {
  108.     // OVERRIDE:  just get the user to override this if they want to never
  109.     // be activated
  110.     //
  111.     return S_OK;
  112. }
  113.  
  114. //=--------------------------------------------------------------------------=
  115. // COleControl::QuickActivate    [IQuickActivate]
  116. //=--------------------------------------------------------------------------=
  117. // allows the container to activate the control.
  118. //
  119. // Parameters:
  120. //    QACONTAINER *        - [in]  info about the container
  121. //    QACONTROL *          - [out] info about the control
  122. //
  123. // Output:
  124. //    HRESULT
  125. //
  126. // Notes:
  127. //
  128. STDMETHODIMP COleControl::QuickActivate
  129. (
  130.     QACONTAINER *pContainer,
  131.     QACONTROL *pControl
  132. )
  133. {
  134.     HRESULT hr;
  135.     DWORD   dw;
  136.  
  137.     // we need these guys.
  138.     //
  139.     if (!pContainer) return E_UNEXPECTED;
  140.     if (!pControl) return E_UNEXPECTED;
  141.  
  142.     // start grabbing things from the QACONTAINER structure and apply them
  143.     // as relevant
  144.     //
  145.     if (pContainer->cbSize < sizeof(QACONTAINER)) return E_UNEXPECTED;
  146.     if (pControl->cbSize < sizeof(QACONTROL)) return E_UNEXPECTED;
  147.  
  148.     // save out the client site, of course.
  149.     //
  150.     if (pContainer->pClientSite) {
  151.         hr = SetClientSite(pContainer->pClientSite);
  152.         RETURN_ON_FAILURE(hr);
  153.     }
  154.  
  155.     // if the lcid is not LANG_NEUTRAL, score!
  156.     //
  157.     if (pContainer->lcid) {
  158.         g_lcidLocale = pContainer->lcid;
  159.         g_fHaveLocale = TRUE;
  160.     }
  161.  
  162.     // pay attention to some ambients
  163.     //
  164.     if (pContainer->dwAmbientFlags & QACONTAINER_MESSAGEREFLECT) {
  165.         m_fHostReflects = TRUE;
  166.         m_fCheckedReflecting = TRUE;
  167.     }
  168.  
  169.     // hook up some notifications.  first property notifications.
  170.     //
  171.     if (pContainer->pPropertyNotifySink) {
  172.         pContainer->pPropertyNotifySink->AddRef();
  173.         hr = m_cpPropNotify.AddSink((void *)pContainer->pPropertyNotifySink, &pControl->dwPropNotifyCookie);
  174.         if (FAILED(hr)) {
  175.             pContainer->pPropertyNotifySink->Release();
  176.             return hr;
  177.         }
  178.     }
  179.  
  180.     // then the event sink.
  181.     //
  182.     if (pContainer->pUnkEventSink) {
  183.         hr = m_cpEvents.Advise(pContainer->pUnkEventSink, &pControl->dwEventCookie);
  184.         if (FAILED(hr)) {
  185.             pContainer->pUnkEventSink->Release();
  186.             return hr;
  187.         }
  188.     }
  189.  
  190.     // finally, the advise sink.
  191.     //
  192.     if (pContainer->pAdviseSink) {
  193.         // don't need to pass the cookie back since there can only be one
  194.         // person advising at a time.
  195.         //
  196.         hr = Advise(pContainer->pAdviseSink, &dw);
  197.         RETURN_ON_FAILURE(hr);
  198.     }
  199.  
  200.     // set up a few things in the QACONTROL structure.  we're opaque by default
  201.     //
  202.     pControl->dwMiscStatus = OLEMISCFLAGSOFCONTROL(m_ObjectType);
  203.     pControl->dwViewStatus = FCONTROLISOPAQUE(m_ObjectType) ? VIEWSTATUS_OPAQUE : 0;
  204.     pControl->dwPointerActivationPolicy = ACTIVATIONPOLICYOFCONTROL(m_ObjectType);
  205.  
  206.     // that's pretty much all we're interested in.  we will, however, pass on the
  207.     // rest of the things to the end control writer and see if they want to do
  208.     // anything with them. they shouldn't touch any of the above except for the
  209.     // ambients.
  210.     //
  211.     return OnQuickActivate(pContainer, &(pControl->dwViewStatus));
  212. }
  213.  
  214. //=--------------------------------------------------------------------------=
  215. // COleControl::SetContentExtent    [IQuickActivate]
  216. //=--------------------------------------------------------------------------=
  217. // the container calls this to set the content extent of the control.
  218. //
  219. // Parameters:
  220. //    LPSIZEL            - [in] the size of the content extent
  221. //
  222. // Output:
  223. //    HRESULT            - S_OK, or E_FAIL for fixed size control
  224. //
  225. // Notes:
  226. //
  227. STDMETHODIMP COleControl::SetContentExtent
  228. (
  229.     LPSIZEL pSize
  230. )
  231. {
  232.     return SetExtent(DVASPECT_CONTENT, pSize);
  233. }
  234.  
  235. //=--------------------------------------------------------------------------=
  236. // COleControl::GetContentExtent    [IQuickActivate]
  237. //=--------------------------------------------------------------------------=
  238. // the container calls this to get the content extent of the control
  239. //
  240. // Parameters:
  241. //    LPSIZEL        - [out] returns current size
  242. //
  243. // Output:
  244. //    HRESULT
  245. //
  246. // Notes:
  247. //
  248. STDMETHODIMP COleControl::GetContentExtent
  249. (
  250.     LPSIZEL pSize
  251. )
  252. {
  253.     return GetExtent(DVASPECT_CONTENT, pSize);
  254. }
  255.  
  256. //=--------------------------------------------------------------------------=
  257. // COleControl::OnQuickActivate    [overridable]
  258. //=--------------------------------------------------------------------------=
  259. // not all the of the members of the QACONTAINER need to be consumed by the
  260. // framework, but are, at least, extremely interesting.  thus, we will pass
  261. // on the struture to the end control writer, and let them consume these.
  262. //
  263. // Parameters:
  264. //    QACONTAINER *            - [in]  contains additional information
  265. //    DWORD *                  - [out] put ViewStatus flags here.
  266. //
  267. // Output:
  268. //    HRESULT
  269. //
  270. // Notes:
  271. //    - control writers should only look at/consume:
  272. //        a. dwAmbientFlags
  273. //        b. colorFore/colorBack
  274. //        c. pFont
  275. //        d. pUndoMgr
  276. //        e. dwAppearance
  277. //        f. hpal
  278. //
  279. //    - all the others are set up the for the user by the framework.
  280. //    - control writers should set up the pdwViewStatus with flags as per
  281. //      IViewObjectEx::GetViewStatus.  if you don't know what this is or don't
  282. //      care, then don't touch.
  283. //
  284. HRESULT COleControl::OnQuickActivate
  285. (
  286.     QACONTAINER *pContainer,
  287.     DWORD       *pdwViewStatus
  288. )
  289. {
  290.     // by default, nuthin much to do!
  291.     //
  292.     return S_OK;
  293. }
  294.