1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #include "precompiled_reportdesign.hxx" 28 #include "metadata.hxx" 29 #include <svtools/localresaccess.hxx> 30 #include "com/sun/star/inspection/XPropertyHandler.hpp" 31 #include <tools/debug.hxx> 32 #include <comphelper/extract.hxx> 33 #ifndef RTPUI_REPORTDESIGN_HELPID_HRC 34 #include "helpids.hrc" 35 #endif 36 #ifndef _RPTUI_DLGRESID_HRC 37 #include "RptResId.hrc" 38 #endif 39 #ifndef REPORTDESIGN_SHARED_UISTRINGS_HRC 40 #include "uistrings.hrc" 41 #endif 42 43 #include <functional> 44 #include <algorithm> 45 46 //............................................................................ 47 namespace rptui 48 { 49 //............................................................................ 50 51 using namespace ::com::sun::star::uno; 52 using namespace ::com::sun::star; 53 54 //======================================================================== 55 //= OPropertyInfoImpl 56 //======================================================================== 57 struct OPropertyInfoImpl 58 { 59 String sName; 60 String sTranslation; 61 rtl::OString sHelpId; 62 sal_Int32 nId; 63 sal_uInt16 nPos; 64 sal_uInt32 nUIFlags; 65 66 OPropertyInfoImpl( 67 const ::rtl::OUString& rName, 68 sal_Int32 _nId, 69 const String& aTranslation, 70 sal_uInt16 nPosId, 71 const rtl::OString& _sHelpId, 72 sal_uInt32 _nUIFlags); 73 }; 74 75 //------------------------------------------------------------------------ 76 OPropertyInfoImpl::OPropertyInfoImpl(const ::rtl::OUString& _rName, sal_Int32 _nId, 77 const String& aString, sal_uInt16 nP, const rtl::OString& sHid, sal_uInt32 _nUIFlags) 78 :sName(_rName) 79 ,sTranslation(aString) 80 ,sHelpId(sHid) 81 ,nId(_nId) 82 ,nPos(nP) 83 ,nUIFlags(_nUIFlags) 84 { 85 } 86 87 //------------------------------------------------------------------------ 88 // Vergleichen von PropertyInfo 89 struct PropertyInfoLessByName : public ::std::binary_function< OPropertyInfoImpl, OPropertyInfoImpl, bool > 90 { 91 bool operator()( const OPropertyInfoImpl& _lhs, const OPropertyInfoImpl& _rhs ) 92 { 93 return _lhs.sName < _rhs.sName; 94 } 95 }; 96 97 //======================================================================== 98 //= OPropertyInfoService 99 //======================================================================== 100 #define DEF_INFO( ident, uinameres, helpid, flags ) \ 101 OPropertyInfoImpl( PROPERTY_##ident, PROPERTY_ID_##ident, \ 102 String( ModuleRes( RID_STR_##uinameres ) ), nPos++, HID_RPT_PROP_##helpid, flags ) 103 104 #define DEF_INFO_1( ident, uinameres, helpid, flag1 ) \ 105 DEF_INFO( ident, uinameres, helpid, PROP_FLAG_##flag1 ) 106 107 #define DEF_INFO_2( ident, uinameres, helpid, flag1, flag2 ) \ 108 DEF_INFO( ident, uinameres, helpid, PROP_FLAG_##flag1 | PROP_FLAG_##flag2 ) 109 110 #define DEF_INFO_3( ident, uinameres, helpid, flag1, flag2, flag3 ) \ 111 DEF_INFO( ident, uinameres, helpid, PROP_FLAG_##flag1 | PROP_FLAG_##flag2 | PROP_FLAG_##flag3 ) 112 113 #define DEF_INFO_4( ident, uinameres, helpid, flag1, flag2, flag3, flag4 ) \ 114 DEF_INFO( ident, uinameres, helpid, PROP_FLAG_##flag1 | PROP_FLAG_##flag2 | PROP_FLAG_##flag3 | PROP_FLAG_##flag4 ) 115 116 #define DEF_INFO_5( ident, uinameres, helpid, flag1, flag2, flag3, flag4, flag5 ) \ 117 DEF_INFO( ident, uinameres, helpid, PROP_FLAG_##flag1 | PROP_FLAG_##flag2 | PROP_FLAG_##flag3 | PROP_FLAG_##flag4 | PROP_FLAG_##flag5 ) 118 119 sal_uInt16 OPropertyInfoService::s_nCount = 0; 120 OPropertyInfoImpl* OPropertyInfoService::s_pPropertyInfos = NULL; 121 //------------------------------------------------------------------------ 122 const OPropertyInfoImpl* OPropertyInfoService::getPropertyInfo() 123 { 124 if ( s_pPropertyInfos ) 125 return s_pPropertyInfos; 126 127 OModuleClient aResourceAccess; 128 // this ensures that we have our resource file loaded 129 130 sal_uInt16 nPos = 1; 131 static OPropertyInfoImpl aPropertyInfos[] = 132 { 133 /* 134 DEF_INFO_?( propname and id, resoure id, help id, flags ), 135 */ 136 DEF_INFO_1( FORCENEWPAGE, FORCENEWPAGE, FORCENEWPAGE, COMPOSEABLE ) 137 ,DEF_INFO_1( NEWROWORCOL, NEWROWORCOL, NEWROWORCOL, COMPOSEABLE ) 138 ,DEF_INFO_1( KEEPTOGETHER, KEEPTOGETHER, KEEPTOGETHER, COMPOSEABLE ) 139 ,DEF_INFO_1( CANGROW, CANGROW, CANGROW, COMPOSEABLE ) 140 ,DEF_INFO_1( CANSHRINK, CANSHRINK, CANSHRINK, COMPOSEABLE ) 141 ,DEF_INFO_1( REPEATSECTION, REPEATSECTION, REPEATSECTION, COMPOSEABLE ) 142 ,DEF_INFO_1( PRINTREPEATEDVALUES, PRINTREPEATEDVALUES, PRINTREPEATEDVALUES, COMPOSEABLE ) 143 ,DEF_INFO_1( CONDITIONALPRINTEXPRESSION, CONDITIONALPRINTEXPRESSION, CONDITIONALPRINTEXPRESSION, COMPOSEABLE ) 144 ,DEF_INFO_1( STARTNEWCOLUMN, STARTNEWCOLUMN, STARTNEWCOLUMN, COMPOSEABLE ) 145 ,DEF_INFO_1( RESETPAGENUMBER, RESETPAGENUMBER, RESETPAGENUMBER, COMPOSEABLE ) 146 ,DEF_INFO_1( PRINTWHENGROUPCHANGE, PRINTWHENGROUPCHANGE, PRINTWHENGROUPCHANGE, COMPOSEABLE ) 147 ,DEF_INFO_1( VISIBLE, VISIBLE, VISIBLE, COMPOSEABLE ) 148 ,DEF_INFO_1( GROUPKEEPTOGETHER, GROUPKEEPTOGETHER, GROUPKEEPTOGETHER, COMPOSEABLE ) 149 ,DEF_INFO_1( PAGEHEADEROPTION, PAGEHEADEROPTION, PAGEHEADEROPTION, COMPOSEABLE ) 150 ,DEF_INFO_1( PAGEFOOTEROPTION, PAGEFOOTEROPTION, PAGEFOOTEROPTION, COMPOSEABLE ) 151 ,DEF_INFO_1( POSITIONX, POSITIONX, RPT_POSITIONX, COMPOSEABLE ) 152 ,DEF_INFO_1( POSITIONY, POSITIONY, RPT_POSITIONY, COMPOSEABLE ) 153 ,DEF_INFO_1( WIDTH, WIDTH, RPT_WIDTH, COMPOSEABLE ) 154 ,DEF_INFO_1( HEIGHT, HEIGHT, RPT_HEIGHT, COMPOSEABLE ) 155 ,DEF_INFO_1( FONT, FONT, RPT_FONT, COMPOSEABLE ) 156 ,DEF_INFO_1( PREEVALUATED, PREEVALUATED, PREEVALUATED, COMPOSEABLE ) 157 ,DEF_INFO_1( DEEPTRAVERSING, DEEPTRAVERSING, DEEPTRAVERSING, COMPOSEABLE ) 158 ,DEF_INFO_1( FORMULA, FORMULA, FORMULA, COMPOSEABLE ) 159 ,DEF_INFO_1( INITIALFORMULA, INITIALFORMULA, INITIALFORMULA, COMPOSEABLE ) 160 ,DEF_INFO_2( TYPE, TYPE, TYPE, COMPOSEABLE,DATA_PROPERTY ) 161 ,DEF_INFO_2( DATAFIELD, DATAFIELD, DATAFIELD, COMPOSEABLE,DATA_PROPERTY ) 162 ,DEF_INFO_2( FORMULALIST, FORMULALIST, FORMULALIST, COMPOSEABLE,DATA_PROPERTY ) 163 ,DEF_INFO_2( SCOPE, SCOPE, SCOPE, COMPOSEABLE,DATA_PROPERTY ) 164 ,DEF_INFO_1( PRESERVEIRI, PRESERVEIRI, PRESERVEIRI, COMPOSEABLE ) 165 ,DEF_INFO_1( BACKCOLOR, BACKCOLOR, BACKCOLOR, COMPOSEABLE ) 166 ,DEF_INFO_1( CONTROLBACKGROUND, BACKCOLOR, BACKCOLOR, COMPOSEABLE ) 167 ,DEF_INFO_1( BACKTRANSPARENT, BACKTRANSPARENT, BACKTRANSPARENT, COMPOSEABLE ) 168 ,DEF_INFO_1( CONTROLBACKGROUNDTRANSPARENT, CONTROLBACKGROUNDTRANSPARENT 169 ,CONTROLBACKGROUNDTRANSPARENT, COMPOSEABLE ) 170 ,DEF_INFO_1( CHARTTYPE, CHARTTYPE, CHARTTYPE, COMPOSEABLE ) 171 ,DEF_INFO_1( PREVIEW_COUNT, PREVIEW_COUNT, PREVIEW_COUNT, COMPOSEABLE ) 172 ,DEF_INFO_2( MASTERFIELDS, MASTERFIELDS, MASTERFIELDS, COMPOSEABLE,DATA_PROPERTY ) 173 ,DEF_INFO_2( DETAILFIELDS, DETAILFIELDS, DETAILFIELDS, COMPOSEABLE,DATA_PROPERTY) 174 ,DEF_INFO_1( AREA, AREA, AREA, COMPOSEABLE ) 175 ,DEF_INFO_2( MIMETYPE, MIMETYPE, MIMETYPE, COMPOSEABLE,DATA_PROPERTY ) 176 ,DEF_INFO_1( PARAADJUST, PARAADJUST, PARAADJUST, COMPOSEABLE ) 177 ,DEF_INFO_1( VERTICALALIGN, VERTICALALIGN, VERTICALALIGN, COMPOSEABLE ) 178 }; 179 180 s_pPropertyInfos = aPropertyInfos; 181 s_nCount = sizeof(aPropertyInfos) / sizeof(OPropertyInfoImpl); 182 183 ::std::sort( aPropertyInfos, aPropertyInfos + s_nCount, PropertyInfoLessByName() ); 184 185 return s_pPropertyInfos; 186 } 187 188 //------------------------------------------------------------------------ 189 sal_Int32 OPropertyInfoService::getPropertyId(const String& _rName) const 190 { 191 const OPropertyInfoImpl* pInfo = getPropertyInfo(_rName); 192 return pInfo ? pInfo->nId : -1; 193 } 194 195 //------------------------------------------------------------------------ 196 String OPropertyInfoService::getPropertyTranslation(sal_Int32 _nId) const 197 { 198 const OPropertyInfoImpl* pInfo = getPropertyInfo(_nId); 199 return (pInfo) ? pInfo->sTranslation : String(); 200 } 201 202 //------------------------------------------------------------------------ 203 rtl::OString OPropertyInfoService::getPropertyHelpId(sal_Int32 _nId) const 204 { 205 const OPropertyInfoImpl* pInfo = getPropertyInfo(_nId); 206 return (pInfo) ? pInfo->sHelpId : rtl::OString(); 207 } 208 209 //------------------------------------------------------------------------ 210 sal_uInt32 OPropertyInfoService::getPropertyUIFlags(sal_Int32 _nId) const 211 { 212 const OPropertyInfoImpl* pInfo = getPropertyInfo(_nId); 213 return (pInfo) ? pInfo->nUIFlags : 0; 214 } 215 216 //------------------------------------------------------------------------ 217 const OPropertyInfoImpl* OPropertyInfoService::getPropertyInfo(const String& _rName) 218 { 219 // intialisierung 220 if(!s_pPropertyInfos) 221 getPropertyInfo(); 222 OPropertyInfoImpl aSearch(_rName, 0L, String(), 0, "", 0); 223 224 const OPropertyInfoImpl* pPropInfo = ::std::lower_bound( 225 s_pPropertyInfos, s_pPropertyInfos + s_nCount, aSearch, PropertyInfoLessByName() ); 226 227 if ( ( pPropInfo < s_pPropertyInfos + s_nCount ) && pPropInfo->sName == _rName ) 228 return pPropInfo; 229 230 return NULL; 231 } 232 233 234 //------------------------------------------------------------------------ 235 const OPropertyInfoImpl* OPropertyInfoService::getPropertyInfo(sal_Int32 _nId) 236 { 237 // intialisierung 238 if(!s_pPropertyInfos) 239 getPropertyInfo(); 240 241 // TODO: a real structure which allows quick access by name as well as by id 242 for (sal_uInt16 i = 0; i < s_nCount; i++) 243 if (s_pPropertyInfos[i].nId == _nId) 244 return &s_pPropertyInfos[i]; 245 246 return NULL; 247 } 248 249 //------------------------------------------------------------------------ 250 bool OPropertyInfoService::isComposable( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler >& _rxFormComponentHandler ) 251 { 252 sal_Int32 nId = getPropertyId( _rPropertyName ); 253 if ( nId != -1 ) 254 { 255 sal_uInt32 nFlags = getPropertyUIFlags( nId ); 256 return ( nFlags & PROP_FLAG_COMPOSEABLE ) != 0; 257 } 258 259 return _rxFormComponentHandler->isComposable( _rPropertyName ); 260 } 261 262 //------------------------------------------------------------------------ 263 void OPropertyInfoService::getExcludeProperties(::std::vector< beans::Property >& _rExcludeProperties,const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler >& _xFormComponentHandler) 264 { 265 uno::Sequence< beans::Property > aProps = _xFormComponentHandler->getSupportedProperties(); 266 static const ::rtl::OUString pExcludeProperties[] = 267 { 268 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Enabled")), 269 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Printable")), 270 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WordBreak")), 271 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MultiLine")), 272 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tag")), 273 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HelpText")), 274 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HelpURL")), 275 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MaxTextLen")), 276 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReadOnly")), 277 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tabstop")), 278 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TabIndex")), 279 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ValueMin")), 280 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ValueMax")), 281 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Spin")), 282 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SpinValue")), 283 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SpinValueMin")), 284 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SpinValueMax")), 285 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultSpinValue")), 286 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SpinIncrement")), 287 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Repeat")), 288 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RepeatDelay")), 289 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlLabel")), /// TODO: has to be checked 290 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LabelControl")), 291 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title")), // comment this out if you want to have title feature for charts 292 PROPERTY_MAXTEXTLEN, 293 PROPERTY_EFFECTIVEDEFAULT, 294 PROPERTY_EFFECTIVEMAX, 295 PROPERTY_EFFECTIVEMIN, 296 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HideInactiveSelection")), 297 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SubmitAction")), 298 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("InputRequired")), 299 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VerticalAlign")), 300 PROPERTY_ALIGN, 301 PROPERTY_EMPTY_IS_NULL, 302 PROPERTY_FILTERPROPOSAL 303 ,PROPERTY_POSITIONX 304 ,PROPERTY_POSITIONY 305 ,PROPERTY_WIDTH 306 ,PROPERTY_HEIGHT 307 ,PROPERTY_FONT 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 320 ,PROPERTY_VERTICALALIGN 321 }; 322 323 beans::Property* pPropsIter = aProps.getArray(); 324 beans::Property* pPropsEnd = pPropsIter + aProps.getLength(); 325 for (; pPropsIter != pPropsEnd; ++pPropsIter) 326 { 327 size_t nPos = 0; 328 for (; nPos < sizeof(pExcludeProperties)/sizeof(pExcludeProperties[0]) && pExcludeProperties[nPos] != pPropsIter->Name;++nPos ) 329 ; 330 if ( nPos == sizeof(pExcludeProperties)/sizeof(pExcludeProperties[0]) ) 331 _rExcludeProperties.push_back(*pPropsIter); 332 } 333 } 334 335 336 //............................................................................ 337 } // namespace pcr 338 //............................................................................ 339 340