bump product version to 6.3.0.0.beta1
[LibreOffice.git] / reportdesign / source / ui / inspection / GeometryHandler.cxx
blob746c9de1a3f8e6a6554e6e2e69f5c9905c193bd9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <iterator>
23 #include <map>
25 #include <GeometryHandler.hxx>
27 #include <comphelper/sequence.hxx>
28 #include <comphelper/types.hxx>
29 #include <comphelper/property.hxx>
30 #include <comphelper/mimeconfighelper.hxx>
31 #include <cppuhelper/supportsservice.hxx>
33 #include <strings.hxx>
34 #include <reportformula.hxx>
36 #include <i18nutil/searchopt.hxx>
37 #include <unotools/textsearch.hxx>
38 #include <unotools/configmgr.hxx>
39 #include <unotools/localedatawrapper.hxx>
41 #include <toolkit/helper/vclunohelper.hxx>
42 #include <unotools/syslocale.hxx>
43 #include <tools/diagnose_ex.h>
44 #include <tools/resary.hxx>
45 #include <com/sun/star/lang/NullPointerException.hpp>
46 #include <com/sun/star/lang/XInitialization.hpp>
47 #include <com/sun/star/form/inspection/FormComponentPropertyHandler.hpp>
48 #include <com/sun/star/inspection/StringRepresentation.hpp>
49 #include <com/sun/star/inspection/PropertyControlType.hpp>
50 #include <com/sun/star/inspection/XStringListControl.hpp>
51 #include <com/sun/star/report/Function.hpp>
52 #include <com/sun/star/report/XReportDefinition.hpp>
53 #include <com/sun/star/report/XShape.hpp>
54 #include <com/sun/star/report/XSection.hpp>
55 #include <com/sun/star/report/XFixedLine.hpp>
56 #include <com/sun/star/script/Converter.hpp>
57 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
58 #include <com/sun/star/sdb/CommandType.hpp>
59 #include <com/sun/star/sdb/FilterDialog.hpp>
60 #include <com/sun/star/sdb/SQLContext.hpp>
61 #include <com/sun/star/sdbc/XConnection.hpp>
62 #include <com/sun/star/util/SearchAlgorithms2.hpp>
63 #include <com/sun/star/util/MeasureUnit.hpp>
64 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
65 #include <com/sun/star/container/XNameContainer.hpp>
66 #include <com/sun/star/inspection/XNumericControl.hpp>
67 #include <com/sun/star/style/ParagraphAdjust.hpp>
69 #include <vcl/waitobj.hxx>
70 #include <tools/fldunit.hxx>
71 #include <vcl/stdtext.hxx>
73 #include <core_resource.hxx>
74 #include <stringarray.hrc>
75 #include <strings.hrc>
76 #include <RptDef.hxx>
77 #include <UITools.hxx>
79 #include <connectivity/dbexception.hxx>
80 #include <connectivity/dbconversion.hxx>
81 #include <connectivity/dbtools.hxx>
83 #include <metadata.hxx>
84 #include <svl/itempool.hxx>
85 #include <svl/itemset.hxx>
86 #include <svx/xdef.hxx>
87 #include <svx/xpool.hxx>
88 #include <svx/xtable.hxx>
89 #include <svx/xlnwtit.hxx>
90 #include <svx/xlntrit.hxx>
91 #include <svx/xlnclit.hxx>
92 #include <svx/xlnstit.hxx>
93 #include <svx/xlnedit.hxx>
94 #include <svx/xlnstwit.hxx>
95 #include <svx/xlnedwit.hxx>
96 #include <svx/xlnstcit.hxx>
97 #include <svx/xlnedcit.hxx>
98 #include <svx/xlndsit.hxx>
99 #include <svx/xlineit0.hxx>
100 #include <svx/svxids.hrc>
101 #include <svx/drawitem.hxx>
102 #include <editeng/brushitem.hxx>
103 #include <sfx2/docfilt.hxx>
105 #include <dlgpage.hxx>
106 #include <helpids.h>
107 #include <toolkit/helper/convert.hxx>
108 #include <o3tl/functional.hxx>
110 #define DATA_OR_FORMULA 0
111 #define FUNCTION 1
112 #define COUNTER 2
113 #define USER_DEF_FUNCTION 3
114 #define UNDEF_DATA 4
117 namespace rptui
120 using namespace ::com::sun::star;
122 namespace{
124 OUString lcl_getQuotedFunctionName(const OUString& _sFunction)
126 return "[" + _sFunction + "]";
129 OUString lcl_getQuotedFunctionName(const uno::Reference< report::XFunction>& _xFunction)
131 return lcl_getQuotedFunctionName(_xFunction->getName());
134 void lcl_collectFunctionNames(const uno::Reference< report::XFunctions>& _xFunctions,TFunctions& _rFunctionNames)
136 uno::Reference< report::XFunctionsSupplier> xParent(_xFunctions->getParent(),uno::UNO_QUERY_THROW);
137 const sal_Int32 nCount = _xFunctions->getCount();
138 for (sal_Int32 i = 0; i < nCount ; ++i)
140 uno::Reference< report::XFunction > xFunction(_xFunctions->getByIndex(i),uno::UNO_QUERY_THROW);
141 _rFunctionNames.emplace( lcl_getQuotedFunctionName(xFunction),TFunctionPair(xFunction,xParent) );
145 void lcl_collectFunctionNames(const uno::Reference< report::XSection>& _xSection,TFunctions& _rFunctionNames)
147 const uno::Reference< report::XReportDefinition> xReportDefinition = _xSection->getReportDefinition();
148 const uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups();
149 sal_Int32 nPos = -1;
150 uno::Reference< report::XGroup> xGroup = _xSection->getGroup();
151 if ( xGroup.is() )
152 nPos = getPositionInIndexAccess(xGroups.get(),xGroup);
153 else if ( _xSection == xReportDefinition->getDetail() )
154 nPos = xGroups->getCount()-1;
156 for (sal_Int32 i = 0 ; i <= nPos ; ++i)
158 xGroup.set(xGroups->getByIndex(i),uno::UNO_QUERY_THROW);
159 lcl_collectFunctionNames(xGroup->getFunctions(),_rFunctionNames);
161 lcl_collectFunctionNames(xReportDefinition->getFunctions(),_rFunctionNames);
164 void lcl_convertFormulaTo(const uno::Any& _aPropertyValue,uno::Any& _rControlValue)
166 OUString sName;
167 _aPropertyValue >>= sName;
168 const sal_Int32 nLen = sName.getLength();
169 if ( nLen )
171 ReportFormula aFormula( sName );
172 _rControlValue <<= aFormula.getUndecoratedContent();
176 // return value rounded to the nearest multiple of base
177 // if equidistant of two multiples, round up (for positive numbers)
178 // T is assumed to be an integer type
179 template <typename T, T base> T lcl_round(T value)
181 OSL_ENSURE(value >= 0, "lcl_round: positive numbers only please");
182 const T threshold = (base % 2 == 0) ? (base/2) : (base/2 + 1);
183 const T rest = value % base;
184 if ( rest >= threshold )
185 return value + (base - rest);
186 else
187 return value - rest;
190 } // anonymous namespace
192 bool GeometryHandler::impl_isDataField(const OUString& _sName) const
194 bool bIsField = ( ::std::find( m_aFieldNames.begin(), m_aFieldNames.end(), _sName ) != m_aFieldNames.end() );
196 if ( !bIsField )
198 bIsField = ( ::std::find( m_aParamNames.begin(), m_aParamNames.end(), _sName ) != m_aParamNames.end() );
200 return bIsField;
203 OUString GeometryHandler::impl_convertToFormula( const uno::Any& _rControlValue )
205 OUString sName;
206 _rControlValue >>= sName;
208 if ( sName.isEmpty() )
209 return sName;
211 ReportFormula aParser( sName );
212 if ( aParser.isValid() )
213 return sName;
215 return ReportFormula(impl_isDataField(sName) ? ReportFormula::Field : ReportFormula::Expression, sName).getCompleteFormula();
218 GeometryHandler::GeometryHandler(uno::Reference< uno::XComponentContext > const & context)
219 : GeometryHandler_Base(m_aMutex)
220 , m_aPropertyListeners(m_aMutex)
221 , m_xContext(context)
222 , m_nDataFieldType(0)
223 , m_bNewFunction(false)
224 , m_bIn(false)
228 m_xFormComponentHandler = form::inspection::FormComponentPropertyHandler::create(m_xContext);
229 m_xTypeConverter = script::Converter::create(context);
230 loadDefaultFunctions();
232 catch(const uno::Exception&)
237 GeometryHandler::~GeometryHandler()
241 OUString SAL_CALL GeometryHandler::getImplementationName( )
243 return getImplementationName_Static();
246 sal_Bool SAL_CALL GeometryHandler::supportsService( const OUString& ServiceName )
248 return cppu::supportsService(this, ServiceName);
251 uno::Sequence< OUString > SAL_CALL GeometryHandler::getSupportedServiceNames( )
253 return getSupportedServiceNames_static();
256 OUString GeometryHandler::getImplementationName_Static( )
258 return OUString("com.sun.star.comp.report.GeometryHandler");
261 uno::Sequence< OUString > GeometryHandler::getSupportedServiceNames_static( )
263 uno::Sequence< OUString > aSupported { "com.sun.star.report.inspection.GeometryHandler" };
264 return aSupported;
267 uno::Reference< uno::XInterface > GeometryHandler::create( const uno::Reference< uno::XComponentContext >& _rxContext )
269 return *(new GeometryHandler( _rxContext ));
271 // override WeakComponentImplHelperBase::disposing()
272 // This function is called upon disposing the component,
273 // if your component needs special work when it becomes
274 // disposed, do it here.
275 void SAL_CALL GeometryHandler::disposing()
279 ::comphelper::disposeComponent(m_xFormComponentHandler);
280 ::comphelper::disposeComponent(m_xTypeConverter);
281 if ( m_xReportComponent.is() && m_xReportComponent->getPropertySetInfo()->hasPropertyByName(PROPERTY_DATAFIELD) )
282 m_xReportComponent->removePropertyChangeListener(PROPERTY_DATAFIELD,static_cast< beans::XPropertyChangeListener* >( this ));
284 m_xReportComponent.clear();
285 m_xRowSet.clear();
286 m_aPropertyListeners.clear();
288 catch(uno::Exception&)
291 void SAL_CALL GeometryHandler::addEventListener(const uno::Reference< lang::XEventListener > & xListener)
293 m_xFormComponentHandler->addEventListener(xListener);
296 void SAL_CALL GeometryHandler::removeEventListener(const uno::Reference< lang::XEventListener > & aListener)
298 m_xFormComponentHandler->removeEventListener(aListener);
301 // inspection::XPropertyHandler:
303 /********************************************************************************/
304 void SAL_CALL GeometryHandler::inspect( const uno::Reference< uno::XInterface > & _rxInspectee )
306 ::osl::MutexGuard aGuard( m_aMutex );
307 m_sScope.clear();
308 m_sDefaultFunction.clear();
309 m_bNewFunction = false;
310 m_nDataFieldType = 0;
311 m_xFunction.clear();
312 m_aFunctionNames.clear();
315 if ( m_xReportComponent.is() && m_xReportComponent->getPropertySetInfo()->hasPropertyByName(PROPERTY_DATAFIELD) )
316 m_xReportComponent->removePropertyChangeListener(PROPERTY_DATAFIELD,static_cast< beans::XPropertyChangeListener* >( this ));
318 const uno::Reference< container::XNameContainer > xObjectAsContainer( _rxInspectee, uno::UNO_QUERY );
319 m_xReportComponent.set( xObjectAsContainer->getByName("ReportComponent"), uno::UNO_QUERY );
321 const OUString sRowSet("RowSet");
322 if ( xObjectAsContainer->hasByName( sRowSet ) )
324 const uno::Any aRowSet( xObjectAsContainer->getByName(sRowSet) );
325 aRowSet >>= m_xRowSet;
326 // forward the rowset to our delegator handler
327 uno::Reference< beans::XPropertySet > xProp( m_xFormComponentHandler,uno::UNO_QUERY );
328 xProp->setPropertyValue( sRowSet, aRowSet );
330 m_aParamNames = getParameterNames( m_xRowSet );
331 impl_initFieldList_nothrow(m_aFieldNames);
332 if ( m_xReportComponent->getPropertySetInfo()->hasPropertyByName(PROPERTY_DATAFIELD) )
333 m_xReportComponent->addPropertyChangeListener(PROPERTY_DATAFIELD,static_cast< beans::XPropertyChangeListener* >( this ));
336 const uno::Reference< report::XReportComponent> xReportComponent( m_xReportComponent, uno::UNO_QUERY);
337 uno::Reference< report::XSection> xSection( m_xReportComponent, uno::UNO_QUERY );
338 if ( !xSection.is() && xReportComponent.is() )
339 xSection = xReportComponent->getSection();
340 if ( xSection.is() )
341 lcl_collectFunctionNames( xSection, m_aFunctionNames );
343 catch(const uno::Exception &)
345 throw lang::NullPointerException();
347 m_xFormComponentHandler->inspect(m_xReportComponent);
350 uno::Any SAL_CALL GeometryHandler::getPropertyValue(const OUString & PropertyName)
352 ::osl::MutexGuard aGuard( m_aMutex );
353 uno::Any aPropertyValue;
354 const sal_Int32 nId = OPropertyInfoService::getPropertyId(PropertyName);
355 switch(nId)
357 case PROPERTY_ID_CONDITIONALPRINTEXPRESSION:
358 case PROPERTY_ID_INITIALFORMULA:
359 case PROPERTY_ID_FORMULA:
360 case PROPERTY_ID_DATAFIELD:
361 aPropertyValue = m_xReportComponent->getPropertyValue( PropertyName );
362 lcl_convertFormulaTo(aPropertyValue,aPropertyValue);
363 if ( PROPERTY_ID_DATAFIELD == nId )
365 OUString sDataField;
366 aPropertyValue >>= sDataField;
367 switch(m_nDataFieldType)
369 case DATA_OR_FORMULA:
370 break;
371 case FUNCTION:
372 if ( isDefaultFunction(sDataField,sDataField) )
373 aPropertyValue <<= sDataField;
374 else if ( sDataField.isEmpty() )
375 aPropertyValue = uno::Any();
376 break;
377 case COUNTER:
378 case USER_DEF_FUNCTION:
379 aPropertyValue = uno::Any();
380 break;
384 break;
385 case PROPERTY_ID_TYPE:
387 const sal_uInt32 nOldDataFieldType = m_nDataFieldType;
388 m_nDataFieldType = impl_getDataFieldType_throw();
389 if ( UNDEF_DATA == m_nDataFieldType )
390 m_nDataFieldType = nOldDataFieldType;
391 aPropertyValue <<= m_nDataFieldType;
393 break;
394 case PROPERTY_ID_FORMULALIST:
395 case PROPERTY_ID_SCOPE:
397 uno::Any aDataField = m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD );
398 lcl_convertFormulaTo(aDataField,aDataField);
399 OUString sDataField;
400 aDataField >>= sDataField;
401 switch(m_nDataFieldType)
403 case DATA_OR_FORMULA:
404 break;
405 case FUNCTION:
406 if ( isDefaultFunction(sDataField,sDataField,uno::Reference< report::XFunctionsSupplier>(),true) )
407 aPropertyValue <<= (PROPERTY_ID_FORMULALIST == nId ? m_sDefaultFunction : m_sScope);
408 break;
409 case USER_DEF_FUNCTION:
410 if ( !sDataField.isEmpty() && PROPERTY_ID_FORMULALIST == nId )
411 aPropertyValue = aDataField;
412 break;
413 case COUNTER:
414 if ( PROPERTY_ID_SCOPE == nId && impl_isCounterFunction_throw(sDataField,m_sScope) )
415 aPropertyValue <<= m_sScope;
416 break;
420 break;
421 case PROPERTY_ID_BACKCOLOR:
422 case PROPERTY_ID_CONTROLBACKGROUND:
424 aPropertyValue = m_xReportComponent->getPropertyValue( PropertyName );
425 Color nColor = COL_TRANSPARENT;
426 if ( (aPropertyValue >>= nColor) && COL_TRANSPARENT == nColor )
427 aPropertyValue.clear();
429 break;
430 case PROPERTY_ID_MIMETYPE:
432 OUString sValue;
433 m_xReportComponent->getPropertyValue( PropertyName ) >>= sValue;
434 aPropertyValue <<= impl_ConvertMimeTypeToUI_nothrow(sValue);
436 break;
437 default:
438 aPropertyValue = m_xReportComponent->getPropertyValue( PropertyName );
439 break;
441 return aPropertyValue;
444 void SAL_CALL GeometryHandler::setPropertyValue(const OUString & PropertyName, const uno::Any & Value)
446 ::osl::ResettableMutexGuard aGuard( m_aMutex );
447 uno::Any aNewValue = Value;
448 const sal_Int32 nId = OPropertyInfoService::getPropertyId(PropertyName);
449 bool bHandled = false;
450 switch(nId)
452 case PROPERTY_ID_INITIALFORMULA:
453 case PROPERTY_ID_FORMULA:
454 break;
455 case PROPERTY_ID_DATAFIELD:
457 OBlocker aBlocker(m_bIn);
458 m_xReportComponent->setPropertyValue(PropertyName, aNewValue);
459 bHandled = true;
460 const OUString sOldFunctionName = m_sDefaultFunction;
461 const OUString sOldScope = m_sScope;
463 uno::Any aPropertyValue;
464 lcl_convertFormulaTo(Value,aPropertyValue);
465 OUString sDataField;
466 aPropertyValue >>= sDataField;
468 m_sScope.clear();
469 m_sDefaultFunction.clear();
470 m_xFunction.clear();
471 const sal_uInt32 nOldDataFieldType = m_nDataFieldType;
472 if ( !sDataField.isEmpty() )
474 if ( isDefaultFunction(sDataField,sDataField,uno::Reference< report::XFunctionsSupplier>(),true) )
475 m_nDataFieldType = FUNCTION;
476 else if ( m_aFunctionNames.find(sDataField) != m_aFunctionNames.end() )
477 m_nDataFieldType = USER_DEF_FUNCTION;
480 resetOwnProperties(aGuard,sOldFunctionName,sOldScope,nOldDataFieldType);
482 break;
483 case PROPERTY_ID_TYPE:
485 bHandled = true;
486 Value >>= m_nDataFieldType;
488 const OUString sOldFunctionName = m_sDefaultFunction;
489 const OUString sOldScope = m_sScope;
490 m_sDefaultFunction.clear();
491 m_sScope.clear();
493 if ( m_nDataFieldType == COUNTER )
495 impl_setCounterFunction_throw();
497 else
499 if ( m_bNewFunction )
500 removeFunction();
501 m_xFunction.clear();
502 OBlocker aBlocker(m_bIn);
503 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(OUString()));
505 resetOwnProperties(aGuard,sOldFunctionName,sOldScope,m_nDataFieldType);
507 break;
508 case PROPERTY_ID_FORMULALIST:
510 bHandled = true;
511 OUString sFunction;
512 if ( !(Value >>= sFunction) || sFunction.isEmpty() )
514 if ( m_nDataFieldType == FUNCTION )
516 m_sDefaultFunction.clear();
517 if ( m_bNewFunction )
518 removeFunction();
519 m_xFunction.clear();
521 beans::PropertyChangeEvent aEvent;
522 aEvent.PropertyName = PROPERTY_SCOPE;
523 aEvent.OldValue <<= m_sScope;
524 m_sScope.clear();
525 aEvent.NewValue <<= m_sScope;
526 aGuard.clear();
527 m_aPropertyListeners.notify( aEvent, &beans::XPropertyChangeListener::propertyChange );
529 else if ( m_nDataFieldType == USER_DEF_FUNCTION )
531 OBlocker aBlocker(m_bIn);
532 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(OUString()));
535 else if ( m_nDataFieldType == USER_DEF_FUNCTION )
537 OUString sDataField;
538 OBlocker aBlocker(m_bIn);
539 const sal_uInt32 nNewDataType = impl_getDataFieldType_throw(sFunction);
540 if ( nNewDataType != UNDEF_DATA && nNewDataType != m_nDataFieldType )
542 const OUString sOldFunctionName = m_sDefaultFunction;
543 const OUString sOldScope = m_sScope;
544 m_sScope.clear();
545 m_sDefaultFunction.clear();
546 m_xFunction.clear();
547 if ( nNewDataType == COUNTER )
548 impl_isCounterFunction_throw(sFunction,m_sScope);
549 else
551 OUString sNamePostfix;
552 const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostfix);
553 isDefaultFunction(sFunction,sDataField,xFunctionsSupplier,true);
555 const sal_uInt32 nOldDataFieldType = m_nDataFieldType;
556 m_nDataFieldType = nNewDataType;
557 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(impl_convertToFormula( uno::makeAny(sFunction))));
558 resetOwnProperties(aGuard,sOldFunctionName,sOldScope,nOldDataFieldType);
560 else
561 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(impl_convertToFormula( uno::makeAny(sFunction))));
563 else if ( m_nDataFieldType == FUNCTION )
565 uno::Any aPropertyValue = m_xReportComponent->getPropertyValue(PROPERTY_DATAFIELD);
566 lcl_convertFormulaTo(aPropertyValue,aPropertyValue);
567 OUString sDataField;
568 aPropertyValue >>= sDataField;
569 if ( m_nDataFieldType == FUNCTION && (!isDefaultFunction(sDataField,sDataField) || m_sDefaultFunction != sFunction) )
571 if ( m_bNewFunction )
572 removeFunction();
573 // function currently does not exist
574 createDefaultFunction(aGuard,sFunction,sDataField);
575 m_sDefaultFunction = sFunction;
580 break;
581 case PROPERTY_ID_SCOPE:
582 if ( !(Value >>= m_sScope) )
583 m_sScope.clear();
584 else
586 if ( m_bNewFunction )
587 removeFunction();
588 if ( m_nDataFieldType == COUNTER )
589 impl_setCounterFunction_throw();
590 else
592 OSL_ENSURE(m_xFunction.is(),"Where is my function gone!");
594 OUString sNamePostfix;
595 const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostfix);
597 OUString sQuotedFunctionName(lcl_getQuotedFunctionName(m_xFunction));
598 if ( isDefaultFunction(sQuotedFunctionName,sQuotedFunctionName,xFunctionsSupplier,true) )
599 m_bNewFunction = false;
600 else
602 OUString sDefaultFunctionName;
603 OUString sDataField;
604 OSL_VERIFY( impl_isDefaultFunction_nothrow(m_xFunction,sDataField,sDefaultFunctionName) );
605 m_sDefaultFunction = sDefaultFunctionName;
606 createDefaultFunction(aGuard,m_sDefaultFunction,sDataField);
610 bHandled = true;
611 break;
612 case PROPERTY_ID_POSITIONX:
613 case PROPERTY_ID_POSITIONY:
614 case PROPERTY_ID_HEIGHT:
615 case PROPERTY_ID_WIDTH:
617 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY);
618 if ( xSourceReportComponent.is() ) // check only report components
620 sal_Int32 nNewValue = 0;
621 Value >>= nNewValue;
622 OSL_ENSURE(nNewValue >= 0, "A position/dimension should not be negative!");
623 nNewValue = lcl_round<sal_Int32, 10>(nNewValue);
624 awt::Point aAwtPoint = xSourceReportComponent->getPosition();
625 awt::Size aAwtSize = xSourceReportComponent->getSize();
626 if ( nId == PROPERTY_ID_POSITIONX )
627 aAwtPoint.X = nNewValue;
628 else if ( nId == PROPERTY_ID_POSITIONY )
629 aAwtPoint.Y = nNewValue;
630 else if ( nId == PROPERTY_ID_HEIGHT )
631 aAwtSize.Height = nNewValue;
632 else if ( nId == PROPERTY_ID_WIDTH )
633 aAwtSize.Width = nNewValue;
635 checkPosAndSize(aAwtPoint,aAwtSize);
638 break;
639 case PROPERTY_ID_FONT:
641 const uno::Reference< report::XReportControlFormat > xReportControlFormat( m_xReportComponent,uno::UNO_QUERY_THROW );
642 uno::Sequence< beans::NamedValue > aFontSettings;
643 OSL_VERIFY( Value >>= aFontSettings );
644 applyCharacterSettings( xReportControlFormat, aFontSettings );
645 bHandled = true;
647 break;
648 case PROPERTY_ID_MIMETYPE:
650 OUString sValue;
651 Value >>= sValue;
652 aNewValue <<= impl_ConvertUIToMimeType_nothrow(sValue);
654 break;
655 default:
656 break;
659 if ( !bHandled )
660 m_xReportComponent->setPropertyValue(PropertyName, aNewValue);
664 beans::PropertyState SAL_CALL GeometryHandler::getPropertyState(const OUString & PropertyName)
666 ::osl::MutexGuard aGuard( m_aMutex );
667 return m_xFormComponentHandler->getPropertyState(PropertyName);
670 void GeometryHandler::implCreateListLikeControl(
671 const uno::Reference< inspection::XPropertyControlFactory >& _rxControlFactory
672 ,inspection::LineDescriptor & out_Descriptor
673 ,const char** pResId
674 ,bool _bReadOnlyControl
675 ,bool _bTrueIfListBoxFalseIfComboBox
678 std::vector<OUString> aList;
679 for (const char** pItem = pResId; *pItem; ++pItem)
680 aList.push_back(RptResId(*pItem));
681 implCreateListLikeControl(_rxControlFactory, out_Descriptor, aList, _bReadOnlyControl, _bTrueIfListBoxFalseIfComboBox);
684 void GeometryHandler::implCreateListLikeControl(
685 const uno::Reference< inspection::XPropertyControlFactory >& _rxControlFactory
686 ,inspection::LineDescriptor & out_Descriptor
687 ,const ::std::vector< OUString>& _aEntries
688 ,bool _bReadOnlyControl
689 ,bool _bTrueIfListBoxFalseIfComboBox
692 const uno::Reference< inspection::XStringListControl > xListControl(
693 _rxControlFactory->createPropertyControl(
694 _bTrueIfListBoxFalseIfComboBox ? inspection::PropertyControlType::ListBox : inspection::PropertyControlType::ComboBox, _bReadOnlyControl
696 uno::UNO_QUERY_THROW
699 out_Descriptor.Control = xListControl.get();
700 for (auto const& it : _aEntries)
702 xListControl->appendListEntry(it);
707 inspection::LineDescriptor SAL_CALL GeometryHandler::describePropertyLine(const OUString & PropertyName, const uno::Reference< inspection::XPropertyControlFactory > & _xControlFactory)
709 inspection::LineDescriptor aOut;
710 const sal_Int32 nId = OPropertyInfoService::getPropertyId(PropertyName);
711 switch(nId)
713 case PROPERTY_ID_FORCENEWPAGE:
714 case PROPERTY_ID_NEWROWORCOL:
715 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_FORCENEWPAGE_CONST,false,true);
716 break;
717 case PROPERTY_ID_GROUPKEEPTOGETHER:
718 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_GROUPKEEPTOGETHER_CONST,false,true);
719 break;
720 case PROPERTY_ID_PAGEHEADEROPTION:
721 case PROPERTY_ID_PAGEFOOTEROPTION:
722 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_REPORTPRINTOPTION_CONST,false,true);
723 break;
724 case PROPERTY_ID_FORMULALIST:
726 ::std::vector< OUString > aList;
727 impl_fillFormulaList_nothrow(aList);
728 implCreateListLikeControl(_xControlFactory,aOut,aList,false,true);
730 break;
731 case PROPERTY_ID_SCOPE:
733 ::std::vector< OUString > aList;
734 impl_fillScopeList_nothrow(aList);
735 implCreateListLikeControl(_xControlFactory,aOut,aList,false,true);
737 break;
738 case PROPERTY_ID_MIMETYPE:
740 ::std::vector< OUString > aList;
741 impl_fillMimeTypes_nothrow(aList);
742 implCreateListLikeControl(_xControlFactory,aOut,aList,false,true);
744 break;
745 case PROPERTY_ID_TYPE:
746 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_TYPE_CONST,false,true);
747 break;
748 case PROPERTY_ID_VISIBLE:
749 case PROPERTY_ID_CANGROW:
750 case PROPERTY_ID_CANSHRINK:
751 case PROPERTY_ID_REPEATSECTION:
752 case PROPERTY_ID_PRINTREPEATEDVALUES:
753 case PROPERTY_ID_STARTNEWCOLUMN:
754 case PROPERTY_ID_RESETPAGENUMBER:
755 case PROPERTY_ID_PRINTWHENGROUPCHANGE:
756 case PROPERTY_ID_KEEPTOGETHER:
757 case PROPERTY_ID_DEEPTRAVERSING:
758 case PROPERTY_ID_PREEVALUATED:
759 case PROPERTY_ID_PRESERVEIRI:
760 case PROPERTY_ID_BACKTRANSPARENT:
761 case PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT:
763 const char** pResId = RID_STR_BOOL;
764 if ( PROPERTY_ID_KEEPTOGETHER == nId && uno::Reference< report::XGroup>(m_xReportComponent,uno::UNO_QUERY).is())
765 pResId = RID_STR_KEEPTOGETHER_CONST;
766 implCreateListLikeControl(_xControlFactory,aOut,pResId,false,true);
768 break;
769 case PROPERTY_ID_INITIALFORMULA:
770 case PROPERTY_ID_FORMULA:
771 aOut.PrimaryButtonId = UID_RPT_PROP_FORMULA;
772 aOut.HasPrimaryButton = true;
773 aOut.Control = _xControlFactory->createPropertyControl(inspection::PropertyControlType::MultiLineTextField , false);
774 break;
775 case PROPERTY_ID_CONDITIONALPRINTEXPRESSION:
776 aOut.PrimaryButtonId = UID_RPT_PROP_FORMULA;
777 aOut.HasPrimaryButton = true;
778 aOut.Control = _xControlFactory->createPropertyControl(inspection::PropertyControlType::MultiLineTextField , false);
779 break;
780 case PROPERTY_ID_DATAFIELD:
782 uno::Reference< inspection::XStringListControl > xListControl(
783 _xControlFactory->createPropertyControl(
784 m_nDataFieldType == DATA_OR_FORMULA ? inspection::PropertyControlType::ComboBox : inspection::PropertyControlType::ListBox, false
786 uno::UNO_QUERY_THROW
789 if ( m_nDataFieldType == DATA_OR_FORMULA )
791 aOut.PrimaryButtonId = UID_RPT_PROP_FORMULA;
792 aOut.HasPrimaryButton = true;
795 aOut.Control = xListControl.get();
796 if ( m_nDataFieldType == USER_DEF_FUNCTION )
798 // add function names
799 ::std::for_each(m_aFunctionNames.begin(), m_aFunctionNames.end(),
800 [&xListControl] (const TFunctions::value_type& func) {
801 xListControl->appendListEntry(func.first);
804 else
806 for (auto const& it : m_aFieldNames)
808 xListControl->appendListEntry(it);
810 for (auto const& it : m_aParamNames)
812 xListControl->appendListEntry(it);
816 break;
817 case PROPERTY_ID_BACKCOLOR:
818 case PROPERTY_ID_CONTROLBACKGROUND:
819 aOut.Control = _xControlFactory->createPropertyControl( inspection::PropertyControlType::ColorListBox, false );
820 break;
821 case PROPERTY_ID_FONT:
822 aOut.PrimaryButtonId = UID_RPT_RPT_PROP_DLG_FONT_TYPE;
823 aOut.Control = _xControlFactory->createPropertyControl( inspection::PropertyControlType::TextField, true );
824 aOut.HasPrimaryButton = true;
825 break;
826 case PROPERTY_ID_AREA:
827 aOut.PrimaryButtonId = UID_RPT_RPT_PROP_DLG_AREA;
828 aOut.Control = _xControlFactory->createPropertyControl( inspection::PropertyControlType::TextField, true );
829 aOut.HasPrimaryButton = true;
830 break;
831 case PROPERTY_ID_VERTICALALIGN:
832 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_VERTICAL_ALIGN_CONST,false,true);
833 break;
834 case PROPERTY_ID_PARAADJUST:
835 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_PARAADJUST_CONST,false,true);
836 break;
837 default:
839 aOut = m_xFormComponentHandler->describePropertyLine(PropertyName, _xControlFactory);
843 if ( nId != -1 )
845 aOut.Category = (OPropertyInfoService::getPropertyUIFlags(nId ) & PropUIFlags::DataProperty) ?
846 OUString("Data")
848 OUString("General");
849 aOut.HelpURL = HelpIdUrl::getHelpURL( OPropertyInfoService::getPropertyHelpId( nId ) );
850 aOut.DisplayName = OPropertyInfoService::getPropertyTranslation(nId);
853 if ( ( nId == PROPERTY_ID_POSITIONX )
854 || ( nId == PROPERTY_ID_POSITIONY )
855 || ( nId == PROPERTY_ID_WIDTH )
856 || ( nId == PROPERTY_ID_HEIGHT )
859 const MeasurementSystem eSystem = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
860 const sal_Int16 nDisplayUnit = VCLUnoHelper::ConvertToMeasurementUnit( MeasurementSystem::Metric == eSystem ? FieldUnit::CM : FieldUnit::INCH, 1 );
861 uno::Reference< inspection::XNumericControl > xNumericControl(aOut.Control,uno::UNO_QUERY);
862 xNumericControl->setDecimalDigits( 2 );
863 xNumericControl->setValueUnit( util::MeasureUnit::MM_100TH );
864 uno::Reference< drawing::XShapeDescriptor> xShapeDesc(m_xReportComponent,uno::UNO_QUERY);
865 bool bSetMin = !xShapeDesc.is() || xShapeDesc->getShapeType() != "com.sun.star.drawing.CustomShape";
866 if ( bSetMin )
867 xNumericControl->setMinValue(beans::Optional<double>(true,0.0));
868 if ( nDisplayUnit != -1 )
869 xNumericControl->setDisplayUnit( nDisplayUnit );
870 uno::Reference< report::XReportComponent> xComp(m_xReportComponent,uno::UNO_QUERY);
871 if ( xComp.is() && xComp->getSection().is() )
873 uno::Reference< report::XReportDefinition > xReport = xComp->getSection()->getReportDefinition();
874 OSL_ENSURE(xReport.is(),"Why is the report definition NULL!");
875 if ( xReport.is() )
877 const awt::Size aSize = getStyleProperty<awt::Size>(xReport,PROPERTY_PAPERSIZE);
878 const sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReport,PROPERTY_LEFTMARGIN);
879 const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReport,PROPERTY_RIGHTMARGIN);
880 switch(nId)
882 case PROPERTY_ID_POSITIONX:
883 case PROPERTY_ID_WIDTH:
884 if ( bSetMin )
885 xNumericControl->setMinValue(beans::Optional<double>(true,0.0));
886 xNumericControl->setMaxValue(beans::Optional<double>(true,double(aSize.Width - nLeftMargin - nRightMargin)));
887 if ( PROPERTY_ID_WIDTH == nId )
889 uno::Reference<report::XFixedLine> xFixedLine(m_xReportComponent,uno::UNO_QUERY);
890 if ( xFixedLine.is() && xFixedLine->getOrientation() == 1 ) // vertical
891 xNumericControl->setMinValue(beans::Optional<double>(true,0.08 ));
893 break;
894 default:
895 break;
899 else if ( PROPERTY_ID_HEIGHT == nId )
901 const uno::Reference< report::XSection> xSection(m_xReportComponent,uno::UNO_QUERY);
902 if ( xSection.is() )
904 sal_Int32 nHeight = 0;
905 const sal_Int32 nCount = xSection->getCount();
906 for (sal_Int32 i = 0; i < nCount; ++i)
908 uno::Reference<drawing::XShape> xShape(xSection->getByIndex(i),uno::UNO_QUERY);
909 nHeight = ::std::max<sal_Int32>(nHeight,xShape->getPosition().Y + xShape->getSize().Height);
911 xNumericControl->setMinValue(beans::Optional<double>(true,nHeight ));
915 return aOut;
918 beans::Property GeometryHandler::getProperty(const OUString & PropertyName)
920 uno::Sequence< beans::Property > aProps = getSupportedProperties();
921 const beans::Property* pIter = aProps.getConstArray();
922 const beans::Property* pEnd = pIter + aProps.getLength();
923 const beans::Property* pFind = ::std::find_if(pIter, pEnd,
924 [&PropertyName] (const beans::Property& x) -> bool {
925 return x.Name == PropertyName;
927 if ( pFind == pEnd )
928 return beans::Property();
929 return *pFind;
931 uno::Any GeometryHandler::getConstantValue(bool _bToControlValue,const char** pResId,const uno::Any& _aValue,const OUString& _sConstantName,const OUString & PropertyName )
933 std::vector<OUString> aList;
934 for (const char** pItem = pResId; *pItem; ++pItem)
935 aList.push_back(RptResId(*pItem));
936 uno::Sequence< OUString > aSeq(aList.size());
937 for (size_t i = 0; i < aList.size(); ++i)
938 aSeq[i] = aList[i];
940 uno::Reference< inspection::XStringRepresentation > xConversionHelper = inspection::StringRepresentation::createConstant( m_xContext,m_xTypeConverter,_sConstantName,aSeq);
941 if ( _bToControlValue )
943 return uno::makeAny( xConversionHelper->convertToControlValue( _aValue ) );
945 else
947 OUString sControlValue;
948 _aValue >>= sControlValue;
949 const beans::Property aProp = getProperty(PropertyName);
950 return xConversionHelper->convertToPropertyValue( sControlValue, aProp.Type );
954 uno::Any SAL_CALL GeometryHandler::convertToPropertyValue(const OUString & PropertyName, const uno::Any & _rControlValue)
956 ::osl::MutexGuard aGuard( m_aMutex );
957 uno::Any aPropertyValue( _rControlValue );
958 const sal_Int32 nId = OPropertyInfoService::getPropertyId(PropertyName);
959 switch(nId)
961 case PROPERTY_ID_FORCENEWPAGE:
962 case PROPERTY_ID_NEWROWORCOL:
963 aPropertyValue = getConstantValue(false,RID_STR_FORCENEWPAGE_CONST,_rControlValue,"com.sun.star.report.ForceNewPage",PropertyName);
964 break;
965 case PROPERTY_ID_GROUPKEEPTOGETHER:
966 aPropertyValue = getConstantValue(false,RID_STR_GROUPKEEPTOGETHER_CONST,_rControlValue,"com.sun.star.report.GroupKeepTogether",PropertyName);
967 break;
968 case PROPERTY_ID_PAGEHEADEROPTION:
969 case PROPERTY_ID_PAGEFOOTEROPTION:
970 aPropertyValue = getConstantValue(false,RID_STR_REPORTPRINTOPTION_CONST,_rControlValue,"com.sun.star.report.ReportPrintOption",PropertyName);
971 break;
972 case PROPERTY_ID_BACKCOLOR:
973 case PROPERTY_ID_CONTROLBACKGROUND:
974 if ( !_rControlValue.hasValue() )
976 aPropertyValue <<= COL_TRANSPARENT;
977 break;
979 [[fallthrough]];
981 case PROPERTY_ID_KEEPTOGETHER:
982 if ( uno::Reference< report::XGroup>(m_xReportComponent,uno::UNO_QUERY).is())
984 aPropertyValue = getConstantValue(false,RID_STR_KEEPTOGETHER_CONST,_rControlValue,"com.sun.star.report.KeepTogether",PropertyName);
985 break;
987 [[fallthrough]];
989 case PROPERTY_ID_VISIBLE:
990 case PROPERTY_ID_CANGROW:
991 case PROPERTY_ID_CANSHRINK:
992 case PROPERTY_ID_REPEATSECTION:
993 case PROPERTY_ID_PRINTREPEATEDVALUES:
994 case PROPERTY_ID_STARTNEWCOLUMN:
995 case PROPERTY_ID_RESETPAGENUMBER:
996 case PROPERTY_ID_PRINTWHENGROUPCHANGE:
997 case PROPERTY_ID_DEEPTRAVERSING:
998 case PROPERTY_ID_PREEVALUATED:
999 case PROPERTY_ID_PRESERVEIRI:
1000 case PROPERTY_ID_BACKTRANSPARENT:
1001 case PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT:
1003 if ( aPropertyValue.hasValue() )
1005 const beans::Property aProp = getProperty(PropertyName);
1006 if ( aPropertyValue.getValueType().equals( aProp.Type ) )
1007 // nothing to do, type is already as desired
1008 return aPropertyValue;
1010 if ( _rControlValue.getValueType().getTypeClass() == uno::TypeClass_STRING )
1012 OUString sControlValue;
1013 _rControlValue >>= sControlValue;
1015 const uno::Reference< inspection::XStringRepresentation > xConversionHelper = inspection::StringRepresentation::create( m_xContext,m_xTypeConverter );
1016 aPropertyValue = xConversionHelper->convertToPropertyValue( sControlValue, aProp.Type );
1018 else
1022 aPropertyValue = m_xTypeConverter->convertTo( _rControlValue, aProp.Type );
1024 catch( const uno::Exception& )
1026 OSL_FAIL( "GeometryHandler::convertToPropertyValue: caught an exception while converting via TypeConverter!" );
1031 break;
1033 case PROPERTY_ID_CONDITIONALPRINTEXPRESSION:
1034 case PROPERTY_ID_INITIALFORMULA:
1035 case PROPERTY_ID_FORMULA:
1036 return uno::makeAny( impl_convertToFormula( _rControlValue ) );
1037 case PROPERTY_ID_DATAFIELD:
1039 OUString sDataField;
1040 _rControlValue >>= sDataField;
1041 if ( isDefaultFunction(sDataField,sDataField) )
1043 OSL_ENSURE(m_xFunction.is(),"No function set!");
1044 aPropertyValue <<= impl_convertToFormula( uno::makeAny(lcl_getQuotedFunctionName(m_xFunction)) );
1046 else
1047 aPropertyValue <<= impl_convertToFormula( _rControlValue );
1049 break;
1050 case PROPERTY_ID_POSITIONX:
1052 aPropertyValue = m_xFormComponentHandler->convertToPropertyValue(PropertyName, _rControlValue);
1053 sal_Int32 nPosX = 0;
1054 aPropertyValue >>= nPosX;
1055 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY);
1056 if ( xSourceReportComponent->getSection().is() )
1057 nPosX += getStyleProperty<sal_Int32>(xSourceReportComponent->getSection()->getReportDefinition(),PROPERTY_LEFTMARGIN);
1058 aPropertyValue <<= nPosX;
1060 break;
1061 case PROPERTY_ID_FONT:
1062 aPropertyValue = m_xFormComponentHandler->convertToPropertyValue(PROPERTY_FONT, _rControlValue);
1063 break;
1064 case PROPERTY_ID_SCOPE:
1065 case PROPERTY_ID_FORMULALIST:
1066 case PROPERTY_ID_AREA:
1067 aPropertyValue = _rControlValue;
1068 break;
1069 case PROPERTY_ID_TYPE:
1071 OUString sValue;
1072 _rControlValue >>= sValue;
1074 sal_uInt32 nFound(RESARRAY_INDEX_NOTFOUND);
1075 sal_uInt32 i = 0;
1076 for (const char** pItem = RID_STR_TYPE_CONST; *pItem; ++pItem)
1078 if (sValue == RptResId(*pItem))
1080 nFound = i;
1081 break;
1083 ++i;
1085 if (nFound != RESARRAY_INDEX_NOTFOUND)
1086 aPropertyValue <<= nFound;
1088 break;
1089 case PROPERTY_ID_MIMETYPE:
1090 aPropertyValue = _rControlValue;
1091 break;
1092 case PROPERTY_ID_VERTICALALIGN:
1094 OUString sValue;
1095 _rControlValue >>= sValue;
1097 sal_uInt32 nFound(RESARRAY_INDEX_NOTFOUND);
1098 sal_uInt32 i = 0;
1099 for (const char** pItem = RID_STR_VERTICAL_ALIGN_CONST; *pItem; ++pItem)
1101 if (sValue == RptResId(*pItem))
1103 nFound = i;
1104 break;
1106 ++i;
1108 if (nFound != RESARRAY_INDEX_NOTFOUND)
1109 aPropertyValue <<= static_cast<style::VerticalAlignment>(nFound);
1111 break;
1112 case PROPERTY_ID_PARAADJUST:
1114 OUString sValue;
1115 _rControlValue >>= sValue;
1117 sal_uInt32 nFound(RESARRAY_INDEX_NOTFOUND);
1118 sal_uInt32 i = 0;
1119 for (const char** pItem = RID_STR_PARAADJUST_CONST; *pItem; ++pItem)
1121 if (sValue == RptResId(*pItem))
1123 nFound = i;
1124 break;
1126 ++i;
1129 if (nFound != RESARRAY_INDEX_NOTFOUND)
1130 aPropertyValue <<= static_cast<sal_Int16>(nFound);
1132 break;
1133 default:
1134 return m_xFormComponentHandler->convertToPropertyValue(PropertyName, _rControlValue);
1136 return aPropertyValue;
1139 uno::Any SAL_CALL GeometryHandler::convertToControlValue(const OUString & PropertyName, const uno::Any & _rPropertyValue, const uno::Type & _rControlValueType)
1141 uno::Any aControlValue( _rPropertyValue );
1142 if ( !aControlValue.hasValue() )
1143 // NULL is converted to NULL
1144 return aControlValue;
1146 uno::Any aPropertyValue(_rPropertyValue);
1148 ::osl::MutexGuard aGuard( m_aMutex );
1149 const sal_Int32 nId = OPropertyInfoService::getPropertyId(PropertyName);
1150 switch(nId)
1152 case PROPERTY_ID_AREA:
1153 break;
1154 case PROPERTY_ID_FORCENEWPAGE:
1155 case PROPERTY_ID_NEWROWORCOL:
1156 aControlValue = getConstantValue(true,RID_STR_FORCENEWPAGE_CONST,aPropertyValue,"com.sun.star.report.ForceNewPage",PropertyName);
1157 break;
1158 case PROPERTY_ID_GROUPKEEPTOGETHER:
1159 aControlValue = getConstantValue(true,RID_STR_GROUPKEEPTOGETHER_CONST,aPropertyValue,"com.sun.star.report.GroupKeepTogether",PropertyName);
1160 break;
1161 case PROPERTY_ID_PAGEHEADEROPTION:
1162 case PROPERTY_ID_PAGEFOOTEROPTION:
1163 aControlValue = getConstantValue(true,RID_STR_REPORTPRINTOPTION_CONST,aPropertyValue,"com.sun.star.report.ReportPrintOption",PropertyName);
1164 break;
1165 case PROPERTY_ID_KEEPTOGETHER:
1166 if ( uno::Reference< report::XGroup>(m_xReportComponent,uno::UNO_QUERY).is())
1168 aControlValue = getConstantValue(true,RID_STR_KEEPTOGETHER_CONST,aPropertyValue,"com.sun.star.report.KeepTogether",PropertyName);
1169 break;
1171 [[fallthrough]];
1172 case PROPERTY_ID_VISIBLE:
1173 case PROPERTY_ID_CANGROW:
1174 case PROPERTY_ID_CANSHRINK:
1175 case PROPERTY_ID_REPEATSECTION:
1176 case PROPERTY_ID_PRINTREPEATEDVALUES:
1177 case PROPERTY_ID_STARTNEWCOLUMN:
1178 case PROPERTY_ID_RESETPAGENUMBER:
1179 case PROPERTY_ID_PRINTWHENGROUPCHANGE:
1180 case PROPERTY_ID_DEEPTRAVERSING:
1181 case PROPERTY_ID_PREEVALUATED:
1182 case PROPERTY_ID_PRESERVEIRI:
1183 case PROPERTY_ID_BACKTRANSPARENT:
1184 case PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT:
1186 if ( _rControlValueType.getTypeClass() == uno::TypeClass_STRING )
1188 const uno::Reference< inspection::XStringRepresentation > xConversionHelper = inspection::StringRepresentation::create( m_xContext,m_xTypeConverter );
1189 aControlValue <<= xConversionHelper->convertToControlValue( aPropertyValue );
1191 else
1195 aControlValue = m_xTypeConverter->convertTo( aPropertyValue, _rControlValueType );
1197 catch( const uno::Exception& )
1199 OSL_FAIL( "GeometryHandler::convertToControlValue: caught an exception while converting via TypeConverter!" );
1202 break;
1204 case PROPERTY_ID_CONDITIONALPRINTEXPRESSION:
1205 case PROPERTY_ID_INITIALFORMULA:
1206 case PROPERTY_ID_FORMULA:
1207 lcl_convertFormulaTo(aPropertyValue,aControlValue);
1208 break;
1209 case PROPERTY_ID_DATAFIELD:
1211 OUString sValue;
1212 aControlValue >>= sValue;
1213 if ( isDefaultFunction(sValue,sValue) )
1214 aControlValue <<= sValue;
1215 else
1216 lcl_convertFormulaTo(aPropertyValue,aControlValue);
1218 break;
1219 case PROPERTY_ID_FONT:
1220 aControlValue = m_xFormComponentHandler->convertToControlValue(PROPERTY_FONT, aPropertyValue, _rControlValueType);
1221 break;
1222 case PROPERTY_ID_POSITIONX:
1224 sal_Int32 nPosX = 0;
1225 aPropertyValue >>= nPosX;
1226 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY);
1227 if ( xSourceReportComponent->getSection().is() )
1228 nPosX -= getStyleProperty<sal_Int32>(xSourceReportComponent->getSection()->getReportDefinition(),PROPERTY_LEFTMARGIN);
1229 aPropertyValue <<= nPosX;
1230 aControlValue = m_xFormComponentHandler->convertToControlValue(PropertyName, aPropertyValue, _rControlValueType);
1232 break;
1233 case PROPERTY_ID_FORMULALIST:
1234 aControlValue <<= m_sDefaultFunction;
1235 break;
1236 case PROPERTY_ID_SCOPE:
1237 aControlValue <<= m_sScope;
1238 break;
1239 case PROPERTY_ID_MIMETYPE:
1240 aControlValue = aPropertyValue;
1241 break;
1242 case PROPERTY_ID_TYPE:
1244 if (m_nDataFieldType < SAL_N_ELEMENTS(RID_STR_TYPE_CONST) - 1)
1245 aControlValue <<= RptResId(RID_STR_TYPE_CONST[m_nDataFieldType]);
1247 break;
1248 case PROPERTY_ID_VERTICALALIGN:
1250 style::VerticalAlignment nParagraphVertAlign = style::VerticalAlignment_TOP;
1251 aPropertyValue >>= nParagraphVertAlign;
1252 if (sal_uInt32(nParagraphVertAlign) < SAL_N_ELEMENTS(RID_STR_VERTICAL_ALIGN_CONST) - 1)
1253 aControlValue <<= RptResId(RID_STR_VERTICAL_ALIGN_CONST[static_cast<sal_uInt32>(nParagraphVertAlign)]);
1255 break;
1256 case PROPERTY_ID_PARAADJUST:
1258 sal_Int16 nParagraphAdjust = sal_Int16(style::ParagraphAdjust_LEFT);
1259 aPropertyValue >>= nParagraphAdjust;
1260 if (static_cast<sal_uInt32>(nParagraphAdjust) < SAL_N_ELEMENTS(RID_STR_PARAADJUST_CONST) - 1)
1261 aControlValue <<= RptResId(RID_STR_PARAADJUST_CONST[nParagraphAdjust]);
1263 break;
1264 case PROPERTY_ID_BACKCOLOR:
1265 case PROPERTY_ID_CONTROLBACKGROUND:
1267 Color nColor = COL_TRANSPARENT;
1268 if ( (aPropertyValue >>= nColor) && COL_TRANSPARENT == nColor )
1269 aPropertyValue.clear();
1271 [[fallthrough]];
1272 default:
1273 aControlValue = m_xFormComponentHandler->convertToControlValue(PropertyName, aPropertyValue, _rControlValueType);
1275 return aControlValue;
1277 void SAL_CALL GeometryHandler::addPropertyChangeListener(const uno::Reference< beans::XPropertyChangeListener > & _rxListener)
1279 ::osl::MutexGuard aGuard( m_aMutex );
1280 m_aPropertyListeners.addListener( _rxListener );
1281 m_xFormComponentHandler->addPropertyChangeListener(_rxListener);
1284 void SAL_CALL GeometryHandler::removePropertyChangeListener(const uno::Reference< beans::XPropertyChangeListener > & _rxListener)
1286 ::osl::MutexGuard aGuard( m_aMutex );
1287 m_aPropertyListeners.removeListener( _rxListener );
1288 m_xFormComponentHandler->removePropertyChangeListener(_rxListener);
1292 uno::Sequence< beans::Property > SAL_CALL GeometryHandler::getSupportedProperties()
1294 ::std::vector< beans::Property > aNewProps;
1295 aNewProps.reserve(20); // only a guess
1296 rptui::OPropertyInfoService::getExcludeProperties( aNewProps, m_xFormComponentHandler );
1298 const OUString pIncludeProperties[] =
1300 OUString(PROPERTY_FORCENEWPAGE)
1301 ,OUString(PROPERTY_KEEPTOGETHER)
1302 ,OUString(PROPERTY_CANGROW)
1303 ,OUString(PROPERTY_CANSHRINK)
1304 ,OUString(PROPERTY_REPEATSECTION)
1305 ,OUString(PROPERTY_PRINTREPEATEDVALUES)
1306 ,OUString(PROPERTY_CONDITIONALPRINTEXPRESSION)
1307 ,OUString(PROPERTY_STARTNEWCOLUMN)
1308 ,OUString(PROPERTY_RESETPAGENUMBER)
1309 ,OUString(PROPERTY_PRINTWHENGROUPCHANGE)
1310 ,OUString(PROPERTY_VISIBLE)
1311 ,OUString(PROPERTY_PAGEHEADEROPTION)
1312 ,OUString(PROPERTY_PAGEFOOTEROPTION)
1313 ,OUString("ControlLabel")
1314 ,OUString(PROPERTY_POSITIONX)
1315 ,OUString(PROPERTY_POSITIONY)
1316 ,OUString(PROPERTY_WIDTH)
1317 ,OUString(PROPERTY_HEIGHT)
1318 ,OUString(PROPERTY_PREEVALUATED)
1319 ,OUString(PROPERTY_DEEPTRAVERSING)
1320 ,OUString(PROPERTY_FORMULA)
1321 ,OUString(PROPERTY_INITIALFORMULA)
1322 ,OUString(PROPERTY_PRESERVEIRI)
1323 ,OUString(PROPERTY_DATAFIELD)
1324 ,OUString(PROPERTY_FONT)
1325 ,OUString(PROPERTY_BACKCOLOR)
1326 ,OUString(PROPERTY_BACKTRANSPARENT)
1327 ,OUString(PROPERTY_CONTROLBACKGROUND)
1328 ,OUString(PROPERTY_CONTROLBACKGROUNDTRANSPARENT)
1329 ,OUString(PROPERTY_LABEL)
1330 ,OUString(PROPERTY_MIMETYPE)
1331 ,OUString(PROPERTY_VERTICALALIGN)
1332 ,OUString(PROPERTY_PARAADJUST)
1334 const uno::Reference < beans::XPropertySetInfo > xInfo = m_xReportComponent->getPropertySetInfo();
1335 const uno::Sequence< beans::Property> aSeq = xInfo->getProperties();
1336 for (const auto & rIncludeProp : pIncludeProperties)
1338 const beans::Property* pFind = ::std::find_if(aSeq.begin(), aSeq.end(),
1339 [&rIncludeProp] (const beans::Property& x) -> bool {
1340 return x.Name == rIncludeProp;
1342 if ( pFind != aSeq.end() )
1344 // special case for controls which contain a data field
1345 if ( PROPERTY_DATAFIELD == rIncludeProp )
1347 beans::Property aValue;
1348 aValue.Name = PROPERTY_FORMULALIST;
1349 aNewProps.push_back(aValue);
1350 aValue.Name = PROPERTY_SCOPE;
1351 aNewProps.push_back(aValue);
1352 aValue.Name = PROPERTY_TYPE;
1353 aNewProps.push_back(aValue);
1355 aNewProps.push_back(*pFind);
1359 // special property for shapes
1360 // if ( uno::Reference< report::XShape>(m_xReportComponent,uno::UNO_QUERY).is() )
1361 // {
1362 // beans::Property aValue;
1363 // aValue.Name = PROPERTY_AREA;
1364 // aNewProps.push_back(aValue);
1365 // }
1366 // re-enable when the remaining issues of #i88727# are fixed
1368 return uno::Sequence< beans::Property > (&(*aNewProps.begin()),aNewProps.size());
1371 uno::Sequence< OUString > SAL_CALL GeometryHandler::getSupersededProperties()
1373 uno::Sequence< OUString > aRet;
1374 const uno::Reference<report::XReportDefinition> xReport(m_xReportComponent,uno::UNO_QUERY);
1375 if ( xReport.is() && !uno::Reference< report::XSection>(xReport->getParent(),uno::UNO_QUERY).is() )
1377 aRet.realloc(5);
1378 OUString* pIter = aRet.getArray();
1379 *pIter++ = PROPERTY_POSITIONX;
1380 *pIter++ = PROPERTY_POSITIONY;
1381 *pIter++ = PROPERTY_WIDTH;
1382 *pIter++ = PROPERTY_HEIGHT;
1383 *pIter++ = PROPERTY_DATAFIELD;
1385 return aRet;
1388 uno::Sequence< OUString > SAL_CALL GeometryHandler::getActuatingProperties()
1390 ::osl::MutexGuard aGuard( m_aMutex );
1392 uno::Sequence< OUString > aSeq(5);
1393 aSeq[0] = PROPERTY_BACKTRANSPARENT;
1394 aSeq[1] = PROPERTY_CONTROLBACKGROUNDTRANSPARENT;
1395 aSeq[2] = PROPERTY_FORMULALIST;
1396 aSeq[3] = PROPERTY_TYPE;
1397 aSeq[4] = PROPERTY_DATAFIELD;
1399 return ::comphelper::concatSequences(m_xFormComponentHandler->getActuatingProperties(),aSeq);
1402 sal_Bool SAL_CALL GeometryHandler::isComposable(const OUString & _rPropertyName)
1404 return OPropertyInfoService::isComposable( _rPropertyName, m_xFormComponentHandler );
1407 inspection::InteractiveSelectionResult SAL_CALL GeometryHandler::onInteractivePropertySelection(const OUString & PropertyName, sal_Bool Primary, uno::Any & _rData, const uno::Reference< inspection::XObjectInspectorUI > & _rxInspectorUI)
1409 if ( !_rxInspectorUI.is() )
1410 throw lang::NullPointerException();
1411 if (PropertyName == PROPERTY_FILTER)
1413 ::osl::ClearableMutexGuard aGuard( m_aMutex );
1415 inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
1416 OUString sClause;
1417 if ( impl_dialogFilter_nothrow( sClause, aGuard ) )
1419 _rData <<= sClause;
1420 eResult = inspection::InteractiveSelectionResult_ObtainedValue;
1422 return eResult;
1424 else if (PropertyName == PROPERTY_FONT)
1426 ::osl::ClearableMutexGuard aGuard( m_aMutex );
1428 inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
1429 const uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName("DialogParentWindow") ,uno::UNO_QUERY);
1430 const uno::Reference< report::XReportControlFormat> xReportControlFormat(m_xReportComponent,uno::UNO_QUERY);
1431 aGuard.clear();
1433 uno::Sequence< beans::NamedValue > aFontSettings;
1434 if ( rptui::openCharDialog( xReportControlFormat, xInspectorWindow, aFontSettings ) )
1436 _rData <<= aFontSettings;
1437 eResult = inspection::InteractiveSelectionResult_ObtainedValue;
1439 return eResult;
1441 else if ( PropertyName == PROPERTY_FORMULA
1442 || PropertyName == PROPERTY_INITIALFORMULA
1443 || PropertyName == PROPERTY_DATAFIELD
1444 || PropertyName == PROPERTY_CONDITIONALPRINTEXPRESSION)
1446 ::osl::ClearableMutexGuard aGuard( m_aMutex );
1449 OUString sFormula;
1450 m_xReportComponent->getPropertyValue(PropertyName) >>= sFormula;
1451 const uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName("DialogParentWindow") ,uno::UNO_QUERY);
1452 uno::Reference< uno::XComponentContext > xContext = m_xContext;
1453 uno::Reference< beans::XPropertySet > xRowSet( m_xRowSet,uno::UNO_QUERY);
1454 aGuard.clear();
1456 inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
1457 if ( rptui::openDialogFormula_nothrow( sFormula, xContext,xInspectorWindow,xRowSet ) )
1459 _rData <<= sFormula;
1460 eResult = inspection::InteractiveSelectionResult_ObtainedValue;
1462 return eResult;
1464 else if (PropertyName == PROPERTY_AREA)
1466 ::osl::ClearableMutexGuard aGuard( m_aMutex );
1468 inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
1469 const uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName("DialogParentWindow") ,uno::UNO_QUERY);
1470 const uno::Reference< report::XShape> xShape(m_xReportComponent,uno::UNO_QUERY);
1471 aGuard.clear();
1473 if ( rptui::openAreaDialog( xShape, xInspectorWindow) )
1475 eResult = inspection::InteractiveSelectionResult_ObtainedValue;
1476 beans::PropertyChangeEvent aScopeEvent;
1477 aScopeEvent.PropertyName = PROPERTY_FILLCOLOR;
1478 aScopeEvent.NewValue = xShape->getPropertyValue(PROPERTY_FILLCOLOR);
1479 m_aPropertyListeners.notify( aScopeEvent, &beans::XPropertyChangeListener::propertyChange );
1481 return eResult;
1485 return m_xFormComponentHandler->onInteractivePropertySelection(PropertyName, Primary, _rData, _rxInspectorUI);
1488 void SAL_CALL GeometryHandler::actuatingPropertyChanged(const OUString & ActuatingPropertyName, const uno::Any & NewValue, const uno::Any & OldValue, const uno::Reference< inspection::XObjectInspectorUI > & _rxInspectorUI, sal_Bool _bFirstTimeInit)
1490 if ( !_rxInspectorUI.is() )
1491 throw lang::NullPointerException();
1493 ::osl::MutexGuard aGuard( m_aMutex );
1494 const sal_Int32 nId = OPropertyInfoService::getPropertyId(ActuatingPropertyName);
1495 switch(nId)
1497 case PROPERTY_ID_TYPE:
1499 sal_uInt32 nNewVal = 0;
1500 NewValue >>= nNewVal;
1501 switch(nNewVal)
1503 case DATA_OR_FORMULA:
1504 _rxInspectorUI->rebuildPropertyUI(PROPERTY_DATAFIELD);
1505 _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,true);
1506 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,false);
1507 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,false);
1508 OSL_ENSURE(m_sDefaultFunction.isEmpty(),"Why is the m_sDefaultFunction set?");
1509 OSL_ENSURE(m_sScope.isEmpty(),"Why is the m_sScope set?");
1510 break;
1511 case FUNCTION:
1512 _rxInspectorUI->rebuildPropertyUI(PROPERTY_DATAFIELD);
1513 _rxInspectorUI->rebuildPropertyUI(PROPERTY_FORMULALIST);
1514 _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,true);
1515 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,!m_sDefaultFunction.isEmpty());
1516 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,!m_sScope.isEmpty());
1517 break;
1518 case USER_DEF_FUNCTION:
1519 _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,false);
1520 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,true);
1521 _rxInspectorUI->rebuildPropertyUI(PROPERTY_FORMULALIST);
1522 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,false);
1523 break;
1524 case COUNTER:
1525 _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,false);
1526 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,false);
1527 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,true);
1528 break;
1531 break;
1532 case PROPERTY_ID_DATAFIELD:
1534 bool bEnable = (m_nDataFieldType != DATA_OR_FORMULA && m_nDataFieldType != COUNTER );
1535 if ( bEnable )
1537 OUString sValue;
1538 m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD ) >>= sValue;
1539 bEnable = !sValue.isEmpty();
1541 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,bEnable);
1542 if ( bEnable )
1544 _rxInspectorUI->rebuildPropertyUI(PROPERTY_DATAFIELD);
1545 _rxInspectorUI->rebuildPropertyUI(PROPERTY_FORMULALIST);
1547 m_xFormComponentHandler->actuatingPropertyChanged(ActuatingPropertyName, NewValue, OldValue, _rxInspectorUI, _bFirstTimeInit);
1549 break;
1550 case PROPERTY_ID_FORMULALIST:
1552 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,m_nDataFieldType == FUNCTION || m_nDataFieldType == COUNTER);
1554 break;
1555 case PROPERTY_ID_BACKTRANSPARENT:
1556 case PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT:
1558 bool bValue = false;
1559 NewValue >>= bValue;
1560 bValue = !bValue;
1561 _rxInspectorUI->enablePropertyUI(PROPERTY_BACKCOLOR,bValue);
1562 _rxInspectorUI->enablePropertyUI(PROPERTY_CONTROLBACKGROUND,bValue);
1564 break;
1565 default:
1566 m_xFormComponentHandler->actuatingPropertyChanged(ActuatingPropertyName, NewValue, OldValue, _rxInspectorUI, _bFirstTimeInit);
1567 break;
1571 sal_Bool SAL_CALL GeometryHandler::suspend(sal_Bool Suspend)
1573 return m_xFormComponentHandler->suspend(Suspend);
1576 bool GeometryHandler::impl_dialogFilter_nothrow( OUString& _out_rSelectedClause, ::osl::ClearableMutexGuard& _rClearBeforeDialog ) const
1578 _out_rSelectedClause.clear();
1579 bool bSuccess = false;
1580 ::dbtools::SQLExceptionInfo aErrorInfo;
1581 uno::Reference< awt::XWindow > xInspectorWindow;
1582 uno::Reference< lang::XMultiComponentFactory > xFactory;
1585 xFactory = m_xContext->getServiceManager();
1586 xInspectorWindow.set(m_xContext->getValueByName("DialogParentWindow") ,uno::UNO_QUERY);
1587 uno::Reference<sdbc::XConnection> xCon(m_xContext->getValueByName("ActiveConnection") ,uno::UNO_QUERY);
1588 if ( !xCon.is() )
1589 return false;
1591 uno::Reference< beans::XPropertySet> xRowSetProp(m_xRowSet,uno::UNO_QUERY);
1592 if ( !m_xRowSet.is() )
1594 m_xRowSet.set(xFactory->createInstanceWithContext("com.sun.star.sdb.RowSet",m_xContext),uno::UNO_QUERY);
1595 xRowSetProp.set(m_xRowSet,uno::UNO_QUERY);
1596 xRowSetProp->setPropertyValue(PROPERTY_ACTIVECONNECTION,uno::makeAny(xCon));
1597 ::comphelper::copyProperties(m_xReportComponent,xRowSetProp);
1600 // get a composer for the statement which the form is currently based on
1601 uno::Reference< sdb::XSingleSelectQueryComposer > xComposer( ::dbtools::getCurrentSettingsComposer( xRowSetProp, m_xContext ) );
1602 OSL_ENSURE( xComposer.is(), "GeometryHandler::impl_dialogFilter_nothrow: could not obtain a composer!" );
1603 if ( !xComposer.is() )
1604 return false;
1606 // create the dialog
1607 uno::Reference< ui::dialogs::XExecutableDialog > xDialog = sdb::FilterDialog::createWithQuery(m_xContext, xComposer, m_xRowSet, xInspectorWindow);
1609 const OUString sPropertyUIName(RptResId(RID_STR_FILTER));
1610 // initialize the dialog
1611 xDialog->setTitle( sPropertyUIName );
1613 _rClearBeforeDialog.clear();
1614 bSuccess = ( xDialog->execute() != 0 );
1615 if ( bSuccess )
1616 _out_rSelectedClause = xComposer->getFilter();
1618 catch (const sdb::SQLContext& e) { aErrorInfo = e; }
1619 catch (const sdbc::SQLWarning& e) { aErrorInfo = e; }
1620 catch (const sdbc::SQLException& e) { aErrorInfo = e; }
1621 catch( const uno::Exception& )
1623 OSL_FAIL( "GeometryHandler::impl_dialogFilter_nothrow: caught an exception!" );
1626 if ( aErrorInfo.isValid() )
1627 ::dbtools::showError( aErrorInfo, xInspectorWindow, m_xContext );
1629 return bSuccess;
1632 void GeometryHandler::checkPosAndSize( const awt::Point& _aNewPos,
1633 const awt::Size& _aSize)
1635 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY);
1636 const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY);
1637 if ( !xSection.is() || uno::Reference< report::XShape>(xSourceReportComponent,uno::UNO_QUERY).is() ) // shapes can overlap.
1638 return;
1640 ::Point aPos(VCLPoint(_aNewPos));
1641 if ( aPos.X() < 0 || aPos.Y() < 0 ) // TODO: have to check size with pos aka || (aPos.X() + aAwtSize.Width) > m_xSection->getReportDefinition()->
1642 throw beans::PropertyVetoException(RptResId(RID_STR_ILLEGAL_POSITION),xSourceReportComponent);
1644 ::tools::Rectangle aSourceRect(aPos,VCLSize(_aSize));
1646 const sal_Int32 nCount = xSection->getCount();
1647 for (sal_Int32 i = 0; i < nCount ; ++i)
1649 const uno::Reference< report::XReportComponent> xReportComponent(xSection->getByIndex(i),uno::UNO_QUERY);
1650 if ( xReportComponent.is() && xReportComponent != xSourceReportComponent )
1652 const ::tools::Rectangle aBoundRect(VCLPoint(xReportComponent->getPosition()),VCLSize(xReportComponent->getSize()));
1653 const ::tools::Rectangle aRect = aSourceRect.GetIntersection(aBoundRect);
1654 if ( !aRect.IsEmpty() && (aRect.Left() != aRect.Right() && aRect.Top() != aRect.Bottom() ) )
1655 throw beans::PropertyVetoException(RptResId( RID_STR_OVERLAP_OTHER_CONTROL),xSourceReportComponent);
1660 void GeometryHandler::impl_fillFormulaList_nothrow(::std::vector< OUString >& out_rList) const
1662 if ( m_nDataFieldType == FUNCTION )
1664 for (auto const& it : m_aDefaultFunctions)
1666 out_rList.push_back(it.getName());
1669 else if ( m_nDataFieldType == USER_DEF_FUNCTION )
1670 ::std::transform( m_aFunctionNames.begin(),
1671 m_aFunctionNames.end(),
1672 ::std::back_inserter(out_rList),
1673 ::o3tl::select1st< TFunctions::value_type >() );
1676 OUString GeometryHandler::impl_ConvertUIToMimeType_nothrow(const OUString& _sUIName) const
1678 ::std::vector< OUString > aList;
1679 impl_fillMimeTypes_nothrow(aList);
1680 OUString sRet;
1681 ::std::vector< OUString >::const_iterator aFind = ::std::find(aList.begin(),aList.end(),_sUIName);
1682 if ( aFind != aList.end() )
1684 const std::size_t nPos = aFind - aList.begin();
1685 const uno::Reference< report::XReportDefinition> xReportDefinition(m_xReportComponent,uno::UNO_QUERY);
1686 if ( xReportDefinition.is() )
1688 const uno::Sequence< OUString > aMimeTypes( xReportDefinition->getAvailableMimeTypes() );
1689 sRet = aMimeTypes[nPos];
1692 return sRet;
1695 OUString GeometryHandler::impl_ConvertMimeTypeToUI_nothrow(const OUString& _sMimetype) const
1697 ::comphelper::MimeConfigurationHelper aMimeHelper(m_xContext);
1698 OUString sRet;
1699 std::shared_ptr<const SfxFilter> pFilter = SfxFilter::GetDefaultFilter( aMimeHelper.GetDocServiceNameFromMediaType(_sMimetype) );
1700 if ( pFilter )
1701 sRet = pFilter->GetUIName();
1702 if ( sRet.isEmpty() )
1703 sRet = _sMimetype;
1704 return sRet;
1707 void GeometryHandler::impl_fillMimeTypes_nothrow(::std::vector< OUString >& _out_rList) const
1711 const uno::Reference< report::XReportDefinition> xReportDefinition(m_xReportComponent,uno::UNO_QUERY);
1712 if ( xReportDefinition.is() )
1714 uno::Sequence< OUString > aMimeTypes( xReportDefinition->getAvailableMimeTypes() );
1715 const OUString* pIter = aMimeTypes.getConstArray();
1716 const OUString* pEnd = pIter + aMimeTypes.getLength();
1717 for(;pIter != pEnd; ++pIter)
1719 const OUString sDocName( impl_ConvertMimeTypeToUI_nothrow(*pIter) );
1720 if ( !sDocName.isEmpty() )
1721 _out_rList.push_back(sDocName);
1725 catch(uno::Exception&)
1727 OSL_FAIL("Exception caught!");
1731 void GeometryHandler::impl_fillScopeList_nothrow(::std::vector< OUString >& _out_rList) const
1735 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY_THROW);
1736 const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY_THROW);
1738 const uno::Reference< report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
1739 const uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups();
1740 sal_Int32 nPos = -1;
1741 uno::Reference< report::XGroup> xGroup = xSection->getGroup();
1742 if ( xGroup.is() )
1743 nPos = getPositionInIndexAccess(xGroups.get(),xGroup);
1744 else if ( xSection == xReportDefinition->getDetail() )
1745 nPos = xGroups->getCount()-1;
1747 const OUString sGroup = RptResId(RID_STR_SCOPE_GROUP);
1748 for (sal_Int32 i = 0 ; i <= nPos ; ++i)
1750 xGroup.set(xGroups->getByIndex(i),uno::UNO_QUERY_THROW);
1751 OUString sGroupName = sGroup.replaceFirst("%1",xGroup->getExpression());
1752 _out_rList.push_back(sGroupName);
1754 _out_rList.push_back(xReportDefinition->getName());
1756 catch(uno::Exception&)
1758 OSL_FAIL("Exception caught!");
1762 uno::Reference< report::XFunctionsSupplier> GeometryHandler::fillScope_throw(OUString& _rsNamePostfix)
1764 uno::Reference< report::XFunctionsSupplier> xReturn;
1766 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY_THROW);
1767 const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY_THROW);
1768 const uno::Reference< report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
1769 if ( m_sScope.isEmpty() )
1771 const uno::Reference< report::XGroup> xGroup(xSection->getGroup(),uno::UNO_QUERY);
1772 if ( xGroup.is() )
1774 OUString sGroupName = RptResId(RID_STR_SCOPE_GROUP);
1775 _rsNamePostfix = xGroup->getExpression();
1776 m_sScope = sGroupName.replaceFirst("%1",_rsNamePostfix);
1777 xReturn = xGroup.get();
1779 else if ( xSection == xReportDefinition->getDetail() )
1781 const uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups();
1782 const sal_Int32 nCount = xGroups->getCount();
1783 if ( nCount )
1785 const uno::Reference< report::XGroup> xGroup2(xGroups->getByIndex(nCount - 1),uno::UNO_QUERY_THROW);
1786 OUString sGroupName = RptResId(RID_STR_SCOPE_GROUP);
1787 _rsNamePostfix = xGroup2->getExpression();
1788 m_sScope = sGroupName.replaceFirst("%1",_rsNamePostfix);
1789 xReturn = xGroup2.get();
1792 if ( m_sScope.isEmpty() )
1794 xReturn = xReportDefinition.get();
1795 _rsNamePostfix = m_sScope = xReportDefinition->getName();
1798 else if ( m_sScope == xReportDefinition->getName() )
1800 xReturn = xReportDefinition.get();
1801 _rsNamePostfix = m_sScope;
1803 else
1805 uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups();
1806 const sal_Int32 nCount = xGroups->getCount();
1808 for (sal_Int32 i = 0 ; i < nCount; ++i)
1810 const uno::Reference< report::XGroup> xGroup(xGroups->getByIndex(i),uno::UNO_QUERY_THROW);
1811 OUString sGroupName = RptResId(RID_STR_SCOPE_GROUP);
1812 if ( m_sScope == sGroupName.replaceFirst("%1",xGroup->getExpression()) )
1814 _rsNamePostfix = xGroup->getExpression();
1815 xReturn = xGroup.get();
1816 break;
1821 OSL_ENSURE(xReturn.is(),"Why don't we have a functionssupplier here!");
1823 return xReturn;
1826 bool GeometryHandler::isDefaultFunction( const OUString& _sQuotedFunction
1827 ,OUString& _rDataField
1828 ,const uno::Reference< report::XFunctionsSupplier>& _xFunctionsSupplier
1829 ,bool _bSet) const
1831 bool bDefaultFunction = false;
1834 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY_THROW);
1835 const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY_THROW);
1836 const uno::Reference< report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
1838 ::std::pair<TFunctions::const_iterator,TFunctions::const_iterator> aFind = m_aFunctionNames.equal_range(_sQuotedFunction);
1839 while ( aFind.first != aFind.second )
1841 if ( !_xFunctionsSupplier.is() || _xFunctionsSupplier == aFind.first->second.second )
1843 const beans::Optional< OUString> aInitalFormula = aFind.first->second.first->getInitialFormula();
1844 if ( aInitalFormula.IsPresent )
1846 OUString sDefaultFunctionName;
1847 bDefaultFunction = impl_isDefaultFunction_nothrow(aFind.first->second.first,_rDataField,sDefaultFunctionName);
1848 if ( bDefaultFunction )
1850 m_xFunction = aFind.first->second.first;
1851 if ( _bSet )
1853 m_sDefaultFunction = sDefaultFunctionName;
1854 uno::Reference< report::XGroup> xGroup(aFind.first->second.second,uno::UNO_QUERY);
1855 if ( xGroup.is() )
1857 OUString sGroupName = RptResId(RID_STR_SCOPE_GROUP);
1858 m_sScope = sGroupName.replaceFirst("%1",xGroup->getExpression());
1860 else
1861 m_sScope = xReportDefinition->getName();
1864 break;
1867 ++(aFind.first);
1870 catch(uno::Exception&)
1872 OSL_FAIL("Exception caught!");
1874 return bDefaultFunction;
1877 bool GeometryHandler::impl_isDefaultFunction_nothrow( const uno::Reference< report::XFunction>& _xFunction
1878 ,OUString& _rDataField
1879 ,OUString& _rsDefaultFunctionName) const
1881 bool bDefaultFunction = false;
1884 const OUString sFormula( _xFunction->getFormula() );
1885 i18nutil::SearchOptions2 aSearchOptions;
1886 aSearchOptions.AlgorithmType2 = util::SearchAlgorithms2::REGEXP;
1887 aSearchOptions.searchFlag = 0x00000100;
1888 auto aIter = std::find_if(m_aDefaultFunctions.begin(), m_aDefaultFunctions.end(),
1889 [&aSearchOptions, &sFormula](const DefaultFunction& rDefaultFunction) {
1890 aSearchOptions.searchString = rDefaultFunction.m_sSearchString;
1891 utl::TextSearch aTextSearch( aSearchOptions);
1892 sal_Int32 start = 0;
1893 sal_Int32 end = sFormula.getLength();
1894 return aTextSearch.SearchForward(sFormula, &start, &end) && start == 0 && end == sFormula.getLength();
1896 if (aIter != m_aDefaultFunctions.end()) // default function found
1898 sal_Int32 start = 0;
1899 sal_Int32 end = sFormula.getLength();
1900 aSearchOptions.searchString = "\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]";
1901 utl::TextSearch aDataSearch( aSearchOptions);
1902 (void)aDataSearch.SearchForward(sFormula, &start, &end);
1903 ++start;
1904 _rDataField = sFormula.copy(start,end-start-1);
1905 _rsDefaultFunctionName = aIter->m_sName;
1906 bDefaultFunction = true;
1909 catch(uno::Exception&)
1911 OSL_FAIL("Exception caught!");
1913 return bDefaultFunction;
1916 void GeometryHandler::loadDefaultFunctions()
1918 if ( m_aDefaultFunctions.empty() )
1920 m_aCounterFunction.m_bPreEvaluated = false;
1921 m_aCounterFunction.m_sName = RptResId(RID_STR_F_COUNTER);
1922 m_aCounterFunction.m_sFormula = "rpt:[%FunctionName] + 1";
1923 m_aCounterFunction.m_sSearchString = "rpt:\\[[:alpha:]+([:space:]*[:alnum:]*)*\\][:space:]*\\+[:space:]*[:digit:]*";
1924 m_aCounterFunction.m_sInitialFormula.IsPresent = true;
1925 m_aCounterFunction.m_sInitialFormula.Value = "rpt:1";
1927 DefaultFunction aDefault;
1929 aDefault.m_bPreEvaluated = true;
1931 aDefault.m_sName = RptResId(RID_STR_F_ACCUMULATION);
1932 aDefault.m_sFormula = "rpt:[%Column] + [%FunctionName]";
1933 aDefault.m_sSearchString = "rpt:\\[[:alpha:]+([:space:]*[:alnum:]*)*\\][:space:]*\\+[:space:]*\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]";
1934 aDefault.m_sInitialFormula.IsPresent = true;
1935 aDefault.m_sInitialFormula.Value = "rpt:[%Column]";
1936 m_aDefaultFunctions.push_back(aDefault);
1938 aDefault.m_sName = RptResId(RID_STR_F_MINIMUM);
1939 aDefault.m_sFormula = "rpt:IF([%Column] < [%FunctionName];[%Column];[%FunctionName])";
1940 aDefault.m_sSearchString = "rpt:IF\\((\\[[:alpha:]+([:space:]*[:alnum:]*)*\\])[:space:]*<[:space:]*(\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]);[:space:]*\\1[:space:]*;[:space:]*\\3[:space:]*\\)";
1941 aDefault.m_sInitialFormula.IsPresent = true;
1942 aDefault.m_sInitialFormula.Value = "rpt:[%Column]";
1943 m_aDefaultFunctions.push_back(aDefault);
1945 aDefault.m_sName = RptResId(RID_STR_F_MAXIMUM);
1946 aDefault.m_sFormula = "rpt:IF([%Column] > [%FunctionName];[%Column];[%FunctionName])";
1947 aDefault.m_sSearchString = "rpt:IF\\((\\[[:alpha:]+([:space:]*[:alnum:]*)*\\])[:space:]*>[:space:]*(\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]);[:space:]*\\1[:space:]*;[:space:]*\\3[:space:]*\\)";
1948 aDefault.m_sInitialFormula.IsPresent = true;
1949 aDefault.m_sInitialFormula.Value = "rpt:[%Column]";
1950 m_aDefaultFunctions.push_back(aDefault);
1954 void GeometryHandler::createDefaultFunction(::osl::ResettableMutexGuard& _aGuard ,const OUString& _sFunction,const OUString& _sDataField)
1958 OUString sNamePostfix;
1959 const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostfix);
1961 auto aIter = std::find_if(m_aDefaultFunctions.begin(), m_aDefaultFunctions.end(),
1962 [&_sFunction](const DefaultFunction& rDefaultFunction) { return rDefaultFunction.m_sName == _sFunction; });
1963 if (aIter != m_aDefaultFunctions.end())
1965 const OUString sFunctionName( _sFunction + _sDataField + sNamePostfix);
1966 const OUString sQuotedFunctionName(lcl_getQuotedFunctionName(sFunctionName));
1968 beans::PropertyChangeEvent aEvent;
1969 aEvent.PropertyName = PROPERTY_SCOPE;
1970 aEvent.OldValue <<= m_sScope;
1972 ::std::pair<TFunctions::const_iterator,TFunctions::const_iterator> aFind = m_aFunctionNames.equal_range(sQuotedFunctionName);
1973 while ( aFind.first != aFind.second )
1975 if ( xFunctionsSupplier == aFind.first->second.second )
1977 m_xFunction = aFind.first->second.first;
1978 OUString sTemp;
1979 isDefaultFunction(sQuotedFunctionName,sTemp,uno::Reference< report::XFunctionsSupplier>(),true); // implicitly sets the m_sScope
1980 break;
1982 ++(aFind.first);
1984 if ( aFind.first == aFind.second )
1985 impl_createFunction(sFunctionName,_sDataField,*aIter);
1987 OBlocker aBlocker(m_bIn);
1988 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny( impl_convertToFormula( uno::makeAny(sQuotedFunctionName) )));
1989 aEvent.NewValue <<= m_sScope;
1990 _aGuard.clear();
1991 m_aPropertyListeners.notify( aEvent, &beans::XPropertyChangeListener::propertyChange );
1994 catch(uno::Exception&)
1996 OSL_FAIL("Exception caught!");
2000 void GeometryHandler::removeFunction()
2002 if ( m_xFunction.is() )
2004 const OUString sQuotedFunctionName(lcl_getQuotedFunctionName(m_xFunction));
2005 ::std::pair<TFunctions::iterator,TFunctions::iterator> aFind = m_aFunctionNames.equal_range(sQuotedFunctionName);
2006 while ( aFind.first != aFind.second )
2008 if ( aFind.first->second.first == m_xFunction )
2010 uno::Reference< report::XFunctions> xFunctions = aFind.first->second.second->getFunctions();
2011 xFunctions->removeByIndex(xFunctions->getCount() - 1 ); /// TODO: insert new method in XFunctions: removeFunction(xfunction)
2012 m_aFunctionNames.erase(aFind.first);
2013 m_bNewFunction = false;
2014 break;
2016 ++(aFind.first);
2021 void GeometryHandler::resetOwnProperties(::osl::ResettableMutexGuard& _aGuard,const OUString& _sOldFunctionName,const OUString& _sOldScope,const sal_uInt32 _nOldDataFieldType)
2023 const OUString sNewFunction = m_sDefaultFunction;
2024 const OUString sNewScope = m_sScope;
2025 const sal_uInt32 nNewDataFieldType = m_nDataFieldType;
2026 _aGuard.clear();
2027 if ( _nOldDataFieldType != nNewDataFieldType )
2029 beans::PropertyChangeEvent aScopeEvent;
2030 aScopeEvent.PropertyName = PROPERTY_TYPE;
2031 aScopeEvent.OldValue <<= _nOldDataFieldType;
2032 aScopeEvent.NewValue <<= nNewDataFieldType;
2033 m_aPropertyListeners.notify( aScopeEvent, &beans::XPropertyChangeListener::propertyChange );
2035 if ( _sOldFunctionName != sNewFunction )
2037 beans::PropertyChangeEvent aFormulaEvent;
2038 aFormulaEvent.PropertyName = PROPERTY_FORMULALIST;
2039 aFormulaEvent.OldValue <<= _sOldFunctionName;
2040 aFormulaEvent.NewValue <<= sNewFunction;
2042 m_aPropertyListeners.notify( aFormulaEvent, &beans::XPropertyChangeListener::propertyChange );
2044 if ( _sOldScope != sNewScope )
2046 beans::PropertyChangeEvent aScopeEvent;
2047 aScopeEvent.PropertyName = PROPERTY_SCOPE;
2048 aScopeEvent.OldValue <<= _sOldScope;
2049 aScopeEvent.NewValue <<= sNewScope;
2050 m_aPropertyListeners.notify( aScopeEvent, &beans::XPropertyChangeListener::propertyChange );
2053 _aGuard.reset();
2056 void GeometryHandler::impl_initFieldList_nothrow( uno::Sequence< OUString >& _rFieldNames ) const
2058 _rFieldNames.realloc(0);
2061 uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName("DialogParentWindow") ,uno::UNO_QUERY);
2062 VclPtr<vcl::Window> pInspectorWindow = VCLUnoHelper::GetWindow( xInspectorWindow );
2063 WaitObject aWaitCursor( pInspectorWindow );
2065 // get the form of the control we're inspecting
2066 uno::Reference< beans::XPropertySet > xFormSet( m_xRowSet, uno::UNO_QUERY );
2067 if ( !xFormSet.is() )
2068 return;
2070 OUString sObjectName;
2071 OSL_VERIFY( xFormSet->getPropertyValue( PROPERTY_COMMAND ) >>= sObjectName );
2072 // when there is no command we don't need to ask for columns
2073 uno::Reference<sdbc::XConnection> xCon(m_xContext->getValueByName("ActiveConnection") ,uno::UNO_QUERY);
2074 if ( !sObjectName.isEmpty() && xCon.is() )
2076 sal_Int32 nObjectType = sdb::CommandType::COMMAND;
2077 OSL_VERIFY( xFormSet->getPropertyValue( PROPERTY_COMMANDTYPE ) >>= nObjectType );
2079 _rFieldNames = ::dbtools::getFieldNamesByCommandDescriptor( xCon, nObjectType, sObjectName );
2082 catch (uno::Exception&)
2084 OSL_FAIL( "GeometryHandler::impl_initFieldList_nothrow: caught an exception!" );
2088 bool GeometryHandler::impl_isCounterFunction_throw(const OUString& _sQuotedFunctionName,OUString& Out_sScope) const
2090 ::std::pair<TFunctions::const_iterator,TFunctions::const_iterator> aFind = m_aFunctionNames.equal_range(_sQuotedFunctionName);
2091 while ( aFind.first != aFind.second )
2093 const beans::Optional< OUString> aInitalFormula = aFind.first->second.first->getInitialFormula();
2094 if ( aInitalFormula.IsPresent )
2096 const OUString sFormula( aFind.first->second.first->getFormula() );
2097 i18nutil::SearchOptions2 aSearchOptions;
2098 aSearchOptions.AlgorithmType2 = util::SearchAlgorithms2::REGEXP;
2099 aSearchOptions.searchFlag = 0x00000100;
2100 aSearchOptions.searchString = m_aCounterFunction.m_sSearchString;
2101 utl::TextSearch aTextSearch( aSearchOptions);
2102 sal_Int32 start = 0;
2103 sal_Int32 end = sFormula.getLength();
2104 if ( aTextSearch.SearchForward(sFormula,&start,&end) && start == 0 && end == sFormula.getLength()) // counter function found
2106 const uno::Reference< report::XGroup > xGroup(aFind.first->second.second,uno::UNO_QUERY);
2107 if ( xGroup.is() )
2109 OUString sGroupName = RptResId(RID_STR_SCOPE_GROUP);
2110 Out_sScope = sGroupName.replaceFirst("%1",xGroup->getExpression());
2112 else
2113 Out_sScope = uno::Reference< report::XReportDefinition >(aFind.first->second.second,uno::UNO_QUERY_THROW)->getName();
2114 break;
2117 ++(aFind.first);
2119 return aFind.first != aFind.second;
2122 void GeometryHandler::impl_createFunction(const OUString& _sFunctionName,const OUString& _sDataField,const DefaultFunction& _aFunction)
2124 if ( m_bNewFunction )
2125 removeFunction();
2127 const OUString sQuotedFunctionName(lcl_getQuotedFunctionName(_sFunctionName));
2128 m_xFunction.set(report::Function::create(m_xContext));
2129 m_xFunction->setName( _sFunctionName );
2131 const OUString sPlaceHolder1("%Column");
2132 const OUString sPlaceHolder2("%FunctionName");
2133 OUString sFormula(_aFunction.m_sFormula);
2134 sFormula = sFormula.replaceAll(sPlaceHolder1,_sDataField);
2135 sFormula = sFormula.replaceAll(sPlaceHolder2,_sFunctionName);
2137 m_xFunction->setFormula(sFormula);
2138 m_xFunction->setPreEvaluated(_aFunction.m_bPreEvaluated);
2139 m_xFunction->setDeepTraversing(false);
2140 if ( _aFunction.m_sInitialFormula.IsPresent )
2142 beans::Optional< OUString> aInitialFormula = _aFunction.m_sInitialFormula;
2143 OUString sInitialFormula = aInitialFormula.Value;
2144 sInitialFormula = sInitialFormula.replaceAll(sPlaceHolder1,_sDataField);
2145 sInitialFormula = sInitialFormula.replaceAll(sPlaceHolder2,_sFunctionName);
2146 aInitialFormula.Value = sInitialFormula;
2147 m_xFunction->setInitialFormula( aInitialFormula );
2149 OUString sNamePostfix;
2150 const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostfix);
2151 const uno::Reference< container::XIndexContainer> xFunctions(xFunctionsSupplier->getFunctions(),uno::UNO_QUERY_THROW);
2152 xFunctions->insertByIndex(xFunctions->getCount(),uno::makeAny(m_xFunction));
2153 m_aFunctionNames.emplace(sQuotedFunctionName,TFunctionPair(m_xFunction,xFunctionsSupplier));
2154 m_bNewFunction = true;
2157 void GeometryHandler::impl_setCounterFunction_throw()
2159 OUString sNamePostfix;
2160 fillScope_throw(sNamePostfix);
2161 OUString sFunctionName = m_aCounterFunction.m_sName;
2162 sFunctionName += sNamePostfix;
2163 const OUString sQuotedFunctionName = lcl_getQuotedFunctionName(sFunctionName);
2164 OUString sScope;
2165 if ( !(!sFunctionName.isEmpty() && m_aFunctionNames.find(sQuotedFunctionName) != m_aFunctionNames.end() && impl_isCounterFunction_throw(sQuotedFunctionName,sScope)) )
2166 impl_createFunction(sFunctionName,OUString(),m_aCounterFunction);
2168 OBlocker aBlocker(m_bIn);
2169 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(impl_convertToFormula( uno::makeAny(sQuotedFunctionName))));
2172 sal_uInt32 GeometryHandler::impl_getDataFieldType_throw(const OUString& _sDataField) const
2174 sal_uInt32 nDataFieldType = UNDEF_DATA;
2175 OUString sDataField;
2176 if ( !_sDataField.isEmpty() )
2177 sDataField = _sDataField;
2178 else
2180 uno::Any aDataField( m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD ) );
2181 lcl_convertFormulaTo(aDataField,aDataField);
2182 aDataField >>= sDataField;
2185 if ( !sDataField.isEmpty() )
2187 if ( impl_isDataField(sDataField) )
2188 nDataFieldType = DATA_OR_FORMULA;
2189 else if ( isDefaultFunction(sDataField,sDataField) )
2190 nDataFieldType = FUNCTION;
2191 else if ( m_aFunctionNames.find(sDataField) != m_aFunctionNames.end() )
2193 nDataFieldType = USER_DEF_FUNCTION;
2194 OUString sScope;
2195 if ( impl_isCounterFunction_throw(sDataField,sScope) )
2196 nDataFieldType = COUNTER;
2198 else
2199 nDataFieldType = DATA_OR_FORMULA;
2201 return nDataFieldType;
2204 // XEventListener
2205 void SAL_CALL GeometryHandler::disposing(const lang::EventObject& )
2208 // XPropertyChangeListener
2209 void SAL_CALL GeometryHandler::propertyChange(const beans::PropertyChangeEvent& /*evt*/)
2211 ::osl::ResettableMutexGuard aGuard( m_aMutex );
2212 if ( !m_bIn )
2214 const sal_uInt32 nOldDataFieldType = m_nDataFieldType;
2215 const OUString sOldFunctionName = m_sDefaultFunction;
2216 const OUString sOldScope = m_sScope;
2217 m_sDefaultFunction.clear();
2218 m_sScope.clear();
2219 m_nDataFieldType = impl_getDataFieldType_throw();
2220 if ( UNDEF_DATA == m_nDataFieldType )
2221 m_nDataFieldType = nOldDataFieldType;
2222 uno::Any aDataField = m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD );
2223 lcl_convertFormulaTo(aDataField,aDataField);
2224 OUString sDataField;
2225 aDataField >>= sDataField;
2226 switch(m_nDataFieldType)
2228 case FUNCTION:
2229 isDefaultFunction(sDataField,sDataField,uno::Reference< report::XFunctionsSupplier>(),true);
2230 break;
2231 case COUNTER:
2232 impl_isCounterFunction_throw(sDataField,m_sScope);
2233 break;
2234 default:
2238 resetOwnProperties(aGuard,sOldFunctionName,sOldScope,nOldDataFieldType);
2242 } // namespace rptui
2245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */