1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_EMBEDDEDOBJ_SOURCE_INC_COMMONEMBOBJ_HXX
21 #define INCLUDED_EMBEDDEDOBJ_SOURCE_INC_COMMONEMBOBJ_HXX
23 #include <com/sun/star/uno/Sequence.hxx>
24 #include <com/sun/star/uno/Reference.hxx>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/container/XChild.hpp>
27 #include <com/sun/star/document/XStorageBasedDocument.hpp>
28 #include <com/sun/star/embed/XEmbeddedObject.hpp>
29 #include <com/sun/star/embed/XEmbedPersist2.hpp>
30 #include <com/sun/star/embed/XLinkageSupport.hpp>
31 #include <com/sun/star/embed/XInplaceObject.hpp>
32 #include <com/sun/star/awt/XWindow.hpp>
33 #include <com/sun/star/awt/Rectangle.hpp>
34 #include <com/sun/star/util/XCloseable.hpp>
35 #include <com/sun/star/chart2/XDefaultSizeTransmitter.hpp>
36 #include <cppuhelper/weak.hxx>
37 #include <rtl/ref.hxx>
39 namespace com
{ namespace sun
{ namespace star
{
44 class XMultiServiceFactory
;
56 class OMultiTypeInterfaceContainerHelper
;
59 namespace comphelper
{
60 class NamedValueCollection
;
63 #define NUM_SUPPORTED_STATES 5
64 // #define NUM_SUPPORTED_VERBS 5
66 #include "docholder.hxx"
71 * Represents an OLE object that has native data and we loaded that data into a
72 * document model successfully.
74 class OCommonEmbeddedObject
: public css::embed::XEmbeddedObject
75 , public css::embed::XEmbedPersist2
76 , public css::embed::XLinkageSupport
77 , public css::embed::XInplaceObject
78 , public css::container::XChild
79 , public css::chart2::XDefaultSizeTransmitter
80 , public ::cppu::OWeakObject
83 ::osl::Mutex m_aMutex
;
85 rtl::Reference
<DocumentHolder
> m_xDocHolder
;
87 ::cppu::OMultiTypeInterfaceContainerHelper
* m_pInterfaceContainer
;
94 sal_Int32 m_nObjectState
;
95 sal_Int32 m_nTargetState
; // should be -1 except during state changing
96 sal_Int32 m_nUpdateMode
;
98 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
100 css::uno::Sequence
< css::beans::PropertyValue
> m_aDocMediaDescriptor
;
102 css::uno::Sequence
< sal_Int8
> m_aClassID
;
103 OUString m_aClassName
;
105 OUString m_aDocServiceName
;
106 OUString m_aPresetFilterName
;
108 sal_Int64 m_nMiscStatus
;
110 css::uno::Sequence
< css::embed::VerbDescriptor
> m_aObjectVerbs
;
112 css::uno::Sequence
< sal_Int32
> m_aAcceptedStates
;
113 css::uno::Sequence
< sal_Int32
> m_pIntermediateStatesSeqs
[NUM_SUPPORTED_STATES
][NUM_SUPPORTED_STATES
];
114 css::uno::Sequence
< css::uno::Sequence
< sal_Int32
> > m_aVerbTable
;
116 css::uno::Reference
< css::embed::XEmbeddedClient
> m_xClientSite
;
118 OUString m_aContainerName
;
119 OUString m_aDefaultParentBaseURL
;
120 OUString m_aModuleName
;
121 bool m_bEmbeddedScriptSupport
;
122 bool m_bDocumentRecoverySupport
;
124 // following information will be used between SaveAs and SaveCompleted
125 bool m_bWaitSaveCompleted
;
126 OUString m_aNewEntryName
;
127 css::uno::Reference
< css::embed::XStorage
> m_xNewParentStorage
;
128 css::uno::Reference
< css::embed::XStorage
> m_xNewObjectStorage
;
129 css::uno::Sequence
< css::beans::PropertyValue
> m_aNewDocMediaDescriptor
;
131 css::uno::Reference
< css::awt::XWindow
> m_xClientWindow
; // ???
132 css::awt::Rectangle m_aOwnRectangle
;
133 css::awt::Rectangle m_aClipRectangle
;
137 // embedded object related stuff
138 OUString m_aEntryName
;
139 css::uno::Reference
< css::embed::XStorage
> m_xParentStorage
;
140 css::uno::Reference
< css::embed::XStorage
> m_xObjectStorage
;
141 css::uno::Reference
< css::embed::XStorage
> m_xRecoveryStorage
;
143 // link related stuff
145 OUString m_aLinkFilterName
;
146 bool m_bLinkHasPassword
;
147 OUString m_aLinkPassword
;
149 css::uno::Reference
< css::uno::XInterface
> m_xParent
;
151 bool m_bHasClonedSize
; // the object has cached size
152 css::awt::Size m_aClonedSize
;
153 sal_Int32 m_nClonedMapUnit
;
154 css::awt::Size m_aDefaultSizeForChart_In_100TH_MM
;//#i103460# charts do not necessarily have an own size within ODF files, in this case they need to use the size settings from the surrounding frame, which is made available with this member
157 void CommonInit_Impl( const css::uno::Sequence
< css::beans::NamedValue
>& aObjectProps
);
159 void LinkInit_Impl( const css::uno::Sequence
< css::beans::NamedValue
>& aObjectProps
,
160 const css::uno::Sequence
< css::beans::PropertyValue
>& aMediaDescr
,
161 const css::uno::Sequence
< css::beans::PropertyValue
>& aObjectDescr
);
164 void SwitchOwnPersistence(
165 const css::uno::Reference
< css::embed::XStorage
>& xNewParentStorage
,
166 const css::uno::Reference
< css::embed::XStorage
>& xNewObjectStorage
,
167 const OUString
& aNewName
);
169 void SwitchOwnPersistence(
170 const css::uno::Reference
< css::embed::XStorage
>& xNewParentStorage
,
171 const OUString
& aNewName
);
173 const OUString
& GetDocumentServiceName() const { return m_aDocServiceName
; }
174 const OUString
& GetPresetFilterName() const { return m_aPresetFilterName
; }
176 css::uno::Reference
< css::io::XInputStream
>
177 StoreDocumentToTempStream_Impl( sal_Int32 nStorageFormat
,
178 const OUString
& aBaseURL
,
179 const OUString
& aHierarchName
);
181 sal_Int32
ConvertVerbToState_Impl( sal_Int32 nVerb
);
185 void StateChangeNotification_Impl( bool bBeforeChange
, sal_Int32 nOldState
, sal_Int32 nNewState
,::osl::ResettableMutexGuard
& _rGuard
);
187 void SwitchStateTo_Impl( sal_Int32 nNextState
);
189 css::uno::Sequence
< sal_Int32
> const & GetIntermediateStatesSequence_Impl( sal_Int32 nNewState
);
191 OUString
GetFilterName( sal_Int32 nVersion
) const;
192 css::uno::Reference
< css::util::XCloseable
> LoadDocumentFromStorage_Impl();
194 css::uno::Reference
< css::util::XCloseable
> LoadLink_Impl();
196 css::uno::Reference
< css::util::XCloseable
> InitNewDocument_Impl();
198 void StoreDocToStorage_Impl(
199 const css::uno::Reference
<css::embed::XStorage
>& xStorage
,
200 const css::uno::Sequence
<css::beans::PropertyValue
>& rMediaArgs
,
201 const css::uno::Sequence
<css::beans::PropertyValue
>& rObjArgs
,
202 sal_Int32 nStorageVersion
,
203 const OUString
& aHierarchName
,
204 bool bAttachToStorage
);
206 void SwitchDocToStorage_Impl(
207 const css::uno::Reference
< css::document::XStorageBasedDocument
>& xDoc
,
208 const css::uno::Reference
< css::embed::XStorage
>& xStorage
);
210 void FillDefaultLoadArgs_Impl(
211 const css::uno::Reference
< css::embed::XStorage
>& i_rxStorage
,
212 ::comphelper::NamedValueCollection
& o_rLoadArgs
215 void EmbedAndReparentDoc_Impl(
216 const css::uno::Reference
< css::util::XCloseable
>& i_rxDocument
219 css::uno::Reference
< css::util::XCloseable
> CreateDocFromMediaDescr_Impl(
220 const css::uno::Sequence
< css::beans::PropertyValue
>& aMedDescr
);
222 css::uno::Reference
< css::util::XCloseable
> CreateTempDocFromLink_Impl();
224 OUString
GetBaseURL_Impl() const;
225 static OUString
GetBaseURLFrom_Impl(
226 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
,
227 const css::uno::Sequence
< css::beans::PropertyValue
>& lObjArgs
);
230 OCommonEmbeddedObject(
231 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
232 const css::uno::Sequence
< css::beans::NamedValue
>& aObjectProps
);
234 // no persistence for linked objects, so the descriptors are provided in constructor
235 OCommonEmbeddedObject(
236 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
237 const css::uno::Sequence
< css::beans::NamedValue
>& aObjectProps
,
238 const css::uno::Sequence
< css::beans::PropertyValue
>& aMediaDescr
,
239 const css::uno::Sequence
< css::beans::PropertyValue
>& aObjectDescr
);
241 virtual ~OCommonEmbeddedObject() override
;
243 void SaveObject_Impl();
245 void requestPositioning( const css::awt::Rectangle
& aRect
);
247 // not a real listener and should not be
248 void PostEvent_Impl( const OUString
& aEventName
);
250 OUString
const & getContainerName() const { return m_aContainerName
; }
253 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
255 virtual void SAL_CALL
acquire()
258 virtual void SAL_CALL
release()
263 virtual void SAL_CALL
changeState( sal_Int32 nNewState
) override
;
265 virtual css::uno::Sequence
< sal_Int32
> SAL_CALL
getReachableStates() override
;
267 virtual sal_Int32 SAL_CALL
getCurrentState() override
;
269 virtual void SAL_CALL
doVerb( sal_Int32 nVerbID
) override
;
271 virtual css::uno::Sequence
< css::embed::VerbDescriptor
> SAL_CALL
getSupportedVerbs() override
;
273 virtual void SAL_CALL
setClientSite(
274 const css::uno::Reference
< css::embed::XEmbeddedClient
>& xClient
) override
;
276 virtual css::uno::Reference
< css::embed::XEmbeddedClient
> SAL_CALL
getClientSite() override
;
278 virtual void SAL_CALL
update() override
;
280 virtual void SAL_CALL
setUpdateMode( sal_Int32 nMode
) override
;
282 virtual sal_Int64 SAL_CALL
getStatus( sal_Int64 nAspect
) override
;
284 virtual void SAL_CALL
setContainerName( const OUString
& sName
) override
;
289 virtual void SAL_CALL
setVisualAreaSize( sal_Int64 nAspect
, const css::awt::Size
& aSize
) override
;
291 virtual css::awt::Size SAL_CALL
getVisualAreaSize( sal_Int64 nAspect
) override
;
293 virtual css::embed::VisualRepresentation SAL_CALL
getPreferredVisualRepresentation( ::sal_Int64 nAspect
) override
;
295 virtual sal_Int32 SAL_CALL
getMapUnit( sal_Int64 nAspect
) override
;
299 virtual void SAL_CALL
setPersistentEntry(
300 const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
301 const OUString
& sEntName
,
302 sal_Int32 nEntryConnectionMode
,
303 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
,
304 const css::uno::Sequence
< css::beans::PropertyValue
>& lObjArgs
) override
;
306 virtual void SAL_CALL
storeToEntry( const css::uno::Reference
< css::embed::XStorage
>& xStorage
, const OUString
& sEntName
, const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
, const css::uno::Sequence
< css::beans::PropertyValue
>& lObjArgs
) override
;
308 virtual void SAL_CALL
storeAsEntry(
309 const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
310 const OUString
& sEntName
,
311 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
,
312 const css::uno::Sequence
< css::beans::PropertyValue
>& lObjArgs
) override
;
314 virtual void SAL_CALL
saveCompleted( sal_Bool bUseNew
) override
;
316 virtual sal_Bool SAL_CALL
hasEntry() override
;
318 virtual OUString SAL_CALL
getEntryName() override
;
322 virtual void SAL_CALL
breakLink( const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
323 const OUString
& sEntName
) override
;
325 virtual sal_Bool SAL_CALL
isLink() override
;
327 virtual OUString SAL_CALL
getLinkURL() override
;
330 // XCommonEmbedPersist
332 virtual void SAL_CALL
storeOwn() override
;
334 virtual sal_Bool SAL_CALL
isReadonly() override
;
336 virtual void SAL_CALL
reload(
337 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
,
338 const css::uno::Sequence
< css::beans::PropertyValue
>& lObjArgs
) override
;
342 virtual sal_Bool SAL_CALL
isStored() override
;
346 virtual void SAL_CALL
setObjectRectangles( const css::awt::Rectangle
& aPosRect
,
347 const css::awt::Rectangle
& aClipRect
) override
;
349 virtual void SAL_CALL
enableModeless( sal_Bool bEnable
) override
;
351 virtual void SAL_CALL
translateAccelerators(
352 const css::uno::Sequence
< css::awt::KeyEvent
>& aKeys
) override
;
356 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getClassID() override
;
358 virtual OUString SAL_CALL
getClassName() override
;
360 virtual void SAL_CALL
setClassInfo(
361 const css::uno::Sequence
< sal_Int8
>& aClassID
, const OUString
& aClassName
) override
;
364 // XComponentSupplier
366 virtual css::uno::Reference
< css::util::XCloseable
> SAL_CALL
getComponent() override
;
368 // XStateChangeBroadcaster
369 virtual void SAL_CALL
addStateChangeListener( const css::uno::Reference
< css::embed::XStateChangeListener
>& xListener
) override
;
370 virtual void SAL_CALL
removeStateChangeListener( const css::uno::Reference
< css::embed::XStateChangeListener
>& xListener
) override
;
374 virtual void SAL_CALL
close( sal_Bool DeliverOwnership
) override
;
376 virtual void SAL_CALL
addCloseListener(
377 const css::uno::Reference
< css::util::XCloseListener
>& Listener
) override
;
379 virtual void SAL_CALL
removeCloseListener(
380 const css::uno::Reference
< css::util::XCloseListener
>& Listener
) override
;
383 virtual void SAL_CALL
addEventListener(
384 const css::uno::Reference
< css::document::XEventListener
>& Listener
) override
;
386 virtual void SAL_CALL
removeEventListener(
387 const css::uno::Reference
< css::document::XEventListener
>& Listener
) override
;
390 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
getParent( ) override
;
391 virtual void SAL_CALL
setParent( const css::uno::Reference
< css::uno::XInterface
>& Parent
) override
;
393 // XDefaultSizeTransmitter
394 //#i103460# charts do not necessarily have an own size within ODF files, in this case they need to use the size settings from the surrounding frame, which is made available with this method
395 virtual void SAL_CALL
setDefaultSize( const css::awt::Size
& rSize_100TH_MM
) override
;
400 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */