masterfix DEV300: #i10000# build fix
[LibreOffice.git] / forms / source / xforms / model_helper.hxx
blobd67a83c8cdb13b8d095049be5e7930bccb88d071
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 #ifndef _MODEL_HELPER_HXX
28 #define _MODEL_HELPER_HXX
31 // some helper definitions that must be available for model.cxx and
32 // model_ui.cxx
35 #include "namedcollection.hxx"
36 #include "binding.hxx"
37 #include "submission.hxx"
38 #include "unohelper.hxx"
40 #include <com/sun/star/uno/Reference.hxx>
41 #include <com/sun/star/uno/Sequence.hxx>
42 #include <com/sun/star/lang/XUnoTunnel.hpp>
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include <com/sun/star/beans/PropertyValue.hpp>
46 namespace xforms
48 class Model;
52 // BindingCollection
55 namespace xforms
58 class BindingCollection : public NamedCollection<com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> >
60 Model* mpModel;
62 public:
63 BindingCollection( Model* pModel ) : mpModel( pModel ) {}
64 virtual ~BindingCollection() {}
66 virtual bool isValid( const T& t ) const
68 return Binding::getBinding( t ) != NULL;
71 protected:
72 virtual void _insert( const T& t )
74 OSL_ENSURE( Binding::getBinding( t ) != NULL, "invalid item?" );
75 Binding::getBinding( t )->_setModel( Binding::Model_t( mpModel ) );
78 virtual void _remove( const T& t )
80 OSL_ENSURE( Binding::getBinding( t ) != NULL, "invalid item?" );
81 Binding::getBinding( t )->_setModel( Binding::Model_t() );
88 // SubmissionCollection
91 class SubmissionCollection : public NamedCollection<com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> >
93 Model* mpModel;
95 public:
96 SubmissionCollection( Model* pModel ) : mpModel( pModel ) {}
97 virtual ~SubmissionCollection() {}
99 public:
100 virtual bool isValid( const T& t ) const
102 return Submission::getSubmission( t ) != NULL;
105 protected:
106 virtual void _insert( const T& t )
108 OSL_ENSURE( Submission::getSubmission( t ) != NULL, "invalid item?" );
109 Submission::getSubmission( t )->setModel( com::sun::star::uno::Reference<com::sun::star::xforms::XModel>( mpModel ) );
112 virtual void _remove( const T& t )
114 OSL_ENSURE( Submission::getSubmission( t ) != NULL, "invalid item?" );
115 Submission::getSubmission( t )->setModel( com::sun::star::uno::Reference<com::sun::star::xforms::XModel>( ) );
121 // InstanceCollection
124 class InstanceCollection : public Collection<com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> >
126 public:
127 virtual bool isValid( const T& t ) const
129 const com::sun::star::beans::PropertyValue* pValues = t.getConstArray();
130 rtl::OUString sInstance( OUSTRING("Instance") );
131 sal_Bool bFound = sal_False;
132 for( sal_Int32 i = 0; ( ! bFound ) && ( i < t.getLength() ); i++ )
134 bFound |= ( pValues[i].Name == sInstance );
136 return bFound ? true : false;
142 // helper functions
145 sal_Int32 lcl_findInstance( const InstanceCollection*,
146 const rtl::OUString& );
149 // get values from Sequence<PropertyValue> describing an Instance
150 void getInstanceData(
151 const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>&,
152 rtl::OUString* pID,
153 com::sun::star::uno::Reference<com::sun::star::xml::dom::XDocument>*,
154 rtl::OUString* pURL,
155 bool* pURLOnce );
157 // set values on Sequence<PropertyValue> for an Instance
158 void setInstanceData(
159 com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>&,
160 const rtl::OUString* pID,
161 const com::sun::star::uno::Reference<com::sun::star::xml::dom::XDocument>*,
162 const rtl::OUString* pURL,
163 const bool* pURLOnce );
165 } // namespace xforms
167 #endif