android: Update app-specific/MIME type icons
[LibreOffice.git] / forms / source / xforms / model.hxx
blob59fa7450fb8074797cdfeeefcf1636117c0acfd1
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/implbase.hxx>
23 #include "propertysetbase.hxx"
24 #include <com/sun/star/xforms/XModel2.hpp>
25 #include <com/sun/star/xforms/XFormsUIHelper1.hpp>
26 #include <com/sun/star/util/XUpdatable.hpp>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/uno/Reference.hxx>
29 #include <rtl/ref.hxx>
30 #include "mip.hxx"
31 #include <map>
34 // forward declaractions
35 namespace com::sun::star
37 namespace xml::dom { class XDocument; }
38 namespace xml::dom { class XNode; }
39 namespace uno { template<typename T> class Sequence; }
40 namespace lang { class IndexOutOfBoundsException; }
41 namespace lang { class IllegalArgumentException; }
42 namespace beans { class XPropertySet; }
43 namespace container { class XSet; }
44 namespace container { class XNameContainer; }
45 namespace frame { class XModel; }
47 namespace xforms
49 class BindingCollection;
50 class SubmissionCollection;
51 class InstanceCollection;
52 class EvaluationContext;
56 namespace xforms
59 /** An XForms Model. Contains:
60 * # (set of) instance data (XML DOM tree)
61 * # (set of) bindings
62 * # (set of) submissions
63 * # (NOT YET IMPLEMENTED) actions (set of)
65 * See http://www.w3.org/TR/xforms/ for more information.
67 typedef cppu::ImplInheritanceHelper<
68 PropertySetBase,
69 css::xforms::XModel2,
70 css::xforms::XFormsUIHelper1,
71 css::util::XUpdatable,
72 css::lang::XServiceInfo
73 > Model_t;
74 class Model : public Model_t
76 // a number of local typedefs, to make the remaining header readable
77 typedef css::uno::Reference<css::xml::dom::XNode> XNode_t;
78 typedef css::uno::Reference<css::beans::XPropertySet> XPropertySet_t;
80 typedef std::multimap<XNode_t,std::pair<void*,MIP> > MIPs_t;
83 private:
85 OUString msID; /// the model ID
86 rtl::Reference<BindingCollection> mxBindings; /// the bindings
87 rtl::Reference<SubmissionCollection> mxSubmissions; /// the submissions
88 rtl::Reference<InstanceCollection> mxInstances; /// the instance(s)
90 css::uno::Reference<css::xforms::XDataTypeRepository> mxDataTypes; /// the XSD data-types used
91 css::uno::Reference<css::xml::dom::XDocument> mxForeignSchema; /// the XSD-schema part we cannot
92 /// map onto data types
93 OUString msSchemaRef; /// xforms:model/@schema attribute
95 css::uno::Reference<css::container::XNameContainer> mxNamespaces; /// namespaces for entire model
97 MIPs_t maMIPs; /// map nodes to their MIPs
99 bool mbInitialized; /// has model been initialized ?
100 bool mbExternalData; /// is the data of this model to be considered an integral part of the document?
102 void initializePropertySet();
104 void ensureAtLeastOneInstance();
107 public:
109 /// create a new model with an empty, default instance
110 Model();
111 virtual ~Model() noexcept override;
113 xforms::EvaluationContext getEvaluationContext();
115 // get/set that part of the schema, that we can't interpret as data types
116 css::uno::Reference<css::xml::dom::XDocument> getForeignSchema() const { return mxForeignSchema;}
117 void setForeignSchema( const css::uno::Reference<css::xml::dom::XDocument>& );
119 // get/set the xforms:model/@schema attribute
120 OUString getSchemaRef() const { return msSchemaRef;}
121 void setSchemaRef( const OUString& );
123 // get/set namespaces for entire model
124 css::uno::Reference<css::container::XNameContainer> getNamespaces() const { return mxNamespaces;}
125 void setNamespaces( const css::uno::Reference<css::container::XNameContainer>& );
127 // get/set the ExternalData property
128 bool getExternalData() const { return mbExternalData;}
129 void setExternalData( bool _bData );
132 #if OSL_DEBUG_LEVEL > 0 && !defined NDEBUG
133 void dbg_assertInvariant() const;
134 #endif
137 // MIP (model item property) management
140 // register MIPs which apply to a given node; only to be called by bindings
141 // (The pTag parameter serves only to be able to remove the MIPs
142 // that were added using the same tag. No functions will be
143 // performed on it; hence the void* type.)
144 void addMIP( void* pTag, const XNode_t&, const MIP& );
145 void removeMIPs( void const * pTag );
147 /// query which MIPs apply to the given node
148 MIP queryMIP( const XNode_t& xNode ) const;
150 /// re-bind all bindings
151 void rebind();
153 /// call defer notifications on all bindings
154 void deferNotifications( bool );
156 /// set a data value in the instance
157 /// (also defers notifications)
158 bool setSimpleContent( const XNode_t&, const OUString& );
160 /// load instance data
161 void loadInstance( sal_Int32 nInstance );
162 void loadInstances();
164 /// has model been initialized?
165 bool isInitialized() const { return mbInitialized;}
167 /// is model currently valid (for submission)?
168 bool isValid() const;
171 // XModel
172 // implement the xforms::XModel implementation
175 virtual OUString SAL_CALL getID() override;
177 virtual void SAL_CALL setID( const OUString& sID ) override;
179 virtual void SAL_CALL initialize() override;
181 virtual void SAL_CALL rebuild() override;
183 virtual void SAL_CALL recalculate() override;
185 virtual void SAL_CALL revalidate() override;
187 virtual void SAL_CALL refresh() override;
189 virtual void SAL_CALL submit( const OUString& sID ) override;
191 virtual void SAL_CALL submitWithInteraction( const OUString& id, const css::uno::Reference<css::task::XInteractionHandler>& _rxHandler ) override;
193 virtual css::uno::Reference<css::xforms::XDataTypeRepository> SAL_CALL getDataTypeRepository( ) override;
196 // XModel: instance management
198 virtual css::uno::Reference<css::container::XSet> SAL_CALL getInstances() override;
200 virtual css::uno::Reference<css::xml::dom::XDocument> SAL_CALL getInstanceDocument( const OUString& ) override;
202 virtual css::uno::Reference<css::xml::dom::XDocument> SAL_CALL getDefaultInstance() override;
205 // XModel: binding management
207 virtual css::uno::Reference<css::beans::XPropertySet> SAL_CALL createBinding() override;
209 virtual css::uno::Reference<css::beans::XPropertySet> SAL_CALL cloneBinding( const css::uno::Reference<css::beans::XPropertySet>& ) override;
211 virtual css::uno::Reference<css::beans::XPropertySet> SAL_CALL getBinding( const OUString& ) override;
213 virtual css::uno::Reference<css::container::XSet> SAL_CALL getBindings() override;
216 // XModel: submission management
218 virtual css::uno::Reference<css::xforms::XSubmission> SAL_CALL createSubmission() override;
220 virtual css::uno::Reference<css::xforms::XSubmission> SAL_CALL cloneSubmission( const css::uno::Reference<css::beans::XPropertySet>& ) override;
222 virtual css::uno::Reference<css::xforms::XSubmission> SAL_CALL getSubmission( const OUString& ) override;
224 virtual css::uno::Reference<css::container::XSet> SAL_CALL getSubmissions() override;
226 // XPropertySet
228 virtual css::uno::Any SAL_CALL getPropertyValue(const OUString& p) override
229 { return PropertySetBase::getPropertyValue(p); }
231 virtual void SAL_CALL addPropertyChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XPropertyChangeListener>& p2) override
232 { PropertySetBase::addPropertyChangeListener(p1, p2); }
234 virtual void SAL_CALL removePropertyChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XPropertyChangeListener>& p2) override
235 { PropertySetBase::removePropertyChangeListener(p1, p2); }
237 virtual void SAL_CALL addVetoableChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XVetoableChangeListener>& p2) override
238 { PropertySetBase::addVetoableChangeListener(p1, p2); }
240 virtual void SAL_CALL removeVetoableChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XVetoableChangeListener>& p2) override
241 { PropertySetBase::removeVetoableChangeListener(p1, p2); }
243 virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override
244 { return PropertySetBase::getPropertySetInfo(); }
246 virtual void SAL_CALL setPropertyValue(const OUString& p1, const css::uno::Any& p2) override
247 { PropertySetBase::setPropertyValue(p1, p2); }
250 // XFormsUIHelper1 & friends:
251 // (implementation in model_ui.cxx)
254 /// determine a reasonable control service for a given node
255 /// (based on data type MIP assigned to the node)
256 virtual OUString SAL_CALL getDefaultServiceNameForNode( const css::uno::Reference<css::xml::dom::XNode>& xNode ) override;
258 /// call getDefaultBindingExpressionForNode with default evaluation context
259 virtual OUString SAL_CALL getDefaultBindingExpressionForNode( const css::uno::Reference<css::xml::dom::XNode>& xNode ) override;
261 /// determine a reasonable default binding expression for a given node
262 /// and a given evaluation context
263 /// @returns expression, or empty string if no expression could be derived
264 OUString getDefaultBindingExpressionForNode(
265 const XNode_t&,
266 const EvaluationContext& );
268 virtual OUString SAL_CALL getNodeDisplayName( const css::uno::Reference<css::xml::dom::XNode>&,
269 sal_Bool bDetail ) override;
271 virtual OUString SAL_CALL getNodeName( const css::uno::Reference<css::xml::dom::XNode>& ) override;
273 virtual OUString SAL_CALL getBindingName( const css::uno::Reference< ::css::beans::XPropertySet >&,
274 sal_Bool bDetail ) override;
276 virtual OUString SAL_CALL getSubmissionName( const css::uno::Reference< ::css::beans::XPropertySet >&,
277 sal_Bool bDetail ) override;
279 virtual css::uno::Reference< ::css::beans::XPropertySet > SAL_CALL cloneBindingAsGhost( const css::uno::Reference< ::css::beans::XPropertySet >& ) override;
281 virtual void SAL_CALL removeBindingIfUseless( const css::uno::Reference< ::css::beans::XPropertySet >& ) override;
283 virtual css::uno::Reference<css::xml::dom::XDocument> SAL_CALL newInstance( const OUString& sName,
284 const OUString& sURL,
285 sal_Bool bURLOnce ) override;
287 virtual void SAL_CALL renameInstance( const OUString& sFrom,
288 const OUString& sTo,
289 const OUString& sURL,
290 sal_Bool bURLOnce ) override;
292 virtual void SAL_CALL removeInstance( const OUString& sName ) override;
295 virtual css::uno::Reference<css::xforms::XModel> SAL_CALL newModel( const css::uno::Reference<css::frame::XModel>& xComponent,
296 const OUString& sName ) override;
297 virtual void SAL_CALL renameModel( const css::uno::Reference<css::frame::XModel>& xComponent,
298 const OUString& sFrom,
299 const OUString& sTo ) override;
301 virtual void SAL_CALL removeModel( const css::uno::Reference<css::frame::XModel>& xComponent,
302 const OUString& sName ) override;
305 virtual css::uno::Reference< css::xml::dom::XNode > SAL_CALL createElement(
306 const css::uno::Reference< ::css::xml::dom::XNode >& xParent,
307 const OUString& sName ) override;
309 virtual css::uno::Reference< css::xml::dom::XNode > SAL_CALL createAttribute(
310 const css::uno::Reference< ::css::xml::dom::XNode >& xParent,
311 const OUString& sName ) override;
313 virtual css::uno::Reference< css::xml::dom::XNode > SAL_CALL renameNode(
314 const css::uno::Reference< ::css::xml::dom::XNode >& xNode,
315 const OUString& sName ) override;
317 virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL getBindingForNode( const
318 css::uno::Reference<css::xml::dom::XNode>&,
319 sal_Bool bCreate ) override;
321 virtual void SAL_CALL removeBindingForNode( const css::uno::Reference< ::css::xml::dom::XNode >& ) override;
323 virtual OUString SAL_CALL getResultForExpression(
324 const css::uno::Reference< css::beans::XPropertySet >& xBinding,
325 sal_Bool bIsBindingExpression,
326 const OUString& sExpression ) override;
328 virtual sal_Bool SAL_CALL isValidXMLName( const OUString& sName ) override;
330 virtual sal_Bool SAL_CALL isValidPrefixName( const OUString& sName ) override;
332 virtual void SAL_CALL setNodeValue(
333 const css::uno::Reference< ::css::xml::dom::XNode >& xNode,
334 const OUString& sValue ) override;
337 // XUpdatable
340 public:
341 virtual void SAL_CALL update() override;
344 // XTypeProvider::getImplementationId
347 public:
348 virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override;
350 OUString SAL_CALL getImplementationName() override;
352 sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override;
354 css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
357 } // namespace
359 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */