1 // ole_document_impl.h : IOleDocument implementation
3 // This file is a modified version of the OleDocument.h file, which is
4 // part of the ActiveDoc MSDN sample. The modifications are largely
5 // conversions to Google coding guidelines. Below if the original header
8 // This is a part of the Active Template Library.
9 // Copyright (c) Microsoft Corporation. All rights reserved.
11 // This source code is only intended as a supplement to the
12 // Active Template Library Reference and related
13 // electronic documentation provided with the library.
14 // See these sources for detailed information regarding the
15 // Active Template Library product.
17 #ifndef CHROME_FRAME_OLE_DOCUMENT_IMPL_H_
18 #define CHROME_FRAME_OLE_DOCUMENT_IMPL_H_
20 // TODO(sanjeevr): Revisit this impl file and cleanup dependencies
24 #include "base/logging.h"
26 //////////////////////////////////////////////////////////////////////////////
29 class ATL_NO_VTABLE IOleDocumentImpl
: public IOleDocument
{
31 STDMETHOD(CreateView
)(IOleInPlaceSite
* in_place_site
,
34 IOleDocumentView
** new_view
) {
35 DVLOG(1) << __FUNCTION__
;
38 T
* t
= static_cast<T
*>(this);
39 // If we've already created a view then we can't create another as we
40 // currently only support the ability to create one view
41 if (t
->m_spInPlaceSite
)
43 IOleDocumentView
* view
;
44 t
->GetUnknown()->QueryInterface(IID_IOleDocumentView
,
45 reinterpret_cast<void**>(&view
));
46 // If we support IOleDocument we should support IOleDocumentView
47 ATLENSURE(view
!= NULL
);
48 // If they've given us a site then use it
49 if (in_place_site
!= NULL
)
50 view
->SetInPlaceSite(in_place_site
);
51 // If they have given us an IStream pointer then use it to
52 // initialize the view
54 view
->ApplyViewState(stream
);
60 STDMETHOD(GetDocMiscStatus
)(DWORD
* status
) {
61 DVLOG(1) << __FUNCTION__
;
64 *status
= DOCMISC_NOFILESUPPORT
;
68 STDMETHOD(EnumViews
)(IEnumOleDocumentViews
** enum_views
,
69 IOleDocumentView
** view
) {
70 DVLOG(1) << __FUNCTION__
;
73 T
* t
= static_cast<T
*>(this);
74 // We only support one view
75 return t
->_InternalQueryInterface(IID_IOleDocumentView
,
76 reinterpret_cast<void**>(view
));
80 //////////////////////////////////////////////////////////////////////////////
81 // IOleDocumentViewImpl
84 class ATL_NO_VTABLE IOleDocumentViewImpl
: public IOleDocumentView
{
86 STDMETHOD(SetInPlaceSite
)(IOleInPlaceSite
* in_place_site
) {
87 DVLOG(1) << __FUNCTION__
;
88 T
* t
= static_cast<T
*>(this);
89 if (t
->m_spInPlaceSite
) {
90 // If we already have a site get rid of it
92 HRESULT hr
= t
->InPlaceDeactivate();
95 DCHECK(!t
->m_bInPlaceActive
);
97 if (in_place_site
!= NULL
) {
98 t
->m_spInPlaceSite
.Release();
99 in_place_site
->QueryInterface(
100 IID_IOleInPlaceSiteWindowless
,
101 reinterpret_cast<void **>(&t
->m_spInPlaceSite
));
102 if (!t
->m_spInPlaceSite
) {
103 // TODO(sanjeevr): This is a super-hack because m_spInPlaceSite
104 // is an IOleInPlaceSiteWindowless pointer and we are setting
105 // an IOleInPlaceSite pointer into it. The problem is that ATL
106 // (CComControlBase) uses this in a schizophrenic manner based
107 // on the m_bWndLess flag. Ouch, ouch, ouch! Find a way to clean
109 // Disclaimer: I did not invent this hack, it exists in the MSDN
110 // sample from where this code has been derived and it also exists
111 // in ATL itself (look at atlctl.h line 938).
113 reinterpret_cast<IOleInPlaceSiteWindowless
*>(in_place_site
);
119 STDMETHOD(GetInPlaceSite
)(IOleInPlaceSite
** in_place_site
) {
120 DVLOG(1) << __FUNCTION__
;
121 if (in_place_site
== NULL
)
123 T
* t
= static_cast<T
*>(this);
124 return t
->m_spInPlaceSite
->QueryInterface(
126 reinterpret_cast<LPVOID
*>(in_place_site
));
129 STDMETHOD(GetDocument
)(IUnknown
** document
) {
130 DVLOG(1) << __FUNCTION__
;
131 if (document
== NULL
)
133 T
* t
= static_cast<T
*>(this);
134 *document
= t
->GetUnknown();
135 (*document
)->AddRef();
139 STDMETHOD(SetRect
)(LPRECT view_rect
) {
140 static bool is_resizing
= false;
144 DVLOG(1) << __FUNCTION__
<< " " << view_rect
->left
<< ","
145 << view_rect
->top
<< "," << view_rect
->right
<< ","
146 << view_rect
->bottom
;
147 T
* t
= static_cast<T
*>(this);
148 t
->SetObjectRects(view_rect
, view_rect
);
153 STDMETHOD(GetRect
)(LPRECT view_rect
) {
154 DVLOG(1) << __FUNCTION__
;
155 if (view_rect
== NULL
)
157 T
* t
= static_cast<T
*>(this);
158 *view_rect
= t
->m_rcPos
;
162 STDMETHOD(SetRectComplex
)(LPRECT view_rect
,
165 LPRECT size_box_rect
) {
166 DVLOG(1) << __FUNCTION__
<< " not implemented";
170 STDMETHOD(Show
)(BOOL show
) {
171 DVLOG(1) << __FUNCTION__
;
172 T
* t
= static_cast<T
*>(this);
176 hr
= t
->ActiveXDocActivate(OLEIVERB_INPLACEACTIVATE
);
178 hr
= t
->UIActivate(FALSE
);
179 ::ShowWindow(t
->m_hWnd
, SW_HIDE
);
184 STDMETHOD(UIActivate
)(BOOL ui_activate
) {
185 DVLOG(1) << __FUNCTION__
;
186 T
* t
= static_cast<T
*>(this);
189 // We must know the client site first
190 if (t
->m_spInPlaceSite
== NULL
)
193 hr
= t
->ActiveXDocActivate(OLEIVERB_UIACTIVATE
);
195 // Menu integration is still not complete, so do not destroy
196 // IE's menus. If we call InPlaceMenuDestroy here, menu items such
197 // as Print etc will be disabled and we will not get calls to QueryStatus
198 // for those commands.
199 // t->InPlaceMenuDestroy();
200 // t->DestroyToolbar();
201 hr
= t
->UIDeactivate();
207 DVLOG(1) << __FUNCTION__
<< " not implemented";
211 STDMETHOD(CloseView
)(DWORD reserved
) {
212 DVLOG(1) << __FUNCTION__
;
213 T
* t
= static_cast<T
*>(this);
215 t
->SetInPlaceSite(NULL
);
219 STDMETHOD(SaveViewState
)(LPSTREAM stream
) {
220 DVLOG(1) << __FUNCTION__
<< " not implemented";
224 STDMETHOD(ApplyViewState
)(LPSTREAM stream
) {
225 DVLOG(1) << __FUNCTION__
<< " not implemented";
229 STDMETHOD(Clone
)(IOleInPlaceSite
* new_in_place_site
,
230 IOleDocumentView
** new_view
) {
231 DVLOG(1) << __FUNCTION__
<< " not implemented";
235 HRESULT
ActiveXDocActivate(LONG verb
) {
240 #endif // CHROME_FRAME_OLE_DOCUMENT_IMPL_H_