merge the formfield patch from ooo-build
[ooovba.git] / reportdesign / source / ui / inspection / metadata.cxx
blobcad9803c7f42e71ff1c8e5187c8b7f84bcfe98c4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: metadata.cxx,v $
10 * $Revision: 1.9 $
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 ************************************************************************/
30 #include "precompiled_reportdesign.hxx"
31 #include "metadata.hxx"
32 #include <svtools/localresaccess.hxx>
33 #include "com/sun/star/inspection/XPropertyHandler.hpp"
34 #include <tools/debug.hxx>
35 #include <cppuhelper/extract.hxx>
36 #ifndef RTPUI_REPORTDESIGN_HELPID_HRC
37 #include "helpids.hrc"
38 #endif
39 #ifndef _RPTUI_DLGRESID_HRC
40 #include "RptResId.hrc"
41 #endif
42 #ifndef REPORTDESIGN_SHARED_UISTRINGS_HRC
43 #include "uistrings.hrc"
44 #endif
46 #include <functional>
47 #include <algorithm>
49 //............................................................................
50 namespace rptui
52 //............................................................................
54 using namespace ::com::sun::star::uno;
55 using namespace ::com::sun::star;
57 //========================================================================
58 //= OPropertyInfoImpl
59 //========================================================================
60 struct OPropertyInfoImpl
62 String sName;
63 String sTranslation;
64 sal_uInt32 nHelpId;
65 sal_Int32 nId;
66 sal_uInt16 nPos;
67 sal_uInt32 nUIFlags;
69 OPropertyInfoImpl(
70 const ::rtl::OUString& rName,
71 sal_Int32 _nId,
72 const String& aTranslation,
73 sal_uInt16 nPosId,
74 sal_uInt32 nHelpId,
75 sal_uInt32 _nUIFlags);
78 //------------------------------------------------------------------------
79 OPropertyInfoImpl::OPropertyInfoImpl(const ::rtl::OUString& _rName, sal_Int32 _nId,
80 const String& aString, sal_uInt16 nP, sal_uInt32 nHid, sal_uInt32 _nUIFlags)
81 :sName(_rName)
82 ,sTranslation(aString)
83 ,nHelpId(nHid)
84 ,nId(_nId)
85 ,nPos(nP)
86 ,nUIFlags(_nUIFlags)
90 //------------------------------------------------------------------------
91 // Vergleichen von PropertyInfo
92 struct PropertyInfoLessByName : public ::std::binary_function< OPropertyInfoImpl, OPropertyInfoImpl, bool >
94 bool operator()( const OPropertyInfoImpl& _lhs, const OPropertyInfoImpl& _rhs )
96 return _lhs.sName < _rhs.sName;
100 //========================================================================
101 //= OPropertyInfoService
102 //========================================================================
103 #define DEF_INFO( ident, uinameres, helpid, flags ) \
104 OPropertyInfoImpl( PROPERTY_##ident, PROPERTY_ID_##ident, \
105 String( ModuleRes( RID_STR_##uinameres ) ), nPos++, HID_RPT_PROP_##helpid, flags )
107 #define DEF_INFO_1( ident, uinameres, helpid, flag1 ) \
108 DEF_INFO( ident, uinameres, helpid, PROP_FLAG_##flag1 )
110 #define DEF_INFO_2( ident, uinameres, helpid, flag1, flag2 ) \
111 DEF_INFO( ident, uinameres, helpid, PROP_FLAG_##flag1 | PROP_FLAG_##flag2 )
113 #define DEF_INFO_3( ident, uinameres, helpid, flag1, flag2, flag3 ) \
114 DEF_INFO( ident, uinameres, helpid, PROP_FLAG_##flag1 | PROP_FLAG_##flag2 | PROP_FLAG_##flag3 )
116 #define DEF_INFO_4( ident, uinameres, helpid, flag1, flag2, flag3, flag4 ) \
117 DEF_INFO( ident, uinameres, helpid, PROP_FLAG_##flag1 | PROP_FLAG_##flag2 | PROP_FLAG_##flag3 | PROP_FLAG_##flag4 )
119 #define DEF_INFO_5( ident, uinameres, helpid, flag1, flag2, flag3, flag4, flag5 ) \
120 DEF_INFO( ident, uinameres, helpid, PROP_FLAG_##flag1 | PROP_FLAG_##flag2 | PROP_FLAG_##flag3 | PROP_FLAG_##flag4 | PROP_FLAG_##flag5 )
122 sal_uInt16 OPropertyInfoService::s_nCount = 0;
123 OPropertyInfoImpl* OPropertyInfoService::s_pPropertyInfos = NULL;
124 //------------------------------------------------------------------------
125 const OPropertyInfoImpl* OPropertyInfoService::getPropertyInfo()
127 if ( s_pPropertyInfos )
128 return s_pPropertyInfos;
130 OModuleClient aResourceAccess;
131 // this ensures that we have our resource file loaded
133 sal_uInt16 nPos = 1;
134 static OPropertyInfoImpl aPropertyInfos[] =
137 DEF_INFO_?( propname and id, resoure id, help id, flags ),
139 DEF_INFO_1( FORCENEWPAGE, FORCENEWPAGE, FORCENEWPAGE, COMPOSEABLE )
140 ,DEF_INFO_1( NEWROWORCOL, NEWROWORCOL, NEWROWORCOL, COMPOSEABLE )
141 ,DEF_INFO_1( KEEPTOGETHER, KEEPTOGETHER, KEEPTOGETHER, COMPOSEABLE )
142 ,DEF_INFO_1( CANGROW, CANGROW, CANGROW, COMPOSEABLE )
143 ,DEF_INFO_1( CANSHRINK, CANSHRINK, CANSHRINK, COMPOSEABLE )
144 ,DEF_INFO_1( REPEATSECTION, REPEATSECTION, REPEATSECTION, COMPOSEABLE )
145 ,DEF_INFO_1( PRINTREPEATEDVALUES, PRINTREPEATEDVALUES, PRINTREPEATEDVALUES, COMPOSEABLE )
146 ,DEF_INFO_1( CONDITIONALPRINTEXPRESSION, CONDITIONALPRINTEXPRESSION, CONDITIONALPRINTEXPRESSION, COMPOSEABLE )
147 ,DEF_INFO_1( STARTNEWCOLUMN, STARTNEWCOLUMN, STARTNEWCOLUMN, COMPOSEABLE )
148 ,DEF_INFO_1( RESETPAGENUMBER, RESETPAGENUMBER, RESETPAGENUMBER, COMPOSEABLE )
149 ,DEF_INFO_1( PRINTWHENGROUPCHANGE, PRINTWHENGROUPCHANGE, PRINTWHENGROUPCHANGE, COMPOSEABLE )
150 ,DEF_INFO_1( VISIBLE, VISIBLE, VISIBLE, COMPOSEABLE )
151 ,DEF_INFO_1( GROUPKEEPTOGETHER, GROUPKEEPTOGETHER, GROUPKEEPTOGETHER, COMPOSEABLE )
152 ,DEF_INFO_1( PAGEHEADEROPTION, PAGEHEADEROPTION, PAGEHEADEROPTION, COMPOSEABLE )
153 ,DEF_INFO_1( PAGEFOOTEROPTION, PAGEFOOTEROPTION, PAGEFOOTEROPTION, COMPOSEABLE )
154 ,DEF_INFO_1( POSITIONX, POSITIONX, RPT_POSITIONX, COMPOSEABLE )
155 ,DEF_INFO_1( POSITIONY, POSITIONY, RPT_POSITIONY, COMPOSEABLE )
156 ,DEF_INFO_1( WIDTH, WIDTH, RPT_WIDTH, COMPOSEABLE )
157 ,DEF_INFO_1( HEIGHT, HEIGHT, RPT_HEIGHT, COMPOSEABLE )
158 ,DEF_INFO_1( FONT, FONT, RPT_FONT, COMPOSEABLE )
159 ,DEF_INFO_1( PREEVALUATED, PREEVALUATED, PREEVALUATED, COMPOSEABLE )
160 ,DEF_INFO_1( DEEPTRAVERSING, DEEPTRAVERSING, DEEPTRAVERSING, COMPOSEABLE )
161 ,DEF_INFO_1( FORMULA, FORMULA, FORMULA, COMPOSEABLE )
162 ,DEF_INFO_1( INITIALFORMULA, INITIALFORMULA, INITIALFORMULA, COMPOSEABLE )
163 ,DEF_INFO_2( TYPE, TYPE, TYPE, COMPOSEABLE,DATA_PROPERTY )
164 ,DEF_INFO_2( DATAFIELD, DATAFIELD, DATAFIELD, COMPOSEABLE,DATA_PROPERTY )
165 ,DEF_INFO_2( FORMULALIST, FORMULALIST, FORMULALIST, COMPOSEABLE,DATA_PROPERTY )
166 ,DEF_INFO_2( SCOPE, SCOPE, SCOPE, COMPOSEABLE,DATA_PROPERTY )
167 ,DEF_INFO_1( PRESERVEIRI, PRESERVEIRI, PRESERVEIRI, COMPOSEABLE )
168 ,DEF_INFO_1( BACKCOLOR, BACKCOLOR, BACKCOLOR, COMPOSEABLE )
169 ,DEF_INFO_1( CONTROLBACKGROUND, BACKCOLOR, BACKCOLOR, COMPOSEABLE )
170 ,DEF_INFO_1( BACKTRANSPARENT, BACKTRANSPARENT, BACKTRANSPARENT, COMPOSEABLE )
171 ,DEF_INFO_1( CONTROLBACKGROUNDTRANSPARENT, CONTROLBACKGROUNDTRANSPARENT
172 ,CONTROLBACKGROUNDTRANSPARENT, COMPOSEABLE )
173 ,DEF_INFO_1( CHARTTYPE, CHARTTYPE, CHARTTYPE, COMPOSEABLE )
174 ,DEF_INFO_1( PREVIEW_COUNT, PREVIEW_COUNT, PREVIEW_COUNT, COMPOSEABLE )
175 ,DEF_INFO_2( MASTERFIELDS, MASTERFIELDS, MASTERFIELDS, COMPOSEABLE,DATA_PROPERTY )
176 ,DEF_INFO_2( DETAILFIELDS, DETAILFIELDS, DETAILFIELDS, COMPOSEABLE,DATA_PROPERTY)
177 ,DEF_INFO_1( AREA, AREA, AREA, COMPOSEABLE )
178 ,DEF_INFO_2( MIMETYPE, MIMETYPE, MIMETYPE, COMPOSEABLE,DATA_PROPERTY )
179 ,DEF_INFO_1( PARAADJUST, PARAADJUST, PARAADJUST, COMPOSEABLE )
180 ,DEF_INFO_1( VERTICALALIGN, VERTICALALIGN, VERTICALALIGN, COMPOSEABLE )
183 s_pPropertyInfos = aPropertyInfos;
184 s_nCount = sizeof(aPropertyInfos) / sizeof(OPropertyInfoImpl);
186 ::std::sort( aPropertyInfos, aPropertyInfos + s_nCount, PropertyInfoLessByName() );
188 return s_pPropertyInfos;
191 //------------------------------------------------------------------------
192 sal_Int32 OPropertyInfoService::getPropertyId(const String& _rName) const
194 const OPropertyInfoImpl* pInfo = getPropertyInfo(_rName);
195 return pInfo ? pInfo->nId : -1;
198 //------------------------------------------------------------------------
199 String OPropertyInfoService::getPropertyTranslation(sal_Int32 _nId) const
201 const OPropertyInfoImpl* pInfo = getPropertyInfo(_nId);
202 return (pInfo) ? pInfo->sTranslation : String();
205 //------------------------------------------------------------------------
206 sal_Int32 OPropertyInfoService::getPropertyHelpId(sal_Int32 _nId) const
208 const OPropertyInfoImpl* pInfo = getPropertyInfo(_nId);
209 return (pInfo) ? pInfo->nHelpId : 0;
212 //------------------------------------------------------------------------
213 sal_uInt32 OPropertyInfoService::getPropertyUIFlags(sal_Int32 _nId) const
215 const OPropertyInfoImpl* pInfo = getPropertyInfo(_nId);
216 return (pInfo) ? pInfo->nUIFlags : 0;
219 //------------------------------------------------------------------------
220 const OPropertyInfoImpl* OPropertyInfoService::getPropertyInfo(const String& _rName)
222 // intialisierung
223 if(!s_pPropertyInfos)
224 getPropertyInfo();
225 OPropertyInfoImpl aSearch(_rName, 0L, String(), 0, 0, 0);
227 const OPropertyInfoImpl* pPropInfo = ::std::lower_bound(
228 s_pPropertyInfos, s_pPropertyInfos + s_nCount, aSearch, PropertyInfoLessByName() );
230 if ( ( pPropInfo < s_pPropertyInfos + s_nCount ) && pPropInfo->sName == _rName )
231 return pPropInfo;
233 return NULL;
237 //------------------------------------------------------------------------
238 const OPropertyInfoImpl* OPropertyInfoService::getPropertyInfo(sal_Int32 _nId)
240 // intialisierung
241 if(!s_pPropertyInfos)
242 getPropertyInfo();
244 // TODO: a real structure which allows quick access by name as well as by id
245 for (sal_uInt16 i = 0; i < s_nCount; i++)
246 if (s_pPropertyInfos[i].nId == _nId)
247 return &s_pPropertyInfos[i];
249 return NULL;
252 //------------------------------------------------------------------------
253 bool OPropertyInfoService::isComposable( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler >& _rxFormComponentHandler )
255 sal_Int32 nId = getPropertyId( _rPropertyName );
256 if ( nId != -1 )
258 sal_uInt32 nFlags = getPropertyUIFlags( nId );
259 return ( nFlags & PROP_FLAG_COMPOSEABLE ) != 0;
262 return _rxFormComponentHandler->isComposable( _rPropertyName );
265 //------------------------------------------------------------------------
266 void OPropertyInfoService::getExcludeProperties(::std::vector< beans::Property >& _rExcludeProperties,const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler >& _xFormComponentHandler)
268 uno::Sequence< beans::Property > aProps = _xFormComponentHandler->getSupportedProperties();
269 static const ::rtl::OUString pExcludeProperties[] =
271 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Enabled")),
272 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Printable")),
273 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WordBreak")),
274 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MultiLine")),
275 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tag")),
276 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HelpText")),
277 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HelpURL")),
278 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MaxTextLen")),
279 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReadOnly")),
280 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tabstop")),
281 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TabIndex")),
282 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ValueMin")),
283 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ValueMax")),
284 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Spin")),
285 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SpinValue")),
286 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SpinValueMin")),
287 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SpinValueMax")),
288 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultSpinValue")),
289 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SpinIncrement")),
290 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Repeat")),
291 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RepeatDelay")),
292 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlLabel")), /// TODO: has to be checked
293 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LabelControl")),
294 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title")), // comment this out if you want to have title feature for charts
295 PROPERTY_MAXTEXTLEN,
296 PROPERTY_EFFECTIVEDEFAULT,
297 PROPERTY_EFFECTIVEMAX,
298 PROPERTY_EFFECTIVEMIN,
299 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HideInactiveSelection")),
300 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SubmitAction")),
301 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("InputRequired")),
302 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VerticalAlign")),
303 PROPERTY_ALIGN,
304 PROPERTY_EMPTY_IS_NULL,
305 PROPERTY_FILTERPROPOSAL
306 ,PROPERTY_POSITIONX
307 ,PROPERTY_POSITIONY
308 ,PROPERTY_WIDTH
309 ,PROPERTY_HEIGHT
310 ,PROPERTY_FONT
311 ,PROPERTY_LABEL
312 ,PROPERTY_LINECOLOR
313 ,PROPERTY_BORDER
314 ,PROPERTY_BORDERCOLOR
315 ,PROPERTY_BACKTRANSPARENT
316 ,PROPERTY_CONTROLBACKGROUND
317 ,PROPERTY_BACKGROUNDCOLOR
318 ,PROPERTY_CONTROLBACKGROUNDTRANSPARENT
319 ,PROPERTY_FORMULALIST
320 ,PROPERTY_SCOPE
321 ,PROPERTY_TYPE
322 ,PROPERTY_DATASOURCENAME
323 ,PROPERTY_VERTICALALIGN
326 beans::Property* pPropsIter = aProps.getArray();
327 beans::Property* pPropsEnd = pPropsIter + aProps.getLength();
328 for (; pPropsIter != pPropsEnd; ++pPropsIter)
330 size_t nPos = 0;
331 for (; nPos < sizeof(pExcludeProperties)/sizeof(pExcludeProperties[0]) && pExcludeProperties[nPos] != pPropsIter->Name;++nPos )
333 if ( nPos == sizeof(pExcludeProperties)/sizeof(pExcludeProperties[0]) )
334 _rExcludeProperties.push_back(*pPropsIter);
339 //............................................................................
340 } // namespace pcr
341 //............................................................................