Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / extensions / source / propctrlr / eformshelper.hxx
blob8ce00e446e254745650e3cb97ebaa2116d7487fb
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_EXTENSIONS_SOURCE_PROPCTRLR_EFORMSHELPER_HXX
21 #define INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_EFORMSHELPER_HXX
23 #include "pcrcommon.hxx"
25 #include <com/sun/star/frame/XModel.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/xforms/XModel.hpp>
28 #include <com/sun/star/xforms/XFormsSupplier.hpp>
29 #include <com/sun/star/form/binding/XBindableValue.hpp>
30 #include <com/sun/star/form/binding/XListEntrySource.hpp>
31 #include <osl/mutex.hxx>
32 #include <rtl/ustring.hxx>
34 #include <vector>
35 #include <set>
36 #include <map>
39 namespace pcr
43 typedef std::map< OUString, css::uno::Reference< css::beans::XPropertySet >, std::less< OUString > >
44 MapStringToPropertySet;
47 //= EFormsHelper
49 class EFormsHelper
51 protected:
52 css::uno::Reference< css::beans::XPropertySet >
53 m_xControlModel;
54 css::uno::Reference< css::form::binding::XBindableValue >
55 m_xBindableControl;
56 css::uno::Reference< css::xforms::XFormsSupplier >
57 m_xDocument;
58 PropertyChangeListeners
59 m_aPropertyListeners;
60 MapStringToPropertySet
61 m_aSubmissionUINames; // only filled upon request
62 MapStringToPropertySet
63 m_aBindingUINames; // only filled upon request
65 public:
66 EFormsHelper(
67 ::osl::Mutex& _rMutex,
68 const css::uno::Reference< css::beans::XPropertySet >& _rxControlModel,
69 const css::uno::Reference< css::frame::XModel >& _rxContextDocument
72 /** determines whether the given document is an eForm
74 If this method returns <FALSE/>, you cannot instantiate an EFormsHelper with
75 this document, since none of its functionality will be available then.
77 static bool
78 isEForm(
79 const css::uno::Reference< css::frame::XModel >& _rxContextDocument
82 /** registers a listener to be notified when any aspect of the binding changes.
84 The listener will be registered at the current binding of the control model. If the binding
85 changes (see <method>setBinding</method>), the listener will be revoked from the old binding,
86 registered at the new binding, and for all properties which differ between both bindings,
87 the listener will be notified.
88 @see revokeBindingListener
90 void registerBindingListener(
91 const css::uno::Reference< css::beans::XPropertyChangeListener >& _rxBindingListener
94 /** revokes the binding listener which has previously been registered
95 @see registerBindingListener
97 void revokeBindingListener(
98 const css::uno::Reference< css::beans::XPropertyChangeListener >& _rxBindingListener
101 /** checks whether it's possible to bind the control model to a given XSD data type
103 @param _nDataType
104 the data type which should be bound. If this is -1, <TRUE/> is returned if the control model
105 can be bound to <em>any</em> data type.
107 bool canBindToDataType( sal_Int32 _nDataType = -1 ) const;
109 /** checks whether the control model can be bound to any XSD data type
111 bool canBindToAnyDataType() const { return canBindToDataType(); }
113 /** checks whether the control model is a source for list entries, as supplied by XML data bindings
115 bool isListEntrySink() const;
117 /** retrieves the names of all XForms models in the document the control lives in
119 void getFormModelNames( std::vector< OUString >& /* [out] */ _rModelNames ) const;
121 /** retrieves the names of all bindings for a given model
122 @see getFormModelNames
124 void getBindingNames( const OUString& _rModelName, std::vector< OUString >& /* [out] */ _rBindingNames ) const;
126 /// retrieves the XForms model (within the control model's document) with the given name
127 css::uno::Reference< css::xforms::XModel >
128 getFormModelByName( const OUString& _rModelName ) const;
130 /** retrieves the model which the active binding of the control model belongs to
132 css::uno::Reference< css::xforms::XModel >
133 getCurrentFormModel() const;
135 /** retrieves the name of the model which the active binding of the control model belongs to
137 OUString
138 getCurrentFormModelName() const;
140 /** retrieves the binding instance which is currently attached to the control model
142 css::uno::Reference< css::beans::XPropertySet >
143 getCurrentBinding() const;
145 /** retrieves the name of the binding instance which is currently attached to the control model
147 OUString
148 getCurrentBindingName() const;
150 /** sets a new binding at the control model
152 void setBinding( const css::uno::Reference< css::beans::XPropertySet >& _rxBinding );
154 /** retrieves the binding instance which is currently used as list source for the control model
155 @see isListEntrySink
157 css::uno::Reference< css::form::binding::XListEntrySource >
158 getCurrentListSourceBinding() const;
160 /** sets a new list source at the control model
161 @see isListEntrySink
163 void setListSourceBinding( const css::uno::Reference< css::form::binding::XListEntrySource >& _rxListSource );
165 /** retrieves a given binding for a given model, or creates a new one
167 @param _rTargetModel
168 the name of the model to create a binding for. Must not be empty
169 @param _rBindingName
170 the name of the binding to retrieve. If the model denoted by <arg>_rTargetModel</arg> does not
171 have a binding with this name, a new binding is created and returned.
173 css::uno::Reference< css::beans::XPropertySet >
174 getOrCreateBindingForModel( const OUString& _rTargetModel, const OUString& _rBindingName ) const;
176 /** types of sub-elements of a model
178 enum ModelElementType
180 Submission,
181 Binding
184 /** retrieves the name of a model's sub-element, as to be shown in the UI
185 @see getModelElementFromUIName
186 @see getAllElementUINames
188 static OUString
189 getModelElementUIName(
190 const ModelElementType _eType,
191 const css::uno::Reference< css::beans::XPropertySet >& _rxElement
194 /** retrieves the submission object for an UI name
196 Note that <member>getAllElementUINames</member> must have been called before, for the given element type
198 @see getModelElementUIName
199 @see getAllElementUINames
201 css::uno::Reference< css::beans::XPropertySet >
202 getModelElementFromUIName(
203 const ModelElementType _eType,
204 const OUString& _rUIName
205 ) const;
207 /** retrieves the UI names of all elements of all models in our document
208 @param _eType
209 the type of elements for which the names should be retrieved
210 @param _rElementNames
211 the array of element names
212 @see getModelElementUIName
213 @see getModelElementFromUIName
215 void getAllElementUINames(
216 const ModelElementType _eType,
217 std::vector< OUString >& /* [out] */ _rElementNames,
218 bool _bPrepentEmptyEntry
221 protected:
222 void firePropertyChanges(
223 const css::uno::Reference< css::beans::XPropertySet >& _rxOldProps,
224 const css::uno::Reference< css::beans::XPropertySet >& _rxNewProps,
225 std::set< OUString >& _rFilter
226 ) const;
228 /** fires a change in a single property, if the property value changed, and if we have a listener
229 interested in property changes
231 void firePropertyChange(
232 const OUString& _rName,
233 const css::uno::Any& _rOldValue,
234 const css::uno::Any& _rNewValue
235 ) const;
237 private:
238 void impl_switchBindingListening_throw( bool _bDoListening, const css::uno::Reference< css::beans::XPropertyChangeListener >& _rxListener );
240 /// implementation for both <member>getOrCreateBindingForModel</member>
241 css::uno::Reference< css::beans::XPropertySet >
242 implGetOrCreateBinding( const OUString& _rTargetModel, const OUString& _rBindingName ) const;
244 void
245 impl_toggleBindingPropertyListening_throw( bool _bDoListen, const css::uno::Reference< css::beans::XPropertyChangeListener >& _rxConcreteListenerOrNull );
247 private:
248 EFormsHelper( const EFormsHelper& ) = delete;
249 EFormsHelper& operator=( const EFormsHelper& ) = delete;
253 } // namespace pcr
256 #endif // INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_EFORMSHELPER_HXX
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */