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