bump product version to 4.1.6.2
[LibreOffice.git] / forms / source / xforms / model_helper.hxx
blob582cb054a43f7ba6e1cf79c80138ff1b9e0fc917
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 _MODEL_HELPER_HXX
20 #define _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
60 return Binding::getBinding( t ) != NULL;
63 protected:
64 virtual void _insert( const T& t )
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 )
72 OSL_ENSURE( Binding::getBinding( t ) != NULL, "invalid item?" );
73 Binding::getBinding( t )->_setModel( Binding::Model_t() );
80 // SubmissionCollection
83 class SubmissionCollection : public NamedCollection<com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> >
85 Model* mpModel;
87 public:
88 SubmissionCollection( Model* pModel ) : mpModel( pModel ) {}
89 virtual ~SubmissionCollection() {}
91 public:
92 virtual bool isValid( const T& t ) const
94 return Submission::getSubmission( t ) != NULL;
97 protected:
98 virtual void _insert( const T& t )
100 OSL_ENSURE( Submission::getSubmission( t ) != NULL, "invalid item?" );
101 Submission::getSubmission( t )->setModel( com::sun::star::uno::Reference<com::sun::star::xforms::XModel>( mpModel ) );
104 virtual void _remove( const T& t )
106 OSL_ENSURE( Submission::getSubmission( t ) != NULL, "invalid item?" );
107 Submission::getSubmission( t )->setModel( com::sun::star::uno::Reference<com::sun::star::xforms::XModel>( ) );
113 // InstanceCollection
116 class InstanceCollection : public Collection<com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> >
118 public:
119 virtual bool isValid( const T& t ) const
121 const com::sun::star::beans::PropertyValue* pValues = t.getConstArray();
122 OUString sInstance( "Instance" );
123 sal_Bool bFound = sal_False;
124 for( sal_Int32 i = 0; ( ! bFound ) && ( i < t.getLength() ); i++ )
126 bFound |= ( pValues[i].Name == sInstance );
128 return bFound ? true : false;
134 // helper functions
137 sal_Int32 lcl_findInstance( const InstanceCollection*,
138 const OUString& );
141 // get values from Sequence<PropertyValue> describing an Instance
142 void getInstanceData(
143 const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>&,
144 OUString* pID,
145 com::sun::star::uno::Reference<com::sun::star::xml::dom::XDocument>*,
146 OUString* pURL,
147 bool* pURLOnce );
149 // set values on Sequence<PropertyValue> for an Instance
150 void setInstanceData(
151 com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>&,
152 const OUString* pID,
153 const com::sun::star::uno::Reference<com::sun::star::xml::dom::XDocument>*,
154 const OUString* pURL,
155 const bool* pURLOnce );
157 } // namespace xforms
159 #endif
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */