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 / todosvr / iodocvw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-05  |  12.6 KB  |  416 lines

  1. //=--------------------------------------------------------------------------=
  2. // IODocVw.Cpp
  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 IOleDocumentView interface for CDocumentObject
  13. //
  14. #include "CDocObj.H"
  15.  
  16. // for ASSERT and FAIL
  17. //
  18. SZTHISFILE
  19.  
  20. //=--------------------------------------------------------------------------=
  21. // CDocumentObject::SetInPlaceSite    [IOleDocument]
  22. //=--------------------------------------------------------------------------=
  23. // associates a view site with this view
  24. //
  25. // Parameters:
  26. //    IOleInPlaceSite *   - [in] pointer to container's view site object
  27. //
  28. // Output:
  29. //    HRESULT             - S_OK, E_FAIL
  30. //
  31. // Notes: 
  32. //
  33. STDMETHODIMP CDocumentObject::SetInPlaceSite(IOleInPlaceSite* pIPSite)
  34. {
  35.     TRACE("\nCDocumentObject::SetInPlaceSite");
  36.  
  37.     // if view already has an associated site,
  38.     //    call IOleInPlaceObject::InPlaceDeactivate and release the site
  39.     if (m_pViewSite)
  40.     {
  41.         InPlaceDeactivate();
  42.         QUICK_RELEASE(m_pViewSite);
  43.     }
  44.  
  45.     // remember the new view site
  46.     m_pViewSite = pIPSite;
  47.     ADDREF_OBJECT(m_pViewSite);
  48.  
  49.     return S_OK;
  50. }
  51.  
  52. //=--------------------------------------------------------------------------=
  53. // CDocumentObject::GetInPlaceSite    [IOleDocument]
  54. //=--------------------------------------------------------------------------=
  55. // retrieves the view site associated with this view
  56. //
  57. // Parameters:
  58. //    IOleInPlaceSite**   - [out] location to return pointer to container's 
  59. //                                view site object
  60. //
  61. // Output:
  62. //    HRESULT             - S_OK, E_FAIL
  63. //
  64. // Notes: 
  65. //
  66. STDMETHODIMP CDocumentObject::GetInPlaceSite(IOleInPlaceSite** ppIPSite)
  67. {
  68.     TRACE("\nCDocumentObject::GetInPlaceSite");
  69.  
  70.     ADDREF_OBJECT(m_pViewSite);
  71.     *ppIPSite = m_pViewSite;
  72.     return S_OK;
  73. }
  74.  
  75. //=--------------------------------------------------------------------------=
  76. // CDocumentObject::GetDocument    [IOleDocument]
  77. //=--------------------------------------------------------------------------=
  78. // retrieves the document associated with this view
  79. //
  80. // Parameters:
  81. //    IUnknown**   - [out] location to return pointer to our object
  82. //
  83. // Output:
  84. //    HRESULT      - S_OK
  85. //
  86. // Notes: 
  87. //
  88. STDMETHODIMP CDocumentObject::GetDocument(IUnknown** ppunk)
  89. {
  90.     TRACE("\nCDocumentObject::GetDocument");
  91.     return InternalQueryInterface(IID_IUnknown, (void**)ppunk);
  92. }
  93.  
  94. //=--------------------------------------------------------------------------=
  95. // CDocumentObject::SetRect    [IOleDocument]
  96. //=--------------------------------------------------------------------------=
  97. // sets the coordinates of the view port for this view
  98. //
  99. // Parameters:
  100. //    LPRECT   - [in] coordinates of viewpoint in client coordinates of the
  101. //                    view window
  102. //
  103. // Output:
  104. //    HRESULT  - S_OK, E_FAIL
  105. //
  106. // Notes: 
  107. //
  108. STDMETHODIMP CDocumentObject::SetRect(LPRECT prcView)
  109. {
  110.     TRACE("\nCDocumentObject::SetRect");
  111.  
  112.     // SetObjectRects expects object extent to be set, but
  113.     // DocObjects ignore SetExtent. Set m_Size to the size 
  114.     // specified by the view.
  115.     m_Size.cx = prcView->right - prcView->left;
  116.     m_Size.cy = prcView->bottom - prcView->top;
  117.  
  118.     HRESULT hr = SetObjectRects(prcView, prcView);
  119.     if (SUCCEEDED(hr))
  120.     {
  121.         // SetObjectRects moves but does not resize window so we will 
  122.         // do that here...
  123.         if (m_hwnd) 
  124.             SetWindowPos(m_hwnd, 0, 0, 0, m_Size.cx, m_Size.cy,
  125.                          SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
  126.     }
  127.     return hr;
  128. }
  129.  
  130. //=--------------------------------------------------------------------------=
  131. // CDocumentObject::GetRect    [IOleDocument]
  132. //=--------------------------------------------------------------------------=
  133. // retrieves the coordinates of the view port for this view
  134. //
  135. // Parameters:
  136. //    LPRECT   - [out] location to put the coordinates of the viewpoint in 
  137. //                     client coordinates of the view window
  138. //
  139. // Output:
  140. //    HRESULT  - S_OK, E_UNEXPECTED
  141. //
  142. // Notes: 
  143. //
  144. STDMETHODIMP CDocumentObject::GetRect(LPRECT prcView)
  145. {
  146.     TRACE("\nCDocumentObject::GetRect");
  147.     if (prcView)
  148.     {
  149.         prcView->top    = 0;
  150.         prcView->left   = 0;
  151.         prcView->bottom = m_Size.cy;
  152.         prcView->right  = m_Size.cx;
  153.         return S_OK;
  154.     }
  155.     else
  156.         return E_UNEXPECTED;
  157. }
  158.  
  159. //=--------------------------------------------------------------------------=
  160. // CDocumentObject::SetRectComplex    [IOleDocument]
  161. //=--------------------------------------------------------------------------=
  162. // sets the coordinates of the view port, scrollbars, and sizebox for this view
  163. //
  164. // Parameters:
  165. //    LPRECT   - [in] coordinates of viewpoint in client coordinates of the
  166. //                    view window
  167. //    LPRECT   - [in] coordinates of horizontal scrollbar in client 
  168. //                    coordinates of the view window
  169. //    LPRECT   - [in] coordinates of vertical scrollbar in client coordinates 
  170. //                    of the view window
  171. //    LPRECT   - [in] coordinates of sizebox in client coordinates of the
  172. //                    view window
  173. //
  174. // Output:
  175. //    HRESULT  - S_OK, E_FAIL, E_NOTIMPL
  176. //
  177. // Notes: 
  178. //      This implementation does not support complex rectangles!
  179. //
  180. STDMETHODIMP CDocumentObject::SetRectComplex(LPRECT prcView, LPRECT prcHScroll,
  181.                                              LPRECT prcVScroll, LPRECT prcSizeBox)
  182. {
  183.     TRACE("\nCDocumentObject::SetRectComplex");
  184.     return E_NOTIMPL;
  185. }
  186.  
  187. //=--------------------------------------------------------------------------=
  188. // CDocumentObject::Show    [IOleDocument]
  189. //=--------------------------------------------------------------------------=
  190. // instructs the view to in-place activate or in-place deactivate itself
  191. //
  192. // Parameters:
  193. //    BOOL     - [in] whether to activate or deactivate
  194. //
  195. // Output:
  196. //    HRESULT  - S_OK, E_OUTOFMEMORY, E_FAIL, E_UNEXPECTED
  197. //
  198. // Notes: 
  199. //
  200. STDMETHODIMP CDocumentObject::Show(BOOL fShow)
  201. {
  202.     TRACE("\nEnter CDocumentObject::Show");
  203.  
  204.     HRESULT hr;
  205.     if (fShow)
  206.     {
  207.         // inplace activate without UI activate & show the view window
  208.         hr = ActivateAsDocObject(OLEIVERB_INPLACEACTIVATE);
  209.     }
  210.     else
  211.     {
  212.         // UI deactivate
  213.         hr = UIActivate(FALSE);
  214.  
  215.         // hide the view window
  216.         SetInPlaceVisible(FALSE);
  217.     }
  218.  
  219.     TRACE("\nLeave CDocumentObject::Show");
  220.     return hr;
  221. }
  222.  
  223. //=--------------------------------------------------------------------------=
  224. // CDocumentObject::UIActivate    [IOleDocument]
  225. //=--------------------------------------------------------------------------=
  226. // instructs the view to UI activate or deactivate itself
  227. //
  228. // Parameters:
  229. //    BOOL     - [in] whether to activate or deactivate
  230. //
  231. // Output:
  232. //    HRESULT  - S_OK, E_OUTOFMEMORY, E_FAIL, E_UNEXPECTED
  233. //
  234. // Notes: 
  235. //
  236. STDMETHODIMP CDocumentObject::UIActivate(BOOL fUIActivate)
  237. {
  238.     TRACE("\nEnter CDocumentObject::UIActivate");
  239.  
  240.     HRESULT hr;
  241.     if (fUIActivate)
  242.     {
  243.         // UI activate the view, take focus and bring view window forward
  244.         hr = ActivateAsDocObject(OLEIVERB_UIACTIVATE);
  245.     }
  246.     else
  247.     {
  248.         // UI deactivate
  249.         hr = UIDeactivate();
  250.     }
  251.  
  252.     TRACE("\nLeave CDocumentObject::UIActivate");
  253.     return hr;
  254. }
  255.  
  256. //=--------------------------------------------------------------------------=
  257. // CDocumentObject::Open    [IOleDocument]
  258. //=--------------------------------------------------------------------------=
  259. // asks the view to display itself in a separate popup window 
  260. //
  261. // Parameters:
  262. //    none
  263. //
  264. // Output:
  265. //    HRESULT  - S_OK, E_OUTOFMEMORY, E_FAIL, E_UNEXPECTED, E_NOTIMPL
  266. //
  267. // Notes: 
  268. //      This implementation does not support opening a view in a 
  269. //      separate window.
  270. //
  271. STDMETHODIMP CDocumentObject::Open(void)
  272. {
  273.     TRACE("\nCDocumentObject::Open");
  274.     return E_NOTIMPL;
  275. }
  276.  
  277. //=--------------------------------------------------------------------------=
  278. // CDocumentObject::CloseView    [IOleDocument]
  279. //=--------------------------------------------------------------------------=
  280. // instructs the view to close down and release its IOleInPlaceSite pointer
  281. //
  282. // Parameters:
  283. //    ULONG    - [in] reserved
  284. //
  285. // Output:
  286. //    HRESULT  - S_OK
  287. //
  288. // Notes: 
  289. //
  290. STDMETHODIMP CDocumentObject::CloseView(ULONG ulReserved)
  291. {
  292.     TRACE("\nCDocumentObject::CloseView");
  293.  
  294.     // hide the view
  295.     Show(FALSE);
  296.  
  297.     // deactivate the object
  298.     SetInPlaceSite(NULL);
  299.  
  300.     return S_OK;
  301. }
  302.  
  303. //=--------------------------------------------------------------------------=
  304. // CDocumentObject::SaveViewState    [IOleDocument]
  305. //=--------------------------------------------------------------------------=
  306. // instructs the view to save its state into the given stream
  307. //
  308. // Parameters:
  309. //    IStream* - [in] stream to write to
  310. //
  311. // Output:
  312. //    HRESULT  - S_OK, E_POINTER, E_NOTIMPL
  313. //
  314. // Notes:
  315. //
  316. STDMETHODIMP CDocumentObject::SaveViewState(LPSTREAM pstm)
  317. {
  318.     TRACE("\nCDocumentObject::SaveViewState");
  319.  
  320.     // Delegate to a virtual function which specific DocObjects can
  321.     // override to save their view state.
  322.     return OnSaveViewState(pstm);
  323. }
  324.  
  325. //=--------------------------------------------------------------------------=
  326. // CDocumentObject::ApplyViewState    [IOleDocument]
  327. //=--------------------------------------------------------------------------=
  328. // instructs the view to restore its state from the given stream
  329. //
  330. // Parameters:
  331. //    IStream* - [in] stream to read from
  332. //
  333. // Output:
  334. //    HRESULT  - S_OK, E_POINTER, E_NOTIMPL
  335. //
  336. // Notes: 
  337. //
  338. STDMETHODIMP CDocumentObject::ApplyViewState(LPSTREAM pstm)
  339. {
  340.     TRACE("\nCDocumentObject::ApplyViewState");
  341.  
  342.     // Delegate to a virtual function which specific DocObjects can
  343.     // override to restore their view state.
  344.     return OnApplyViewState(pstm);
  345. }
  346.  
  347. //=--------------------------------------------------------------------------=
  348. // CDocumentObject::Clone    [IOleDocument]
  349. //=--------------------------------------------------------------------------=
  350. // creates a duplicate view with an identical internal state to the current
  351. // view
  352. //
  353. // Parameters:
  354. //    IOleInPlaceSite*   - [in] pointer to the inplace site for the clone
  355. //   
  356. //    IOleDocumentView** - [out] location for the new view pointer
  357. //
  358. // Output:
  359. //    HRESULT  - S_OK, E_POINTER, E_NOTIMPL
  360. //
  361. // Notes: 
  362. //      This implementation does not support multiple views, therefore
  363. //      it does not support cloning a view.
  364. //
  365. STDMETHODIMP CDocumentObject::Clone(IOleInPlaceSite* pIPSiteNew, 
  366.                                     IOleDocumentView** ppViewNew)
  367. {
  368.     TRACE("\nCDocumentObject::Clone");
  369.     return E_NOTIMPL;
  370. }
  371.  
  372. //=--------------------------------------------------------------------------=
  373. // CDocumentObject::OnSaveViewState    [IOleDocument]
  374. //=--------------------------------------------------------------------------=
  375. // instructs the view to save its state into the given stream
  376. //
  377. // Parameters:
  378. //    IStream* - [in] stream to write to
  379. //
  380. // Output:
  381. //    HRESULT  - S_OK, E_POINTER, E_NOTIMPL
  382. //
  383. // Notes:
  384. //      This function should be overridden by any DocObject which has
  385. //      a view state. OnApplyViewState is the corresponding function
  386. //      which reads the view state back in.
  387. //
  388. HRESULT CDocumentObject::OnSaveViewState(LPSTREAM pstm)
  389. {
  390.     // Default implementation does nothing
  391.     return S_OK;
  392. }
  393.  
  394. //=--------------------------------------------------------------------------=
  395. // CDocumentObject::OnApplyViewState    
  396. //=--------------------------------------------------------------------------=
  397. // instructs the view to restore its state from the given stream
  398. //
  399. // Parameters:
  400. //    IStream* - [in] stream to read from
  401. //
  402. // Output:
  403. //    HRESULT  - S_OK, E_POINTER, E_NOTIMPL
  404. //
  405. // Notes: 
  406. //      This function should be overridden by any DocObject which has
  407. //      a view state. OnSaveViewState is the corresponding function
  408. //      which writes the view state out.
  409. //
  410. HRESULT CDocumentObject::OnApplyViewState(LPSTREAM pstm)
  411. {
  412.     // Default implementation does nothing
  413.     return S_OK;
  414. }
  415.  
  416.