1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef _FRM_PROPERTY_HXX_
21 #define _FRM_PROPERTY_HXX_
23 #include <com/sun/star/uno/XAggregation.hpp>
24 #include <com/sun/star/beans/XPropertyState.hpp>
25 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 #include <cppuhelper/propshlp.hxx>
27 #include <cppuhelper/proptypehlp.hxx>
28 #include <comphelper/property.hxx>
29 #include <comphelper/propagg.hxx>
30 #include <comphelper/stl_types.hxx>
32 using namespace comphelper
;
34 //=========================================================================
35 //= property helper classes
36 //=========================================================================
38 //... namespace frm .......................................................
41 //.........................................................................
43 //==================================================================
44 //= assigment property handle <-> property name
45 //= used by the PropertySetAggregationHelper
46 //==================================================================
48 class PropertyInfoService
50 //..................................................................
51 struct PropertyAssignment
56 PropertyAssignment() { nHandle
= -1; }
57 PropertyAssignment(const PropertyAssignment
& _rSource
)
58 :sName(_rSource
.sName
), nHandle(_rSource
.nHandle
) { }
59 PropertyAssignment(const OUString
& _rName
, sal_Int32 _nHandle
)
60 :sName(_rName
), nHandle(_nHandle
) { }
64 DECLARE_STL_VECTOR(PropertyAssignment
, PropertyMap
);
65 static PropertyMap s_AllKnownProperties
;
67 //..................................................................
68 // comparing two PropertyAssignment's
70 typedef PropertyAssignment PUBLIC_SOLARIS_COMPILER_HACK
;
71 // did not get the following compiled under with SUNPRO 5 without this
74 friend struct PropertyAssignmentNameCompareLess
;
75 typedef ::std::binary_function
< PUBLIC_SOLARIS_COMPILER_HACK
, PUBLIC_SOLARIS_COMPILER_HACK
, sal_Bool
> PropertyAssignmentNameCompareLess_Base
;
76 struct PropertyAssignmentNameCompareLess
: public PropertyAssignmentNameCompareLess_Base
78 inline sal_Bool
operator() (const PUBLIC_SOLARIS_COMPILER_HACK
& _rL
, const PUBLIC_SOLARIS_COMPILER_HACK
& _rR
) const
80 return (_rL
.sName
.compareTo(_rR
.sName
) < 0);
85 PropertyInfoService() { }
88 static sal_Int32
getPropertyId(const OUString
& _rName
);
89 static OUString
getPropertyName(sal_Int32 _nHandle
);
92 static void initialize();
95 //..................................................................
96 // a class implementing the comphelper::IPropertyInfoService
97 class ConcreteInfoService
: public ::comphelper::IPropertyInfoService
100 virtual ~ConcreteInfoService() {}
102 virtual sal_Int32
getPreferedPropertyId(const OUString
& _rName
);
105 //------------------------------------------------------------------------------
106 #define DECL_PROP_IMPL(varname, type) \
107 *pProperties++ = com::sun::star::beans::Property(PROPERTY_##varname, PROPERTY_ID_##varname, ::getCppuType(static_cast< type* >(0)),
109 //------------------------------------------------------------------------------
110 #define DECL_BOOL_PROP_IMPL(varname) \
111 *pProperties++ = com::sun::star::beans::Property(PROPERTY_##varname, PROPERTY_ID_##varname, ::getBooleanCppuType(),
113 //------------------------------------------------------------------------------
114 #define DECL_IFACE_PROP_IMPL(varname, type) \
115 *pProperties++ = com::sun::star::beans::Property(PROPERTY_##varname, PROPERTY_ID_##varname, ::getCppuType(static_cast< com::sun::star::uno::Reference< type >* >(0)),
117 //------------------------------------------------------------------------------
118 #define BEGIN_DESCRIBE_PROPERTIES( count, baseclass ) \
119 baseclass::describeFixedProperties( _rProps ); \
120 sal_Int32 nOldCount = _rProps.getLength(); \
121 _rProps.realloc( nOldCount + ( count ) ); \
122 ::com::sun::star::beans::Property* pProperties = _rProps.getArray() + nOldCount; \
124 //------------------------------------------------------------------------------
125 #define BEGIN_DESCRIBE_BASE_PROPERTIES( count ) \
126 _rProps.realloc( count ); \
127 ::com::sun::star::beans::Property* pProperties = _rProps.getArray(); \
129 //------------------------------------------------------------------------------
130 #define BEGIN_DESCRIBE_AGGREGATION_PROPERTIES( count, aggregate ) \
131 _rProps.realloc( count ); \
132 ::com::sun::star::beans::Property* pProperties = _rProps.getArray(); \
134 if (aggregate.is()) \
135 _rAggregateProps = aggregate->getPropertySetInfo()->getProperties(); \
138 //------------------------------------------------------------------------------
139 #define DECL_PROP0(varname, type) \
140 DECL_PROP_IMPL(varname, type) 0)
142 //------------------------------------------------------------------------------
143 #define DECL_PROP1(varname, type, attrib1) \
144 DECL_PROP_IMPL(varname, type) com::sun::star::beans::PropertyAttribute::attrib1)
146 //------------------------------------------------------------------------------
147 #define DECL_PROP2(varname, type, attrib1, attrib2) \
148 DECL_PROP_IMPL(varname, type) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2)
150 //------------------------------------------------------------------------------
151 #define DECL_PROP3(varname, type, attrib1, attrib2, attrib3) \
152 DECL_PROP_IMPL(varname, type) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2 | com::sun::star::beans::PropertyAttribute::attrib3)
154 //------------------------------------------------------------------------------
155 #define DECL_PROP4(varname, type, attrib1, attrib2, attrib3, attrib4) \
156 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)
158 // === some property types require special handling
159 // === such as interfaces
160 //------------------------------------------------------------------------------
161 #define DECL_IFACE_PROP0(varname, type) \
162 DECL_IFACE_PROP_IMPL(varname, type) 0)
164 //------------------------------------------------------------------------------
165 #define DECL_IFACE_PROP1(varname, type, attrib1) \
166 DECL_IFACE_PROP_IMPL(varname, type) starbeans::PropertyAttribute::attrib1)
168 //------------------------------------------------------------------------------
169 #define DECL_IFACE_PROP2(varname, type, attrib1, attrib2) \
170 DECL_IFACE_PROP_IMPL(varname, type) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2)
172 //------------------------------------------------------------------------------
173 #define DECL_IFACE_PROP3(varname, type, attrib1, attrib2, attrib3) \
174 DECL_IFACE_PROP_IMPL(varname, type) starbeans::PropertyAttribute::attrib1 | starbeans::PropertyAttribute::attrib2 | starbeans::PropertyAttribute::attrib3)
176 //------------------------------------------------------------------------------
177 #define DECL_IFACE_PROP4(varname, type, attrib1, attrib2, attrib3, attrib4) \
178 DECL_IFACE_PROP_IMPL(varname, type) starbeans::PropertyAttribute::attrib1 | starbeans::PropertyAttribute::attrib2 | starbeans::PropertyAttribute::attrib3 | PropertyAttribute::attrib4)
180 // === or Boolean properties
181 //------------------------------------------------------------------------------
182 #define DECL_BOOL_PROP0(varname) \
183 DECL_BOOL_PROP_IMPL(varname) 0)
185 //------------------------------------------------------------------------------
186 #define DECL_BOOL_PROP1(varname, attrib1) \
187 DECL_BOOL_PROP_IMPL(varname) com::sun::star::beans::PropertyAttribute::attrib1)
189 //------------------------------------------------------------------------------
190 #define DECL_BOOL_PROP2(varname, attrib1, attrib2) \
191 DECL_BOOL_PROP_IMPL(varname) com::sun::star::beans::PropertyAttribute::attrib1 | com::sun::star::beans::PropertyAttribute::attrib2)
193 //------------------------------------------------------------------------------
194 #define DECL_BOOL_PROP3( varname, attrib1, attrib2, attrib3 ) \
195 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 #define END_DESCRIBE_PROPERTIES() \
200 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?"); \
202 //==============================================================================
203 //------------------------------------------------------------------------------
204 #define REGISTER_PROP_1( prop, member, attrib1 ) \
205 registerProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::attrib1, \
206 &member, ::getCppuType( &member ) );
208 #define REGISTER_PROP_2( prop, member, attrib1, attrib2 ) \
209 registerProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::attrib1 | PropertyAttribute::attrib2, \
210 &member, ::getCppuType( &member ) );
212 #define REGISTER_PROP_3( prop, member, attrib1, attrib2, attrib3 ) \
213 registerProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::attrib1 | PropertyAttribute::attrib2 | PropertyAttribute::attrib3, \
214 &member, ::getCppuType( &member ) );
216 //------------------------------------------------------------------------------
217 #define REGISTER_VOID_PROP_1( prop, memberAny, type, attrib1 ) \
218 registerMayBeVoidProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::MAYBEVOID | PropertyAttribute::attrib1, \
219 &memberAny, ::getCppuType( static_cast< type* >( NULL ) ) );
221 #define REGISTER_VOID_PROP_2( prop, memberAny, type, attrib1, attrib2 ) \
222 registerMayBeVoidProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::MAYBEVOID | PropertyAttribute::attrib1 | PropertyAttribute::attrib2, \
223 &memberAny, ::getCppuType( static_cast< type* >( NULL ) ) );
225 //.........................................................................
227 //... namespace frm .......................................................
229 #endif // _FRM_PROPERTY_HXX_
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */