Bug Summary

File:home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx
Warning:line 1496, column 48
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name documentdefinition.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D OOO_DLLIMPLEMENTATION_DBA -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/dbaccess/inc -I /home/maarten/src/libreoffice/core/dbaccess/source/inc -I /home/maarten/src/libreoffice/core/dbaccess/source/core/inc -I /home/maarten/src/libreoffice/core/dbaccess/source/filter/hsqldb -I /home/maarten/src/libreoffice/core/workdir/YaccTarget/connectivity/source/parse -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx

/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "documentdefinition.hxx"
21#include <ModelImpl.hxx>
22#include <stringconstants.hxx>
23#include <sdbcoretools.hxx>
24#include <tools/diagnose_ex.h>
25#include <osl/diagnose.h>
26#include <comphelper/sequence.hxx>
27#include <comphelper/namedvaluecollection.hxx>
28#include <comphelper/classids.hxx>
29#include <comphelper/propertysequence.hxx>
30#include <comphelper/types.hxx>
31#include <com/sun/star/frame/XUntitledNumbers.hpp>
32#include <com/sun/star/awt/Size.hpp>
33#include <com/sun/star/lang/DisposedException.hpp>
34#include <com/sun/star/beans/PropertyAttribute.hpp>
35#include <com/sun/star/frame/Desktop.hpp>
36#include <com/sun/star/frame/XModel.hpp>
37#include <com/sun/star/frame/XTitle.hpp>
38#include <com/sun/star/frame/XController.hpp>
39#include <com/sun/star/task/XJobExecutor.hpp>
40#include <com/sun/star/report/XReportDefinition.hpp>
41#include <com/sun/star/report/XReportEngine.hpp>
42#include <com/sun/star/ucb/OpenMode.hpp>
43#include <com/sun/star/embed/WrongStateException.hpp>
44#include <com/sun/star/embed/EmbeddedObjectCreator.hpp>
45#include <com/sun/star/embed/Aspects.hpp>
46#include <com/sun/star/embed/OOoEmbeddedObjectFactory.hpp>
47#include <ucbhelper/cancelcommandexecution.hxx>
48#include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
49#include <com/sun/star/embed/ElementModes.hpp>
50#include <com/sun/star/embed/XEmbedPersist.hpp>
51#include <com/sun/star/embed/EmbedStates.hpp>
52#include <com/sun/star/embed/EntryInitModes.hpp>
53#include <com/sun/star/ucb/MissingPropertiesException.hpp>
54#include <com/sun/star/ucb/OpenCommandArgument2.hpp>
55#include <com/sun/star/util/CloseVetoException.hpp>
56#include <com/sun/star/frame/XModule.hpp>
57#include <com/sun/star/datatransfer/DataFlavor.hpp>
58#include <com/sun/star/datatransfer/XTransferable.hpp>
59#include <com/sun/star/container/XNameContainer.hpp>
60#include <com/sun/star/embed/XCommonEmbedPersist.hpp>
61#include "intercept.hxx"
62#include <com/sun/star/sdb/ErrorCondition.hpp>
63#include <com/sun/star/sdb/XInteractionDocumentSave.hpp>
64#include <com/sun/star/task/InteractionHandler.hpp>
65#include <com/sun/star/sdb/DocumentSaveRequest.hpp>
66#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
67#include <com/sun/star/document/MacroExecMode.hpp>
68#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
69#include <com/sun/star/form/XFormsSupplier.hpp>
70#include <com/sun/star/form/XForm.hpp>
71#include <comphelper/interaction.hxx>
72#include <connectivity/dbtools.hxx>
73#include <vcl/svapp.hxx>
74#include <osl/mutex.hxx>
75#include <com/sun/star/view/XViewSettingsSupplier.hpp>
76#include <core_resource.hxx>
77#include <strings.hrc>
78#include <com/sun/star/task/XInteractionApprove.hpp>
79#include <com/sun/star/task/XInteractionDisapprove.hpp>
80#include <com/sun/star/frame/XLayoutManager.hpp>
81#include <cppuhelper/compbase.hxx>
82#include <cppuhelper/exc_hlp.hxx>
83#include <cppuhelper/implbase.hxx>
84#include <comphelper/mimeconfighelper.hxx>
85#include <com/sun/star/container/XContentEnumerationAccess.hpp>
86#include <com/sun/star/io/WrongFormatException.hpp>
87#include <com/sun/star/sdb/application/XDatabaseDocumentUI.hpp>
88#include <com/sun/star/sdb/application/DatabaseObject.hpp>
89#include <com/sun/star/util/XModifiable2.hpp>
90
91using namespace ::com::sun::star;
92using namespace view;
93using namespace uno;
94using namespace util;
95using namespace ucb;
96using namespace beans;
97using namespace lang;
98using namespace awt;
99using namespace embed;
100using namespace frame;
101using namespace document;
102using namespace sdbc;
103using namespace sdb;
104using namespace io;
105using namespace container;
106using namespace datatransfer;
107using namespace task;
108using namespace form;
109using namespace drawing;
110using namespace ::osl;
111using namespace ::comphelper;
112using namespace ::cppu;
113
114using sdb::application::XDatabaseDocumentUI;
115namespace DatabaseObject = sdb::application::DatabaseObject;
116
117#define DEFAULT_WIDTH10000 10000
118#define DEFAULT_HEIGHT7500 7500
119
120namespace dbaccess
121{
122
123 typedef ::std::optional< bool > optional_bool;
124
125 // helper
126 namespace
127 {
128 OUString lcl_determineContentType_nothrow( const Reference< XStorage >& _rxContainerStorage,
129 const OUString& _rEntityName )
130 {
131 OUString sContentType;
132 try
133 {
134 ::utl::SharedUNOComponent< XPropertySet > xStorageProps(
135 _rxContainerStorage->openStorageElement( _rEntityName, ElementModes::READ ), UNO_QUERY_THROW );
136 OSL_VERIFY( xStorageProps->getPropertyValue( INFO_MEDIATYPE ) >>= sContentType )do { if (!(xStorageProps->getPropertyValue( "MediaType" ) >>=
sContentType)) do { if (true && (!(0))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "136" ": "), "OSL_ASSERT: %s", "0"); } } while (false); }
while (0)
;
137 }
138 catch( const Exception& )
139 {
140 DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "140" ": ", "dbaccess" );
;
141 }
142 return sContentType;
143 }
144 }
145
146 // OEmbedObjectHolder
147 typedef ::cppu::WeakComponentImplHelper< embed::XStateChangeListener > TEmbedObjectHolder;
148
149 namespace {
150
151 class OEmbedObjectHolder : public ::cppu::BaseMutex
152 ,public TEmbedObjectHolder
153 {
154 Reference< XEmbeddedObject > m_xBroadCaster;
155 ODocumentDefinition* m_pDefinition;
156 bool m_bInStateChange;
157 protected:
158 virtual void SAL_CALL disposing() override;
159 public:
160 OEmbedObjectHolder(const Reference< XEmbeddedObject >& _xBroadCaster,ODocumentDefinition* _pDefinition)
161 : TEmbedObjectHolder(m_aMutex)
162 ,m_xBroadCaster(_xBroadCaster)
163 ,m_pDefinition(_pDefinition)
164 ,m_bInStateChange(false)
165 {
166 osl_atomic_increment( &m_refCount )__sync_add_and_fetch((&m_refCount), 1);
167 {
168 if ( m_xBroadCaster.is() )
169 m_xBroadCaster->addStateChangeListener(this);
170 }
171 osl_atomic_decrement( &m_refCount )__sync_sub_and_fetch((&m_refCount), 1);
172 }
173
174 virtual void SAL_CALL changingState( const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) override;
175 virtual void SAL_CALL stateChanged( const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) override;
176 virtual void SAL_CALL disposing( const lang::EventObject& Source ) override;
177 };
178
179 }
180
181 void SAL_CALL OEmbedObjectHolder::disposing()
182 {
183 if ( m_xBroadCaster.is() )
184 m_xBroadCaster->removeStateChangeListener(this);
185 m_xBroadCaster = nullptr;
186 m_pDefinition = nullptr;
187 }
188
189 void SAL_CALL OEmbedObjectHolder::changingState( const lang::EventObject& /*aEvent*/, ::sal_Int32 /*nOldState*/, ::sal_Int32 /*nNewState*/ )
190 {
191 }
192
193 void SAL_CALL OEmbedObjectHolder::stateChanged( const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState )
194 {
195 if ( !m_bInStateChange && nNewState == EmbedStates::RUNNING && nOldState == EmbedStates::ACTIVE && m_pDefinition )
196 {
197 m_bInStateChange = true;
198 Reference<XInterface> xHoldAlive(static_cast< ::cppu::OWeakObject* >(m_pDefinition),UNO_QUERY);
199 {
200 Reference<XEmbeddedObject> xEmbeddedObject(aEvent.Source,UNO_QUERY);
201 if ( xEmbeddedObject.is() )
202 xEmbeddedObject->changeState(EmbedStates::LOADED);
203 }
204 m_bInStateChange = false;
205 }
206 }
207
208 void SAL_CALL OEmbedObjectHolder::disposing( const lang::EventObject& /*Source*/ )
209 {
210 m_xBroadCaster = nullptr;
211 }
212
213 // OEmbeddedClientHelper
214 class OEmbeddedClientHelper : public ::cppu::WeakImplHelper<XEmbeddedClient>
215 {
216 public:
217 virtual void SAL_CALL saveObject( ) override
218 {
219 }
220 // XComponentSupplier
221 virtual Reference< util::XCloseable > SAL_CALL getComponent( ) override
222 {
223 return Reference< css::util::XCloseable >();
224 }
225
226 // XEmbeddedClient
227 virtual void SAL_CALL visibilityChanged( sal_Bool /*bVisible*/ ) override
228 {
229 }
230 };
231
232 namespace {
233
234 // LockModifiable
235 class LockModifiable
236 {
237 public:
238 explicit LockModifiable( const Reference< XInterface >& i_rModifiable )
239 :m_xModifiable( i_rModifiable, UNO_QUERY )
240 {
241 OSL_ENSURE( m_xModifiable.is(), "LockModifiable::LockModifiable: invalid component!" )do { if (true && (!(m_xModifiable.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "241" ": "), "%s", "LockModifiable::LockModifiable: invalid component!"
); } } while (false)
;
242 if ( m_xModifiable.is() )
243 {
244 if ( !m_xModifiable->isSetModifiedEnabled() )
245 {
246 // somebody already locked that, no need to lock it, again, and no need to unlock it later
247 m_xModifiable.clear();
248 }
249 else
250 {
251 m_xModifiable->disableSetModified();
252 }
253 }
254 }
255
256 ~LockModifiable()
257 {
258 if ( m_xModifiable.is() )
259 m_xModifiable->enableSetModified();
260 }
261
262 private:
263 Reference< XModifiable2 > m_xModifiable;
264 };
265
266 }
267
268 // LifetimeCoupler
269 typedef ::cppu::WeakImplHelper< css::lang::XEventListener
270 > LifetimeCoupler_Base;
271
272 namespace {
273
274 /** helper class which couples the lifetime of a component to the lifetime
275 of another component
276
277 Instances of this class are constructed with two components. The first is
278 simply held by reference, and thus kept alive. The second one is observed
279 for <code>disposing</code> calls - if they occur, i.e. if the component dies,
280 the reference to the first component is cleared.
281
282 This way, you can ensure that a certain component is kept alive as long
283 as a second component is not disposed.
284 */
285 class LifetimeCoupler : public LifetimeCoupler_Base
286 {
287 private:
288 Reference< XInterface > m_xClient;
289
290 public:
291 static void couple( const Reference< XInterface >& _rxClient, const Reference< XComponent >& _rxActor )
292 {
293 new LifetimeCoupler( _rxClient, _rxActor );
294 }
295
296 private:
297 LifetimeCoupler( const Reference< XInterface >& _rxClient, const Reference< XComponent >& _rxActor )
298 :m_xClient( _rxClient )
299 {
300 OSL_ENSURE( _rxActor.is(), "LifetimeCoupler::LifetimeCoupler: this will crash!" )do { if (true && (!(_rxActor.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "300" ": "), "%s", "LifetimeCoupler::LifetimeCoupler: this will crash!"
); } } while (false)
;
301 osl_atomic_increment( &m_refCount )__sync_add_and_fetch((&m_refCount), 1);
302 {
303 _rxActor->addEventListener( this );
304 }
305 osl_atomic_decrement( &m_refCount )__sync_sub_and_fetch((&m_refCount), 1);
306 OSL_ENSURE( m_refCount, "LifetimeCoupler::LifetimeCoupler: the actor is not holding us by hard ref - this won't work!" )do { if (true && (!(m_refCount))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "306" ": "), "%s", "LifetimeCoupler::LifetimeCoupler: the actor is not holding us by hard ref - this won't work!"
); } } while (false)
;
307 }
308
309 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
310 protected:
311 };
312
313 }
314
315 void SAL_CALL LifetimeCoupler::disposing( const css::lang::EventObject& /*Source*/ )
316 {
317 m_xClient.clear();
318 }
319
320 namespace {
321
322 // ODocumentSaveContinuation
323 class ODocumentSaveContinuation : public OInteraction< XInteractionDocumentSave >
324 {
325 OUString m_sName;
326 Reference<XContent> m_xParentContainer;
327
328 public:
329 ODocumentSaveContinuation() { }
330
331 const Reference<XContent>& getContent() const { return m_xParentContainer; }
332 const OUString& getName() const { return m_sName; }
333
334 // XInteractionDocumentSave
335 virtual void SAL_CALL setName( const OUString& _sName,const Reference<XContent>& _xParent) override;
336 };
337
338 }
339
340 void SAL_CALL ODocumentSaveContinuation::setName( const OUString& _sName,const Reference<XContent>& _xParent)
341 {
342 m_sName = _sName;
343 m_xParentContainer = _xParent;
344 }
345
346OUString ODocumentDefinition::GetDocumentServiceFromMediaType( const Reference< XStorage >& _rxContainerStorage,
347 const OUString& _rEntityName, const Reference< XComponentContext >& _rContext,
348 Sequence< sal_Int8 >& _rClassId )
349{
350 return GetDocumentServiceFromMediaType(
351 lcl_determineContentType_nothrow( _rxContainerStorage, _rEntityName ),
352 _rContext, _rClassId );
353}
354
355OUString ODocumentDefinition::GetDocumentServiceFromMediaType( const OUString& _rMediaType,
356 const Reference< XComponentContext >& _rContext, Sequence< sal_Int8 >& _rClassId )
357{
358 OUString sResult;
359 try
360 {
361 ::comphelper::MimeConfigurationHelper aConfigHelper( _rContext );
362 sResult = aConfigHelper.GetDocServiceNameFromMediaType( _rMediaType );
363 _rClassId = comphelper::MimeConfigurationHelper::GetSequenceClassIDRepresentation(aConfigHelper.GetExplicitlyRegisteredObjClassID( _rMediaType ));
364 if ( !_rClassId.hasElements() && !sResult.isEmpty() )
365 {
366 Reference< XNameAccess > xObjConfig = aConfigHelper.GetObjConfiguration();
367 if ( xObjConfig.is() )
368 {
369 const Sequence< OUString > aClassIDs = xObjConfig->getElementNames();
370 for ( OUString const & classId : aClassIDs )
371 {
372 Reference< XNameAccess > xObjectProps;
373 OUString aEntryDocName;
374
375 if ( ( xObjConfig->getByName( classId ) >>= xObjectProps ) && xObjectProps.is()
376 && ( xObjectProps->getByName("ObjectDocumentServiceName") >>= aEntryDocName )
377 && aEntryDocName == sResult )
378 {
379 _rClassId = comphelper::MimeConfigurationHelper::GetSequenceClassIDRepresentation(classId);
380 break;
381 }
382 }
383 }
384 }
385#if OSL_DEBUG_LEVEL1 > 0
386 // alternative, shorter approach
387 const Sequence< NamedValue > aProps( aConfigHelper.GetObjectPropsByMediaType( _rMediaType ) );
388 const ::comphelper::NamedValueCollection aMediaTypeProps( aProps );
389 const OUString sAlternativeResult = aMediaTypeProps.getOrDefault( "ObjectDocumentServiceName", OUString() );
390 OSL_ENSURE( sAlternativeResult == sResult, "ODocumentDefinition::GetDocumentServiceFromMediaType: failed, this approach is *not* equivalent (1)!" )do { if (true && (!(sAlternativeResult == sResult))) {
sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "390" ": "), "%s", "ODocumentDefinition::GetDocumentServiceFromMediaType: failed, this approach is *not* equivalent (1)!"
); } } while (false)
;
391 const Sequence< sal_Int8 > aAlternativeClassID = aMediaTypeProps.getOrDefault( "ClassID", Sequence< sal_Int8 >() );
392 OSL_ENSURE( aAlternativeClassID == _rClassId, "ODocumentDefinition::GetDocumentServiceFromMediaType: failed, this approach is *not* equivalent (2)!" )do { if (true && (!(aAlternativeClassID == _rClassId)
)) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "392" ": "), "%s", "ODocumentDefinition::GetDocumentServiceFromMediaType: failed, this approach is *not* equivalent (2)!"
); } } while (false)
;
393#endif
394 }
395 catch ( const Exception& )
396 {
397 DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "397" ": ", "dbaccess" );
;
398 }
399 return sResult;
400}
401
402// ODocumentDefinition
403
404ODocumentDefinition::ODocumentDefinition( const Reference< XInterface >& _rxContainer, const Reference< XComponentContext >& _xORB,
405 const TContentPtr& _pImpl, bool _bForm )
406 :OContentHelper(_xORB,_rxContainer,_pImpl)
407 ,OPropertyStateContainer(OContentHelper::rBHelper)
408 ,m_bForm(_bForm)
409 ,m_bOpenInDesign(false)
410 ,m_bInExecute(false)
411 ,m_bRemoveListener(false)
412{
413 registerProperties();
414}
415
416void ODocumentDefinition::initialLoad( const Sequence< sal_Int8 >& i_rClassID, const Sequence< PropertyValue >& i_rCreationArgs,
417 const Reference< XConnection >& i_rConnection )
418{
419 OSL_ENSURE( i_rClassID.hasElements(), "ODocumentDefinition::initialLoad: illegal class ID!" )do { if (true && (!(i_rClassID.hasElements()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "419" ": "), "%s", "ODocumentDefinition::initialLoad: illegal class ID!"
); } } while (false)
;
420 if ( !i_rClassID.hasElements() )
421 return;
422
423 loadEmbeddedObject( i_rConnection, i_rClassID, i_rCreationArgs, false, false );
424}
425
426ODocumentDefinition::~ODocumentDefinition()
427{
428 if ( !OContentHelper::rBHelper.bInDispose && !OContentHelper::rBHelper.bDisposed )
429 {
430 acquire();
431 dispose();
432 }
433
434 if ( m_pInterceptor.is() )
435 {
436 m_pInterceptor->dispose();
437 m_pInterceptor.clear();
438 }
439}
440
441void ODocumentDefinition::closeObject()
442{
443 ::osl::MutexGuard aGuard(m_aMutex);
444 if ( m_xEmbeddedObject.is() )
445 {
446 try
447 {
448 m_xEmbeddedObject->close(true);
449 }
450 catch(const Exception&)
451 {
452 }
453 m_xEmbeddedObject = nullptr;
454 m_pClientHelper.clear();
455 }
456}
457
458void SAL_CALL ODocumentDefinition::disposing()
459{
460 OContentHelper::disposing();
461 ::osl::MutexGuard aGuard(m_aMutex);
462 closeObject();
463 ::comphelper::disposeComponent(m_xListener);
464 if ( m_bRemoveListener )
465 {
466 Reference<util::XCloseable> xCloseable(m_pImpl->m_pDataSource->getModel_noCreate(),UNO_QUERY);
467 if ( xCloseable.is() )
468 xCloseable->removeCloseListener(this);
469 }
470}
471
472css::uno::Sequence<sal_Int8> ODocumentDefinition::getImplementationId()
473{
474 return css::uno::Sequence<sal_Int8>();
475}
476
477IMPLEMENT_GETTYPES3(ODocumentDefinition,OContentHelper,OPropertyStateContainer,ODocumentDefinition_Base)css::uno::Sequence< css::uno::Type > ODocumentDefinition
::getTypes() { return ::comphelper::concatSequences( OContentHelper
::getTypes( ), OPropertyStateContainer::getTypes( ), ODocumentDefinition_Base
::getTypes( ) ); }
;
478IMPLEMENT_FORWARD_XINTERFACE3( ODocumentDefinition,OContentHelper,OPropertyStateContainer,ODocumentDefinition_Base)void ODocumentDefinition::acquire() throw() { OContentHelper::
acquire(); } void ODocumentDefinition::release() throw() { OContentHelper
::release(); } css::uno::Any ODocumentDefinition::queryInterface
( const css::uno::Type& _rType ) { css::uno::Any aReturn =
OContentHelper::queryInterface( _rType ); if ( !aReturn.hasValue
() ) { aReturn = OPropertyStateContainer::queryInterface( _rType
); if ( !aReturn.hasValue() ) aReturn = ODocumentDefinition_Base
::queryInterface( _rType ); } return aReturn; }
479
480void ODocumentDefinition::registerProperties()
481{
482#define REGISTER_PROPERTY( name, location )registerProperty( PROPERTY_name, PROPERTY_ID_name, PropertyAttribute
::READONLY, &location, cppu::UnoType<decltype(location
)>::get() );
\
483 registerProperty( PROPERTY_##name, PROPERTY_ID_##name, PropertyAttribute::READONLY, &location, cppu::UnoType<decltype(location)>::get() );
484
485#define REGISTER_PROPERTY_BV( name, location )registerProperty( PROPERTY_name, PROPERTY_ID_name, PropertyAttribute
::CONSTRAINED | PropertyAttribute::BOUND | PropertyAttribute::
READONLY, &location, cppu::UnoType<decltype(location)>
::get() );
\
486 registerProperty( PROPERTY_##name, PROPERTY_ID_##name, PropertyAttribute::CONSTRAINED | PropertyAttribute::BOUND | PropertyAttribute::READONLY, &location, cppu::UnoType<decltype(location)>::get() );
487
488 REGISTER_PROPERTY_BV( NAME, m_pImpl->m_aProps.aTitle )registerProperty( "Name", 7, PropertyAttribute::CONSTRAINED |
PropertyAttribute::BOUND | PropertyAttribute::READONLY, &
m_pImpl->m_aProps.aTitle, cppu::UnoType<decltype(m_pImpl
->m_aProps.aTitle)>::get() );
;
489 REGISTER_PROPERTY ( AS_TEMPLATE, m_pImpl->m_aProps.bAsTemplate )registerProperty( "AsTemplate", 124, PropertyAttribute::READONLY
, &m_pImpl->m_aProps.bAsTemplate, cppu::UnoType<decltype
(m_pImpl->m_aProps.bAsTemplate)>::get() );
;
490 REGISTER_PROPERTY ( PERSISTENT_NAME, m_pImpl->m_aProps.sPersistentName )registerProperty( "PersistentName", 117, PropertyAttribute::READONLY
, &m_pImpl->m_aProps.sPersistentName, cppu::UnoType<
decltype(m_pImpl->m_aProps.sPersistentName)>::get() );
;
491 REGISTER_PROPERTY ( IS_FORM, m_bForm )registerProperty( "IsForm", 125, PropertyAttribute::READONLY,
&m_bForm, cppu::UnoType<decltype(m_bForm)>::get() )
;
;
492}
493
494void SAL_CALL ODocumentDefinition::getFastPropertyValue( Any& o_rValue, sal_Int32 i_nHandle ) const
495{
496 if ( i_nHandle == PROPERTY_ID_PERSISTENT_PATH143 )
497 {
498 OUString sPersistentPath;
499 if ( !m_pImpl->m_aProps.sPersistentName.isEmpty() )
500 {
501 OUStringBuffer aBuffer;
502 aBuffer.append( ODatabaseModelImpl::getObjectContainerStorageName( m_bForm ? ODatabaseModelImpl::E_FORM : ODatabaseModelImpl::E_REPORT ) );
503 aBuffer.append( '/' );
504 aBuffer.append( m_pImpl->m_aProps.sPersistentName );
505 sPersistentPath = aBuffer.makeStringAndClear();
506 }
507 o_rValue <<= sPersistentPath;
508 return;
509 }
510
511 OPropertyStateContainer::getFastPropertyValue( o_rValue, i_nHandle );
512}
513
514Reference< XPropertySetInfo > SAL_CALL ODocumentDefinition::getPropertySetInfo( )
515{
516 Reference<XPropertySetInfo> xInfo( createPropertySetInfo( getInfoHelper() ) );
517 return xInfo;
518}
519
520IPropertyArrayHelper& ODocumentDefinition::getInfoHelper()
521{
522 return *getArrayHelper();
523}
524
525IPropertyArrayHelper* ODocumentDefinition::createArrayHelper( ) const
526{
527 // properties maintained by our base class (see registerProperties)
528 Sequence< Property > aProps;
529 describeProperties( aProps );
530
531 // properties not maintained by our base class
532 Sequence< Property > aManualProps( 1 );
533 aManualProps[0].Name = PROPERTY_PERSISTENT_PATH"PersistentPath";
534 aManualProps[0].Handle = PROPERTY_ID_PERSISTENT_PATH143;
535 aManualProps[0].Type = ::cppu::UnoType<OUString>::get();
536 aManualProps[0].Attributes = PropertyAttribute::READONLY;
537
538 return new OPropertyArrayHelper( ::comphelper::concatSequences( aProps, aManualProps ) );
539}
540
541namespace {
542
543class OExecuteImpl
544{
545 bool& m_rbSet;
546public:
547 explicit OExecuteImpl(bool& _rbSet) : m_rbSet(_rbSet){ m_rbSet=true; }
548 ~OExecuteImpl(){ m_rbSet = false; }
549};
550
551 bool lcl_extractOpenMode( const Any& _rValue, sal_Int32& _out_rMode )
552 {
553 OpenCommandArgument aOpenCommand;
554 if ( _rValue >>= aOpenCommand )
555 _out_rMode = aOpenCommand.Mode;
556 else
557 {
558 OpenCommandArgument2 aOpenCommand2;
559 if ( _rValue >>= aOpenCommand2 )
560 _out_rMode = aOpenCommand2.Mode;
561 else
562 return false;
563 }
564 return true;
565 }
566}
567
568void ODocumentDefinition::impl_removeFrameFromDesktop_throw( const Reference<XComponentContext> & _rxContext, const Reference< XFrame >& _rxFrame )
569{
570 Reference< XDesktop2 > xDesktop = Desktop::create( _rxContext );
571 Reference< XFrames > xFrames( xDesktop->getFrames(), UNO_SET_THROW );
572 xFrames->remove( _rxFrame );
573}
574
575void ODocumentDefinition::impl_onActivateEmbeddedObject_nothrow( const bool i_bReactivated )
576{
577 try
578 {
579 Reference< XModel > xModel( getComponent(), UNO_QUERY );
580 Reference< XController > xController( xModel.is() ? xModel->getCurrentController() : Reference< XController >() );
581 if ( !xController.is() )
582 return;
583
584 if ( !m_xListener.is() )
585 // it's the first time the embedded object has been activated
586 // create an OEmbedObjectHolder
587 m_xListener = new OEmbedObjectHolder( m_xEmbeddedObject, this );
588
589 // raise the window to top (especially necessary if this is not the first activation)
590 Reference< XFrame > xFrame( xController->getFrame(), UNO_SET_THROW );
591 Reference< XTopWindow > xTopWindow( xFrame->getContainerWindow(), UNO_QUERY_THROW );
592 xTopWindow->toFront();
593
594 // remove the frame from the desktop's frame collection because we need full control of it.
595 impl_removeFrameFromDesktop_throw( m_aContext, xFrame );
596
597 // ensure that we ourself are kept alive as long as the embedded object's frame is
598 // opened
599 LifetimeCoupler::couple( *this, xFrame.get() );
600
601 // init the edit view
602 if ( m_bForm && m_bOpenInDesign && !i_bReactivated )
603 impl_initFormEditView( xController );
604 }
605 catch( const RuntimeException& )
606 {
607 DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "607" ": ", "dbaccess" );
;
608 }
609}
610
611namespace
612{
613 // PreserveVisualAreaSize
614 /** stack-guard for preserving the size of the VisArea of an XModel
615 */
616 class PreserveVisualAreaSize
617 {
618 private:
619 Reference< XVisualObject > m_xVisObject;
620 awt::Size m_aOriginalSize;
621
622 public:
623 explicit PreserveVisualAreaSize( const Reference< XModel >& _rxModel )
624 :m_xVisObject( _rxModel, UNO_QUERY )
625 {
626 if ( m_xVisObject.is() )
627 {
628 try
629 {
630 m_aOriginalSize = m_xVisObject->getVisualAreaSize( Aspects::MSOLE_CONTENT );
631 }
632 catch ( const Exception& )
633 {
634 TOOLS_WARN_EXCEPTION( "dbaccess", "PreserveVisualAreaSize::PreserveVisualAreaSize" )do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "dbaccess")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case
SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "PreserveVisualAreaSize::PreserveVisualAreaSize"
<< " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"dbaccess"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "634" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "PreserveVisualAreaSize::PreserveVisualAreaSize"
<< " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "PreserveVisualAreaSize::PreserveVisualAreaSize" <<
" " << exceptionToString(tools_warn_exception); ::sal::
detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "634" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "PreserveVisualAreaSize::PreserveVisualAreaSize" <<
" " << exceptionToString(tools_warn_exception)) == 1) {
::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess"
), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "634" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "PreserveVisualAreaSize::PreserveVisualAreaSize"
<< " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "PreserveVisualAreaSize::PreserveVisualAreaSize" <<
" " << exceptionToString(tools_warn_exception); ::sal::
detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "634" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
635 }
636 }
637 }
638
639 ~PreserveVisualAreaSize()
640 {
641 if ( m_xVisObject.is() && m_aOriginalSize.Width && m_aOriginalSize.Height )
642 {
643 try
644 {
645 m_xVisObject->setVisualAreaSize( Aspects::MSOLE_CONTENT, m_aOriginalSize );
646 }
647 catch ( const Exception& )
648 {
649 TOOLS_WARN_EXCEPTION( "dbaccess", "PreserveVisualAreaSize::~PreserveVisualAreaSize" )do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "dbaccess")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case
SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "PreserveVisualAreaSize::~PreserveVisualAreaSize"
<< " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"dbaccess"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "649" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "PreserveVisualAreaSize::~PreserveVisualAreaSize"
<< " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "PreserveVisualAreaSize::~PreserveVisualAreaSize" <<
" " << exceptionToString(tools_warn_exception); ::sal::
detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "649" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "PreserveVisualAreaSize::~PreserveVisualAreaSize"
<< " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"dbaccess"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "649" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "PreserveVisualAreaSize::~PreserveVisualAreaSize"
<< " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "PreserveVisualAreaSize::~PreserveVisualAreaSize" <<
" " << exceptionToString(tools_warn_exception); ::sal::
detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "649" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
650 }
651 }
652 }
653 };
654
655 // LayoutManagerLock
656 /** helper class for stack-usage which during its lifetime locks a layout manager
657 */
658 class LayoutManagerLock
659 {
660 private:
661 Reference< XLayoutManager > m_xLayoutManager;
662
663 public:
664 explicit LayoutManagerLock( const Reference< XController >& _rxController )
665 {
666 OSL_ENSURE( _rxController.is(), "LayoutManagerLock::LayoutManagerLock: this will crash!" )do { if (true && (!(_rxController.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "666" ": "), "%s", "LayoutManagerLock::LayoutManagerLock: this will crash!"
); } } while (false)
;
667 Reference< XFrame > xFrame( _rxController->getFrame() );
668 try
669 {
670 Reference< XPropertySet > xPropSet( xFrame, UNO_QUERY_THROW );
671 m_xLayoutManager.set(
672 xPropSet->getPropertyValue( "LayoutManager" ),
673 UNO_QUERY_THROW );
674 m_xLayoutManager->lock();
675
676 }
677 catch( const Exception& )
678 {
679 TOOLS_WARN_EXCEPTION( "dbaccess", "LayoutManagerLock::LayoutManagerLock" )do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "dbaccess")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case
SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "LayoutManagerLock::LayoutManagerLock"
<< " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"dbaccess"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "679" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "LayoutManagerLock::LayoutManagerLock"
<< " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "LayoutManagerLock::LayoutManagerLock" << " "
<< exceptionToString(tools_warn_exception); ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "679" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "LayoutManagerLock::LayoutManagerLock" << " "
<< exceptionToString(tools_warn_exception)) == 1) { ::
sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess"), (
"/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "679" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "LayoutManagerLock::LayoutManagerLock"
<< " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "LayoutManagerLock::LayoutManagerLock" << " "
<< exceptionToString(tools_warn_exception); ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "679" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
680 }
681 }
682
683 ~LayoutManagerLock()
684 {
685 try
686 {
687 // unlock the layout manager
688 if ( m_xLayoutManager.is() )
689 m_xLayoutManager->unlock();
690 }
691 catch( const Exception& )
692 {
693 TOOLS_WARN_EXCEPTION( "dbaccess", "LayoutManagerLock::~LayoutManagerLock" )do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "dbaccess")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case
SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "LayoutManagerLock::~LayoutManagerLock"
<< " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"dbaccess"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "693" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "LayoutManagerLock::~LayoutManagerLock"
<< " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "LayoutManagerLock::~LayoutManagerLock" << " "
<< exceptionToString(tools_warn_exception); ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "693" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "LayoutManagerLock::~LayoutManagerLock" << " "
<< exceptionToString(tools_warn_exception)) == 1) { ::
sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess"), (
"/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "693" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "LayoutManagerLock::~LayoutManagerLock"
<< " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "LayoutManagerLock::~LayoutManagerLock" << " "
<< exceptionToString(tools_warn_exception); ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("dbaccess"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "693" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
694 }
695 }
696 };
697}
698
699void ODocumentDefinition::impl_initFormEditView( const Reference< XController >& _rxController )
700{
701 try
702 {
703 Reference< XViewSettingsSupplier > xSettingsSupplier( _rxController, UNO_QUERY_THROW );
704 Reference< XPropertySet > xViewSettings( xSettingsSupplier->getViewSettings(), UNO_SET_THROW );
705
706 // the below code could indirectly tamper with the "modified" flag of the model, temporarily disable this
707 LockModifiable aLockModify( _rxController->getModel() );
708
709 // The visual area size can be changed by the setting of the following properties
710 // so it should be restored later
711 PreserveVisualAreaSize aPreserveVisAreaSize( _rxController->getModel() );
712
713 // Layout manager should not layout while the size is still not restored
714 // so it will stay locked for this time
715 LayoutManagerLock aLockLayout( _rxController );
716
717 // setting of the visual properties
718 xViewSettings->setPropertyValue("ShowRulers",makeAny(true));
719 xViewSettings->setPropertyValue("ShowVertRuler",makeAny(true));
720 xViewSettings->setPropertyValue("ShowHoriRuler",makeAny(true));
721 xViewSettings->setPropertyValue("IsRasterVisible",makeAny(true));
722 xViewSettings->setPropertyValue("IsSnapToRaster",makeAny(true));
723 xViewSettings->setPropertyValue("ShowOnlineLayout",makeAny(true));
724 xViewSettings->setPropertyValue("RasterSubdivisionX",makeAny(sal_Int32(5)));
725 xViewSettings->setPropertyValue("RasterSubdivisionY",makeAny(sal_Int32(5)));
726 }
727 catch( const Exception& )
728 {
729 DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "729" ": ", "dbaccess" );
;
730 }
731}
732
733void ODocumentDefinition::impl_showOrHideComponent_throw( const bool i_bShow )
734{
735 const sal_Int32 nCurrentState = m_xEmbeddedObject.is() ? m_xEmbeddedObject->getCurrentState() : EmbedStates::LOADED;
736 switch ( nCurrentState )
737 {
738 default:
739 case EmbedStates::LOADED:
740 throw embed::WrongStateException( OUString(), *this );
741
742 case EmbedStates::RUNNING:
743 if ( !i_bShow )
744 // fine, a running (and not yet active) object is never visible
745 return;
746 {
747 LockModifiable aLockModify( impl_getComponent_throw() );
748 m_xEmbeddedObject->changeState( EmbedStates::ACTIVE );
749 impl_onActivateEmbeddedObject_nothrow( false );
750 }
751 break;
752
753 case EmbedStates::ACTIVE:
754 {
755 Reference< XModel > xEmbeddedDoc( impl_getComponent_throw(), UNO_QUERY_THROW );
756 Reference< XController > xEmbeddedController( xEmbeddedDoc->getCurrentController(), UNO_SET_THROW );
757 Reference< XFrame > xEmbeddedFrame( xEmbeddedController->getFrame(), UNO_SET_THROW );
758 Reference< XWindow > xEmbeddedWindow( xEmbeddedFrame->getContainerWindow(), UNO_SET_THROW );
759 xEmbeddedWindow->setVisible( i_bShow );
760 }
761 break;
762 }
763}
764
765Any ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, const bool _bActivate,
766 const Reference< XCommandEnvironment >& _rxEnvironment )
767{
768 OExecuteImpl aExecuteGuard( m_bInExecute );
769
770 Reference< XConnection > xConnection;
771 sal_Int32 nOpenMode = OpenMode::DOCUMENT;
772
773 ::comphelper::NamedValueCollection aDocumentArgs;
774
775 // for the document, default to the interaction handler as used for loading the DB doc
776 // This might be overwritten below, when examining _rOpenArgument.
777 const ::comphelper::NamedValueCollection& aDBDocArgs( m_pImpl->m_pDataSource->getMediaDescriptor() );
778 Reference< XInteractionHandler > xHandler( aDBDocArgs.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() ) );
779 if ( xHandler.is() )
780 aDocumentArgs.put( "InteractionHandler", xHandler );
781
782 ::std::optional< sal_Int16 > aDocumentMacroMode;
783
784 if ( !lcl_extractOpenMode( _rOpenArgument, nOpenMode ) )
785 {
786 Sequence< PropertyValue > aArguments;
787 if ( _rOpenArgument >>= aArguments )
788 {
789 const PropertyValue* pIter = aArguments.getConstArray();
790 const PropertyValue* pEnd = pIter + aArguments.getLength();
791 for ( ;pIter != pEnd; ++pIter )
792 {
793 if ( pIter->Name == PROPERTY_ACTIVE_CONNECTION"ActiveConnection" )
794 {
795 xConnection.set( pIter->Value, UNO_QUERY );
796 continue;
797 }
798
799 if ( lcl_extractOpenMode( pIter->Value, nOpenMode ) )
800 continue;
801
802 if ( pIter->Name == "MacroExecutionMode" )
803 {
804 sal_Int16 nMacroExecMode( !aDocumentMacroMode ? MacroExecMode::USE_CONFIG : *aDocumentMacroMode );
805 OSL_VERIFY( pIter->Value >>= nMacroExecMode )do { if (!(pIter->Value >>= nMacroExecMode)) do { if
(true && (!(0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "805" ": "), "OSL_ASSERT: %s", "0"); } } while (false); }
while (0)
;
806 aDocumentMacroMode = nMacroExecMode;
807 continue;
808 }
809
810 // unknown argument -> pass to the loaded document
811 aDocumentArgs.put( pIter->Name, pIter->Value );
812 }
813 }
814 }
815
816 bool bExecuteDBDocMacros = m_pImpl->m_pDataSource->checkMacrosOnLoading();
817 // Note that this call implies the user might be asked for the macro execution mode.
818 // Normally, this would happen when the database document is loaded, and subsequent calls
819 // will simply use the user's decision from this point in time.
820 // However, it is possible to programmatically load forms/reports, without actually
821 // loading the database document into a frame. In this case, the user will be asked
822 // here and now.
823 // #i87741#
824
825 // allow the command arguments to downgrade the macro execution mode, but not to upgrade
826 // it
827 if ( ( m_pImpl->m_pDataSource->getImposedMacroExecMode() == MacroExecMode::USE_CONFIG )
828 && bExecuteDBDocMacros
829 )
830 {
831 // while loading the whole database document, USE_CONFIG, was passed.
832 // Additionally, *by now* executing macros from the DB doc is allowed (this is what bExecuteDBDocMacros
833 // indicates). This means either one of:
834 // 1. The DB doc or one of the sub docs contained macros and
835 // 1a. the user explicitly allowed executing them
836 // 1b. the configuration allows executing them without asking the user
837 // 2. Neither the DB doc nor the sub docs contained macros, thus macro
838 // execution was silently enabled, assuming that any macro will be a
839 // user-created macro
840 //
841 // The problem with this: If the to-be-opened sub document has macros embedded in
842 // the content.xml (which is valid ODF, but normally not produced by OOo itself),
843 // then this has not been detected while loading the database document - it would
844 // be too expensive, as it effectively would require loading all forms/reports.
845 //
846 // So, in such a case, and with 2. above, we would silently execute those macros,
847 // regardless of the global security settings - which would be a security issue, of
848 // course.
849 if ( m_pImpl->m_pDataSource->determineEmbeddedMacros() == ODatabaseModelImpl::eNoMacros )
850 {
851 // this is case 2. from above
852 // So, pass a USE_CONFIG to the to-be-loaded document. This means that
853 // the user will be prompted with a security message upon opening this
854 // sub document, in case the settings require this, *and* the document
855 // contains scripts in the content.xml. But this is better than the security
856 // issue we had before ...
857 aDocumentMacroMode = MacroExecMode::USE_CONFIG;
858 }
859 }
860
861 if ( !aDocumentMacroMode )
862 {
863 // nobody so far felt responsible for setting it
864 // => use the DBDoc-wide macro exec mode for the document, too
865 aDocumentMacroMode = bExecuteDBDocMacros ? MacroExecMode::ALWAYS_EXECUTE_NO_WARN
866 : MacroExecMode::NEVER_EXECUTE;
867 }
868 aDocumentArgs.put( "MacroExecutionMode", *aDocumentMacroMode );
869
870 if ( ( nOpenMode == OpenMode::ALL )
871 || ( nOpenMode == OpenMode::FOLDERS )
872 || ( nOpenMode == OpenMode::DOCUMENTS )
873 || ( nOpenMode == OpenMode::DOCUMENT_SHARE_DENY_NONE )
874 || ( nOpenMode == OpenMode::DOCUMENT_SHARE_DENY_WRITE )
875 )
876 {
877 // not supported
878 ucbhelper::cancelCommandExecution(
879 makeAny( UnsupportedOpenModeException(
880 OUString(),
881 static_cast< cppu::OWeakObject * >( this ),
882 sal_Int16( nOpenMode ) ) ),
883 _rxEnvironment );
884 // Unreachable
885 OSL_FAIL( "unreachable" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "885" ": "), "%s", "unreachable"); } } while (false)
;
886 }
887
888 OSL_ENSURE( !m_pImpl->m_aProps.sPersistentName.isEmpty(),do { if (true && (!(!m_pImpl->m_aProps.sPersistentName
.isEmpty()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "889" ": "), "%s", "ODocumentDefinition::onCommandOpenSomething: no persistent name - cannot load!"
); } } while (false)
889 "ODocumentDefinition::onCommandOpenSomething: no persistent name - cannot load!" )do { if (true && (!(!m_pImpl->m_aProps.sPersistentName
.isEmpty()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "889" ": "), "%s", "ODocumentDefinition::onCommandOpenSomething: no persistent name - cannot load!"
); } } while (false)
;
890 if ( m_pImpl->m_aProps.sPersistentName.isEmpty() )
891 return Any();
892
893 // embedded objects themself do not support the hidden flag. We implement support for
894 // it by changing the STATE to RUNNING only, instead of ACTIVE.
895 bool bOpenHidden = aDocumentArgs.getOrDefault( "Hidden", false );
896 aDocumentArgs.remove( "Hidden" );
897
898 loadEmbeddedObject( xConnection, Sequence< sal_Int8 >(), aDocumentArgs.getPropertyValues(), false, !m_bOpenInDesign );
899 OSL_ENSURE( m_xEmbeddedObject.is(), "ODocumentDefinition::onCommandOpenSomething: what's this?" )do { if (true && (!(m_xEmbeddedObject.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "899" ": "), "%s", "ODocumentDefinition::onCommandOpenSomething: what's this?"
); } } while (false)
;
900 if ( !m_xEmbeddedObject.is() )
901 return Any();
902
903 Reference< XModel > xModel( getComponent(), UNO_QUERY );
904 Reference< report::XReportDefinition > xReportDefinition(xModel,UNO_QUERY);
905
906 Reference< XModule > xModule( xModel, UNO_QUERY );
907 if ( xModule.is() )
908 {
909 if ( m_bForm )
910 xModule->setIdentifier( "com.sun.star.sdb.FormDesign" );
911 else if ( !xReportDefinition.is() )
912 xModule->setIdentifier( "com.sun.star.text.TextDocument" );
913
914 updateDocumentTitle();
915 }
916
917 bool bIsAliveNewStyleReport = ( !m_bOpenInDesign && xReportDefinition.is() );
918 if ( bIsAliveNewStyleReport )
919 {
920 // we are in ReadOnly mode
921 // we would like to open the Writer or Calc with the report direct, without design it.
922 Reference< report::XReportEngine > xReportEngine( m_aContext->getServiceManager()->createInstanceWithContext("com.sun.star.comp.report.OReportEngineJFree", m_aContext), UNO_QUERY_THROW );
923
924 xReportEngine->setReportDefinition(xReportDefinition);
925 xReportEngine->setActiveConnection(m_xLastKnownConnection);
926 if ( bOpenHidden )
927 return makeAny( xReportEngine->createDocumentModel() );
928 return makeAny( xReportEngine->createDocumentAlive( nullptr ) );
929 }
930
931 if ( _bActivate && !bOpenHidden )
932 {
933 LockModifiable aLockModify( impl_getComponent_throw() );
934 m_xEmbeddedObject->changeState( EmbedStates::ACTIVE );
935 impl_onActivateEmbeddedObject_nothrow( false );
936 }
937 else
938 {
939 // ensure that we ourself are kept alive as long as the document is open
940 LifetimeCoupler::couple( *this, xModel.get() );
941 }
942
943 if ( !m_bForm && m_pImpl->m_aProps.bAsTemplate && !m_bOpenInDesign )
944 ODocumentDefinition::fillReportData( m_aContext, getComponent(), xConnection );
945
946 return makeAny( xModel );
947}
948
949Any SAL_CALL ODocumentDefinition::execute( const Command& aCommand, sal_Int32 CommandId, const Reference< XCommandEnvironment >& Environment )
950{
951 Any aRet;
952
953 bool bOpen = aCommand.Name == "open";
954 bool bOpenInDesign = aCommand.Name == "openDesign";
955 bool bOpenForMail = aCommand.Name == "openForMail";
956 if ( bOpen || bOpenInDesign || bOpenForMail )
957 {
958 // opening the document involves a lot of VCL code, which is not thread-safe, but needs the SolarMutex locked.
959 // Unfortunately, the DocumentDefinition, as well as the EmbeddedObject implementation, calls into VCL-dependent
960 // components *without* releasing the own mutex, which is a guaranteed recipe for deadlocks.
961 // We have control over this implementation here, and in modifying it to release the own mutex before calling into
962 // the VCL-dependent components is not too difficult (was there, seen it).
963 // However, we do /not/ have control over the EmbeddedObject implementation, and from a first look, it seems as
964 // making it release the own mutex before calling SolarMutex-code is ... difficult, at least.
965 // So, to be on the same side, we lock the SolarMutex here. Yes, it sucks.
966 ::SolarMutexGuard aSolarGuard;
967 osl::MutexGuard aGuard(m_aMutex);
968 if ( m_bInExecute )
969 return aRet;
970
971 bool bActivateObject = true;
972 if ( bOpenForMail )
973 {
974 OSL_FAIL( "ODocumentDefinition::execute: 'openForMail' should not be used anymore - use the 'Hidden' parameter instead!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "974" ": "), "%s", "ODocumentDefinition::execute: 'openForMail' should not be used anymore - use the 'Hidden' parameter instead!"
); } } while (false)
;
975 bActivateObject = false;
976 }
977
978 // if the object is already opened, do nothing
979 if ( m_xEmbeddedObject.is() )
980 {
981 sal_Int32 nCurrentState = m_xEmbeddedObject->getCurrentState();
982 bool bIsActive = ( nCurrentState == EmbedStates::ACTIVE );
983
984 if ( bIsActive )
985 {
986 // exception: new-style reports always create a new document when "open" is executed
987 Reference< report::XReportDefinition > xReportDefinition( impl_getComponent_throw( false ), UNO_QUERY );
988 bool bIsAliveNewStyleReport = ( xReportDefinition.is() && ( bOpen || bOpenForMail ) );
989
990 if ( !bIsAliveNewStyleReport )
991 {
992 impl_onActivateEmbeddedObject_nothrow( true );
993 return makeAny( getComponent() );
994 }
995 }
996 }
997
998 m_bOpenInDesign = bOpenInDesign || bOpenForMail;
999 return onCommandOpenSomething( aCommand.Argument, bActivateObject, Environment );
1000 }
1001
1002 osl::MutexGuard aGuard(m_aMutex);
1003 if ( m_bInExecute )
1004 return aRet;
1005
1006 if ( aCommand.Name == "copyTo" )
1007 {
1008 Sequence<Any> aIni;
1009 aCommand.Argument >>= aIni;
1010 if ( aIni.getLength() != 2 )
1011 {
1012 OSL_FAIL( "Wrong argument type!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1012" ": "), "%s", "Wrong argument type!"); } } while (
false)
;
1013 ucbhelper::cancelCommandExecution(
1014 makeAny( IllegalArgumentException(
1015 OUString(),
1016 static_cast< cppu::OWeakObject * >( this ),
1017 -1 ) ),
1018 Environment );
1019 // Unreachable
1020 }
1021 Reference< XStorage> xDest(aIni[0],UNO_QUERY);
1022 OUString sPersistentName;
1023 aIni[1] >>= sPersistentName;
1024 Reference< XStorage> xStorage = getContainerStorage();
1025
1026 xStorage->copyElementTo(m_pImpl->m_aProps.sPersistentName,xDest,sPersistentName);
1027 }
1028 else if ( aCommand.Name == "preview" )
1029 {
1030 onCommandPreview(aRet);
1031 }
1032 else if ( aCommand.Name == "insert" )
1033 {
1034 Sequence<Any> aIni;
1035 aCommand.Argument >>= aIni;
1036 if ( !aIni.hasElements() )
1037 {
1038 OSL_FAIL( "Wrong argument count!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1038" ": "), "%s", "Wrong argument count!"); } } while (
false)
;
1039 ucbhelper::cancelCommandExecution(
1040 makeAny( IllegalArgumentException(
1041 OUString(),
1042 static_cast< cppu::OWeakObject * >( this ),
1043 -1 ) ),
1044 Environment );
1045 // Unreachable
1046 }
1047 OUString sURL;
1048 aIni[0] >>= sURL;
1049 onCommandInsert( sURL, Environment );
1050 }
1051 else if ( aCommand.Name == "getdocumentinfo" // compatibility
1052 || aCommand.Name == "getDocumentInfo" )
1053 {
1054 onCommandGetDocumentProperties( aRet );
1055 }
1056 else if ( aCommand.Name == "delete" )
1057 {
1058 // delete
1059 closeObject();
1060 Reference< XStorage> xStorage = getContainerStorage();
1061 if ( xStorage.is() )
1062 xStorage->removeElement(m_pImpl->m_aProps.sPersistentName);
1063
1064 dispose();
1065
1066 }
1067 else if ( aCommand.Name == "storeOwn" // compatibility
1068 || aCommand.Name == "store"
1069 )
1070 {
1071 impl_store_throw();
1072 }
1073 else if ( aCommand.Name == "shutdown" // compatibility
1074 || aCommand.Name == "close"
1075 )
1076 {
1077 aRet <<= impl_close_throw();
1078 }
1079 else if ( aCommand.Name == "show" )
1080 {
1081 impl_showOrHideComponent_throw( true );
1082 }
1083 else if ( aCommand.Name == "hide" )
1084 {
1085 impl_showOrHideComponent_throw( false );
1086 }
1087 else
1088 {
1089 aRet = OContentHelper::execute(aCommand,CommandId,Environment);
1090 }
1091
1092 return aRet;
1093}
1094
1095namespace
1096{
1097 void lcl_resetChildFormsToEmptyDataSource( const Reference< XIndexAccess>& _rxFormsContainer )
1098 {
1099 OSL_PRECOND( _rxFormsContainer.is(), "lcl_resetChildFormsToEmptyDataSource: illegal call!" )do { if (true && (!(_rxFormsContainer.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1099" ": "), "%s", "lcl_resetChildFormsToEmptyDataSource: illegal call!"
); } } while (false)
;
1100 sal_Int32 count = _rxFormsContainer->getCount();
1101 for ( sal_Int32 i = 0; i < count; ++i )
1102 {
1103 Reference< XForm > xForm( _rxFormsContainer->getByIndex( i ), UNO_QUERY );
1104 if ( !xForm.is() )
1105 continue;
1106
1107 // if the element is a form, reset its DataSourceName property to an empty string
1108 try
1109 {
1110 Reference< XPropertySet > xFormProps( xForm, UNO_QUERY_THROW );
1111 xFormProps->setPropertyValue( PROPERTY_DATASOURCENAME"DataSourceName", makeAny( OUString() ) );
1112 }
1113 catch( const Exception& )
1114 {
1115 DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1115" ": ", "dbaccess" );
;
1116 }
1117
1118 // if the element is a container itself, step down the component hierarchy
1119 Reference< XIndexAccess > xContainer( xForm, UNO_QUERY );
1120 if ( xContainer.is() )
1121 lcl_resetChildFormsToEmptyDataSource( xContainer );
1122 }
1123 }
1124
1125 void lcl_resetFormsToEmptyDataSource( const Reference< XEmbeddedObject>& _rxEmbeddedObject )
1126 {
1127 try
1128 {
1129 Reference< XDrawPageSupplier > xSuppPage( _rxEmbeddedObject->getComponent(), UNO_QUERY_THROW );
1130 // if this interface does not exist, then either getComponent returned NULL,
1131 // or the document is a multi-page document. The latter is allowed, but currently
1132 // simply not handled by this code, as it would not normally happen.
1133
1134 Reference< XFormsSupplier > xSuppForms( xSuppPage->getDrawPage(), UNO_QUERY_THROW );
1135 Reference< XIndexAccess > xForms( xSuppForms->getForms(), UNO_QUERY_THROW );
1136 lcl_resetChildFormsToEmptyDataSource( xForms );
1137 }
1138 catch( const Exception& )
1139 {
1140 DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1140" ": ", "dbaccess" );
;
1141 }
1142
1143 }
1144}
1145
1146void ODocumentDefinition::onCommandInsert( const OUString& _sURL, const Reference< XCommandEnvironment >& Environment )
1147{
1148 osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
1149
1150 // Check, if all required properties were set.
1151 if ( _sURL.isEmpty() || m_xEmbeddedObject.is() )
1152 {
1153 OSL_FAIL( "Content::onCommandInsert - property value missing!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1153" ": "), "%s", "Content::onCommandInsert - property value missing!"
); } } while (false)
;
1154
1155 Sequence<OUString> aProps { PROPERTY_URL"URL" };
1156 ucbhelper::cancelCommandExecution(
1157 makeAny( MissingPropertiesException(
1158 OUString(),
1159 static_cast< cppu::OWeakObject * >( this ),
1160 aProps ) ),
1161 Environment );
1162 // Unreachable
1163 }
1164
1165 if ( !m_xEmbeddedObject.is() )
1166 {
1167 Reference< XStorage> xStorage = getContainerStorage();
1168 if ( xStorage.is() )
1169 {
1170 Reference< XEmbeddedObjectCreator> xEmbedFactory = EmbeddedObjectCreator::create(m_aContext);
1171 Sequence<PropertyValue> aEmpty,aMediaDesc(1);
1172 aMediaDesc[0].Name = PROPERTY_URL"URL";
1173 aMediaDesc[0].Value <<= _sURL;
1174 m_xEmbeddedObject.set(xEmbedFactory->createInstanceInitFromMediaDescriptor( xStorage
1175 ,m_pImpl->m_aProps.sPersistentName
1176 ,aMediaDesc
1177 ,aEmpty),UNO_QUERY);
1178
1179 lcl_resetFormsToEmptyDataSource( m_xEmbeddedObject );
1180 // #i57669#
1181
1182 Reference<XEmbedPersist> xPersist(m_xEmbeddedObject,UNO_QUERY);
1183 if ( xPersist.is() )
1184 {
1185 xPersist->storeOwn();
1186 }
1187 try
1188 {
1189 if ( m_xEmbeddedObject.is() )
1190 m_xEmbeddedObject->close(true);
1191 }
1192 catch(const Exception&)
1193 {
1194 }
1195 m_xEmbeddedObject = nullptr;
1196 }
1197 }
1198
1199 aGuard.clear();
1200}
1201
1202bool ODocumentDefinition::save(bool _bApprove, const css::uno::Reference<css::awt::XTopWindow>& rDialogParent)
1203{
1204 // default handling: instantiate an interaction handler and let it handle the parameter request
1205 if ( !m_bOpenInDesign )
1206 return false;
1207 try
1208 {
1209
1210 {
1211 ::SolarMutexGuard aSolarGuard;
1212
1213 // the request
1214 Reference<XNameAccess> xName(m_xParentContainer,UNO_QUERY);
1215 DocumentSaveRequest aRequest;
1216 aRequest.Name = m_pImpl->m_aProps.aTitle;
1217 if ( aRequest.Name.isEmpty() )
1218 {
1219 if ( m_bForm )
1220 aRequest.Name = DBA_RES( RID_STR_FORM )::dbaccess::ResourceManager::loadString( reinterpret_cast<
char const *>("RID_STR_FORM" "\004" u8"Form") )
;
1221 else
1222 aRequest.Name = DBA_RES( RID_STR_REPORT )::dbaccess::ResourceManager::loadString( reinterpret_cast<
char const *>("RID_STR_REPORT" "\004" u8"Report") )
;
1223 aRequest.Name = ::dbtools::createUniqueName(xName,aRequest.Name);
1224 }
1225
1226 aRequest.Content.set(m_xParentContainer,UNO_QUERY);
1227 OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aRequest));
1228 Reference< XInteractionRequest > xRequest(pRequest);
1229 // some knittings
1230 // two continuations allowed: OK and Cancel
1231 ODocumentSaveContinuation* pDocuSave = nullptr;
1232
1233 if ( m_pImpl->m_aProps.aTitle.isEmpty() )
1234 {
1235 pDocuSave = new ODocumentSaveContinuation;
1236 pRequest->addContinuation(pDocuSave);
1237 }
1238 if ( _bApprove )
1239 {
1240 OInteraction< XInteractionApprove >* pApprove = new OInteraction< XInteractionApprove >;
1241 pRequest->addContinuation(pApprove);
1242 }
1243
1244 OInteraction< XInteractionDisapprove >* pDisApprove = new OInteraction< XInteractionDisapprove >;
1245 pRequest->addContinuation(pDisApprove);
1246
1247 OInteractionAbort* pAbort = new OInteractionAbort;
1248 pRequest->addContinuation(pAbort);
1249
1250 Reference<XWindow> xDialogParent(rDialogParent, UNO_QUERY);
1251
1252 // create the handler, let it handle the request
1253 Reference<XInteractionHandler2> xHandler(InteractionHandler::createWithParent(m_aContext, xDialogParent));
1254 xHandler->handle(xRequest);
1255
1256 if ( pAbort->wasSelected() )
1257 return false;
1258 if ( pDisApprove->wasSelected() )
1259 return true;
1260 if ( pDocuSave && pDocuSave->wasSelected() )
1261 {
1262 Reference<XNameContainer> xNC( pDocuSave->getContent(), UNO_QUERY_THROW );
1263
1264 ::osl::ResettableMutexGuard aGuard( m_aMutex );
1265 NameChangeNotifier aNameChangeAndNotify( *this, pDocuSave->getName(), aGuard );
1266 m_pImpl->m_aProps.aTitle = pDocuSave->getName();
1267
1268 Reference< XContent> xContent = this;
1269 xNC->insertByName(pDocuSave->getName(),makeAny(xContent));
1270
1271 updateDocumentTitle();
1272 }
1273 }
1274
1275 ::osl::MutexGuard aGuard(m_aMutex);
1276 Reference<XEmbedPersist> xPersist(m_xEmbeddedObject,UNO_QUERY);
1277 if ( xPersist.is() )
1278 {
1279 xPersist->storeOwn();
1280 notifyDataSourceModified();
1281 }
1282 }
1283 catch(const Exception&)
1284 {
1285 OSL_FAIL("ODocumentDefinition::save: caught an Exception (tried to let the InteractionHandler handle it)!")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1285" ": "), "%s", "ODocumentDefinition::save: caught an Exception (tried to let the InteractionHandler handle it)!"
); } } while (false)
;
1286 }
1287 return true;
1288}
1289
1290void ODocumentDefinition::saveAs()
1291{
1292 // default handling: instantiate an interaction handler and let it handle the parameter request
1293 if ( !m_bOpenInDesign )
1294 return;
1295
1296 {
1297 osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
1298 if ( m_pImpl->m_aProps.aTitle.isEmpty() )
1299 {
1300 aGuard.clear();
1301 save(false, css::uno::Reference<css::awt::XTopWindow>()); // (sal_False) : we don't want an approve dialog
1302 return;
1303 }
1304 }
1305 try
1306 {
1307 ::SolarMutexGuard aSolarGuard;
1308
1309 // the request
1310 DocumentSaveRequest aRequest;
1311 aRequest.Name = m_pImpl->m_aProps.aTitle;
1312
1313 aRequest.Content.set(m_xParentContainer,UNO_QUERY);
1314 OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aRequest));
1315 Reference< XInteractionRequest > xRequest(pRequest);
1316 // some knittings
1317 // two continuations allowed: OK and Cancel
1318 ODocumentSaveContinuation* pDocuSave = new ODocumentSaveContinuation;
1319 pRequest->addContinuation(pDocuSave);
1320 OInteraction< XInteractionDisapprove >* pDisApprove = new OInteraction< XInteractionDisapprove >;
1321 pRequest->addContinuation(pDisApprove);
1322 OInteractionAbort* pAbort = new OInteractionAbort;
1323 pRequest->addContinuation(pAbort);
1324
1325 // create the handler, let it handle the request
1326 Reference< XInteractionHandler2 > xHandler( InteractionHandler::createWithParent(m_aContext, nullptr) );
1327 xHandler->handle(xRequest);
1328
1329 if ( pAbort->wasSelected() )
1330 return;
1331 if ( pDisApprove->wasSelected() )
1332 return;
1333 if ( pDocuSave->wasSelected() )
1334 {
1335 ::osl::MutexGuard aGuard(m_aMutex);
1336 Reference<XNameContainer> xNC(pDocuSave->getContent(),UNO_QUERY);
1337 if ( xNC.is() )
1338 {
1339 if ( m_pImpl->m_aProps.aTitle != pDocuSave->getName() )
1340 {
1341 try
1342 {
1343 Reference< XStorage> xStorage = getContainerStorage();
1344
1345 OUString sPersistentName = ::dbtools::createUniqueName(xStorage,"Obj");
1346 xStorage->copyElementTo(m_pImpl->m_aProps.sPersistentName,xStorage,sPersistentName);
1347
1348 OUString sOldName = m_pImpl->m_aProps.aTitle;
1349 rename(pDocuSave->getName());
1350 updateDocumentTitle();
1351
1352 uno::Sequence<uno::Any> aArguments(comphelper::InitAnyPropertySequence(
1353 {
1354 {PROPERTY_NAME"Name", uno::Any(sOldName)}, // set as folder
1355 {PROPERTY_PERSISTENT_NAME"PersistentName", uno::Any(sPersistentName)},
1356 {PROPERTY_AS_TEMPLATE"AsTemplate", uno::Any(m_pImpl->m_aProps.bAsTemplate)},
1357 }));
1358 Reference< XMultiServiceFactory > xORB( m_xParentContainer, UNO_QUERY_THROW );
1359 Reference< XInterface > xComponent( xORB->createInstanceWithArguments( SERVICE_SDB_DOCUMENTDEFINITION"com.sun.star.sdb.DocumentDefinition", aArguments ) );
1360 Reference< XNameContainer > xNameContainer( m_xParentContainer, UNO_QUERY_THROW );
1361 xNameContainer->insertByName( sOldName, makeAny( xComponent ) );
1362 }
1363 catch(const Exception&)
1364 {
1365 DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1365" ": ", "dbaccess" );
;
1366 }
1367 }
1368 Reference<XEmbedPersist> xPersist(m_xEmbeddedObject,UNO_QUERY);
1369 if ( xPersist.is() )
1370 {
1371 xPersist->storeOwn();
1372 notifyDataSourceModified();
1373 }
1374 }
1375 }
1376 }
1377 catch(const Exception&)
1378 {
1379 OSL_FAIL("ODocumentDefinition::save: caught an Exception (tried to let the InteractionHandler handle it)!")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1379" ": "), "%s", "ODocumentDefinition::save: caught an Exception (tried to let the InteractionHandler handle it)!"
); } } while (false)
;
1380 }
1381}
1382
1383namespace
1384{
1385 void lcl_putLoadArgs( ::comphelper::NamedValueCollection& _io_rArgs, const optional_bool& _bSuppressMacros, const optional_bool& _bReadOnly )
1386 {
1387 if ( !!_bSuppressMacros )
1388 {
1389 if ( *_bSuppressMacros )
1390 {
1391 // if we're to suppress macros, do exactly this
1392 _io_rArgs.put( "MacroExecutionMode", MacroExecMode::NEVER_EXECUTE );
1393 }
1394 else
1395 {
1396 // otherwise, put the setting only if not already present
1397 if ( !_io_rArgs.has( "MacroExecutionMode" ) )
1398 {
1399 _io_rArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG );
1400 }
1401 }
1402 }
1403
1404 if ( !!_bReadOnly )
1405 _io_rArgs.put( "ReadOnly", *_bReadOnly );
1406 }
1407}
1408
1409namespace
1410{
1411 Reference< XFrame > lcl_getDatabaseDocumentFrame( ODatabaseModelImpl const & _rImpl )
1412 {
1413 Reference< XModel > xDatabaseDocumentModel( _rImpl.getModel_noCreate() );
1414
1415 Reference< XController > xDatabaseDocumentController;
1416 if ( xDatabaseDocumentModel.is() )
1417 xDatabaseDocumentController = xDatabaseDocumentModel->getCurrentController();
1418
1419 Reference< XFrame > xFrame;
1420 if ( xDatabaseDocumentController.is() )
1421 xFrame = xDatabaseDocumentController->getFrame();
1422
1423 return xFrame;
1424 }
1425}
1426
1427bool ODocumentDefinition::objectSupportsEmbeddedScripts() const
1428{
1429 bool bAllowDocumentMacros = !m_pImpl->m_pDataSource
1430 || ( m_pImpl->m_pDataSource->determineEmbeddedMacros() == ODatabaseModelImpl::eSubDocumentMacros );
1431
1432 // if *any* of the objects of the database document already has macros, we
1433 // continue to allow it to have them, until the user does a migration.
1434 // If there are no macros, we don't allow them to be created.
1435
1436 return bAllowDocumentMacros;
1437}
1438
1439OUString ODocumentDefinition::determineContentType() const
1440{
1441 return lcl_determineContentType_nothrow( getContainerStorage(), m_pImpl->m_aProps.sPersistentName );
1442}
1443
1444void ODocumentDefinition::separateOpenCommandArguments( const Sequence< PropertyValue >& i_rOpenCommandArguments,
1445 ::comphelper::NamedValueCollection& o_rDocumentLoadArgs, ::comphelper::NamedValueCollection& o_rEmbeddedObjectDescriptor )
1446{
1447 ::comphelper::NamedValueCollection aOpenCommandArguments( i_rOpenCommandArguments );
1448
1449 const char* const pObjectDescriptorArgs[] =
1450 {
1451 "RecoveryStorage"
1452 };
1453 for (const char* pObjectDescriptorArg : pObjectDescriptorArgs)
1454 {
1455 if ( aOpenCommandArguments.has( pObjectDescriptorArg ) )
1456 {
1457 o_rEmbeddedObjectDescriptor.put( pObjectDescriptorArg, aOpenCommandArguments.get( pObjectDescriptorArg ) );
1458 aOpenCommandArguments.remove( pObjectDescriptorArg );
1459 }
1460 }
1461
1462 o_rDocumentLoadArgs.merge( aOpenCommandArguments, false );
1463}
1464
1465Sequence< PropertyValue > ODocumentDefinition::fillLoadArgs( const Reference< XConnection>& _xConnection, const bool _bSuppressMacros, const bool _bReadOnly,
1466 const Sequence< PropertyValue >& i_rOpenCommandArguments, Sequence< PropertyValue >& _out_rEmbeddedObjectDescriptor )
1467{
1468 // (re-)create interceptor, and put it into the descriptor of the embedded object
1469 if ( m_pInterceptor.is() )
8
Taking false branch
1470 {
1471 m_pInterceptor->dispose();
1472 m_pInterceptor.clear();
1473 }
1474
1475 m_pInterceptor = new OInterceptor( this );
1476 Reference<XDispatchProviderInterceptor> xInterceptor = m_pInterceptor.get();
1477
1478 ::comphelper::NamedValueCollection aEmbeddedDescriptor;
1479 aEmbeddedDescriptor.put( "OutplaceDispatchInterceptor", xInterceptor );
1480
1481 ::comphelper::NamedValueCollection aMediaDesc;
1482 separateOpenCommandArguments( i_rOpenCommandArguments, aMediaDesc, aEmbeddedDescriptor );
1483
1484 // create the OutplaceFrameProperties, and put them into the descriptor of the embedded object
1485 ::comphelper::NamedValueCollection OutplaceFrameProperties;
1486 OutplaceFrameProperties.put( "TopWindow", true );
1487 OutplaceFrameProperties.put( "SupportPersistentWindowState", true );
1488
1489 Reference< XFrame > xParentFrame;
1490 if ( m_pImpl->m_pDataSource )
9
Assuming field 'm_pDataSource' is null
10
Assuming pointer value is null
11
Taking false branch
1491 xParentFrame = lcl_getDatabaseDocumentFrame( *m_pImpl->m_pDataSource );
1492 if ( !xParentFrame.is() )
12
Calling 'BaseReference::is'
14
Returning from 'BaseReference::is'
15
Taking true branch
1493 { // i87957 we need a parent frame
1494 Reference< XDesktop2 > xDesktop = Desktop::create( m_aContext );
1495 xParentFrame.set( xDesktop, UNO_QUERY_THROW );
1496 Reference<util::XCloseable> xCloseable(m_pImpl->m_pDataSource->getModel_noCreate(),UNO_QUERY);
16
Called C++ object pointer is null
1497 if ( xCloseable.is() )
1498 {
1499 xCloseable->addCloseListener(this);
1500 m_bRemoveListener = true;
1501 }
1502 }
1503 OSL_ENSURE( xParentFrame.is(), "ODocumentDefinition::fillLoadArgs: no parent frame!" )do { if (true && (!(xParentFrame.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1503" ": "), "%s", "ODocumentDefinition::fillLoadArgs: no parent frame!"
); } } while (false)
;
1504 if ( xParentFrame.is() )
1505 OutplaceFrameProperties.put( "ParentFrame", xParentFrame );
1506
1507 aEmbeddedDescriptor.put( "OutplaceFrameProperties", OutplaceFrameProperties.getNamedValues() );
1508
1509 // tell the embedded object to have (or not have) script support
1510 aEmbeddedDescriptor.put( "EmbeddedScriptSupport", objectSupportsEmbeddedScripts() );
1511
1512 // tell the embedded object to not participate in the document recovery game - the DB doc will handle it
1513 aEmbeddedDescriptor.put( "DocumentRecoverySupport", false );
1514
1515 // pass the descriptor of the embedded object to the caller
1516 aEmbeddedDescriptor >>= _out_rEmbeddedObjectDescriptor;
1517
1518 // create the ComponentData, and put it into the document's media descriptor
1519 {
1520 ::comphelper::NamedValueCollection aComponentData;
1521 aComponentData.put( "ActiveConnection", _xConnection );
1522 aComponentData.put( "ApplyFormDesignMode", !_bReadOnly );
1523 aMediaDesc.put( "ComponentData", aComponentData.getPropertyValues() );
1524 }
1525
1526 if ( !m_pImpl->m_aProps.aTitle.isEmpty() )
1527 aMediaDesc.put( "DocumentTitle", m_pImpl->m_aProps.aTitle );
1528
1529 aMediaDesc.put( "DocumentBaseURL", m_pImpl->m_pDataSource->getURL() );
1530
1531 // put the common load arguments into the document's media descriptor
1532 lcl_putLoadArgs( aMediaDesc, optional_bool( _bSuppressMacros ), optional_bool( _bReadOnly ) );
1533
1534 return aMediaDesc.getPropertyValues();
1535}
1536
1537void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& i_rConnection, const Sequence< sal_Int8 >& _aClassID,
1538 const Sequence< PropertyValue >& i_rOpenCommandArguments, const bool _bSuppressMacros, const bool _bReadOnly )
1539{
1540 if ( !m_xEmbeddedObject.is() )
3
Taking false branch
1541 {
1542 Reference< XStorage> xStorage = getContainerStorage();
1543 if ( xStorage.is() )
1544 {
1545 Reference< XEmbeddedObjectCreator> xEmbedFactory = OOoEmbeddedObjectFactory::create(m_aContext);
1546 OUString sDocumentService;
1547 bool bSetSize = false;
1548 sal_Int32 nEntryConnectionMode = EntryInitModes::DEFAULT_INIT;
1549 Sequence< sal_Int8 > aClassID = _aClassID;
1550 if ( aClassID.hasElements() )
1551 {
1552 nEntryConnectionMode = EntryInitModes::TRUNCATE_INIT;
1553 bSetSize = true;
1554 }
1555 else
1556 {
1557 sDocumentService = GetDocumentServiceFromMediaType( getContentType(), m_aContext, aClassID );
1558 // check if we are not a form and
1559 // the org.libreoffice.report.pentaho.SOReportJobFactory is not present.
1560 if ( !m_bForm && sDocumentService != "com.sun.star.text.TextDocument")
1561 {
1562 // we seem to be a "new style" report, check if report extension is present.
1563 Reference< XContentEnumerationAccess > xEnumAccess( m_aContext->getServiceManager(), UNO_QUERY );
1564 const OUString sReportEngineServiceName = ::dbtools::getDefaultReportEngineServiceName(m_aContext);
1565 Reference< XEnumeration > xEnumDrivers = xEnumAccess->createContentEnumeration(sReportEngineServiceName);
1566 if ( !xEnumDrivers.is() || !xEnumDrivers->hasMoreElements() )
1567 {
1568 css::io::WrongFormatException aWFE;
1569 aWFE.Message = DBA_RES( RID_STR_MISSING_EXTENSION )::dbaccess::ResourceManager::loadString( reinterpret_cast<
char const *>("RID_STR_MISSING_EXTENSION" "\004" u8"The extension is not installed."
) )
;
1570 throw aWFE;
1571 }
1572 }
1573 if ( !aClassID.hasElements() )
1574 {
1575 if ( m_bForm )
1576 aClassID = MimeConfigurationHelper::GetSequenceClassID(SO3_SW_CLASSID0x8BC6B165, 0xB1B2, 0x4EDD, 0xAA, 0x47, 0xDA, 0xE2, 0xEE, 0x68
, 0x9D, 0xD6
);
1577 else
1578 {
1579 aClassID = MimeConfigurationHelper::GetSequenceClassID(SO3_RPT_CLASSID_900xd7896d52, 0xb7af, 0x4820, 0x9d, 0xfe, 0xd4, 0x04, 0xd0, 0x15
, 0x96, 0x0f
);
1580 }
1581 }
1582 }
1583
1584 OSL_ENSURE( aClassID.hasElements(),"No Class ID" )do { if (true && (!(aClassID.hasElements()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1584" ": "), "%s", "No Class ID"); } } while (false)
;
1585
1586 Sequence< PropertyValue > aEmbeddedObjectDescriptor;
1587 Sequence< PropertyValue > aLoadArgs( fillLoadArgs(
1588 i_rConnection, _bSuppressMacros, _bReadOnly, i_rOpenCommandArguments, aEmbeddedObjectDescriptor ) );
1589
1590 m_xEmbeddedObject.set(xEmbedFactory->createInstanceUserInit(aClassID
1591 ,sDocumentService
1592 ,xStorage
1593 ,m_pImpl->m_aProps.sPersistentName
1594 ,nEntryConnectionMode
1595 ,aLoadArgs
1596 ,aEmbeddedObjectDescriptor
1597 ),UNO_QUERY);
1598 if ( m_xEmbeddedObject.is() )
1599 {
1600 if ( !m_pClientHelper.is() )
1601 {
1602 m_pClientHelper = new OEmbeddedClientHelper;
1603 }
1604 Reference<XEmbeddedClient> xClient = m_pClientHelper.get();
1605 m_xEmbeddedObject->setClientSite(xClient);
1606 m_xEmbeddedObject->changeState(EmbedStates::RUNNING);
1607 if ( bSetSize )
1608 {
1609 LockModifiable aLockModify( impl_getComponent_throw( false ) );
1610
1611 awt::Size aSize( DEFAULT_WIDTH10000, DEFAULT_HEIGHT7500 );
1612 m_xEmbeddedObject->setVisualAreaSize(Aspects::MSOLE_CONTENT,aSize);
1613 }
1614 }
1615 }
1616 }
1617 else
1618 {
1619 sal_Int32 nCurrentState = m_xEmbeddedObject->getCurrentState();
1620 if ( nCurrentState == EmbedStates::LOADED )
4
Assuming 'nCurrentState' is equal to 'LOADED'
5
Taking true branch
1621 {
1622 if ( !m_pClientHelper.is() )
6
Taking true branch
1623 {
1624 m_pClientHelper = new OEmbeddedClientHelper;
1625 }
1626 Reference<XEmbeddedClient> xClient = m_pClientHelper.get();
1627 m_xEmbeddedObject->setClientSite(xClient);
1628
1629 Sequence< PropertyValue > aEmbeddedObjectDescriptor;
1630 Sequence< PropertyValue > aLoadArgs( fillLoadArgs(
7
Calling 'ODocumentDefinition::fillLoadArgs'
1631 i_rConnection, _bSuppressMacros, _bReadOnly, i_rOpenCommandArguments, aEmbeddedObjectDescriptor ) );
1632
1633 Reference<XCommonEmbedPersist> xCommon(m_xEmbeddedObject,UNO_QUERY);
1634 OSL_ENSURE(xCommon.is(),"unsupported interface!")do { if (true && (!(xCommon.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1634" ": "), "%s", "unsupported interface!"); } } while
(false)
;
1635 if ( xCommon.is() )
1636 xCommon->reload( aLoadArgs, aEmbeddedObjectDescriptor );
1637 m_xEmbeddedObject->changeState(EmbedStates::RUNNING);
1638 }
1639 else
1640 {
1641 OSL_ENSURE( ( nCurrentState == EmbedStates::RUNNING ) || ( nCurrentState == EmbedStates::ACTIVE ),do { if (true && (!(( nCurrentState == EmbedStates::RUNNING
) || ( nCurrentState == EmbedStates::ACTIVE )))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1642" ": "), "%s", "ODocumentDefinition::loadEmbeddedObject: unexpected state!"
); } } while (false)
1642 "ODocumentDefinition::loadEmbeddedObject: unexpected state!" )do { if (true && (!(( nCurrentState == EmbedStates::RUNNING
) || ( nCurrentState == EmbedStates::ACTIVE )))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1642" ": "), "%s", "ODocumentDefinition::loadEmbeddedObject: unexpected state!"
); } } while (false)
;
1643
1644 // if the document was already loaded (which means the embedded object is in state RUNNING or ACTIVE),
1645 // then just re-set some model parameters
1646 try
1647 {
1648 // ensure the media descriptor doesn't contain any values which are intended for the
1649 // EmbeddedObjectDescriptor only
1650 ::comphelper::NamedValueCollection aEmbeddedObjectDescriptor;
1651 ::comphelper::NamedValueCollection aNewMediaDesc;
1652 separateOpenCommandArguments( i_rOpenCommandArguments, aNewMediaDesc, aEmbeddedObjectDescriptor );
1653
1654 // merge the new media descriptor into the existing media descriptor
1655 const Reference< XModel > xModel( getComponent(), UNO_QUERY_THROW );
1656 const Sequence< PropertyValue > aArgs = xModel->getArgs();
1657 ::comphelper::NamedValueCollection aExistentMediaDesc( aArgs );
1658 aExistentMediaDesc.merge( aNewMediaDesc, false );
1659
1660 lcl_putLoadArgs( aExistentMediaDesc, optional_bool(), optional_bool() );
1661 // don't put _bSuppressMacros and _bReadOnly here - if the document was already
1662 // loaded, we should not tamper with its settings.
1663 // #i88977# #i86872#
1664
1665 xModel->attachResource( xModel->getURL(), aExistentMediaDesc.getPropertyValues() );
1666 }
1667 catch( const Exception& )
1668 {
1669 DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1669" ": ", "dbaccess" );
;
1670 }
1671 }
1672 }
1673
1674 // set the OfficeDatabaseDocument instance as parent of the embedded document
1675 // #i40358#
1676 Reference< XChild > xDepdendDocAsChild( getComponent(), UNO_QUERY );
1677 if ( xDepdendDocAsChild.is() )
1678 {
1679 try
1680 {
1681 if ( !xDepdendDocAsChild->getParent().is() )
1682 { // first encounter
1683 xDepdendDocAsChild->setParent( getDataSource( m_xParentContainer ) );
1684 }
1685 }
1686 catch( const Exception& )
1687 {
1688 DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1688" ": ", "dbaccess" );
;
1689 }
1690 }
1691
1692 if ( i_rConnection.is() )
1693 m_xLastKnownConnection = i_rConnection;
1694}
1695
1696void ODocumentDefinition::onCommandPreview(Any& _rImage)
1697{
1698 loadEmbeddedObjectForPreview();
1699 if ( !m_xEmbeddedObject.is() )
1700 return;
1701
1702 try
1703 {
1704 Reference<XTransferable> xTransfer(getComponent(),UNO_QUERY);
1705 if ( xTransfer.is() )
1706 {
1707 DataFlavor aFlavor;
1708 aFlavor.MimeType = "image/png";
1709 aFlavor.HumanPresentableName = "Portable Network Graphics";
1710 aFlavor.DataType = cppu::UnoType<Sequence < sal_Int8 >>::get();
1711
1712 _rImage = xTransfer->getTransferData( aFlavor );
1713 }
1714 }
1715 catch( const Exception& )
1716 {
1717 }
1718}
1719
1720void ODocumentDefinition::getPropertyDefaultByHandle( sal_Int32 /*_nHandle*/, Any& _rDefault ) const
1721{
1722 _rDefault.clear();
1723}
1724
1725void ODocumentDefinition::onCommandGetDocumentProperties( Any& _rProps )
1726{
1727 loadEmbeddedObjectForPreview();
1
Calling 'ODocumentDefinition::loadEmbeddedObjectForPreview'
1728 if ( !m_xEmbeddedObject.is() )
1729 return;
1730
1731 try
1732 {
1733 Reference<XDocumentPropertiesSupplier> xDocSup(
1734 getComponent(), UNO_QUERY );
1735 if ( xDocSup.is() )
1736 _rProps <<= xDocSup->getDocumentProperties();
1737 }
1738 catch( const Exception& )
1739 {
1740 DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1740" ": ", "dbaccess" );
;
1741 }
1742}
1743
1744Reference< util::XCloseable > ODocumentDefinition::impl_getComponent_throw( const bool i_ForceCreate )
1745{
1746 OSL_ENSURE(m_xEmbeddedObject.is(),"Illegal call for embeddedObject")do { if (true && (!(m_xEmbeddedObject.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1746" ": "), "%s", "Illegal call for embeddedObject"); }
} while (false)
;
1747 Reference< util::XCloseable > xComp;
1748 if ( m_xEmbeddedObject.is() )
1749 {
1750 int nState = m_xEmbeddedObject->getCurrentState();
1751 if ( ( nState == EmbedStates::LOADED ) && i_ForceCreate )
1752 {
1753 m_xEmbeddedObject->changeState( EmbedStates::RUNNING );
1754 nState = m_xEmbeddedObject->getCurrentState();
1755 OSL_ENSURE( nState == EmbedStates::RUNNING, "ODocumentDefinition::impl_getComponent_throw: could not switch to RUNNING!" )do { if (true && (!(nState == EmbedStates::RUNNING)))
{ sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1755" ": "), "%s", "ODocumentDefinition::impl_getComponent_throw: could not switch to RUNNING!"
); } } while (false)
;
1756 }
1757
1758 if ( nState == EmbedStates::ACTIVE || nState == EmbedStates::RUNNING )
1759 {
1760 if ( m_xEmbeddedObject.is() )
1761 {
1762 xComp = m_xEmbeddedObject->getComponent();
1763 OSL_ENSURE(xComp.is(),"No valid component")do { if (true && (!(xComp.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1763" ": "), "%s", "No valid component"); } } while (false
)
;
1764 }
1765 }
1766 }
1767 return xComp;
1768}
1769
1770Reference< util::XCloseable > ODocumentDefinition::getComponent()
1771{
1772 ::osl::MutexGuard aGuard( m_aMutex );
1773 return impl_getComponent_throw();
1774}
1775
1776namespace
1777{
1778 Reference< XDatabaseDocumentUI > lcl_getDatabaseDocumentUI( ODatabaseModelImpl const & _rModelImpl )
1779 {
1780 Reference< XDatabaseDocumentUI > xUI;
1781
1782 Reference< XModel > xModel( _rModelImpl.getModel_noCreate() );
1783 if ( xModel.is() )
1784 xUI.set( xModel->getCurrentController(), UNO_QUERY );
1785 return xUI;
1786 }
1787}
1788
1789Reference< XComponent > ODocumentDefinition::impl_openUI_nolck_throw( bool _bForEditing )
1790{
1791 ::osl::ClearableMutexGuard aGuard( m_aMutex );
1792 if ( !m_pImpl || !m_pImpl->m_pDataSource )
1793 throw DisposedException();
1794
1795 Reference< XComponent > xComponent;
1796 try
1797 {
1798 Reference< XDatabaseDocumentUI > xUI( lcl_getDatabaseDocumentUI( *m_pImpl->m_pDataSource ) );
1799 if ( !xUI.is() )
1800 {
1801 // no XDatabaseDocumentUI -> just execute the respective command
1802 m_bOpenInDesign = _bForEditing;
1803 xComponent = Reference<XComponent>(onCommandOpenSomething(Any(), true, nullptr), UNO_QUERY);
1804 OSL_ENSURE( xComponent.is(), "ODocumentDefinition::impl_openUI_nolck_throw: opening the thingie failed." )do { if (true && (!(xComponent.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1804" ": "), "%s", "ODocumentDefinition::impl_openUI_nolck_throw: opening the thingie failed."
); } } while (false)
;
1805 return xComponent;
1806 }
1807
1808
1809 OUString sName( impl_getHierarchicalName( false ) );
1810 sal_Int32 nObjectType = m_bForm ? DatabaseObject::FORM : DatabaseObject::REPORT;
1811 aGuard.clear();
1812
1813 xComponent = xUI->loadComponent(
1814 nObjectType, sName, _bForEditing
1815 );
1816 }
1817 catch( const RuntimeException& ) { throw; }
1818 catch( const Exception& )
1819 {
1820 throw WrappedTargetException(
1821 OUString(), *this, ::cppu::getCaughtException() );
1822 }
1823
1824 return xComponent;
1825}
1826
1827void ODocumentDefinition::impl_store_throw()
1828{
1829 Reference<XEmbedPersist> xPersist( m_xEmbeddedObject, UNO_QUERY );
1830 if ( xPersist.is() )
1831 {
1832 xPersist->storeOwn();
1833 notifyDataSourceModified();
1834 }
1835}
1836
1837bool ODocumentDefinition::impl_close_throw()
1838{
1839 bool bSuccess = prepareClose();
1840 if ( bSuccess && m_xEmbeddedObject.is() )
1841 {
1842 m_xEmbeddedObject->changeState( EmbedStates::LOADED );
1843 bSuccess = m_xEmbeddedObject->getCurrentState() == EmbedStates::LOADED;
1844 }
1845 return bSuccess;
1846}
1847
1848Reference< XComponent > SAL_CALL ODocumentDefinition::open( )
1849{
1850 return impl_openUI_nolck_throw( false );
1851}
1852
1853Reference< XComponent > SAL_CALL ODocumentDefinition::openDesign( )
1854{
1855 return impl_openUI_nolck_throw( true );
1856}
1857
1858void SAL_CALL ODocumentDefinition::store( )
1859{
1860 ::osl::MutexGuard aGuard( m_aMutex );
1861 try
1862 {
1863 impl_store_throw();
1864 }
1865 catch( const RuntimeException& ) { throw; }
1866 catch( const Exception& )
1867 {
1868 throw WrappedTargetException(
1869 OUString(), *this, ::cppu::getCaughtException() );
1870 }
1871}
1872
1873sal_Bool SAL_CALL ODocumentDefinition::close( )
1874{
1875 ::osl::MutexGuard aGuard( m_aMutex );
1876
1877 bool bSuccess = false;
1878 try
1879 {
1880 bSuccess = impl_close_throw();
1881 }
1882 catch( const RuntimeException& ) { throw; }
1883 catch( const Exception& )
1884 {
1885 throw WrappedTargetException(
1886 OUString(), *this, ::cppu::getCaughtException() );
1887 }
1888 return bSuccess;
1889}
1890
1891OUString SAL_CALL ODocumentDefinition::getHierarchicalName()
1892{
1893 ::osl::MutexGuard aGuard( m_aMutex );
1894 return impl_getHierarchicalName( false );
1895}
1896
1897OUString SAL_CALL ODocumentDefinition::composeHierarchicalName( const OUString& i_rRelativeName )
1898{
1899 OUStringBuffer aBuffer;
1900 aBuffer.append( getHierarchicalName() );
1901 aBuffer.append( '/' );
1902 aBuffer.append( i_rRelativeName );
1903 return aBuffer.makeStringAndClear();
1904}
1905
1906void SAL_CALL ODocumentDefinition::rename( const OUString& _rNewName )
1907{
1908 try
1909 {
1910 ::osl::ResettableMutexGuard aGuard(m_aMutex);
1911 if ( _rNewName == m_pImpl->m_aProps.aTitle )
1912 return;
1913
1914 // document definitions are organized in a hierarchical way, so reject names
1915 // which contain a /, as this is reserved for hierarchy level separation
1916 if ( _rNewName.indexOf( '/' ) != -1 )
1917 m_aErrorHelper.raiseException( ErrorCondition::DB_OBJECT_NAME_WITH_SLASHES, *this );
1918
1919 NameChangeNotifier aNameChangeAndNotify( *this, _rNewName, aGuard );
1920 m_pImpl->m_aProps.aTitle = _rNewName;
1921
1922 if ( m_xEmbeddedObject.is() && m_xEmbeddedObject->getCurrentState() == EmbedStates::ACTIVE )
1923 updateDocumentTitle();
1924 }
1925 catch(const PropertyVetoException&)
1926 {
1927 throw ElementExistException(_rNewName,*this);
1928 }
1929}
1930
1931Reference< XStorage> ODocumentDefinition::getContainerStorage() const
1932{
1933 return m_pImpl->m_pDataSource
1934 ? m_pImpl->m_pDataSource->getStorage( m_bForm ? ODatabaseModelImpl::E_FORM : ODatabaseModelImpl::E_REPORT )
1935 : Reference< XStorage>();
1936}
1937
1938bool ODocumentDefinition::isModified()
1939{
1940 osl::ClearableGuard< osl::Mutex > aGuard(m_aMutex);
1941 bool bRet = false;
1942 if ( m_xEmbeddedObject.is() )
1943 {
1944 Reference<XModifiable> xModel(getComponent(),UNO_QUERY);
1945 bRet = xModel.is() && xModel->isModified();
1946 }
1947 return bRet;
1948}
1949
1950bool ODocumentDefinition::prepareClose()
1951{
1952 if ( !m_xEmbeddedObject.is() )
1953 return true;
1954
1955 try
1956 {
1957 // suspend the controller. Embedded objects are not allowed to raise
1958 // own UI at their own discretion, instead, this has always to be triggered
1959 // by the embedding component. Thus, we do the suspend call here.
1960 // #i49370#
1961
1962 Reference< util::XCloseable > xComponent( impl_getComponent_throw( false ) );
1963 if ( !xComponent.is() )
1964 return true;
1965
1966 Reference< XModel > xModel( xComponent, UNO_QUERY );
1967 Reference< XController > xController;
1968 if ( xModel.is() )
1969 xController = xModel->getCurrentController();
1970
1971 OSL_ENSURE( xController.is() || ( m_xEmbeddedObject->getCurrentState() < EmbedStates::ACTIVE ),do { if (true && (!(xController.is() || ( m_xEmbeddedObject
->getCurrentState() < EmbedStates::ACTIVE )))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1972" ": "), "%s", "ODocumentDefinition::prepareClose: no controller!"
); } } while (false)
1972 "ODocumentDefinition::prepareClose: no controller!" )do { if (true && (!(xController.is() || ( m_xEmbeddedObject
->getCurrentState() < EmbedStates::ACTIVE )))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "1972" ": "), "%s", "ODocumentDefinition::prepareClose: no controller!"
); } } while (false)
;
1973 if ( !xController.is() )
1974 // document has not yet been activated, i.e. has no UI, yet
1975 return true;
1976
1977 if (!xController->suspend(true))
1978 // controller vetoed the closing
1979 return false;
1980
1981 if ( isModified() )
1982 {
1983 Reference< XFrame > xFrame( xController->getFrame() );
1984 Reference<XTopWindow> xTopWindow;
1985 if ( xFrame.is() )
1986 {
1987 xTopWindow = Reference<XTopWindow>(xFrame->getContainerWindow(), UNO_QUERY_THROW);
1988 xTopWindow->toFront();
1989 }
1990 if (!save(true, xTopWindow))
1991 {
1992 // revert suspension
1993 xController->suspend(false);
1994 // saving failed or was cancelled
1995 return false;
1996 }
1997 }
1998 }
1999 catch( const Exception& )
2000 {
2001 DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "2001" ": ", "dbaccess" );
;
2002 }
2003
2004 return true;
2005}
2006
2007void ODocumentDefinition::fillReportData( const Reference< XComponentContext >& _rContext,
2008 const Reference< util::XCloseable >& _rxComponent,
2009 const Reference< XConnection >& _rxActiveConnection )
2010{
2011 uno::Sequence<uno::Any> aArgs(comphelper::InitAnyPropertySequence(
2012 {
2013 {"TextDocument", uno::Any(_rxComponent)},
2014 {"ActiveConnection", uno::Any(_rxActiveConnection)}
2015 }));
2016 try
2017 {
2018 Reference< XJobExecutor > xExecutable(
2019 _rContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.wizards.report.CallReportWizard", aArgs, _rContext), UNO_QUERY_THROW );
2020 xExecutable->trigger( "fill" );
2021 }
2022 catch( const Exception& )
2023 {
2024 DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.cxx"
":" "2024" ": ", "dbaccess" );
;
2025 }
2026}
2027
2028void ODocumentDefinition::updateDocumentTitle()
2029{
2030 OUString sName = m_pImpl->m_aProps.aTitle;
2031 if ( m_pImpl->m_pDataSource )
2032 {
2033 if ( sName.isEmpty() )
2034 {
2035 if ( m_bForm )
2036 sName = DBA_RES( RID_STR_FORM )::dbaccess::ResourceManager::loadString( reinterpret_cast<
char const *>("RID_STR_FORM" "\004" u8"Form") )
;
2037 else
2038 sName = DBA_RES( RID_STR_REPORT )::dbaccess::ResourceManager::loadString( reinterpret_cast<
char const *>("RID_STR_REPORT" "\004" u8"Report") )
;
2039 Reference< XUntitledNumbers > xUntitledProvider(m_pImpl->m_pDataSource->getModel_noCreate(), UNO_QUERY );
2040 if ( xUntitledProvider.is() )
2041 sName += OUString::number( xUntitledProvider->leaseNumber(getComponent()) );
2042 }
2043
2044 Reference< XTitle > xDatabaseDocumentModel(m_pImpl->m_pDataSource->getModel_noCreate(),uno::UNO_QUERY);
2045 if ( xDatabaseDocumentModel.is() )
2046 sName = xDatabaseDocumentModel->getTitle() + " : " + sName;
2047 }
2048 Reference< XTitle> xTitle(getComponent(),UNO_QUERY);
2049 if ( xTitle.is() )
2050 xTitle->setTitle(sName);
2051}
2052
2053void SAL_CALL ODocumentDefinition::queryClosing( const lang::EventObject&, sal_Bool )
2054{
2055 try
2056 {
2057 if ( !close() )
2058 throw util::CloseVetoException();
2059 }
2060 catch(const lang::WrappedTargetException&)
2061 {
2062 throw util::CloseVetoException();
2063 }
2064}
2065
2066void SAL_CALL ODocumentDefinition::notifyClosing( const lang::EventObject& /*Source*/ )
2067{
2068}
2069
2070void SAL_CALL ODocumentDefinition::disposing( const lang::EventObject& /*Source*/ )
2071{
2072}
2073
2074void ODocumentDefinition::firePropertyChange( sal_Int32 i_nHandle, const Any& i_rNewValue, const Any& i_rOldValue,
2075 bool i_bVetoable, const NotifierAccess& )
2076{
2077 fire( &i_nHandle, &i_rNewValue, &i_rOldValue, 1, i_bVetoable );
2078}
2079
2080// NameChangeNotifier
2081NameChangeNotifier::NameChangeNotifier( ODocumentDefinition& i_rDocumentDefinition, const OUString& i_rNewName,
2082 ::osl::ResettableMutexGuard& i_rClearForNotify )
2083 :m_rDocumentDefinition( i_rDocumentDefinition )
2084 ,m_aOldValue( makeAny( i_rDocumentDefinition.getCurrentName() ) )
2085 ,m_aNewValue( makeAny( i_rNewName ) )
2086 ,m_rClearForNotify( i_rClearForNotify )
2087{
2088 impl_fireEvent_throw( true );
2089}
2090
2091NameChangeNotifier::~NameChangeNotifier()
2092{
2093 impl_fireEvent_throw( false );
2094}
2095
2096void NameChangeNotifier::impl_fireEvent_throw( const bool i_bVetoable )
2097{
2098 m_rClearForNotify.clear();
2099 m_rDocumentDefinition.firePropertyChange(
2100 PROPERTY_ID_NAME7, m_aNewValue, m_aOldValue, i_bVetoable, ODocumentDefinition::NotifierAccess() );
2101 m_rClearForNotify.reset();
2102}
2103
2104} // namespace dbaccess
2105
2106/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/dbaccess/source/core/dataaccess/documentdefinition.hxx

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#include <cppuhelper/propshlp.hxx>
23#include <cppuhelper/implbase4.hxx>
24#include <ContentHelper.hxx>
25#include <comphelper/propertystatecontainer.hxx>
26#include <comphelper/proparrhlp.hxx>
27#include <apitools.hxx>
28#include <comphelper/uno3.hxx>
29#include <com/sun/star/awt/XTopWindow.hpp>
30#include <com/sun/star/sdbc/XConnection.hpp>
31#include <com/sun/star/frame/XController.hpp>
32#include <com/sun/star/embed/XStateChangeListener.hpp>
33#include <com/sun/star/embed/XEmbeddedObject.hpp>
34#include <com/sun/star/embed/XStorage.hpp>
35#include <com/sun/star/sdb/XSubDocument.hpp>
36#include <com/sun/star/util/XCloseListener.hpp>
37#include <com/sun/star/container/XHierarchicalName.hpp>
38#include <rtl/ref.hxx>
39
40namespace comphelper
41{
42 class NamedValueCollection;
43}
44
45namespace dbaccess
46{
47
48 class OInterceptor;
49 class OEmbeddedClientHelper;
50// ODocumentDefinition - a database "document" which is simply a link to a real
51// document
52
53typedef ::cppu::ImplHelper4 < css::embed::XComponentSupplier
54 , css::sdb::XSubDocument
55 , css::util::XCloseListener
56 , css::container::XHierarchicalName
57 > ODocumentDefinition_Base;
58
59class ODocumentDefinition
60 :public OContentHelper
61 ,public ::comphelper::OPropertyStateContainer
62 ,public ::comphelper::OPropertyArrayUsageHelper< ODocumentDefinition >
63 ,public ODocumentDefinition_Base
64{
65 css::uno::Reference< css::embed::XEmbeddedObject> m_xEmbeddedObject;
66 css::uno::Reference< css::embed::XStateChangeListener > m_xListener;
67 css::uno::Reference< css::sdbc::XConnection > m_xLastKnownConnection;
68
69 rtl::Reference<OInterceptor> m_pInterceptor;
70 bool m_bForm; // <TRUE/> if it is a form
71 bool m_bOpenInDesign;
72 bool m_bInExecute;
73 bool m_bRemoveListener;
74 rtl::Reference<OEmbeddedClientHelper> m_pClientHelper;
75
76protected:
77 virtual ~ODocumentDefinition() override;
78
79public:
80
81 ODocumentDefinition(
82 const css::uno::Reference< css::uno::XInterface >& _rxContainer,
83 const css::uno::Reference< css::uno::XComponentContext >&,
84 const TContentPtr& _pImpl,
85 bool _bForm
86 );
87
88 void initialLoad(
89 const css::uno::Sequence< sal_Int8 >& i_rClassID,
90 const css::uno::Sequence< css::beans::PropertyValue >& i_rCreationArgs,
91 const css::uno::Reference< css::sdbc::XConnection >& i_rConnection
92 );
93
94 virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override;
95 virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override;
96
97// css::uno::XInterface
98 DECLARE_XINTERFACE( )virtual css::uno::Any queryInterface( const css::uno::Type&
aType ) override; virtual void acquire() throw() override; virtual
void release() throw() override;
99
100// css::beans::XPropertySet
101 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
102
103 // OPropertySetHelper
104 virtual void SAL_CALL getFastPropertyValue(
105 css::uno::Any& o_rValue,
106 sal_Int32 i_nHandle
107 ) const override;
108
109 // XComponentSupplier
110 virtual css::uno::Reference< css::util::XCloseable > SAL_CALL getComponent( ) override;
111
112 // XSubDocument
113 virtual css::uno::Reference< css::lang::XComponent > SAL_CALL open( ) override;
114 virtual css::uno::Reference< css::lang::XComponent > SAL_CALL openDesign( ) override;
115 virtual void SAL_CALL store( ) override;
116 virtual sal_Bool SAL_CALL close( ) override;
117
118 // XHierarchicalName
119 virtual OUString SAL_CALL getHierarchicalName( ) override;
120 virtual OUString SAL_CALL composeHierarchicalName( const OUString& aRelativeName ) override;
121
122// OPropertySetHelper
123 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
124
125 // XCommandProcessor
126 virtual css::uno::Any SAL_CALL execute( const css::ucb::Command& aCommand, sal_Int32 CommandId, const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment ) override ;
127
128 // XRename
129 virtual void SAL_CALL rename( const OUString& newName ) override;
130
131 // XCloseListener
132 virtual void SAL_CALL queryClosing( const css::lang::EventObject& Source, sal_Bool GetsOwnership ) override;
133 virtual void SAL_CALL notifyClosing( const css::lang::EventObject& Source ) override;
134
135 // XEventListener
136 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
137
138 /** returns the forms/reports container storage, depending on m_bForm. Our own storage
139 inside this container storage is the one with the name as indicated by m_pImpl->m_aProps.sPersistentName.
140 */
141 css::uno::Reference< css::embed::XStorage >
142 getContainerStorage() const;
143
144 bool save(bool _bApprove, const css::uno::Reference<css::awt::XTopWindow>& rDialogParent);
145 void saveAs();
146 void closeObject();
147 bool isModified();
148 bool isNewReport() const { return !m_bForm && !m_pImpl->m_aProps.bAsTemplate; }
149
150 static void fillReportData(
151 const css::uno::Reference< css::uno::XComponentContext > & _rxContext,
152 const css::uno::Reference< css::util::XCloseable >& _rxComponent,
153 const css::uno::Reference< css::sdbc::XConnection >& _rxActiveConnection
154 );
155
156 const css::uno::Reference< css::sdbc::XConnection >&
157 getConnection() const { return m_xLastKnownConnection; }
158
159 /** prepares closing the document component
160
161 The method suspends the controller associated with the document, and saves the document
162 if necessary.
163
164 @return
165 <TRUE/> if and only if the document component can be closed
166 */
167 bool prepareClose();
168
169 static OUString GetDocumentServiceFromMediaType(
170 const OUString& _rMediaType,
171 const css::uno::Reference< css::uno::XComponentContext > & _rxContext,
172 css::uno::Sequence< sal_Int8 >& _rClassId
173 );
174 static OUString GetDocumentServiceFromMediaType(
175 const css::uno::Reference< css::embed::XStorage >& _rxContainerStorage,
176 const OUString& _rEntityName,
177 const css::uno::Reference< css::uno::XComponentContext > & _rxContext,
178 css::uno::Sequence< sal_Int8 >& _rClassId
179 );
180
181 struct NotifierAccess { friend class NameChangeNotifier; private: NotifierAccess() { } };
182 const OUString& getCurrentName() const { return m_pImpl->m_aProps.aTitle; }
183 void firePropertyChange(
184 sal_Int32 i_nHandle,
185 const css::uno::Any& i_rNewValue,
186 const css::uno::Any& i_rOldValue,
187 bool i_bVetoable,
188 const NotifierAccess&
189 );
190
191private:
192 /** does necessary initializations after our embedded object has been switched to ACTIVE
193 */
194 void impl_onActivateEmbeddedObject_nothrow( const bool i_bReactivated );
195
196 /** initializes a newly created view/controller of a form which is displaying our embedded object
197
198 Has only to be called if the respective embedded object has been loaded for design (and
199 not for data entry)
200
201 @param _rxController
202 the controller which belongs to the XModel of our (active) embedded object
203 */
204 static void impl_initFormEditView( const css::uno::Reference< css::frame::XController >& _rxController );
205
206 /** removes the given frame from the desktop's frame collection
207 @throws css::uno::RuntimeException
208 */
209 static void impl_removeFrameFromDesktop_throw(
210 const css::uno::Reference< css::uno::XComponentContext >& _rContxt,
211 const css::uno::Reference< css::frame::XFrame >& _rxFrame
212 );
213
214 /** opens the UI for this sub document
215 */
216 css::uno::Reference< css::lang::XComponent >
217 impl_openUI_nolck_throw( bool _bForEditing );
218
219 /** stores our document, if it's already loaded
220 */
221 void impl_store_throw();
222
223 /** closes our document, if it's open
224 */
225 bool impl_close_throw();
226
227 /** returns our component, creates it if necessary
228 */
229 css::uno::Reference< css::util::XCloseable >
230 impl_getComponent_throw( const bool i_ForceCreate = true );
231
232 /** shows or hides our component
233
234 The embedded object must exist, and be in state LOADED, at least.
235 */
236 void impl_showOrHideComponent_throw( const bool i_bShow );
237
238 // OPropertyArrayUsageHelper
239 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override;
240
241 virtual void getPropertyDefaultByHandle( sal_Int32 _nHandle, css::uno::Any& _rDefault ) const override;
242
243 // helper
244 virtual void SAL_CALL disposing() override;
245
246 // OContentHelper overridables
247 virtual OUString determineContentType() const override;
248
249 /** fills the load arguments
250 */
251 css::uno::Sequence< css::beans::PropertyValue >
252 fillLoadArgs(
253 const css::uno::Reference< css::sdbc::XConnection>& _xConnection,
254 const bool _bSuppressMacros,
255 const bool _bReadOnly,
256 const css::uno::Sequence< css::beans::PropertyValue >& i_rOpenCommandArguments,
257 css::uno::Sequence< css::beans::PropertyValue >& _out_rEmbeddedObjectDescriptor
258 );
259
260 /** splits the given arguments to an "open*" command into arguments for loading the document, and arguments to be
261 put into the EmbeddedObjectDescriptor
262
263 Any values already present in <code>o_rDocumentLoadArgs</code> and <code>o_rEmbeddedObjectDescriptor</code>
264 will be overwritten by values from <code>i_rOpenCommandArguments</code>, if applicable, otherwise they will
265 be preserved.
266
267 @param i_rOpenCommandArguments
268 the arguments passed to the "open*" command at the content
269 @param o_rDocumentLoadArgs
270 the arguments to be passed when actually loading the embedded document.
271 @param o_rEmbeddedObjectDescriptor
272 the EmbeddedObjectDescriptor to be passed when initializing the embedded object
273 */
274 static void separateOpenCommandArguments(
275 const css::uno::Sequence< css::beans::PropertyValue >& i_rOpenCommandArguments,
276 ::comphelper::NamedValueCollection& o_rDocumentLoadArgs,
277 ::comphelper::NamedValueCollection& o_rEmbeddedObjectDescriptor
278 );
279
280 /** loads the EmbeddedObject if not already loaded
281 @param _aClassID
282 If set, it will be used to create the embedded object.
283 */
284 void loadEmbeddedObject(
285 const css::uno::Reference< css::sdbc::XConnection>& _xConnection,
286 const css::uno::Sequence< sal_Int8 >& _aClassID,
287 const css::uno::Sequence< css::beans::PropertyValue >& _rAdditionalArgs,
288 const bool _bSuppressMacros,
289 const bool _bReadOnly
290 );
291
292 /** loads the embedded object for preview. Macros will be suppressed, and the document will
293 be read-only.
294 */
295 void loadEmbeddedObjectForPreview()
296 {
297 loadEmbeddedObject(
2
Calling 'ODocumentDefinition::loadEmbeddedObject'
298 nullptr,
299 css::uno::Sequence< sal_Int8 >(),
300 css::uno::Sequence< css::beans::PropertyValue >(),
301 true,
302 true
303 );
304 }
305
306 /** searches for read-only flag in the args of the model and sets it to the given value,
307 if the value was not found, it will be appended.
308 @param _bReadOnly
309 If <TRUE/> the document will be switched to readonly mode
310 */
311 void updateDocumentTitle();
312
313 void registerProperties();
314
315 /** determines whether the document we represent supports embedded scripts and macros
316 */
317 bool objectSupportsEmbeddedScripts() const;
318
319 //- commands
320
321 void onCommandGetDocumentProperties( css::uno::Any& _rProps );
322 /// @throws css::uno::Exception
323 void onCommandInsert( const OUString& _sURL, const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment );
324 void onCommandPreview( css::uno::Any& _rImage );
325 css::uno::Any
326 onCommandOpenSomething(
327 const css::uno::Any& _rArgument,
328 const bool _bActivate,
329 const css::uno::Reference< css::ucb::XCommandEnvironment >& _rxEnvironment
330 );
331private:
332 using ::cppu::OPropertySetHelper::getFastPropertyValue;
333};
334
335class NameChangeNotifier
336{
337public:
338 NameChangeNotifier(
339 ODocumentDefinition& i_rDocumentDefinition,
340 const OUString& i_rNewName,
341 ::osl::ResettableMutexGuard& i_rClearForNotify
342 );
343 ~NameChangeNotifier();
344
345private:
346 ODocumentDefinition& m_rDocumentDefinition;
347 const css::uno::Any m_aOldValue;
348 const css::uno::Any m_aNewValue;
349 ::osl::ResettableMutexGuard& m_rClearForNotify;
350
351 void impl_fireEvent_throw( const bool i_bVetoable );
352};
353
354} // namespace dbaccess
355
356/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Reference.h

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#ifndef INCLUDED_COM_SUN_STAR_UNO_REFERENCE_H
20#define INCLUDED_COM_SUN_STAR_UNO_REFERENCE_H
21
22#include "sal/config.h"
23
24#include <cassert>
25#include <cstddef>
26
27#if defined LIBO_INTERNAL_ONLY1
28#include <type_traits>
29#endif
30
31#include "rtl/alloc.h"
32
33namespace com
34{
35namespace sun
36{
37namespace star
38{
39namespace uno
40{
41
42class RuntimeException;
43class XInterface;
44class Type;
45class Any;
46
47/** Enum defining UNO_REF_NO_ACQUIRE for setting reference without acquiring a given interface.
48 Deprecated, please use SAL_NO_ACQUIRE.
49 @deprecated
50*/
51enum UnoReference_NoAcquire
52{
53 /** This enum value can be used for creating a reference granting a given interface,
54 i.e. transferring ownership to it.
55 */
56 UNO_REF_NO_ACQUIRE
57};
58
59/** This base class serves as a base class for all template reference classes and
60 has been introduced due to compiler problems with templated operators ==, =!.
61*/
62class BaseReference
63{
64protected:
65 /** the interface pointer
66 */
67 XInterface * _pInterface;
68
69 /** Queries given interface for type rType.
70
71 @param pInterface interface pointer
72 @param rType interface type
73 @return interface of demanded type (may be null)
74 */
75 inline static XInterface * SAL_CALL iquery( XInterface * pInterface, const Type & rType );
76 /** Queries given interface for type rType.
77 Throws a RuntimeException if the demanded interface cannot be queried.
78
79 @param pInterface interface pointer
80 @param rType interface type
81 @return interface of demanded type
82 */
83 inline static XInterface * SAL_CALL iquery_throw( XInterface * pInterface, const Type & rType );
84
85public:
86 /** Gets interface pointer. This call does not acquire the interface.
87
88 @return UNacquired interface pointer
89 */
90 XInterface * SAL_CALL get() const
91 { return _pInterface; }
92
93 /** Checks if reference is null.
94
95 @return true if reference acquires an interface, i.e. true if it is not null
96 */
97 bool SAL_CALL is() const
98 { return (NULL__null != _pInterface); }
13
Returning zero, which participates in a condition later
99
100#if defined LIBO_INTERNAL_ONLY1
101 /** Checks if reference is null.
102
103 @return true if reference acquires an interface, i.e. true if it is not null
104 */
105 explicit operator bool() const
106 { return is(); }
107#endif
108
109 /** Equality operator: compares two interfaces
110 Checks if both references are null or refer to the same object.
111
112 @param pInterface another interface
113 @return true if both references are null or refer to the same object, false otherwise
114 */
115 inline bool SAL_CALL operator == ( XInterface * pInterface ) const;
116 /** Inequality operator: compares two interfaces
117 Checks if both references are null or refer to the same object.
118
119 @param pInterface another interface
120 @return false if both references are null or refer to the same object, true otherwise
121 */
122 inline bool SAL_CALL operator != ( XInterface * pInterface ) const;
123
124 /** Equality operator: compares two interfaces
125 Checks if both references are null or refer to the same object.
126
127 @param rRef another reference
128 @return true if both references are null or refer to the same object, false otherwise
129 */
130 inline bool SAL_CALL operator == ( const BaseReference & rRef ) const;
131 /** Inequality operator: compares two interfaces
132 Checks if both references are null or refer to the same object.
133
134 @param rRef another reference
135 @return false if both references are null or refer to the same object, true otherwise
136 */
137 inline bool SAL_CALL operator != ( const BaseReference & rRef ) const;
138
139 /** Needed by some STL containers.
140
141 @param rRef another reference
142 @return true, if this reference is less than rRef
143 */
144 inline bool SAL_CALL operator < ( const BaseReference & rRef ) const;
145};
146
147/** Enum defining UNO_QUERY for implicit interface query.
148*/
149enum UnoReference_Query
150{
151 /** This enum value can be used for implicit interface query.
152 */
153 UNO_QUERY
154};
155/** Enum defining UNO_QUERY_THROW for implicit interface query.
156 If the demanded interface is unavailable, then a RuntimeException is thrown.
157*/
158enum UnoReference_QueryThrow
159{
160 /** This enum value can be used for implicit interface query.
161 */
162 UNO_QUERY_THROW
163};
164/** Enum defining UNO_SET_THROW for throwing if attempts are made to assign a null
165 interface
166
167 @since UDK 3.2.8
168*/
169enum UnoReference_SetThrow
170{
171 UNO_SET_THROW
172};
173
174/** Template reference class for interface type derived from BaseReference.
175 A special constructor given the UNO_QUERY identifier queries interfaces
176 for reference type.
177*/
178template< class interface_type >
179class SAL_DLLPUBLIC_RTTI__attribute__ ((type_visibility("default"))) Reference : public BaseReference
180{
181 /** Queries given interface for type interface_type.
182
183 @param pInterface interface pointer
184 @return interface of demanded type (may be null)
185 */
186 inline static XInterface * SAL_CALL iquery( XInterface * pInterface );
187 /** Queries given interface for type interface_type.
188 Throws a RuntimeException if the demanded interface cannot be queried.
189
190 @param pInterface interface pointer
191 @return interface of demanded type
192 */
193 inline static XInterface * SAL_CALL iquery_throw( XInterface * pInterface );
194 /** Returns the given interface if it is not <NULL/>, throws a RuntimeException otherwise.
195
196 @param pInterface interface pointer
197 @return pInterface
198 */
199 inline static interface_type * SAL_CALL iset_throw( interface_type * pInterface );
200
201 /** Cast from an "interface pointer" (e.g., BaseReference::_pInterface) to a
202 pointer to this interface_type.
203
204 To work around ambiguities in the case of multiple-inheritance interface
205 types (which inherit XInterface more than once), use reinterpret_cast
206 (resp. a sequence of two static_casts, to avoid warnings about
207 reinterpret_cast used between related classes) to switch from a pointer
208 to XInterface to a pointer to this derived interface_type. In
209 principle, this is not guaranteed to work. In practice, it seems to
210 work on all supported platforms.
211 */
212 static interface_type * castFromXInterface(XInterface * p) {
213 return static_cast< interface_type * >(static_cast< void * >(p));
214 }
215
216 /** Cast from a pointer to this interface_type to an "interface pointer"
217 (e.g., BaseReference::_pInterface).
218
219 To work around ambiguities in the case of multiple-inheritance interface
220 types (which inherit XInterface more than once), use reinterpret_cast
221 (resp. a sequence of two static_casts, to avoid warnings about
222 reinterpret_cast used between related classes) to switch from a pointer
223 to this derived interface_type to a pointer to XInterface. In
224 principle, this is not guaranteed to work. In practice, it seems to
225 work on all supported platforms.
226 */
227 static XInterface * castToXInterface(interface_type * p) {
228 return static_cast< XInterface * >(static_cast< void * >(p));
229 }
230
231public:
232 /// @cond INTERNAL
233 // these are here to force memory de/allocation to sal lib.
234 static void * SAL_CALL operator new ( ::size_t nSize )
235 { return ::rtl_allocateMemory( nSize ); }
236 static void SAL_CALL operator delete ( void * pMem )
237 { ::rtl_freeMemory( pMem ); }
238 static void * SAL_CALL operator new ( ::size_t, void * pMem )
239 { return pMem; }
240 static void SAL_CALL operator delete ( void *, void * )
241 {}
242 /// @endcond
243
244 /** Destructor: Releases interface if set.
245 */
246 inline ~Reference() COVERITY_NOEXCEPT_FALSE;
247
248 /** Default Constructor: Sets null reference.
249 */
250 inline Reference();
251
252 /** Copy constructor: Copies interface reference.
253
254 @param rRef another reference
255 */
256 inline Reference( const Reference< interface_type > & rRef );
257
258#if defined LIBO_INTERNAL_ONLY1
259 /** Move constructor
260
261 @param rRef another reference
262 */
263 inline Reference( Reference< interface_type > && rRef ) noexcept;
264
265 /** Up-casting conversion constructor: Copies interface reference.
266
267 Does not work for up-casts to ambiguous bases. For the special case of
268 up-casting to Reference< XInterface >, see the corresponding conversion
269 operator.
270
271 @param rRef another reference
272 */
273 template< class derived_type >
274 inline Reference(
275 const Reference< derived_type > & rRef,
276 std::enable_if_t<
277 std::is_base_of_v<interface_type, derived_type>
278 && !std::is_same_v<interface_type, XInterface>, void *> = nullptr);
279#endif
280
281 /** Constructor: Sets given interface pointer.
282
283 @param pInterface an interface pointer
284 */
285 inline Reference( interface_type * pInterface );
286
287 /** Constructor: Sets given interface pointer without acquiring it.
288
289 @param pInterface another reference
290 @param dummy SAL_NO_ACQUIRE to force obvious distinction to other constructors
291 */
292 inline Reference( interface_type * pInterface, __sal_NoAcquire dummy);
293 /** Constructor: Sets given interface pointer without acquiring it.
294 Deprecated, please use SAL_NO_ACQUIRE version.
295
296 @deprecated
297 @param pInterface another reference
298 @param dummy UNO_REF_NO_ACQUIRE to force obvious distinction to other constructors
299 */
300 inline SAL_DEPRECATED("use SAL_NO_ACQUIRE version")__attribute__((deprecated("use SAL_NO_ACQUIRE version"))) Reference( interface_type * pInterface, UnoReference_NoAcquire dummy );
301
302 /** Constructor: Queries given interface for reference interface type (interface_type).
303
304 @param rRef another reference
305 @param dummy UNO_QUERY to force obvious distinction to other constructors
306 */
307 inline Reference( const BaseReference & rRef, UnoReference_Query dummy );
308 /** Constructor: Queries given interface for reference interface type (interface_type).
309
310 @param pInterface an interface pointer
311 @param dummy UNO_QUERY to force obvious distinction to other constructors
312 */
313 inline Reference( XInterface * pInterface, UnoReference_Query dummy);
314 /** Constructor: Queries given any for reference interface type (interface_type).
315
316 @param rAny an any
317 @param dummy UNO_QUERY to force obvious distinction to other constructors
318 */
319 inline Reference( const Any & rAny, UnoReference_Query dummy);
320 /** Constructor: Queries given interface for reference interface type (interface_type).
321 Throws a RuntimeException if the demanded interface cannot be queried.
322
323 @param rRef another reference
324 @param dummy UNO_QUERY_THROW to force obvious distinction
325 to other constructors
326 */
327 inline Reference( const BaseReference & rRef, UnoReference_QueryThrow dummy );
328#ifdef LIBO_INTERNAL_ONLY1
329 /**
330 Prevent code from calling the QUERY_THROW constructor, when they meant to use the SET_THROW constructor.
331 */
332 Reference( const Reference< interface_type > & rRef, UnoReference_QueryThrow dummy ) = delete;
333#endif
334 /** Constructor: Queries given interface for reference interface type (interface_type).
335 Throws a RuntimeException if the demanded interface cannot be queried.
336
337 @param pInterface an interface pointer
338 @param dummy UNO_QUERY_THROW to force obvious distinction
339 to other constructors
340 */
341 inline Reference( XInterface * pInterface, UnoReference_QueryThrow dummy );
342 /** Constructor: Queries given any for reference interface type (interface_type).
343 Throws a RuntimeException if the demanded interface cannot be queried.
344
345 @param rAny an any
346 @param dummy UNO_QUERY_THROW to force obvious distinction
347 to other constructors
348 */
349 inline Reference( const Any & rAny, UnoReference_QueryThrow dummy );
350 /** Constructor: assigns from the given interface of the same type. Throws a RuntimeException
351 if the source interface is NULL.
352
353 @param rRef another interface reference of the same type
354 @param dummy UNO_SET_THROW to distinguish from default copy constructor
355
356 @since UDK 3.2.8
357 */
358 inline Reference( const Reference< interface_type > & rRef, UnoReference_SetThrow dummy );
359 /** Constructor: assigns from the given interface of the same type. Throws a RuntimeException
360 if the source interface is NULL.
361
362 @param pInterface an interface pointer
363 @param dummy UNO_SET_THROW to distinguish from default assignment constructor
364
365 @since UDK 3.2.8
366 */
367 inline Reference( interface_type * pInterface, UnoReference_SetThrow dummy );
368
369 /** Cast operator to Reference< XInterface >: Reference objects are binary compatible and
370 any interface must be derived from com.sun.star.uno.XInterface.
371 This a useful direct cast possibility.
372 */
373 SAL_CALL operator const Reference< XInterface > & () const
374 { return * reinterpret_cast< const Reference< XInterface > * >( this ); }
375
376 /** Dereference operator: Used to call interface methods.
377
378 @return UNacquired interface pointer
379 */
380 interface_type * SAL_CALL operator -> () const {
381 assert(_pInterface != NULL)(static_cast <bool> (_pInterface != __null) ? void (0) :
__assert_fail ("_pInterface != NULL", "/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Reference.h"
, 381, __extension__ __PRETTY_FUNCTION__))
;
382 return castFromXInterface(_pInterface);
383 }
384
385 /** Indirection operator.
386
387 @since LibreOffice 6.3
388 @return UNacquired interface reference
389 */
390 interface_type & SAL_CALL operator * () const {
391 assert(_pInterface != NULL)(static_cast <bool> (_pInterface != __null) ? void (0) :
__assert_fail ("_pInterface != NULL", "/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Reference.h"
, 391, __extension__ __PRETTY_FUNCTION__))
;
392 return *castFromXInterface(_pInterface);
393 }
394
395 /** Gets interface pointer. This call does not acquire the interface.
396
397 @return UNacquired interface pointer
398 */
399 interface_type * SAL_CALL get() const
400 { return castFromXInterface(_pInterface); }
401
402 /** Clears reference, i.e. releases interface. Reference is null after clear() call.
403 */
404 inline void SAL_CALL clear();
405
406 /** Sets the given interface. An interface already set will be released.
407
408 @param rRef another reference
409 @return true, if non-null interface was set
410 */
411 inline bool SAL_CALL set( const Reference< interface_type > & rRef );
412 /** Sets the given interface. An interface already set will be released.
413
414 @param pInterface another interface
415 @return true, if non-null interface was set
416 */
417 inline bool SAL_CALL set( interface_type * pInterface );
418
419 /** Sets interface pointer without acquiring it. An interface already set will be released.
420
421 @param pInterface an interface pointer
422 @param dummy SAL_NO_ACQUIRE to force obvious distinction to set methods
423 @return true, if non-null interface was set
424 */
425 inline bool SAL_CALL set( interface_type * pInterface, __sal_NoAcquire dummy);
426 /** Sets interface pointer without acquiring it. An interface already set will be released.
427 Deprecated, please use SAL_NO_ACQUIRE version.
428
429 @deprecated
430 @param pInterface an interface pointer
431 @param dummy UNO_REF_NO_ACQUIRE to force obvious distinction to set methods
432 @return true, if non-null interface was set
433 */
434 inline SAL_DEPRECATED("use SAL_NO_ACQUIRE version")__attribute__((deprecated("use SAL_NO_ACQUIRE version"))) bool SAL_CALL set( interface_type * pInterface, UnoReference_NoAcquire dummy);
435
436 /** Queries given interface for reference interface type (interface_type) and sets it.
437 An interface already set will be released.
438
439 @param pInterface an interface pointer
440 @param dummy UNO_QUERY to force obvious distinction to set methods
441 @return true, if non-null interface was set
442 */
443 inline bool SAL_CALL set( XInterface * pInterface, UnoReference_Query dummy );
444 /** Queries given interface for reference interface type (interface_type) and sets it.
445 An interface already set will be released.
446
447 @param rRef another reference
448 @param dummy UNO_QUERY to force obvious distinction to set methods
449 @return true, if non-null interface was set
450 */
451 inline bool SAL_CALL set( const BaseReference & rRef, UnoReference_Query dummy);
452
453 /** Queries given any for reference interface type (interface_type)
454 and sets it. An interface already set will be released.
455
456 @param rAny
457 an Any containing an interface
458 @param dummy
459 UNO_QUERY to force obvious distinction
460 to set methods
461 @return
462 true, if non-null interface was set
463 */
464 inline bool set( Any const & rAny, UnoReference_Query dummy );
465
466 /** Queries given interface for reference interface type (interface_type) and sets it.
467 An interface already set will be released.
468 Throws a RuntimeException if the demanded interface cannot be set.
469
470 @param pInterface an interface pointer
471 @param dummy UNO_QUERY_THROW to force obvious distinction
472 to set methods
473 */
474 inline void SAL_CALL set( XInterface * pInterface, UnoReference_QueryThrow dummy );
475 /** Queries given interface for reference interface type (interface_type) and sets it.
476 An interface already set will be released.
477 Throws a RuntimeException if the demanded interface cannot be set.
478
479 @param rRef another reference
480 @param dummy UNO_QUERY_THROW to force obvious distinction
481 to set methods
482 */
483 inline void SAL_CALL set( const BaseReference & rRef, UnoReference_QueryThrow dummy );
484#ifdef LIBO_INTERNAL_ONLY1
485 /**
486 Prevent code from calling the QUERY_THROW version, when they meant to use the SET_THROW version.
487 */
488 void set( const Reference< interface_type > & rRef, UnoReference_QueryThrow dummy ) = delete;
489#endif
490
491 /** Queries given any for reference interface type (interface_type) and
492 sets it. An interface already set will be released.
493 Throws a RuntimeException if the demanded interface cannot be set.
494
495 @param rAny
496 an Any containing an interface
497 @param dummy
498 UNO_QUERY_THROW to force obvious distinction to set methods
499 */
500 inline void set( Any const & rAny, UnoReference_QueryThrow dummy);
501 /** sets the given interface
502 An interface already set will be released.
503 Throws a RuntimeException if the source interface is @b NULL.
504
505 @param pInterface an interface pointer
506 @param dummy UNO_SET_THROW to force obvious distinction to other set methods
507
508 @since UDK 3.2.8
509 */
510 inline void SAL_CALL set( interface_type * pInterface, UnoReference_SetThrow dummy);
511 /** sets the given interface
512 An interface already set will be released.
513 Throws a RuntimeException if the source interface is @b NULL.
514
515 @param rRef an interface reference
516 @param dummy UNO_SET_THROW to force obvious distinction to other set methods
517
518 @since UDK 3.2.8
519 */
520 inline void SAL_CALL set( const Reference< interface_type > & rRef, UnoReference_SetThrow dummy);
521
522
523 /** Assignment operator: Acquires given interface pointer and sets reference.
524 An interface already set will be released.
525
526 @param pInterface an interface pointer
527 @return this reference
528 */
529 inline Reference< interface_type > & SAL_CALL operator = ( interface_type * pInterface );
530 /** Assignment operator: Acquires given interface reference and sets reference.
531 An interface already set will be released.
532
533 @param rRef an interface reference
534 @return this reference
535 */
536 inline Reference< interface_type > & SAL_CALL operator = ( const Reference< interface_type > & rRef );
537#if defined LIBO_INTERNAL_ONLY1
538 /** Assignment move operator: Acquires given interface reference and sets reference.
539 An interface already set will be released.
540
541 @param rRef an interface reference
542 @return this reference
543 */
544 inline Reference< interface_type > & SAL_CALL operator = ( Reference< interface_type > && rRef ) noexcept;
545#endif
546 /** Queries given interface reference for type interface_type.
547
548 @param rRef interface reference
549 @return interface reference of demanded type (may be null)
550 */
551 SAL_WARN_UNUSED_RESULT[[nodiscard]] inline static Reference< interface_type > SAL_CALL query( const BaseReference & rRef );
552 /** Queries given interface for type interface_type.
553
554 @param pInterface interface pointer
555 @return interface reference of demanded type (may be null)
556 */
557 SAL_WARN_UNUSED_RESULT[[nodiscard]] inline static Reference< interface_type > SAL_CALL query( XInterface * pInterface );
558};
559
560}
561}
562}
563}
564
565#endif
566
567/* vim:set shiftwidth=4 softtabstop=4 expandtab: */