bump product version to 4.1.6.2
[LibreOffice.git] / forms / source / xforms / binding.hxx
blob7328bf3e8bad7aff63b0956fcbbd11a5785f7e75
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 _BINDING_HXX
21 #define _BINDING_HXX
23 #include <com/sun/star/uno/Reference.hxx>
25 // forward declaractions
26 namespace xforms
28 class Model;
29 class EvaluationContext;
31 namespace com { namespace sun { namespace star {
32 namespace xml {
33 namespace xpath { class XXPathAPI; }
34 namespace dom
36 class XNode;
37 class XNodeList;
40 namespace container { class XNameContainer; }
41 namespace xforms { class XModel; }
42 namespace xsd { class XDataType; }
43 } } }
45 #include <cppuhelper/implbase8.hxx>
46 #include <propertysetbase.hxx>
47 #include <com/sun/star/form/binding/XValueBinding.hpp>
48 #include <com/sun/star/form/binding/XListEntrySource.hpp>
49 #include <com/sun/star/form/validation/XValidator.hpp>
50 #include <com/sun/star/util/XModifyBroadcaster.hpp>
51 #include <com/sun/star/container/XNamed.hpp>
52 #include <com/sun/star/xml/dom/events/XEventListener.hpp>
53 #include <com/sun/star/lang/XUnoTunnel.hpp>
54 #include <com/sun/star/util/XCloneable.hpp>
56 #include "pathexpression.hxx"
57 #include "boolexpression.hxx"
58 #include "mip.hxx"
59 #include <rtl/ustring.hxx>
60 #include <vector>
61 #include <memory> // auto_ptr
65 namespace xforms
68 /** An XForms Binding. Contains:
69 * # a connection to its model
70 * # an ID
71 * # an binding expression
72 * # model item properties
73 * # (NOT YET IMPLEMENTED) child bindings (sequence of)
75 * See http://www.w3.org/TR/xforms/ for more information.
78 typedef cppu::ImplInheritanceHelper8<
79 PropertySetBase,
80 com::sun::star::form::binding::XValueBinding,
81 com::sun::star::form::binding::XListEntrySource,
82 com::sun::star::form::validation::XValidator,
83 com::sun::star::util::XModifyBroadcaster,
84 com::sun::star::container::XNamed,
85 com::sun::star::xml::dom::events::XEventListener,
86 com::sun::star::lang::XUnoTunnel,
87 com::sun::star::util::XCloneable
88 > Binding_t;
90 class Binding : public Binding_t
92 public:
93 typedef com::sun::star::uno::Reference<com::sun::star::xforms::XModel> Model_t;
94 typedef com::sun::star::uno::Reference<com::sun::star::util::XModifyListener> XModifyListener_t;
95 typedef std::vector<XModifyListener_t> ModifyListeners_t;
96 typedef com::sun::star::uno::Reference<com::sun::star::form::validation::XValidityConstraintListener> XValidityConstraintListener_t;
97 typedef std::vector<XValidityConstraintListener_t> XValidityConstraintListeners_t;
98 typedef com::sun::star::uno::Reference<com::sun::star::form::binding::XListEntryListener> XListEntryListener_t;
99 typedef std::vector<XListEntryListener_t> XListEntryListeners_t;
100 typedef com::sun::star::uno::Reference<com::sun::star::container::XNameContainer> XNameContainer_t;
101 typedef com::sun::star::uno::Reference<com::sun::star::xml::dom::XNode> XNode_t;
102 typedef com::sun::star::uno::Reference<com::sun::star::xml::dom::XNodeList> XNodeList_t;
103 typedef com::sun::star::uno::Reference<com::sun::star::util::XCloneable> XCloneable_t;
104 typedef com::sun::star::uno::Sequence<sal_Int8> IntSequence_t;
105 typedef com::sun::star::uno::Sequence<OUString> StringSequence_t;
106 typedef std::vector<MIP> MIPs_t;
107 typedef std::vector<XNode_t> XNodes_t;
111 private:
113 /// the Model to which this Binding belongs; may be NULL
114 Model_t mxModel;
116 /// binding-ID. A document-wide unique ID for this binding element.
117 OUString msBindingID;
119 /// an XPath-expression to be instantiated on the data instance
120 PathExpression maBindingExpression;
122 /// an XPath-expression to determine read-only status
123 BoolExpression maReadonly;
125 /// an XPath-expression to determine relevance
126 BoolExpression maRelevant;
128 /// an XPath-expression to determine if item is required
129 BoolExpression maRequired;
131 /// an XPath-expression to determine if item is valid
132 BoolExpression maConstraint;
134 /// user-readable explanation of the constraint
135 OUString msExplainConstraint;
137 /// an XPath-expression to calculate values
138 ComputedExpression maCalculate;
140 /// the XML namespaces used for XML names/XPath-expressions in this binding
141 XNameContainer_t mxNamespaces;
143 /// a type name
144 OUString msTypeName;
146 /// modify listeners
147 ModifyListeners_t maModifyListeners;
149 /// list entry listener
150 XListEntryListeners_t maListEntryListeners;
152 /// validity listeners;
153 XValidityConstraintListeners_t maValidityListeners;
155 /// nodes on which we are listening for events
156 XNodes_t maEventNodes;
158 /// the current MIP object for the first node we are bound to
159 MIP maMIP;
161 /// flag to detect recursions in calculate
162 bool mbInCalculate;
164 // flags to manage deferred notifications:
165 /// if >0, valueModified() and bindingModified() will only set flags
166 sal_Int32 mnDeferModifyNotifications;
167 bool mbValueModified; /// if true, valueModified needs to be called
168 bool mbBindingModified; /// if true, bindingModified needs to be called
171 void initializePropertySet();
174 public:
175 Binding();
176 virtual ~Binding() throw();
179 // property methods: get/set value
182 Model_t getModel() const; /// get XForms model
183 void _setModel( const Model_t& ); /// set XForms model (only called by Model)
186 OUString getModelID() const; /// get ID of XForms model
188 OUString getBindingID() const; /// get ID for this binding
189 void setBindingID( const OUString& ); /// set ID for this binding
191 OUString getBindingExpression() const; /// get binding expression
192 void setBindingExpression( const OUString& ); /// set binding exp.
194 // MIPs (model item properties)
196 OUString getReadonlyExpression() const; /// get read-only MIP
197 void setReadonlyExpression( const OUString& ); /// set read-only MIP
199 OUString getRelevantExpression() const; /// get relevant MIP
200 void setRelevantExpression( const OUString& ); /// set relevant MIP
202 OUString getRequiredExpression() const; /// get required MIP
203 void setRequiredExpression( const OUString& ); /// set required MIP
205 OUString getConstraintExpression() const; /// get constraint MIP
206 void setConstraintExpression( const OUString& );/// set constraint MIP
208 OUString getCalculateExpression() const; /// get calculate MIP
209 void setCalculateExpression( const OUString& ); /// set calculate MIP
211 OUString getType() const; /// get type name MIP (static)
212 void setType( const OUString& ); /// set type name MIP (static)
214 // a binding expression can only be interpreted with respect to
215 // suitable namespace declarations. We collect those in the model and in a binding.
217 // access to a binding's namespace
218 // (set-method only changes local namespaces (but may add to model))
219 XNameContainer_t getBindingNamespaces() const; /// set binding namespaces
220 void setBindingNamespaces( const XNameContainer_t& ); /// get binding nmsp.
222 // access to the model's namespaces
223 // (set-method changes model's namespaces (unless a local one is present))
224 XNameContainer_t getModelNamespaces() const; /// set model namespaces
225 void setModelNamespaces( const XNameContainer_t& ); /// get model nmsp.
228 // read-only properties that map MIPs to control data source properties
229 bool getReadOnly() const; // MIP readonly
230 bool getRelevant() const; // MIP relevant
231 bool getExternalData() const; // mapped from model's ExternalData property
234 // missing binding properties:
235 // - type (static; default: xsd:string)
236 // - minOccurs/maxOccurs (computed XPath; default: 0/inf)
237 // - p3ptype (static; no default)
242 /// get this binding's context node
243 xforms::EvaluationContext getEvaluationContext() const;
245 /// get evalation contexts for this binding's MIPs
246 std::vector<xforms::EvaluationContext> getMIPEvaluationContexts();
248 /// get nodeset the bind is bound to
249 XNodeList_t getXNodeList();
251 /// heuristically determine whether this binding is simple binding
252 /// (here: simple binding == does not depend on other parts of the
253 /// instance, it's not a 'dynamic' binding)
254 bool isSimpleBinding() const;
256 /// heuristically determine whether this binding's binding
257 /// expression is simple
258 bool isSimpleBindingExpression() const;
260 /// update this binding (e.g. called by model for refresh )
261 void update();
263 /// prevent change notifications being sent to controls
264 void deferNotifications( bool );
266 /// is this binding valid? (are constraint, type and required MIPs ok?)
267 bool isValid();
269 /// determine whether this binding currently performs a useful
270 /// function, r whether is may be discarded
271 bool isUseful();
273 /// explain why binding is invalid
274 OUString explainInvalid();
277 // the ID for XUnoTunnel calls
278 static IntSequence_t getUnoTunnelID();
279 static Binding* getBinding( const com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& );
282 // class-scoped typedef for easy-to-read UNO interfaces
285 // basic types
286 typedef com::sun::star::uno::Any Any_t;
287 typedef com::sun::star::uno::Sequence<com::sun::star::uno::Type> Sequence_Type_t;
288 typedef com::sun::star::uno::Type Type_t;
290 // reference types
291 typedef com::sun::star::uno::Reference<com::sun::star::beans::XPropertyChangeListener> XPropertyChangeListener_t;
292 typedef com::sun::star::uno::Reference<com::sun::star::beans::XPropertySetInfo> XPropertySetInfo_t;
293 typedef com::sun::star::uno::Reference<com::sun::star::beans::XVetoableChangeListener> XVetoableChangeListener_t;
294 typedef com::sun::star::uno::Reference<com::sun::star::xml::xpath::XXPathAPI> XXPathAPI_t;
295 typedef com::sun::star::uno::Reference<com::sun::star::xml::dom::events::XEvent> XEvent_t;
296 typedef com::sun::star::uno::Reference<com::sun::star::xsd::XDataType> XDataType_t;
298 // exceptions
299 typedef com::sun::star::beans::PropertyVetoException PropertyVetoException_t;
300 typedef com::sun::star::beans::UnknownPropertyException UnknownPropertyException_t;
301 typedef com::sun::star::lang::IllegalArgumentException IllegalArgumentException_t;
302 typedef com::sun::star::lang::NoSupportException NoSupportException_t;
303 typedef com::sun::star::lang::WrappedTargetException WrappedTargetException_t;
304 typedef com::sun::star::uno::RuntimeException RuntimeException_t;
305 typedef com::sun::star::form::binding::IncompatibleTypesException IncompatibleTypesException_t;
306 typedef com::sun::star::form::binding::InvalidBindingStateException InvalidBindingStateException_t;
307 typedef com::sun::star::lang::NullPointerException NullPointerException_t;
308 typedef com::sun::star::lang::IndexOutOfBoundsException IndexOutOfBoundsException_t;
312 private:
313 /// check whether object is live, and throw suitable exception if not
314 /// (to be used be API methods before acting on the object)
315 void checkLive() throw( RuntimeException_t );
317 /// check whether binding has a model, and throw exception if not
318 /// (to be used be API methods before acting on the object)
319 void checkModel() throw( RuntimeException_t );
321 /// determine whether object is live
322 /// live: has model, and model has been initialized
323 bool isLive() const;
325 /// get the model implementation
326 xforms::Model* getModelImpl() const;
327 xforms::Model* getModelImpl( const Model_t& xModel ) const;
329 /// get MIP evaluation contexts
330 /// (only valid if control has already been bound)
331 std::vector<xforms::EvaluationContext> _getMIPEvaluationContexts() const;
333 /// bind this binding, and pre-compute the affected nodes
334 void bind( bool bForceRebind = false );
336 /// the binding value has been changed:
337 /// trigger a modified event on all modified listeners
338 void valueModified();
340 /// the binding itself has changed:
341 /// force rebind, then call valueModified()
342 void bindingModified();
345 /// register the event listeners for
346 void registerListeners();
348 /// set MIPs defined by this binding on MIP item
349 MIP getLocalMIP() const;
351 /// get the data type that applies to this binding
352 XDataType_t getDataType();
354 /// determine whether binding is valid according to the given data type
355 bool isValid_DataType();
357 /// explain validity of binding with respect to the given data type
358 OUString explainInvalid_DataType();
360 /// 'clear' this binding - remove all listeners, etc.
361 void clear();
363 /// distribute MIPs from current node recursively to children
364 void distributeMIP( const XNode_t &rxNode );
366 /// implement get*Namespaces()
367 XNameContainer_t _getNamespaces() const;
369 /// implement set*Namespaces()
370 void _setNamespaces( const XNameContainer_t&, bool bBinding );
372 /// set a useful default binding ID (if none is set)
373 void _checkBindingID();
375 public:
376 /// for debugging purposes only: get the MIPs defined by this binding
377 const MIP* _getMIP();
384 // XValueBinding:
387 public:
389 virtual Sequence_Type_t SAL_CALL getSupportedValueTypes()
390 throw( RuntimeException_t );
392 virtual sal_Bool SAL_CALL supportsType( const Type_t& aType )
393 throw( RuntimeException_t );
395 virtual Any_t SAL_CALL getValue( const Type_t& aType )
396 throw( IncompatibleTypesException_t,
397 RuntimeException_t );
399 virtual void SAL_CALL setValue( const Any_t& aValue )
400 throw( IncompatibleTypesException_t,
401 InvalidBindingStateException_t,
402 NoSupportException_t,
403 RuntimeException_t );
408 // XListEntry Source
411 virtual sal_Int32 SAL_CALL getListEntryCount()
412 throw( RuntimeException_t );
414 virtual OUString SAL_CALL getListEntry( sal_Int32 nPosition )
415 throw( IndexOutOfBoundsException_t,
416 RuntimeException_t );
418 virtual StringSequence_t SAL_CALL getAllListEntries()
419 throw( RuntimeException_t );
421 virtual void SAL_CALL addListEntryListener( const XListEntryListener_t& )
422 throw( NullPointerException_t,
423 RuntimeException_t );
425 virtual void SAL_CALL removeListEntryListener( const XListEntryListener_t&)
426 throw( NullPointerException_t,
427 RuntimeException_t );
432 // XValidator:
435 virtual sal_Bool SAL_CALL isValid(
436 const Any_t& )
437 throw( RuntimeException_t );
439 virtual OUString SAL_CALL explainInvalid(
440 const Any_t& )
441 throw( RuntimeException_t );
443 virtual void SAL_CALL addValidityConstraintListener(
444 const XValidityConstraintListener_t& xListener )
445 throw( NullPointerException_t,
446 RuntimeException_t );
448 virtual void SAL_CALL removeValidityConstraintListener(
449 const XValidityConstraintListener_t& xListener )
450 throw( NullPointerException_t,
451 RuntimeException_t );
455 // XModifyBroadcaster & friends:
456 // inform listeners about changes in our values
459 public:
461 virtual void SAL_CALL addModifyListener(
462 const XModifyListener_t& xListener )
463 throw( RuntimeException_t );
465 virtual void SAL_CALL removeModifyListener(
466 const XModifyListener_t& xListener )
467 throw( RuntimeException_t );
473 // XNamed:
474 // get/set name
477 public:
479 virtual OUString SAL_CALL getName()
480 throw( RuntimeException_t );
482 virtual void SAL_CALL setName( const OUString& )
483 throw( RuntimeException_t );
488 // xml::dom::event::XEventListener
489 // receive an event if our node changed
492 virtual void SAL_CALL handleEvent(
493 const XEvent_t& xEvent )
494 throw( RuntimeException_t );
499 // XUnoTunnel
502 virtual sal_Int64 SAL_CALL getSomething( const IntSequence_t& )
503 throw( RuntimeException_t );
507 // XCloneable
510 virtual XCloneable_t SAL_CALL createClone()
511 throw( RuntimeException_t );
515 } // namespace xforms
517 #endif
519 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */