diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2016-10-08 23:38:05 +1000 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2017-03-10 11:05:54 +0000 |
commit | 3de2e8a32bead23229b263f21d4dff13dc695e4d (patch) | |
tree | e48dec154ab7996ed2956a6d85afd5f4549fd093 /shell/inc/spsupp | |
parent | 75f118da50b217956ee7a735e921524d0c2935ff (diff) |
tdf#103058: Implement OpenDocuments ActiveX control
Change-Id: I97489090476cd884a122a4b36d3ac62ca86fd886
Reviewed-on: https://gerrit.libreoffice.org/29608
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'shell/inc/spsupp')
-rw-r--r-- | shell/inc/spsupp/COMOpenDocuments.hpp | 215 | ||||
-rw-r--r-- | shell/inc/spsupp/COMRefCounted.hpp | 43 | ||||
-rw-r--r-- | shell/inc/spsupp/registrar.hpp | 26 | ||||
-rw-r--r-- | shell/inc/spsupp/spsuppClassFactory.hpp | 50 | ||||
-rw-r--r-- | shell/inc/spsupp/spsuppServ.hpp | 20 |
5 files changed, 354 insertions, 0 deletions
diff --git a/shell/inc/spsupp/COMOpenDocuments.hpp b/shell/inc/spsupp/COMOpenDocuments.hpp new file mode 100644 index 000000000000..1b2a52999ead --- /dev/null +++ b/shell/inc/spsupp/COMOpenDocuments.hpp @@ -0,0 +1,215 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* +* This file is part of the LibreOffice project. +* +* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this +* file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#ifndef _COMOPENDOCUMENTS_HPP_ +#define _COMOPENDOCUMENTS_HPP_ + +#include "spsupp_h.h" +#include "COMRefCounted.hpp" +#include "Objsafe.h" +#include "assert.h" + +class COMOpenDocuments : public COMRefCounted<IOWSNewDocument3> +{ +public: + + class Error { + public: + Error(HRESULT syserr) : m_nErr(syserr) {} + HRESULT val() const { return m_nErr; } + private: + HRESULT m_nErr; + }; + + COMOpenDocuments(); + virtual ~COMOpenDocuments(); + + // IUnknown methods + + HRESULT STDMETHODCALLTYPE QueryInterface( + REFIID riid, + void **ppvObject) override; + + // IDispatch methods + + HRESULT STDMETHODCALLTYPE GetTypeInfoCount( + UINT *pctinfo) override; + + HRESULT STDMETHODCALLTYPE GetTypeInfo( + UINT iTInfo, + LCID lcid, + ITypeInfo **ppTInfo) override; + + HRESULT STDMETHODCALLTYPE GetIDsOfNames( + REFIID riid, + LPOLESTR *rgszNames, + UINT cNames, + LCID lcid, + DISPID *rgDispId) override; + + HRESULT STDMETHODCALLTYPE Invoke( + DISPID dispIdMember, + REFIID riid, + LCID lcid, + WORD wFlags, + DISPPARAMS *pDispParams, + VARIANT *pVarResult, + EXCEPINFO *pExcepInfo, + UINT *puArgErr) override; + + // IOWSNewDocument methods https://msdn.microsoft.com/en-us/library/cc264316 + + HRESULT STDMETHODCALLTYPE CreateNewDocument( + BSTR bstrTemplateLocation, + BSTR bstrDefaultSaveLocation, + VARIANT_BOOL *pbResult) override; + + HRESULT STDMETHODCALLTYPE EditDocument( + BSTR bstrDocumentLocation, + VARIANT varProgID, + VARIANT_BOOL *pbResult) override; + + // IOWSNewDocument2 methods + + HRESULT STDMETHODCALLTYPE ViewDocument( + BSTR bstrDocumentLocation, + VARIANT varProgID, + VARIANT_BOOL *pbResult) override; + + HRESULT STDMETHODCALLTYPE ViewDocument2( + IDispatch *pdisp, + BSTR bstrDocumentLocation, + VARIANT varProgID, + VARIANT_BOOL *pbResult) override; + + HRESULT STDMETHODCALLTYPE EditDocument2( + IDispatch *pdisp, + BSTR bstrDocumentLocation, + VARIANT varProgID, + VARIANT_BOOL *pbResult) override; + + HRESULT STDMETHODCALLTYPE CreateNewDocument2( + IDispatch *pdisp, + BSTR bstrTemplateLocation, + BSTR bstrDefaultSaveLocation, + VARIANT_BOOL *pbResult) override; + + HRESULT STDMETHODCALLTYPE PromptedOnLastOpen( + VARIANT_BOOL *pbResult) override; + + // IOWSNewDocument3 methods + + HRESULT STDMETHODCALLTYPE ViewDocument3( + IDispatch *pdisp, + BSTR bstrDocumentLocation, + int OpenType, + VARIANT varProgID, + VARIANT_BOOL *pbResult) override; + + HRESULT STDMETHODCALLTYPE CheckinDocument( + BSTR bstrDocumentLocation, + int CheckinType, + BSTR CheckinComment, + VARIANT_BOOL bKeepCheckout, + VARIANT_BOOL *pbResult) override; + + HRESULT STDMETHODCALLTYPE DiscardLocalCheckout( + BSTR bstrDocumentLocationRaw, + VARIANT_BOOL *pbResult) override; + + HRESULT STDMETHODCALLTYPE ViewInExcel( + BSTR SiteUrl, + BSTR FileName, + BSTR SessionId, + BSTR Cmd, + BSTR Sheet, + int Row, + int Column, + VARIANT varProgID) override; + + HRESULT STDMETHODCALLTYPE CheckoutDocumentPrompt( + BSTR bstrDocumentLocationRaw, + VARIANT_BOOL fEditAfterCheckout, + VARIANT varProgID, + VARIANT_BOOL *pbResult) override; + + HRESULT STDMETHODCALLTYPE EditDocument3( + IDispatch *pdisp, + BSTR bstrDocumentLocation, + VARIANT_BOOL fUseLocalCopy, + VARIANT varProgID, + VARIANT_BOOL *pbResult) override; + + HRESULT STDMETHODCALLTYPE NewBlogPost( + BSTR bstrProviderId, + BSTR bstrBlogUrl, + BSTR bstrBlogName) override; + + // Non-COM methods + + static long GetObjectCount(); + +private: + //Aggregated object + class COMObjectSafety : public IObjectSafety + { + public: + COMObjectSafety(IUnknown* pOwner) : m_pOwner(pOwner) { assert(m_pOwner); } + virtual ~COMObjectSafety() {} + + // IUnknown members delegate to the outer unknown + // IUnknown members do not control lifetime of object + + HRESULT STDMETHODCALLTYPE QueryInterface( + REFIID riid, + void **ppvObject) override + { + return m_pOwner->QueryInterface(riid, ppvObject); + } + + ULONG STDMETHODCALLTYPE AddRef() override { return m_pOwner->AddRef(); } + + ULONG STDMETHODCALLTYPE Release() override { return m_pOwner->Release(); } + + // IObjectSafety methods + + HRESULT STDMETHODCALLTYPE GetInterfaceSafetyOptions( + REFIID riid, + DWORD *pdwSupportedOptions, + DWORD *pdwEnabledOptions) override; + + HRESULT STDMETHODCALLTYPE SetInterfaceSafetyOptions( + REFIID riid, + DWORD dwOptionSetMask, + DWORD dwEnabledOptions) override; + + // Non-COM methods + + bool GetSafe_forUntrustedCaller() { return (m_iEnabledOptions & INTERFACESAFE_FOR_UNTRUSTED_CALLER) != 0; } + bool GetSafe_forUntrustedData() { return (m_iEnabledOptions & INTERFACESAFE_FOR_UNTRUSTED_DATA) != 0; } + + private: + IUnknown* m_pOwner; + DWORD m_iEnabledOptions = 0; + enum : DWORD { iSupportedOptionsMask = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA }; + + void SetMaskedOptions(DWORD iMask, DWORD iOptions); + void SetSafe_forUntrustedCaller(bool bSafe); + void SetSafe_forUntrustedData(bool bSafe); + }; + + static long m_nObjCount; + static ITypeInfo* m_pTypeInfo; + static wchar_t m_szLOPath[MAX_PATH]; + COMObjectSafety m_aObjectSafety; +}; + +#endif // _COMOPENDOCUMENTS_HPP_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/inc/spsupp/COMRefCounted.hpp b/shell/inc/spsupp/COMRefCounted.hpp new file mode 100644 index 000000000000..1a60ed372300 --- /dev/null +++ b/shell/inc/spsupp/COMRefCounted.hpp @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* +* This file is part of the LibreOffice project. +* +* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this +* file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#ifndef _COMREFCOUNTED_HPP_ +#define _COMREFCOUNTED_HPP_ + +#include "objbase.h" + +template <class Interface> +class COMRefCounted : public Interface +{ +public: + COMRefCounted() {} + virtual ~COMRefCounted() {} + + // IUnknown methods + + ULONG STDMETHODCALLTYPE AddRef() override + { + return static_cast<ULONG>(::InterlockedIncrement(&m_nRef)); + } + + ULONG STDMETHODCALLTYPE Release() override + { + if (::InterlockedDecrement(&m_nRef) == 0) + delete this; + return (m_nRef > 0) ? static_cast<ULONG>(m_nRef) : 0; + } + +private: + + long m_nRef = 1; // Created referenced +}; + +#endif // _COMREFCOUNTED_HPP_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/inc/spsupp/registrar.hpp b/shell/inc/spsupp/registrar.hpp new file mode 100644 index 000000000000..00b230e5c624 --- /dev/null +++ b/shell/inc/spsupp/registrar.hpp @@ -0,0 +1,26 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* +* This file is part of the LibreOffice project. +* +* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this +* file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#ifndef _REGISTRAR_H +#define _REGISTRAR_H + +#include "windows.h" + +namespace Registrar { + HRESULT RegisterObject(REFIID riidCLSID, + REFIID riidTypeLib, + const wchar_t* sProgram, + const wchar_t* sComponent, + const wchar_t* Path); + HRESULT UnRegisterObject(REFIID riidCLSID, const wchar_t* LibId, const wchar_t* ClassId); +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/inc/spsupp/spsuppClassFactory.hpp b/shell/inc/spsupp/spsuppClassFactory.hpp new file mode 100644 index 000000000000..9bb879f70393 --- /dev/null +++ b/shell/inc/spsupp/spsuppClassFactory.hpp @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* +* This file is part of the LibreOffice project. +* +* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this +* file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#ifndef _SPSUPPCLASSFACTORY_H_ +#define _SPSUPPCLASSFACTORY_H_ + +#include "COMRefCounted.hpp" + +class ClassFactory : public COMRefCounted<IClassFactory> +{ +public: + ClassFactory(); + virtual ~ClassFactory(); + + // IUnknown methods + + HRESULT STDMETHODCALLTYPE QueryInterface( + REFIID riid, + void **ppvObject) override; + + // IClassFactory methods + + HRESULT STDMETHODCALLTYPE CreateInstance( + IUnknown *pUnkOuter, + REFIID riid, + void **ppvObject) override; + + HRESULT STDMETHODCALLTYPE LockServer( + BOOL fLock) override; + + // Non-COM methods + + static long GetObjectCount() { return m_nObjCount; } + static long GetLockCount() { return m_nLockCount; } + +private: + + static long m_nObjCount; + static long m_nLockCount; +}; + +#endif // _SPSUPPCLASSFACTORY_H_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/inc/spsupp/spsuppServ.hpp b/shell/inc/spsupp/spsuppServ.hpp new file mode 100644 index 000000000000..971e6bcda9b8 --- /dev/null +++ b/shell/inc/spsupp/spsuppServ.hpp @@ -0,0 +1,20 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* +* This file is part of the LibreOffice project. +* +* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this +* file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#ifndef _SPSUPPSERV_HPP_ +#define _SPSUPPSERV_HPP_ + +#include <objbase.h> + +ITypeLib* GetTypeLib(); +const wchar_t* GetLOPath(); + +#endif // _SPSUPPSERV_HPP_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |