summaryrefslogtreecommitdiffstats
path: root/embedserv/source/inc/embeddoc.hxx
blob: 488b142bc1a808019011c49ea7709293866e8109 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/* -*- 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/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_EMBEDSERV_SOURCE_INC_EMBEDDOC_HXX
#define INCLUDED_EMBEDSERV_SOURCE_INC_EMBEDDOC_HXX

#include "common.h"
#include <oleidl.h>
#include <objidl.h>

#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/uno/Sequence.h>
#include <unordered_map>

#include "embeddocaccess.hxx"
#include "docholder.hxx"

typedef std::unordered_map< DWORD, IAdviseSink* > AdviseSinkHashMap;

class GDIMetaFile;
class CIIAObj;

class EmbedDocument_Impl
    : public IPersistStorage,
      public IDataObject,
      public IOleObject,
      public IOleInPlaceObject,
      public IPersistFile,
      public IDispatch,
      public IExternalConnection
{
protected:
    css::uno::Sequence< css::beans::PropertyValue >
                fillArgsForLoading_Impl( css::uno::Reference< css::io::XInputStream > const & xStream,
                                         DWORD nStreamMode,
                                         LPCOLESTR pFilePath = nullptr );
    css::uno::Sequence< css::beans::PropertyValue >
                fillArgsForStoring_Impl( css::uno::Reference< css::io::XOutputStream > const & xStream );

    HRESULT SaveTo_Impl( IStorage* pStg );

    sal_uInt64 getMetaFileHandle_Impl( bool isEnhMeta );

public:
    EmbedDocument_Impl( const css::uno::Reference< css::lang::XMultiServiceFactory >& smgr,
                        const GUID* guid );
    virtual ~EmbedDocument_Impl();

    /* IUnknown methods */
    STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppvObj) override;
    STDMETHOD_(ULONG, AddRef)() override;
    STDMETHOD_(ULONG, Release)() override;

    /* IPersistMethod */
    STDMETHOD(GetClassID)(CLSID *pClassID) override;

    /* IPersistStorage methods */
    STDMETHOD(IsDirty) () override;
    STDMETHOD(InitNew) ( IStorage *pStg ) override;
    STDMETHOD(Load) ( IStorage* pStr ) override;
    STDMETHOD(Save) ( IStorage *pStgSave, BOOL fSameAsLoad ) override;
    STDMETHOD(SaveCompleted) ( IStorage *pStgNew ) override;
    STDMETHOD(HandsOffStorage) (void) override;

    /* IDataObject methods */
    STDMETHOD(GetData) ( FORMATETC * pFormatetc, STGMEDIUM * pMedium ) override;
    STDMETHOD(GetDataHere) ( FORMATETC * pFormatetc, STGMEDIUM * pMedium ) override;
    STDMETHOD(QueryGetData) ( FORMATETC * pFormatetc ) override;
    STDMETHOD(GetCanonicalFormatEtc) ( FORMATETC * pFormatetcIn, FORMATETC * pFormatetcOut ) override;
    STDMETHOD(SetData) ( FORMATETC * pFormatetc, STGMEDIUM * pMedium, BOOL fRelease ) override;
    STDMETHOD(EnumFormatEtc) ( DWORD dwDirection, IEnumFORMATETC ** ppFormatetc ) override;
    STDMETHOD(DAdvise) ( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection ) override;
    STDMETHOD(DUnadvise) ( DWORD dwConnection ) override;
    STDMETHOD(EnumDAdvise) ( IEnumSTATDATA ** ppenumAdvise ) override;

    /* IOleObject methods */
    STDMETHOD(SetClientSite) ( IOleClientSite* pSite ) override;
    STDMETHOD(GetClientSite) ( IOleClientSite** pSite ) override;
    STDMETHOD(SetHostNames) ( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj ) override;
    STDMETHOD(Close) ( DWORD dwSaveOption) override;
    STDMETHOD(SetMoniker) ( DWORD dwWhichMoniker, IMoniker *pmk ) override;
    STDMETHOD(GetMoniker) ( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk ) override;
    STDMETHOD(InitFromData) ( IDataObject *pDataObject, BOOL fCreation, DWORD dwReserved ) override;
    STDMETHOD(GetClipboardData) ( DWORD dwReserved, IDataObject **ppDataObject ) override;
    STDMETHOD(DoVerb) ( LONG iVerb, LPMSG lpmsg, IOleClientSite *pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect ) override;
    STDMETHOD(EnumVerbs) ( IEnumOLEVERB **ppEnumOleVerb ) override;
    STDMETHOD(Update) () override;
    STDMETHOD(IsUpToDate) () override;
    STDMETHOD(GetUserClassID) ( CLSID *pClsid ) override;
    STDMETHOD(GetUserType) ( DWORD dwFormOfType, LPOLESTR *pszUserType ) override;
    STDMETHOD(SetExtent) ( DWORD dwDrawAspect, SIZEL *psizel ) override;
    STDMETHOD(GetExtent) ( DWORD dwDrawAspect, SIZEL *psizel ) override;
    STDMETHOD(Advise) ( IAdviseSink *pAdvSink, DWORD *pdwConnection ) override;
    STDMETHOD(Unadvise) ( DWORD dwConnection ) override;
    STDMETHOD(EnumAdvise) ( IEnumSTATDATA **ppenumAdvise ) override;
    STDMETHOD(GetMiscStatus) ( DWORD dwAspect, DWORD *pdwStatus ) override;
    STDMETHOD(SetColorScheme) ( LOGPALETTE *pLogpal ) override;

    /* IOleInPlaceObject methods */
    STDMETHOD(GetWindow)(HWND *) override;
    STDMETHOD(ContextSensitiveHelp)(BOOL) override;
    STDMETHOD(InPlaceDeactivate)() override;
    STDMETHOD(UIDeactivate)() override;
    STDMETHOD(SetObjectRects)(LPCRECT, LPCRECT) override;
    STDMETHOD(ReactivateAndUndo)() override;

    /* IPersistFile methods */
    STDMETHOD(Load) ( LPCOLESTR pszFileName, DWORD dwMode ) override;
    STDMETHOD(Save) ( LPCOLESTR pszFileName, BOOL fRemember ) override;
    STDMETHOD(SaveCompleted) ( LPCOLESTR pszFileName ) override;
    STDMETHOD(GetCurFile) ( LPOLESTR *ppszFileName ) override;

    /* IDispatch methods */
    STDMETHOD(GetTypeInfoCount) ( unsigned int FAR*  pctinfo ) override;
    STDMETHOD(GetTypeInfo) ( unsigned int iTInfo, LCID lcid, ITypeInfo FAR* FAR* ppTInfo ) override;
    STDMETHOD(GetIDsOfNames) ( REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgDispId ) override;
    STDMETHOD(Invoke) ( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR* pDispParams, VARIANT FAR* pVarResult, EXCEPINFO FAR* pExcepInfo, unsigned int FAR* puArgErr ) override;

    /* IExternalConnection methods */
    virtual DWORD STDMETHODCALLTYPE AddConnection( DWORD extconn, DWORD reserved) override;
    virtual DWORD STDMETHODCALLTYPE ReleaseConnection( DWORD extconn, DWORD reserved, BOOL fLastReleaseCloses) override;

    // c++ - methods

    void notify( bool bDataChanged = true );
    HRESULT SaveObject();
    HRESULT ShowObject();
    GUID GetGUID() const { return m_guid; }
    HRESULT OLENotifyClosing();

    void Deactivate();
    HRESULT OLENotifyDeactivation();

protected:
    oslInterlockedCount                 m_refCount;

    css::uno::Reference< css::lang::XMultiServiceFactory > m_xFactory;

    DocumentHolder*                     m_pDocHolder;
    OUString                     m_aFileName;

    CComPtr< IStorage >                 m_pMasterStorage;
    CComPtr< IStream >                  m_pOwnStream;
    CComPtr< IStream >                  m_pExtStream;
    GUID                                m_guid;

    bool                                m_bIsDirty;

    CComPtr< IOleClientSite >           m_pClientSite;
    CComPtr< IDataAdviseHolder >        m_pDAdviseHolder;

    AdviseSinkHashMap                   m_aAdviseHashMap;
    DWORD                               m_nAdviseNum;

    ::rtl::Reference< EmbeddedDocumentInstanceAccess_Impl > m_xOwnAccess;

    bool                                m_bIsInVerbHandling;
};

class BooleanGuard_Impl
{
    bool& m_bValue;

public:
    BooleanGuard_Impl( bool& bValue )
    : m_bValue( bValue )
    {
        m_bValue = true;
    }

    ~BooleanGuard_Impl()
    {
        m_bValue = false;
    }
};

#endif // INCLUDED_EMBEDSERV_SOURCE_INC_EMBEDDOC_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */