merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / core / dataaccess / documentdefinition.cxx
blobb72a620adb9b20d41051632f4c5e131ebc9a4a03
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: documentdefinition.cxx,v $
10 * $Revision: 1.64.20.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef _DBA_COREDATAACCESS_DOCUMENTDEFINITION_HXX_
35 #include "documentdefinition.hxx"
36 #endif
37 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
38 #include "dbastrings.hrc"
39 #endif
40 #ifndef DBACORE_SDBCORETOOLS_HXX
41 #include "sdbcoretools.hxx"
42 #endif
43 #ifndef _TOOLS_DEBUG_HXX
44 #include <tools/debug.hxx>
45 #endif
46 #ifndef TOOLS_DIAGNOSE_EX_H
47 #include <tools/diagnose_ex.h>
48 #endif
49 #ifndef _COMPHELPER_PROPERTY_HXX_
50 #include <comphelper/property.hxx>
51 #endif
52 #ifndef _COMPHELPER_SEQUENCE_HXX_
53 #include <comphelper/sequence.hxx>
54 #endif
55 #ifndef _COMPHELPER_MEDIADESCRIPTOR_HXX_
56 #include <comphelper/mediadescriptor.hxx>
57 #endif
58 #ifndef COMPHELPER_NAMEDVALUECOLLECTION_HXX
59 #include <comphelper/namedvaluecollection.hxx>
60 #endif
61 #ifndef _COMPHELPER_CLASSIDS_HXX
62 #include <comphelper/classids.hxx>
63 #endif
64 #include <com/sun/star/frame/XUntitledNumbers.hpp>
65 #ifndef _COM_SUN_STAR_AWT_XTOPWINDOW_HPP_
66 #include <com/sun/star/awt/XTopWindow.hpp>
67 #endif
68 #ifndef _COM_SUN_STAR_AWT_SIZE_HPP_
69 #include <com/sun/star/awt/Size.hpp>
70 #endif
71 #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
72 #include <com/sun/star/lang/DisposedException.hpp>
73 #endif
74 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
75 #include <com/sun/star/beans/PropertyAttribute.hpp>
76 #endif
77 #ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
78 #include <com/sun/star/frame/XModel.hpp>
79 #endif
80 #include <com/sun/star/frame/XTitle.hpp>
81 #ifndef _COM_SUN_STAR_FRAME_XCONTROLLER_HPP_
82 #include <com/sun/star/frame/XController.hpp>
83 #endif
84 #ifndef _COM_SUN_STAR_TASK_XJOBEXECUTOR_HPP_
85 #include <com/sun/star/task/XJobExecutor.hpp>
86 #endif
87 #ifndef _COM_SUN_STAR_FRAME_XDISPATCHPROVIDERINTERCEPTION_HPP_
88 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
89 #endif
90 #ifndef _COM_SUN_STAR_FRAME_XFRAMESSUPPLIER_HPP_
91 #include <com/sun/star/frame/XFramesSupplier.hpp>
92 #endif
93 #ifndef _COM_SUN_STAR_UCB_INSERTCOMMANDARGUMENT_HPP_
94 #include <com/sun/star/ucb/InsertCommandArgument.hpp>
95 #endif
96 #include <com/sun/star/report/XReportDefinition.hpp>
97 #include <com/sun/star/report/XReportEngine.hpp>
98 #ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_
99 #include <com/sun/star/ucb/OpenMode.hpp>
100 #endif
101 #ifndef _COM_SUN_STAR_XEMBEDOBJECTFACTORY_HPP_
102 #include <com/sun/star/embed/XEmbedObjectFactory.hpp>
103 #endif
104 #ifndef _COM_SUN_STAR_XEMBEDOBJECTCREATOR_HPP_
105 #include <com/sun/star/embed/XEmbedObjectCreator.hpp>
106 #endif
107 #ifndef _COM_SUN_STAR_EMBED_ASPECTS_HPP_
108 #include <com/sun/star/embed/Aspects.hpp>
109 #endif
110 #ifndef _UCBHELPER_CANCELCOMMANDEXECUTION_HXX_
111 #include <ucbhelper/cancelcommandexecution.hxx>
112 #endif
113 #ifndef _COM_SUN_STAR_UCB_UNSUPPORTEDDATASINKEXCEPTION_HPP_
114 #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
115 #endif
116 #ifndef _COM_SUN_STAR_UCB_UNSUPPORTEDOPENMODEEXCEPTION_HPP_
117 #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
118 #endif
119 #ifndef _COM_SUN_STAR_ELEMENTMODES_HPP_
120 #include <com/sun/star/embed/ElementModes.hpp>
121 #endif
122 #ifndef _COM_SUN_STAR_XEMBEDPERSIST_HPP_
123 #include <com/sun/star/embed/XEmbedPersist.hpp>
124 #endif
125 #ifndef _COM_SUN_STAR_EMBEDSTATES_HPP_
126 #include <com/sun/star/embed/EmbedStates.hpp>
127 #endif
128 #ifndef _COM_SUN_STAR_XCOMPONENTSUPPLIER_HPP_
129 #include <com/sun/star/embed/XComponentSupplier.hpp>
130 #endif
131 #ifndef _COM_SUN_STAR_ENTRYINITMODES_HPP_
132 #include <com/sun/star/embed/EntryInitModes.hpp>
133 #endif
134 #ifndef _COM_SUN_STAR_UCB_MISSINGPROPERTIESEXCEPTION_HPP_
135 #include <com/sun/star/ucb/MissingPropertiesException.hpp>
136 #endif
137 #ifndef _COM_SUN_STAR_UCB_MISSINGINPUTSTREAMEXCEPTION_HPP_
138 #include <com/sun/star/ucb/MissingInputStreamException.hpp>
139 #endif
140 #ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT2_HPP_
141 #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
142 #endif
143 #ifndef _COM_SUN_STAR_UTIL_XCLOSEBROADCASTER_HPP_
144 #include <com/sun/star/util/XCloseBroadcaster.hpp>
145 #endif
146 #ifndef _COM_SUN_STAR_FRAME_XMODULE_HPP_
147 #include <com/sun/star/frame/XModule.hpp>
148 #endif
149 #ifndef _COM_SUN_STAR_DATATRANSFER_DATAFLAVOR_HPP_
150 #include <com/sun/star/datatransfer/DataFlavor.hpp>
151 #endif
152 #ifndef _COM_SUN_STAR_DATATRANSFER_XTRANSFERABLE_HPP_
153 #include <com/sun/star/datatransfer/XTransferable.hpp>
154 #endif
155 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
156 #include <com/sun/star/container/XNameContainer.hpp>
157 #endif
158 #ifndef _COM_SUN_STAR_XTRANSACTEDOBJECT_HPP_
159 #include <com/sun/star/embed/XTransactedObject.hpp>
160 #endif
161 #ifndef _COM_SUN_STAR_EMBED_XCOMMONEMBEDPERSIST_HPP_
162 #include <com/sun/star/embed/XCommonEmbedPersist.hpp>
163 #endif
164 #ifndef DBA_INTERCEPT_HXX
165 #include "intercept.hxx"
166 #endif
167 #ifndef _COM_SUN_STAR_SDB_ERRORCONDITION_HPP_
168 #include <com/sun/star/sdb/ErrorCondition.hpp>
169 #endif
170 #ifndef _COM_SUN_STAR_SDB_XINTERACTIONDOCUMENTSAVE_HPP_
171 #include <com/sun/star/sdb/XInteractionDocumentSave.hpp>
172 #endif
173 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_
174 #include <com/sun/star/task/XInteractionHandler.hpp>
175 #endif
176 #ifndef _COM_SUN_STAR_SDB_DOCUMENTSAVEREQUEST_HPP_
177 #include <com/sun/star/sdb/DocumentSaveRequest.hpp>
178 #endif
179 #ifndef _COM_SUN_STAR_DOCUMENT_XDOCUMENTPROPERTIESSUPPLIER_HPP_
180 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
181 #endif
182 #ifndef _COM_SUN_STAR_DOCUMENT_MACROEXECMODE_HPP_
183 #include <com/sun/star/document/MacroExecMode.hpp>
184 #endif
185 #ifndef _COM_SUN_STAR_DRAWING_XDRAWPAGESUPPLIER_HPP_
186 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
187 #endif
188 #ifndef _COM_SUN_STAR_CONTAINER_XINDEXCONTAINER_HPP_
189 #include <com/sun/star/container/XIndexContainer.hpp>
190 #endif
191 #ifndef _COM_SUN_STAR_FORM_XFORMSSUPPLIER_HPP_
192 #include <com/sun/star/form/XFormsSupplier.hpp>
193 #endif
194 #ifndef _COM_SUN_STAR_FORM_XFORM_HPP_
195 #include <com/sun/star/form/XForm.hpp>
196 #endif
197 #ifndef _COMPHELPER_INTERACTION_HXX_
198 #include <comphelper/interaction.hxx>
199 #endif
200 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
201 #include <connectivity/dbtools.hxx>
202 #endif
203 #ifndef _SV_SVAPP_HXX
204 #include <vcl/svapp.hxx>
205 #endif
206 #ifndef _VOS_MUTEX_HXX_
207 #include <vos/mutex.hxx>
208 #endif
209 #ifndef _COM_SUN_STAR_VIEW_XVIEWSETTINGSSUPPLIER_HPP_
210 #include <com/sun/star/view/XViewSettingsSupplier.hpp>
211 #endif
212 #ifndef _DBA_CORE_RESOURCE_HXX_
213 #include "core_resource.hxx"
214 #endif
215 #ifndef _DBA_CORE_RESOURCE_HRC_
216 #include "core_resource.hrc"
217 #endif
218 #ifndef _DBA_COREDATAACCESS_DATASOURCE_HXX_
219 #include "datasource.hxx"
220 #endif
221 #ifndef _COM_SUN_STAR_EMBED_XSTATECHANGEBROADCASTER_HPP_
222 #include <com/sun/star/embed/XStateChangeBroadcaster.hpp>
223 #endif
224 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONAPPROVE_HPP_
225 #include <com/sun/star/task/XInteractionApprove.hpp>
226 #endif
227 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONDISAPPROVE_HPP_
228 #include <com/sun/star/task/XInteractionDisapprove.hpp>
229 #endif
230 #ifndef _COM_SUN_STAR_FRAME_XLAYOUTMANAGER_HPP_
231 #include <com/sun/star/frame/XLayoutManager.hpp>
232 #endif
233 #ifndef _CPPUHELPER_COMPBASE1_HXX_
234 #include <cppuhelper/compbase1.hxx>
235 #endif
236 #include <cppuhelper/exc_hlp.hxx>
237 #ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
238 #include <com/sun/star/frame/FrameSearchFlag.hpp>
239 #endif
240 #ifndef _COMPHELPER_SEQUENCEASHASHMAP_HXX_
241 #include <comphelper/sequenceashashmap.hxx>
242 #endif
243 #ifndef _COMPHELPER_MIMECONFIGHELPER_HXX_
244 #include <comphelper/mimeconfighelper.hxx>
245 #endif
246 #ifndef _COMPHELPER_STORAGEHELPER_HXX
247 #include <comphelper/storagehelper.hxx>
248 #endif
249 #ifndef _COM_SUN_STAR_CONTAINER_XCONTENTENUMERATIONACCESS_HPP_
250 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
251 #endif
252 #include <com/sun/star/io/WrongFormatException.hpp>
253 #include <com/sun/star/sdb/application/XDatabaseDocumentUI.hpp>
254 #include <com/sun/star/sdb/application/DatabaseObject.hpp>
256 using namespace ::com::sun::star;
257 using namespace view;
258 using namespace uno;
259 using namespace util;
260 using namespace ucb;
261 using namespace beans;
262 using namespace lang;
263 using namespace awt;
264 using namespace embed;
265 using namespace frame;
266 using namespace document;
267 using namespace sdbc;
268 using namespace sdb;
269 using namespace io;
270 using namespace container;
271 using namespace datatransfer;
272 using namespace task;
273 using namespace form;
274 using namespace drawing;
275 using namespace ::osl;
276 using namespace ::comphelper;
277 using namespace ::cppu;
278 namespace css = ::com::sun::star;
280 using sdb::application::XDatabaseDocumentUI;
281 namespace DatabaseObject = sdb::application::DatabaseObject;
284 #define DEFAULT_WIDTH 10000
285 #define DEFAULT_HEIGHT 7500
286 //.............................................................................
287 namespace dbaccess
289 //.............................................................................
291 typedef ::boost::optional< bool > optional_bool;
293 //=========================================================================
294 //= helper
295 //=========================================================================
296 namespace
298 // --------------------------------------------------------------------
299 ::rtl::OUString lcl_determineContentType_nothrow( const Reference< XStorage >& _rxContainerStorage,
300 const ::rtl::OUString& _rEntityName )
302 ::rtl::OUString sContentType;
305 Reference< XStorage > xContainerStorage( _rxContainerStorage, UNO_QUERY_THROW );
306 ::utl::SharedUNOComponent< XPropertySet > xStorageProps(
307 xContainerStorage->openStorageElement( _rEntityName, ElementModes::READ ), UNO_QUERY_THROW );
308 OSL_VERIFY( xStorageProps->getPropertyValue( INFO_MEDIATYPE ) >>= sContentType );
310 catch( const Exception& )
312 DBG_UNHANDLED_EXCEPTION();
314 return sContentType;
318 //==================================================================
319 // OEmbedObjectHolder
320 //==================================================================
321 typedef ::cppu::WeakComponentImplHelper1< embed::XStateChangeListener > TEmbedObjectHolder;
322 class OEmbedObjectHolder : public ::comphelper::OBaseMutex
323 ,public TEmbedObjectHolder
325 Reference< XEmbeddedObject > m_xBroadCaster;
326 ODocumentDefinition* m_pDefinition;
327 bool m_bInStateChange;
328 bool m_bInChangingState;
329 protected:
330 virtual void SAL_CALL disposing();
331 public:
332 OEmbedObjectHolder(const Reference< XEmbeddedObject >& _xBroadCaster,ODocumentDefinition* _pDefinition)
333 : TEmbedObjectHolder(m_aMutex)
334 ,m_xBroadCaster(_xBroadCaster)
335 ,m_pDefinition(_pDefinition)
336 ,m_bInStateChange(false)
337 ,m_bInChangingState(false)
339 osl_incrementInterlockedCount( &m_refCount );
341 if ( m_xBroadCaster.is() )
342 m_xBroadCaster->addStateChangeListener(this);
344 osl_decrementInterlockedCount( &m_refCount );
347 virtual void SAL_CALL changingState( const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (embed::WrongStateException, uno::RuntimeException);
348 virtual void SAL_CALL stateChanged( const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (uno::RuntimeException);
349 virtual void SAL_CALL disposing( const lang::EventObject& Source ) throw (uno::RuntimeException);
351 //------------------------------------------------------------------
352 void SAL_CALL OEmbedObjectHolder::disposing()
354 if ( m_xBroadCaster.is() )
355 m_xBroadCaster->removeStateChangeListener(this);
356 m_xBroadCaster = NULL;
357 m_pDefinition = NULL;
359 //------------------------------------------------------------------
360 void SAL_CALL OEmbedObjectHolder::changingState( const lang::EventObject& /*aEvent*/, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (embed::WrongStateException, uno::RuntimeException)
362 if ( !m_bInChangingState && nNewState == EmbedStates::RUNNING && nOldState == EmbedStates::ACTIVE && m_pDefinition )
364 m_bInChangingState = true;
365 //m_pDefinition->save(sal_False);
366 m_bInChangingState = false;
369 //------------------------------------------------------------------
370 void SAL_CALL OEmbedObjectHolder::stateChanged( const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (uno::RuntimeException)
372 if ( !m_bInStateChange && nNewState == EmbedStates::RUNNING && nOldState == EmbedStates::ACTIVE && m_pDefinition )
374 m_bInStateChange = true;
375 Reference<XInterface> xInt(static_cast< ::cppu::OWeakObject* >(m_pDefinition),UNO_QUERY);
377 Reference<XEmbeddedObject> xEmbeddedObject(aEvent.Source,UNO_QUERY);
378 if ( xEmbeddedObject.is() )
379 xEmbeddedObject->changeState(EmbedStates::LOADED);
381 m_bInStateChange = false;
384 //------------------------------------------------------------------
385 void SAL_CALL OEmbedObjectHolder::disposing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException)
387 m_xBroadCaster = NULL;
390 //==================================================================
391 // OEmbeddedClientHelper
392 //==================================================================
393 typedef ::cppu::WeakImplHelper1 < XEmbeddedClient
394 > EmbeddedClientHelper_BASE;
395 class OEmbeddedClientHelper : public EmbeddedClientHelper_BASE
397 ODocumentDefinition* m_pClient;
398 public:
399 OEmbeddedClientHelper(ODocumentDefinition* _pClient) :m_pClient(_pClient) {}
401 virtual void SAL_CALL saveObject( ) throw (ObjectSaveVetoException, Exception, RuntimeException)
404 virtual void SAL_CALL onShowWindow( sal_Bool /*bVisible*/ ) throw (RuntimeException)
407 // XComponentSupplier
408 virtual Reference< util::XCloseable > SAL_CALL getComponent( ) throw (RuntimeException)
410 return Reference< css::util::XCloseable >();
413 // XEmbeddedClient
414 virtual void SAL_CALL visibilityChanged( ::sal_Bool /*bVisible*/ ) throw (WrongStateException, RuntimeException)
417 inline void resetClient(ODocumentDefinition* _pClient) { m_pClient = _pClient; }
420 //==================================================================
421 // LifetimeCoupler
422 //==================================================================
423 typedef ::cppu::WeakImplHelper1 < css::lang::XEventListener
424 > LifetimeCoupler_Base;
425 /** helper class which couples the lifetime of a component to the lifetim
426 of another component
428 Instances of this class are constructed with two components. The first is
429 simply held by reference, and thus kept alive. The second one is observed
430 for <code>disposing</code> calls - if they occur, i.e. if the component dies,
431 the reference to the first component is cleared.
433 This way, you can ensure that a certain component is kept alive as long
434 as a second component is not disposed.
436 class LifetimeCoupler : public LifetimeCoupler_Base
438 private:
439 Reference< XInterface > m_xClient;
441 public:
442 inline static void couple( const Reference< XInterface >& _rxClient, const Reference< XComponent >& _rxActor )
444 Reference< css::lang::XEventListener > xEnsureDelete( new LifetimeCoupler( _rxClient, _rxActor ) );
447 private:
448 inline LifetimeCoupler( const Reference< XInterface >& _rxClient, const Reference< XComponent >& _rxActor )
449 :m_xClient( _rxClient )
451 DBG_ASSERT( _rxActor.is(), "LifetimeCoupler::LifetimeCoupler: this will crash!" );
452 osl_incrementInterlockedCount( &m_refCount );
454 _rxActor->addEventListener( this );
456 osl_decrementInterlockedCount( &m_refCount );
457 DBG_ASSERT( m_refCount, "LifetimeCoupler::LifetimeCoupler: the actor is not holding us by hard ref - this won't work!" );
460 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) throw (RuntimeException);
461 protected:
464 //------------------------------------------------------------------
465 void SAL_CALL LifetimeCoupler::disposing( const css::lang::EventObject& /*Source*/ ) throw (RuntimeException)
467 m_xClient.clear();
470 //==================================================================
471 // ODocumentSaveContinuation
472 //==================================================================
473 class ODocumentSaveContinuation : public OInteraction< XInteractionDocumentSave >
475 ::rtl::OUString m_sName;
476 Reference<XContent> m_xParentContainer;
478 public:
479 ODocumentSaveContinuation() { }
481 inline Reference<XContent> getContent() const { return m_xParentContainer; }
482 inline ::rtl::OUString getName() const { return m_sName; }
484 // XInteractionDocumentSave
485 virtual void SAL_CALL setName( const ::rtl::OUString& _sName,const Reference<XContent>& _xParent) throw(RuntimeException);
488 //------------------------------------------------------------------
489 void SAL_CALL ODocumentSaveContinuation::setName( const ::rtl::OUString& _sName,const Reference<XContent>& _xParent) throw(RuntimeException)
491 m_sName = _sName;
492 m_xParentContainer = _xParent;
495 // -----------------------------------------------------------------------------
496 ::rtl::OUString ODocumentDefinition::GetDocumentServiceFromMediaType( const Reference< XStorage >& _rxContainerStorage,
497 const ::rtl::OUString& _rEntityName, const ::comphelper::ComponentContext& _rContext,
498 Sequence< sal_Int8 >& _rClassId )
500 return GetDocumentServiceFromMediaType(
501 lcl_determineContentType_nothrow( _rxContainerStorage, _rEntityName ),
502 _rContext, _rClassId );
505 // -----------------------------------------------------------------------------
506 ::rtl::OUString ODocumentDefinition::GetDocumentServiceFromMediaType( const ::rtl::OUString& _rMediaType,
507 const ::comphelper::ComponentContext& _rContext, Sequence< sal_Int8 >& _rClassId )
509 ::rtl::OUString sResult;
512 ::comphelper::MimeConfigurationHelper aConfigHelper( _rContext.getLegacyServiceFactory() );
513 sResult = aConfigHelper.GetDocServiceNameFromMediaType( _rMediaType );
514 _rClassId = aConfigHelper.GetSequenceClassIDRepresentation(aConfigHelper.GetExplicitlyRegisteredObjClassID( _rMediaType ));
515 if ( !_rClassId.getLength() && sResult.getLength() )
517 Reference< XNameAccess > xObjConfig = aConfigHelper.GetObjConfiguration();
518 if ( xObjConfig.is() )
520 Sequence< ::rtl::OUString > aClassIDs = xObjConfig->getElementNames();
521 for ( sal_Int32 nInd = 0; nInd < aClassIDs.getLength(); nInd++ )
523 Reference< XNameAccess > xObjectProps;
524 ::rtl::OUString aEntryDocName;
526 if ( ( xObjConfig->getByName( aClassIDs[nInd] ) >>= xObjectProps ) && xObjectProps.is()
527 && ( xObjectProps->getByName(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ObjectDocumentServiceName"))
528 ) >>= aEntryDocName )
529 && aEntryDocName.equals( sResult ) )
531 _rClassId = aConfigHelper.GetSequenceClassIDRepresentation(aClassIDs[nInd]);
532 break;
538 catch ( Exception& )
540 DBG_UNHANDLED_EXCEPTION();
542 return sResult;
544 // -----------------------------------------------------------------------------
545 //==========================================================================
546 //= ODocumentDefinition
547 //==========================================================================
548 DBG_NAME(ODocumentDefinition)
550 //--------------------------------------------------------------------------
551 ODocumentDefinition::ODocumentDefinition(const Reference< XInterface >& _rxContainer
552 , const Reference< XMultiServiceFactory >& _xORB
553 ,const TContentPtr& _pImpl
554 , sal_Bool _bForm
555 , const Sequence< sal_Int8 >& _aClassID
556 ,const Reference<XConnection>& _xConnection
558 :OContentHelper(_xORB,_rxContainer,_pImpl)
559 ,OPropertyStateContainer(OContentHelper::rBHelper)
560 ,m_pInterceptor(NULL)
561 ,m_bForm(_bForm)
562 ,m_bOpenInDesign(sal_False)
563 ,m_bInExecute(sal_False)
564 ,m_bRemoveListener(sal_False)
565 ,m_pClientHelper(NULL)
567 DBG_CTOR(ODocumentDefinition, NULL);
568 registerProperties();
569 if ( _aClassID.getLength() )
570 loadEmbeddedObject( _xConnection, _aClassID, Sequence< PropertyValue >(), false, false );
572 //--------------------------------------------------------------------------
573 ODocumentDefinition::~ODocumentDefinition()
575 DBG_DTOR(ODocumentDefinition, NULL);
576 if ( !OContentHelper::rBHelper.bInDispose && !OContentHelper::rBHelper.bDisposed )
578 acquire();
579 dispose();
582 if ( m_pInterceptor )
584 m_pInterceptor->dispose();
585 m_pInterceptor->release();
586 m_pInterceptor = NULL;
589 // -----------------------------------------------------------------------------
590 void ODocumentDefinition::closeObject()
592 ::osl::MutexGuard aGuard(m_aMutex);
593 if ( m_xEmbeddedObject.is() )
597 Reference< com::sun::star::util::XCloseable> xCloseable(m_xEmbeddedObject,UNO_QUERY);
598 if ( xCloseable.is() )
599 xCloseable->close(sal_True);
601 catch(Exception)
604 m_xEmbeddedObject = NULL;
605 if ( m_pClientHelper )
607 m_pClientHelper->resetClient(NULL);
608 m_pClientHelper->release();
609 m_pClientHelper = NULL;
613 // -----------------------------------------------------------------------------
614 void SAL_CALL ODocumentDefinition::disposing()
616 OContentHelper::disposing();
617 ::osl::MutexGuard aGuard(m_aMutex);
618 closeObject();
619 ::comphelper::disposeComponent(m_xListener);
620 if ( m_bRemoveListener && m_xDesktop.is() )
622 Reference<util::XCloseable> xCloseable(m_pImpl->m_pDataSource->getModel_noCreate(),UNO_QUERY);
623 if ( xCloseable.is() )
624 xCloseable->removeCloseListener(this);
626 m_xDesktop = NULL;
628 // -----------------------------------------------------------------------------
629 IMPLEMENT_TYPEPROVIDER3(ODocumentDefinition,OContentHelper,OPropertyStateContainer,ODocumentDefinition_Base);
630 IMPLEMENT_FORWARD_XINTERFACE3( ODocumentDefinition,OContentHelper,OPropertyStateContainer,ODocumentDefinition_Base)
631 IMPLEMENT_SERVICE_INFO1(ODocumentDefinition,"com.sun.star.comp.dba.ODocumentDefinition",SERVICE_SDB_DOCUMENTDEFINITION)
632 //--------------------------------------------------------------------------
633 void ODocumentDefinition::registerProperties()
635 registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND | PropertyAttribute::READONLY | PropertyAttribute::CONSTRAINED,
636 &m_pImpl->m_aProps.aTitle, ::getCppuType(&m_pImpl->m_aProps.aTitle));
637 registerProperty(PROPERTY_AS_TEMPLATE, PROPERTY_ID_AS_TEMPLATE, PropertyAttribute::BOUND | PropertyAttribute::READONLY | PropertyAttribute::CONSTRAINED,
638 &m_pImpl->m_aProps.bAsTemplate, ::getCppuType(&m_pImpl->m_aProps.bAsTemplate));
639 registerProperty(PROPERTY_PERSISTENT_NAME, PROPERTY_ID_PERSISTENT_NAME, PropertyAttribute::BOUND | PropertyAttribute::READONLY | PropertyAttribute::CONSTRAINED,
640 &m_pImpl->m_aProps.sPersistentName, ::getCppuType(&m_pImpl->m_aProps.sPersistentName));
641 registerProperty(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsForm")), PROPERTY_ID_IS_FORM, PropertyAttribute::BOUND | PropertyAttribute::READONLY | PropertyAttribute::CONSTRAINED,
642 &m_bForm, ::getCppuType(&m_bForm));
644 // -----------------------------------------------------------------------------
645 Reference< XPropertySetInfo > SAL_CALL ODocumentDefinition::getPropertySetInfo( ) throw(RuntimeException)
647 Reference<XPropertySetInfo> xInfo( createPropertySetInfo( getInfoHelper() ) );
648 return xInfo;
651 //--------------------------------------------------------------------------
652 IPropertyArrayHelper& ODocumentDefinition::getInfoHelper()
654 return *getArrayHelper();
658 //--------------------------------------------------------------------------
659 IPropertyArrayHelper* ODocumentDefinition::createArrayHelper( ) const
661 Sequence< Property > aProps;
662 describeProperties(aProps);
663 return new OPropertyArrayHelper(aProps);
665 class OExecuteImpl
667 sal_Bool& m_rbSet;
668 public:
669 OExecuteImpl(sal_Bool& _rbSet) : m_rbSet(_rbSet){ m_rbSet=sal_True; }
670 ~OExecuteImpl(){ m_rbSet = sal_False; }
672 // -----------------------------------------------------------------------------
673 namespace
675 bool lcl_extractOpenMode( const Any& _rValue, sal_Int32& _out_rMode )
677 OpenCommandArgument aOpenCommand;
678 if ( _rValue >>= aOpenCommand )
679 _out_rMode = aOpenCommand.Mode;
680 else
682 OpenCommandArgument2 aOpenCommand2;
683 if ( _rValue >>= aOpenCommand2 )
684 _out_rMode = aOpenCommand2.Mode;
685 else
686 return false;
688 return true;
692 // -----------------------------------------------------------------------------
693 void ODocumentDefinition::impl_removeFrameFromDesktop_throw( const Reference< XFrame >& _rxFrame )
695 if ( !m_xDesktop.is() )
696 m_xDesktop.set( m_aContext.createComponent( (::rtl::OUString)SERVICE_FRAME_DESKTOP ), UNO_QUERY_THROW );
698 Reference< XFrames > xFrames( m_xDesktop->getFrames(), UNO_QUERY_THROW );
699 xFrames->remove( _rxFrame );
702 // -----------------------------------------------------------------------------
703 void ODocumentDefinition::impl_onActivateEmbeddedObject()
707 Reference< XModel > xModel( getComponent(), UNO_QUERY );
708 Reference< XController > xController( xModel.is() ? xModel->getCurrentController() : Reference< XController >() );
709 if ( !xController.is() )
710 return;
712 if ( !m_xListener.is() )
713 // it's the first time the embedded object has been activated
714 // create an OEmbedObjectHolder
715 m_xListener = new OEmbedObjectHolder(m_xEmbeddedObject,this);
717 Reference< XFrame > xFrame( xController->getFrame() );
718 if ( xFrame.is() )
720 // raise the window to top (especially necessary if this is not the first activation)
721 Reference< XTopWindow > xTopWindow( xFrame->getContainerWindow(), UNO_QUERY_THROW );
722 xTopWindow->toFront();
724 // remove the frame from the desktop's frame collection because we need full control of it.
725 impl_removeFrameFromDesktop_throw( xFrame );
728 // ensure that we ourself are kept alive as long as the embedded object's frame is
729 // opened
730 LifetimeCoupler::couple( *this, Reference< XComponent >( xFrame, UNO_QUERY_THROW ) );
732 // init the edit view
733 if ( m_bOpenInDesign )
734 impl_initObjectEditView( xController );
736 catch( const RuntimeException& )
738 DBG_UNHANDLED_EXCEPTION();
742 // -----------------------------------------------------------------------------
743 namespace
745 // =========================================================================
746 // = PreserveVisualAreaSize
747 // =========================================================================
748 /** stack-guard for preserving the size of the VisArea of an XModel
750 class PreserveVisualAreaSize
752 private:
753 Reference< XVisualObject > m_xVisObject;
754 awt::Size m_aOriginalSize;
756 public:
757 inline PreserveVisualAreaSize( const Reference< XModel >& _rxModel )
758 :m_xVisObject( _rxModel, UNO_QUERY )
760 if ( m_xVisObject.is() )
764 m_aOriginalSize = m_xVisObject->getVisualAreaSize( Aspects::MSOLE_CONTENT );
766 catch ( Exception& )
768 DBG_ERROR( "PreserveVisualAreaSize::PreserveVisualAreaSize: caught an exception!" );
773 inline ~PreserveVisualAreaSize()
775 if ( m_xVisObject.is() && m_aOriginalSize.Width && m_aOriginalSize.Height )
779 m_xVisObject->setVisualAreaSize( Aspects::MSOLE_CONTENT, m_aOriginalSize );
781 catch ( Exception& )
783 DBG_ERROR( "PreserveVisualAreaSize::~PreserveVisualAreaSize: caught an exception!" );
789 // =========================================================================
790 // = LayoutManagerLock
791 // =========================================================================
792 /** helper class for stack-usage which during its lifetime locks a layout manager
794 class LayoutManagerLock
796 private:
797 Reference< XLayoutManager > m_xLayoutManager;
799 public:
800 inline LayoutManagerLock( const Reference< XController >& _rxController )
802 DBG_ASSERT( _rxController.is(), "LayoutManagerLock::LayoutManagerLock: this will crash!" );
803 Reference< XFrame > xFrame( _rxController->getFrame() );
806 Reference< XPropertySet > xPropSet( xFrame, UNO_QUERY_THROW );
807 m_xLayoutManager.set(
808 xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ) ) ),
809 UNO_QUERY_THROW );
810 m_xLayoutManager->lock();
813 catch( Exception& )
815 DBG_ERROR( "LayoutManagerLock::LayoutManagerLock: caught an exception!" );
819 inline ~LayoutManagerLock()
823 // unlock the layout manager
824 if ( m_xLayoutManager.is() )
825 m_xLayoutManager->unlock();
827 catch( Exception& )
829 DBG_ERROR( "LayoutManagerLock::~LayoutManagerLock: caught an exception!" );
835 // -----------------------------------------------------------------------------
836 void ODocumentDefinition::impl_initObjectEditView( const Reference< XController >& _rxController )
838 if ( !m_bForm )
839 // currently, only forms need to be initialized
840 return;
844 Reference< XViewSettingsSupplier > xSettingsSupplier( _rxController, UNO_QUERY_THROW );
845 Reference< XPropertySet > xViewSettings( xSettingsSupplier->getViewSettings(), UNO_QUERY_THROW );
847 // The visual area size can be changed by the setting of the following properties
848 // so it should be restored later
849 PreserveVisualAreaSize aPreserveVisAreaSize( _rxController->getModel() );
851 // Layout manager should not layout while the size is still not restored
852 // so it will stay locked for this time
853 LayoutManagerLock aLockLayout( _rxController );
855 // setting of the visual properties
856 xViewSettings->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowRulers")),makeAny(sal_True));
857 xViewSettings->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowVertRuler")),makeAny(sal_True));
858 xViewSettings->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowHoriRuler")),makeAny(sal_True));
859 xViewSettings->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsRasterVisible")),makeAny(sal_True));
860 xViewSettings->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsSnapToRaster")),makeAny(sal_True));
861 xViewSettings->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowOnlineLayout")),makeAny(sal_True));
862 xViewSettings->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RasterSubdivisionX")),makeAny(sal_Int32(5)));
863 xViewSettings->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RasterSubdivisionY")),makeAny(sal_Int32(5)));
865 Reference< XModifiable > xModifiable( _rxController->getModel(), UNO_QUERY_THROW );
866 xModifiable->setModified( sal_False );
868 catch( const Exception& )
870 DBG_UNHANDLED_EXCEPTION();
874 // -----------------------------------------------------------------------------
875 void ODocumentDefinition::onCommandOpenSomething( const Any& _rOpenArgument, const bool _bActivate,
876 const Reference< XCommandEnvironment >& _rxEnvironment, Any& _out_rComponent, ::osl::ClearableMutexGuard & _aGuard )
878 OExecuteImpl aExecuteGuard(m_bInExecute);
880 Reference< XConnection > xConnection;
881 sal_Int32 nOpenMode = OpenMode::DOCUMENT;
883 ::comphelper::NamedValueCollection aDocumentArgs;
885 // for the document, default to the interaction handler as used for loading the DB doc
886 // This might be overwritten below, when examining _rOpenArgument.
887 ::comphelper::NamedValueCollection aDBDocArgs( m_pImpl->m_pDataSource->getResource() );
888 aDocumentArgs.put( "InteractionHandler", aDBDocArgs.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() ) );
890 ::boost::optional< sal_Int16 > aDocumentMacroMode;
892 if ( !lcl_extractOpenMode( _rOpenArgument, nOpenMode ) )
894 Sequence< PropertyValue > aArguments;
895 if ( _rOpenArgument >>= aArguments )
897 const PropertyValue* pIter = aArguments.getConstArray();
898 const PropertyValue* pEnd = pIter + aArguments.getLength();
899 for ( ;pIter != pEnd; ++pIter )
901 if ( pIter->Name == PROPERTY_ACTIVE_CONNECTION )
903 xConnection.set( pIter->Value, UNO_QUERY );
904 continue;
907 if ( lcl_extractOpenMode( pIter->Value, nOpenMode ) )
908 continue;
910 if ( pIter->Name.equalsAscii( "MacroExecutionMode" ) )
912 sal_Int16 nMacroExecMode( !aDocumentMacroMode ? MacroExecMode::USE_CONFIG : *aDocumentMacroMode );
913 OSL_VERIFY( pIter->Value >>= nMacroExecMode );
914 aDocumentMacroMode.reset( nMacroExecMode );
915 continue;
918 // unknown argument -> pass to the loaded document
919 aDocumentArgs.put( pIter->Name, pIter->Value );
924 bool bExecuteDBDocMacros = m_pImpl->m_pDataSource->checkMacrosOnLoading();
925 // Note that this call implies the user might be asked for the macro execution mode.
926 // Normally, this would happen when the database document is loaded, and subsequent calls
927 // will simply use the user's decision from this point in time.
928 // However, it is possible to programmatically load forms/reports, without actually
929 // loading the database document into a frame. In this case, the user will be asked
930 // here and now.
931 // #i87741# / 2008-05-05 / frank.schoenheit@sun.com
933 // allow the command arguments to downgrade the macro execution mode, but not to upgrade
934 // it
935 if ( ( m_pImpl->m_pDataSource->getImposedMacroExecMode() == MacroExecMode::USE_CONFIG )
936 && bExecuteDBDocMacros
939 // while loading the whole database document, USE_CONFIG, was passed.
940 // Additionally, *by now* executing macros from the DB doc is allowed (this is what bExecuteDBDocMacros
941 // indicates). This means either one of:
942 // 1. The DB doc or one of the sub docs contained macros and
943 // 1a. the user explicitly allowed executing them
944 // 1b. the configuration allows executing them without asking the user
945 // 2. Neither the DB doc nor the sub docs contained macros, thus macro
946 // execution was silently enabled, assuming that any macro will be a
947 // user-created macro
949 // The problem with this: If the to-be-opened sub document has macros embedded in
950 // the content.xml (which is valid ODF, but normally not produced by OOo itself),
951 // then this has not been detected while loading the database document - it would
952 // be too expensive, as it effectively would require loading all forms/reports.
954 // So, in such a case, and with 2. above, we would silently execute those macros,
955 // regardless of the global security settings - which would be a security issue, of
956 // course.
957 if ( m_pImpl->m_pDataSource->determineEmbeddedMacros() == ODatabaseModelImpl::eNoMacros )
959 // this is case 2. from above
960 // So, pass a USE_CONFIG to the to-be-loaded document. This means that
961 // the user will be prompted with a security message upon opening this
962 // sub document, in case the settings require this, *and* the document
963 // contains scripts in the content.xml. But this is better than the security
964 // issue we had before ...
965 aDocumentMacroMode.reset( MacroExecMode::USE_CONFIG );
969 if ( !aDocumentMacroMode )
971 // nobody so far felt responsible for setting it
972 // => use the DBDoc-wide macro exec mode for the document, too
973 aDocumentMacroMode.reset( bExecuteDBDocMacros ? MacroExecMode::ALWAYS_EXECUTE_NO_WARN : MacroExecMode::NEVER_EXECUTE );
975 aDocumentArgs.put( "MacroExecutionMode", *aDocumentMacroMode );
978 if ( xConnection.is() )
979 m_xLastKnownConnection = xConnection;
981 if ( ( nOpenMode == OpenMode::ALL )
982 || ( nOpenMode == OpenMode::FOLDERS )
983 || ( nOpenMode == OpenMode::DOCUMENTS )
984 || ( nOpenMode == OpenMode::DOCUMENT_SHARE_DENY_NONE )
985 || ( nOpenMode == OpenMode::DOCUMENT_SHARE_DENY_WRITE )
988 // not supported
989 ucbhelper::cancelCommandExecution(
990 makeAny( UnsupportedOpenModeException(
991 rtl::OUString(),
992 static_cast< cppu::OWeakObject * >( this ),
993 sal_Int16( nOpenMode ) ) ),
994 _rxEnvironment );
995 // Unreachable
996 DBG_ERROR( "unreachable" );
999 OSL_ENSURE( m_pImpl->m_aProps.sPersistentName.getLength(),
1000 "ODocumentDefinition::onCommandOpenSomething: no persistent name - cannot load!" );
1001 if ( !m_pImpl->m_aProps.sPersistentName.getLength() )
1002 return;
1004 // embedded objects themself do not support the hidden flag. We implement support for
1005 // it by changing the STATE to RUNNING only, instead of ACTIVE.
1006 bool bOpenHidden = aDocumentArgs.getOrDefault( "Hidden", false );
1007 aDocumentArgs.remove( "Hidden" );
1009 loadEmbeddedObject( xConnection, Sequence< sal_Int8 >(), aDocumentArgs.getPropertyValues(), false, !m_bOpenInDesign );
1010 OSL_ENSURE( m_xEmbeddedObject.is(), "ODocumentDefinition::onCommandOpenSomething: what's this?" );
1011 if ( !m_xEmbeddedObject.is() )
1012 return;
1014 Reference< XModel > xModel( getComponent(), UNO_QUERY );
1015 Reference< report::XReportDefinition > xReportDefinition(xModel,UNO_QUERY);
1017 Reference< XModule > xModule( xModel, UNO_QUERY );
1018 if ( xModule.is() )
1020 if ( m_bForm )
1021 xModule->setIdentifier( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.FormDesign" ) ) );
1022 else if ( !xReportDefinition.is() )
1023 xModule->setIdentifier( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.TextReportDesign" ) ) );
1025 updateDocumentTitle();
1028 bool bIsAliveNewStyleReport = ( !m_bOpenInDesign && xReportDefinition.is() );
1029 if ( bIsAliveNewStyleReport )
1031 // we are in ReadOnly mode
1032 // we would like to open the Writer or Calc with the report direct, without design it.
1033 Reference< report::XReportEngine > xReportEngine( m_aContext.createComponent( "com.sun.star.comp.report.OReportEngineJFree" ), UNO_QUERY_THROW );
1035 xReportEngine->setReportDefinition(xReportDefinition);
1036 xReportEngine->setActiveConnection(m_xLastKnownConnection);
1037 if ( bOpenHidden )
1038 _out_rComponent <<= xReportEngine->createDocumentModel( );
1039 else
1040 _out_rComponent <<= xReportEngine->createDocumentAlive(NULL);
1041 return;
1044 if ( _bActivate && !bOpenHidden )
1046 m_xEmbeddedObject->changeState( EmbedStates::ACTIVE );
1047 impl_onActivateEmbeddedObject();
1050 // LLA: Alle fillReportData() calls pr�fen, sollte es welche geben, die danach noch viel machen
1051 // LLA: sollten wir einen _aGuard Pointer �bergeben, sonst erstmal als Referenz
1052 fillReportData(_aGuard);
1053 _out_rComponent <<= xModel;
1056 // -----------------------------------------------------------------------------
1057 Any SAL_CALL ODocumentDefinition::execute( const Command& aCommand, sal_Int32 CommandId, const Reference< XCommandEnvironment >& Environment ) throw (Exception, CommandAbortedException, RuntimeException)
1059 Any aRet;
1060 ::osl::ClearableMutexGuard aGuard(m_aMutex);
1061 if ( !m_bInExecute )
1063 sal_Bool bOpen = aCommand.Name.equalsAscii( "open" );
1064 sal_Bool bOpenInDesign = aCommand.Name.equalsAscii( "openDesign" );
1065 sal_Bool bOpenForMail = aCommand.Name.equalsAscii( "openForMail" );
1066 if ( bOpen || bOpenInDesign || bOpenForMail )
1068 bool bActivateObject = true;
1069 if ( bOpenForMail )
1071 OSL_ENSURE( false, "ODocumentDefinition::execute: 'openForMail' should not be used anymore - use the 'Hidden' parameter instead!" );
1072 bActivateObject = false;
1075 // if the object is already opened, do nothing
1076 // #i89509# / 2008-05-22 / frank.schoenheit@sun.com
1077 if ( m_xEmbeddedObject.is() )
1079 sal_Int32 nCurrentState = m_xEmbeddedObject->getCurrentState();
1080 bool bIsActive = ( nCurrentState == EmbedStates::ACTIVE );
1082 // exception: new-style reports always create a new document when "open" is executed
1083 Reference< report::XReportDefinition > xReportDefinition( getComponent(), UNO_QUERY );
1084 bool bIsAliveNewStyleReport = ( xReportDefinition.is() && ( bOpen || bOpenForMail ) );
1086 if ( bIsActive && !bIsAliveNewStyleReport )
1088 impl_onActivateEmbeddedObject();
1089 return makeAny( getComponent() );
1093 // m_bOpenInDesign = bOpenInDesign;
1094 // onCommandOpenSomething( aCommand.Argument, !bOpenForMail, Environment, aRet, aGuard );
1096 m_bOpenInDesign = bOpenInDesign || bOpenForMail;
1097 onCommandOpenSomething( aCommand.Argument, bActivateObject, Environment, aRet, aGuard );
1099 else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "copyTo" ) ) )
1101 Sequence<Any> aIni;
1102 aCommand.Argument >>= aIni;
1103 if ( aIni.getLength() != 2 )
1105 OSL_ENSURE( sal_False, "Wrong argument type!" );
1106 ucbhelper::cancelCommandExecution(
1107 makeAny( IllegalArgumentException(
1108 rtl::OUString(),
1109 static_cast< cppu::OWeakObject * >( this ),
1110 -1 ) ),
1111 Environment );
1112 // Unreachable
1114 Reference< XStorage> xDest(aIni[0],UNO_QUERY);
1115 ::rtl::OUString sPersistentName;
1116 aIni[1] >>= sPersistentName;
1117 Reference< XStorage> xStorage = getContainerStorage();
1118 // -----------------------------------------------------------------------------
1119 xStorage->copyElementTo(m_pImpl->m_aProps.sPersistentName,xDest,sPersistentName);
1120 /*loadEmbeddedObject( true );
1121 Reference<XEmbedPersist> xPersist(m_xEmbeddedObject,UNO_QUERY);
1122 if ( xPersist.is() )
1124 xPersist->storeToEntry(xStorage,sPersistentName,Sequence<PropertyValue>(),Sequence<PropertyValue>());
1125 xPersist->storeOwn();
1126 m_xEmbeddedObject->changeState(EmbedStates::LOADED);
1128 else
1129 throw CommandAbortedException();*/
1131 else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "preview" ) ) )
1133 onCommandPreview(aRet);
1135 else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "insert" ) ) )
1137 Sequence<Any> aIni;
1138 aCommand.Argument >>= aIni;
1139 if ( aIni.getLength() > 0 && aIni.getLength() < 2 )
1141 OSL_ENSURE( sal_False, "Wrong argument type!" );
1142 ucbhelper::cancelCommandExecution(
1143 makeAny( IllegalArgumentException(
1144 rtl::OUString(),
1145 static_cast< cppu::OWeakObject * >( this ),
1146 -1 ) ),
1147 Environment );
1148 // Unreachable
1150 ::rtl::OUString sURL;
1151 aIni[0] >>= sURL;
1152 onCommandInsert( sURL, Environment );
1154 else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "getdocumentinfo" ) ) // compatibility
1155 || aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "getDocumentInfo" ) )
1158 onCommandGetDocumentProperties( aRet );
1160 else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "delete" ) ) )
1162 //////////////////////////////////////////////////////////////////
1163 // delete
1164 //////////////////////////////////////////////////////////////////
1165 closeObject();
1166 Reference< XStorage> xStorage = getContainerStorage();
1167 if ( xStorage.is() )
1168 xStorage->removeElement(m_pImpl->m_aProps.sPersistentName);
1170 dispose();
1173 else if ( ( aCommand.Name.compareToAscii( "storeOwn" ) == 0 ) // compatibility
1174 || ( aCommand.Name.compareToAscii( "store" ) == 0 )
1177 impl_store_throw();
1179 else if ( ( aCommand.Name.compareToAscii( "shutdown" ) == 0 ) // compatibility
1180 || ( aCommand.Name.compareToAscii( "close" ) == 0 )
1183 aRet <<= impl_close_throw();
1185 else
1187 aRet = OContentHelper::execute(aCommand,CommandId,Environment);
1190 return aRet;
1192 // -----------------------------------------------------------------------------
1193 namespace
1195 void lcl_resetChildFormsToEmptyDataSource( const Reference< XIndexAccess>& _rxFormsContainer )
1197 OSL_PRECOND( _rxFormsContainer.is(), "lcl_resetChildFormsToEmptyDataSource: illegal call!" );
1198 sal_Int32 count = _rxFormsContainer->getCount();
1199 for ( sal_Int32 i = 0; i < count; ++i )
1201 Reference< XForm > xForm( _rxFormsContainer->getByIndex( i ), UNO_QUERY );
1202 if ( !xForm.is() )
1203 continue;
1205 // if the element is a form, reset its DataSourceName property to an empty string
1208 Reference< XPropertySet > xFormProps( xForm, UNO_QUERY_THROW );
1209 xFormProps->setPropertyValue( PROPERTY_DATASOURCENAME, makeAny( ::rtl::OUString() ) );
1211 catch( const Exception& )
1213 DBG_UNHANDLED_EXCEPTION();
1216 // if the element is a container itself, step down the component hierarchy
1217 Reference< XIndexAccess > xContainer( xForm, UNO_QUERY );
1218 if ( xContainer.is() )
1219 lcl_resetChildFormsToEmptyDataSource( xContainer );
1223 void lcl_resetFormsToEmptyDataSource( const Reference< XEmbeddedObject>& _rxEmbeddedObject )
1227 Reference< XComponentSupplier > xCompProv( _rxEmbeddedObject, UNO_QUERY_THROW );
1228 Reference< XDrawPageSupplier > xSuppPage( xCompProv->getComponent(), UNO_QUERY_THROW );
1229 // if this interface does not exist, then either getComponent returned NULL,
1230 // or the document is a multi-page document. The latter is allowed, but currently
1231 // simply not handled by this code, as it would not normally happen.
1233 Reference< XFormsSupplier > xSuppForms( xSuppPage->getDrawPage(), UNO_QUERY_THROW );
1234 Reference< XIndexAccess > xForms( xSuppForms->getForms(), UNO_QUERY_THROW );
1235 lcl_resetChildFormsToEmptyDataSource( xForms );
1237 catch( const Exception& )
1239 DBG_UNHANDLED_EXCEPTION();
1244 // -----------------------------------------------------------------------------
1245 void ODocumentDefinition::onCommandInsert( const ::rtl::OUString& _sURL, const Reference< XCommandEnvironment >& Environment )
1246 throw( Exception )
1248 osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
1250 // Check, if all required properties were set.
1251 if ( !_sURL.getLength() || m_xEmbeddedObject.is() )
1253 OSL_ENSURE( sal_False, "Content::onCommandInsert - property value missing!" );
1255 Sequence< rtl::OUString > aProps( 1 );
1256 aProps[ 0 ] = PROPERTY_URL;
1257 ucbhelper::cancelCommandExecution(
1258 makeAny( MissingPropertiesException(
1259 rtl::OUString(),
1260 static_cast< cppu::OWeakObject * >( this ),
1261 aProps ) ),
1262 Environment );
1263 // Unreachable
1267 if ( !m_xEmbeddedObject.is() )
1269 Reference< XStorage> xStorage = getContainerStorage();
1270 if ( xStorage.is() )
1272 Reference< XEmbedObjectCreator> xEmbedFactory( m_aContext.createComponent( "com.sun.star.embed.EmbeddedObjectCreator" ), UNO_QUERY );
1273 if ( xEmbedFactory.is() )
1275 Sequence<PropertyValue> aEmpty,aMediaDesc(1);
1276 aMediaDesc[0].Name = PROPERTY_URL;
1277 aMediaDesc[0].Value <<= _sURL;
1278 m_xEmbeddedObject.set(xEmbedFactory->createInstanceInitFromMediaDescriptor( xStorage
1279 ,m_pImpl->m_aProps.sPersistentName
1280 ,aMediaDesc
1281 ,aEmpty),UNO_QUERY);
1283 lcl_resetFormsToEmptyDataSource( m_xEmbeddedObject );
1284 // #i57669# / 2005-12-01 / frank.schoenheit@sun.com
1286 Reference<XEmbedPersist> xPersist(m_xEmbeddedObject,UNO_QUERY);
1287 if ( xPersist.is() )
1289 xPersist->storeOwn();
1293 Reference< com::sun::star::util::XCloseable> xCloseable(m_xEmbeddedObject,UNO_QUERY);
1294 if ( xCloseable.is() )
1295 xCloseable->close(sal_True);
1297 catch(Exception)
1300 m_xEmbeddedObject = NULL;
1305 // @@@
1306 // storeData();
1308 aGuard.clear();
1309 // inserted();
1311 // -----------------------------------------------------------------------------
1312 sal_Bool ODocumentDefinition::save(sal_Bool _bApprove)
1314 // default handling: instantiate an interaction handler and let it handle the parameter request
1315 if ( !m_bOpenInDesign )
1316 return sal_False;
1321 ::vos::OGuard aSolarGuard(Application::GetSolarMutex());
1323 // the request
1324 Reference<XNameAccess> xName(m_xParentContainer,UNO_QUERY);
1325 DocumentSaveRequest aRequest;
1326 aRequest.Name = m_pImpl->m_aProps.aTitle;
1327 if ( !aRequest.Name.getLength() )
1329 if ( m_bForm )
1330 aRequest.Name = DBACORE_RESSTRING( RID_STR_FORM );
1331 else
1332 aRequest.Name = DBACORE_RESSTRING( RID_STR_REPORT );
1333 aRequest.Name = ::dbtools::createUniqueName(xName,aRequest.Name);
1335 else if ( xName->hasByName(aRequest.Name) )
1336 aRequest.Name = ::dbtools::createUniqueName(xName,aRequest.Name);
1338 aRequest.Content.set(m_xParentContainer,UNO_QUERY);
1339 OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aRequest));
1340 Reference< XInteractionRequest > xRequest(pRequest);
1341 // some knittings
1342 // two continuations allowed: OK and Cancel
1343 ODocumentSaveContinuation* pDocuSave = NULL;
1345 if ( !m_pImpl->m_aProps.aTitle.getLength() )
1347 pDocuSave = new ODocumentSaveContinuation;
1348 pRequest->addContinuation(pDocuSave);
1350 OInteraction< XInteractionApprove >* pApprove = NULL;
1351 if ( _bApprove )
1353 pApprove = new OInteraction< XInteractionApprove >;
1354 pRequest->addContinuation(pApprove);
1357 OInteraction< XInteractionDisapprove >* pDisApprove = new OInteraction< XInteractionDisapprove >;
1358 pRequest->addContinuation(pDisApprove);
1360 OInteractionAbort* pAbort = new OInteractionAbort;
1361 pRequest->addContinuation(pAbort);
1363 // create the handler, let it handle the request
1364 Reference< XInteractionHandler > xHandler( m_aContext.createComponent( (::rtl::OUString)SERVICE_SDB_INTERACTION_HANDLER ), UNO_QUERY );
1365 if ( xHandler.is() )
1366 xHandler->handle(xRequest);
1368 if ( pAbort->wasSelected() )
1369 return sal_False;
1370 if ( pDisApprove->wasSelected() )
1371 return sal_True;
1372 if ( pDocuSave && pDocuSave->wasSelected() )
1374 ::osl::MutexGuard aGuard(m_aMutex);
1375 Reference<XNameContainer> xNC(pDocuSave->getContent(),UNO_QUERY);
1376 if ( xNC.is() )
1378 m_pImpl->m_aProps.aTitle = pDocuSave->getName();
1379 Reference< XContent> xContent = this;
1380 xNC->insertByName(pDocuSave->getName(),makeAny(xContent));
1382 updateDocumentTitle();
1387 ::osl::MutexGuard aGuard(m_aMutex);
1388 Reference<XEmbedPersist> xPersist(m_xEmbeddedObject,UNO_QUERY);
1389 if ( xPersist.is() )
1391 xPersist->storeOwn();
1392 notifyDataSourceModified();
1395 catch(Exception&)
1397 OSL_ENSURE(0,"ODocumentDefinition::save: caught an Exception (tried to let the InteractionHandler handle it)!");
1399 return sal_True;
1401 // -----------------------------------------------------------------------------
1402 sal_Bool ODocumentDefinition::saveAs()
1404 // default handling: instantiate an interaction handler and let it handle the parameter request
1405 if ( !m_bOpenInDesign )
1406 return sal_False;
1409 osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
1410 if ( !m_pImpl->m_aProps.aTitle.getLength() )
1412 aGuard.clear();
1413 return save(sal_False); // (sal_False) : we don't want an approve dialog
1419 ::vos::OGuard aSolarGuard(Application::GetSolarMutex());
1421 // the request
1422 Reference<XNameAccess> xName(m_xParentContainer,UNO_QUERY);
1423 DocumentSaveRequest aRequest;
1424 aRequest.Name = m_pImpl->m_aProps.aTitle;
1426 aRequest.Content.set(m_xParentContainer,UNO_QUERY);
1427 OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aRequest));
1428 Reference< XInteractionRequest > xRequest(pRequest);
1429 // some knittings
1430 // two continuations allowed: OK and Cancel
1431 ODocumentSaveContinuation* pDocuSave = new ODocumentSaveContinuation;
1432 pRequest->addContinuation(pDocuSave);
1433 OInteraction< XInteractionDisapprove >* pDisApprove = new OInteraction< XInteractionDisapprove >;
1434 pRequest->addContinuation(pDisApprove);
1435 OInteractionAbort* pAbort = new OInteractionAbort;
1436 pRequest->addContinuation(pAbort);
1438 // create the handler, let it handle the request
1439 Reference< XInteractionHandler > xHandler(m_aContext.createComponent(::rtl::OUString(SERVICE_SDB_INTERACTION_HANDLER)), UNO_QUERY);
1440 if ( xHandler.is() )
1441 xHandler->handle(xRequest);
1443 if ( pAbort->wasSelected() )
1444 return sal_False;
1445 if ( pDisApprove->wasSelected() )
1446 return sal_True;
1447 if ( pDocuSave->wasSelected() )
1449 ::osl::MutexGuard aGuard(m_aMutex);
1450 Reference<XNameContainer> xNC(pDocuSave->getContent(),UNO_QUERY);
1451 if ( xNC.is() )
1453 if ( m_pImpl->m_aProps.aTitle == pDocuSave->getName() )
1455 Reference<XEmbedPersist> xPersist(m_xEmbeddedObject,UNO_QUERY);
1456 if ( xPersist.is() )
1458 xPersist->storeOwn();
1459 notifyDataSourceModified();
1462 else
1466 Reference< XStorage> xStorage = getContainerStorage();
1467 const static ::rtl::OUString sBaseName(RTL_CONSTASCII_USTRINGPARAM("Obj"));
1468 // -----------------------------------------------------------------------------
1469 Reference<XNameAccess> xElements(xStorage,UNO_QUERY_THROW);
1470 ::rtl::OUString sPersistentName = ::dbtools::createUniqueName(xElements,sBaseName);
1471 xStorage->copyElementTo(m_pImpl->m_aProps.sPersistentName,xStorage,sPersistentName);
1473 ::rtl::OUString sOldName = m_pImpl->m_aProps.aTitle;
1474 rename(pDocuSave->getName());
1475 updateDocumentTitle();
1477 Sequence< Any > aArguments(3);
1478 PropertyValue aValue;
1479 // set as folder
1480 aValue.Name = PROPERTY_NAME;
1481 aValue.Value <<= sOldName;
1482 aArguments[0] <<= aValue;
1484 aValue.Name = PROPERTY_PERSISTENT_NAME;
1485 aValue.Value <<= sPersistentName;
1486 aArguments[1] <<= aValue;
1488 aValue.Name = PROPERTY_AS_TEMPLATE;
1489 aValue.Value <<= m_pImpl->m_aProps.bAsTemplate;
1490 aArguments[2] <<= aValue;
1492 Reference< XMultiServiceFactory > xORB( m_xParentContainer, UNO_QUERY_THROW );
1493 Reference< XInterface > xComponent( xORB->createInstanceWithArguments( SERVICE_SDB_DOCUMENTDEFINITION, aArguments ) );
1494 Reference< XNameContainer > xNameContainer( m_xParentContainer, UNO_QUERY_THROW );
1495 xNameContainer->insertByName( sOldName, makeAny( xComponent ) );
1497 catch(Exception&)
1499 DBG_UNHANDLED_EXCEPTION();
1508 catch(Exception&)
1510 OSL_ENSURE(0,"ODocumentDefinition::save: caught an Exception (tried to let the InteractionHandler handle it)!");
1512 return sal_True;
1515 namespace
1517 // .........................................................................
1518 void lcl_putLoadArgs( ::comphelper::NamedValueCollection& _io_rArgs, const optional_bool _bSuppressMacros, const optional_bool _bReadOnly )
1520 if ( !!_bSuppressMacros )
1522 if ( *_bSuppressMacros )
1524 // if we're to suppress macros, do exactly this
1525 _io_rArgs.put( "MacroExecutionMode", MacroExecMode::NEVER_EXECUTE );
1527 else
1529 // otherwise, put the setting only if not already present
1530 if ( !_io_rArgs.has( "MacroExecutionMode" ) )
1532 _io_rArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG );
1537 if ( !!_bReadOnly )
1538 _io_rArgs.put( "ReadOnly", *_bReadOnly );
1542 // -----------------------------------------------------------------------------
1543 namespace
1545 Reference< XFrame > lcl_getDatabaseDocumentFrame( ODatabaseModelImpl& _rImpl )
1547 Reference< XModel > xDatabaseDocumentModel( _rImpl.getModel_noCreate() );
1549 Reference< XController > xDatabaseDocumentController;
1550 if ( xDatabaseDocumentModel.is() )
1551 xDatabaseDocumentController = xDatabaseDocumentModel->getCurrentController();
1553 Reference< XFrame > xFrame;
1554 if ( xDatabaseDocumentController.is() )
1555 xFrame = xDatabaseDocumentController->getFrame();
1557 return xFrame;
1561 // -----------------------------------------------------------------------------
1562 sal_Bool ODocumentDefinition::objectSupportsEmbeddedScripts() const
1564 bool bAllowDocumentMacros = !m_pImpl->m_pDataSource
1565 || ( m_pImpl->m_pDataSource->determineEmbeddedMacros() == ODatabaseModelImpl::eSubDocumentMacros );
1567 // if *any* of the objects of the database document already has macros, we continue to allow it
1568 // to have them, until the user did a migration.
1569 // If there are no macros, yet, we don't allow to create them
1571 return bAllowDocumentMacros;
1574 // -----------------------------------------------------------------------------
1575 ::rtl::OUString ODocumentDefinition::determineContentType() const
1577 return lcl_determineContentType_nothrow( getContainerStorage(), m_pImpl->m_aProps.sPersistentName );
1580 // -----------------------------------------------------------------------------
1581 Sequence< PropertyValue > ODocumentDefinition::fillLoadArgs( const Reference< XConnection>& _xConnection, const bool _bSuppressMacros, const bool _bReadOnly,
1582 const Sequence< PropertyValue >& _rAdditionalArgs, Sequence< PropertyValue >& _out_rEmbeddedObjectDescriptor )
1584 // .........................................................................
1585 // (re-)create interceptor, and put it into the descriptor of the embedded object
1586 if ( m_pInterceptor )
1588 m_pInterceptor->dispose();
1589 m_pInterceptor->release();
1590 m_pInterceptor = NULL;
1593 m_pInterceptor = new OInterceptor( this ,_bReadOnly);
1594 m_pInterceptor->acquire();
1595 Reference<XDispatchProviderInterceptor> xInterceptor = m_pInterceptor;
1597 ::comphelper::NamedValueCollection aEmbeddedDescriptor;
1598 aEmbeddedDescriptor.put( "OutplaceDispatchInterceptor", xInterceptor );
1600 // .........................................................................
1601 // create the OutplaceFrameProperties, and put them into the descriptor of the embedded object
1602 ::comphelper::NamedValueCollection OutplaceFrameProperties;
1603 OutplaceFrameProperties.put( "TopWindow", (sal_Bool)sal_True );
1605 Reference< XFrame > xParentFrame;
1606 if ( m_pImpl->m_pDataSource )
1607 xParentFrame = lcl_getDatabaseDocumentFrame( *m_pImpl->m_pDataSource );
1608 if ( !xParentFrame.is() )
1609 { // i87957 we need a parent frame
1610 if ( !m_xDesktop.is() )
1611 m_xDesktop.set( m_aContext.createComponent( (::rtl::OUString)SERVICE_FRAME_DESKTOP ), UNO_QUERY_THROW );
1612 xParentFrame.set(m_xDesktop,uno::UNO_QUERY);
1613 if ( xParentFrame.is() )
1615 Reference<util::XCloseable> xCloseable(m_pImpl->m_pDataSource->getModel_noCreate(),UNO_QUERY);
1616 if ( xCloseable.is() )
1618 xCloseable->addCloseListener(this);
1619 m_bRemoveListener = sal_True;
1623 OSL_ENSURE( xParentFrame.is(), "ODocumentDefinition::fillLoadArgs: no parent frame!" );
1624 if ( xParentFrame.is() )
1625 OutplaceFrameProperties.put( "ParentFrame", xParentFrame );
1627 aEmbeddedDescriptor.put( "OutplaceFrameProperties", OutplaceFrameProperties.getNamedValues() );
1629 // .........................................................................
1630 // tell the embedded object to have (or not have) script support
1631 aEmbeddedDescriptor.put( "EmbeddedScriptSupport", (sal_Bool)objectSupportsEmbeddedScripts() );
1633 // .........................................................................
1634 // pass the descriptor of the embedded object to the caller
1635 aEmbeddedDescriptor >>= _out_rEmbeddedObjectDescriptor;
1637 // .........................................................................
1638 ::comphelper::NamedValueCollection aMediaDesc( _rAdditionalArgs );
1640 // .........................................................................
1641 // create the ComponentData, and put it into the document's media descriptor
1643 ::comphelper::NamedValueCollection aComponentData;
1644 aComponentData.put( "ActiveConnection", _xConnection );
1645 aComponentData.put( "ApplyFormDesignMode", !_bReadOnly );
1646 aMediaDesc.put( "ComponentData", aComponentData.getPropertyValues() );
1649 if ( m_pImpl->m_aProps.aTitle.getLength() )
1650 aMediaDesc.put( "DocumentTitle", m_pImpl->m_aProps.aTitle );
1652 aMediaDesc.put( "DocumentBaseURL", m_pImpl->m_pDataSource->getURL() );
1654 // .........................................................................
1655 // put the common load arguments into the document's media descriptor
1656 lcl_putLoadArgs( aMediaDesc, optional_bool( _bSuppressMacros ), optional_bool( _bReadOnly ) );
1658 return aMediaDesc.getPropertyValues();
1660 // -----------------------------------------------------------------------------
1661 void ODocumentDefinition::loadEmbeddedObject( const Reference< XConnection >& _xConnection, const Sequence< sal_Int8 >& _aClassID,
1662 const Sequence< PropertyValue >& _rAdditionalArgs, const bool _bSuppressMacros, const bool _bReadOnly )
1664 if ( !m_xEmbeddedObject.is() )
1666 Reference< XStorage> xStorage = getContainerStorage();
1667 if ( xStorage.is() )
1669 Reference< XEmbedObjectFactory> xEmbedFactory( m_aContext.createComponent( "com.sun.star.embed.OOoEmbeddedObjectFactory" ), UNO_QUERY );
1670 if ( xEmbedFactory.is() )
1672 ::rtl::OUString sDocumentService;
1673 sal_Bool bSetSize = sal_False;
1674 sal_Int32 nEntryConnectionMode = EntryInitModes::DEFAULT_INIT;
1675 Sequence< sal_Int8 > aClassID = _aClassID;
1676 if ( aClassID.getLength() )
1678 nEntryConnectionMode = EntryInitModes::TRUNCATE_INIT;
1679 bSetSize = sal_True;
1681 else
1683 sDocumentService = GetDocumentServiceFromMediaType( getContentType(), m_aContext, aClassID );
1684 // check if we are not a form and
1685 // the com.sun.star.report.pentaho.SOReportJobFactory is not present.
1686 if ( !m_bForm && !sDocumentService.equalsAscii("com.sun.star.text.TextDocument"))
1688 // we seems to be a new report, check if report extension is present.
1689 Reference< XContentEnumerationAccess > xEnumAccess( m_aContext.getLegacyServiceFactory(), UNO_QUERY );
1690 const ::rtl::OUString sReportEngineServiceName = ::dbtools::getDefaultReportEngineServiceName(m_aContext.getLegacyServiceFactory());
1691 Reference< XEnumeration > xEnumDrivers = xEnumAccess->createContentEnumeration(sReportEngineServiceName);
1692 if ( !xEnumDrivers.is() || !xEnumDrivers->hasMoreElements() )
1694 com::sun::star::io::WrongFormatException aWFE;
1695 aWFE.Message = ::rtl::OUString::createFromAscii("Extension not present.");
1696 // TODO: resource
1697 throw aWFE;
1700 if ( !aClassID.getLength() )
1702 if ( m_bForm )
1703 aClassID = MimeConfigurationHelper::GetSequenceClassID(SO3_SW_CLASSID);
1704 else
1706 aClassID = MimeConfigurationHelper::GetSequenceClassID(SO3_RPT_CLASSID_90);
1711 OSL_ENSURE( aClassID.getLength(),"No Class ID" );
1713 Sequence< PropertyValue > aEmbeddedObjectDescriptor;
1714 Sequence< PropertyValue > aLoadArgs( fillLoadArgs(
1715 _xConnection, _bSuppressMacros, _bReadOnly, _rAdditionalArgs, aEmbeddedObjectDescriptor ) );
1717 m_xEmbeddedObject.set(xEmbedFactory->createInstanceUserInit(aClassID
1718 ,sDocumentService
1719 ,xStorage
1720 ,m_pImpl->m_aProps.sPersistentName
1721 ,nEntryConnectionMode
1722 ,aLoadArgs
1723 ,aEmbeddedObjectDescriptor
1724 ),UNO_QUERY);
1725 if ( m_xEmbeddedObject.is() )
1727 if ( !m_pClientHelper )
1729 m_pClientHelper = new OEmbeddedClientHelper(this);
1730 m_pClientHelper->acquire();
1732 Reference<XEmbeddedClient> xClient = m_pClientHelper;
1733 m_xEmbeddedObject->setClientSite(xClient);
1734 m_xEmbeddedObject->changeState(EmbedStates::RUNNING);
1735 if ( bSetSize )
1737 awt::Size aSize( DEFAULT_WIDTH, DEFAULT_HEIGHT );
1739 m_xEmbeddedObject->setVisualAreaSize(Aspects::MSOLE_CONTENT,aSize);
1745 else
1747 sal_Int32 nCurrentState = m_xEmbeddedObject->getCurrentState();
1748 if ( nCurrentState == EmbedStates::LOADED )
1750 if ( !m_pClientHelper )
1752 m_pClientHelper = new OEmbeddedClientHelper(this);
1753 m_pClientHelper->acquire();
1755 Reference<XEmbeddedClient> xClient = m_pClientHelper;
1756 m_xEmbeddedObject->setClientSite(xClient);
1758 Sequence< PropertyValue > aEmbeddedObjectDescriptor;
1759 Sequence< PropertyValue > aLoadArgs( fillLoadArgs(
1760 _xConnection, _bSuppressMacros, _bReadOnly, _rAdditionalArgs, aEmbeddedObjectDescriptor ) );
1762 Reference<XCommonEmbedPersist> xCommon(m_xEmbeddedObject,UNO_QUERY);
1763 OSL_ENSURE(xCommon.is(),"unsupported interface!");
1764 if ( xCommon.is() )
1765 xCommon->reload( aLoadArgs, aEmbeddedObjectDescriptor );
1766 m_xEmbeddedObject->changeState(EmbedStates::RUNNING);
1768 else
1770 OSL_ENSURE( ( nCurrentState == EmbedStates::RUNNING ) || ( nCurrentState == EmbedStates::ACTIVE ),
1771 "ODocumentDefinition::loadEmbeddedObject: unexpected state!" );
1773 // if the document was already loaded (which means the embedded object is in state RUNNING or ACTIVE),
1774 // then just re-set some model parameters
1777 Reference< XModel > xModel( getComponent(), UNO_QUERY_THROW );
1778 Sequence< PropertyValue > aArgs = xModel->getArgs();
1780 ::comphelper::NamedValueCollection aMediaDesc( aArgs );
1781 ::comphelper::NamedValueCollection aArguments( _rAdditionalArgs );
1782 aMediaDesc.merge( aArguments, sal_False );
1784 lcl_putLoadArgs( aMediaDesc, optional_bool(), optional_bool() );
1785 // don't put _bSuppressMacros and _bReadOnly here - if the document was already
1786 // loaded, we should not tamper with its settings.
1787 // #i88977# / 2008-05-05 / frank.schoenheit@sun.com
1788 // #i86872# / 2008-03-13 / frank.schoenheit@sun.com
1790 aMediaDesc >>= aArgs;
1791 xModel->attachResource( xModel->getURL(), aArgs );
1793 catch( const Exception& )
1795 DBG_UNHANDLED_EXCEPTION();
1800 // set the OfficeDatabaseDocument instance as parent of the embedded document
1801 // #i40358# / 2005-01-19 / frank.schoenheit@sun.com
1802 Reference< XChild > xDepdendDocAsChild( getComponent(), UNO_QUERY );
1803 if ( xDepdendDocAsChild.is() )
1807 if ( !xDepdendDocAsChild->getParent().is() )
1808 { // first encounter
1809 xDepdendDocAsChild->setParent( getDataSource( m_xParentContainer ) );
1812 catch( const Exception& )
1814 DBG_UNHANDLED_EXCEPTION();
1819 // -----------------------------------------------------------------------------
1820 void ODocumentDefinition::onCommandPreview(Any& _rImage)
1822 loadEmbeddedObjectForPreview();
1823 if ( m_xEmbeddedObject.is() )
1827 Reference<XTransferable> xTransfer(getComponent(),UNO_QUERY);
1828 if ( xTransfer.is() )
1830 DataFlavor aFlavor;
1831 aFlavor.MimeType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("image/png"));
1832 aFlavor.HumanPresentableName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Portable Network Graphics"));
1833 aFlavor.DataType = ::getCppuType(static_cast< const Sequence < sal_Int8 >* >(NULL));
1835 _rImage = xTransfer->getTransferData( aFlavor );
1838 catch( Exception )
1843 // -----------------------------------------------------------------------------
1844 void ODocumentDefinition::getPropertyDefaultByHandle( sal_Int32 /*_nHandle*/, Any& _rDefault ) const
1846 _rDefault.clear();
1848 // -----------------------------------------------------------------------------
1849 void ODocumentDefinition::onCommandGetDocumentProperties( Any& _rProps )
1851 loadEmbeddedObjectForPreview();
1852 if ( m_xEmbeddedObject.is() )
1856 Reference<XDocumentPropertiesSupplier> xDocSup(
1857 getComponent(), UNO_QUERY );
1858 if ( xDocSup.is() )
1859 _rProps <<= xDocSup->getDocumentProperties();
1861 catch( const Exception& )
1863 DBG_UNHANDLED_EXCEPTION();
1867 // -----------------------------------------------------------------------------
1868 Reference< util::XCloseable> ODocumentDefinition::getComponent() throw (RuntimeException)
1870 OSL_ENSURE(m_xEmbeddedObject.is(),"Illegal call for embeddedObject");
1871 Reference< util::XCloseable> xComp;
1872 if ( m_xEmbeddedObject.is() )
1874 int nOldState = m_xEmbeddedObject->getCurrentState();
1875 int nState = nOldState;
1876 if ( nOldState == EmbedStates::LOADED )
1878 m_xEmbeddedObject->changeState( EmbedStates::RUNNING );
1879 nState = EmbedStates::RUNNING;
1882 if ( nState == EmbedStates::ACTIVE || nState == EmbedStates::RUNNING )
1884 Reference<XComponentSupplier> xCompProv(m_xEmbeddedObject,UNO_QUERY);
1885 if ( xCompProv.is() )
1887 xComp = xCompProv->getComponent();
1888 OSL_ENSURE(xComp.is(),"No valid component");
1892 return xComp;
1895 // -----------------------------------------------------------------------------
1896 namespace
1898 Reference< XDatabaseDocumentUI > lcl_getDatabaseDocumentUI( ODatabaseModelImpl& _rModelImpl )
1900 Reference< XDatabaseDocumentUI > xUI;
1902 Reference< XModel > xModel( _rModelImpl.getModel_noCreate() );
1903 if ( xModel.is() )
1904 xUI.set( xModel->getCurrentController(), UNO_QUERY );
1905 return xUI;
1909 // -----------------------------------------------------------------------------
1910 Reference< XComponent > ODocumentDefinition::impl_openUI_nolck_throw( bool _bForEditing )
1912 ::osl::ClearableMutexGuard aGuard( m_aMutex );
1913 if ( !m_pImpl || !m_pImpl->m_pDataSource )
1914 throw DisposedException();
1916 Reference< XDatabaseDocumentUI > xUI( lcl_getDatabaseDocumentUI( *m_pImpl->m_pDataSource ) );
1917 if ( !xUI.is() )
1919 // no XDatabaseDocumentUI -> just execute the respective command
1920 m_bOpenInDesign = _bForEditing;
1921 Any aComponent;
1922 onCommandOpenSomething( Any(), true, NULL, aComponent, aGuard );
1923 Reference< XComponent > xComponent;
1924 OSL_VERIFY( aComponent >>= xComponent );
1925 return xComponent;
1928 Reference< XComponent > xComponent;
1931 ::rtl::OUString sName( impl_getHierarchicalName( false ) );
1932 sal_Int32 nObjectType = m_bForm ? DatabaseObject::FORM : DatabaseObject::REPORT;
1933 aGuard.clear();
1935 xComponent = xUI->loadComponent(
1936 nObjectType, sName, _bForEditing
1939 catch( RuntimeException& ) { throw; }
1940 catch( const Exception& )
1942 throw WrappedTargetException(
1943 ::rtl::OUString(), *this, ::cppu::getCaughtException() );
1945 return xComponent;
1948 // -----------------------------------------------------------------------------
1949 void ODocumentDefinition::impl_store_throw()
1951 Reference<XEmbedPersist> xPersist( m_xEmbeddedObject, UNO_QUERY );
1952 if ( xPersist.is() )
1954 xPersist->storeOwn();
1955 notifyDataSourceModified();
1959 // -----------------------------------------------------------------------------
1960 bool ODocumentDefinition::impl_close_throw()
1962 bool bSuccess = prepareClose();
1963 if ( bSuccess && m_xEmbeddedObject.is() )
1965 m_xEmbeddedObject->changeState( EmbedStates::LOADED );
1966 bSuccess = m_xEmbeddedObject->getCurrentState() == EmbedStates::LOADED;
1968 return bSuccess;
1971 // -----------------------------------------------------------------------------
1972 Reference< XComponent > SAL_CALL ODocumentDefinition::open( ) throw (WrappedTargetException, RuntimeException)
1974 return impl_openUI_nolck_throw( false );
1977 // -----------------------------------------------------------------------------
1978 Reference< XComponent > SAL_CALL ODocumentDefinition::openDesign( ) throw (WrappedTargetException, RuntimeException)
1980 return impl_openUI_nolck_throw( true );
1983 // -----------------------------------------------------------------------------
1984 void SAL_CALL ODocumentDefinition::store( ) throw (WrappedTargetException, RuntimeException)
1986 ::osl::MutexGuard aGuard( m_aMutex );
1989 impl_store_throw();
1991 catch( RuntimeException& ) { throw; }
1992 catch( const Exception& )
1994 throw WrappedTargetException(
1995 ::rtl::OUString(), *this, ::cppu::getCaughtException() );
1999 // -----------------------------------------------------------------------------
2000 ::sal_Bool SAL_CALL ODocumentDefinition::close( ) throw (WrappedTargetException, RuntimeException)
2002 ::osl::MutexGuard aGuard( m_aMutex );
2004 sal_Bool bSuccess = sal_False;
2007 bSuccess = impl_close_throw();
2009 catch( RuntimeException& ) { throw; }
2010 catch( const Exception& )
2012 throw WrappedTargetException(
2013 ::rtl::OUString(), *this, ::cppu::getCaughtException() );
2015 return bSuccess;
2019 // -----------------------------------------------------------------------------
2020 void SAL_CALL ODocumentDefinition::rename( const ::rtl::OUString& _rNewName ) throw (SQLException, ElementExistException, RuntimeException)
2024 osl::ClearableGuard< osl::Mutex > aGuard(m_aMutex);
2025 if ( _rNewName.equals( m_pImpl->m_aProps.aTitle ) )
2026 return;
2028 // document definitions are organized in a hierarchical way, so reject names
2029 // which contain a /, as this is reserved for hierarchy level separation
2030 if ( _rNewName.indexOf( '/' ) != -1 )
2031 m_aErrorHelper.raiseException( ErrorCondition::DB_OBJECT_NAME_WITH_SLASHES, *this );
2033 sal_Int32 nHandle = PROPERTY_ID_NAME;
2034 Any aOld = makeAny( m_pImpl->m_aProps.aTitle );
2035 Any aNew = makeAny( _rNewName );
2037 aGuard.clear();
2038 fire(&nHandle, &aNew, &aOld, 1, sal_True );
2039 m_pImpl->m_aProps.aTitle = _rNewName;
2040 fire(&nHandle, &aNew, &aOld, 1, sal_False );
2042 ::osl::ClearableGuard< ::osl::Mutex > aGuard2( m_aMutex );
2043 if ( m_xEmbeddedObject.is() && m_xEmbeddedObject->getCurrentState() == EmbedStates::ACTIVE )
2044 updateDocumentTitle();
2046 catch(const PropertyVetoException&)
2048 throw ElementExistException(_rNewName,*this);
2051 // -----------------------------------------------------------------------------
2052 Reference< XStorage> ODocumentDefinition::getContainerStorage() const
2054 return m_pImpl->m_pDataSource
2055 ? m_pImpl->m_pDataSource->getStorage( ODatabaseModelImpl::getObjectContainerStorageName( m_bForm ? ODatabaseModelImpl::E_FORM : ODatabaseModelImpl::E_REPORT ) )
2056 : Reference< XStorage>();
2058 // -----------------------------------------------------------------------------
2059 sal_Bool ODocumentDefinition::isModified()
2061 osl::ClearableGuard< osl::Mutex > aGuard(m_aMutex);
2062 sal_Bool bRet = sal_False;
2063 if ( m_xEmbeddedObject.is() )
2065 Reference<XModifiable> xModel(getComponent(),UNO_QUERY);
2066 bRet = xModel.is() && xModel->isModified();
2068 return bRet;
2070 // -----------------------------------------------------------------------------
2071 bool ODocumentDefinition::prepareClose()
2073 if ( !m_xEmbeddedObject.is() )
2074 return true;
2078 // suspend the controller. Embedded objects are not allowed to raise
2079 // own UI at their own discretion, instead, this has always to be triggered
2080 // by the embedding component. Thus, we do the suspend call here.
2081 // #i49370# / 2005-06-09 / frank.schoenheit@sun.com
2083 Reference< XModel > xModel( getComponent(), UNO_QUERY );
2084 Reference< XController > xController;
2085 if ( xModel.is() )
2086 xController = xModel->getCurrentController();
2088 OSL_ENSURE( xController.is() || ( m_xEmbeddedObject->getCurrentState() < EmbedStates::ACTIVE ),
2089 "ODocumentDefinition::prepareClose: no controller!" );
2090 if ( !xController.is() )
2091 // document has not yet been activated, i.e. has no UI, yet
2092 return true;
2094 sal_Bool bCouldSuspend = xController->suspend( sal_True );
2095 if ( !bCouldSuspend )
2096 // controller vetoed the closing
2097 return false;
2099 if ( isModified() )
2101 Reference< XFrame > xFrame( xController->getFrame() );
2102 if ( xFrame.is() )
2104 Reference< XTopWindow > xTopWindow( xFrame->getContainerWindow(), UNO_QUERY_THROW );
2105 xTopWindow->toFront();
2107 if ( !save( sal_True ) )
2109 if ( bCouldSuspend )
2110 // revert suspension
2111 xController->suspend( sal_False );
2112 // saving failed or was cancelled
2113 return false;
2117 catch( const Exception& )
2119 DBG_UNHANDLED_EXCEPTION();
2122 return true;
2124 // -----------------------------------------------------------------------------
2125 void ODocumentDefinition::fillReportData(::osl::ClearableMutexGuard & _aGuard)
2127 if ( !m_bForm && m_pImpl->m_aProps.bAsTemplate && !m_bOpenInDesign ) // open a report in alive mode, so we need to fill it
2129 Sequence<Any> aArgs(2);
2130 PropertyValue aValue;
2131 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TextDocument"));
2132 aValue.Value <<= getComponent();
2133 aArgs[0] <<= aValue;
2134 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ActiveConnection"));
2135 aValue.Value <<= m_xLastKnownConnection;
2136 aArgs[1] <<= aValue;
2138 Reference< XJobExecutor > xExecuteable( m_aContext.createComponentWithArguments( "com.sun.star.wizards.report.CallReportWizard", aArgs ), UNO_QUERY );
2139 if ( xExecuteable.is() )
2141 _aGuard.clear();
2142 xExecuteable->trigger(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("fill")));
2146 // -----------------------------------------------------------------------------
2147 void ODocumentDefinition::updateDocumentTitle()
2149 ::rtl::OUString sName = m_pImpl->m_aProps.aTitle;
2150 if ( m_pImpl->m_pDataSource )
2152 if ( !sName.getLength() )
2154 if ( m_bForm )
2155 sName = DBACORE_RESSTRING( RID_STR_FORM );
2156 else
2157 sName = DBACORE_RESSTRING( RID_STR_REPORT );
2158 Reference< XUntitledNumbers > xUntitledProvider(m_pImpl->m_pDataSource->getModel_noCreate(), UNO_QUERY );
2159 if ( xUntitledProvider.is() )
2160 sName += ::rtl::OUString::valueOf( xUntitledProvider->leaseNumber(getComponent()) );
2163 Reference< XTitle > xDatabaseDocumentModel(m_pImpl->m_pDataSource->getModel_noCreate(),uno::UNO_QUERY);
2164 if ( xDatabaseDocumentModel.is() )
2165 sName = xDatabaseDocumentModel->getTitle() + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" : ")) + sName;
2167 Reference< XTitle> xTitle(getComponent(),UNO_QUERY);
2168 if ( xTitle.is() )
2169 xTitle->setTitle(sName);
2171 // -----------------------------------------------------------------------------
2172 void SAL_CALL ODocumentDefinition::queryClosing( const lang::EventObject& Source, ::sal_Bool GetsOwnership ) throw (util::CloseVetoException, uno::RuntimeException)
2174 (void) Source;
2175 (void) GetsOwnership;
2178 if ( !close() )
2179 throw util::CloseVetoException();
2181 catch(const lang::WrappedTargetException&)
2183 throw util::CloseVetoException();
2186 // -----------------------------------------------------------------------------
2187 void SAL_CALL ODocumentDefinition::notifyClosing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException)
2190 // -----------------------------------------------------------------------------
2191 void SAL_CALL ODocumentDefinition::disposing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException)
2194 //........................................................................
2195 } // namespace dbaccess
2196 //........................................................................