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 "GeometryHandler.hxx" 29 30 #include <comphelper/sequence.hxx> 31 #include <comphelper/types.hxx> 32 #include <comphelper/property.hxx> 33 #include <comphelper/mimeconfighelper.hxx> 34 35 #include "uistrings.hrc" 36 #include "reportformula.hxx" 37 38 #include <unotools/textsearch.hxx> 39 #include <unotools/configmgr.hxx> 40 41 #include <toolkit/helper/vclunohelper.hxx> 42 #include <unotools/syslocale.hxx> 43 #include <tools/diagnose_ex.h> 44 #include <tools/StringListResource.hxx> 45 #include <com/sun/star/lang/XInitialization.hpp> 46 #include "com/sun/star/inspection/StringRepresentation.hpp" 47 #include <com/sun/star/inspection/PropertyLineElement.hpp> 48 #include <com/sun/star/inspection/PropertyControlType.hpp> 49 #include <com/sun/star/inspection/XStringListControl.hpp> 50 #include <com/sun/star/report/Function.hpp> 51 #include <com/sun/star/report/XReportDefinition.hpp> 52 #include <com/sun/star/report/XShape.hpp> 53 #include <com/sun/star/report/XSection.hpp> 54 #include <com/sun/star/report/XFormattedField.hpp> 55 #include <com/sun/star/report/XFixedLine.hpp> 56 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp> 57 #include <com/sun/star/sdb/CommandType.hpp> 58 #include <com/sun/star/sdb/SQLContext.hpp> 59 #include <com/sun/star/sdbc/XConnection.hpp> 60 #include <com/sun/star/util/SearchOptions.hpp> 61 #include <com/sun/star/util/MeasureUnit.hpp> 62 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 63 #include <com/sun/star/container/XNameContainer.hpp> 64 #include <com/sun/star/inspection/XNumericControl.hpp> 65 #include <com/sun/star/style/ParagraphAdjust.hpp> 66 67 #include <vcl/msgbox.hxx> 68 #include <vcl/waitobj.hxx> 69 #include <tools/fldunit.hxx> 70 #include <vcl/stdtext.hxx> 71 72 #include "ModuleHelper.hxx" 73 #include "RptResId.hrc" 74 #include "RptDef.hxx" 75 #include "UITools.hxx" 76 77 #include <connectivity/dbexception.hxx> 78 #include <connectivity/dbconversion.hxx> 79 #include <connectivity/dbtools.hxx> 80 81 #include <boost/bind.hpp> 82 #include <tools/string.hxx> 83 #include "metadata.hxx" 84 #include <svl/itempool.hxx> 85 #include <svl/itemset.hxx> 86 87 #define ITEMID_COLOR_TABLE SID_COLOR_TABLE 88 #define ITEMID_DASH_LIST SID_DASH_LIST 89 #define ITEMID_LINEEND_LIST SID_LINEEND_LIST 90 #include <svx/xdef.hxx> 91 #include <svx/xpool.hxx> 92 #include <svx/xtable.hxx> 93 #include <svx/xlnwtit.hxx> 94 #include <svx/xlntrit.hxx> 95 #include <svx/xlnclit.hxx> 96 #include <svx/xlnstit.hxx> 97 #include <svx/xlnedit.hxx> 98 #include <svx/xlnstwit.hxx> 99 #include <svx/xlnedwit.hxx> 100 #include <svx/xlnstcit.hxx> 101 #include <svx/xlnedcit.hxx> 102 #include <svx/xlndsit.hxx> 103 #include <svx/xlineit0.hxx> 104 #include <svx/svxids.hrc> 105 106 #define ITEMID_COLOR_TABLE SID_COLOR_TABLE 107 #define ITEMID_DASH_LIST SID_DASH_LIST 108 #define ITEMID_LINEEND_LIST SID_LINEEND_LIST 109 #include <svx/drawitem.hxx> 110 #define ITEMID_BRUSH SID_ATTR_BRUSH 111 #include <editeng/brshitem.hxx> 112 #include <sfx2/docfilt.hxx> 113 114 #include "dlgpage.hxx" 115 #include "helpids.hrc" 116 #include <toolkit/helper/convert.hxx> 117 118 #define DATA_OR_FORMULA 0 119 #define FUNCTION 1 120 #define COUNTER 2 121 #define USER_DEF_FUNCTION 3 122 #define UNDEF_DATA 4 123 124 //........................................................................ 125 namespace rptui 126 { 127 //........................................................................ 128 using namespace ::com::sun::star; 129 //using namespace formula; 130 131 // comparing two property instances 132 struct PropertyCompare : public ::std::binary_function< beans::Property, ::rtl::OUString , bool > 133 { 134 bool operator() (const beans::Property& x, const ::rtl::OUString& y) const 135 { 136 return x.Name.equals(y);// ? true : false; 137 } 138 bool operator() (const ::rtl::OUString& x,const beans::Property& y) const 139 { 140 return x.equals(y.Name);// ? true : false; 141 } 142 }; 143 144 // ----------------------------------------------------------------------------- 145 ::rtl::OUString lcl_getQuotedFunctionName(const ::rtl::OUString& _sFunction) 146 { 147 ::rtl::OUString sQuotedFunctionName(RTL_CONSTASCII_USTRINGPARAM("[")); 148 sQuotedFunctionName += _sFunction + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("]")); 149 return sQuotedFunctionName; 150 } 151 // ----------------------------------------------------------------------------- 152 ::rtl::OUString lcl_getQuotedFunctionName(const uno::Reference< report::XFunction>& _xFunction) 153 { 154 return lcl_getQuotedFunctionName(_xFunction->getName()); 155 } 156 // ----------------------------------------------------------------------------- 157 void lcl_collectFunctionNames(const uno::Reference< report::XFunctions>& _xFunctions,TFunctions& _rFunctionNames) 158 { 159 uno::Reference< report::XFunctionsSupplier> xParent(_xFunctions->getParent(),uno::UNO_QUERY_THROW); 160 const sal_Int32 nCount = _xFunctions->getCount(); 161 for (sal_Int32 i = 0; i < nCount ; ++i) 162 { 163 uno::Reference< report::XFunction > xFunction(_xFunctions->getByIndex(i),uno::UNO_QUERY_THROW); 164 _rFunctionNames.insert(TFunctions::value_type(lcl_getQuotedFunctionName(xFunction),TFunctionPair(xFunction,xParent))); 165 } 166 } 167 // ----------------------------------------------------------------------------- 168 void lcl_collectFunctionNames(const uno::Reference< report::XSection>& _xSection,TFunctions& _rFunctionNames) 169 { 170 const uno::Reference< report::XReportDefinition> xReportDefinition = _xSection->getReportDefinition(); 171 const uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups(); 172 sal_Int32 nPos = -1; 173 uno::Reference< report::XGroup> xGroup = _xSection->getGroup(); 174 if ( xGroup.is() ) 175 nPos = getPositionInIndexAccess(xGroups.get(),xGroup); 176 else if ( _xSection == xReportDefinition->getDetail() ) 177 nPos = xGroups->getCount()-1; 178 179 for (sal_Int32 i = 0 ; i <= nPos ; ++i) 180 { 181 xGroup.set(xGroups->getByIndex(i),uno::UNO_QUERY_THROW); 182 lcl_collectFunctionNames(xGroup->getFunctions(),_rFunctionNames); 183 } 184 lcl_collectFunctionNames(xReportDefinition->getFunctions(),_rFunctionNames); 185 } 186 // ----------------------------------------------------------------------------- 187 void lcl_convertFormulaTo(const uno::Any& _aPropertyValue,uno::Any& _rControlValue) 188 { 189 ::rtl::OUString sName; 190 _aPropertyValue >>= sName; 191 const sal_Int32 nLen = sName.getLength(); 192 if ( nLen ) 193 { 194 ReportFormula aFormula( sName ); 195 _rControlValue <<= aFormula.getUndecoratedContent(); 196 } 197 } 198 // ----------------------------------------------------------------------------- 199 bool GeometryHandler::impl_isDataField(const ::rtl::OUString& _sName) const 200 { 201 const ::rtl::OUString* pEnd = m_aFieldNames.getConstArray() + m_aFieldNames.getLength(); 202 bool bIsField = ( ::std::find( m_aFieldNames.getConstArray(), pEnd, _sName ) != pEnd ); 203 204 if ( !bIsField ) 205 { 206 pEnd = m_aParamNames.getConstArray() + m_aParamNames.getLength(); 207 bIsField = ( ::std::find( m_aParamNames.getConstArray(), pEnd, _sName ) != pEnd ); 208 } 209 return bIsField; 210 } 211 // ----------------------------------------------------------------------------- 212 ::rtl::OUString GeometryHandler::impl_convertToFormula( const uno::Any& _rControlValue ) 213 { 214 ::rtl::OUString sName; 215 _rControlValue >>= sName; 216 217 if ( !sName.getLength() ) 218 return sName; 219 220 ReportFormula aParser( sName ); 221 if ( aParser.isValid() ) 222 return sName; 223 224 aParser = ReportFormula( impl_isDataField(sName) ? ReportFormula::Field : ReportFormula::Expression, sName ); 225 return aParser.getCompleteFormula(); 226 } 227 DBG_NAME(rpt_GeometryHandler) 228 GeometryHandler::GeometryHandler(uno::Reference< uno::XComponentContext > const & context) : 229 GeometryHandler_Base(m_aMutex) 230 ,m_aPropertyListeners( m_aMutex ) 231 ,m_xContext(context) 232 ,m_pInfoService(new OPropertyInfoService()) 233 ,m_nDataFieldType(0) 234 ,m_bIn(false) 235 { 236 DBG_CTOR(rpt_GeometryHandler,NULL); 237 try 238 { 239 const uno::Reference< lang::XMultiComponentFactory > xFac = m_xContext->getServiceManager(); 240 m_xFormComponentHandler.set(xFac->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.inspection.FormComponentPropertyHandler")),m_xContext),uno::UNO_QUERY_THROW); 241 m_xTypeConverter.set(xFac->createInstanceWithContext( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter" )),m_xContext),uno::UNO_QUERY_THROW); 242 loadDefaultFunctions(); 243 } 244 catch(const uno::Exception&) 245 { 246 } 247 } 248 // ----------------------------------------------------------------------------- 249 GeometryHandler::~GeometryHandler() 250 { 251 DBG_DTOR(rpt_GeometryHandler,NULL); 252 } 253 //------------------------------------------------------------------------ 254 ::rtl::OUString SAL_CALL GeometryHandler::getImplementationName( ) throw(uno::RuntimeException) 255 { 256 return getImplementationName_Static(); 257 } 258 259 //------------------------------------------------------------------------ 260 sal_Bool SAL_CALL GeometryHandler::supportsService( const ::rtl::OUString& ServiceName ) throw(uno::RuntimeException) 261 { 262 return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_static()); 263 } 264 265 //------------------------------------------------------------------------ 266 uno::Sequence< ::rtl::OUString > SAL_CALL GeometryHandler::getSupportedServiceNames( ) throw(uno::RuntimeException) 267 { 268 return getSupportedServiceNames_static(); 269 } 270 271 //------------------------------------------------------------------------ 272 ::rtl::OUString GeometryHandler::getImplementationName_Static( ) throw(uno::RuntimeException) 273 { 274 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.GeometryHandler")); 275 } 276 277 //------------------------------------------------------------------------ 278 uno::Sequence< ::rtl::OUString > GeometryHandler::getSupportedServiceNames_static( ) throw(uno::RuntimeException) 279 { 280 uno::Sequence< ::rtl::OUString > aSupported(1); 281 aSupported[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.inspection.GeometryHandler")); 282 return aSupported; 283 } 284 285 //------------------------------------------------------------------------ 286 uno::Reference< uno::XInterface > SAL_CALL GeometryHandler::create( const uno::Reference< uno::XComponentContext >& _rxContext ) 287 { 288 return *(new GeometryHandler( _rxContext )); 289 } 290 // overload WeakComponentImplHelperBase::disposing() 291 // This function is called upon disposing the component, 292 // if your component needs special work when it becomes 293 // disposed, do it here. 294 void SAL_CALL GeometryHandler::disposing() 295 { 296 try 297 { 298 ::comphelper::disposeComponent(m_xFormComponentHandler); 299 ::comphelper::disposeComponent(m_xTypeConverter); 300 if ( m_xReportComponent.is() && m_xReportComponent->getPropertySetInfo()->hasPropertyByName(PROPERTY_DATAFIELD) ) 301 m_xReportComponent->removePropertyChangeListener(PROPERTY_DATAFIELD,static_cast< beans::XPropertyChangeListener* >( this )); 302 303 m_xReportComponent.clear(); 304 m_xRowSet.clear(); 305 m_aPropertyListeners.clear(); 306 } 307 catch(uno::Exception&) 308 {} 309 } 310 void SAL_CALL GeometryHandler::addEventListener(const uno::Reference< lang::XEventListener > & xListener) throw (uno::RuntimeException) 311 { 312 m_xFormComponentHandler->addEventListener(xListener); 313 } 314 315 void SAL_CALL GeometryHandler::removeEventListener(const uno::Reference< lang::XEventListener > & aListener) throw (uno::RuntimeException) 316 { 317 m_xFormComponentHandler->removeEventListener(aListener); 318 } 319 320 // inspection::XPropertyHandler: 321 322 /********************************************************************************/ 323 void SAL_CALL GeometryHandler::inspect( const uno::Reference< uno::XInterface > & _rxInspectee ) throw (uno::RuntimeException, lang::NullPointerException) 324 { 325 ::osl::MutexGuard aGuard( m_aMutex ); 326 m_sScope = m_sDefaultFunction = ::rtl::OUString(); 327 m_bNewFunction = false; 328 m_nDataFieldType = 0; 329 m_xFunction.clear(); 330 m_aFunctionNames.clear(); 331 try 332 { 333 if ( m_xReportComponent.is() && m_xReportComponent->getPropertySetInfo()->hasPropertyByName(PROPERTY_DATAFIELD) ) 334 m_xReportComponent->removePropertyChangeListener(PROPERTY_DATAFIELD,static_cast< beans::XPropertyChangeListener* >( this )); 335 336 const uno::Reference< container::XNameContainer > xObjectAsContainer( _rxInspectee, uno::UNO_QUERY ); 337 m_xReportComponent.set( xObjectAsContainer->getByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ReportComponent" ) ) ), uno::UNO_QUERY ); 338 339 const ::rtl::OUString sRowSet(RTL_CONSTASCII_USTRINGPARAM("RowSet")); 340 if ( xObjectAsContainer->hasByName( sRowSet ) ) 341 { 342 const uno::Any aRowSet( xObjectAsContainer->getByName(sRowSet) ); 343 aRowSet >>= m_xRowSet; 344 // forward the rowset to our delegator handler 345 uno::Reference< beans::XPropertySet > xProp( m_xFormComponentHandler,uno::UNO_QUERY ); 346 xProp->setPropertyValue( sRowSet, aRowSet ); 347 348 m_aParamNames = getParameterNames( m_xRowSet ); 349 impl_initFieldList_nothrow(m_aFieldNames); 350 if ( m_xReportComponent->getPropertySetInfo()->hasPropertyByName(PROPERTY_DATAFIELD) ) 351 m_xReportComponent->addPropertyChangeListener(PROPERTY_DATAFIELD,static_cast< beans::XPropertyChangeListener* >( this )); 352 } 353 354 const uno::Reference< report::XReportComponent> xReportComponent( m_xReportComponent, uno::UNO_QUERY); 355 uno::Reference< report::XSection> xSection( m_xReportComponent, uno::UNO_QUERY ); 356 if ( !xSection.is() && xReportComponent.is() ) 357 xSection = xReportComponent->getSection(); 358 if ( xSection.is() ) 359 lcl_collectFunctionNames( xSection, m_aFunctionNames ); 360 } 361 catch(uno::Exception) 362 { 363 throw lang::NullPointerException(); 364 } 365 m_xFormComponentHandler->inspect(m_xReportComponent); 366 } 367 368 uno::Any SAL_CALL GeometryHandler::getPropertyValue(const ::rtl::OUString & PropertyName) throw (uno::RuntimeException, beans::UnknownPropertyException) 369 { 370 ::osl::MutexGuard aGuard( m_aMutex ); 371 uno::Any aPropertyValue; 372 const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName); 373 switch(nId) 374 { 375 case PROPERTY_ID_CONDITIONALPRINTEXPRESSION: 376 case PROPERTY_ID_INITIALFORMULA: 377 case PROPERTY_ID_FORMULA: 378 case PROPERTY_ID_DATAFIELD: 379 aPropertyValue = m_xReportComponent->getPropertyValue( PropertyName ); 380 lcl_convertFormulaTo(aPropertyValue,aPropertyValue); 381 if ( PROPERTY_ID_DATAFIELD == nId ) 382 { 383 ::rtl::OUString sDataField; 384 aPropertyValue >>= sDataField; 385 switch(m_nDataFieldType) 386 { 387 case DATA_OR_FORMULA: 388 break; 389 case FUNCTION: 390 if ( isDefaultFunction(sDataField,sDataField) ) 391 aPropertyValue <<= sDataField; 392 else if ( !sDataField.getLength() ) 393 aPropertyValue = uno::Any(); 394 break; 395 case COUNTER: 396 case USER_DEF_FUNCTION: 397 aPropertyValue = uno::Any(); 398 break; 399 } 400 401 } 402 break; 403 case PROPERTY_ID_TYPE: 404 { 405 const sal_uInt32 nOldDataFieldType = m_nDataFieldType; 406 m_nDataFieldType = impl_getDataFieldType_throw(); 407 if ( UNDEF_DATA == m_nDataFieldType ) 408 m_nDataFieldType = nOldDataFieldType; 409 aPropertyValue <<= m_nDataFieldType; 410 } 411 break; 412 case PROPERTY_ID_FORMULALIST: 413 case PROPERTY_ID_SCOPE: 414 { 415 uno::Any aDataField = m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD ); 416 lcl_convertFormulaTo(aDataField,aDataField); 417 ::rtl::OUString sDataField; 418 aDataField >>= sDataField; 419 switch(m_nDataFieldType) 420 { 421 case DATA_OR_FORMULA: 422 break; 423 case FUNCTION: 424 if ( isDefaultFunction(sDataField,sDataField,uno::Reference< report::XFunctionsSupplier>(),true) ) 425 aPropertyValue <<= (PROPERTY_ID_FORMULALIST == nId ? m_sDefaultFunction : m_sScope); 426 break; 427 case USER_DEF_FUNCTION: 428 if ( sDataField.getLength() && PROPERTY_ID_FORMULALIST == nId ) 429 aPropertyValue = aDataField; 430 break; 431 case COUNTER: 432 if ( PROPERTY_ID_SCOPE == nId && impl_isCounterFunction_throw(sDataField,m_sScope) ) 433 aPropertyValue <<= m_sScope; 434 break; 435 } 436 437 } 438 break; 439 case PROPERTY_ID_BACKCOLOR: 440 case PROPERTY_ID_CONTROLBACKGROUND: 441 { 442 aPropertyValue = m_xReportComponent->getPropertyValue( PropertyName ); 443 sal_Int32 nColor = COL_TRANSPARENT; 444 if ( (aPropertyValue >>= nColor) && static_cast<sal_Int32>(COL_TRANSPARENT) == nColor ) 445 aPropertyValue.clear(); 446 } 447 break; 448 case PROPERTY_ID_MIMETYPE: 449 { 450 ::rtl::OUString sValue; 451 m_xReportComponent->getPropertyValue( PropertyName ) >>= sValue; 452 aPropertyValue <<= impl_ConvertMimeTypeToUI_nothrow(sValue); 453 } 454 break; 455 default: 456 aPropertyValue = m_xReportComponent->getPropertyValue( PropertyName ); 457 break; 458 } 459 return aPropertyValue; 460 } 461 462 void SAL_CALL GeometryHandler::setPropertyValue(const ::rtl::OUString & PropertyName, const uno::Any & Value) throw (uno::RuntimeException, beans::UnknownPropertyException) 463 { 464 ::osl::ResettableMutexGuard aGuard( m_aMutex ); 465 uno::Any aNewValue = Value; 466 const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName); 467 bool bHandled = false; 468 switch(nId) 469 { 470 case PROPERTY_ID_INITIALFORMULA: 471 case PROPERTY_ID_FORMULA: 472 break; 473 case PROPERTY_ID_DATAFIELD: 474 { 475 OBlocker aBlocker(m_bIn); 476 m_xReportComponent->setPropertyValue(PropertyName, aNewValue); 477 bHandled = true; 478 const ::rtl::OUString sOldFunctionName = m_sDefaultFunction; 479 const ::rtl::OUString sOldScope = m_sScope; 480 481 uno::Any aPropertyValue; 482 lcl_convertFormulaTo(Value,aPropertyValue); 483 ::rtl::OUString sDataField; 484 aPropertyValue >>= sDataField; 485 486 m_sScope = m_sDefaultFunction = ::rtl::OUString(); 487 m_xFunction.clear(); 488 const sal_uInt32 nOldDataFieldType = m_nDataFieldType; 489 if ( sDataField.getLength() ) 490 { 491 if ( isDefaultFunction(sDataField,sDataField,uno::Reference< report::XFunctionsSupplier>(),true) ) 492 m_nDataFieldType = FUNCTION; 493 else if ( m_aFunctionNames.find(sDataField) != m_aFunctionNames.end() ) 494 m_nDataFieldType = USER_DEF_FUNCTION; 495 } 496 497 resetOwnProperties(aGuard,sOldFunctionName,sOldScope,nOldDataFieldType); 498 } 499 break; 500 case PROPERTY_ID_TYPE: 501 { 502 bHandled = true; 503 Value >>= m_nDataFieldType; 504 505 const ::rtl::OUString sOldFunctionName = m_sDefaultFunction; 506 const ::rtl::OUString sOldScope = m_sScope; 507 m_sDefaultFunction = m_sScope = ::rtl::OUString(); 508 509 if ( m_nDataFieldType == COUNTER ) 510 { 511 impl_setCounterFunction_throw(); 512 } 513 else 514 { 515 if ( m_bNewFunction ) 516 removeFunction(); 517 m_xFunction.clear(); 518 OBlocker aBlocker(m_bIn); 519 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(::rtl::OUString())); 520 } 521 resetOwnProperties(aGuard,sOldFunctionName,sOldScope,m_nDataFieldType); 522 } 523 break; 524 case PROPERTY_ID_FORMULALIST: 525 { 526 bHandled = true; 527 ::rtl::OUString sFunction; 528 if ( !(Value >>= sFunction) || !sFunction.getLength() ) 529 { 530 if ( m_nDataFieldType == FUNCTION ) 531 { 532 m_sDefaultFunction = ::rtl::OUString(); 533 if ( m_bNewFunction ) 534 removeFunction(); 535 m_xFunction.clear(); 536 537 beans::PropertyChangeEvent aEvent; 538 aEvent.PropertyName = PROPERTY_SCOPE; 539 aEvent.OldValue <<= m_sScope; 540 m_sScope = ::rtl::OUString(); 541 aEvent.NewValue <<= m_sScope; 542 aGuard.clear(); 543 m_aPropertyListeners.notify( aEvent, &beans::XPropertyChangeListener::propertyChange ); 544 } 545 else if ( m_nDataFieldType == USER_DEF_FUNCTION ) 546 { 547 OBlocker aBlocker(m_bIn); 548 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(::rtl::OUString())); 549 } 550 } 551 else if ( m_nDataFieldType == USER_DEF_FUNCTION ) 552 { 553 ::rtl::OUString sDataField; 554 OBlocker aBlocker(m_bIn); 555 const sal_uInt32 nNewDataType = impl_getDataFieldType_throw(sFunction); 556 if ( nNewDataType != UNDEF_DATA && nNewDataType != m_nDataFieldType ) 557 { 558 const ::rtl::OUString sOldFunctionName = m_sDefaultFunction; 559 const ::rtl::OUString sOldScope = m_sScope; 560 m_sScope = m_sDefaultFunction = ::rtl::OUString(); 561 m_xFunction.clear(); 562 if ( nNewDataType == COUNTER ) 563 impl_isCounterFunction_throw(sFunction,m_sScope); 564 else 565 { 566 ::rtl::OUString sNamePostFix; 567 const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostFix); 568 isDefaultFunction(sFunction,sDataField,xFunctionsSupplier,true); 569 } 570 const sal_uInt32 nOldDataFieldType = m_nDataFieldType; 571 m_nDataFieldType = nNewDataType; 572 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(impl_convertToFormula( uno::makeAny(sFunction)))); 573 resetOwnProperties(aGuard,sOldFunctionName,sOldScope,nOldDataFieldType); 574 } 575 else 576 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(impl_convertToFormula( uno::makeAny(sFunction)))); 577 } 578 else if ( m_nDataFieldType == FUNCTION ) 579 { 580 uno::Any aPropertyValue = m_xReportComponent->getPropertyValue(PROPERTY_DATAFIELD); 581 lcl_convertFormulaTo(aPropertyValue,aPropertyValue); 582 ::rtl::OUString sDataField; 583 aPropertyValue >>= sDataField; 584 if ( m_nDataFieldType == FUNCTION && (!isDefaultFunction(sDataField,sDataField) || m_sDefaultFunction != sFunction) ) 585 { 586 if ( m_bNewFunction ) 587 removeFunction(); 588 // function currently does not exist 589 createDefaultFunction(aGuard,sFunction,sDataField); 590 m_sDefaultFunction = sFunction; 591 } 592 } 593 } 594 595 break; 596 case PROPERTY_ID_SCOPE: 597 if ( !(Value >>= m_sScope) ) 598 m_sScope = ::rtl::OUString(); 599 else 600 { 601 if ( m_bNewFunction ) 602 removeFunction(); 603 if ( m_nDataFieldType == COUNTER ) 604 impl_setCounterFunction_throw(); 605 else 606 { 607 OSL_ENSURE(m_xFunction.is(),"Where is my function gone!"); 608 609 ::rtl::OUString sNamePostFix; 610 const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostFix); 611 612 ::rtl::OUString sQuotedFunctionName(lcl_getQuotedFunctionName(m_xFunction)); 613 if ( isDefaultFunction(sQuotedFunctionName,sQuotedFunctionName,xFunctionsSupplier,true) ) 614 m_bNewFunction = false; 615 else 616 { 617 ::rtl::OUString sDefaultFunctionName; 618 ::rtl::OUString sDataField; 619 OSL_VERIFY( impl_isDefaultFunction_nothrow(m_xFunction,sDataField,sDefaultFunctionName) ); 620 m_sDefaultFunction = sDefaultFunctionName; 621 createDefaultFunction(aGuard,m_sDefaultFunction,sDataField); 622 } 623 } 624 } 625 bHandled = true; 626 break; 627 case PROPERTY_ID_POSITIONX: 628 case PROPERTY_ID_POSITIONY: 629 case PROPERTY_ID_HEIGHT: 630 case PROPERTY_ID_WIDTH: 631 { 632 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY); 633 if ( xSourceReportComponent.is() ) // check only report components 634 { 635 sal_Int32 nNewValue = 0; 636 Value >>= nNewValue; 637 awt::Point aAwtPoint = xSourceReportComponent->getPosition(); 638 awt::Size aAwtSize = xSourceReportComponent->getSize(); 639 if ( nId == PROPERTY_ID_POSITIONX ) 640 aAwtPoint.X = nNewValue; 641 else if ( nId == PROPERTY_ID_POSITIONY ) 642 aAwtPoint.Y = nNewValue; 643 else if ( nId == PROPERTY_ID_HEIGHT ) 644 aAwtSize.Height = nNewValue; 645 else if ( nId == PROPERTY_ID_WIDTH ) 646 aAwtSize.Width = nNewValue; 647 648 checkPosAndSize(aAwtPoint,aAwtSize); 649 } 650 } 651 break; 652 case PROPERTY_ID_FONT: 653 { 654 const uno::Reference< report::XReportControlFormat > xReportControlFormat( m_xReportComponent,uno::UNO_QUERY_THROW ); 655 uno::Sequence< beans::NamedValue > aFontSettings; 656 OSL_VERIFY( Value >>= aFontSettings ); 657 applyCharacterSettings( xReportControlFormat, aFontSettings ); 658 bHandled = true; 659 } 660 break; 661 case PROPERTY_ID_MIMETYPE: 662 { 663 ::rtl::OUString sValue; 664 Value >>= sValue; 665 aNewValue <<= impl_ConvertUIToMimeType_nothrow(sValue); 666 } 667 default: 668 break; 669 } 670 671 if ( !bHandled ) 672 m_xReportComponent->setPropertyValue(PropertyName, aNewValue); 673 } 674 675 // ----------------------------------------------------------------------------- 676 beans::PropertyState SAL_CALL GeometryHandler::getPropertyState(const ::rtl::OUString & PropertyName) throw (uno::RuntimeException, beans::UnknownPropertyException) 677 { 678 ::osl::MutexGuard aGuard( m_aMutex ); 679 return m_xFormComponentHandler->getPropertyState(PropertyName); 680 } 681 // ----------------------------------------------------------------------------- 682 void GeometryHandler::implCreateListLikeControl( 683 const uno::Reference< inspection::XPropertyControlFactory >& _rxControlFactory 684 ,inspection::LineDescriptor & out_Descriptor 685 ,sal_uInt16 _nResId 686 ,sal_Bool _bReadOnlyControl 687 ,sal_Bool _bTrueIfListBoxFalseIfComboBox 688 ) 689 { 690 ::std::vector< ::rtl::OUString > aList; 691 tools::StringListResource aRes(ModuleRes(_nResId),aList); 692 693 implCreateListLikeControl(_rxControlFactory,out_Descriptor,aList,_bReadOnlyControl,_bTrueIfListBoxFalseIfComboBox); 694 } 695 // ----------------------------------------------------------------------------- 696 void GeometryHandler::implCreateListLikeControl( 697 const uno::Reference< inspection::XPropertyControlFactory >& _rxControlFactory 698 ,inspection::LineDescriptor & out_Descriptor 699 ,const ::std::vector< ::rtl::OUString>& _aEntries 700 ,sal_Bool _bReadOnlyControl 701 ,sal_Bool _bTrueIfListBoxFalseIfComboBox 702 ) 703 { 704 const uno::Reference< inspection::XStringListControl > xListControl( 705 _rxControlFactory->createPropertyControl( 706 _bTrueIfListBoxFalseIfComboBox ? inspection::PropertyControlType::ListBox : inspection::PropertyControlType::ComboBox, _bReadOnlyControl 707 ), 708 uno::UNO_QUERY_THROW 709 ); 710 711 out_Descriptor.Control = xListControl.get(); 712 ::std::for_each( _aEntries.begin(), _aEntries.end(),::boost::bind( &inspection::XStringListControl::appendListEntry, xListControl,_1 )); 713 } 714 // ----------------------------------------------------------------------------- 715 716 inspection::LineDescriptor SAL_CALL GeometryHandler::describePropertyLine(const ::rtl::OUString & PropertyName, const uno::Reference< inspection::XPropertyControlFactory > & _xControlFactory) throw (beans::UnknownPropertyException, lang::NullPointerException,uno::RuntimeException) 717 { 718 inspection::LineDescriptor aOut; 719 const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName); 720 switch(nId) 721 { 722 case PROPERTY_ID_FORCENEWPAGE: 723 case PROPERTY_ID_NEWROWORCOL: 724 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_FORCENEWPAGE_CONST,sal_False,sal_True); 725 break; 726 case PROPERTY_ID_GROUPKEEPTOGETHER: 727 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_GROUPKEEPTOGETHER_CONST,sal_False,sal_True); 728 break; 729 case PROPERTY_ID_PAGEHEADEROPTION: 730 case PROPERTY_ID_PAGEFOOTEROPTION: 731 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_REPORTPRINTOPTION_CONST,sal_False,sal_True); 732 break; 733 case PROPERTY_ID_FORMULALIST: 734 { 735 ::std::vector< ::rtl::OUString > aList; 736 impl_fillFormulaList_nothrow(aList); 737 implCreateListLikeControl(_xControlFactory,aOut,aList,sal_False,sal_True); 738 } 739 break; 740 case PROPERTY_ID_SCOPE: 741 { 742 ::std::vector< ::rtl::OUString > aList; 743 impl_fillScopeList_nothrow(aList); 744 implCreateListLikeControl(_xControlFactory,aOut,aList,sal_False,sal_True); 745 } 746 break; 747 case PROPERTY_ID_MIMETYPE: 748 { 749 ::std::vector< ::rtl::OUString > aList; 750 impl_fillMimeTypes_nothrow(aList); 751 implCreateListLikeControl(_xControlFactory,aOut,aList,sal_False,sal_True); 752 } 753 break; 754 case PROPERTY_ID_TYPE: 755 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_TYPE_CONST,sal_False,sal_True); 756 break; 757 case PROPERTY_ID_VISIBLE: 758 case PROPERTY_ID_CANGROW: 759 case PROPERTY_ID_CANSHRINK: 760 case PROPERTY_ID_REPEATSECTION: 761 case PROPERTY_ID_PRINTREPEATEDVALUES: 762 case PROPERTY_ID_STARTNEWCOLUMN: 763 case PROPERTY_ID_RESETPAGENUMBER: 764 case PROPERTY_ID_PRINTWHENGROUPCHANGE: 765 case PROPERTY_ID_KEEPTOGETHER: 766 case PROPERTY_ID_DEEPTRAVERSING: 767 case PROPERTY_ID_PREEVALUATED: 768 case PROPERTY_ID_PRESERVEIRI: 769 case PROPERTY_ID_BACKTRANSPARENT: 770 case PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT: 771 { 772 sal_uInt16 nResId = RID_STR_BOOL; 773 if ( PROPERTY_ID_KEEPTOGETHER == nId && uno::Reference< report::XGroup>(m_xReportComponent,uno::UNO_QUERY).is()) 774 nResId = RID_STR_KEEPTOGETHER_CONST; 775 implCreateListLikeControl(_xControlFactory,aOut,nResId,sal_False,sal_True); 776 } 777 break; 778 case PROPERTY_ID_INITIALFORMULA: 779 case PROPERTY_ID_FORMULA: 780 aOut.PrimaryButtonId = rtl::OUString::createFromAscii(UID_RPT_PROP_FORMULA); 781 aOut.HasPrimaryButton = sal_True; 782 aOut.Control = _xControlFactory->createPropertyControl(inspection::PropertyControlType::MultiLineTextField , sal_False); 783 break; 784 case PROPERTY_ID_CONDITIONALPRINTEXPRESSION: 785 aOut.PrimaryButtonId = rtl::OUString::createFromAscii(UID_RPT_PROP_FORMULA); 786 aOut.HasPrimaryButton = sal_True; 787 aOut.Control = _xControlFactory->createPropertyControl(inspection::PropertyControlType::MultiLineTextField , sal_False); 788 break; 789 case PROPERTY_ID_DATAFIELD: 790 { 791 uno::Reference< inspection::XStringListControl > xListControl( 792 _xControlFactory->createPropertyControl( 793 m_nDataFieldType == DATA_OR_FORMULA ? inspection::PropertyControlType::ComboBox : inspection::PropertyControlType::ListBox, sal_False 794 ), 795 uno::UNO_QUERY_THROW 796 ); 797 798 if ( m_nDataFieldType == DATA_OR_FORMULA ) 799 { 800 aOut.PrimaryButtonId = rtl::OUString::createFromAscii(UID_RPT_PROP_FORMULA); 801 aOut.HasPrimaryButton = sal_True; 802 } 803 804 aOut.Control = xListControl.get(); 805 if ( m_nDataFieldType == USER_DEF_FUNCTION ) 806 { 807 // add function names 808 ::std::for_each( m_aFunctionNames.begin(), m_aFunctionNames.end(), 809 ::std::compose1( 810 ::boost::bind( &inspection::XStringListControl::appendListEntry, xListControl,_1 ), 811 ::std::select1st<TFunctions::value_type>())); 812 } 813 else 814 { 815 ::std::for_each( m_aFieldNames.getConstArray(), m_aFieldNames.getConstArray() + m_aFieldNames.getLength(), 816 ::boost::bind( &inspection::XStringListControl::appendListEntry, xListControl, _1 ) ); 817 ::std::for_each( m_aParamNames.getConstArray(), m_aParamNames.getConstArray() + m_aParamNames.getLength(), 818 ::boost::bind( &inspection::XStringListControl::appendListEntry, xListControl, _1 ) ); 819 } 820 } 821 break; 822 case PROPERTY_ID_BACKCOLOR: 823 case PROPERTY_ID_CONTROLBACKGROUND: 824 aOut.Control = _xControlFactory->createPropertyControl( inspection::PropertyControlType::ColorListBox, sal_False ); 825 break; 826 case PROPERTY_ID_FONT: 827 aOut.PrimaryButtonId = rtl::OUString::createFromAscii(UID_RPT_RPT_PROP_DLG_FONT_TYPE); 828 aOut.Control = _xControlFactory->createPropertyControl( inspection::PropertyControlType::TextField, sal_True ); 829 aOut.HasPrimaryButton = sal_True; 830 break; 831 case PROPERTY_ID_AREA: 832 aOut.PrimaryButtonId = rtl::OUString::createFromAscii(UID_RPT_RPT_PROP_DLG_AREA); 833 aOut.Control = _xControlFactory->createPropertyControl( inspection::PropertyControlType::TextField, sal_True ); 834 aOut.HasPrimaryButton = sal_True; 835 break; 836 case PROPERTY_ID_VERTICALALIGN: 837 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_VERTICAL_ALIGN_CONST,sal_False,sal_True); 838 break; 839 case PROPERTY_ID_PARAADJUST: 840 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_PARAADJUST_CONST,sal_False,sal_True); 841 break; 842 default: 843 { 844 aOut = m_xFormComponentHandler->describePropertyLine(PropertyName, _xControlFactory); 845 } 846 } 847 848 if ( nId != -1 ) 849 { 850 aOut.Category = ((m_pInfoService->getPropertyUIFlags(nId ) & PROP_FLAG_DATA_PROPERTY) != 0) ? 851 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Data")) 852 : 853 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("General")); 854 aOut.HelpURL = HelpIdUrl::getHelpURL( m_pInfoService->getPropertyHelpId( nId ) ); 855 aOut.DisplayName = m_pInfoService->getPropertyTranslation(nId); 856 } 857 858 if ( ( nId == PROPERTY_ID_POSITIONX ) 859 || ( nId == PROPERTY_ID_POSITIONY ) 860 || ( nId == PROPERTY_ID_WIDTH ) 861 || ( nId == PROPERTY_ID_HEIGHT ) 862 ) 863 { 864 const MeasurementSystem eSystem = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum(); 865 const sal_Int16 nDisplayUnit = VCLUnoHelper::ConvertToMeasurementUnit( MEASURE_METRIC == eSystem ? FUNIT_CM : FUNIT_INCH, 1 ); 866 uno::Reference< inspection::XNumericControl > xNumericControl(aOut.Control,uno::UNO_QUERY); 867 xNumericControl->setDecimalDigits( 2 ); 868 xNumericControl->setValueUnit( util::MeasureUnit::MM_100TH ); 869 uno::Reference< drawing::XShapeDescriptor> xShapeDesc(m_xReportComponent,uno::UNO_QUERY); 870 bool bSetMin = !xShapeDesc.is() || xShapeDesc->getShapeType() != ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.CustomShape")); 871 if ( bSetMin ) 872 xNumericControl->setMinValue(beans::Optional<double>(sal_True,0.0)); 873 if ( nDisplayUnit != -1 ) 874 xNumericControl->setDisplayUnit( nDisplayUnit ); 875 uno::Reference< report::XReportComponent> xComp(m_xReportComponent,uno::UNO_QUERY); 876 if ( xComp.is() && xComp->getSection().is() ) 877 { 878 uno::Reference< report::XReportDefinition > xReport = xComp->getSection()->getReportDefinition(); 879 OSL_ENSURE(xReport.is(),"Why is the report definition NULL!"); 880 if ( xReport.is() ) 881 { 882 const awt::Size aSize = getStyleProperty<awt::Size>(xReport,PROPERTY_PAPERSIZE); 883 const sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReport,PROPERTY_LEFTMARGIN); 884 const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReport,PROPERTY_RIGHTMARGIN); 885 switch(nId) 886 { 887 case PROPERTY_ID_POSITIONX: 888 case PROPERTY_ID_POSITIONY: 889 case PROPERTY_ID_WIDTH: 890 if ( bSetMin ) 891 xNumericControl->setMinValue(beans::Optional<double>(sal_True,0.0)); 892 xNumericControl->setMaxValue(beans::Optional<double>(sal_True,double(aSize.Width - nLeftMargin - nRightMargin))); 893 if ( PROPERTY_ID_WIDTH == nId ) 894 { 895 uno::Reference<report::XFixedLine> xFixedLine(m_xReportComponent,uno::UNO_QUERY); 896 if ( xFixedLine.is() && xFixedLine->getOrientation() == 1 ) // vertical 897 xNumericControl->setMinValue(beans::Optional<double>(sal_True,0.08 )); 898 } 899 break; 900 default: 901 break; 902 } 903 } 904 } 905 else if ( PROPERTY_ID_HEIGHT == nId ) 906 { 907 const uno::Reference< report::XSection> xSection(m_xReportComponent,uno::UNO_QUERY); 908 if ( xSection.is() ) 909 { 910 sal_Int32 nHeight = 0; 911 const sal_Int32 nCount = xSection->getCount(); 912 for (sal_Int32 i = 0; i < nCount; ++i) 913 { 914 uno::Reference<drawing::XShape> xShape(xSection->getByIndex(i),uno::UNO_QUERY); 915 nHeight = ::std::max<sal_Int32>(nHeight,xShape->getPosition().Y + xShape->getSize().Height); 916 } 917 xNumericControl->setMinValue(beans::Optional<double>(sal_True,nHeight )); 918 } 919 } 920 } 921 return aOut; 922 } 923 // ----------------------------------------------------------------------------- 924 beans::Property GeometryHandler::getProperty(const ::rtl::OUString & PropertyName) 925 { 926 uno::Sequence< beans::Property > aProps = getSupportedProperties(); 927 const beans::Property* pIter = aProps.getConstArray(); 928 const beans::Property* pEnd = pIter + aProps.getLength(); 929 const beans::Property* pFind = ::std::find_if(pIter,pEnd,::std::bind2nd(PropertyCompare(),boost::cref(PropertyName))); 930 if ( pFind == pEnd ) 931 return beans::Property(); 932 return *pFind; 933 } 934 uno::Any GeometryHandler::getConstantValue(sal_Bool _bToControlValue,sal_uInt16 _nResId,const uno::Any& _aValue,const ::rtl::OUString& _sConstantName,const ::rtl::OUString & PropertyName ) 935 { 936 ::std::vector< ::rtl::OUString > aList; 937 tools::StringListResource aRes(ModuleRes(_nResId),aList); 938 uno::Sequence< ::rtl::OUString > aSeq(aList.size()); 939 ::std::copy( aList.begin(), aList.end(), aSeq.getArray() ); 940 941 uno::Reference< inspection::XStringRepresentation > xConversionHelper = inspection::StringRepresentation::createConstant( m_xContext,m_xTypeConverter,_sConstantName,aSeq); 942 if ( _bToControlValue ) 943 { 944 return uno::makeAny( xConversionHelper->convertToControlValue( _aValue ) ); 945 } 946 else 947 { 948 ::rtl::OUString sControlValue; 949 _aValue >>= sControlValue; 950 const beans::Property aProp = getProperty(PropertyName); 951 return xConversionHelper->convertToPropertyValue( sControlValue, aProp.Type ); 952 } 953 } 954 955 uno::Any SAL_CALL GeometryHandler::convertToPropertyValue(const ::rtl::OUString & PropertyName, const uno::Any & _rControlValue) throw (uno::RuntimeException, beans::UnknownPropertyException) 956 { 957 ::osl::MutexGuard aGuard( m_aMutex ); 958 uno::Any aPropertyValue( _rControlValue ); 959 const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName); 960 switch(nId) 961 { 962 case PROPERTY_ID_FORCENEWPAGE: 963 case PROPERTY_ID_NEWROWORCOL: 964 aPropertyValue = getConstantValue(sal_False,RID_STR_FORCENEWPAGE_CONST,_rControlValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.ForceNewPage")),PropertyName); 965 break; 966 case PROPERTY_ID_GROUPKEEPTOGETHER: 967 aPropertyValue = getConstantValue(sal_False,RID_STR_GROUPKEEPTOGETHER_CONST,_rControlValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.GroupKeepTogether")),PropertyName); 968 break; 969 case PROPERTY_ID_PAGEHEADEROPTION: 970 case PROPERTY_ID_PAGEFOOTEROPTION: 971 aPropertyValue = getConstantValue(sal_False,RID_STR_REPORTPRINTOPTION_CONST,_rControlValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.ReportPrintOption")),PropertyName); 972 break; 973 case PROPERTY_ID_BACKCOLOR: 974 case PROPERTY_ID_CONTROLBACKGROUND: 975 if ( !_rControlValue.hasValue() ) 976 { 977 aPropertyValue <<= static_cast<sal_Int32>(COL_TRANSPARENT); 978 break; 979 } 980 // run through 981 982 case PROPERTY_ID_KEEPTOGETHER: 983 if ( uno::Reference< report::XGroup>(m_xReportComponent,uno::UNO_QUERY).is()) 984 { 985 aPropertyValue = getConstantValue(sal_False,RID_STR_KEEPTOGETHER_CONST,_rControlValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.KeepTogether")),PropertyName); 986 break; 987 } 988 // run through 989 990 case PROPERTY_ID_VISIBLE: 991 case PROPERTY_ID_CANGROW: 992 case PROPERTY_ID_CANSHRINK: 993 case PROPERTY_ID_REPEATSECTION: 994 case PROPERTY_ID_PRINTREPEATEDVALUES: 995 case PROPERTY_ID_STARTNEWCOLUMN: 996 case PROPERTY_ID_RESETPAGENUMBER: 997 case PROPERTY_ID_PRINTWHENGROUPCHANGE: 998 case PROPERTY_ID_DEEPTRAVERSING: 999 case PROPERTY_ID_PREEVALUATED: 1000 case PROPERTY_ID_PRESERVEIRI: 1001 case PROPERTY_ID_BACKTRANSPARENT: 1002 case PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT: 1003 { 1004 if ( aPropertyValue.hasValue() ) 1005 { 1006 const beans::Property aProp = getProperty(PropertyName); 1007 if ( aPropertyValue.getValueType().equals( aProp.Type ) ) 1008 // nothing to do, type is already as desired 1009 return aPropertyValue; 1010 1011 if ( _rControlValue.getValueType().getTypeClass() == uno::TypeClass_STRING ) 1012 { 1013 ::rtl::OUString sControlValue; 1014 _rControlValue >>= sControlValue; 1015 1016 const uno::Reference< inspection::XStringRepresentation > xConversionHelper = inspection::StringRepresentation::create( m_xContext,m_xTypeConverter ); 1017 aPropertyValue = xConversionHelper->convertToPropertyValue( sControlValue, aProp.Type ); 1018 } 1019 else 1020 { 1021 try 1022 { 1023 aPropertyValue = m_xTypeConverter->convertTo( _rControlValue, aProp.Type ); 1024 } 1025 catch( const uno::Exception& ) 1026 { 1027 OSL_ENSURE( sal_False, "GeometryHandler::convertToPropertyValue: caught an exception while converting via TypeConverter!" ); 1028 } 1029 } 1030 } 1031 1032 break; 1033 } 1034 case PROPERTY_ID_CONDITIONALPRINTEXPRESSION: 1035 case PROPERTY_ID_INITIALFORMULA: 1036 case PROPERTY_ID_FORMULA: 1037 return uno::makeAny( impl_convertToFormula( _rControlValue ) ); 1038 case PROPERTY_ID_DATAFIELD: 1039 { 1040 ::rtl::OUString sDataField; 1041 _rControlValue >>= sDataField; 1042 if ( isDefaultFunction(sDataField,sDataField) ) 1043 { 1044 OSL_ENSURE(m_xFunction.is(),"No function set!"); 1045 aPropertyValue <<= impl_convertToFormula( uno::makeAny(lcl_getQuotedFunctionName(m_xFunction)) ); 1046 } 1047 else 1048 aPropertyValue <<= impl_convertToFormula( _rControlValue ); 1049 } 1050 break; 1051 case PROPERTY_ID_POSITIONX: 1052 { 1053 aPropertyValue = m_xFormComponentHandler->convertToPropertyValue(PropertyName, _rControlValue); 1054 sal_Int32 nPosX = 0; 1055 aPropertyValue >>= nPosX; 1056 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY); 1057 if ( xSourceReportComponent->getSection().is() ) 1058 nPosX += getStyleProperty<sal_Int32>(xSourceReportComponent->getSection()->getReportDefinition(),PROPERTY_LEFTMARGIN); 1059 aPropertyValue <<= nPosX; 1060 } 1061 break; 1062 case PROPERTY_ID_FONT: 1063 aPropertyValue = m_xFormComponentHandler->convertToPropertyValue(PROPERTY_FONT, _rControlValue); 1064 break; 1065 case PROPERTY_ID_SCOPE: 1066 case PROPERTY_ID_FORMULALIST: 1067 case PROPERTY_ID_AREA: 1068 aPropertyValue = _rControlValue; 1069 break; 1070 case PROPERTY_ID_TYPE: 1071 { 1072 ::rtl::OUString sValue; 1073 _rControlValue >>= sValue; 1074 ::std::vector< ::rtl::OUString > aList; 1075 tools::StringListResource aRes(ModuleRes(RID_STR_TYPE_CONST),aList); 1076 ::std::vector< ::rtl::OUString >::iterator aFind = ::std::find(aList.begin(),aList.end(),sValue); 1077 if ( aFind != aList.end() ) 1078 aPropertyValue <<= static_cast<sal_uInt32>(aFind - aList.begin()); 1079 } 1080 break; 1081 case PROPERTY_ID_MIMETYPE: 1082 aPropertyValue = _rControlValue; 1083 break; 1084 case PROPERTY_ID_VERTICALALIGN: 1085 { 1086 ::rtl::OUString sValue; 1087 _rControlValue >>= sValue; 1088 ::std::vector< ::rtl::OUString > aList; 1089 tools::StringListResource aRes(ModuleRes(RID_STR_VERTICAL_ALIGN_CONST),aList); 1090 ::std::vector< ::rtl::OUString >::iterator aFind = ::std::find(aList.begin(),aList.end(),sValue); 1091 if ( aFind != aList.end() ) 1092 aPropertyValue <<= static_cast<style::VerticalAlignment>(aFind - aList.begin()); 1093 } 1094 break; 1095 case PROPERTY_ID_PARAADJUST: 1096 { 1097 ::rtl::OUString sValue; 1098 _rControlValue >>= sValue; 1099 ::std::vector< ::rtl::OUString > aList; 1100 tools::StringListResource aRes(ModuleRes(RID_STR_PARAADJUST_CONST),aList); 1101 ::std::vector< ::rtl::OUString >::iterator aFind = ::std::find(aList.begin(),aList.end(),sValue); 1102 if ( aFind != aList.end() ) 1103 aPropertyValue <<= static_cast<sal_Int16>(aFind - aList.begin()); 1104 } 1105 break; 1106 default: 1107 return m_xFormComponentHandler->convertToPropertyValue(PropertyName, _rControlValue); 1108 } 1109 return aPropertyValue; 1110 } 1111 1112 uno::Any SAL_CALL GeometryHandler::convertToControlValue(const ::rtl::OUString & PropertyName, const uno::Any & _rPropertyValue, const uno::Type & _rControlValueType) throw (uno::RuntimeException, beans::UnknownPropertyException) 1113 { 1114 uno::Any aControlValue( _rPropertyValue ); 1115 if ( !aControlValue.hasValue() ) 1116 // NULL is converted to NULL 1117 return aControlValue; 1118 1119 uno::Any aPropertyValue(_rPropertyValue); 1120 1121 ::osl::MutexGuard aGuard( m_aMutex ); 1122 const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName); 1123 switch(nId) 1124 { 1125 case PROPERTY_ID_AREA: 1126 break; 1127 case PROPERTY_ID_FORCENEWPAGE: 1128 case PROPERTY_ID_NEWROWORCOL: 1129 aControlValue = getConstantValue(sal_True,RID_STR_FORCENEWPAGE_CONST,aPropertyValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.ForceNewPage")),PropertyName); 1130 break; 1131 case PROPERTY_ID_GROUPKEEPTOGETHER: 1132 aControlValue = getConstantValue(sal_True,RID_STR_GROUPKEEPTOGETHER_CONST,aPropertyValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.GroupKeepTogether")),PropertyName); 1133 break; 1134 case PROPERTY_ID_PAGEHEADEROPTION: 1135 case PROPERTY_ID_PAGEFOOTEROPTION: 1136 aControlValue = getConstantValue(sal_True,RID_STR_REPORTPRINTOPTION_CONST,aPropertyValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.ReportPrintOption")),PropertyName); 1137 break; 1138 case PROPERTY_ID_KEEPTOGETHER: 1139 if ( uno::Reference< report::XGroup>(m_xReportComponent,uno::UNO_QUERY).is()) 1140 { 1141 aControlValue = getConstantValue(sal_True,RID_STR_KEEPTOGETHER_CONST,aPropertyValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.KeepTogether")),PropertyName); 1142 break; 1143 } 1144 // run through 1145 case PROPERTY_ID_VISIBLE: 1146 case PROPERTY_ID_CANGROW: 1147 case PROPERTY_ID_CANSHRINK: 1148 case PROPERTY_ID_REPEATSECTION: 1149 case PROPERTY_ID_PRINTREPEATEDVALUES: 1150 case PROPERTY_ID_STARTNEWCOLUMN: 1151 case PROPERTY_ID_RESETPAGENUMBER: 1152 case PROPERTY_ID_PRINTWHENGROUPCHANGE: 1153 case PROPERTY_ID_DEEPTRAVERSING: 1154 case PROPERTY_ID_PREEVALUATED: 1155 case PROPERTY_ID_PRESERVEIRI: 1156 case PROPERTY_ID_BACKTRANSPARENT: 1157 case PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT: 1158 { 1159 if ( _rControlValueType.getTypeClass() == uno::TypeClass_STRING ) 1160 { 1161 const uno::Reference< inspection::XStringRepresentation > xConversionHelper = inspection::StringRepresentation::create( m_xContext,m_xTypeConverter ); 1162 aControlValue <<= xConversionHelper->convertToControlValue( aPropertyValue ); 1163 } 1164 else 1165 { 1166 try 1167 { 1168 aControlValue = m_xTypeConverter->convertTo( aPropertyValue, _rControlValueType ); 1169 } 1170 catch( const uno::Exception& ) 1171 { 1172 OSL_ENSURE( sal_False, "GeometryHandler::convertToControlValue: caught an exception while converting via TypeConverter!" ); 1173 } 1174 } 1175 break; 1176 } 1177 case PROPERTY_ID_CONDITIONALPRINTEXPRESSION: 1178 case PROPERTY_ID_INITIALFORMULA: 1179 case PROPERTY_ID_FORMULA: 1180 lcl_convertFormulaTo(aPropertyValue,aControlValue); 1181 break; 1182 case PROPERTY_ID_DATAFIELD: 1183 { 1184 ::rtl::OUString sValue; 1185 aControlValue >>= sValue; 1186 if ( isDefaultFunction(sValue,sValue) ) 1187 aControlValue <<= sValue; 1188 else 1189 lcl_convertFormulaTo(aPropertyValue,aControlValue); 1190 } 1191 break; 1192 case PROPERTY_ID_FONT: 1193 aControlValue = m_xFormComponentHandler->convertToControlValue(PROPERTY_FONT, aPropertyValue, _rControlValueType); 1194 break; 1195 case PROPERTY_ID_POSITIONX: 1196 { 1197 sal_Int32 nPosX = 0; 1198 aPropertyValue >>= nPosX; 1199 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY); 1200 if ( xSourceReportComponent->getSection().is() ) 1201 nPosX -= getStyleProperty<sal_Int32>(xSourceReportComponent->getSection()->getReportDefinition(),PROPERTY_LEFTMARGIN); 1202 aPropertyValue <<= nPosX; 1203 aControlValue = m_xFormComponentHandler->convertToControlValue(PropertyName, aPropertyValue, _rControlValueType); 1204 } 1205 break; 1206 case PROPERTY_ID_FORMULALIST: 1207 aControlValue <<= m_sDefaultFunction; 1208 break; 1209 case PROPERTY_ID_SCOPE: 1210 aControlValue <<= m_sScope; 1211 break; 1212 case PROPERTY_ID_MIMETYPE: 1213 aControlValue = aPropertyValue; 1214 break; 1215 case PROPERTY_ID_TYPE: 1216 { 1217 ::std::vector< ::rtl::OUString > aList; 1218 tools::StringListResource aRes(ModuleRes(RID_STR_TYPE_CONST),aList); 1219 if ( m_nDataFieldType < aList.size() ) 1220 aControlValue <<= aList[m_nDataFieldType]; 1221 } 1222 break; 1223 case PROPERTY_ID_VERTICALALIGN: 1224 { 1225 style::VerticalAlignment nParagraphVertAlign = style::VerticalAlignment_TOP; 1226 aPropertyValue >>= nParagraphVertAlign; 1227 ::std::vector< ::rtl::OUString > aList; 1228 tools::StringListResource aRes(ModuleRes(RID_STR_VERTICAL_ALIGN_CONST),aList); 1229 if ( static_cast<sal_Int16>(nParagraphVertAlign) < static_cast<sal_Int16>(aList.size()) ) 1230 aControlValue <<= aList[nParagraphVertAlign]; 1231 } 1232 break; 1233 case PROPERTY_ID_PARAADJUST: 1234 { 1235 sal_Int16 nParagraphAdjust = style::ParagraphAdjust_LEFT; 1236 aPropertyValue >>= nParagraphAdjust; 1237 ::std::vector< ::rtl::OUString > aList; 1238 tools::StringListResource aRes(ModuleRes(RID_STR_PARAADJUST_CONST),aList); 1239 if ( nParagraphAdjust < static_cast<sal_Int16>(aList.size()) ) 1240 aControlValue <<= aList[nParagraphAdjust]; 1241 } 1242 break; 1243 case PROPERTY_ID_BACKCOLOR: 1244 case PROPERTY_ID_CONTROLBACKGROUND: 1245 { 1246 sal_Int32 nColor = COL_TRANSPARENT; 1247 if ( (aPropertyValue >>= nColor) && static_cast<sal_Int32>(COL_TRANSPARENT) == nColor ) 1248 aPropertyValue.clear(); 1249 } 1250 // run through 1251 default: 1252 aControlValue = m_xFormComponentHandler->convertToControlValue(PropertyName, aPropertyValue, _rControlValueType); 1253 } 1254 return aControlValue; 1255 } 1256 void SAL_CALL GeometryHandler::addPropertyChangeListener(const uno::Reference< beans::XPropertyChangeListener > & _rxListener) throw (uno::RuntimeException, lang::NullPointerException) 1257 { 1258 ::osl::MutexGuard aGuard( m_aMutex ); 1259 m_aPropertyListeners.addListener( _rxListener ); 1260 m_xFormComponentHandler->addPropertyChangeListener(_rxListener); 1261 } 1262 1263 void SAL_CALL GeometryHandler::removePropertyChangeListener(const uno::Reference< beans::XPropertyChangeListener > & _rxListener) throw (uno::RuntimeException) 1264 { 1265 ::osl::MutexGuard aGuard( m_aMutex ); 1266 m_aPropertyListeners.removeListener( _rxListener ); 1267 m_xFormComponentHandler->removePropertyChangeListener(_rxListener); 1268 } 1269 // ----------------------------------------------------------------------------- 1270 //-------------------------------------------------------------------------- 1271 uno::Sequence< beans::Property > SAL_CALL GeometryHandler::getSupportedProperties() throw (uno::RuntimeException) 1272 { 1273 ::std::vector< beans::Property > aNewProps; 1274 aNewProps.reserve(20); // only a guess 1275 m_pInfoService->getExcludeProperties( aNewProps, m_xFormComponentHandler ); 1276 1277 const ::rtl::OUString pIncludeProperties[] = 1278 { 1279 PROPERTY_FORCENEWPAGE 1280 ,PROPERTY_KEEPTOGETHER 1281 ,PROPERTY_CANGROW 1282 ,PROPERTY_CANSHRINK 1283 ,PROPERTY_REPEATSECTION 1284 ,PROPERTY_PRINTREPEATEDVALUES 1285 ,PROPERTY_CONDITIONALPRINTEXPRESSION 1286 ,PROPERTY_STARTNEWCOLUMN 1287 ,PROPERTY_RESETPAGENUMBER 1288 ,PROPERTY_PRINTWHENGROUPCHANGE 1289 ,PROPERTY_VISIBLE 1290 ,PROPERTY_PAGEHEADEROPTION 1291 ,PROPERTY_PAGEFOOTEROPTION 1292 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlLabel")) 1293 ,PROPERTY_POSITIONX 1294 ,PROPERTY_POSITIONY 1295 ,PROPERTY_WIDTH 1296 ,PROPERTY_HEIGHT 1297 ,PROPERTY_PREEVALUATED 1298 ,PROPERTY_DEEPTRAVERSING 1299 ,PROPERTY_FORMULA 1300 ,PROPERTY_INITIALFORMULA 1301 ,PROPERTY_PRESERVEIRI 1302 ,PROPERTY_DATAFIELD 1303 ,PROPERTY_FONT 1304 ,PROPERTY_BACKCOLOR 1305 ,PROPERTY_BACKTRANSPARENT 1306 ,PROPERTY_CONTROLBACKGROUND 1307 ,PROPERTY_CONTROLBACKGROUNDTRANSPARENT 1308 ,PROPERTY_LABEL 1309 ,PROPERTY_MIMETYPE 1310 ,PROPERTY_VERTICALALIGN 1311 ,PROPERTY_PARAADJUST 1312 }; 1313 const uno::Reference < beans::XPropertySetInfo > xInfo = m_xReportComponent->getPropertySetInfo(); 1314 const uno::Sequence< beans::Property> aSeq = xInfo->getProperties(); 1315 for (size_t i = 0; i < sizeof(pIncludeProperties)/sizeof(pIncludeProperties[0]) ;++i ) 1316 { 1317 const beans::Property* pIter = aSeq.getConstArray(); 1318 const beans::Property* pEnd = pIter + aSeq.getLength(); 1319 const beans::Property* pFind = ::std::find_if(pIter,pEnd,::std::bind2nd(PropertyCompare(),boost::cref(pIncludeProperties[i]))); 1320 if ( pFind != pEnd ) 1321 { 1322 // special case for controls which contain a data field 1323 if ( PROPERTY_DATAFIELD == pIncludeProperties[i] ) 1324 { 1325 beans::Property aValue; 1326 aValue.Name = PROPERTY_FORMULALIST; 1327 aNewProps.push_back(aValue); 1328 aValue.Name = PROPERTY_SCOPE; 1329 aNewProps.push_back(aValue); 1330 aValue.Name = PROPERTY_TYPE; 1331 aNewProps.push_back(aValue); 1332 } 1333 aNewProps.push_back(*pFind); 1334 } 1335 } // for (size_t i = 0; i < sizeof(pIncludeProperties)/sizeof(pIncludeProperties[0]) ;++i ) 1336 1337 // special property for shapes 1338 // if ( uno::Reference< report::XShape>(m_xReportComponent,uno::UNO_QUERY).is() ) 1339 // { 1340 // beans::Property aValue; 1341 // aValue.Name = PROPERTY_AREA; 1342 // aNewProps.push_back(aValue); 1343 // } 1344 // re-enable when the remaining issues of #i88727# are fixed 1345 1346 return uno::Sequence< beans::Property > (&(*aNewProps.begin()),aNewProps.size()); 1347 } 1348 1349 uno::Sequence< ::rtl::OUString > SAL_CALL GeometryHandler::getSupersededProperties() throw (uno::RuntimeException) 1350 { 1351 uno::Sequence< ::rtl::OUString > aRet; 1352 const uno::Reference<report::XReportDefinition> xReport(m_xReportComponent,uno::UNO_QUERY); 1353 if ( xReport.is() && !uno::Reference< report::XSection>(xReport->getParent(),uno::UNO_QUERY).is() ) 1354 { 1355 aRet.realloc(5); 1356 ::rtl::OUString* pIter = aRet.getArray(); 1357 *pIter++ = PROPERTY_POSITIONX; 1358 *pIter++ = PROPERTY_POSITIONY; 1359 *pIter++ = PROPERTY_WIDTH; 1360 *pIter++ = PROPERTY_HEIGHT; 1361 *pIter++ = PROPERTY_DATAFIELD; 1362 } 1363 return aRet; 1364 } 1365 1366 uno::Sequence< ::rtl::OUString > SAL_CALL GeometryHandler::getActuatingProperties() throw (uno::RuntimeException) 1367 { 1368 ::osl::MutexGuard aGuard( m_aMutex ); 1369 1370 uno::Sequence< ::rtl::OUString > aSeq(5); 1371 aSeq[0] = PROPERTY_BACKTRANSPARENT; 1372 aSeq[1] = PROPERTY_CONTROLBACKGROUNDTRANSPARENT; 1373 aSeq[2] = PROPERTY_FORMULALIST; 1374 aSeq[3] = PROPERTY_TYPE; 1375 aSeq[4] = PROPERTY_DATAFIELD; 1376 1377 return ::comphelper::concatSequences(m_xFormComponentHandler->getActuatingProperties(),aSeq); 1378 } 1379 1380 ::sal_Bool SAL_CALL GeometryHandler::isComposable(const ::rtl::OUString & _rPropertyName) throw (uno::RuntimeException, beans::UnknownPropertyException) 1381 { 1382 return m_pInfoService->isComposable( _rPropertyName, m_xFormComponentHandler ); 1383 } 1384 1385 inspection::InteractiveSelectionResult SAL_CALL GeometryHandler::onInteractivePropertySelection(const ::rtl::OUString & PropertyName, ::sal_Bool Primary, uno::Any & _rData, const uno::Reference< inspection::XObjectInspectorUI > & _rxInspectorUI) throw (uno::RuntimeException, beans::UnknownPropertyException, lang::NullPointerException) 1386 { 1387 if ( !_rxInspectorUI.is() ) 1388 throw lang::NullPointerException(); 1389 if ( PropertyName.equalsAscii(PROPERTY_FILTER) ) 1390 { 1391 ::osl::ClearableMutexGuard aGuard( m_aMutex ); 1392 1393 inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled; 1394 ::rtl::OUString sClause; 1395 if ( impl_dialogFilter_nothrow( sClause, aGuard ) ) 1396 { 1397 _rData <<= sClause; 1398 eResult = inspection::InteractiveSelectionResult_ObtainedValue; 1399 } 1400 return eResult; 1401 } 1402 else if ( PropertyName.equalsAscii(PROPERTY_FONT) ) 1403 { 1404 ::osl::ClearableMutexGuard aGuard( m_aMutex ); 1405 1406 inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled; 1407 const uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DialogParentWindow"))) ,uno::UNO_QUERY); 1408 const uno::Reference< report::XReportControlFormat> xReportControlFormat(m_xReportComponent,uno::UNO_QUERY); 1409 aGuard.clear(); 1410 1411 uno::Sequence< beans::NamedValue > aFontSettings; 1412 if ( rptui::openCharDialog( xReportControlFormat, xInspectorWindow, aFontSettings ) ) 1413 { 1414 _rData <<= aFontSettings; 1415 eResult = inspection::InteractiveSelectionResult_ObtainedValue; 1416 } 1417 return eResult; 1418 } 1419 else if ( PropertyName.equalsAscii(PROPERTY_FORMULA) 1420 || PropertyName.equalsAscii(PROPERTY_INITIALFORMULA) 1421 || PropertyName.equalsAscii(PROPERTY_DATAFIELD) 1422 || PropertyName.equalsAscii(PROPERTY_CONDITIONALPRINTEXPRESSION)) 1423 { 1424 ::osl::ClearableMutexGuard aGuard( m_aMutex ); 1425 1426 1427 ::rtl::OUString sFormula; 1428 m_xReportComponent->getPropertyValue(PropertyName) >>= sFormula; 1429 const uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DialogParentWindow"))) ,uno::UNO_QUERY); 1430 uno::Reference< uno::XComponentContext > xContext = m_xContext; 1431 uno::Reference< beans::XPropertySet > xRowSet( m_xRowSet,uno::UNO_QUERY); 1432 aGuard.clear(); 1433 1434 inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled; 1435 if ( rptui::openDialogFormula_nothrow( sFormula, xContext,xInspectorWindow,xRowSet ) ) 1436 { 1437 _rData <<= sFormula; 1438 eResult = inspection::InteractiveSelectionResult_ObtainedValue; 1439 } 1440 return eResult; 1441 } 1442 else if ( PropertyName.equalsAscii(PROPERTY_AREA) ) 1443 { 1444 ::osl::ClearableMutexGuard aGuard( m_aMutex ); 1445 1446 inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled; 1447 const uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DialogParentWindow"))) ,uno::UNO_QUERY); 1448 const uno::Reference< report::XShape> xShape(m_xReportComponent,uno::UNO_QUERY); 1449 aGuard.clear(); 1450 1451 if ( rptui::openAreaDialog( xShape, xInspectorWindow) ) 1452 { 1453 eResult = inspection::InteractiveSelectionResult_ObtainedValue; 1454 beans::PropertyChangeEvent aScopeEvent; 1455 aScopeEvent.PropertyName = PROPERTY_FILLCOLOR; 1456 // aScopeEvent.OldValue <<= _nOldDataFieldType; 1457 aScopeEvent.NewValue <<= xShape->getPropertyValue(PROPERTY_FILLCOLOR); 1458 m_aPropertyListeners.notify( aScopeEvent, &beans::XPropertyChangeListener::propertyChange ); 1459 } 1460 return eResult; 1461 } 1462 1463 1464 return m_xFormComponentHandler->onInteractivePropertySelection(PropertyName, Primary, _rData, _rxInspectorUI); 1465 } 1466 1467 void SAL_CALL GeometryHandler::actuatingPropertyChanged(const ::rtl::OUString & ActuatingPropertyName, const uno::Any & NewValue, const uno::Any & OldValue, const uno::Reference< inspection::XObjectInspectorUI > & _rxInspectorUI, ::sal_Bool _bFirstTimeInit) throw (uno::RuntimeException, lang::NullPointerException) 1468 { 1469 if ( !_rxInspectorUI.is() ) 1470 throw lang::NullPointerException(); 1471 1472 ::osl::MutexGuard aGuard( m_aMutex ); 1473 const sal_Int32 nId = m_pInfoService->getPropertyId(ActuatingPropertyName); 1474 switch(nId) 1475 { 1476 case PROPERTY_ID_TYPE: 1477 { 1478 sal_uInt32 nNewVal = 0; 1479 NewValue >>= nNewVal; 1480 switch(nNewVal) 1481 { 1482 case DATA_OR_FORMULA: 1483 _rxInspectorUI->rebuildPropertyUI(PROPERTY_DATAFIELD); 1484 _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,sal_True); 1485 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,sal_False); 1486 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,sal_False); 1487 OSL_ENSURE(m_sDefaultFunction.getLength() == 0,"Why is the m_sDefaultFunction set?"); 1488 OSL_ENSURE(m_sScope.getLength() == 0,"Why is the m_sScope set?"); 1489 break; 1490 case FUNCTION: 1491 _rxInspectorUI->rebuildPropertyUI(PROPERTY_DATAFIELD); 1492 _rxInspectorUI->rebuildPropertyUI(PROPERTY_FORMULALIST); 1493 _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,sal_True); 1494 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,m_sDefaultFunction.getLength() != 0); 1495 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,m_sScope.getLength() != 0); 1496 break; 1497 case USER_DEF_FUNCTION: 1498 _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,sal_False); 1499 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,sal_True); 1500 _rxInspectorUI->rebuildPropertyUI(PROPERTY_FORMULALIST); 1501 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,sal_False); 1502 break; 1503 case COUNTER: 1504 _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,sal_False); 1505 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,sal_False); 1506 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,sal_True); 1507 break; 1508 } 1509 } 1510 break; 1511 case PROPERTY_ID_DATAFIELD: 1512 { 1513 sal_Bool bEnable = (m_nDataFieldType != DATA_OR_FORMULA && m_nDataFieldType != COUNTER ); 1514 if ( bEnable ) 1515 { 1516 ::rtl::OUString sValue; 1517 m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD ) >>= sValue; 1518 bEnable = sValue.getLength() != 0; 1519 } 1520 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,bEnable); 1521 if ( bEnable ) 1522 { 1523 _rxInspectorUI->rebuildPropertyUI(PROPERTY_DATAFIELD); 1524 _rxInspectorUI->rebuildPropertyUI(PROPERTY_FORMULALIST); 1525 } // if ( bEnable ) 1526 m_xFormComponentHandler->actuatingPropertyChanged(ActuatingPropertyName, NewValue, OldValue, _rxInspectorUI, _bFirstTimeInit); 1527 } 1528 break; 1529 case PROPERTY_ID_FORMULALIST: 1530 { 1531 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,m_nDataFieldType == FUNCTION || m_nDataFieldType == COUNTER); 1532 } 1533 break; 1534 case PROPERTY_ID_BACKTRANSPARENT: 1535 case PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT: 1536 { 1537 sal_Bool bValue = sal_False; 1538 NewValue >>= bValue; 1539 bValue = !bValue; 1540 _rxInspectorUI->enablePropertyUI(PROPERTY_BACKCOLOR,bValue); 1541 _rxInspectorUI->enablePropertyUI(PROPERTY_CONTROLBACKGROUND,bValue); 1542 } 1543 break; 1544 default: 1545 m_xFormComponentHandler->actuatingPropertyChanged(ActuatingPropertyName, NewValue, OldValue, _rxInspectorUI, _bFirstTimeInit); 1546 break; 1547 } 1548 } 1549 1550 ::sal_Bool SAL_CALL GeometryHandler::suspend(::sal_Bool Suspend) throw (uno::RuntimeException) 1551 { 1552 return m_xFormComponentHandler->suspend(Suspend); 1553 } 1554 // ----------------------------------------------------------------------------- 1555 bool GeometryHandler::impl_dialogFilter_nothrow( ::rtl::OUString& _out_rSelectedClause, ::osl::ClearableMutexGuard& _rClearBeforeDialog ) const 1556 { 1557 _out_rSelectedClause = ::rtl::OUString(); 1558 bool bSuccess = false; 1559 ::dbtools::SQLExceptionInfo aErrorInfo; 1560 uno::Reference< awt::XWindow > xInspectorWindow; 1561 uno::Reference< lang::XMultiComponentFactory > xFactory; 1562 uno::Reference<lang::XMultiServiceFactory> xServiceFactory; 1563 try 1564 { 1565 xFactory = m_xContext->getServiceManager(); 1566 xServiceFactory.set(xFactory,uno::UNO_QUERY); 1567 xInspectorWindow.set(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DialogParentWindow"))) ,uno::UNO_QUERY); 1568 uno::Reference<sdbc::XConnection> xCon(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ActiveConnection"))) ,uno::UNO_QUERY); 1569 if ( !xCon.is() ) 1570 return false; 1571 1572 uno::Reference< beans::XPropertySet> xRowSetProp(m_xRowSet,uno::UNO_QUERY); 1573 if ( !m_xRowSet.is() ) 1574 { 1575 m_xRowSet.set(xFactory->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.RowSet")),m_xContext),uno::UNO_QUERY); 1576 xRowSetProp.set(m_xRowSet,uno::UNO_QUERY); 1577 xRowSetProp->setPropertyValue(PROPERTY_ACTIVECONNECTION,uno::makeAny(xCon)); 1578 ::comphelper::copyProperties(m_xReportComponent,xRowSetProp); 1579 } 1580 1581 // get a composer for the statement which the form is currently based on 1582 uno::Reference< sdb::XSingleSelectQueryComposer > xComposer( ::dbtools::getCurrentSettingsComposer( xRowSetProp, xServiceFactory ) ); 1583 OSL_ENSURE( xComposer.is(), "GeometryHandler::impl_dialogFilter_nothrow: could not obtain a composer!" ); 1584 if ( !xComposer.is() ) 1585 return false; 1586 1587 // create the dialog 1588 uno::Reference< ui::dialogs::XExecutableDialog > xDialog(xFactory->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.FilterDialog")),m_xContext),uno::UNO_QUERY); 1589 if ( !xDialog.is() ) 1590 { 1591 Window* pInspectorWindow = VCLUnoHelper::GetWindow( xInspectorWindow ); 1592 ShowServiceNotAvailableError( pInspectorWindow, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.FilterDialog")), sal_True ); 1593 return false; 1594 } 1595 1596 const String aGcc3WorkaroundTemporary( ModuleRes(RID_STR_FILTER)); 1597 const ::rtl::OUString sPropertyUIName( aGcc3WorkaroundTemporary ); 1598 // initialize the dialog 1599 uno::Reference< beans::XPropertySet > xDialogProps( xDialog, uno::UNO_QUERY_THROW ); 1600 xDialogProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "QueryComposer" ) ), uno::makeAny( xComposer ) ); 1601 xDialogProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RowSet" ) ), uno::makeAny( m_xRowSet ) ); 1602 xDialogProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" ) ), uno::makeAny( xInspectorWindow ) ); 1603 xDialogProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ), uno::makeAny( sPropertyUIName ) ); 1604 1605 _rClearBeforeDialog.clear(); 1606 bSuccess = ( xDialog->execute() != 0 ); 1607 if ( bSuccess ) 1608 _out_rSelectedClause = xComposer->getFilter(); 1609 } 1610 catch (sdb::SQLContext& e) { aErrorInfo = e; } 1611 catch (sdbc::SQLWarning& e) { aErrorInfo = e; } 1612 catch (sdbc::SQLException& e) { aErrorInfo = e; } 1613 catch( const uno::Exception& ) 1614 { 1615 OSL_ENSURE( sal_False, "GeometryHandler::impl_dialogFilter_nothrow: caught an exception!" ); 1616 } 1617 1618 if ( aErrorInfo.isValid() ) 1619 ::dbtools::showError( aErrorInfo, xInspectorWindow, xServiceFactory ); 1620 1621 return bSuccess; 1622 } 1623 // ----------------------------------------------------------------------------- 1624 void GeometryHandler::checkPosAndSize( const awt::Point& _aNewPos, 1625 const awt::Size& _aSize) 1626 { 1627 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY); 1628 const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY); 1629 if ( !xSection.is() || uno::Reference< report::XShape>(xSourceReportComponent,uno::UNO_QUERY).is() ) // shapes can overlap. 1630 return; 1631 1632 ::Point aPos(VCLPoint(_aNewPos)); 1633 if ( aPos.X() < 0 || aPos.Y() < 0 ) // TODO: have to check size with pos aka || (aPos.X() + aAwtSize.Width) > m_xSection->getReportDefinition()-> 1634 throw beans::PropertyVetoException(String(ModuleRes(RID_STR_ILLEGAL_POSITION)),xSourceReportComponent); 1635 1636 ::Rectangle aSourceRect(aPos,VCLSize(_aSize)); 1637 1638 const sal_Int32 nCount = xSection->getCount(); 1639 for (sal_Int32 i = 0; i < nCount ; ++i) 1640 { 1641 const uno::Reference< report::XReportComponent> xReportComponent(xSection->getByIndex(i),uno::UNO_QUERY); 1642 if ( xReportComponent.is() && xReportComponent != xSourceReportComponent ) 1643 { 1644 const ::Rectangle aBoundRect(VCLPoint(xReportComponent->getPosition()),VCLSize(xReportComponent->getSize())); 1645 const ::Rectangle aRect = aSourceRect.GetIntersection(aBoundRect); 1646 if ( !aRect.IsEmpty() && (aRect.Left() != aRect.Right() && aRect.Top() != aRect.Bottom() ) ) 1647 throw beans::PropertyVetoException(String(ModuleRes( RID_STR_OVERLAP_OTHER_CONTROL)),xSourceReportComponent); 1648 } 1649 } 1650 } 1651 // ----------------------------------------------------------------------------- 1652 void GeometryHandler::impl_fillFormulaList_nothrow(::std::vector< ::rtl::OUString >& _out_rList) const 1653 { 1654 if ( m_nDataFieldType == FUNCTION ) 1655 ::std::transform(m_aDefaultFunctions.begin(),m_aDefaultFunctions.end(),::std::back_inserter(_out_rList),::boost::bind( &DefaultFunction::getName, _1 )); 1656 else if ( m_nDataFieldType == USER_DEF_FUNCTION ) 1657 ::std::transform(m_aFunctionNames.begin(),m_aFunctionNames.end(),::std::back_inserter(_out_rList),::std::select1st<TFunctions::value_type>()); 1658 } 1659 // ----------------------------------------------------------------------------- 1660 ::rtl::OUString GeometryHandler::impl_ConvertUIToMimeType_nothrow(const ::rtl::OUString& _sUIName) const 1661 { 1662 ::std::vector< ::rtl::OUString > aList; 1663 impl_fillMimeTypes_nothrow(aList); 1664 ::rtl::OUString sRet; 1665 ::std::vector< ::rtl::OUString >::const_iterator aFind = ::std::find(aList.begin(),aList.end(),_sUIName); 1666 if ( aFind != aList.end() ) 1667 { 1668 const sal_Size nPos = aFind - aList.begin(); 1669 const uno::Reference< report::XReportDefinition> xReportDefinition(m_xReportComponent,uno::UNO_QUERY); 1670 if ( xReportDefinition.is() ) 1671 { 1672 const uno::Sequence< ::rtl::OUString > aMimeTypes( xReportDefinition->getAvailableMimeTypes() ); 1673 sRet = aMimeTypes[nPos]; 1674 } 1675 } // if ( aFind != aList.end() ) 1676 return sRet; 1677 } 1678 // ----------------------------------------------------------------------------- 1679 ::rtl::OUString GeometryHandler::impl_ConvertMimeTypeToUI_nothrow(const ::rtl::OUString& _sMimetype) const 1680 { 1681 uno::Reference<lang::XMultiServiceFactory> xServiceFactory(m_xContext->getServiceManager(),uno::UNO_QUERY_THROW); 1682 ::comphelper::MimeConfigurationHelper aMimeHelper(xServiceFactory); 1683 ::rtl::OUString sRet; 1684 const SfxFilter* pFilter = SfxFilter::GetDefaultFilter( aMimeHelper.GetDocServiceNameFromMediaType(_sMimetype) ); 1685 if ( pFilter ) 1686 sRet = pFilter->GetUIName(); 1687 if ( !sRet.getLength() ) 1688 sRet = _sMimetype; 1689 return sRet; 1690 } 1691 // ----------------------------------------------------------------------------- 1692 void GeometryHandler::impl_fillMimeTypes_nothrow(::std::vector< ::rtl::OUString >& _out_rList) const 1693 { 1694 try 1695 { 1696 const uno::Reference< report::XReportDefinition> xReportDefinition(m_xReportComponent,uno::UNO_QUERY); 1697 if ( xReportDefinition.is() ) 1698 { 1699 uno::Sequence< ::rtl::OUString > aMimeTypes( xReportDefinition->getAvailableMimeTypes() ); 1700 const ::rtl::OUString* pIter = aMimeTypes.getConstArray(); 1701 const ::rtl::OUString* pEnd = pIter + aMimeTypes.getLength(); 1702 for(;pIter != pEnd; ++pIter) 1703 { 1704 const ::rtl::OUString sDocName( impl_ConvertMimeTypeToUI_nothrow(*pIter) ); 1705 if ( sDocName.getLength() ) 1706 _out_rList.push_back(sDocName); 1707 } 1708 } 1709 } 1710 catch(uno::Exception&) 1711 { 1712 OSL_ENSURE(0,"Exception caught!"); 1713 } 1714 } 1715 // ----------------------------------------------------------------------------- 1716 void GeometryHandler::impl_fillScopeList_nothrow(::std::vector< ::rtl::OUString >& _out_rList) const 1717 { 1718 try 1719 { 1720 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY_THROW); 1721 const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY_THROW); 1722 1723 const uno::Reference< report::XReportDefinition> xReportDefinition = xSection->getReportDefinition(); 1724 const uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups(); 1725 sal_Int32 nPos = -1; 1726 uno::Reference< report::XGroup> xGroup = xSection->getGroup(); 1727 if ( xGroup.is() ) 1728 nPos = getPositionInIndexAccess(xGroups.get(),xGroup); 1729 else if ( xSection == xReportDefinition->getDetail() ) 1730 nPos = xGroups->getCount()-1; 1731 1732 const String sGroup = String(ModuleRes(RID_STR_SCOPE_GROUP)); 1733 for (sal_Int32 i = 0 ; i <= nPos ; ++i) 1734 { 1735 xGroup.set(xGroups->getByIndex(i),uno::UNO_QUERY_THROW); 1736 String sGroupName = sGroup; 1737 sGroupName.SearchAndReplaceAscii("%1",xGroup->getExpression()); 1738 _out_rList.push_back(sGroupName); 1739 } 1740 _out_rList.push_back(xReportDefinition->getName()); 1741 } 1742 catch(uno::Exception&) 1743 { 1744 OSL_ENSURE(0,"Exception caught!"); 1745 } 1746 } 1747 // ----------------------------------------------------------------------------- 1748 uno::Reference< report::XFunctionsSupplier> GeometryHandler::fillScope_throw(::rtl::OUString& _rsNamePostFix) 1749 { 1750 uno::Reference< report::XFunctionsSupplier> xReturn; 1751 1752 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY_THROW); 1753 const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY_THROW); 1754 const uno::Reference< report::XReportDefinition> xReportDefinition = xSection->getReportDefinition(); 1755 if ( !m_sScope.getLength() ) 1756 { 1757 const uno::Reference< report::XGroup> xGroup(xSection->getGroup(),uno::UNO_QUERY); 1758 if ( xGroup.is() ) 1759 { 1760 String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP)); 1761 _rsNamePostFix = xGroup->getExpression(); 1762 sGroupName.SearchAndReplaceAscii("%1",_rsNamePostFix); 1763 m_sScope = sGroupName; 1764 xReturn = xGroup.get(); 1765 } 1766 else if ( xSection == xReportDefinition->getDetail() ) 1767 { 1768 const uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups(); 1769 const sal_Int32 nCount = xGroups->getCount(); 1770 if ( nCount ) 1771 { 1772 const uno::Reference< report::XGroup> xGroup2(xGroups->getByIndex(nCount - 1),uno::UNO_QUERY_THROW); 1773 String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP)); 1774 _rsNamePostFix = xGroup2->getExpression(); 1775 sGroupName.SearchAndReplaceAscii("%1",_rsNamePostFix); 1776 m_sScope = sGroupName; 1777 xReturn = xGroup2.get(); 1778 } 1779 } 1780 if ( !m_sScope.getLength() ) 1781 { 1782 xReturn = xReportDefinition.get(); 1783 _rsNamePostFix = m_sScope = xReportDefinition->getName(); 1784 } 1785 } 1786 else if ( m_sScope == xReportDefinition->getName() ) 1787 { 1788 xReturn = xReportDefinition.get(); 1789 _rsNamePostFix = m_sScope; 1790 } 1791 else 1792 { 1793 uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups(); 1794 const sal_Int32 nCount = xGroups->getCount(); 1795 1796 for (sal_Int32 i = 0 ; i < nCount; ++i) 1797 { 1798 const uno::Reference< report::XGroup> xGroup(xGroups->getByIndex(i),uno::UNO_QUERY_THROW); 1799 String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP)); 1800 sGroupName.SearchAndReplaceAscii("%1",xGroup->getExpression()); 1801 if ( m_sScope == ::rtl::OUString(sGroupName) ) 1802 { 1803 _rsNamePostFix = xGroup->getExpression(); 1804 xReturn = xGroup.get(); 1805 break; 1806 } 1807 } 1808 1809 } 1810 OSL_ENSURE(xReturn.is(),"Why don't we have a functionssupplier here!"); 1811 1812 return xReturn; 1813 } 1814 // ----------------------------------------------------------------------------- 1815 sal_Bool GeometryHandler::isDefaultFunction( const ::rtl::OUString& _sQuotedFunction 1816 ,::rtl::OUString& _rDataField 1817 ,const uno::Reference< report::XFunctionsSupplier>& _xFunctionsSupplier 1818 ,bool _bSet) const 1819 { 1820 sal_Bool bDefaultFunction = sal_False; 1821 try 1822 { 1823 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY_THROW); 1824 const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY_THROW); 1825 const uno::Reference< report::XReportDefinition> xReportDefinition = xSection->getReportDefinition(); 1826 1827 ::std::pair<TFunctions::const_iterator,TFunctions::const_iterator> aFind = m_aFunctionNames.equal_range(_sQuotedFunction); 1828 while ( aFind.first != aFind.second ) 1829 { 1830 if ( !_xFunctionsSupplier.is() || _xFunctionsSupplier == aFind.first->second.second ) 1831 { 1832 const beans::Optional< ::rtl::OUString> aInitalFormula = aFind.first->second.first->getInitialFormula(); 1833 if ( aInitalFormula.IsPresent ) 1834 { 1835 ::rtl::OUString sDefaultFunctionName; 1836 bDefaultFunction = impl_isDefaultFunction_nothrow(aFind.first->second.first,_rDataField,sDefaultFunctionName); 1837 if ( bDefaultFunction ) 1838 { 1839 m_xFunction = aFind.first->second.first; 1840 if ( _bSet ) 1841 { 1842 m_sDefaultFunction = sDefaultFunctionName; 1843 uno::Reference< report::XGroup> xGroup(aFind.first->second.second,uno::UNO_QUERY); 1844 if ( xGroup.is() ) 1845 { 1846 String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP)); 1847 sGroupName.SearchAndReplaceAscii("%1",xGroup->getExpression()); 1848 m_sScope = sGroupName; 1849 } 1850 else 1851 m_sScope = xReportDefinition->getName(); 1852 } 1853 } 1854 break; 1855 } 1856 } 1857 ++(aFind.first); 1858 } 1859 } 1860 catch(uno::Exception&) 1861 { 1862 OSL_ENSURE(0,"Exception caught!"); 1863 } 1864 return bDefaultFunction; 1865 } 1866 // ----------------------------------------------------------------------------- 1867 sal_Bool GeometryHandler::impl_isDefaultFunction_nothrow( const uno::Reference< report::XFunction>& _xFunction 1868 ,::rtl::OUString& _rDataField 1869 ,::rtl::OUString& _rsDefaultFunctionName) const 1870 { 1871 sal_Bool bDefaultFunction = sal_False; 1872 try 1873 { 1874 const String sFormula( _xFunction->getFormula() ); 1875 util::SearchOptions aSearchOptions; 1876 aSearchOptions.algorithmType = util::SearchAlgorithms_REGEXP; 1877 aSearchOptions.searchFlag = 0x00000100; 1878 ::std::vector< DefaultFunction >::const_iterator aIter = m_aDefaultFunctions.begin(); 1879 ::std::vector< DefaultFunction >::const_iterator aDeEnd = m_aDefaultFunctions.end(); 1880 for (; aIter != aDeEnd; ++aIter) 1881 { 1882 aSearchOptions.searchString = aIter->m_sSearchString; 1883 utl::TextSearch aTextSearch(aSearchOptions); 1884 xub_StrLen start = 0; 1885 xub_StrLen end = sFormula.Len(); 1886 if ( aTextSearch.SearchFrwrd(sFormula,&start,&end) && start == 0 && end == sFormula.Len()) // default function found 1887 { 1888 aSearchOptions.searchString = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]")); 1889 utl::TextSearch aDataSearch(aSearchOptions); 1890 aDataSearch.SearchFrwrd(sFormula,&start,&end ); 1891 ++start; 1892 _rDataField = sFormula.Copy(start,end-start-1); 1893 _rsDefaultFunctionName = aIter->m_sName; 1894 break; 1895 } 1896 } 1897 1898 bDefaultFunction = aIter != aDeEnd; 1899 } 1900 catch(uno::Exception&) 1901 { 1902 OSL_ENSURE(0,"Exception caught!"); 1903 } 1904 return bDefaultFunction; 1905 } 1906 // ----------------------------------------------------------------------------- 1907 void GeometryHandler::loadDefaultFunctions() 1908 { 1909 if ( m_aDefaultFunctions.empty() ) 1910 { 1911 m_aCounterFunction.m_bPreEvaluated = sal_False; 1912 m_aCounterFunction.m_bDeepTraversing = sal_False; 1913 m_aCounterFunction.m_sName = String(ModuleRes(RID_STR_F_COUNTER)); 1914 m_aCounterFunction.m_sFormula = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:[%FunctionName] + 1")); 1915 m_aCounterFunction.m_sSearchString = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:\\[[:alpha:]+([:space:]*[:alnum:]*)*\\][:space:]*\\+[:space:]*[:digit:]*")); 1916 m_aCounterFunction.m_sInitialFormula.IsPresent = sal_True; 1917 m_aCounterFunction.m_sInitialFormula.Value = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:1")); 1918 1919 DefaultFunction aDefault; 1920 aDefault.m_bDeepTraversing = sal_False; 1921 1922 //aDefault.m_sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Counter")); 1923 //aDefault.m_sFormula = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:[%FunctionName] + 1")); 1924 //aDefault.m_sSearchString = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:\\[[:alpha:]+[:alnum:]*\\][:space:]*\\+[:space:]*1")); 1925 //aDefault.m_sInitialFormula.IsPresent = sal_True; 1926 //aDefault.m_sInitialFormula.Value = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:1")); 1927 //m_aDefaultFunctions.push_back(aDefault); 1928 1929 aDefault.m_bPreEvaluated = sal_True; 1930 1931 aDefault.m_sName = String(ModuleRes(RID_STR_F_ACCUMULATION)); 1932 aDefault.m_sFormula = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:[%Column] + [%FunctionName]")); 1933 aDefault.m_sSearchString = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:\\[[:alpha:]+([:space:]*[:alnum:]*)*\\][:space:]*\\+[:space:]*\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]")); 1934 aDefault.m_sInitialFormula.IsPresent = sal_True; 1935 aDefault.m_sInitialFormula.Value = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:[%Column]")); 1936 m_aDefaultFunctions.push_back(aDefault); 1937 1938 aDefault.m_sName = String(ModuleRes(RID_STR_F_MINIMUM)); 1939 aDefault.m_sFormula = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:IF([%Column] < [%FunctionName];[%Column];[%FunctionName])")); 1940 aDefault.m_sSearchString = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:IF\\((\\[[:alpha:]+([:space:]*[:alnum:]*)*\\])[:space:]*<[:space:]*(\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]);[:space:]*\\1[:space:]*;[:space:]*\\3[:space:]*\\)")); 1941 aDefault.m_sInitialFormula.IsPresent = sal_True; 1942 aDefault.m_sInitialFormula.Value = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:[%Column]")); 1943 m_aDefaultFunctions.push_back(aDefault); 1944 1945 aDefault.m_sName = String(ModuleRes(RID_STR_F_MAXIMUM)); 1946 aDefault.m_sFormula = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:IF([%Column] > [%FunctionName];[%Column];[%FunctionName])")); 1947 aDefault.m_sSearchString = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:IF\\((\\[[:alpha:]+([:space:]*[:alnum:]*)*\\])[:space:]*>[:space:]*(\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]);[:space:]*\\1[:space:]*;[:space:]*\\3[:space:]*\\)")); 1948 aDefault.m_sInitialFormula.IsPresent = sal_True; 1949 aDefault.m_sInitialFormula.Value = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:[%Column]")); 1950 m_aDefaultFunctions.push_back(aDefault); 1951 } 1952 } 1953 // ----------------------------------------------------------------------------- 1954 void GeometryHandler::createDefaultFunction(::osl::ResettableMutexGuard& _aGuard ,const ::rtl::OUString& _sFunction,const ::rtl::OUString& _sDataField) 1955 { 1956 try 1957 { 1958 ::rtl::OUString sNamePostFix; 1959 const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostFix); 1960 1961 ::std::vector< DefaultFunction >::const_iterator aIter = m_aDefaultFunctions.begin(); 1962 ::std::vector< DefaultFunction >::const_iterator aDeEnd = m_aDefaultFunctions.end(); 1963 for (; aIter != aDeEnd; ++aIter) 1964 { 1965 if ( aIter->m_sName == _sFunction ) 1966 { 1967 const ::rtl::OUString sFunctionName( _sFunction + _sDataField + sNamePostFix); 1968 const ::rtl::OUString sQuotedFunctionName(lcl_getQuotedFunctionName(sFunctionName)); 1969 1970 beans::PropertyChangeEvent aEvent; 1971 aEvent.PropertyName = PROPERTY_SCOPE; 1972 aEvent.OldValue <<= m_sScope; 1973 1974 ::std::pair<TFunctions::const_iterator,TFunctions::const_iterator> aFind = m_aFunctionNames.equal_range(sQuotedFunctionName); 1975 while ( aFind.first != aFind.second ) 1976 { 1977 if ( xFunctionsSupplier == aFind.first->second.second ) 1978 { 1979 m_xFunction = aFind.first->second.first; 1980 ::rtl::OUString sTemp; 1981 isDefaultFunction(sQuotedFunctionName,sTemp,uno::Reference< report::XFunctionsSupplier>(),true); // implicitly sets the m_sScope 1982 break; 1983 } 1984 ++(aFind.first); 1985 } 1986 if ( aFind.first == aFind.second ) 1987 impl_createFunction(sFunctionName,_sDataField,*aIter); 1988 1989 OBlocker aBlocker(m_bIn); 1990 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny( impl_convertToFormula( uno::makeAny(sQuotedFunctionName) ))); 1991 aEvent.NewValue <<= m_sScope; 1992 _aGuard.clear(); 1993 m_aPropertyListeners.notify( aEvent, &beans::XPropertyChangeListener::propertyChange ); 1994 break; 1995 } 1996 } 1997 } 1998 catch(uno::Exception&) 1999 { 2000 OSL_ENSURE(0,"Exception caught!"); 2001 } 2002 } 2003 // ----------------------------------------------------------------------------- 2004 void GeometryHandler::removeFunction() 2005 { 2006 if ( m_xFunction.is() ) 2007 { 2008 const ::rtl::OUString sQuotedFunctionName(lcl_getQuotedFunctionName(m_xFunction)); 2009 ::std::pair<TFunctions::iterator,TFunctions::iterator> aFind = m_aFunctionNames.equal_range(sQuotedFunctionName); 2010 while ( aFind.first != aFind.second ) 2011 { 2012 if ( aFind.first->second.first == m_xFunction ) 2013 { 2014 uno::Reference< report::XFunctions> xFunctions = aFind.first->second.second->getFunctions(); 2015 xFunctions->removeByIndex(xFunctions->getCount() - 1 ); /// TODO: insert new method in XFunctions: removeFunction(xfunction) 2016 m_aFunctionNames.erase(aFind.first); 2017 m_bNewFunction = false; 2018 break; 2019 } 2020 ++(aFind.first); 2021 } 2022 } 2023 } 2024 // ----------------------------------------------------------------------------- 2025 void GeometryHandler::resetOwnProperties(::osl::ResettableMutexGuard& _aGuard,const ::rtl::OUString& _sOldFunctionName,const ::rtl::OUString& _sOldScope,const sal_uInt32 _nOldDataFieldType) 2026 { 2027 const ::rtl::OUString sNewFunction = m_sDefaultFunction; 2028 const ::rtl::OUString sNewScope = m_sScope; 2029 const sal_uInt32 nNewDataFieldType = m_nDataFieldType; 2030 _aGuard.clear(); 2031 if ( _nOldDataFieldType != nNewDataFieldType ) 2032 { 2033 beans::PropertyChangeEvent aScopeEvent; 2034 aScopeEvent.PropertyName = PROPERTY_TYPE; 2035 aScopeEvent.OldValue <<= _nOldDataFieldType; 2036 aScopeEvent.NewValue <<= nNewDataFieldType; 2037 m_aPropertyListeners.notify( aScopeEvent, &beans::XPropertyChangeListener::propertyChange ); 2038 } 2039 if ( _sOldFunctionName != sNewFunction ) 2040 { 2041 beans::PropertyChangeEvent aFormulaEvent; 2042 aFormulaEvent.PropertyName = PROPERTY_FORMULALIST; 2043 aFormulaEvent.OldValue <<= _sOldFunctionName; 2044 aFormulaEvent.NewValue <<= sNewFunction; 2045 2046 m_aPropertyListeners.notify( aFormulaEvent, &beans::XPropertyChangeListener::propertyChange ); 2047 } 2048 if ( _sOldScope != sNewScope ) 2049 { 2050 beans::PropertyChangeEvent aScopeEvent; 2051 aScopeEvent.PropertyName = PROPERTY_SCOPE; 2052 aScopeEvent.OldValue <<= _sOldScope; 2053 aScopeEvent.NewValue <<= sNewScope; 2054 m_aPropertyListeners.notify( aScopeEvent, &beans::XPropertyChangeListener::propertyChange ); 2055 } 2056 2057 _aGuard.reset(); 2058 } 2059 //------------------------------------------------------------------------ 2060 void GeometryHandler::impl_initFieldList_nothrow( uno::Sequence< ::rtl::OUString >& _rFieldNames ) const 2061 { 2062 _rFieldNames.realloc(0); 2063 try 2064 { 2065 uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DialogParentWindow"))) ,uno::UNO_QUERY); 2066 Window* pInspectorWindow = VCLUnoHelper::GetWindow( xInspectorWindow ); 2067 WaitObject aWaitCursor( pInspectorWindow ); 2068 2069 uno::Reference< sdbc::XPreparedStatement > xStatement; 2070 2071 // get the form of the control we're inspecting 2072 uno::Reference< beans::XPropertySet > xFormSet( m_xRowSet, uno::UNO_QUERY ); 2073 if ( !xFormSet.is() ) 2074 return; 2075 2076 ::rtl::OUString sObjectName; 2077 OSL_VERIFY( xFormSet->getPropertyValue( PROPERTY_COMMAND ) >>= sObjectName ); 2078 // when there is no command we don't need to ask for columns 2079 uno::Reference<sdbc::XConnection> xCon(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ActiveConnection"))) ,uno::UNO_QUERY); 2080 if ( sObjectName.getLength() && xCon.is() ) 2081 { 2082 sal_Int32 nObjectType = sdb::CommandType::COMMAND; 2083 OSL_VERIFY( xFormSet->getPropertyValue( PROPERTY_COMMANDTYPE ) >>= nObjectType ); 2084 2085 _rFieldNames = ::dbtools::getFieldNamesByCommandDescriptor( xCon, nObjectType, sObjectName ); 2086 } 2087 } 2088 catch (uno::Exception&) 2089 { 2090 DBG_ERROR( "GeometryHandler::impl_initFieldList_nothrow: caught an exception!" ); 2091 } 2092 } 2093 // ----------------------------------------------------------------------------- 2094 bool GeometryHandler::impl_isCounterFunction_throw(const ::rtl::OUString& _sQuotedFunctionName,::rtl::OUString& _Out_sScope) const 2095 { 2096 ::std::pair<TFunctions::const_iterator,TFunctions::const_iterator> aFind = m_aFunctionNames.equal_range(_sQuotedFunctionName); 2097 while ( aFind.first != aFind.second ) 2098 { 2099 const beans::Optional< ::rtl::OUString> aInitalFormula = aFind.first->second.first->getInitialFormula(); 2100 if ( aInitalFormula.IsPresent ) 2101 { 2102 const String sFormula( aFind.first->second.first->getFormula() ); 2103 util::SearchOptions aSearchOptions; 2104 aSearchOptions.algorithmType = util::SearchAlgorithms_REGEXP; 2105 aSearchOptions.searchFlag = 0x00000100; 2106 aSearchOptions.searchString = m_aCounterFunction.m_sSearchString; 2107 utl::TextSearch aTextSearch(aSearchOptions); 2108 xub_StrLen start = 0; 2109 xub_StrLen end = sFormula.Len(); 2110 if ( aTextSearch.SearchFrwrd(sFormula,&start,&end) && start == 0 && end == sFormula.Len()) // counter function found 2111 { 2112 const uno::Reference< report::XGroup > xGroup(aFind.first->second.second,uno::UNO_QUERY); 2113 if ( xGroup.is() ) 2114 { 2115 String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP)); 2116 sGroupName.SearchAndReplaceAscii("%1",xGroup->getExpression()); 2117 _Out_sScope = sGroupName; 2118 } 2119 else 2120 _Out_sScope = uno::Reference< report::XReportDefinition >(aFind.first->second.second,uno::UNO_QUERY_THROW)->getName(); 2121 break; 2122 } 2123 } 2124 ++(aFind.first); 2125 } 2126 return aFind.first != aFind.second; 2127 } 2128 // ----------------------------------------------------------------------------- 2129 void GeometryHandler::impl_createFunction(const ::rtl::OUString& _sFunctionName,const ::rtl::OUString& _sDataField,const DefaultFunction& _aFunction) 2130 { 2131 if ( m_bNewFunction ) 2132 removeFunction(); 2133 2134 const ::rtl::OUString sQuotedFunctionName(lcl_getQuotedFunctionName(_sFunctionName)); 2135 m_xFunction.set(report::Function::create(m_xContext)); 2136 m_xFunction->setName( _sFunctionName ); 2137 2138 const String sPlaceHolder1(RTL_CONSTASCII_USTRINGPARAM("%Column")); 2139 const String sPlaceHolder2(RTL_CONSTASCII_USTRINGPARAM("%FunctionName")); 2140 String sFormula(_aFunction.m_sFormula); 2141 sFormula.SearchAndReplaceAll(sPlaceHolder1,_sDataField); 2142 sFormula.SearchAndReplaceAll(sPlaceHolder2,_sFunctionName); 2143 2144 m_xFunction->setFormula(sFormula); 2145 m_xFunction->setPreEvaluated(_aFunction.m_bPreEvaluated); 2146 m_xFunction->setDeepTraversing(_aFunction.m_bDeepTraversing); 2147 if ( _aFunction.m_sInitialFormula.IsPresent ) 2148 { 2149 beans::Optional< ::rtl::OUString> aInitialFormula = _aFunction.m_sInitialFormula; 2150 String sInitialFormula = aInitialFormula.Value; 2151 sInitialFormula.SearchAndReplaceAll(sPlaceHolder1,_sDataField); 2152 sInitialFormula.SearchAndReplaceAll(sPlaceHolder2,_sFunctionName); 2153 aInitialFormula.Value = sInitialFormula; 2154 m_xFunction->setInitialFormula( aInitialFormula ); 2155 } 2156 ::rtl::OUString sNamePostFix; 2157 const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostFix); 2158 const uno::Reference< container::XIndexContainer> xFunctions(xFunctionsSupplier->getFunctions(),uno::UNO_QUERY_THROW); 2159 xFunctions->insertByIndex(xFunctions->getCount(),uno::makeAny(m_xFunction)); 2160 m_aFunctionNames.insert(TFunctions::value_type(sQuotedFunctionName,TFunctionPair(m_xFunction,xFunctionsSupplier))); 2161 m_bNewFunction = true; 2162 } 2163 // ----------------------------------------------------------------------------- 2164 void GeometryHandler::impl_setCounterFunction_throw() 2165 { 2166 ::rtl::OUString sNamePostFix; 2167 fillScope_throw(sNamePostFix); 2168 ::rtl::OUString sFunctionName = m_aCounterFunction.m_sName; 2169 sFunctionName += sNamePostFix; 2170 const ::rtl::OUString sQuotedFunctionName = lcl_getQuotedFunctionName(sFunctionName); 2171 ::rtl::OUString sScope; 2172 if ( !(sFunctionName.getLength() && m_aFunctionNames.find(sQuotedFunctionName) != m_aFunctionNames.end() && impl_isCounterFunction_throw(sQuotedFunctionName,sScope)) ) 2173 impl_createFunction(sFunctionName,::rtl::OUString(),m_aCounterFunction); 2174 2175 OBlocker aBlocker(m_bIn); 2176 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(impl_convertToFormula( uno::makeAny(sQuotedFunctionName)))); 2177 } 2178 // ----------------------------------------------------------------------------- 2179 sal_uInt32 GeometryHandler::impl_getDataFieldType_throw(const ::rtl::OUString& _sDataField) const 2180 { 2181 sal_uInt32 nDataFieldType = UNDEF_DATA; 2182 ::rtl::OUString sDataField; 2183 if ( _sDataField.getLength() ) 2184 sDataField = _sDataField; 2185 else 2186 { 2187 uno::Any aDataField( m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD ) ); 2188 lcl_convertFormulaTo(aDataField,aDataField); 2189 aDataField >>= sDataField; 2190 } 2191 2192 if ( sDataField.getLength() ) 2193 { 2194 if ( impl_isDataField(sDataField) ) 2195 nDataFieldType = DATA_OR_FORMULA; 2196 else if ( isDefaultFunction(sDataField,sDataField) ) 2197 nDataFieldType = FUNCTION; 2198 else if ( m_aFunctionNames.find(sDataField) != m_aFunctionNames.end() ) 2199 { 2200 nDataFieldType = USER_DEF_FUNCTION; 2201 ::rtl::OUString sScope; 2202 if ( impl_isCounterFunction_throw(sDataField,sScope) ) 2203 nDataFieldType = COUNTER; 2204 } 2205 else 2206 nDataFieldType = DATA_OR_FORMULA; 2207 } 2208 return nDataFieldType; 2209 } 2210 // ----------------------------------------------------------------------------- 2211 // XEventListener 2212 void SAL_CALL GeometryHandler::disposing(const lang::EventObject& ) throw( uno::RuntimeException ) 2213 { 2214 } 2215 // XPropertyChangeListener 2216 void SAL_CALL GeometryHandler::propertyChange(const beans::PropertyChangeEvent& /*evt*/) throw(uno::RuntimeException) 2217 { 2218 ::osl::ResettableMutexGuard aGuard( m_aMutex ); 2219 if ( !m_bIn ) 2220 { 2221 const sal_uInt32 nOldDataFieldType = m_nDataFieldType; 2222 const ::rtl::OUString sOldFunctionName = m_sDefaultFunction; 2223 const ::rtl::OUString sOldScope = m_sScope; 2224 m_sDefaultFunction = m_sScope = ::rtl::OUString(); 2225 m_nDataFieldType = impl_getDataFieldType_throw(); 2226 if ( UNDEF_DATA == m_nDataFieldType ) 2227 m_nDataFieldType = nOldDataFieldType; 2228 uno::Any aDataField = m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD ); 2229 lcl_convertFormulaTo(aDataField,aDataField); 2230 ::rtl::OUString sDataField; 2231 aDataField >>= sDataField; 2232 switch(m_nDataFieldType) 2233 { 2234 case FUNCTION: 2235 isDefaultFunction(sDataField,sDataField,uno::Reference< report::XFunctionsSupplier>(),true); 2236 break; 2237 case COUNTER: 2238 impl_isCounterFunction_throw(sDataField,m_sScope); 2239 break; 2240 default: 2241 ; 2242 } 2243 2244 resetOwnProperties(aGuard,sOldFunctionName,sOldScope,nOldDataFieldType); 2245 } 2246 } 2247 //........................................................................ 2248 } // namespace rptui 2249 //........................................................................ 2250 2251