Update ooo320-m1
[ooovba.git] / dbaccess / source / core / dataaccess / documentdefinition.hxx
blobde02023f0ca7694da5cde7304c6f61fc459ba2c2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: documentdefinition.hxx,v $
10 * $Revision: 1.28.6.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _DBA_COREDATAACCESS_DOCUMENTDEFINITION_HXX_
32 #define _DBA_COREDATAACCESS_DOCUMENTDEFINITION_HXX_
34 #ifndef _CPPUHELPER_PROPSHLP_HXX
35 #include <cppuhelper/propshlp.hxx>
36 #endif
37 #ifndef _CPPUHELPER_IMPLBASE3_HXX_
38 #include <cppuhelper/implbase3.hxx>
39 #endif
40 #ifndef DBA_CONTENTHELPER_HXX
41 #include "ContentHelper.hxx"
42 #endif
43 #ifndef COMPHELPER_PROPERTYSTATECONTAINER_HXX
44 #include <comphelper/propertystatecontainer.hxx>
45 #endif
46 #ifndef _COMPHELPER_PROPERTY_ARRAY_HELPER_HXX_
47 #include <comphelper/proparrhlp.hxx>
48 #endif
49 #ifndef _DBASHARED_APITOOLS_HXX_
50 #include "apitools.hxx"
51 #endif
52 #ifndef _COMPHELPER_UNO3_HXX_
53 #include <comphelper/uno3.hxx>
54 #endif
55 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
56 #include <com/sun/star/sdbc/XConnection.hpp>
57 #endif
58 #ifndef _COM_SUN_STAR_FRAME_XCOMPONENTLOADER_HPP_
59 #include <com/sun/star/frame/XComponentLoader.hpp>
60 #endif
61 #ifndef _COM_SUN_STAR_FRAME_XCONTROLLER_HPP_
62 #include <com/sun/star/frame/XController.hpp>
63 #endif
64 #ifndef _COM_SUN_STAR_EMBED_XSTATECHANGELISTENER_HPP_
65 #include <com/sun/star/embed/XStateChangeListener.hpp>
66 #endif
67 #include <com/sun/star/sdb/XSubDocument.hpp>
68 #include <com/sun/star/util/XCloseListener.hpp>
70 //........................................................................
71 namespace dbaccess
73 //........................................................................
75 class OInterceptor;
76 class OEmbeddedClientHelper;
77 //==========================================================================
78 //= ODocumentDefinition - a database "document" which is simply a link to a real
79 //= document
80 //==========================================================================
82 typedef ::cppu::ImplHelper3 < ::com::sun::star::embed::XComponentSupplier
83 , ::com::sun::star::sdb::XSubDocument
84 , ::com::sun::star::util::XCloseListener
85 > ODocumentDefinition_Base;
87 class ODocumentDefinition
88 :public OContentHelper
89 ,public ::comphelper::OPropertyStateContainer
90 ,public ::comphelper::OPropertyArrayUsageHelper< ODocumentDefinition >
91 ,public ODocumentDefinition_Base
93 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XEmbeddedObject> m_xEmbeddedObject;
94 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStateChangeListener > m_xListener;
95 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFramesSupplier > m_xDesktop;
96 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > m_xLastKnownConnection;
98 OInterceptor* m_pInterceptor;
99 sal_Bool m_bForm; // <TRUE/> if it is a form
100 sal_Bool m_bOpenInDesign;
101 sal_Bool m_bInExecute;
102 sal_Bool m_bRemoveListener;
103 OEmbeddedClientHelper* m_pClientHelper;
105 protected:
106 virtual ~ODocumentDefinition();
108 public:
110 ODocumentDefinition(
111 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContainer
112 ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&
113 ,const TContentPtr& _pImpl
114 ,sal_Bool _bForm
115 ,const ::com::sun::star::uno::Sequence< sal_Int8 >& _aClassID = ::com::sun::star::uno::Sequence< sal_Int8 >()
116 ,const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection = ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>()
119 // com::sun::star::lang::XTypeProvider
120 DECLARE_TYPEPROVIDER( );
122 // ::com::sun::star::uno::XInterface
123 DECLARE_XINTERFACE( )
125 // ::com::sun::star::lang::XServiceInfo
126 DECLARE_SERVICE_INFO_STATIC();
128 // ::com::sun::star::beans::XPropertySet
129 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException);
131 // XComponentSupplier
132 virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseable > SAL_CALL getComponent( ) throw (::com::sun::star::uno::RuntimeException);
134 // XSubDocument
135 virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL open( ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
136 virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL openDesign( ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
137 virtual void SAL_CALL store( ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
138 virtual ::sal_Bool SAL_CALL close( ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
140 // OPropertySetHelper
141 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
143 // XCommandProcessor
144 virtual ::com::sun::star::uno::Any SAL_CALL execute( const ::com::sun::star::ucb::Command& aCommand, sal_Int32 CommandId, const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& Environment ) throw (::com::sun::star::uno::Exception, ::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::RuntimeException) ;
146 // XRename
147 virtual void SAL_CALL rename( const ::rtl::OUString& newName ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException);
149 // XCloseListener
150 virtual void SAL_CALL queryClosing( const ::com::sun::star::lang::EventObject& Source, ::sal_Bool GetsOwnership ) throw (::com::sun::star::util::CloseVetoException, ::com::sun::star::uno::RuntimeException);
151 virtual void SAL_CALL notifyClosing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
153 // XEventListener
154 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
156 /** returns the forms/reports container storage, depending on m_bForm. Our own storage
157 inside this container storage is the one with the name as indicated by m_pImpl->m_aProps.sPersistentName.
159 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
160 getContainerStorage() const;
162 sal_Bool save(sal_Bool _bApprove);
163 sal_Bool saveAs();
164 void closeObject();
165 sal_Bool isModified();
166 void fillReportData(::osl::ClearableMutexGuard & _aGuard);
167 inline sal_Bool isNewReport() const { return !m_bForm && !m_pImpl->m_aProps.bAsTemplate; }
169 /** prepares closing the document component
171 The method suspends the controller associated with the document, and saves the document
172 if necessary.
174 @return
175 <TRUE/> if and only if the document component can be closed
177 bool prepareClose();
179 static ::com::sun::star::uno::Sequence< sal_Int8 > getDefaultDocumentTypeClassId();
181 static ::rtl::OUString GetDocumentServiceFromMediaType(
182 const ::rtl::OUString& _rMediaType,
183 const ::comphelper::ComponentContext& _rContext,
184 ::com::sun::star::uno::Sequence< sal_Int8 >& _rClassId
186 static ::rtl::OUString GetDocumentServiceFromMediaType(
187 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxContainerStorage,
188 const ::rtl::OUString& _rEntityName,
189 const ::comphelper::ComponentContext& _rContext,
190 ::com::sun::star::uno::Sequence< sal_Int8 >& _rClassId
193 private:
194 /** does necessary initializations after our embedded object has been switched to ACTIVE
195 @param _bOpenedInDesignMode
196 determines whether the embedded object has been opened for designing it or for data display
198 void impl_onActivateEmbeddedObject();
200 /** initializes a newly created view/controller which is displaying our embedded object
202 Has only to be called if the respective embedded object has been loaded for design (and
203 not for data entry)
205 @param _rxController
206 the controller which belongs to the XModel of our (active) embedded object
208 void impl_initObjectEditView( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& _rxController );
210 /** removes the given frame from the desktop's frame collection
211 @raises ::com::sun::star::uno::RuntimeException
213 void impl_removeFrameFromDesktop_throw( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxFrame );
215 /** opens the UI for this sub document
217 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
218 impl_openUI_nolck_throw( bool _bForEditing );
220 /** stores our document, if it's already loaded
222 void
223 impl_store_throw();
225 /** closes our document, if it's open
227 bool
228 impl_close_throw();
230 private:
231 // OPropertyArrayUsageHelper
232 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
234 virtual void getPropertyDefaultByHandle( sal_Int32 _nHandle, ::com::sun::star::uno::Any& _rDefault ) const;
236 // helper
237 virtual void SAL_CALL disposing();
239 // OContentHelper overridables
240 virtual ::rtl::OUString determineContentType() const;
242 private:
243 /** fills the load arguments
245 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >
246 fillLoadArgs(
247 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,
248 const bool _bSuppressMacros,
249 const bool _bReadOnly,
250 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rAdditionalArgs,
251 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _out_rEmbeddedObjectDescriptor
254 /** loads the EmbeddedObject if not already loaded
255 @param _aClassID
256 If set, it will be used to create the embedded object.
258 void loadEmbeddedObject(
259 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,
260 const ::com::sun::star::uno::Sequence< sal_Int8 >& _aClassID,
261 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rAdditionalArgs,
262 const bool _bSuppressMacros,
263 const bool _bReadOnly
266 /** loads the embedded object, if not already loaded. No new object can be created with this method.
268 void loadEmbeddedObject( bool _bSuppressMacros = false )
270 loadEmbeddedObject(
271 NULL,
272 ::com::sun::star::uno::Sequence< sal_Int8 >(),
273 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >(),
274 _bSuppressMacros,
275 false
279 /** loads the embedded object for preview. Macros will be suppressed, and the document will
280 be read-only.
282 void loadEmbeddedObjectForPreview()
284 loadEmbeddedObject(
285 NULL,
286 ::com::sun::star::uno::Sequence< sal_Int8 >(),
287 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >(),
288 true,
289 true
293 /** searches for read-only flag in the args of the model and sets it to the given value,
294 if the value was not found, it will be appended.
295 @param _bReadOnly
296 If <TRUE/> the document will be switched to readonly mode
298 void updateDocumentTitle();
300 void registerProperties();
302 /** determines whether the document we represent supports embedded scripts and macros
304 sal_Bool objectSupportsEmbeddedScripts() const;
306 //-------------------------------------------------------------------------
307 //- commands
308 //-------------------------------------------------------------------------
310 void onCommandGetDocumentProperties( ::com::sun::star::uno::Any& _rProps );
311 void onCommandInsert( const ::rtl::OUString& _sURL, const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& Environment ) throw( ::com::sun::star::uno::Exception );
312 void onCommandPreview( ::com::sun::star::uno::Any& _rImage );
313 void onCommandOpenSomething( const ::com::sun::star::uno::Any& _rArgument, const bool _bActivate,
314 const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& _rxEnvironment,
315 ::com::sun::star::uno::Any& _out_rComponent,
316 ::osl::ClearableMutexGuard & _aClearableGuard);
319 //........................................................................
320 } // namespace dbaccess
321 //........................................................................
323 #endif // _DBA_COREDATAACCESS_DOCUMENTDEFINITION_HXX_