build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / dbaccess / source / core / dataaccess / documentdefinition.hxx
blobbef6c99c94854c5c8ddc981ecf28c24a671b93b6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_DBACCESS_SOURCE_CORE_DATAACCESS_DOCUMENTDEFINITION_HXX
21 #define INCLUDED_DBACCESS_SOURCE_CORE_DATAACCESS_DOCUMENTDEFINITION_HXX
23 #include <cppuhelper/propshlp.hxx>
24 #include <cppuhelper/implbase4.hxx>
25 #include "ContentHelper.hxx"
26 #include <comphelper/propertystatecontainer.hxx>
27 #include <comphelper/proparrhlp.hxx>
28 #include "apitools.hxx"
29 #include <comphelper/uno3.hxx>
30 #include <com/sun/star/sdbc/XConnection.hpp>
31 #include <com/sun/star/frame/XComponentLoader.hpp>
32 #include <com/sun/star/frame/XController.hpp>
33 #include <com/sun/star/embed/XStateChangeListener.hpp>
34 #include <com/sun/star/sdb/XSubDocument.hpp>
35 #include <com/sun/star/util/XCloseListener.hpp>
36 #include <com/sun/star/container/XHierarchicalName.hpp>
38 namespace comphelper
40 class NamedValueCollection;
43 namespace dbaccess
46 class OInterceptor;
47 class OEmbeddedClientHelper;
48 // ODocumentDefinition - a database "document" which is simply a link to a real
49 // document
51 typedef ::cppu::ImplHelper4 < css::embed::XComponentSupplier
52 , css::sdb::XSubDocument
53 , css::util::XCloseListener
54 , css::container::XHierarchicalName
55 > ODocumentDefinition_Base;
57 class ODocumentDefinition
58 :public OContentHelper
59 ,public ::comphelper::OPropertyStateContainer
60 ,public ::comphelper::OPropertyArrayUsageHelper< ODocumentDefinition >
61 ,public ODocumentDefinition_Base
63 css::uno::Reference< css::embed::XEmbeddedObject> m_xEmbeddedObject;
64 css::uno::Reference< css::embed::XStateChangeListener > m_xListener;
65 css::uno::Reference< css::sdbc::XConnection > m_xLastKnownConnection;
67 rtl::Reference<OInterceptor> m_pInterceptor;
68 bool m_bForm; // <TRUE/> if it is a form
69 bool m_bOpenInDesign;
70 bool m_bInExecute;
71 bool m_bRemoveListener;
72 rtl::Reference<OEmbeddedClientHelper> m_pClientHelper;
74 protected:
75 virtual ~ODocumentDefinition() override;
77 public:
79 ODocumentDefinition(
80 const css::uno::Reference< css::uno::XInterface >& _rxContainer,
81 const css::uno::Reference< css::uno::XComponentContext >&,
82 const TContentPtr& _pImpl,
83 bool _bForm
86 void initialLoad(
87 const css::uno::Sequence< sal_Int8 >& i_rClassID,
88 const css::uno::Sequence< css::beans::PropertyValue >& i_rCreationArgs,
89 const css::uno::Reference< css::sdbc::XConnection >& i_rConnection
92 virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes()
93 throw (css::uno::RuntimeException, std::exception) override;
94 virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId()
95 throw (css::uno::RuntimeException, std::exception) override;
97 // css::uno::XInterface
98 DECLARE_XINTERFACE( )
100 // css::beans::XPropertySet
101 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(css::uno::RuntimeException, std::exception) override;
103 // OPropertySetHelper
104 virtual void SAL_CALL getFastPropertyValue(
105 css::uno::Any& o_rValue,
106 sal_Int32 i_nHandle
107 ) const override;
109 // XComponentSupplier
110 virtual css::uno::Reference< css::util::XCloseable > SAL_CALL getComponent( ) throw (css::uno::RuntimeException, std::exception) override;
112 // XSubDocument
113 virtual css::uno::Reference< css::lang::XComponent > SAL_CALL open( ) throw (css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) override;
114 virtual css::uno::Reference< css::lang::XComponent > SAL_CALL openDesign( ) throw (css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) override;
115 virtual void SAL_CALL store( ) throw (css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) override;
116 virtual sal_Bool SAL_CALL close( ) throw (css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) override;
118 // XHierarchicalName
119 virtual OUString SAL_CALL getHierarchicalName( ) throw (css::uno::RuntimeException, std::exception) override;
120 virtual OUString SAL_CALL composeHierarchicalName( const OUString& aRelativeName ) throw (css::lang::IllegalArgumentException, css::lang::NoSupportException, css::uno::RuntimeException, std::exception) override;
122 // OPropertySetHelper
123 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
125 // XCommandProcessor
126 virtual css::uno::Any SAL_CALL execute( const css::ucb::Command& aCommand, sal_Int32 CommandId, const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment ) throw (css::uno::Exception, css::ucb::CommandAbortedException, css::uno::RuntimeException, std::exception) override ;
128 // XRename
129 virtual void SAL_CALL rename( const OUString& newName ) throw (css::sdbc::SQLException, css::container::ElementExistException, css::uno::RuntimeException, std::exception) override;
131 // XCloseListener
132 virtual void SAL_CALL queryClosing( const css::lang::EventObject& Source, sal_Bool GetsOwnership ) throw (css::util::CloseVetoException, css::uno::RuntimeException, std::exception) override;
133 virtual void SAL_CALL notifyClosing( const css::lang::EventObject& Source ) throw (css::uno::RuntimeException, std::exception) override;
135 // XEventListener
136 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) throw (css::uno::RuntimeException, std::exception) override;
138 /** returns the forms/reports container storage, depending on m_bForm. Our own storage
139 inside this container storage is the one with the name as indicated by m_pImpl->m_aProps.sPersistentName.
141 css::uno::Reference< css::embed::XStorage >
142 getContainerStorage() const;
144 bool save(bool _bApprove);
145 void saveAs();
146 void closeObject();
147 bool isModified();
148 inline bool isNewReport() const { return !m_bForm && !m_pImpl->m_aProps.bAsTemplate; }
150 static void fillReportData(
151 const css::uno::Reference< css::uno::XComponentContext > & _rxContext,
152 const css::uno::Reference< css::util::XCloseable >& _rxComponent,
153 const css::uno::Reference< css::sdbc::XConnection >& _rxActiveConnection
156 const css::uno::Reference< css::sdbc::XConnection >&
157 getConnection() const { return m_xLastKnownConnection; }
159 /** prepares closing the document component
161 The method suspends the controller associated with the document, and saves the document
162 if necessary.
164 @return
165 <TRUE/> if and only if the document component can be closed
167 bool prepareClose();
169 static OUString GetDocumentServiceFromMediaType(
170 const OUString& _rMediaType,
171 const css::uno::Reference< css::uno::XComponentContext > & _rxContext,
172 css::uno::Sequence< sal_Int8 >& _rClassId
174 static OUString GetDocumentServiceFromMediaType(
175 const css::uno::Reference< css::embed::XStorage >& _rxContainerStorage,
176 const OUString& _rEntityName,
177 const css::uno::Reference< css::uno::XComponentContext > & _rxContext,
178 css::uno::Sequence< sal_Int8 >& _rClassId
181 struct NotifierAccess { friend class NameChangeNotifier; private: NotifierAccess() { } };
182 const OUString& getCurrentName() const { return m_pImpl->m_aProps.aTitle; }
183 void firePropertyChange(
184 sal_Int32 i_nHandle,
185 const css::uno::Any& i_rNewValue,
186 const css::uno::Any& i_rOldValue,
187 bool i_bVetoable,
188 const NotifierAccess&
191 private:
192 /** does necessary initializations after our embedded object has been switched to ACTIVE
194 void impl_onActivateEmbeddedObject_nothrow( const bool i_bReactivated );
196 /** initializes a newly created view/controller of a form which is displaying our embedded object
198 Has only to be called if the respective embedded object has been loaded for design (and
199 not for data entry)
201 @param _rxController
202 the controller which belongs to the XModel of our (active) embedded object
204 static void impl_initFormEditView( const css::uno::Reference< css::frame::XController >& _rxController );
206 /** removes the given frame from the desktop's frame collection
207 @throws css::uno::RuntimeException
209 static void impl_removeFrameFromDesktop_throw(
210 const css::uno::Reference< css::uno::XComponentContext >& _rContxt,
211 const css::uno::Reference< css::frame::XFrame >& _rxFrame
214 /** opens the UI for this sub document
216 css::uno::Reference< css::lang::XComponent >
217 impl_openUI_nolck_throw( bool _bForEditing );
219 /** stores our document, if it's already loaded
221 void impl_store_throw();
223 /** closes our document, if it's open
225 bool impl_close_throw();
227 /** returns our component, creates it if necessary
229 css::uno::Reference< css::util::XCloseable >
230 impl_getComponent_throw( const bool i_ForceCreate = true );
232 /** shows or hides our component
234 The embedded object must exist, and be in state LOADED, at least.
236 void impl_showOrHideComponent_throw( const bool i_bShow );
238 // OPropertyArrayUsageHelper
239 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override;
241 virtual void getPropertyDefaultByHandle( sal_Int32 _nHandle, css::uno::Any& _rDefault ) const override;
243 // helper
244 virtual void SAL_CALL disposing() override;
246 // OContentHelper overridables
247 virtual OUString determineContentType() const override;
249 /** fills the load arguments
251 css::uno::Sequence< css::beans::PropertyValue >
252 fillLoadArgs(
253 const css::uno::Reference< css::sdbc::XConnection>& _xConnection,
254 const bool _bSuppressMacros,
255 const bool _bReadOnly,
256 const css::uno::Sequence< css::beans::PropertyValue >& i_rOpenCommandArguments,
257 css::uno::Sequence< css::beans::PropertyValue >& _out_rEmbeddedObjectDescriptor
260 /** splits the given arguments to an "open*" command into arguments for loading the document, and arguments to be
261 put into the EmbeddedObjectDescriptor
263 Any values already present in <code>o_rDocumentLoadArgs</code> and <code>o_rEmbeddedObjectDescriptor</code>
264 will be overwritten by values from <code>i_rOpenCommandArguments</code>, if applicable, otherwise they will
265 be preserved.
267 @param i_rOpenCommandArguments
268 the arguments passed to the "open*" command at the content
269 @param o_rDocumentLoadArgs
270 the arguments to be passed when actually loading the embedded document.
271 @param o_rEmbeddedObjectDescriptor
272 the EmbeddedObjectDescriptor to be passed when initializing the embedded object
274 static void separateOpenCommandArguments(
275 const css::uno::Sequence< css::beans::PropertyValue >& i_rOpenCommandArguments,
276 ::comphelper::NamedValueCollection& o_rDocumentLoadArgs,
277 ::comphelper::NamedValueCollection& o_rEmbeddedObjectDescriptor
280 /** loads the EmbeddedObject if not already loaded
281 @param _aClassID
282 If set, it will be used to create the embedded object.
284 void loadEmbeddedObject(
285 const css::uno::Reference< css::sdbc::XConnection>& _xConnection,
286 const css::uno::Sequence< sal_Int8 >& _aClassID,
287 const css::uno::Sequence< css::beans::PropertyValue >& _rAdditionalArgs,
288 const bool _bSuppressMacros,
289 const bool _bReadOnly
292 /** loads the embedded object for preview. Macros will be suppressed, and the document will
293 be read-only.
295 void loadEmbeddedObjectForPreview()
297 loadEmbeddedObject(
298 nullptr,
299 css::uno::Sequence< sal_Int8 >(),
300 css::uno::Sequence< css::beans::PropertyValue >(),
301 true,
302 true
306 /** searches for read-only flag in the args of the model and sets it to the given value,
307 if the value was not found, it will be appended.
308 @param _bReadOnly
309 If <TRUE/> the document will be switched to readonly mode
311 void updateDocumentTitle();
313 void registerProperties();
315 /** determines whether the document we represent supports embedded scripts and macros
317 bool objectSupportsEmbeddedScripts() const;
319 //- commands
321 void onCommandGetDocumentProperties( css::uno::Any& _rProps );
322 /// @throws css::uno::Exception
323 void onCommandInsert( const OUString& _sURL, const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment ) throw( css::uno::Exception );
324 void onCommandPreview( css::uno::Any& _rImage );
325 css::uno::Any
326 onCommandOpenSomething(
327 const css::uno::Any& _rArgument,
328 const bool _bActivate,
329 const css::uno::Reference< css::ucb::XCommandEnvironment >& _rxEnvironment
331 private:
332 using ::cppu::OPropertySetHelper::getFastPropertyValue;
335 class NameChangeNotifier
337 public:
338 NameChangeNotifier(
339 ODocumentDefinition& i_rDocumentDefinition,
340 const OUString& i_rNewName,
341 ::osl::ResettableMutexGuard& i_rClearForNotify
343 ~NameChangeNotifier();
345 private:
346 ODocumentDefinition& m_rDocumentDefinition;
347 const css::uno::Any m_aOldValue;
348 const css::uno::Any m_aNewValue;
349 ::osl::ResettableMutexGuard& m_rClearForNotify;
351 void impl_fireEvent_throw( const bool i_bVetoable );
354 } // namespace dbaccess
356 #endif // INCLUDED_DBACCESS_SOURCE_CORE_DATAACCESS_DOCUMENTDEFINITION_HXX
358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */