tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / forms / source / xforms / model.hxx
blob94d3f3e052fee2c019a9f1b7972356ab0109f26e
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 declarations
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;
53 class ODataTypeRepository;
57 namespace xforms
60 /** An XForms Model. Contains:
61 * # (set of) instance data (XML DOM tree)
62 * # (set of) bindings
63 * # (set of) submissions
64 * # (NOT YET IMPLEMENTED) actions (set of)
66 * See http://www.w3.org/TR/xforms/ for more information.
68 typedef cppu::ImplInheritanceHelper<
69 PropertySetBase,
70 css::xforms::XModel2,
71 css::xforms::XFormsUIHelper1,
72 css::util::XUpdatable,
73 css::lang::XServiceInfo
74 > Model_t;
75 class Model : public Model_t
77 // a number of local typedefs, to make the remaining header readable
78 typedef css::uno::Reference<css::xml::dom::XNode> XNode_t;
79 typedef css::uno::Reference<css::beans::XPropertySet> XPropertySet_t;
81 typedef std::multimap<XNode_t,std::pair<void*,MIP> > MIPs_t;
84 private:
86 OUString msID; /// the model ID
87 rtl::Reference<BindingCollection> mxBindings; /// the bindings
88 rtl::Reference<SubmissionCollection> mxSubmissions; /// the submissions
89 rtl::Reference<InstanceCollection> mxInstances; /// the instance(s)
91 rtl::Reference<ODataTypeRepository> mxDataTypes; /// the XSD data-types used
92 css::uno::Reference<css::xml::dom::XDocument> mxForeignSchema; /// the XSD-schema part we cannot
93 /// map onto data types
94 OUString msSchemaRef; /// xforms:model/@schema attribute
96 css::uno::Reference<css::container::XNameContainer> mxNamespaces; /// namespaces for entire model
98 MIPs_t maMIPs; /// map nodes to their MIPs
100 bool mbInitialized; /// has model been initialized ?
101 bool mbExternalData; /// is the data of this model to be considered an integral part of the document?
103 void initializePropertySet();
105 void ensureAtLeastOneInstance();
108 public:
110 /// create a new model with an empty, default instance
111 Model();
112 virtual ~Model() noexcept override;
114 xforms::EvaluationContext getEvaluationContext();
116 // get/set that part of the schema, that we can't interpret as data types
117 css::uno::Reference<css::xml::dom::XDocument> getForeignSchema() const { return mxForeignSchema;}
118 void setForeignSchema( const css::uno::Reference<css::xml::dom::XDocument>& );
120 // get/set the xforms:model/@schema attribute
121 OUString getSchemaRef() const { return msSchemaRef;}
122 void setSchemaRef( const OUString& );
124 // get/set namespaces for entire model
125 css::uno::Reference<css::container::XNameContainer> getNamespaces() const { return mxNamespaces;}
126 void setNamespaces( const css::uno::Reference<css::container::XNameContainer>& );
128 // get/set the ExternalData property
129 bool getExternalData() const { return mbExternalData;}
130 void setExternalData( bool _bData );
133 #if OSL_DEBUG_LEVEL > 0 && !defined NDEBUG
134 void dbg_assertInvariant() const;
135 #endif
138 // MIP (model item property) management
141 // register MIPs which apply to a given node; only to be called by bindings
142 // (The pTag parameter serves only to be able to remove the MIPs
143 // that were added using the same tag. No functions will be
144 // performed on it; hence the void* type.)
145 void addMIP( void* pTag, const XNode_t&, const MIP& );
146 void removeMIPs( void const * pTag );
148 /// query which MIPs apply to the given node
149 MIP queryMIP( const XNode_t& xNode ) const;
151 /// re-bind all bindings
152 void rebind();
154 /// call defer notifications on all bindings
155 void deferNotifications( bool );
157 /// set a data value in the instance
158 /// (also defers notifications)
159 bool setSimpleContent( const XNode_t&, const OUString& );
161 /// load instance data
162 void loadInstance( sal_Int32 nInstance );
163 void loadInstances();
165 /// has model been initialized?
166 bool isInitialized() const { return mbInitialized;}
168 /// is model currently valid (for submission)?
169 bool isValid() const;
172 // XModel
173 // implement the xforms::XModel implementation
176 virtual OUString SAL_CALL getID() override;
178 virtual void SAL_CALL setID( const OUString& sID ) override;
180 virtual void SAL_CALL initialize() override;
182 virtual void SAL_CALL rebuild() override;
184 virtual void SAL_CALL recalculate() override;
186 virtual void SAL_CALL revalidate() override;
188 virtual void SAL_CALL refresh() override;
190 virtual void SAL_CALL submit( const OUString& sID ) override;
192 virtual void SAL_CALL submitWithInteraction( const OUString& id, const css::uno::Reference<css::task::XInteractionHandler>& _rxHandler ) override;
194 virtual css::uno::Reference<css::xforms::XDataTypeRepository> SAL_CALL getDataTypeRepository( ) override;
197 // XModel: instance management
199 virtual css::uno::Reference<css::container::XSet> SAL_CALL getInstances() override;
201 virtual css::uno::Reference<css::xml::dom::XDocument> SAL_CALL getInstanceDocument( const OUString& ) override;
203 virtual css::uno::Reference<css::xml::dom::XDocument> SAL_CALL getDefaultInstance() override;
206 // XModel: binding management
208 virtual css::uno::Reference<css::beans::XPropertySet> SAL_CALL createBinding() override;
210 virtual css::uno::Reference<css::beans::XPropertySet> SAL_CALL cloneBinding( const css::uno::Reference<css::beans::XPropertySet>& ) override;
212 virtual css::uno::Reference<css::beans::XPropertySet> SAL_CALL getBinding( const OUString& ) override;
214 virtual css::uno::Reference<css::container::XSet> SAL_CALL getBindings() override;
217 // XModel: submission management
219 virtual css::uno::Reference<css::xforms::XSubmission> SAL_CALL createSubmission() override;
221 virtual css::uno::Reference<css::xforms::XSubmission> SAL_CALL cloneSubmission( const css::uno::Reference<css::beans::XPropertySet>& ) override;
223 virtual css::uno::Reference<css::xforms::XSubmission> SAL_CALL getSubmission( const OUString& ) override;
225 virtual css::uno::Reference<css::container::XSet> SAL_CALL getSubmissions() override;
227 // XPropertySet
229 virtual css::uno::Any SAL_CALL getPropertyValue(const OUString& p) override
230 { return PropertySetBase::getPropertyValue(p); }
232 virtual void SAL_CALL addPropertyChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XPropertyChangeListener>& p2) override
233 { PropertySetBase::addPropertyChangeListener(p1, p2); }
235 virtual void SAL_CALL removePropertyChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XPropertyChangeListener>& p2) override
236 { PropertySetBase::removePropertyChangeListener(p1, p2); }
238 virtual void SAL_CALL addVetoableChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XVetoableChangeListener>& p2) override
239 { PropertySetBase::addVetoableChangeListener(p1, p2); }
241 virtual void SAL_CALL removeVetoableChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XVetoableChangeListener>& p2) override
242 { PropertySetBase::removeVetoableChangeListener(p1, p2); }
244 virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override
245 { return PropertySetBase::getPropertySetInfo(); }
247 virtual void SAL_CALL setPropertyValue(const OUString& p1, const css::uno::Any& p2) override
248 { PropertySetBase::setPropertyValue(p1, p2); }
251 // XFormsUIHelper1 & friends:
252 // (implementation in model_ui.cxx)
255 /// determine a reasonable control service for a given node
256 /// (based on data type MIP assigned to the node)
257 virtual OUString SAL_CALL getDefaultServiceNameForNode( const css::uno::Reference<css::xml::dom::XNode>& xNode ) override;
259 /// call getDefaultBindingExpressionForNode with default evaluation context
260 virtual OUString SAL_CALL getDefaultBindingExpressionForNode( const css::uno::Reference<css::xml::dom::XNode>& xNode ) override;
262 /// determine a reasonable default binding expression for a given node
263 /// and a given evaluation context
264 /// @returns expression, or empty string if no expression could be derived
265 OUString getDefaultBindingExpressionForNode(
266 const XNode_t&,
267 const EvaluationContext& );
269 virtual OUString SAL_CALL getNodeDisplayName( const css::uno::Reference<css::xml::dom::XNode>&,
270 sal_Bool bDetail ) override;
272 virtual OUString SAL_CALL getNodeName( const css::uno::Reference<css::xml::dom::XNode>& ) override;
274 virtual OUString SAL_CALL getBindingName( const css::uno::Reference< ::css::beans::XPropertySet >&,
275 sal_Bool bDetail ) override;
277 virtual OUString SAL_CALL getSubmissionName( const css::uno::Reference< ::css::beans::XPropertySet >&,
278 sal_Bool bDetail ) override;
280 virtual css::uno::Reference< ::css::beans::XPropertySet > SAL_CALL cloneBindingAsGhost( const css::uno::Reference< ::css::beans::XPropertySet >& ) override;
282 virtual void SAL_CALL removeBindingIfUseless( const css::uno::Reference< ::css::beans::XPropertySet >& ) override;
284 virtual css::uno::Reference<css::xml::dom::XDocument> SAL_CALL newInstance( const OUString& sName,
285 const OUString& sURL,
286 sal_Bool bURLOnce ) override;
288 virtual void SAL_CALL renameInstance( const OUString& sFrom,
289 const OUString& sTo,
290 const OUString& sURL,
291 sal_Bool bURLOnce ) override;
293 virtual void SAL_CALL removeInstance( const OUString& sName ) override;
296 virtual css::uno::Reference<css::xforms::XModel> SAL_CALL newModel( const css::uno::Reference<css::frame::XModel>& xComponent,
297 const OUString& sName ) override;
298 virtual void SAL_CALL renameModel( const css::uno::Reference<css::frame::XModel>& xComponent,
299 const OUString& sFrom,
300 const OUString& sTo ) override;
302 virtual void SAL_CALL removeModel( const css::uno::Reference<css::frame::XModel>& xComponent,
303 const OUString& sName ) override;
306 virtual css::uno::Reference< css::xml::dom::XNode > SAL_CALL createElement(
307 const css::uno::Reference< ::css::xml::dom::XNode >& xParent,
308 const OUString& sName ) override;
310 virtual css::uno::Reference< css::xml::dom::XNode > SAL_CALL createAttribute(
311 const css::uno::Reference< ::css::xml::dom::XNode >& xParent,
312 const OUString& sName ) override;
314 virtual css::uno::Reference< css::xml::dom::XNode > SAL_CALL renameNode(
315 const css::uno::Reference< ::css::xml::dom::XNode >& xNode,
316 const OUString& sName ) override;
318 virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL getBindingForNode( const
319 css::uno::Reference<css::xml::dom::XNode>&,
320 sal_Bool bCreate ) override;
322 virtual void SAL_CALL removeBindingForNode( const css::uno::Reference< ::css::xml::dom::XNode >& ) override;
324 virtual OUString SAL_CALL getResultForExpression(
325 const css::uno::Reference< css::beans::XPropertySet >& xBinding,
326 sal_Bool bIsBindingExpression,
327 const OUString& sExpression ) override;
329 virtual sal_Bool SAL_CALL isValidXMLName( const OUString& sName ) override;
331 virtual sal_Bool SAL_CALL isValidPrefixName( const OUString& sName ) override;
333 virtual void SAL_CALL setNodeValue(
334 const css::uno::Reference< ::css::xml::dom::XNode >& xNode,
335 const OUString& sValue ) override;
338 // XUpdatable
341 public:
342 virtual void SAL_CALL update() override;
345 // XTypeProvider::getImplementationId
348 public:
349 virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override;
351 OUString SAL_CALL getImplementationName() override;
353 sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override;
355 css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
358 } // namespace
360 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */