Focus kept on login screen.
[chromium-blink-merge.git] / third_party / active_doc / ole_document_impl.h
blob466c2274fcfc540f274769b8a260302362ef1a26
1 // ole_document_impl.h : IOleDocument implementation
2 //
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
6 // from the file.
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
21 #include <atlbase.h>
22 #include <docobj.h>
24 #include "base/logging.h"
26 //////////////////////////////////////////////////////////////////////////////
27 // IOleDocumentImpl
28 template <class T>
29 class ATL_NO_VTABLE IOleDocumentImpl : public IOleDocument {
30 public:
31 STDMETHOD(CreateView)(IOleInPlaceSite* in_place_site,
32 IStream* stream,
33 DWORD reserved ,
34 IOleDocumentView** new_view) {
35 DVLOG(1) << __FUNCTION__;
36 if (new_view == NULL)
37 return E_POINTER;
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)
42 return E_FAIL;
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
53 if (stream != NULL)
54 view->ApplyViewState(stream);
55 // Return the view
56 *new_view = view;
57 return S_OK;
60 STDMETHOD(GetDocMiscStatus)(DWORD* status) {
61 DVLOG(1) << __FUNCTION__;
62 if (NULL == status)
63 return E_POINTER;
64 *status = DOCMISC_NOFILESUPPORT;
65 return S_OK;
68 STDMETHOD(EnumViews)(IEnumOleDocumentViews** enum_views,
69 IOleDocumentView** view) {
70 DVLOG(1) << __FUNCTION__;
71 if (view == NULL)
72 return E_POINTER;
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
83 template <class T>
84 class ATL_NO_VTABLE IOleDocumentViewImpl : public IOleDocumentView {
85 public:
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
91 UIActivate(FALSE);
92 HRESULT hr = t->InPlaceDeactivate();
93 if (FAILED(hr))
94 return hr;
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
108 // this up.
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).
112 t->m_spInPlaceSite =
113 reinterpret_cast<IOleInPlaceSiteWindowless*>(in_place_site);
116 return S_OK;
119 STDMETHOD(GetInPlaceSite)(IOleInPlaceSite** in_place_site) {
120 DVLOG(1) << __FUNCTION__;
121 if (in_place_site == NULL)
122 return E_POINTER;
123 T* t = static_cast<T*>(this);
124 return t->m_spInPlaceSite->QueryInterface(
125 IID_IOleInPlaceSite,
126 reinterpret_cast<LPVOID *>(in_place_site));
129 STDMETHOD(GetDocument)(IUnknown** document) {
130 DVLOG(1) << __FUNCTION__;
131 if (document == NULL)
132 return E_POINTER;
133 T* t = static_cast<T*>(this);
134 *document = t->GetUnknown();
135 (*document)->AddRef();
136 return S_OK;
139 STDMETHOD(SetRect)(LPRECT view_rect) {
140 static bool is_resizing = false;
141 if (is_resizing)
142 return S_OK;
143 is_resizing = true;
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);
149 is_resizing = false;
150 return S_OK;
153 STDMETHOD(GetRect)(LPRECT view_rect) {
154 DVLOG(1) << __FUNCTION__;
155 if (view_rect == NULL)
156 return E_POINTER;
157 T* t = static_cast<T*>(this);
158 *view_rect = t->m_rcPos;
159 return S_OK;
162 STDMETHOD(SetRectComplex)(LPRECT view_rect,
163 LPRECT hscroll_rect,
164 LPRECT vscroll_rect,
165 LPRECT size_box_rect) {
166 DVLOG(1) << __FUNCTION__ << " not implemented";
167 return E_NOTIMPL;
170 STDMETHOD(Show)(BOOL show) {
171 DVLOG(1) << __FUNCTION__;
172 T* t = static_cast<T*>(this);
173 HRESULT hr = S_OK;
174 if (show) {
175 if (!t->m_bUIActive)
176 hr = t->ActiveXDocActivate(OLEIVERB_INPLACEACTIVATE);
177 } else {
178 hr = t->UIActivate(FALSE);
179 ::ShowWindow(t->m_hWnd, SW_HIDE);
181 return hr;
184 STDMETHOD(UIActivate)(BOOL ui_activate) {
185 DVLOG(1) << __FUNCTION__;
186 T* t = static_cast<T*>(this);
187 HRESULT hr = S_OK;
188 if (ui_activate) {
189 // We must know the client site first
190 if (t->m_spInPlaceSite == NULL)
191 return E_UNEXPECTED;
192 if (!t->m_bUIActive)
193 hr = t->ActiveXDocActivate(OLEIVERB_UIACTIVATE);
194 } else {
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();
203 return hr;
206 STDMETHOD(Open)() {
207 DVLOG(1) << __FUNCTION__ << " not implemented";
208 return E_NOTIMPL;
211 STDMETHOD(CloseView)(DWORD reserved) {
212 DVLOG(1) << __FUNCTION__;
213 T* t = static_cast<T*>(this);
214 t->Show(FALSE);
215 t->SetInPlaceSite(NULL);
216 return S_OK;
219 STDMETHOD(SaveViewState)(LPSTREAM stream) {
220 DVLOG(1) << __FUNCTION__ << " not implemented";
221 return E_NOTIMPL;
224 STDMETHOD(ApplyViewState)(LPSTREAM stream) {
225 DVLOG(1) << __FUNCTION__ << " not implemented";
226 return E_NOTIMPL;
229 STDMETHOD(Clone)(IOleInPlaceSite* new_in_place_site,
230 IOleDocumentView** new_view) {
231 DVLOG(1) << __FUNCTION__ << " not implemented";
232 return E_NOTIMPL;
235 HRESULT ActiveXDocActivate(LONG verb) {
236 return E_NOTIMPL;
240 #endif // CHROME_FRAME_OLE_DOCUMENT_IMPL_H_