tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / extensions / source / propctrlr / eformshelper.hxx
blobe88cb7491d6c7bf93e32ae32114e1fb8c9390fab
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 "pcrcommon.hxx"
24 #include <com/sun/star/frame/XModel.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/xforms/XModel.hpp>
27 #include <com/sun/star/xforms/XFormsSupplier.hpp>
28 #include <com/sun/star/form/binding/XBindableValue.hpp>
29 #include <com/sun/star/form/binding/XListEntrySource.hpp>
30 #include <osl/mutex.hxx>
31 #include <rtl/ustring.hxx>
33 #include <vector>
34 #include <set>
35 #include <map>
38 namespace pcr
42 typedef std::map< OUString, css::uno::Reference< css::beans::XPropertySet >, std::less< OUString > >
43 MapStringToPropertySet;
46 //= EFormsHelper
48 class EFormsHelper
50 protected:
51 css::uno::Reference< css::beans::XPropertySet >
52 m_xControlModel;
53 css::uno::Reference< css::form::binding::XBindableValue >
54 m_xBindableControl;
55 css::uno::Reference< css::xforms::XFormsSupplier >
56 m_xDocument;
57 PropertyChangeListeners
58 m_aPropertyListeners;
59 MapStringToPropertySet
60 m_aSubmissionUINames; // only filled upon request
61 MapStringToPropertySet
62 m_aBindingUINames; // only filled upon request
64 public:
65 EFormsHelper(
66 ::osl::Mutex& _rMutex,
67 const css::uno::Reference< css::beans::XPropertySet >& _rxControlModel,
68 const css::uno::Reference< css::frame::XModel >& _rxContextDocument
71 /** determines whether the given document is an eForm
73 If this method returns <FALSE/>, you cannot instantiate an EFormsHelper with
74 this document, since none of its functionality will be available then.
76 static bool
77 isEForm(
78 const css::uno::Reference< css::frame::XModel >& _rxContextDocument
81 /** registers a listener to be notified when any aspect of the binding changes.
83 The listener will be registered at the current binding of the control model. If the binding
84 changes (see <method>setBinding</method>), the listener will be revoked from the old binding,
85 registered at the new binding, and for all properties which differ between both bindings,
86 the listener will be notified.
87 @see revokeBindingListener
89 void registerBindingListener(
90 const css::uno::Reference< css::beans::XPropertyChangeListener >& _rxBindingListener
93 /** revokes the binding listener which has previously been registered
94 @see registerBindingListener
96 void revokeBindingListener(
97 const css::uno::Reference< css::beans::XPropertyChangeListener >& _rxBindingListener
100 /** checks whether it's possible to bind the control model to a given XSD data type
102 @param _nDataType
103 the data type which should be bound. If this is -1, <TRUE/> is returned if the control model
104 can be bound to <em>any</em> data type.
106 bool canBindToDataType( sal_Int32 _nDataType = -1 ) const;
108 /** checks whether the control model can be bound to any XSD data type
110 bool canBindToAnyDataType() const { return canBindToDataType(); }
112 /** checks whether the control model is a source for list entries, as supplied by XML data bindings
114 bool isListEntrySink() const;
116 /** retrieves the names of all XForms models in the document the control lives in
118 void getFormModelNames( std::vector< OUString >& /* [out] */ _rModelNames ) const;
120 /** retrieves the names of all bindings for a given model
121 @see getFormModelNames
123 void getBindingNames( const OUString& _rModelName, std::vector< OUString >& /* [out] */ _rBindingNames ) const;
125 /// retrieves the XForms model (within the control model's document) with the given name
126 css::uno::Reference< css::xforms::XModel >
127 getFormModelByName( const OUString& _rModelName ) const;
129 /** retrieves the model which the active binding of the control model belongs to
131 css::uno::Reference< css::xforms::XModel >
132 getCurrentFormModel() const;
134 /** retrieves the name of the model which the active binding of the control model belongs to
136 OUString
137 getCurrentFormModelName() const;
139 /** retrieves the binding instance which is currently attached to the control model
141 css::uno::Reference< css::beans::XPropertySet >
142 getCurrentBinding() const;
144 /** retrieves the name of the binding instance which is currently attached to the control model
146 OUString
147 getCurrentBindingName() const;
149 /** sets a new binding at the control model
151 void setBinding( const css::uno::Reference< css::beans::XPropertySet >& _rxBinding );
153 /** retrieves the binding instance which is currently used as list source for the control model
154 @see isListEntrySink
156 css::uno::Reference< css::form::binding::XListEntrySource >
157 getCurrentListSourceBinding() const;
159 /** sets a new list source at the control model
160 @see isListEntrySink
162 void setListSourceBinding( const css::uno::Reference< css::form::binding::XListEntrySource >& _rxListSource );
164 /** retrieves a given binding for a given model, or creates a new one
166 @param _rTargetModel
167 the name of the model to create a binding for. Must not be empty
168 @param _rBindingName
169 the name of the binding to retrieve. If the model denoted by <arg>_rTargetModel</arg> does not
170 have a binding with this name, a new binding is created and returned.
172 css::uno::Reference< css::beans::XPropertySet >
173 getOrCreateBindingForModel( const OUString& _rTargetModel, const OUString& _rBindingName ) const;
175 /** types of sub-elements of a model
177 enum ModelElementType
179 Submission,
180 Binding
183 /** retrieves the name of a model's sub-element, as to be shown in the UI
184 @see getModelElementFromUIName
185 @see getAllElementUINames
187 static OUString
188 getModelElementUIName(
189 const ModelElementType _eType,
190 const css::uno::Reference< css::beans::XPropertySet >& _rxElement
193 /** retrieves the submission object for an UI name
195 Note that <member>getAllElementUINames</member> must have been called before, for the given element type
197 @see getModelElementUIName
198 @see getAllElementUINames
200 css::uno::Reference< css::beans::XPropertySet >
201 getModelElementFromUIName(
202 const ModelElementType _eType,
203 const OUString& _rUIName
204 ) const;
206 /** retrieves the UI names of all elements of all models in our document
207 @param _eType
208 the type of elements for which the names should be retrieved
209 @param _rElementNames
210 the array of element names
211 @see getModelElementUIName
212 @see getModelElementFromUIName
214 void getAllElementUINames(
215 const ModelElementType _eType,
216 std::vector< OUString >& /* [out] */ _rElementNames,
217 bool _bPrepentEmptyEntry
220 protected:
221 void firePropertyChanges(
222 const css::uno::Reference< css::beans::XPropertySet >& _rxOldProps,
223 const css::uno::Reference< css::beans::XPropertySet >& _rxNewProps,
224 std::set< OUString >& _rFilter
225 ) const;
227 /** fires a change in a single property, if the property value changed, and if we have a listener
228 interested in property changes
230 void firePropertyChange(
231 const OUString& _rName,
232 const css::uno::Any& _rOldValue,
233 const css::uno::Any& _rNewValue
234 ) const;
236 private:
237 void impl_switchBindingListening_throw( bool _bDoListening, const css::uno::Reference< css::beans::XPropertyChangeListener >& _rxListener );
239 /// implementation for both <member>getOrCreateBindingForModel</member>
240 css::uno::Reference< css::beans::XPropertySet >
241 implGetOrCreateBinding( const OUString& _rTargetModel, const OUString& _rBindingName ) const;
243 void
244 impl_toggleBindingPropertyListening_throw( bool _bDoListen, const css::uno::Reference< css::beans::XPropertyChangeListener >& _rxConcreteListenerOrNull );
246 private:
247 EFormsHelper( const EFormsHelper& ) = delete;
248 EFormsHelper& operator=( const EFormsHelper& ) = delete;
252 } // namespace pcr
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */