tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / dbaccess / source / core / dataaccess / documentdefinition.hxx
blobb26ca698f412128e646f1c9d92f55ba9ebbde36d
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 #pragma once
22 #include <cppuhelper/propshlp.hxx>
23 #include <cppuhelper/implbase4.hxx>
24 #include <ContentHelper.hxx>
25 #include <comphelper/propertystatecontainer.hxx>
26 #include <comphelper/proparrhlp.hxx>
27 #include <apitools.hxx>
28 #include <comphelper/uno3.hxx>
29 #include <com/sun/star/awt/XTopWindow.hpp>
30 #include <com/sun/star/sdbc/XConnection.hpp>
31 #include <com/sun/star/frame/XController.hpp>
32 #include <com/sun/star/embed/XStateChangeListener.hpp>
33 #include <com/sun/star/embed/XEmbeddedObject.hpp>
34 #include <com/sun/star/embed/XStorage.hpp>
35 #include <com/sun/star/sdb/XSubDocument.hpp>
36 #include <com/sun/star/util/XCloseListener.hpp>
37 #include <com/sun/star/container/XHierarchicalName.hpp>
38 #include <rtl/ref.hxx>
40 namespace comphelper
42 class NamedValueCollection;
45 namespace dbaccess
47 class OEmbedObjectHolder;
48 class OInterceptor;
49 class OEmbeddedClientHelper;
50 // ODocumentDefinition - a database "document" which is simply a link to a real
51 // document
53 typedef ::cppu::ImplHelper4 < css::embed::XComponentSupplier
54 , css::sdb::XSubDocument
55 , css::util::XCloseListener
56 , css::container::XHierarchicalName
57 > ODocumentDefinition_Base;
59 class ODocumentDefinition
60 :public OContentHelper
61 ,public ::comphelper::OPropertyStateContainer
62 ,public ::comphelper::OPropertyArrayUsageHelper< ODocumentDefinition >
63 ,public ODocumentDefinition_Base
65 css::uno::Reference< css::embed::XEmbeddedObject> m_xEmbeddedObject;
66 rtl::Reference< OEmbedObjectHolder > m_xListener;
67 css::uno::Reference< css::sdbc::XConnection > m_xLastKnownConnection;
69 rtl::Reference<OInterceptor> m_pInterceptor;
70 bool m_bForm; // <TRUE/> if it is a form
71 bool m_bOpenInDesign;
72 bool m_bInExecute;
73 bool m_bRemoveListener;
74 rtl::Reference<OEmbeddedClientHelper> m_pClientHelper;
76 protected:
77 virtual ~ODocumentDefinition() override;
79 public:
81 ODocumentDefinition(
82 const css::uno::Reference< css::uno::XInterface >& _rxContainer,
83 const css::uno::Reference< css::uno::XComponentContext >&,
84 const TContentPtr& _pImpl,
85 bool _bForm
88 void initialLoad(
89 const css::uno::Sequence< sal_Int8 >& i_rClassID,
90 const css::uno::Sequence< css::beans::PropertyValue >& i_rCreationArgs,
91 const css::uno::Reference< css::sdbc::XConnection >& i_rConnection
94 virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override;
95 virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override;
97 // css::uno::XInterface
98 DECLARE_XINTERFACE( )
100 // css::beans::XPropertySet
101 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) 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( ) override;
112 // XSubDocument
113 virtual css::uno::Reference< css::lang::XComponent > SAL_CALL open( ) override;
114 virtual css::uno::Reference< css::lang::XComponent > SAL_CALL openDesign( ) override;
115 virtual void SAL_CALL store( ) override;
116 virtual sal_Bool SAL_CALL close( ) override;
118 // XHierarchicalName
119 virtual OUString SAL_CALL getHierarchicalName( ) override;
120 virtual OUString SAL_CALL composeHierarchicalName( const OUString& aRelativeName ) 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 ) override ;
128 // XRename
129 virtual void SAL_CALL rename( const OUString& newName ) override;
131 // XCloseListener
132 virtual void SAL_CALL queryClosing( const css::lang::EventObject& Source, sal_Bool GetsOwnership ) override;
133 virtual void SAL_CALL notifyClosing( const css::lang::EventObject& Source ) override;
135 // XEventListener
136 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) 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, const css::uno::Reference<css::awt::XTopWindow>& rDialogParent);
145 void saveAs();
146 void closeObject();
147 bool isModified();
148 bool isNewReport() const { return !m_bForm && !m_pImpl->m_aProps.bAsTemplate; }
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 >& _rContext,
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 );
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 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */