sync master with lastest vba changes
[ooovba.git] / reportdesign / source / ui / inspection / metadata.cxx
blob5b00dec804fac21f9cf588b011b5fed156c622e0
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;
135 static OPropertyInfoImpl aPropertyInfos[] =
138 DEF_INFO_?( propname and id, resoure id, help id, flags ),
140 DEF_INFO_1( FORCENEWPAGE, FORCENEWPAGE, FORCENEWPAGE, COMPOSEABLE )
141 ,DEF_INFO_1( NEWROWORCOL, NEWROWORCOL, NEWROWORCOL, COMPOSEABLE )
142 ,DEF_INFO_1( KEEPTOGETHER, KEEPTOGETHER, KEEPTOGETHER, COMPOSEABLE )
143 ,DEF_INFO_1( CANGROW, CANGROW, CANGROW, COMPOSEABLE )
144 ,DEF_INFO_1( CANSHRINK, CANSHRINK, CANSHRINK, COMPOSEABLE )
145 ,DEF_INFO_1( REPEATSECTION, REPEATSECTION, REPEATSECTION, COMPOSEABLE )
146 ,DEF_INFO_1( PRINTREPEATEDVALUES, PRINTREPEATEDVALUES, PRINTREPEATEDVALUES, COMPOSEABLE )
147 ,DEF_INFO_1( CONDITIONALPRINTEXPRESSION, CONDITIONALPRINTEXPRESSION, CONDITIONALPRINTEXPRESSION, COMPOSEABLE )
148 ,DEF_INFO_1( STARTNEWCOLUMN, STARTNEWCOLUMN, STARTNEWCOLUMN, COMPOSEABLE )
149 ,DEF_INFO_1( RESETPAGENUMBER, RESETPAGENUMBER, RESETPAGENUMBER, COMPOSEABLE )
150 ,DEF_INFO_1( PRINTWHENGROUPCHANGE, PRINTWHENGROUPCHANGE, PRINTWHENGROUPCHANGE, COMPOSEABLE )
151 ,DEF_INFO_1( VISIBLE, VISIBLE, VISIBLE, COMPOSEABLE )
152 ,DEF_INFO_1( GROUPKEEPTOGETHER, GROUPKEEPTOGETHER, GROUPKEEPTOGETHER, COMPOSEABLE )
153 ,DEF_INFO_1( PAGEHEADEROPTION, PAGEHEADEROPTION, PAGEHEADEROPTION, COMPOSEABLE )
154 ,DEF_INFO_1( PAGEFOOTEROPTION, PAGEFOOTEROPTION, PAGEFOOTEROPTION, COMPOSEABLE )
155 ,DEF_INFO_1( POSITIONX, POSITIONX, RPT_POSITIONX, COMPOSEABLE )
156 ,DEF_INFO_1( POSITIONY, POSITIONY, RPT_POSITIONY, COMPOSEABLE )
157 ,DEF_INFO_1( WIDTH, WIDTH, RPT_WIDTH, COMPOSEABLE )
158 ,DEF_INFO_1( HEIGHT, HEIGHT, RPT_HEIGHT, COMPOSEABLE )
159 ,DEF_INFO_1( CHARFONTNAME, FONT, RPT_FONT, COMPOSEABLE )
160 ,DEF_INFO_1( PREEVALUATED, PREEVALUATED, PREEVALUATED, COMPOSEABLE )
161 ,DEF_INFO_1( DEEPTRAVERSING, DEEPTRAVERSING, DEEPTRAVERSING, COMPOSEABLE )
162 ,DEF_INFO_1( FORMULA, FORMULA, FORMULA, COMPOSEABLE )
163 ,DEF_INFO_1( INITIALFORMULA, INITIALFORMULA, INITIALFORMULA, COMPOSEABLE )
164 ,DEF_INFO_2( TYPE, TYPE, TYPE, COMPOSEABLE,DATA_PROPERTY )
165 ,DEF_INFO_2( DATAFIELD, DATAFIELD, DATAFIELD, COMPOSEABLE,DATA_PROPERTY )
166 ,DEF_INFO_2( FORMULALIST, FORMULALIST, FORMULALIST, COMPOSEABLE,DATA_PROPERTY )
167 ,DEF_INFO_2( SCOPE, SCOPE, SCOPE, COMPOSEABLE,DATA_PROPERTY )
168 ,DEF_INFO_1( PRESERVEIRI, PRESERVEIRI, PRESERVEIRI, COMPOSEABLE )
169 ,DEF_INFO_1( BACKCOLOR, BACKCOLOR, BACKCOLOR, COMPOSEABLE )
170 ,DEF_INFO_1( CONTROLBACKGROUND, BACKCOLOR, BACKCOLOR, COMPOSEABLE )
171 ,DEF_INFO_1( BACKTRANSPARENT, BACKTRANSPARENT, BACKTRANSPARENT, COMPOSEABLE )
172 ,DEF_INFO_1( CONTROLBACKGROUNDTRANSPARENT, CONTROLBACKGROUNDTRANSPARENT
173 ,CONTROLBACKGROUNDTRANSPARENT, COMPOSEABLE )
174 ,DEF_INFO_1( CHARTTYPE, CHARTTYPE, CHARTTYPE, COMPOSEABLE )
175 ,DEF_INFO_1( PREVIEW_COUNT, PREVIEW_COUNT, PREVIEW_COUNT, COMPOSEABLE )
176 ,DEF_INFO_2( MASTERFIELDS, MASTERFIELDS, MASTERFIELDS, COMPOSEABLE,DATA_PROPERTY )
177 ,DEF_INFO_2( DETAILFIELDS, DETAILFIELDS, DETAILFIELDS, COMPOSEABLE,DATA_PROPERTY)
178 ,DEF_INFO_1( AREA, AREA, AREA, COMPOSEABLE )
179 ,DEF_INFO_2( MIMETYPE, MIMETYPE, MIMETYPE, COMPOSEABLE,DATA_PROPERTY )
182 s_pPropertyInfos = aPropertyInfos;
183 s_nCount = sizeof(aPropertyInfos) / sizeof(OPropertyInfoImpl);
185 ::std::sort( aPropertyInfos, aPropertyInfos + s_nCount, PropertyInfoLessByName() );
187 return s_pPropertyInfos;
190 //------------------------------------------------------------------------
191 sal_Int32 OPropertyInfoService::getPropertyId(const String& _rName) const
193 const OPropertyInfoImpl* pInfo = getPropertyInfo(_rName);
194 return pInfo ? pInfo->nId : -1;
197 //------------------------------------------------------------------------
198 String OPropertyInfoService::getPropertyTranslation(sal_Int32 _nId) const
200 const OPropertyInfoImpl* pInfo = getPropertyInfo(_nId);
201 return (pInfo) ? pInfo->sTranslation : String();
204 //------------------------------------------------------------------------
205 sal_Int32 OPropertyInfoService::getPropertyHelpId(sal_Int32 _nId) const
207 const OPropertyInfoImpl* pInfo = getPropertyInfo(_nId);
208 return (pInfo) ? pInfo->nHelpId : 0;
211 //------------------------------------------------------------------------
212 sal_uInt32 OPropertyInfoService::getPropertyUIFlags(sal_Int32 _nId) const
214 const OPropertyInfoImpl* pInfo = getPropertyInfo(_nId);
215 return (pInfo) ? pInfo->nUIFlags : 0;
218 //------------------------------------------------------------------------
219 const OPropertyInfoImpl* OPropertyInfoService::getPropertyInfo(const String& _rName)
221 // intialisierung
222 if(!s_pPropertyInfos)
223 getPropertyInfo();
224 OPropertyInfoImpl aSearch(_rName, 0L, String(), 0, 0, 0);
226 const OPropertyInfoImpl* pPropInfo = ::std::lower_bound(
227 s_pPropertyInfos, s_pPropertyInfos + s_nCount, aSearch, PropertyInfoLessByName() );
229 if ( ( pPropInfo < s_pPropertyInfos + s_nCount ) && pPropInfo->sName == _rName )
230 return pPropInfo;
232 return NULL;
236 //------------------------------------------------------------------------
237 const OPropertyInfoImpl* OPropertyInfoService::getPropertyInfo(sal_Int32 _nId)
239 // intialisierung
240 if(!s_pPropertyInfos)
241 getPropertyInfo();
243 // TODO: a real structure which allows quick access by name as well as by id
244 for (sal_uInt16 i = 0; i < s_nCount; i++)
245 if (s_pPropertyInfos[i].nId == _nId)
246 return &s_pPropertyInfos[i];
248 return NULL;
251 //------------------------------------------------------------------------
252 bool OPropertyInfoService::isComposable( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler >& _rxFormComponentHandler )
254 sal_Int32 nId = getPropertyId( _rPropertyName );
255 if ( nId != -1 )
257 sal_uInt32 nFlags = getPropertyUIFlags( nId );
258 return ( nFlags & PROP_FLAG_COMPOSEABLE ) != 0;
261 return _rxFormComponentHandler->isComposable( _rPropertyName );
264 //------------------------------------------------------------------------
265 void OPropertyInfoService::getExcludeProperties(::std::vector< beans::Property >& _rExcludeProperties,const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler >& _xFormComponentHandler)
267 uno::Sequence< beans::Property > aProps = _xFormComponentHandler->getSupportedProperties();
268 static const ::rtl::OUString pExcludeProperties[] =
270 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Enabled")),
271 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Printable")),
272 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WordBreak")),
273 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MultiLine")),
274 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tag")),
275 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HelpText")),
276 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HelpURL")),
277 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MaxTextLen")),
278 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReadOnly")),
279 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tabstop")),
280 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TabIndex")),
281 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ValueMin")),
282 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ValueMax")),
283 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Spin")),
284 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SpinValue")),
285 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SpinValueMin")),
286 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SpinValueMax")),
287 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultSpinValue")),
288 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SpinIncrement")),
289 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Repeat")),
290 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RepeatDelay")),
291 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlLabel")), /// TODO: has to be checked
292 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LabelControl")),
293 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title")), // comment this out if you want to have title feature for charts
294 PROPERTY_MAXTEXTLEN,
295 PROPERTY_EFFECTIVEDEFAULT,
296 PROPERTY_EFFECTIVEMAX,
297 PROPERTY_EFFECTIVEMIN,
298 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HideInactiveSelection")),
299 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SubmitAction")),
300 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("InputRequired")),
301 PROPERTY_EMPTY_IS_NULL,
302 PROPERTY_FILTERPROPOSAL
303 ,PROPERTY_POSITIONX
304 ,PROPERTY_POSITIONY
305 ,PROPERTY_WIDTH
306 ,PROPERTY_HEIGHT
307 ,PROPERTY_FONTNAME
308 ,PROPERTY_LABEL
309 ,PROPERTY_LINECOLOR
310 ,PROPERTY_BORDER
311 ,PROPERTY_BORDERCOLOR
312 ,PROPERTY_BACKTRANSPARENT
313 ,PROPERTY_CONTROLBACKGROUND
314 ,PROPERTY_BACKGROUNDCOLOR
315 ,PROPERTY_CONTROLBACKGROUNDTRANSPARENT
316 ,PROPERTY_FORMULALIST
317 ,PROPERTY_SCOPE
318 ,PROPERTY_TYPE
319 ,PROPERTY_DATASOURCENAME
322 beans::Property* pPropsIter = aProps.getArray();
323 beans::Property* pPropsEnd = pPropsIter + aProps.getLength();
324 for (; pPropsIter != pPropsEnd; ++pPropsIter)
326 size_t nPos = 0;
327 for (; nPos < sizeof(pExcludeProperties)/sizeof(pExcludeProperties[0]) && pExcludeProperties[nPos] != pPropsIter->Name;++nPos )
329 if ( nPos == sizeof(pExcludeProperties)/sizeof(pExcludeProperties[0]) )
330 _rExcludeProperties.push_back(*pPropsIter);
335 //............................................................................
336 } // namespace pcr
337 //............................................................................