summaryrefslogtreecommitdiffstats
path: root/third_party/active_doc
diff options
context:
space:
mode:
authoramit@chromium.org <amit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-03 22:33:46 +0000
committeramit@chromium.org <amit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-03 22:33:46 +0000
commitf6985243ea050cb848843faf4b63049f5285dce7 (patch)
tree0f6b63aaeffefa25ac104d9121847ee0a254bfd4 /third_party/active_doc
parent52dde0af9ceba4d770c07a37d5ef93d230c4290b (diff)
downloadchromium_src-f6985243ea050cb848843faf4b63049f5285dce7.zip
chromium_src-f6985243ea050cb848843faf4b63049f5285dce7.tar.gz
chromium_src-f6985243ea050cb848843faf4b63049f5285dce7.tar.bz2
Move modified ATL sample code to third_party
No code modifications other than removing chromium licence block. BUG=80617 TEST=none Review URL: http://codereview.chromium.org/6901059 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83979 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/active_doc')
-rw-r--r--third_party/active_doc/LICENSE69
-rw-r--r--third_party/active_doc/README.chromium9
-rw-r--r--third_party/active_doc/in_place_menu.h198
-rw-r--r--third_party/active_doc/ole_document_impl.h240
4 files changed, 516 insertions, 0 deletions
diff --git a/third_party/active_doc/LICENSE b/third_party/active_doc/LICENSE
new file mode 100644
index 0000000..6dd5228
--- /dev/null
+++ b/third_party/active_doc/LICENSE
@@ -0,0 +1,69 @@
+MICROSOFT LIMITED PUBLIC LICENSE
+
+This license governs use of code marked as “sample” or “example” available on
+this web site without a license agreement, as provided under the section above
+titled “NOTICE SPECIFIC TO SOFTWARE AVAILABLE ON THIS WEB SITE.” If you use
+such code (the “software”), you accept this license. If you do not accept the
+license, do not use the software.
+
+
+1. Definitions
+
+The terms “reproduce,” “reproduction,” “derivative works,” and “distribution”
+have the same meaning here as under U.S. copyright law.
+
+A “contribution” is the original software, or any additions or changes to the
+software.
+
+A “contributor” is any person that distributes its contribution under this
+license.
+
+“Licensed patents” are a contributor’s patent claims that read directly on its
+contribution.
+
+
+2. Grant of Rights
+
+(A) Copyright Grant - Subject to the terms of this license, including the
+license conditions and limitations in section 3, each contributor grants you a
+non-exclusive, worldwide, royalty-free copyright license to reproduce its
+contribution, prepare derivative works of its contribution, and distribute its
+contribution or any derivative works that you create.
+
+(B) Patent Grant - Subject to the terms of this license, including the license
+conditions and limitations in section 3, each contributor grants you a
+non-exclusive, worldwide, royalty-free license under its licensed patents to
+make, have made, use, sell, offer for sale, import, and/or otherwise dispose
+of its contribution in the software or derivative works of the contribution in
+the software.
+
+
+3. Conditions and Limitations
+
+(A) No Trademark License- This license does not grant you rights to use any
+contributors’ name, logo, or trademarks.
+
+(B) If you bring a patent claim against any contributor over patents that you
+claim are infringed by the software, your patent license from such contributor
+to the software ends automatically.
+
+(C) If you distribute any portion of the software, you must retain all
+copyright, patent, trademark, and attribution notices that are present in the
+software.
+
+(D) If you distribute any portion of the software in source code form, you may
+do so only under this license by including a complete copy of this license
+with your distribution. If you distribute any portion of the software in
+compiled or object code form, you may only do so under a license that complies
+with this license.
+
+(E) The software is licensed “as-is.” You bear the risk of using it. The
+contributors give no express warranties, guarantees or conditions. You may
+have additional consumer rights under your local laws which this license
+cannot change. To the extent permitted under your local laws, the contributors
+exclude the implied warranties of merchantability, fitness for a particular
+purpose and non-infringement.
+
+(F) Platform Limitation - The licenses granted in sections 2(A) and 2(B)
+extend only to the software or derivative works that you create that run on a
+Microsoft Windows operating system product.
diff --git a/third_party/active_doc/README.chromium b/third_party/active_doc/README.chromium
new file mode 100644
index 0000000..403242b
--- /dev/null
+++ b/third_party/active_doc/README.chromium
@@ -0,0 +1,9 @@
+Name: MSDN sample code
+Short Name: unknown
+URL: http://msdn.microsoft.com/en-us/library/dssbex6h.aspx
+Version: unknown
+Security Critical: no
+
+Local changes:
+* in_place_menu.h: Modified from Menu.h.
+* ole_document_impl.h: Modified from OleDocument.h \ No newline at end of file
diff --git a/third_party/active_doc/in_place_menu.h b/third_party/active_doc/in_place_menu.h
new file mode 100644
index 0000000..4b7be50
--- /dev/null
+++ b/third_party/active_doc/in_place_menu.h
@@ -0,0 +1,198 @@
+// in_place_menu.h : menu merging implementation
+//
+// This file is a modified version of the menu.h file, which is
+// part of the ActiveDoc MSDN sample. The modifications are largely
+// conversions to Google coding guidelines. Below is the original header
+// from the file.
+
+// This is a part of the Active Template Library.
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+// This source code is only intended as a supplement to the
+// Active Template Library Reference and related
+// electronic documentation provided with the library.
+// See these sources for detailed information regarding the
+// Active Template Library product.
+
+#ifndef CHROME_FRAME_IN_PLACE_MENU_H_
+#define CHROME_FRAME_IN_PLACE_MENU_H_
+
+#include "base/logging.h"
+#include "base/win/scoped_comptr.h"
+
+template <class T>
+class InPlaceMenu {
+ public:
+ InPlaceMenu() : shared_menu_(NULL), ole_menu_(NULL), our_menu_(NULL) {
+ }
+
+ ~InPlaceMenu() {
+ InPlaceMenuDestroy();
+ }
+
+ HRESULT InPlaceMenuCreate(LPCWSTR menu_name) {
+ // We might already have an in-place menu set, because we set menus
+ // IOleDocumentView::UIActivate as well as in
+ // IOleInPlaceActiveObject::OnDocWindowActivate. If we have already
+ // done our work, just return silently
+ if (ole_menu_ || shared_menu_)
+ return S_OK;
+
+ base::win::ScopedComPtr<IOleInPlaceFrame> in_place_frame;
+ GetInPlaceFrame(in_place_frame.Receive());
+ // We have no IOleInPlaceFrame, no menu merging possible
+ if (!in_place_frame) {
+ NOTREACHED();
+ return E_FAIL;
+ }
+ // Create a blank menu and ask the container to add
+ // its menus into the OLEMENUGROUPWIDTHS structure
+ shared_menu_ = ::CreateMenu();
+ OLEMENUGROUPWIDTHS mgw = {0};
+ HRESULT hr = in_place_frame->InsertMenus(shared_menu_, &mgw);
+ if (FAILED(hr)) {
+ ::DestroyMenu(shared_menu_);
+ shared_menu_ = NULL;
+ return hr;
+ }
+ // Insert our menus
+ our_menu_ = LoadMenu(_AtlBaseModule.GetResourceInstance(),menu_name);
+ MergeMenus(shared_menu_, our_menu_, &mgw.width[0], 1);
+ // Send the menu to the client
+ ole_menu_ = (HMENU)OleCreateMenuDescriptor(shared_menu_, &mgw);
+ T* t = static_cast<T*>(this);
+ in_place_frame->SetMenu(shared_menu_, ole_menu_, t->m_hWnd);
+ return S_OK;
+ }
+
+ HRESULT InPlaceMenuDestroy() {
+ base::win::ScopedComPtr<IOleInPlaceFrame> in_place_frame;
+ GetInPlaceFrame(in_place_frame.Receive());
+ if (in_place_frame) {
+ in_place_frame->RemoveMenus(shared_menu_);
+ in_place_frame->SetMenu(NULL, NULL, NULL);
+ }
+ if (ole_menu_) {
+ OleDestroyMenuDescriptor(ole_menu_);
+ ole_menu_ = NULL;
+ }
+ if (shared_menu_) {
+ UnmergeMenus(shared_menu_, our_menu_);
+ DestroyMenu(shared_menu_);
+ shared_menu_ = NULL;
+ }
+ if (our_menu_) {
+ DestroyMenu(our_menu_);
+ our_menu_ = NULL;
+ }
+ return S_OK;
+ }
+
+ void MergeMenus(HMENU shared_menu, HMENU source_menu, LONG* menu_widths,
+ unsigned int width_index) {
+ // Copy the popups from the source menu
+ // Insert at appropriate spot depending on width_index
+ DCHECK(width_index == 0 || width_index == 1);
+ int position = 0;
+ if (width_index == 1)
+ position = (int)menu_widths[0];
+ int group_width = 0;
+ int menu_items = GetMenuItemCount(source_menu);
+ for (int index = 0; index < menu_items; index++) {
+ // Get the HMENU of the popup
+ HMENU popup_menu = ::GetSubMenu(source_menu, index);
+ // Separators move us to next group
+ UINT state = GetMenuState(source_menu, index, MF_BYPOSITION);
+ if (!popup_menu && (state & MF_SEPARATOR)) {
+ // Servers should not touch past 5
+ DCHECK(width_index <= 5);
+ menu_widths[width_index] = group_width;
+ group_width = 0;
+ if (width_index < 5)
+ position += static_cast<int>(menu_widths[width_index+1]);
+ width_index += 2;
+ } else {
+ // Get the menu item text
+ TCHAR item_text[256] = {0};
+ int text_length = GetMenuString(source_menu, index, item_text,
+ ARRAYSIZE(item_text), MF_BYPOSITION);
+ // Popups are handled differently than normal menu items
+ if (popup_menu) {
+ if (::GetMenuItemCount(popup_menu) != 0) {
+ // Strip the HIBYTE because it contains a count of items
+ state = LOBYTE(state) | MF_POPUP; // Must be popup
+ // Non-empty popup -- add it to the shared menu bar
+ InsertMenu(shared_menu, position, state|MF_BYPOSITION,
+ reinterpret_cast<UINT_PTR>(popup_menu), item_text);
+ ++position;
+ ++group_width;
+ }
+ } else if (text_length > 0) {
+ // only non-empty items are added
+ DCHECK(item_text[0] != 0);
+ // here the state does not contain a count in the HIBYTE
+ InsertMenu(shared_menu, position, state|MF_BYPOSITION,
+ GetMenuItemID(source_menu, index), item_text);
+ ++position;
+ ++group_width;
+ }
+ }
+ }
+ }
+
+ void UnmergeMenus(HMENU shared_menu, HMENU source_menu) {
+ int our_item_count = GetMenuItemCount(source_menu);
+ int shared_item_count = GetMenuItemCount(shared_menu);
+
+ for (int index = shared_item_count - 1; index >= 0; index--) {
+ // Check the popup menus
+ HMENU popup_menu = ::GetSubMenu(shared_menu, index);
+ if (popup_menu) {
+ // If it is one of ours, remove it from the shared menu
+ for (int sub_index = 0; sub_index < our_item_count; sub_index++) {
+ if (::GetSubMenu(source_menu, sub_index) == popup_menu) {
+ // Remove the menu from hMenuShared
+ RemoveMenu(shared_menu, index, MF_BYPOSITION);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ protected:
+ HRESULT GetInPlaceFrame(IOleInPlaceFrame** in_place_frame) {
+ if (!in_place_frame) {
+ NOTREACHED();
+ return E_POINTER;
+ }
+ T* t = static_cast<T*>(this);
+ HRESULT hr = E_FAIL;
+ if (S_OK != t->GetInPlaceFrame(in_place_frame)) {
+ // We weren't given an IOleInPlaceFrame pointer, so
+ // we'll have to get it ourselves.
+ if (t->m_spInPlaceSite) {
+ t->frame_info_.cb = sizeof(OLEINPLACEFRAMEINFO);
+ base::win::ScopedComPtr<IOleInPlaceUIWindow> in_place_ui_window;
+ RECT position_rect = {0};
+ RECT clip_rect = {0};
+ hr = t->m_spInPlaceSite->GetWindowContext(in_place_frame,
+ in_place_ui_window.Receive(),
+ &position_rect, &clip_rect,
+ &t->frame_info_);
+ }
+ }
+ return hr;
+ }
+
+ protected:
+ // The OLE menu descriptor created by the OleCreateMenuDescriptor
+ HMENU ole_menu_;
+ // The shared menu that we pass to IOleInPlaceFrame::SetMenu
+ HMENU shared_menu_;
+ // Our menu resource that we want to insert
+ HMENU our_menu_;
+};
+
+#endif // CHROME_FRAME_IN_PLACE_MENU_H_
+
diff --git a/third_party/active_doc/ole_document_impl.h b/third_party/active_doc/ole_document_impl.h
new file mode 100644
index 0000000..466c227
--- /dev/null
+++ b/third_party/active_doc/ole_document_impl.h
@@ -0,0 +1,240 @@
+// ole_document_impl.h : IOleDocument implementation
+//
+// This file is a modified version of the OleDocument.h file, which is
+// part of the ActiveDoc MSDN sample. The modifications are largely
+// conversions to Google coding guidelines. Below if the original header
+// from the file.
+
+// This is a part of the Active Template Library.
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+// This source code is only intended as a supplement to the
+// Active Template Library Reference and related
+// electronic documentation provided with the library.
+// See these sources for detailed information regarding the
+// Active Template Library product.
+
+#ifndef CHROME_FRAME_OLE_DOCUMENT_IMPL_H_
+#define CHROME_FRAME_OLE_DOCUMENT_IMPL_H_
+
+// TODO(sanjeevr): Revisit this impl file and cleanup dependencies
+#include <atlbase.h>
+#include <docobj.h>
+
+#include "base/logging.h"
+
+//////////////////////////////////////////////////////////////////////////////
+// IOleDocumentImpl
+template <class T>
+class ATL_NO_VTABLE IOleDocumentImpl : public IOleDocument {
+ public:
+ STDMETHOD(CreateView)(IOleInPlaceSite* in_place_site,
+ IStream* stream,
+ DWORD reserved ,
+ IOleDocumentView** new_view) {
+ DVLOG(1) << __FUNCTION__;
+ if (new_view == NULL)
+ return E_POINTER;
+ T* t = static_cast<T*>(this);
+ // If we've already created a view then we can't create another as we
+ // currently only support the ability to create one view
+ if (t->m_spInPlaceSite)
+ return E_FAIL;
+ IOleDocumentView* view;
+ t->GetUnknown()->QueryInterface(IID_IOleDocumentView,
+ reinterpret_cast<void**>(&view));
+ // If we support IOleDocument we should support IOleDocumentView
+ ATLENSURE(view != NULL);
+ // If they've given us a site then use it
+ if (in_place_site != NULL)
+ view->SetInPlaceSite(in_place_site);
+ // If they have given us an IStream pointer then use it to
+ // initialize the view
+ if (stream != NULL)
+ view->ApplyViewState(stream);
+ // Return the view
+ *new_view = view;
+ return S_OK;
+ }
+
+ STDMETHOD(GetDocMiscStatus)(DWORD* status) {
+ DVLOG(1) << __FUNCTION__;
+ if (NULL == status)
+ return E_POINTER;
+ *status = DOCMISC_NOFILESUPPORT;
+ return S_OK;
+ }
+
+ STDMETHOD(EnumViews)(IEnumOleDocumentViews** enum_views,
+ IOleDocumentView** view) {
+ DVLOG(1) << __FUNCTION__;
+ if (view == NULL)
+ return E_POINTER;
+ T* t = static_cast<T*>(this);
+ // We only support one view
+ return t->_InternalQueryInterface(IID_IOleDocumentView,
+ reinterpret_cast<void**>(view));
+ }
+};
+
+//////////////////////////////////////////////////////////////////////////////
+// IOleDocumentViewImpl
+
+template <class T>
+class ATL_NO_VTABLE IOleDocumentViewImpl : public IOleDocumentView {
+ public:
+ STDMETHOD(SetInPlaceSite)(IOleInPlaceSite* in_place_site) {
+ DVLOG(1) << __FUNCTION__;
+ T* t = static_cast<T*>(this);
+ if (t->m_spInPlaceSite) {
+ // If we already have a site get rid of it
+ UIActivate(FALSE);
+ HRESULT hr = t->InPlaceDeactivate();
+ if (FAILED(hr))
+ return hr;
+ DCHECK(!t->m_bInPlaceActive);
+ }
+ if (in_place_site != NULL) {
+ t->m_spInPlaceSite.Release();
+ in_place_site->QueryInterface(
+ IID_IOleInPlaceSiteWindowless,
+ reinterpret_cast<void **>(&t->m_spInPlaceSite));
+ if (!t->m_spInPlaceSite) {
+ // TODO(sanjeevr): This is a super-hack because m_spInPlaceSite
+ // is an IOleInPlaceSiteWindowless pointer and we are setting
+ // an IOleInPlaceSite pointer into it. The problem is that ATL
+ // (CComControlBase) uses this in a schizophrenic manner based
+ // on the m_bWndLess flag. Ouch, ouch, ouch! Find a way to clean
+ // this up.
+ // Disclaimer: I did not invent this hack, it exists in the MSDN
+ // sample from where this code has been derived and it also exists
+ // in ATL itself (look at atlctl.h line 938).
+ t->m_spInPlaceSite =
+ reinterpret_cast<IOleInPlaceSiteWindowless*>(in_place_site);
+ }
+ }
+ return S_OK;
+ }
+
+ STDMETHOD(GetInPlaceSite)(IOleInPlaceSite** in_place_site) {
+ DVLOG(1) << __FUNCTION__;
+ if (in_place_site == NULL)
+ return E_POINTER;
+ T* t = static_cast<T*>(this);
+ return t->m_spInPlaceSite->QueryInterface(
+ IID_IOleInPlaceSite,
+ reinterpret_cast<LPVOID *>(in_place_site));
+ }
+
+ STDMETHOD(GetDocument)(IUnknown** document) {
+ DVLOG(1) << __FUNCTION__;
+ if (document == NULL)
+ return E_POINTER;
+ T* t = static_cast<T*>(this);
+ *document = t->GetUnknown();
+ (*document)->AddRef();
+ return S_OK;
+ }
+
+ STDMETHOD(SetRect)(LPRECT view_rect) {
+ static bool is_resizing = false;
+ if (is_resizing)
+ return S_OK;
+ is_resizing = true;
+ DVLOG(1) << __FUNCTION__ << " " << view_rect->left << ","
+ << view_rect->top << "," << view_rect->right << ","
+ << view_rect->bottom;
+ T* t = static_cast<T*>(this);
+ t->SetObjectRects(view_rect, view_rect);
+ is_resizing = false;
+ return S_OK;
+ }
+
+ STDMETHOD(GetRect)(LPRECT view_rect) {
+ DVLOG(1) << __FUNCTION__;
+ if (view_rect == NULL)
+ return E_POINTER;
+ T* t = static_cast<T*>(this);
+ *view_rect = t->m_rcPos;
+ return S_OK;
+ }
+
+ STDMETHOD(SetRectComplex)(LPRECT view_rect,
+ LPRECT hscroll_rect,
+ LPRECT vscroll_rect,
+ LPRECT size_box_rect) {
+ DVLOG(1) << __FUNCTION__ << " not implemented";
+ return E_NOTIMPL;
+ }
+
+ STDMETHOD(Show)(BOOL show) {
+ DVLOG(1) << __FUNCTION__;
+ T* t = static_cast<T*>(this);
+ HRESULT hr = S_OK;
+ if (show) {
+ if (!t->m_bUIActive)
+ hr = t->ActiveXDocActivate(OLEIVERB_INPLACEACTIVATE);
+ } else {
+ hr = t->UIActivate(FALSE);
+ ::ShowWindow(t->m_hWnd, SW_HIDE);
+ }
+ return hr;
+ }
+
+ STDMETHOD(UIActivate)(BOOL ui_activate) {
+ DVLOG(1) << __FUNCTION__;
+ T* t = static_cast<T*>(this);
+ HRESULT hr = S_OK;
+ if (ui_activate) {
+ // We must know the client site first
+ if (t->m_spInPlaceSite == NULL)
+ return E_UNEXPECTED;
+ if (!t->m_bUIActive)
+ hr = t->ActiveXDocActivate(OLEIVERB_UIACTIVATE);
+ } else {
+ // Menu integration is still not complete, so do not destroy
+ // IE's menus. If we call InPlaceMenuDestroy here, menu items such
+ // as Print etc will be disabled and we will not get calls to QueryStatus
+ // for those commands.
+ // t->InPlaceMenuDestroy();
+ // t->DestroyToolbar();
+ hr = t->UIDeactivate();
+ }
+ return hr;
+ }
+
+ STDMETHOD(Open)() {
+ DVLOG(1) << __FUNCTION__ << " not implemented";
+ return E_NOTIMPL;
+ }
+
+ STDMETHOD(CloseView)(DWORD reserved) {
+ DVLOG(1) << __FUNCTION__;
+ T* t = static_cast<T*>(this);
+ t->Show(FALSE);
+ t->SetInPlaceSite(NULL);
+ return S_OK;
+ }
+
+ STDMETHOD(SaveViewState)(LPSTREAM stream) {
+ DVLOG(1) << __FUNCTION__ << " not implemented";
+ return E_NOTIMPL;
+ }
+
+ STDMETHOD(ApplyViewState)(LPSTREAM stream) {
+ DVLOG(1) << __FUNCTION__ << " not implemented";
+ return E_NOTIMPL;
+ }
+
+ STDMETHOD(Clone)(IOleInPlaceSite* new_in_place_site,
+ IOleDocumentView** new_view) {
+ DVLOG(1) << __FUNCTION__ << " not implemented";
+ return E_NOTIMPL;
+ }
+
+ HRESULT ActiveXDocActivate(LONG verb) {
+ return E_NOTIMPL;
+ }
+};
+
+#endif // CHROME_FRAME_OLE_DOCUMENT_IMPL_H_