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