bump product version to 5.0.4.1
[LibreOffice.git] / forms / source / xforms / model_helper.hxx
blobc6150b4577473c5965376a4850306fda9c4a71ae
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 .
19 #ifndef INCLUDED_FORMS_SOURCE_XFORMS_MODEL_HELPER_HXX
20 #define INCLUDED_FORMS_SOURCE_XFORMS_MODEL_HELPER_HXX
23 // some helper definitions that must be available for model.cxx and
24 // model_ui.cxx
27 #include "namedcollection.hxx"
28 #include "binding.hxx"
29 #include "submission.hxx"
30 #include "unohelper.hxx"
32 #include <com/sun/star/uno/Reference.hxx>
33 #include <com/sun/star/uno/Sequence.hxx>
34 #include <com/sun/star/lang/XUnoTunnel.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/beans/PropertyValue.hpp>
38 namespace xforms
40 class Model;
44 // BindingCollection
47 namespace xforms
50 class BindingCollection : public NamedCollection<com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> >
52 Model* mpModel;
54 public:
55 BindingCollection( Model* pModel ) : mpModel( pModel ) {}
56 virtual ~BindingCollection() {}
58 virtual bool isValid( const T& t ) const SAL_OVERRIDE
60 return Binding::getBinding( t ) != NULL;
63 protected:
64 virtual void _insert( const T& t ) SAL_OVERRIDE
66 OSL_ENSURE( Binding::getBinding( t ) != NULL, "invalid item?" );
67 Binding::getBinding( t )->_setModel( Binding::Model_t( mpModel ) );
70 virtual void _remove( const T& t ) SAL_OVERRIDE
72 OSL_ENSURE( Binding::getBinding( t ) != NULL, "invalid item?" );
73 Binding::getBinding( t )->_setModel( Binding::Model_t() );
77 class SubmissionCollection : public NamedCollection<com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> >
79 Model* mpModel;
81 public:
82 SubmissionCollection( Model* pModel ) : mpModel( pModel ) {}
83 virtual ~SubmissionCollection() {}
85 public:
86 virtual bool isValid( const T& t ) const SAL_OVERRIDE
88 return Submission::getSubmission( t ) != NULL;
91 protected:
92 virtual void _insert( const T& t ) SAL_OVERRIDE
94 OSL_ENSURE( Submission::getSubmission( t ) != NULL, "invalid item?" );
95 Submission::getSubmission( t )->setModel( com::sun::star::uno::Reference<com::sun::star::xforms::XModel>( mpModel ) );
98 virtual void _remove( const T& t ) SAL_OVERRIDE
100 OSL_ENSURE( Submission::getSubmission( t ) != NULL, "invalid item?" );
101 Submission::getSubmission( t )->setModel( com::sun::star::uno::Reference<com::sun::star::xforms::XModel>( ) );
105 class InstanceCollection : public Collection<com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> >
107 public:
108 virtual bool isValid( const T& t ) const SAL_OVERRIDE
110 const com::sun::star::beans::PropertyValue* pValues = t.getConstArray();
111 OUString sInstance( "Instance" );
112 bool bFound = false;
113 for( sal_Int32 i = 0; ( ! bFound ) && ( i < t.getLength() ); i++ )
115 bFound |= ( pValues[i].Name == sInstance );
117 return bFound;
123 // helper functions
126 sal_Int32 lcl_findInstance( const InstanceCollection*,
127 const OUString& );
130 // get values from Sequence<PropertyValue> describing an Instance
131 void getInstanceData(
132 const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>&,
133 OUString* pID,
134 com::sun::star::uno::Reference<com::sun::star::xml::dom::XDocument>*,
135 OUString* pURL,
136 bool* pURLOnce );
138 // set values on Sequence<PropertyValue> for an Instance
139 void setInstanceData(
140 com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>&,
141 const OUString* pID,
142 const com::sun::star::uno::Reference<com::sun::star::xml::dom::XDocument>*,
143 const OUString* pURL,
144 const bool* pURLOnce );
146 } // namespace xforms
148 #endif
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */