1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: property.hxx,v $
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 ************************************************************************/
31 #ifndef _FRM_PROPERTY_HXX_
32 #define _FRM_PROPERTY_HXX_
34 #include <com/sun/star/uno/XAggregation.hpp>
35 #include <com/sun/star/beans/XPropertyState.hpp>
36 #include <com/sun/star/beans/PropertyAttribute.hpp>
37 #include <cppuhelper/propshlp.hxx>
38 #include <cppuhelper/proptypehlp.hxx>
39 #include <comphelper/property.hxx>
40 #include <comphelper/propagg.hxx>
41 #include <comphelper/stl_types.hxx>
43 using namespace comphelper
;
45 //=========================================================================
46 //= property helper classes
47 //=========================================================================
49 //... namespace frm .......................................................
52 //.........................................................................
54 //==================================================================
55 //= assigment property handle <-> property name
56 //= used by the PropertySetAggregationHelper
57 //==================================================================
59 class PropertyInfoService
61 //..................................................................
62 struct PropertyAssignment
64 ::rtl::OUString sName
;
67 PropertyAssignment() { nHandle
= -1; }
68 PropertyAssignment(const PropertyAssignment
& _rSource
)
69 :sName(_rSource
.sName
), nHandle(_rSource
.nHandle
) { }
70 PropertyAssignment(const ::rtl::OUString
& _rName
, sal_Int32 _nHandle
)
71 :sName(_rName
), nHandle(_nHandle
) { }
75 DECLARE_STL_VECTOR(PropertyAssignment
, PropertyMap
);
76 static PropertyMap s_AllKnownProperties
;
78 //..................................................................
79 // comparing two PropertyAssignment's
81 typedef PropertyAssignment PUBLIC_SOLARIS_COMPILER_HACK
;
82 // did not get the following compiled under with SUNPRO 5 without this
85 friend struct PropertyAssignmentNameCompareLess
;
86 typedef ::std::binary_function
< PUBLIC_SOLARIS_COMPILER_HACK
, PUBLIC_SOLARIS_COMPILER_HACK
, sal_Bool
> PropertyAssignmentNameCompareLess_Base
;
87 struct PropertyAssignmentNameCompareLess
: public PropertyAssignmentNameCompareLess_Base
89 inline sal_Bool
operator() (const PUBLIC_SOLARIS_COMPILER_HACK
& _rL
, const PUBLIC_SOLARIS_COMPILER_HACK
& _rR
) const
91 return (_rL
.sName
.compareTo(_rR
.sName
) < 0);
96 PropertyInfoService() { }
99 static sal_Int32
getPropertyId(const ::rtl::OUString
& _rName
);
100 static ::rtl::OUString
getPropertyName(sal_Int32 _nHandle
);
103 static void initialize();
106 //..................................................................
107 // a class implementing the comphelper::IPropertyInfoService
108 class ConcreteInfoService
: public ::comphelper::IPropertyInfoService
111 virtual sal_Int32
getPreferedPropertyId(const ::rtl::OUString
& _rName
);
114 //------------------------------------------------------------------------------
115 #define DECL_PROP_IMPL(varname, type) \
116 *pProperties++ = com::sun::star::beans::Property(PROPERTY_##varname, PROPERTY_ID_##varname, ::getCppuType(reinterpret_cast< type* >(NULL)),
118 //------------------------------------------------------------------------------
119 #define DECL_BOOL_PROP_IMPL(varname) \
120 *pProperties++ = com::sun::star::beans::Property(PROPERTY_##varname, PROPERTY_ID_##varname, ::getBooleanCppuType(),
122 //------------------------------------------------------------------------------
123 #define DECL_IFACE_PROP_IMPL(varname, type) \
124 *pProperties++ = com::sun::star::beans::Property(PROPERTY_##varname, PROPERTY_ID_##varname, ::getCppuType(reinterpret_cast< com::sun::star::uno::Reference< type >* >(NULL)),
126 //------------------------------------------------------------------------------
127 #define BEGIN_DESCRIBE_PROPERTIES( count, baseclass ) \
128 baseclass::describeFixedProperties( _rProps ); \
129 sal_Int32 nOldCount = _rProps.getLength(); \
130 _rProps.realloc( nOldCount + ( count ) ); \
131 ::com::sun::star::beans::Property* pProperties = _rProps.getArray() + nOldCount; \
133 //------------------------------------------------------------------------------
134 #define BEGIN_DESCRIBE_BASE_PROPERTIES( count ) \
135 _rProps.realloc( count ); \
136 ::com::sun::star::beans::Property* pProperties = _rProps.getArray(); \
138 //------------------------------------------------------------------------------
139 #define BEGIN_DESCRIBE_AGGREGATION_PROPERTIES( count, aggregate ) \
140 _rProps.realloc( count ); \
141 ::com::sun::star::beans::Property* pProperties = _rProps.getArray(); \
143 if (aggregate.is()) \
144 _rAggregateProps = aggregate->getPropertySetInfo()->getProperties(); \
147 //------------------------------------------------------------------------------
148 #define DECL_PROP0(varname, type) \
149 DECL_PROP_IMPL(varname, type) 0)
151 //------------------------------------------------------------------------------
152 #define DECL_PROP1(varname, type, attrib1) \
153 DECL_PROP_IMPL(varname, type) com::sun::star::beans::PropertyAttribute::attrib1)
155 //------------------------------------------------------------------------------
156 #define DECL_PROP2(varname, type, attrib1, attrib2) \
157 DECL_PROP_IMPL(varname, type) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2)
159 //------------------------------------------------------------------------------
160 #define DECL_PROP3(varname, type, attrib1, attrib2, attrib3) \
161 DECL_PROP_IMPL(varname, type) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2 | com::sun::star::beans::PropertyAttribute::attrib3)
163 //------------------------------------------------------------------------------
164 #define DECL_PROP4(varname, type, attrib1, attrib2, attrib3, attrib4) \
165 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)
167 // === some property types require special handling
168 // === such as interfaces
169 //------------------------------------------------------------------------------
170 #define DECL_IFACE_PROP0(varname, type) \
171 DECL_IFACE_PROP_IMPL(varname, type) 0)
173 //------------------------------------------------------------------------------
174 #define DECL_IFACE_PROP1(varname, type, attrib1) \
175 DECL_IFACE_PROP_IMPL(varname, type) starbeans::PropertyAttribute::attrib1)
177 //------------------------------------------------------------------------------
178 #define DECL_IFACE_PROP2(varname, type, attrib1, attrib2) \
179 DECL_IFACE_PROP_IMPL(varname, type) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2)
181 //------------------------------------------------------------------------------
182 #define DECL_IFACE_PROP3(varname, type, attrib1, attrib2, attrib3) \
183 DECL_IFACE_PROP_IMPL(varname, type) starbeans::PropertyAttribute::attrib1 | starbeans::PropertyAttribute::attrib2 | starbeans::PropertyAttribute::attrib3)
185 //------------------------------------------------------------------------------
186 #define DECL_IFACE_PROP4(varname, type, attrib1, attrib2, attrib3, attrib4) \
187 DECL_IFACE_PROP_IMPL(varname, type) starbeans::PropertyAttribute::attrib1 | starbeans::PropertyAttribute::attrib2 | starbeans::PropertyAttribute::attrib3 | PropertyAttribute::attrib4)
189 // === or Boolean properties
190 //------------------------------------------------------------------------------
191 #define DECL_BOOL_PROP0(varname) \
192 DECL_BOOL_PROP_IMPL(varname) 0)
194 //------------------------------------------------------------------------------
195 #define DECL_BOOL_PROP1(varname, attrib1) \
196 DECL_BOOL_PROP_IMPL(varname) com::sun::star::beans::PropertyAttribute::attrib1)
198 //------------------------------------------------------------------------------
199 #define DECL_BOOL_PROP2(varname, attrib1, attrib2) \
200 DECL_BOOL_PROP_IMPL(varname) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2)
202 //------------------------------------------------------------------------------
203 #define DECL_BOOL_PROP3( varname, attrib1, attrib2, attrib3 ) \
204 DECL_BOOL_PROP_IMPL(varname) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2 | com::sun::star::beans::PropertyAttribute::attrib3 )
207 //------------------------------------------------------------------------------
208 #define END_DESCRIBE_PROPERTIES() \
209 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?"); \
211 //==============================================================================
212 //------------------------------------------------------------------------------
213 #define REGISTER_PROP_1( prop, member, attrib1 ) \
214 registerProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::attrib1, \
215 &member, ::getCppuType( &member ) );
217 #define REGISTER_PROP_2( prop, member, attrib1, attrib2 ) \
218 registerProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::attrib1 | PropertyAttribute::attrib2, \
219 &member, ::getCppuType( &member ) );
221 #define REGISTER_PROP_3( prop, member, attrib1, attrib2, attrib3 ) \
222 registerProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::attrib1 | PropertyAttribute::attrib2 | PropertyAttribute::attrib3, \
223 &member, ::getCppuType( &member ) );
225 //------------------------------------------------------------------------------
226 #define REGISTER_VOID_PROP_1( prop, memberAny, type, attrib1 ) \
227 registerMayBeVoidProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::MAYBEVOID | PropertyAttribute::attrib1, \
228 &memberAny, ::getCppuType( static_cast< type* >( NULL ) ) );
230 #define REGISTER_VOID_PROP_2( prop, memberAny, type, attrib1, attrib2 ) \
231 registerMayBeVoidProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::MAYBEVOID | PropertyAttribute::attrib1 | PropertyAttribute::attrib2, \
232 &memberAny, ::getCppuType( static_cast< type* >( NULL ) ) );
234 //.........................................................................
236 //... namespace frm .......................................................
238 #endif // _FRM_PROPERTY_HXX_