Update ooo320-m1
[ooovba.git] / forms / source / xforms / model_helper.hxx
blob6b460bc612f56f85a57ec5290d1c8839c0db394e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: model_helper.hxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _MODEL_HELPER_HXX
31 #define _MODEL_HELPER_HXX
34 // some helper definitions that must be available for model.cxx and
35 // model_ui.cxx
38 #include "namedcollection.hxx"
39 #include "binding.hxx"
40 #include "submission.hxx"
41 #include "unohelper.hxx"
43 #include <com/sun/star/uno/Reference.hxx>
44 #include <com/sun/star/uno/Sequence.hxx>
45 #include <com/sun/star/lang/XUnoTunnel.hpp>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <com/sun/star/beans/PropertyValue.hpp>
49 namespace xforms
51 class Model;
55 // BindingCollection
58 namespace xforms
61 class BindingCollection : public NamedCollection<com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> >
63 Model* mpModel;
65 public:
66 BindingCollection( Model* pModel ) : mpModel( pModel ) {}
67 virtual ~BindingCollection() {}
69 virtual bool isValid( const T& t ) const
71 return Binding::getBinding( t ) != NULL;
74 protected:
75 virtual void _insert( const T& t )
77 OSL_ENSURE( Binding::getBinding( t ) != NULL, "invalid item?" );
78 Binding::getBinding( t )->_setModel( Binding::Model_t( mpModel ) );
81 virtual void _remove( const T& t )
83 OSL_ENSURE( Binding::getBinding( t ) != NULL, "invalid item?" );
84 Binding::getBinding( t )->_setModel( Binding::Model_t() );
91 // SubmissionCollection
94 class SubmissionCollection : public NamedCollection<com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> >
96 Model* mpModel;
98 public:
99 SubmissionCollection( Model* pModel ) : mpModel( pModel ) {}
100 virtual ~SubmissionCollection() {}
102 public:
103 virtual bool isValid( const T& t ) const
105 return Submission::getSubmission( t ) != NULL;
108 protected:
109 virtual void _insert( const T& t )
111 OSL_ENSURE( Submission::getSubmission( t ) != NULL, "invalid item?" );
112 Submission::getSubmission( t )->setModel( com::sun::star::uno::Reference<com::sun::star::xforms::XModel>( mpModel ) );
115 virtual void _remove( const T& t )
117 OSL_ENSURE( Submission::getSubmission( t ) != NULL, "invalid item?" );
118 Submission::getSubmission( t )->setModel( com::sun::star::uno::Reference<com::sun::star::xforms::XModel>( ) );
124 // InstanceCollection
127 class InstanceCollection : public Collection<com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> >
129 public:
130 virtual bool isValid( const T& t ) const
132 const com::sun::star::beans::PropertyValue* pValues = t.getConstArray();
133 rtl::OUString sInstance( OUSTRING("Instance") );
134 sal_Bool bFound = sal_False;
135 for( sal_Int32 i = 0; ( ! bFound ) && ( i < t.getLength() ); i++ )
137 bFound |= ( pValues[i].Name == sInstance );
139 return bFound ? true : false;
145 // helper functions
148 sal_Int32 lcl_findInstance( const InstanceCollection*,
149 const rtl::OUString& );
152 // get values from Sequence<PropertyValue> describing an Instance
153 void getInstanceData(
154 const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>&,
155 rtl::OUString* pID,
156 com::sun::star::uno::Reference<com::sun::star::xml::dom::XDocument>*,
157 rtl::OUString* pURL,
158 bool* pURLOnce );
160 // set values on Sequence<PropertyValue> for an Instance
161 void setInstanceData(
162 com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>&,
163 const rtl::OUString* pID,
164 const com::sun::star::uno::Reference<com::sun::star::xml::dom::XDocument>*,
165 const rtl::OUString* pURL,
166 const bool* pURLOnce );
168 } // namespace xforms
170 #endif