xref: /aoo41x/main/forms/source/inc/property.hxx (revision 2d785d7e)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _FRM_PROPERTY_HXX_
25 #define _FRM_PROPERTY_HXX_
26 
27 #include  <com/sun/star/uno/XAggregation.hpp>
28 #include <com/sun/star/beans/XPropertyState.hpp>
29 #include <com/sun/star/beans/PropertyAttribute.hpp>
30 #include <cppuhelper/propshlp.hxx>
31 #include <cppuhelper/proptypehlp.hxx>
32 #include <comphelper/property.hxx>
33 #include <comphelper/propagg.hxx>
34 #include <comphelper/stl_types.hxx>
35 
36 using namespace comphelper;
37 
38 //=========================================================================
39 //= property helper classes
40 //=========================================================================
41 
42 //... namespace frm .......................................................
43 namespace frm
44 {
45 //.........................................................................
46 
47 //==================================================================
48 //= assigment property handle <-> property name
49 //= used by the PropertySetAggregationHelper
50 //==================================================================
51 
52 class PropertyInfoService
53 {
54 	//..................................................................
55 	struct PropertyAssignment
56 	{
57 		::rtl::OUString		sName;
58 		sal_Int32			nHandle;
59 
PropertyAssignmentfrm::PropertyInfoService::PropertyAssignment60 		PropertyAssignment() { nHandle = -1; }
PropertyAssignmentfrm::PropertyInfoService::PropertyAssignment61 		PropertyAssignment(const PropertyAssignment& _rSource)
62 			:sName(_rSource.sName), nHandle(_rSource.nHandle) { }
PropertyAssignmentfrm::PropertyInfoService::PropertyAssignment63 		PropertyAssignment(const ::rtl::OUString& _rName, sal_Int32 _nHandle)
64 			:sName(_rName), nHandle(_nHandle) { }
65 
66 	};
67 
68 	DECLARE_STL_VECTOR(PropertyAssignment, PropertyMap);
69 	static PropertyMap		s_AllKnownProperties;
70 
71 	//..................................................................
72 	// comparing two PropertyAssignment's
73 public:
74 	typedef PropertyAssignment PUBLIC_SOLARIS_COMPILER_HACK;
75 		// did not get the following compiled under with SUNPRO 5 without this
76 		// public typedef
77 private:
78 	friend struct PropertyAssignmentNameCompareLess;
79 	typedef ::std::binary_function< PUBLIC_SOLARIS_COMPILER_HACK, PUBLIC_SOLARIS_COMPILER_HACK, sal_Bool > PropertyAssignmentNameCompareLess_Base;
80 	struct PropertyAssignmentNameCompareLess : public PropertyAssignmentNameCompareLess_Base
81 	{
operator ()frm::PropertyInfoService::PropertyAssignmentNameCompareLess82 		inline sal_Bool operator() (const PUBLIC_SOLARIS_COMPILER_HACK& _rL, const PUBLIC_SOLARIS_COMPILER_HACK& _rR) const
83 		{
84 			return (_rL.sName.compareTo(_rR.sName) < 0);
85 		}
86 	};
87 
88 public:
PropertyInfoService()89 	PropertyInfoService() { }
90 
91 public:
92 	static sal_Int32			getPropertyId(const ::rtl::OUString& _rName);
93 	static ::rtl::OUString		getPropertyName(sal_Int32 _nHandle);
94 
95 private:
96 	static void initialize();
97 };
98 
99 //..................................................................
100 // a class implementing the comphelper::IPropertyInfoService
101 class ConcreteInfoService : public ::comphelper::IPropertyInfoService
102 {
103 public:
104 	virtual	sal_Int32 getPreferedPropertyId(const ::rtl::OUString& _rName);
105 };
106 
107 //------------------------------------------------------------------------------
108 #define DECL_PROP_IMPL(varname, type) \
109     *pProperties++ = com::sun::star::beans::Property(PROPERTY_##varname, PROPERTY_ID_##varname, ::getCppuType(reinterpret_cast< type* >(NULL)),
110 
111 //------------------------------------------------------------------------------
112 #define DECL_BOOL_PROP_IMPL(varname) \
113     *pProperties++ = com::sun::star::beans::Property(PROPERTY_##varname, PROPERTY_ID_##varname, ::getBooleanCppuType(),
114 
115 //------------------------------------------------------------------------------
116 #define DECL_IFACE_PROP_IMPL(varname, type) \
117     *pProperties++ = com::sun::star::beans::Property(PROPERTY_##varname, PROPERTY_ID_##varname, ::getCppuType(reinterpret_cast< com::sun::star::uno::Reference< type >* >(NULL)),
118 
119 //------------------------------------------------------------------------------
120 #define BEGIN_DESCRIBE_PROPERTIES( count, baseclass )	\
121     baseclass::describeFixedProperties( _rProps ); \
122     sal_Int32 nOldCount = _rProps.getLength(); \
123 	_rProps.realloc( nOldCount + ( count ) );	\
124     ::com::sun::star::beans::Property* pProperties = _rProps.getArray() + nOldCount;       \
125 
126 //------------------------------------------------------------------------------
127 #define BEGIN_DESCRIBE_BASE_PROPERTIES( count )	\
128 	_rProps.realloc( count );	\
129     ::com::sun::star::beans::Property* pProperties = _rProps.getArray();       \
130 
131 //------------------------------------------------------------------------------
132 #define BEGIN_DESCRIBE_AGGREGATION_PROPERTIES( count, aggregate )	\
133 	_rProps.realloc( count );	\
134     ::com::sun::star::beans::Property* pProperties = _rProps.getArray();       \
135 	\
136 	if (aggregate.is())	\
137 		_rAggregateProps = aggregate->getPropertySetInfo()->getProperties();	\
138 
139 // ===
140 //------------------------------------------------------------------------------
141 #define DECL_PROP0(varname, type)	\
142 	DECL_PROP_IMPL(varname, type) 0)
143 
144 //------------------------------------------------------------------------------
145 #define DECL_PROP1(varname, type, attrib1)	\
146         DECL_PROP_IMPL(varname, type) com::sun::star::beans::PropertyAttribute::attrib1)
147 
148 //------------------------------------------------------------------------------
149 #define DECL_PROP2(varname, type, attrib1, attrib2)	\
150         DECL_PROP_IMPL(varname, type) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2)
151 
152 //------------------------------------------------------------------------------
153 #define DECL_PROP3(varname, type, attrib1, attrib2, attrib3)	\
154         DECL_PROP_IMPL(varname, type) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2 | com::sun::star::beans::PropertyAttribute::attrib3)
155 
156 //------------------------------------------------------------------------------
157 #define DECL_PROP4(varname, type, attrib1, attrib2, attrib3, attrib4)	\
158         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)
159 
160 // === some property types require special handling
161 // === such as interfaces
162 //------------------------------------------------------------------------------
163 #define DECL_IFACE_PROP0(varname, type)	\
164 	DECL_IFACE_PROP_IMPL(varname, type) 0)
165 
166 //------------------------------------------------------------------------------
167 #define DECL_IFACE_PROP1(varname, type, attrib1)	\
168 	DECL_IFACE_PROP_IMPL(varname, type) starbeans::PropertyAttribute::attrib1)
169 
170 //------------------------------------------------------------------------------
171 #define DECL_IFACE_PROP2(varname, type, attrib1, attrib2)	\
172         DECL_IFACE_PROP_IMPL(varname, type) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2)
173 
174 //------------------------------------------------------------------------------
175 #define DECL_IFACE_PROP3(varname, type, attrib1, attrib2, attrib3)	\
176 	DECL_IFACE_PROP_IMPL(varname, type) starbeans::PropertyAttribute::attrib1 | starbeans::PropertyAttribute::attrib2 | starbeans::PropertyAttribute::attrib3)
177 
178 //------------------------------------------------------------------------------
179 #define DECL_IFACE_PROP4(varname, type, attrib1, attrib2, attrib3, attrib4)	\
180 	DECL_IFACE_PROP_IMPL(varname, type) starbeans::PropertyAttribute::attrib1 | starbeans::PropertyAttribute::attrib2 | starbeans::PropertyAttribute::attrib3 | PropertyAttribute::attrib4)
181 
182 // === or Boolean properties
183 //------------------------------------------------------------------------------
184 #define DECL_BOOL_PROP0(varname)	\
185 	DECL_BOOL_PROP_IMPL(varname) 0)
186 
187 //------------------------------------------------------------------------------
188 #define DECL_BOOL_PROP1(varname, attrib1)	\
189         DECL_BOOL_PROP_IMPL(varname) com::sun::star::beans::PropertyAttribute::attrib1)
190 
191 //------------------------------------------------------------------------------
192 #define DECL_BOOL_PROP2(varname, attrib1, attrib2)	\
193         DECL_BOOL_PROP_IMPL(varname) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2)
194 
195 //------------------------------------------------------------------------------
196 #define DECL_BOOL_PROP3( varname, attrib1, attrib2, attrib3 )   \
197         DECL_BOOL_PROP_IMPL(varname) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2 | com::sun::star::beans::PropertyAttribute::attrib3 )
198 
199 // ===
200 //------------------------------------------------------------------------------
201 #define END_DESCRIBE_PROPERTIES()	\
202 	DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");	\
203 
204 //==============================================================================
205 //------------------------------------------------------------------------------
206 #define REGISTER_PROP_1( prop, member, attrib1 ) \
207     registerProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::attrib1, \
208         &member, ::getCppuType( &member ) );
209 
210 #define REGISTER_PROP_2( prop, member, attrib1, attrib2 ) \
211     registerProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::attrib1 | PropertyAttribute::attrib2, \
212         &member, ::getCppuType( &member ) );
213 
214 #define REGISTER_PROP_3( prop, member, attrib1, attrib2, attrib3 ) \
215     registerProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::attrib1 | PropertyAttribute::attrib2 | PropertyAttribute::attrib3, \
216         &member, ::getCppuType( &member ) );
217 
218 //------------------------------------------------------------------------------
219 #define REGISTER_VOID_PROP_1( prop, memberAny, type, attrib1 ) \
220     registerMayBeVoidProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::MAYBEVOID | PropertyAttribute::attrib1, \
221         &memberAny, ::getCppuType( static_cast< type* >( NULL ) ) );
222 
223 #define REGISTER_VOID_PROP_2( prop, memberAny, type, attrib1, attrib2 ) \
224     registerMayBeVoidProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::MAYBEVOID | PropertyAttribute::attrib1 | PropertyAttribute::attrib2, \
225         &memberAny, ::getCppuType( static_cast< type* >( NULL ) ) );
226 
227 //.........................................................................
228 }
229 //... namespace frm .......................................................
230 
231 #endif // _FRM_PROPERTY_HXX_
232 
233