xref: /trunk/main/forms/source/inc/property.hxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _FRM_PROPERTY_HXX_
29*cdf0e10cSrcweir #define _FRM_PROPERTY_HXX_
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include  <com/sun/star/uno/XAggregation.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyState.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
34*cdf0e10cSrcweir #include <cppuhelper/propshlp.hxx>
35*cdf0e10cSrcweir #include <cppuhelper/proptypehlp.hxx>
36*cdf0e10cSrcweir #include <comphelper/property.hxx>
37*cdf0e10cSrcweir #include <comphelper/propagg.hxx>
38*cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir using namespace comphelper;
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir //=========================================================================
43*cdf0e10cSrcweir //= property helper classes
44*cdf0e10cSrcweir //=========================================================================
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir //... namespace frm .......................................................
47*cdf0e10cSrcweir namespace frm
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir //.........................................................................
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir //==================================================================
52*cdf0e10cSrcweir //= assigment property handle <-> property name
53*cdf0e10cSrcweir //= used by the PropertySetAggregationHelper
54*cdf0e10cSrcweir //==================================================================
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir class PropertyInfoService
57*cdf0e10cSrcweir {
58*cdf0e10cSrcweir 	//..................................................................
59*cdf0e10cSrcweir 	struct PropertyAssignment
60*cdf0e10cSrcweir 	{
61*cdf0e10cSrcweir 		::rtl::OUString		sName;
62*cdf0e10cSrcweir 		sal_Int32			nHandle;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir 		PropertyAssignment() { nHandle = -1; }
65*cdf0e10cSrcweir 		PropertyAssignment(const PropertyAssignment& _rSource)
66*cdf0e10cSrcweir 			:sName(_rSource.sName), nHandle(_rSource.nHandle) { }
67*cdf0e10cSrcweir 		PropertyAssignment(const ::rtl::OUString& _rName, sal_Int32 _nHandle)
68*cdf0e10cSrcweir 			:sName(_rName), nHandle(_nHandle) { }
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir 	};
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 	DECLARE_STL_VECTOR(PropertyAssignment, PropertyMap);
73*cdf0e10cSrcweir 	static PropertyMap		s_AllKnownProperties;
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 	//..................................................................
76*cdf0e10cSrcweir 	// comparing two PropertyAssignment's
77*cdf0e10cSrcweir public:
78*cdf0e10cSrcweir 	typedef PropertyAssignment PUBLIC_SOLARIS_COMPILER_HACK;
79*cdf0e10cSrcweir 		// did not get the following compiled under with SUNPRO 5 without this
80*cdf0e10cSrcweir 		// public typedef
81*cdf0e10cSrcweir private:
82*cdf0e10cSrcweir 	friend struct PropertyAssignmentNameCompareLess;
83*cdf0e10cSrcweir 	typedef ::std::binary_function< PUBLIC_SOLARIS_COMPILER_HACK, PUBLIC_SOLARIS_COMPILER_HACK, sal_Bool > PropertyAssignmentNameCompareLess_Base;
84*cdf0e10cSrcweir 	struct PropertyAssignmentNameCompareLess : public PropertyAssignmentNameCompareLess_Base
85*cdf0e10cSrcweir 	{
86*cdf0e10cSrcweir 		inline sal_Bool operator() (const PUBLIC_SOLARIS_COMPILER_HACK& _rL, const PUBLIC_SOLARIS_COMPILER_HACK& _rR) const
87*cdf0e10cSrcweir 		{
88*cdf0e10cSrcweir 			return (_rL.sName.compareTo(_rR.sName) < 0);
89*cdf0e10cSrcweir 		}
90*cdf0e10cSrcweir 	};
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir public:
93*cdf0e10cSrcweir 	PropertyInfoService() { }
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir public:
96*cdf0e10cSrcweir 	static sal_Int32			getPropertyId(const ::rtl::OUString& _rName);
97*cdf0e10cSrcweir 	static ::rtl::OUString		getPropertyName(sal_Int32 _nHandle);
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir private:
100*cdf0e10cSrcweir 	static void initialize();
101*cdf0e10cSrcweir };
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir //..................................................................
104*cdf0e10cSrcweir // a class implementing the comphelper::IPropertyInfoService
105*cdf0e10cSrcweir class ConcreteInfoService : public ::comphelper::IPropertyInfoService
106*cdf0e10cSrcweir {
107*cdf0e10cSrcweir public:
108*cdf0e10cSrcweir 	virtual	sal_Int32 getPreferedPropertyId(const ::rtl::OUString& _rName);
109*cdf0e10cSrcweir };
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir //------------------------------------------------------------------------------
112*cdf0e10cSrcweir #define DECL_PROP_IMPL(varname, type) \
113*cdf0e10cSrcweir     *pProperties++ = com::sun::star::beans::Property(PROPERTY_##varname, PROPERTY_ID_##varname, ::getCppuType(reinterpret_cast< type* >(NULL)),
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir //------------------------------------------------------------------------------
116*cdf0e10cSrcweir #define DECL_BOOL_PROP_IMPL(varname) \
117*cdf0e10cSrcweir     *pProperties++ = com::sun::star::beans::Property(PROPERTY_##varname, PROPERTY_ID_##varname, ::getBooleanCppuType(),
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir //------------------------------------------------------------------------------
120*cdf0e10cSrcweir #define DECL_IFACE_PROP_IMPL(varname, type) \
121*cdf0e10cSrcweir     *pProperties++ = com::sun::star::beans::Property(PROPERTY_##varname, PROPERTY_ID_##varname, ::getCppuType(reinterpret_cast< com::sun::star::uno::Reference< type >* >(NULL)),
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir //------------------------------------------------------------------------------
124*cdf0e10cSrcweir #define BEGIN_DESCRIBE_PROPERTIES( count, baseclass )	\
125*cdf0e10cSrcweir     baseclass::describeFixedProperties( _rProps ); \
126*cdf0e10cSrcweir     sal_Int32 nOldCount = _rProps.getLength(); \
127*cdf0e10cSrcweir 	_rProps.realloc( nOldCount + ( count ) );	\
128*cdf0e10cSrcweir     ::com::sun::star::beans::Property* pProperties = _rProps.getArray() + nOldCount;       \
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir //------------------------------------------------------------------------------
131*cdf0e10cSrcweir #define BEGIN_DESCRIBE_BASE_PROPERTIES( count )	\
132*cdf0e10cSrcweir 	_rProps.realloc( count );	\
133*cdf0e10cSrcweir     ::com::sun::star::beans::Property* pProperties = _rProps.getArray();       \
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir //------------------------------------------------------------------------------
136*cdf0e10cSrcweir #define BEGIN_DESCRIBE_AGGREGATION_PROPERTIES( count, aggregate )	\
137*cdf0e10cSrcweir 	_rProps.realloc( count );	\
138*cdf0e10cSrcweir     ::com::sun::star::beans::Property* pProperties = _rProps.getArray();       \
139*cdf0e10cSrcweir 	\
140*cdf0e10cSrcweir 	if (aggregate.is())	\
141*cdf0e10cSrcweir 		_rAggregateProps = aggregate->getPropertySetInfo()->getProperties();	\
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir // ===
144*cdf0e10cSrcweir //------------------------------------------------------------------------------
145*cdf0e10cSrcweir #define DECL_PROP0(varname, type)	\
146*cdf0e10cSrcweir 	DECL_PROP_IMPL(varname, type) 0)
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir //------------------------------------------------------------------------------
149*cdf0e10cSrcweir #define DECL_PROP1(varname, type, attrib1)	\
150*cdf0e10cSrcweir         DECL_PROP_IMPL(varname, type) com::sun::star::beans::PropertyAttribute::attrib1)
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir //------------------------------------------------------------------------------
153*cdf0e10cSrcweir #define DECL_PROP2(varname, type, attrib1, attrib2)	\
154*cdf0e10cSrcweir         DECL_PROP_IMPL(varname, type) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2)
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir //------------------------------------------------------------------------------
157*cdf0e10cSrcweir #define DECL_PROP3(varname, type, attrib1, attrib2, attrib3)	\
158*cdf0e10cSrcweir         DECL_PROP_IMPL(varname, type) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2 | com::sun::star::beans::PropertyAttribute::attrib3)
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir //------------------------------------------------------------------------------
161*cdf0e10cSrcweir #define DECL_PROP4(varname, type, attrib1, attrib2, attrib3, attrib4)	\
162*cdf0e10cSrcweir         DECL_PROP_IMPL(varname, type) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2 | com::sun::star::beans::PropertyAttribute::attrib3 | com::sun::star::beans::PropertyAttribute::attrib4)
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir // === some property types require special handling
165*cdf0e10cSrcweir // === such as interfaces
166*cdf0e10cSrcweir //------------------------------------------------------------------------------
167*cdf0e10cSrcweir #define DECL_IFACE_PROP0(varname, type)	\
168*cdf0e10cSrcweir 	DECL_IFACE_PROP_IMPL(varname, type) 0)
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir //------------------------------------------------------------------------------
171*cdf0e10cSrcweir #define DECL_IFACE_PROP1(varname, type, attrib1)	\
172*cdf0e10cSrcweir 	DECL_IFACE_PROP_IMPL(varname, type) starbeans::PropertyAttribute::attrib1)
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir //------------------------------------------------------------------------------
175*cdf0e10cSrcweir #define DECL_IFACE_PROP2(varname, type, attrib1, attrib2)	\
176*cdf0e10cSrcweir         DECL_IFACE_PROP_IMPL(varname, type) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2)
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir //------------------------------------------------------------------------------
179*cdf0e10cSrcweir #define DECL_IFACE_PROP3(varname, type, attrib1, attrib2, attrib3)	\
180*cdf0e10cSrcweir 	DECL_IFACE_PROP_IMPL(varname, type) starbeans::PropertyAttribute::attrib1 | starbeans::PropertyAttribute::attrib2 | starbeans::PropertyAttribute::attrib3)
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir //------------------------------------------------------------------------------
183*cdf0e10cSrcweir #define DECL_IFACE_PROP4(varname, type, attrib1, attrib2, attrib3, attrib4)	\
184*cdf0e10cSrcweir 	DECL_IFACE_PROP_IMPL(varname, type) starbeans::PropertyAttribute::attrib1 | starbeans::PropertyAttribute::attrib2 | starbeans::PropertyAttribute::attrib3 | PropertyAttribute::attrib4)
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir // === or Boolean properties
187*cdf0e10cSrcweir //------------------------------------------------------------------------------
188*cdf0e10cSrcweir #define DECL_BOOL_PROP0(varname)	\
189*cdf0e10cSrcweir 	DECL_BOOL_PROP_IMPL(varname) 0)
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir //------------------------------------------------------------------------------
192*cdf0e10cSrcweir #define DECL_BOOL_PROP1(varname, attrib1)	\
193*cdf0e10cSrcweir         DECL_BOOL_PROP_IMPL(varname) com::sun::star::beans::PropertyAttribute::attrib1)
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir //------------------------------------------------------------------------------
196*cdf0e10cSrcweir #define DECL_BOOL_PROP2(varname, attrib1, attrib2)	\
197*cdf0e10cSrcweir         DECL_BOOL_PROP_IMPL(varname) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2)
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir //------------------------------------------------------------------------------
200*cdf0e10cSrcweir #define DECL_BOOL_PROP3( varname, attrib1, attrib2, attrib3 )   \
201*cdf0e10cSrcweir         DECL_BOOL_PROP_IMPL(varname) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2 | com::sun::star::beans::PropertyAttribute::attrib3 )
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir // ===
204*cdf0e10cSrcweir //------------------------------------------------------------------------------
205*cdf0e10cSrcweir #define END_DESCRIBE_PROPERTIES()	\
206*cdf0e10cSrcweir 	DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");	\
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir //==============================================================================
209*cdf0e10cSrcweir //------------------------------------------------------------------------------
210*cdf0e10cSrcweir #define REGISTER_PROP_1( prop, member, attrib1 ) \
211*cdf0e10cSrcweir     registerProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::attrib1, \
212*cdf0e10cSrcweir         &member, ::getCppuType( &member ) );
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir #define REGISTER_PROP_2( prop, member, attrib1, attrib2 ) \
215*cdf0e10cSrcweir     registerProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::attrib1 | PropertyAttribute::attrib2, \
216*cdf0e10cSrcweir         &member, ::getCppuType( &member ) );
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir #define REGISTER_PROP_3( prop, member, attrib1, attrib2, attrib3 ) \
219*cdf0e10cSrcweir     registerProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::attrib1 | PropertyAttribute::attrib2 | PropertyAttribute::attrib3, \
220*cdf0e10cSrcweir         &member, ::getCppuType( &member ) );
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir //------------------------------------------------------------------------------
223*cdf0e10cSrcweir #define REGISTER_VOID_PROP_1( prop, memberAny, type, attrib1 ) \
224*cdf0e10cSrcweir     registerMayBeVoidProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::MAYBEVOID | PropertyAttribute::attrib1, \
225*cdf0e10cSrcweir         &memberAny, ::getCppuType( static_cast< type* >( NULL ) ) );
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir #define REGISTER_VOID_PROP_2( prop, memberAny, type, attrib1, attrib2 ) \
228*cdf0e10cSrcweir     registerMayBeVoidProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::MAYBEVOID | PropertyAttribute::attrib1 | PropertyAttribute::attrib2, \
229*cdf0e10cSrcweir         &memberAny, ::getCppuType( static_cast< type* >( NULL ) ) );
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir //.........................................................................
232*cdf0e10cSrcweir }
233*cdf0e10cSrcweir //... namespace frm .......................................................
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir #endif // _FRM_PROPERTY_HXX_
236*cdf0e10cSrcweir 
237