merge the formfield patch from ooo-build
[ooovba.git] / reportdesign / source / ui / inspection / GeometryHandler.cxx
blob3c75b6637e786705f899c8bfb1d989249eaffb0a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: GeometryHandler.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "precompiled_reportdesign.hxx"
31 #include "GeometryHandler.hxx"
33 #include <comphelper/sequence.hxx>
34 #include <comphelper/types.hxx>
35 #include <comphelper/property.hxx>
36 #include <comphelper/mimeconfighelper.hxx>
38 #include "uistrings.hrc"
39 #include "reportformula.hxx"
41 #include <unotools/textsearch.hxx>
42 #include <unotools/configmgr.hxx>
44 #include <toolkit/helper/vclunohelper.hxx>
45 #include <svtools/syslocale.hxx>
46 #include <tools/diagnose_ex.h>
47 #include <tools/StringListResource.hxx>
48 #include <com/sun/star/lang/XInitialization.hpp>
49 #include "com/sun/star/inspection/StringRepresentation.hpp"
50 #include <com/sun/star/inspection/PropertyLineElement.hpp>
51 #include <com/sun/star/inspection/PropertyControlType.hpp>
52 #include <com/sun/star/inspection/XStringListControl.hpp>
53 #include <com/sun/star/report/Function.hpp>
54 #include <com/sun/star/report/XReportDefinition.hpp>
55 #include <com/sun/star/report/XShape.hpp>
56 #include <com/sun/star/report/XSection.hpp>
57 #include <com/sun/star/report/XFormattedField.hpp>
58 #include <com/sun/star/report/XFixedLine.hpp>
59 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
60 #include <com/sun/star/sdb/CommandType.hpp>
61 #include <com/sun/star/sdb/SQLContext.hpp>
62 #include <com/sun/star/sdbc/XConnection.hpp>
63 #include <com/sun/star/util/SearchOptions.hpp>
64 #include <com/sun/star/util/MeasureUnit.hpp>
65 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
66 #include <com/sun/star/container/XNameContainer.hpp>
67 #include <com/sun/star/inspection/XNumericControl.hpp>
68 #include <com/sun/star/style/ParagraphAdjust.hpp>
70 #include <vcl/msgbox.hxx>
71 #include <vcl/waitobj.hxx>
72 #include <vcl/fldunit.hxx>
73 #include <vcl/stdtext.hxx>
75 #include "ModuleHelper.hxx"
76 #include "RptResId.hrc"
77 #include "RptDef.hxx"
78 #include "UITools.hxx"
80 #include <connectivity/dbexception.hxx>
81 #include <connectivity/dbconversion.hxx>
82 #include <connectivity/dbtools.hxx>
84 #include <boost/bind.hpp>
85 #include <tools/string.hxx>
86 #include "metadata.hxx"
87 #include <svtools/itempool.hxx>
88 #include <svtools/itemset.hxx>
90 #define ITEMID_COLOR_TABLE SID_COLOR_TABLE
91 #define ITEMID_DASH_LIST SID_DASH_LIST
92 #define ITEMID_LINEEND_LIST SID_LINEEND_LIST
93 #include <svx/xdef.hxx>
94 #include <svx/xpool.hxx>
95 #include <svx/xtable.hxx>
96 #include <svx/xlnwtit.hxx>
97 #include <svx/xlntrit.hxx>
98 #include <svx/xlnclit.hxx>
99 #include <svx/xlnstit.hxx>
100 #include <svx/xlnedit.hxx>
101 #include <svx/xlnstwit.hxx>
102 #include <svx/xlnedwit.hxx>
103 #include <svx/xlnstcit.hxx>
104 #include <svx/xlnedcit.hxx>
105 #include <svx/xlndsit.hxx>
106 #include <svx/xlineit0.hxx>
107 #include <svx/svxids.hrc>
109 #define ITEMID_COLOR_TABLE SID_COLOR_TABLE
110 #define ITEMID_DASH_LIST SID_DASH_LIST
111 #define ITEMID_LINEEND_LIST SID_LINEEND_LIST
112 #include <svx/drawitem.hxx>
113 #define ITEMID_BRUSH SID_ATTR_BRUSH
114 #include <svx/brshitem.hxx>
115 #include <sfx2/docfilt.hxx>
117 #include "dlgpage.hxx"
118 #include "helpids.hrc"
119 #include <toolkit/helper/convert.hxx>
121 #define DATA_OR_FORMULA 0
122 #define FUNCTION 1
123 #define COUNTER 2
124 #define USER_DEF_FUNCTION 3
125 #define UNDEF_DATA 4
127 //........................................................................
128 namespace rptui
130 //........................................................................
131 using namespace ::com::sun::star;
132 //using namespace formula;
134 // comparing two property instances
135 struct PropertyCompare : public ::std::binary_function< beans::Property, ::rtl::OUString , bool >
137 bool operator() (const beans::Property& x, const ::rtl::OUString& y) const
139 return x.Name.equals(y);// ? true : false;
141 bool operator() (const ::rtl::OUString& x,const beans::Property& y) const
143 return x.equals(y.Name);// ? true : false;
147 // -----------------------------------------------------------------------------
148 ::rtl::OUString lcl_getQuotedFunctionName(const ::rtl::OUString& _sFunction)
150 ::rtl::OUString sQuotedFunctionName(RTL_CONSTASCII_USTRINGPARAM("["));
151 sQuotedFunctionName += _sFunction + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("]"));
152 return sQuotedFunctionName;
154 // -----------------------------------------------------------------------------
155 ::rtl::OUString lcl_getQuotedFunctionName(const uno::Reference< report::XFunction>& _xFunction)
157 return lcl_getQuotedFunctionName(_xFunction->getName());
159 // -----------------------------------------------------------------------------
160 void lcl_collectFunctionNames(const uno::Reference< report::XFunctions>& _xFunctions,TFunctions& _rFunctionNames)
162 uno::Reference< report::XFunctionsSupplier> xParent(_xFunctions->getParent(),uno::UNO_QUERY_THROW);
163 const sal_Int32 nCount = _xFunctions->getCount();
164 for (sal_Int32 i = 0; i < nCount ; ++i)
166 uno::Reference< report::XFunction > xFunction(_xFunctions->getByIndex(i),uno::UNO_QUERY_THROW);
167 _rFunctionNames.insert(TFunctions::value_type(lcl_getQuotedFunctionName(xFunction),TFunctionPair(xFunction,xParent)));
170 // -----------------------------------------------------------------------------
171 void lcl_collectFunctionNames(const uno::Reference< report::XSection>& _xSection,TFunctions& _rFunctionNames)
173 const uno::Reference< report::XReportDefinition> xReportDefinition = _xSection->getReportDefinition();
174 const uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups();
175 sal_Int32 nPos = -1;
176 uno::Reference< report::XGroup> xGroup = _xSection->getGroup();
177 if ( xGroup.is() )
178 nPos = getPositionInIndexAccess(xGroups.get(),xGroup);
179 else if ( _xSection == xReportDefinition->getDetail() )
180 nPos = xGroups->getCount()-1;
182 for (sal_Int32 i = 0 ; i <= nPos ; ++i)
184 xGroup.set(xGroups->getByIndex(i),uno::UNO_QUERY_THROW);
185 lcl_collectFunctionNames(xGroup->getFunctions(),_rFunctionNames);
187 lcl_collectFunctionNames(xReportDefinition->getFunctions(),_rFunctionNames);
189 // -----------------------------------------------------------------------------
190 void lcl_convertFormulaTo(const uno::Any& _aPropertyValue,uno::Any& _rControlValue)
192 ::rtl::OUString sName;
193 _aPropertyValue >>= sName;
194 const sal_Int32 nLen = sName.getLength();
195 if ( nLen )
197 ReportFormula aFormula( sName );
198 _rControlValue <<= aFormula.getUndecoratedContent();
201 // -----------------------------------------------------------------------------
202 bool GeometryHandler::impl_isDataField(const ::rtl::OUString& _sName) const
204 const ::rtl::OUString* pEnd = m_aFieldNames.getConstArray() + m_aFieldNames.getLength();
205 bool bIsField = ( ::std::find( m_aFieldNames.getConstArray(), pEnd, _sName ) != pEnd );
207 if ( !bIsField )
209 pEnd = m_aParamNames.getConstArray() + m_aParamNames.getLength();
210 bIsField = ( ::std::find( m_aParamNames.getConstArray(), pEnd, _sName ) != pEnd );
212 return bIsField;
214 // -----------------------------------------------------------------------------
215 ::rtl::OUString GeometryHandler::impl_convertToFormula( const uno::Any& _rControlValue )
217 ::rtl::OUString sName;
218 _rControlValue >>= sName;
220 if ( !sName.getLength() )
221 return sName;
223 ReportFormula aParser( sName );
224 if ( aParser.isValid() )
225 return sName;
227 aParser = ReportFormula( impl_isDataField(sName) ? ReportFormula::Field : ReportFormula::Expression, sName );
228 return aParser.getCompleteFormula();
230 DBG_NAME(rpt_GeometryHandler)
231 GeometryHandler::GeometryHandler(uno::Reference< uno::XComponentContext > const & context) :
232 GeometryHandler_Base(m_aMutex)
233 ,m_aPropertyListeners( m_aMutex )
234 ,m_xContext(context)
235 ,m_pInfoService(new OPropertyInfoService())
236 ,m_nDataFieldType(0)
237 ,m_bIn(false)
239 DBG_CTOR(rpt_GeometryHandler,NULL);
242 const uno::Reference< lang::XMultiComponentFactory > xFac = m_xContext->getServiceManager();
243 m_xFormComponentHandler.set(xFac->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.inspection.FormComponentPropertyHandler")),m_xContext),uno::UNO_QUERY_THROW);
244 m_xTypeConverter.set(xFac->createInstanceWithContext( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter" )),m_xContext),uno::UNO_QUERY_THROW);
245 loadDefaultFunctions();
247 catch(const uno::Exception&)
251 // -----------------------------------------------------------------------------
252 GeometryHandler::~GeometryHandler()
254 DBG_DTOR(rpt_GeometryHandler,NULL);
256 //------------------------------------------------------------------------
257 ::rtl::OUString SAL_CALL GeometryHandler::getImplementationName( ) throw(uno::RuntimeException)
259 return getImplementationName_Static();
262 //------------------------------------------------------------------------
263 sal_Bool SAL_CALL GeometryHandler::supportsService( const ::rtl::OUString& ServiceName ) throw(uno::RuntimeException)
265 return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_static());
268 //------------------------------------------------------------------------
269 uno::Sequence< ::rtl::OUString > SAL_CALL GeometryHandler::getSupportedServiceNames( ) throw(uno::RuntimeException)
271 return getSupportedServiceNames_static();
274 //------------------------------------------------------------------------
275 ::rtl::OUString GeometryHandler::getImplementationName_Static( ) throw(uno::RuntimeException)
277 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.GeometryHandler"));
280 //------------------------------------------------------------------------
281 uno::Sequence< ::rtl::OUString > GeometryHandler::getSupportedServiceNames_static( ) throw(uno::RuntimeException)
283 uno::Sequence< ::rtl::OUString > aSupported(1);
284 aSupported[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.inspection.GeometryHandler"));
285 return aSupported;
288 //------------------------------------------------------------------------
289 uno::Reference< uno::XInterface > SAL_CALL GeometryHandler::create( const uno::Reference< uno::XComponentContext >& _rxContext )
291 return *(new GeometryHandler( _rxContext ));
293 // overload WeakComponentImplHelperBase::disposing()
294 // This function is called upon disposing the component,
295 // if your component needs special work when it becomes
296 // disposed, do it here.
297 void SAL_CALL GeometryHandler::disposing()
301 ::comphelper::disposeComponent(m_xFormComponentHandler);
302 ::comphelper::disposeComponent(m_xTypeConverter);
303 if ( m_xReportComponent.is() && m_xReportComponent->getPropertySetInfo()->hasPropertyByName(PROPERTY_DATAFIELD) )
304 m_xReportComponent->removePropertyChangeListener(PROPERTY_DATAFIELD,static_cast< beans::XPropertyChangeListener* >( this ));
306 m_xReportComponent.clear();
307 m_xRowSet.clear();
308 m_aPropertyListeners.clear();
310 catch(uno::Exception&)
313 void SAL_CALL GeometryHandler::addEventListener(const uno::Reference< lang::XEventListener > & xListener) throw (uno::RuntimeException)
315 m_xFormComponentHandler->addEventListener(xListener);
318 void SAL_CALL GeometryHandler::removeEventListener(const uno::Reference< lang::XEventListener > & aListener) throw (uno::RuntimeException)
320 m_xFormComponentHandler->removeEventListener(aListener);
323 // inspection::XPropertyHandler:
325 /********************************************************************************/
326 void SAL_CALL GeometryHandler::inspect( const uno::Reference< uno::XInterface > & _rxInspectee ) throw (uno::RuntimeException, lang::NullPointerException)
328 ::osl::MutexGuard aGuard( m_aMutex );
329 m_sScope = m_sDefaultFunction = ::rtl::OUString();
330 m_bNewFunction = false;
331 m_nDataFieldType = 0;
332 m_xFunction.clear();
333 m_aFunctionNames.clear();
336 if ( m_xReportComponent.is() && m_xReportComponent->getPropertySetInfo()->hasPropertyByName(PROPERTY_DATAFIELD) )
337 m_xReportComponent->removePropertyChangeListener(PROPERTY_DATAFIELD,static_cast< beans::XPropertyChangeListener* >( this ));
339 const uno::Reference< container::XNameContainer > xObjectAsContainer( _rxInspectee, uno::UNO_QUERY );
340 m_xReportComponent.set( xObjectAsContainer->getByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ReportComponent" ) ) ), uno::UNO_QUERY );
342 const ::rtl::OUString sRowSet(RTL_CONSTASCII_USTRINGPARAM("RowSet"));
343 if ( xObjectAsContainer->hasByName( sRowSet ) )
345 const uno::Any aRowSet( xObjectAsContainer->getByName(sRowSet) );
346 aRowSet >>= m_xRowSet;
347 // forward the rowset to our delegator handler
348 uno::Reference< beans::XPropertySet > xProp( m_xFormComponentHandler,uno::UNO_QUERY );
349 xProp->setPropertyValue( sRowSet, aRowSet );
351 m_aParamNames = getParameterNames( m_xRowSet );
352 impl_initFieldList_nothrow(m_aFieldNames);
353 if ( m_xReportComponent->getPropertySetInfo()->hasPropertyByName(PROPERTY_DATAFIELD) )
354 m_xReportComponent->addPropertyChangeListener(PROPERTY_DATAFIELD,static_cast< beans::XPropertyChangeListener* >( this ));
357 const uno::Reference< report::XReportComponent> xReportComponent( m_xReportComponent, uno::UNO_QUERY);
358 uno::Reference< report::XSection> xSection( m_xReportComponent, uno::UNO_QUERY );
359 if ( !xSection.is() && xReportComponent.is() )
360 xSection = xReportComponent->getSection();
361 if ( xSection.is() )
362 lcl_collectFunctionNames( xSection, m_aFunctionNames );
364 catch(uno::Exception)
366 throw lang::NullPointerException();
368 m_xFormComponentHandler->inspect(m_xReportComponent);
371 uno::Any SAL_CALL GeometryHandler::getPropertyValue(const ::rtl::OUString & PropertyName) throw (uno::RuntimeException, beans::UnknownPropertyException)
373 ::osl::MutexGuard aGuard( m_aMutex );
374 uno::Any aPropertyValue;
375 const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName);
376 switch(nId)
378 case PROPERTY_ID_CONDITIONALPRINTEXPRESSION:
379 case PROPERTY_ID_INITIALFORMULA:
380 case PROPERTY_ID_FORMULA:
381 case PROPERTY_ID_DATAFIELD:
382 aPropertyValue = m_xReportComponent->getPropertyValue( PropertyName );
383 lcl_convertFormulaTo(aPropertyValue,aPropertyValue);
384 if ( PROPERTY_ID_DATAFIELD == nId )
386 ::rtl::OUString sDataField;
387 aPropertyValue >>= sDataField;
388 switch(m_nDataFieldType)
390 case DATA_OR_FORMULA:
391 break;
392 case FUNCTION:
393 if ( isDefaultFunction(sDataField,sDataField) )
394 aPropertyValue <<= sDataField;
395 else if ( !sDataField.getLength() )
396 aPropertyValue = uno::Any();
397 break;
398 case COUNTER:
399 case USER_DEF_FUNCTION:
400 aPropertyValue = uno::Any();
401 break;
405 break;
406 case PROPERTY_ID_TYPE:
408 const sal_uInt32 nOldDataFieldType = m_nDataFieldType;
409 m_nDataFieldType = impl_getDataFieldType_throw();
410 if ( UNDEF_DATA == m_nDataFieldType )
411 m_nDataFieldType = nOldDataFieldType;
412 aPropertyValue <<= m_nDataFieldType;
414 break;
415 case PROPERTY_ID_FORMULALIST:
416 case PROPERTY_ID_SCOPE:
418 uno::Any aDataField = m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD );
419 lcl_convertFormulaTo(aDataField,aDataField);
420 ::rtl::OUString sDataField;
421 aDataField >>= sDataField;
422 switch(m_nDataFieldType)
424 case DATA_OR_FORMULA:
425 break;
426 case FUNCTION:
427 if ( isDefaultFunction(sDataField,sDataField,uno::Reference< report::XFunctionsSupplier>(),true) )
428 aPropertyValue <<= (PROPERTY_ID_FORMULALIST == nId ? m_sDefaultFunction : m_sScope);
429 break;
430 case USER_DEF_FUNCTION:
431 if ( sDataField.getLength() && PROPERTY_ID_FORMULALIST == nId )
432 aPropertyValue = aDataField;
433 break;
434 case COUNTER:
435 if ( PROPERTY_ID_SCOPE == nId && impl_isCounterFunction_throw(sDataField,m_sScope) )
436 aPropertyValue <<= m_sScope;
437 break;
441 break;
442 case PROPERTY_ID_BACKCOLOR:
443 case PROPERTY_ID_CONTROLBACKGROUND:
445 aPropertyValue = m_xReportComponent->getPropertyValue( PropertyName );
446 sal_Int32 nColor = COL_TRANSPARENT;
447 if ( (aPropertyValue >>= nColor) && static_cast<sal_Int32>(COL_TRANSPARENT) == nColor )
448 aPropertyValue.clear();
450 break;
451 case PROPERTY_ID_MIMETYPE:
453 ::rtl::OUString sValue;
454 m_xReportComponent->getPropertyValue( PropertyName ) >>= sValue;
455 aPropertyValue <<= impl_ConvertMimeTypeToUI_nothrow(sValue);
457 break;
458 default:
459 aPropertyValue = m_xReportComponent->getPropertyValue( PropertyName );
460 break;
462 return aPropertyValue;
465 void SAL_CALL GeometryHandler::setPropertyValue(const ::rtl::OUString & PropertyName, const uno::Any & Value) throw (uno::RuntimeException, beans::UnknownPropertyException)
467 ::osl::ResettableMutexGuard aGuard( m_aMutex );
468 uno::Any aNewValue = Value;
469 const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName);
470 bool bHandled = false;
471 switch(nId)
473 case PROPERTY_ID_INITIALFORMULA:
474 case PROPERTY_ID_FORMULA:
475 break;
476 case PROPERTY_ID_DATAFIELD:
478 OBlocker aBlocker(m_bIn);
479 m_xReportComponent->setPropertyValue(PropertyName, aNewValue);
480 bHandled = true;
481 const ::rtl::OUString sOldFunctionName = m_sDefaultFunction;
482 const ::rtl::OUString sOldScope = m_sScope;
484 uno::Any aPropertyValue;
485 lcl_convertFormulaTo(Value,aPropertyValue);
486 ::rtl::OUString sDataField;
487 aPropertyValue >>= sDataField;
489 m_sScope = m_sDefaultFunction = ::rtl::OUString();
490 m_xFunction.clear();
491 const sal_uInt32 nOldDataFieldType = m_nDataFieldType;
492 if ( sDataField.getLength() )
494 if ( isDefaultFunction(sDataField,sDataField,uno::Reference< report::XFunctionsSupplier>(),true) )
495 m_nDataFieldType = FUNCTION;
496 else if ( m_aFunctionNames.find(sDataField) != m_aFunctionNames.end() )
497 m_nDataFieldType = USER_DEF_FUNCTION;
500 resetOwnProperties(aGuard,sOldFunctionName,sOldScope,nOldDataFieldType);
502 break;
503 case PROPERTY_ID_TYPE:
505 bHandled = true;
506 Value >>= m_nDataFieldType;
508 const ::rtl::OUString sOldFunctionName = m_sDefaultFunction;
509 const ::rtl::OUString sOldScope = m_sScope;
510 m_sDefaultFunction = m_sScope = ::rtl::OUString();
512 if ( m_nDataFieldType == COUNTER )
514 impl_setCounterFunction_throw();
516 else
518 if ( m_bNewFunction )
519 removeFunction();
520 m_xFunction.clear();
521 OBlocker aBlocker(m_bIn);
522 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(::rtl::OUString()));
524 resetOwnProperties(aGuard,sOldFunctionName,sOldScope,m_nDataFieldType);
526 break;
527 case PROPERTY_ID_FORMULALIST:
529 bHandled = true;
530 ::rtl::OUString sFunction;
531 if ( !(Value >>= sFunction) || !sFunction.getLength() )
533 if ( m_nDataFieldType == FUNCTION )
535 m_sDefaultFunction = ::rtl::OUString();
536 if ( m_bNewFunction )
537 removeFunction();
538 m_xFunction.clear();
540 beans::PropertyChangeEvent aEvent;
541 aEvent.PropertyName = PROPERTY_SCOPE;
542 aEvent.OldValue <<= m_sScope;
543 m_sScope = ::rtl::OUString();
544 aEvent.NewValue <<= m_sScope;
545 aGuard.clear();
546 m_aPropertyListeners.notify( aEvent, &beans::XPropertyChangeListener::propertyChange );
548 else if ( m_nDataFieldType == USER_DEF_FUNCTION )
550 OBlocker aBlocker(m_bIn);
551 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(::rtl::OUString()));
554 else if ( m_nDataFieldType == USER_DEF_FUNCTION )
556 ::rtl::OUString sDataField;
557 OBlocker aBlocker(m_bIn);
558 const sal_uInt32 nNewDataType = impl_getDataFieldType_throw(sFunction);
559 if ( nNewDataType != UNDEF_DATA && nNewDataType != m_nDataFieldType )
561 const ::rtl::OUString sOldFunctionName = m_sDefaultFunction;
562 const ::rtl::OUString sOldScope = m_sScope;
563 m_sScope = m_sDefaultFunction = ::rtl::OUString();
564 m_xFunction.clear();
565 if ( nNewDataType == COUNTER )
566 impl_isCounterFunction_throw(sFunction,m_sScope);
567 else
569 ::rtl::OUString sNamePostFix;
570 const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostFix);
571 isDefaultFunction(sFunction,sDataField,xFunctionsSupplier,true);
573 const sal_uInt32 nOldDataFieldType = m_nDataFieldType;
574 m_nDataFieldType = nNewDataType;
575 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(impl_convertToFormula( uno::makeAny(sFunction))));
576 resetOwnProperties(aGuard,sOldFunctionName,sOldScope,nOldDataFieldType);
578 else
579 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(impl_convertToFormula( uno::makeAny(sFunction))));
581 else if ( m_nDataFieldType == FUNCTION )
583 uno::Any aPropertyValue = m_xReportComponent->getPropertyValue(PROPERTY_DATAFIELD);
584 lcl_convertFormulaTo(aPropertyValue,aPropertyValue);
585 ::rtl::OUString sDataField;
586 aPropertyValue >>= sDataField;
587 if ( m_nDataFieldType == FUNCTION && (!isDefaultFunction(sDataField,sDataField) || m_sDefaultFunction != sFunction) )
589 if ( m_bNewFunction )
590 removeFunction();
591 // function currently does not exist
592 createDefaultFunction(aGuard,sFunction,sDataField);
593 m_sDefaultFunction = sFunction;
598 break;
599 case PROPERTY_ID_SCOPE:
600 if ( !(Value >>= m_sScope) )
601 m_sScope = ::rtl::OUString();
602 else
604 if ( m_bNewFunction )
605 removeFunction();
606 if ( m_nDataFieldType == COUNTER )
607 impl_setCounterFunction_throw();
608 else
610 OSL_ENSURE(m_xFunction.is(),"Where is my function gone!");
612 ::rtl::OUString sNamePostFix;
613 const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostFix);
615 ::rtl::OUString sQuotedFunctionName(lcl_getQuotedFunctionName(m_xFunction));
616 if ( isDefaultFunction(sQuotedFunctionName,sQuotedFunctionName,xFunctionsSupplier,true) )
617 m_bNewFunction = false;
618 else
620 ::rtl::OUString sDefaultFunctionName;
621 ::rtl::OUString sDataField;
622 OSL_VERIFY( impl_isDefaultFunction_nothrow(m_xFunction,sDataField,sDefaultFunctionName) );
623 m_sDefaultFunction = sDefaultFunctionName;
624 createDefaultFunction(aGuard,m_sDefaultFunction,sDataField);
628 bHandled = true;
629 break;
630 case PROPERTY_ID_POSITIONX:
631 case PROPERTY_ID_POSITIONY:
632 case PROPERTY_ID_HEIGHT:
633 case PROPERTY_ID_WIDTH:
635 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY);
636 if ( xSourceReportComponent.is() ) // check only report components
638 sal_Int32 nNewValue = 0;
639 Value >>= nNewValue;
640 awt::Point aAwtPoint = xSourceReportComponent->getPosition();
641 awt::Size aAwtSize = xSourceReportComponent->getSize();
642 if ( nId == PROPERTY_ID_POSITIONX )
643 aAwtPoint.X = nNewValue;
644 else if ( nId == PROPERTY_ID_POSITIONY )
645 aAwtPoint.Y = nNewValue;
646 else if ( nId == PROPERTY_ID_HEIGHT )
647 aAwtSize.Height = nNewValue;
648 else if ( nId == PROPERTY_ID_WIDTH )
649 aAwtSize.Width = nNewValue;
651 checkPosAndSize(aAwtPoint,aAwtSize);
654 break;
655 case PROPERTY_ID_FONT:
657 const uno::Reference< report::XReportControlFormat > xReportControlFormat( m_xReportComponent,uno::UNO_QUERY_THROW );
658 uno::Sequence< beans::NamedValue > aFontSettings;
659 OSL_VERIFY( Value >>= aFontSettings );
660 applyCharacterSettings( xReportControlFormat, aFontSettings );
661 bHandled = true;
663 break;
664 case PROPERTY_ID_MIMETYPE:
666 ::rtl::OUString sValue;
667 Value >>= sValue;
668 aNewValue <<= impl_ConvertUIToMimeType_nothrow(sValue);
670 default:
671 break;
674 if ( !bHandled )
675 m_xReportComponent->setPropertyValue(PropertyName, aNewValue);
678 // -----------------------------------------------------------------------------
679 beans::PropertyState SAL_CALL GeometryHandler::getPropertyState(const ::rtl::OUString & PropertyName) throw (uno::RuntimeException, beans::UnknownPropertyException)
681 ::osl::MutexGuard aGuard( m_aMutex );
682 return m_xFormComponentHandler->getPropertyState(PropertyName);
684 // -----------------------------------------------------------------------------
685 void GeometryHandler::implCreateListLikeControl(
686 const uno::Reference< inspection::XPropertyControlFactory >& _rxControlFactory
687 ,inspection::LineDescriptor & out_Descriptor
688 ,sal_uInt16 _nResId
689 ,sal_Bool _bReadOnlyControl
690 ,sal_Bool _bTrueIfListBoxFalseIfComboBox
693 ::std::vector< ::rtl::OUString > aList;
694 tools::StringListResource aRes(ModuleRes(_nResId),aList);
696 implCreateListLikeControl(_rxControlFactory,out_Descriptor,aList,_bReadOnlyControl,_bTrueIfListBoxFalseIfComboBox);
698 // -----------------------------------------------------------------------------
699 void GeometryHandler::implCreateListLikeControl(
700 const uno::Reference< inspection::XPropertyControlFactory >& _rxControlFactory
701 ,inspection::LineDescriptor & out_Descriptor
702 ,const ::std::vector< ::rtl::OUString>& _aEntries
703 ,sal_Bool _bReadOnlyControl
704 ,sal_Bool _bTrueIfListBoxFalseIfComboBox
707 const uno::Reference< inspection::XStringListControl > xListControl(
708 _rxControlFactory->createPropertyControl(
709 _bTrueIfListBoxFalseIfComboBox ? inspection::PropertyControlType::ListBox : inspection::PropertyControlType::ComboBox, _bReadOnlyControl
711 uno::UNO_QUERY_THROW
714 out_Descriptor.Control = xListControl.get();
715 ::std::for_each( _aEntries.begin(), _aEntries.end(),::boost::bind( &inspection::XStringListControl::appendListEntry, xListControl,_1 ));
717 // -----------------------------------------------------------------------------
719 inspection::LineDescriptor SAL_CALL GeometryHandler::describePropertyLine(const ::rtl::OUString & PropertyName, const uno::Reference< inspection::XPropertyControlFactory > & _xControlFactory) throw (beans::UnknownPropertyException, lang::NullPointerException,uno::RuntimeException)
721 inspection::LineDescriptor aOut;
722 const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName);
723 switch(nId)
725 case PROPERTY_ID_FORCENEWPAGE:
726 case PROPERTY_ID_NEWROWORCOL:
727 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_FORCENEWPAGE_CONST,sal_False,sal_True);
728 break;
729 case PROPERTY_ID_GROUPKEEPTOGETHER:
730 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_GROUPKEEPTOGETHER_CONST,sal_False,sal_True);
731 break;
732 case PROPERTY_ID_PAGEHEADEROPTION:
733 case PROPERTY_ID_PAGEFOOTEROPTION:
734 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_REPORTPRINTOPTION_CONST,sal_False,sal_True);
735 break;
736 case PROPERTY_ID_FORMULALIST:
738 ::std::vector< ::rtl::OUString > aList;
739 impl_fillFormulaList_nothrow(aList);
740 implCreateListLikeControl(_xControlFactory,aOut,aList,sal_False,sal_True);
742 break;
743 case PROPERTY_ID_SCOPE:
745 ::std::vector< ::rtl::OUString > aList;
746 impl_fillScopeList_nothrow(aList);
747 implCreateListLikeControl(_xControlFactory,aOut,aList,sal_False,sal_True);
749 break;
750 case PROPERTY_ID_MIMETYPE:
752 ::std::vector< ::rtl::OUString > aList;
753 impl_fillMimeTypes_nothrow(aList);
754 implCreateListLikeControl(_xControlFactory,aOut,aList,sal_False,sal_True);
756 break;
757 case PROPERTY_ID_TYPE:
758 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_TYPE_CONST,sal_False,sal_True);
759 break;
760 case PROPERTY_ID_VISIBLE:
761 case PROPERTY_ID_CANGROW:
762 case PROPERTY_ID_CANSHRINK:
763 case PROPERTY_ID_REPEATSECTION:
764 case PROPERTY_ID_PRINTREPEATEDVALUES:
765 case PROPERTY_ID_STARTNEWCOLUMN:
766 case PROPERTY_ID_RESETPAGENUMBER:
767 case PROPERTY_ID_PRINTWHENGROUPCHANGE:
768 case PROPERTY_ID_KEEPTOGETHER:
769 case PROPERTY_ID_DEEPTRAVERSING:
770 case PROPERTY_ID_PREEVALUATED:
771 case PROPERTY_ID_PRESERVEIRI:
772 case PROPERTY_ID_BACKTRANSPARENT:
773 case PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT:
775 sal_uInt16 nResId = RID_STR_BOOL;
776 if ( PROPERTY_ID_KEEPTOGETHER == nId && uno::Reference< report::XGroup>(m_xReportComponent,uno::UNO_QUERY).is())
777 nResId = RID_STR_KEEPTOGETHER_CONST;
778 implCreateListLikeControl(_xControlFactory,aOut,nResId,sal_False,sal_True);
780 break;
781 case PROPERTY_ID_INITIALFORMULA:
782 case PROPERTY_ID_FORMULA:
783 aOut.PrimaryButtonId = UID_RPT_PROP_FORMULA;
784 aOut.HasPrimaryButton = sal_True;
785 aOut.Control = _xControlFactory->createPropertyControl(inspection::PropertyControlType::MultiLineTextField , sal_False);
786 break;
787 case PROPERTY_ID_CONDITIONALPRINTEXPRESSION:
788 aOut.PrimaryButtonId = UID_RPT_PROP_FORMULA;
789 aOut.HasPrimaryButton = sal_True;
790 aOut.Control = _xControlFactory->createPropertyControl(inspection::PropertyControlType::MultiLineTextField , sal_False);
791 break;
792 case PROPERTY_ID_DATAFIELD:
794 uno::Reference< inspection::XStringListControl > xListControl(
795 _xControlFactory->createPropertyControl(
796 m_nDataFieldType == DATA_OR_FORMULA ? inspection::PropertyControlType::ComboBox : inspection::PropertyControlType::ListBox, sal_False
798 uno::UNO_QUERY_THROW
801 if ( m_nDataFieldType == DATA_OR_FORMULA )
803 aOut.PrimaryButtonId = UID_RPT_PROP_FORMULA;
804 aOut.HasPrimaryButton = sal_True;
807 aOut.Control = xListControl.get();
808 if ( m_nDataFieldType == USER_DEF_FUNCTION )
810 // add function names
811 ::std::for_each( m_aFunctionNames.begin(), m_aFunctionNames.end(),
812 ::std::compose1(
813 ::boost::bind( &inspection::XStringListControl::appendListEntry, xListControl,_1 ),
814 ::std::select1st<TFunctions::value_type>()));
816 else
818 ::std::for_each( m_aFieldNames.getConstArray(), m_aFieldNames.getConstArray() + m_aFieldNames.getLength(),
819 ::boost::bind( &inspection::XStringListControl::appendListEntry, xListControl, _1 ) );
820 ::std::for_each( m_aParamNames.getConstArray(), m_aParamNames.getConstArray() + m_aParamNames.getLength(),
821 ::boost::bind( &inspection::XStringListControl::appendListEntry, xListControl, _1 ) );
824 break;
825 case PROPERTY_ID_BACKCOLOR:
826 case PROPERTY_ID_CONTROLBACKGROUND:
827 aOut.Control = _xControlFactory->createPropertyControl( inspection::PropertyControlType::ColorListBox, sal_False );
828 break;
829 case PROPERTY_ID_FONT:
830 aOut.PrimaryButtonId = UID_RPT_RPT_PROP_DLG_FONT_TYPE;
831 aOut.Control = _xControlFactory->createPropertyControl( inspection::PropertyControlType::TextField, sal_True );
832 aOut.HasPrimaryButton = sal_True;
833 break;
834 case PROPERTY_ID_AREA:
835 aOut.PrimaryButtonId = UID_RPT_RPT_PROP_DLG_AREA;
836 aOut.Control = _xControlFactory->createPropertyControl( inspection::PropertyControlType::TextField, sal_True );
837 aOut.HasPrimaryButton = sal_True;
838 break;
839 case PROPERTY_ID_VERTICALALIGN:
840 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_VERTICAL_ALIGN_CONST,sal_False,sal_True);
841 break;
842 case PROPERTY_ID_PARAADJUST:
843 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_PARAADJUST_CONST,sal_False,sal_True);
844 break;
845 default:
847 aOut = m_xFormComponentHandler->describePropertyLine(PropertyName, _xControlFactory);
851 if ( nId != -1 )
853 aOut.Category = ((m_pInfoService->getPropertyUIFlags(nId ) & PROP_FLAG_DATA_PROPERTY) != 0) ?
854 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Data"))
856 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("General"));
857 aOut.HelpURL = HelpIdUrl::getHelpURL( m_pInfoService->getPropertyHelpId( nId ) );
858 aOut.DisplayName = m_pInfoService->getPropertyTranslation(nId);
861 if ( ( nId == PROPERTY_ID_POSITIONX )
862 || ( nId == PROPERTY_ID_POSITIONY )
863 || ( nId == PROPERTY_ID_WIDTH )
864 || ( nId == PROPERTY_ID_HEIGHT )
867 const MeasurementSystem eSystem = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
868 const sal_Int16 nDisplayUnit = VCLUnoHelper::ConvertToMeasurementUnit( MEASURE_METRIC == eSystem ? FUNIT_CM : FUNIT_INCH, 1 );
869 uno::Reference< inspection::XNumericControl > xNumericControl(aOut.Control,uno::UNO_QUERY);
870 xNumericControl->setDecimalDigits( 2 );
871 xNumericControl->setValueUnit( util::MeasureUnit::MM_100TH );
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() )
878 uno::Reference< report::XReportDefinition > xReport = xComp->getSection()->getReportDefinition();
879 OSL_ENSURE(xReport.is(),"Why is the report definition NULL!");
880 if ( xReport.is() )
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)
887 case PROPERTY_ID_POSITIONX:
888 case PROPERTY_ID_POSITIONY:
889 case PROPERTY_ID_WIDTH:
890 xNumericControl->setMinValue(beans::Optional<double>(sal_True,0.0));
891 xNumericControl->setMaxValue(beans::Optional<double>(sal_True,double(aSize.Width - nLeftMargin - nRightMargin)));
892 if ( PROPERTY_ID_WIDTH == nId )
894 uno::Reference<report::XFixedLine> xFixedLine(m_xReportComponent,uno::UNO_QUERY);
895 if ( xFixedLine.is() && xFixedLine->getOrientation() == 1 ) // vertical
896 xNumericControl->setMinValue(beans::Optional<double>(sal_True,0.08 ));
898 break;
899 default:
900 break;
904 else if ( PROPERTY_ID_HEIGHT == nId )
906 const uno::Reference< report::XSection> xSection(m_xReportComponent,uno::UNO_QUERY);
907 if ( xSection.is() )
909 sal_Int32 nHeight = 0;
910 const sal_Int32 nCount = xSection->getCount();
911 for (sal_Int32 i = 0; i < nCount; ++i)
913 uno::Reference<drawing::XShape> xShape(xSection->getByIndex(i),uno::UNO_QUERY);
914 nHeight = ::std::max<sal_Int32>(nHeight,xShape->getPosition().Y + xShape->getSize().Height);
916 xNumericControl->setMinValue(beans::Optional<double>(sal_True,nHeight ));
920 return aOut;
922 // -----------------------------------------------------------------------------
923 beans::Property GeometryHandler::getProperty(const ::rtl::OUString & PropertyName)
925 uno::Sequence< beans::Property > aProps = getSupportedProperties();
926 const beans::Property* pIter = aProps.getConstArray();
927 const beans::Property* pEnd = pIter + aProps.getLength();
928 const beans::Property* pFind = ::std::find_if(pIter,pEnd,::std::bind2nd(PropertyCompare(),boost::cref(PropertyName)));
929 if ( pFind == pEnd )
930 return beans::Property();
931 return *pFind;
933 uno::Any GeometryHandler::getConstantValue(sal_Bool _bToControlValue,sal_uInt16 _nResId,const uno::Any& _aValue,const ::rtl::OUString& _sConstantName,const ::rtl::OUString & PropertyName )
935 ::std::vector< ::rtl::OUString > aList;
936 tools::StringListResource aRes(ModuleRes(_nResId),aList);
937 uno::Sequence< ::rtl::OUString > aSeq(aList.size());
938 ::std::copy( aList.begin(), aList.end(), aSeq.getArray() );
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 ::rtl::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 ::rtl::OUString & PropertyName, const uno::Any & _rControlValue) throw (uno::RuntimeException, beans::UnknownPropertyException)
956 ::osl::MutexGuard aGuard( m_aMutex );
957 uno::Any aPropertyValue( _rControlValue );
958 const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName);
959 switch(nId)
961 case PROPERTY_ID_FORCENEWPAGE:
962 case PROPERTY_ID_NEWROWORCOL:
963 aPropertyValue = getConstantValue(sal_False,RID_STR_FORCENEWPAGE_CONST,_rControlValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.ForceNewPage")),PropertyName);
964 break;
965 case PROPERTY_ID_GROUPKEEPTOGETHER:
966 aPropertyValue = getConstantValue(sal_False,RID_STR_GROUPKEEPTOGETHER_CONST,_rControlValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.GroupKeepTogether")),PropertyName);
967 break;
968 case PROPERTY_ID_PAGEHEADEROPTION:
969 case PROPERTY_ID_PAGEFOOTEROPTION:
970 aPropertyValue = getConstantValue(sal_False,RID_STR_REPORTPRINTOPTION_CONST,_rControlValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.ReportPrintOption")),PropertyName);
971 break;
972 case PROPERTY_ID_BACKCOLOR:
973 case PROPERTY_ID_CONTROLBACKGROUND:
974 if ( !_rControlValue.hasValue() )
976 aPropertyValue <<= static_cast<sal_Int32>(COL_TRANSPARENT);
977 break;
979 // run through
981 case PROPERTY_ID_KEEPTOGETHER:
982 if ( uno::Reference< report::XGroup>(m_xReportComponent,uno::UNO_QUERY).is())
984 aPropertyValue = getConstantValue(sal_False,RID_STR_KEEPTOGETHER_CONST,_rControlValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.KeepTogether")),PropertyName);
985 break;
987 // run through
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 ::rtl::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_ENSURE( sal_False, "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 ::rtl::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 ::rtl::OUString sValue;
1072 _rControlValue >>= sValue;
1073 ::std::vector< ::rtl::OUString > aList;
1074 tools::StringListResource aRes(ModuleRes(RID_STR_TYPE_CONST),aList);
1075 ::std::vector< ::rtl::OUString >::iterator aFind = ::std::find(aList.begin(),aList.end(),sValue);
1076 if ( aFind != aList.end() )
1077 aPropertyValue <<= static_cast<sal_uInt32>(aFind - aList.begin());
1079 break;
1080 case PROPERTY_ID_MIMETYPE:
1081 aPropertyValue = _rControlValue;
1082 break;
1083 case PROPERTY_ID_VERTICALALIGN:
1085 ::rtl::OUString sValue;
1086 _rControlValue >>= sValue;
1087 ::std::vector< ::rtl::OUString > aList;
1088 tools::StringListResource aRes(ModuleRes(RID_STR_VERTICAL_ALIGN_CONST),aList);
1089 ::std::vector< ::rtl::OUString >::iterator aFind = ::std::find(aList.begin(),aList.end(),sValue);
1090 if ( aFind != aList.end() )
1091 aPropertyValue <<= static_cast<style::VerticalAlignment>(aFind - aList.begin());
1093 break;
1094 case PROPERTY_ID_PARAADJUST:
1096 ::rtl::OUString sValue;
1097 _rControlValue >>= sValue;
1098 ::std::vector< ::rtl::OUString > aList;
1099 tools::StringListResource aRes(ModuleRes(RID_STR_PARAADJUST_CONST),aList);
1100 ::std::vector< ::rtl::OUString >::iterator aFind = ::std::find(aList.begin(),aList.end(),sValue);
1101 if ( aFind != aList.end() )
1102 aPropertyValue <<= static_cast<sal_Int16>(aFind - aList.begin());
1104 break;
1105 default:
1106 return m_xFormComponentHandler->convertToPropertyValue(PropertyName, _rControlValue);
1108 return aPropertyValue;
1111 uno::Any SAL_CALL GeometryHandler::convertToControlValue(const ::rtl::OUString & PropertyName, const uno::Any & _rPropertyValue, const uno::Type & _rControlValueType) throw (uno::RuntimeException, beans::UnknownPropertyException)
1113 uno::Any aControlValue( _rPropertyValue );
1114 if ( !aControlValue.hasValue() )
1115 // NULL is converted to NULL
1116 return aControlValue;
1118 uno::Any aPropertyValue(_rPropertyValue);
1120 ::osl::MutexGuard aGuard( m_aMutex );
1121 const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName);
1122 switch(nId)
1124 case PROPERTY_ID_AREA:
1125 break;
1126 case PROPERTY_ID_FORCENEWPAGE:
1127 case PROPERTY_ID_NEWROWORCOL:
1128 aControlValue = getConstantValue(sal_True,RID_STR_FORCENEWPAGE_CONST,aPropertyValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.ForceNewPage")),PropertyName);
1129 break;
1130 case PROPERTY_ID_GROUPKEEPTOGETHER:
1131 aControlValue = getConstantValue(sal_True,RID_STR_GROUPKEEPTOGETHER_CONST,aPropertyValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.GroupKeepTogether")),PropertyName);
1132 break;
1133 case PROPERTY_ID_PAGEHEADEROPTION:
1134 case PROPERTY_ID_PAGEFOOTEROPTION:
1135 aControlValue = getConstantValue(sal_True,RID_STR_REPORTPRINTOPTION_CONST,aPropertyValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.ReportPrintOption")),PropertyName);
1136 break;
1137 case PROPERTY_ID_KEEPTOGETHER:
1138 if ( uno::Reference< report::XGroup>(m_xReportComponent,uno::UNO_QUERY).is())
1140 aControlValue = getConstantValue(sal_True,RID_STR_KEEPTOGETHER_CONST,aPropertyValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.KeepTogether")),PropertyName);
1141 break;
1143 // run through
1144 case PROPERTY_ID_VISIBLE:
1145 case PROPERTY_ID_CANGROW:
1146 case PROPERTY_ID_CANSHRINK:
1147 case PROPERTY_ID_REPEATSECTION:
1148 case PROPERTY_ID_PRINTREPEATEDVALUES:
1149 case PROPERTY_ID_STARTNEWCOLUMN:
1150 case PROPERTY_ID_RESETPAGENUMBER:
1151 case PROPERTY_ID_PRINTWHENGROUPCHANGE:
1152 case PROPERTY_ID_DEEPTRAVERSING:
1153 case PROPERTY_ID_PREEVALUATED:
1154 case PROPERTY_ID_PRESERVEIRI:
1155 case PROPERTY_ID_BACKTRANSPARENT:
1156 case PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT:
1158 if ( _rControlValueType.getTypeClass() == uno::TypeClass_STRING )
1160 const uno::Reference< inspection::XStringRepresentation > xConversionHelper = inspection::StringRepresentation::create( m_xContext,m_xTypeConverter );
1161 aControlValue <<= xConversionHelper->convertToControlValue( aPropertyValue );
1163 else
1167 aControlValue = m_xTypeConverter->convertTo( aPropertyValue, _rControlValueType );
1169 catch( const uno::Exception& )
1171 OSL_ENSURE( sal_False, "GeometryHandler::convertToControlValue: caught an exception while converting via TypeConverter!" );
1174 break;
1176 case PROPERTY_ID_CONDITIONALPRINTEXPRESSION:
1177 case PROPERTY_ID_INITIALFORMULA:
1178 case PROPERTY_ID_FORMULA:
1179 lcl_convertFormulaTo(aPropertyValue,aControlValue);
1180 break;
1181 case PROPERTY_ID_DATAFIELD:
1183 ::rtl::OUString sValue;
1184 aControlValue >>= sValue;
1185 if ( isDefaultFunction(sValue,sValue) )
1186 aControlValue <<= sValue;
1187 else
1188 lcl_convertFormulaTo(aPropertyValue,aControlValue);
1190 break;
1191 case PROPERTY_ID_FONT:
1192 aControlValue = m_xFormComponentHandler->convertToControlValue(PROPERTY_FONT, aPropertyValue, _rControlValueType);
1193 break;
1194 case PROPERTY_ID_POSITIONX:
1196 sal_Int32 nPosX = 0;
1197 aPropertyValue >>= nPosX;
1198 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY);
1199 if ( xSourceReportComponent->getSection().is() )
1200 nPosX -= getStyleProperty<sal_Int32>(xSourceReportComponent->getSection()->getReportDefinition(),PROPERTY_LEFTMARGIN);
1201 aPropertyValue <<= nPosX;
1202 aControlValue = m_xFormComponentHandler->convertToControlValue(PropertyName, aPropertyValue, _rControlValueType);
1204 break;
1205 case PROPERTY_ID_FORMULALIST:
1206 aControlValue <<= m_sDefaultFunction;
1207 break;
1208 case PROPERTY_ID_SCOPE:
1209 aControlValue <<= m_sScope;
1210 break;
1211 case PROPERTY_ID_MIMETYPE:
1212 aControlValue = aPropertyValue;
1213 break;
1214 case PROPERTY_ID_TYPE:
1216 ::std::vector< ::rtl::OUString > aList;
1217 tools::StringListResource aRes(ModuleRes(RID_STR_TYPE_CONST),aList);
1218 if ( m_nDataFieldType < aList.size() )
1219 aControlValue <<= aList[m_nDataFieldType];
1221 break;
1222 case PROPERTY_ID_VERTICALALIGN:
1224 style::VerticalAlignment nParagraphVertAlign = style::VerticalAlignment_TOP;
1225 aPropertyValue >>= nParagraphVertAlign;
1226 ::std::vector< ::rtl::OUString > aList;
1227 tools::StringListResource aRes(ModuleRes(RID_STR_VERTICAL_ALIGN_CONST),aList);
1228 if ( static_cast<sal_Int16>(nParagraphVertAlign) < static_cast<sal_Int16>(aList.size()) )
1229 aControlValue <<= aList[nParagraphVertAlign];
1231 break;
1232 case PROPERTY_ID_PARAADJUST:
1234 sal_Int16 nParagraphAdjust = style::ParagraphAdjust_LEFT;
1235 aPropertyValue >>= nParagraphAdjust;
1236 ::std::vector< ::rtl::OUString > aList;
1237 tools::StringListResource aRes(ModuleRes(RID_STR_PARAADJUST_CONST),aList);
1238 if ( nParagraphAdjust < static_cast<sal_Int16>(aList.size()) )
1239 aControlValue <<= aList[nParagraphAdjust];
1241 break;
1242 case PROPERTY_ID_BACKCOLOR:
1243 case PROPERTY_ID_CONTROLBACKGROUND:
1245 sal_Int32 nColor = COL_TRANSPARENT;
1246 if ( (aPropertyValue >>= nColor) && static_cast<sal_Int32>(COL_TRANSPARENT) == nColor )
1247 aPropertyValue.clear();
1249 // run through
1250 default:
1251 aControlValue = m_xFormComponentHandler->convertToControlValue(PropertyName, aPropertyValue, _rControlValueType);
1253 return aControlValue;
1255 void SAL_CALL GeometryHandler::addPropertyChangeListener(const uno::Reference< beans::XPropertyChangeListener > & _rxListener) throw (uno::RuntimeException, lang::NullPointerException)
1257 ::osl::MutexGuard aGuard( m_aMutex );
1258 m_aPropertyListeners.addListener( _rxListener );
1259 m_xFormComponentHandler->addPropertyChangeListener(_rxListener);
1262 void SAL_CALL GeometryHandler::removePropertyChangeListener(const uno::Reference< beans::XPropertyChangeListener > & _rxListener) throw (uno::RuntimeException)
1264 ::osl::MutexGuard aGuard( m_aMutex );
1265 m_aPropertyListeners.removeListener( _rxListener );
1266 m_xFormComponentHandler->removePropertyChangeListener(_rxListener);
1268 // -----------------------------------------------------------------------------
1269 //--------------------------------------------------------------------------
1270 uno::Sequence< beans::Property > SAL_CALL GeometryHandler::getSupportedProperties() throw (uno::RuntimeException)
1272 ::std::vector< beans::Property > aNewProps;
1273 aNewProps.reserve(20); // only a guess
1274 m_pInfoService->getExcludeProperties( aNewProps, m_xFormComponentHandler );
1276 const ::rtl::OUString pIncludeProperties[] =
1278 PROPERTY_FORCENEWPAGE
1279 ,PROPERTY_KEEPTOGETHER
1280 ,PROPERTY_CANGROW
1281 ,PROPERTY_CANSHRINK
1282 ,PROPERTY_REPEATSECTION
1283 ,PROPERTY_PRINTREPEATEDVALUES
1284 ,PROPERTY_CONDITIONALPRINTEXPRESSION
1285 ,PROPERTY_STARTNEWCOLUMN
1286 ,PROPERTY_RESETPAGENUMBER
1287 ,PROPERTY_PRINTWHENGROUPCHANGE
1288 ,PROPERTY_VISIBLE
1289 ,PROPERTY_PAGEHEADEROPTION
1290 ,PROPERTY_PAGEFOOTEROPTION
1291 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlLabel"))
1292 ,PROPERTY_POSITIONX
1293 ,PROPERTY_POSITIONY
1294 ,PROPERTY_WIDTH
1295 ,PROPERTY_HEIGHT
1296 ,PROPERTY_PREEVALUATED
1297 ,PROPERTY_DEEPTRAVERSING
1298 ,PROPERTY_FORMULA
1299 ,PROPERTY_INITIALFORMULA
1300 ,PROPERTY_PRESERVEIRI
1301 ,PROPERTY_DATAFIELD
1302 ,PROPERTY_FONT
1303 ,PROPERTY_BACKCOLOR
1304 ,PROPERTY_BACKTRANSPARENT
1305 ,PROPERTY_CONTROLBACKGROUND
1306 ,PROPERTY_CONTROLBACKGROUNDTRANSPARENT
1307 ,PROPERTY_LABEL
1308 ,PROPERTY_MIMETYPE
1309 ,PROPERTY_VERTICALALIGN
1310 ,PROPERTY_PARAADJUST
1312 const uno::Reference < beans::XPropertySetInfo > xInfo = m_xReportComponent->getPropertySetInfo();
1313 const uno::Sequence< beans::Property> aSeq = xInfo->getProperties();
1314 for (size_t i = 0; i < sizeof(pIncludeProperties)/sizeof(pIncludeProperties[0]) ;++i )
1316 const beans::Property* pIter = aSeq.getConstArray();
1317 const beans::Property* pEnd = pIter + aSeq.getLength();
1318 const beans::Property* pFind = ::std::find_if(pIter,pEnd,::std::bind2nd(PropertyCompare(),boost::cref(pIncludeProperties[i])));
1319 if ( pFind != pEnd )
1321 // special case for controls which contain a data field
1322 if ( PROPERTY_DATAFIELD == pIncludeProperties[i] )
1324 beans::Property aValue;
1325 aValue.Name = PROPERTY_FORMULALIST;
1326 aNewProps.push_back(aValue);
1327 aValue.Name = PROPERTY_SCOPE;
1328 aNewProps.push_back(aValue);
1329 aValue.Name = PROPERTY_TYPE;
1330 aNewProps.push_back(aValue);
1332 aNewProps.push_back(*pFind);
1334 } // for (size_t i = 0; i < sizeof(pIncludeProperties)/sizeof(pIncludeProperties[0]) ;++i )
1336 // special property for shapes
1337 // if ( uno::Reference< report::XShape>(m_xReportComponent,uno::UNO_QUERY).is() )
1338 // {
1339 // beans::Property aValue;
1340 // aValue.Name = PROPERTY_AREA;
1341 // aNewProps.push_back(aValue);
1342 // }
1343 // re-enable when the remaining issues of #i88727# are fixed
1345 return uno::Sequence< beans::Property > (&(*aNewProps.begin()),aNewProps.size());
1348 uno::Sequence< ::rtl::OUString > SAL_CALL GeometryHandler::getSupersededProperties() throw (uno::RuntimeException)
1350 uno::Sequence< ::rtl::OUString > aRet;
1351 const uno::Reference<report::XReportDefinition> xReport(m_xReportComponent,uno::UNO_QUERY);
1352 if ( xReport.is() && !uno::Reference< report::XSection>(xReport->getParent(),uno::UNO_QUERY).is() )
1354 aRet.realloc(5);
1355 ::rtl::OUString* pIter = aRet.getArray();
1356 *pIter++ = PROPERTY_POSITIONX;
1357 *pIter++ = PROPERTY_POSITIONY;
1358 *pIter++ = PROPERTY_WIDTH;
1359 *pIter++ = PROPERTY_HEIGHT;
1360 *pIter++ = PROPERTY_DATAFIELD;
1362 return aRet;
1365 uno::Sequence< ::rtl::OUString > SAL_CALL GeometryHandler::getActuatingProperties() throw (uno::RuntimeException)
1367 ::osl::MutexGuard aGuard( m_aMutex );
1369 uno::Sequence< ::rtl::OUString > aSeq(5);
1370 aSeq[0] = PROPERTY_BACKTRANSPARENT;
1371 aSeq[1] = PROPERTY_CONTROLBACKGROUNDTRANSPARENT;
1372 aSeq[2] = PROPERTY_FORMULALIST;
1373 aSeq[3] = PROPERTY_TYPE;
1374 aSeq[4] = PROPERTY_DATAFIELD;
1376 return ::comphelper::concatSequences(m_xFormComponentHandler->getActuatingProperties(),aSeq);
1379 ::sal_Bool SAL_CALL GeometryHandler::isComposable(const ::rtl::OUString & _rPropertyName) throw (uno::RuntimeException, beans::UnknownPropertyException)
1381 return m_pInfoService->isComposable( _rPropertyName, m_xFormComponentHandler );
1384 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 if ( !_rxInspectorUI.is() )
1387 throw lang::NullPointerException();
1388 if ( PropertyName.equalsAscii(PROPERTY_FILTER) )
1390 ::osl::ClearableMutexGuard aGuard( m_aMutex );
1392 inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
1393 ::rtl::OUString sClause;
1394 if ( impl_dialogFilter_nothrow( sClause, aGuard ) )
1396 _rData <<= sClause;
1397 eResult = inspection::InteractiveSelectionResult_ObtainedValue;
1399 return eResult;
1401 else if ( PropertyName.equalsAscii(PROPERTY_FONT) )
1403 ::osl::ClearableMutexGuard aGuard( m_aMutex );
1405 inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
1406 const uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DialogParentWindow"))) ,uno::UNO_QUERY);
1407 const uno::Reference< report::XReportControlFormat> xReportControlFormat(m_xReportComponent,uno::UNO_QUERY);
1408 aGuard.clear();
1410 uno::Sequence< beans::NamedValue > aFontSettings;
1411 if ( rptui::openCharDialog( xReportControlFormat, xInspectorWindow, aFontSettings ) )
1413 _rData <<= aFontSettings;
1414 eResult = inspection::InteractiveSelectionResult_ObtainedValue;
1416 return eResult;
1418 else if ( PropertyName.equalsAscii(PROPERTY_FORMULA)
1419 || PropertyName.equalsAscii(PROPERTY_INITIALFORMULA)
1420 || PropertyName.equalsAscii(PROPERTY_DATAFIELD)
1421 || PropertyName.equalsAscii(PROPERTY_CONDITIONALPRINTEXPRESSION))
1423 ::osl::ClearableMutexGuard aGuard( m_aMutex );
1426 ::rtl::OUString sFormula;
1427 m_xReportComponent->getPropertyValue(PropertyName) >>= sFormula;
1428 const uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DialogParentWindow"))) ,uno::UNO_QUERY);
1429 uno::Reference< uno::XComponentContext > xContext = m_xContext;
1430 uno::Reference< beans::XPropertySet > xRowSet( m_xRowSet,uno::UNO_QUERY);
1431 aGuard.clear();
1433 inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
1434 if ( rptui::openDialogFormula_nothrow( sFormula, xContext,xInspectorWindow,xRowSet ) )
1436 _rData <<= sFormula;
1437 eResult = inspection::InteractiveSelectionResult_ObtainedValue;
1439 return eResult;
1441 else if ( PropertyName.equalsAscii(PROPERTY_AREA) )
1443 ::osl::ClearableMutexGuard aGuard( m_aMutex );
1445 inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
1446 const uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DialogParentWindow"))) ,uno::UNO_QUERY);
1447 const uno::Reference< report::XShape> xShape(m_xReportComponent,uno::UNO_QUERY);
1448 aGuard.clear();
1450 if ( rptui::openAreaDialog( xShape, xInspectorWindow) )
1452 eResult = inspection::InteractiveSelectionResult_ObtainedValue;
1453 beans::PropertyChangeEvent aScopeEvent;
1454 aScopeEvent.PropertyName = PROPERTY_FILLCOLOR;
1455 // aScopeEvent.OldValue <<= _nOldDataFieldType;
1456 aScopeEvent.NewValue <<= xShape->getPropertyValue(PROPERTY_FILLCOLOR);
1457 m_aPropertyListeners.notify( aScopeEvent, &beans::XPropertyChangeListener::propertyChange );
1459 return eResult;
1463 return m_xFormComponentHandler->onInteractivePropertySelection(PropertyName, Primary, _rData, _rxInspectorUI);
1466 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 if ( !_rxInspectorUI.is() )
1469 throw lang::NullPointerException();
1471 ::osl::MutexGuard aGuard( m_aMutex );
1472 const sal_Int32 nId = m_pInfoService->getPropertyId(ActuatingPropertyName);
1473 switch(nId)
1475 case PROPERTY_ID_TYPE:
1477 sal_uInt32 nNewVal = 0;
1478 NewValue >>= nNewVal;
1479 switch(nNewVal)
1481 case DATA_OR_FORMULA:
1482 _rxInspectorUI->rebuildPropertyUI(PROPERTY_DATAFIELD);
1483 _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,sal_True);
1484 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,sal_False);
1485 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,sal_False);
1486 OSL_ENSURE(m_sDefaultFunction.getLength() == 0,"Why is the m_sDefaultFunction set?");
1487 OSL_ENSURE(m_sScope.getLength() == 0,"Why is the m_sScope set?");
1488 break;
1489 case FUNCTION:
1490 _rxInspectorUI->rebuildPropertyUI(PROPERTY_DATAFIELD);
1491 _rxInspectorUI->rebuildPropertyUI(PROPERTY_FORMULALIST);
1492 _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,sal_True);
1493 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,m_sDefaultFunction.getLength() != 0);
1494 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,m_sScope.getLength() != 0);
1495 break;
1496 case USER_DEF_FUNCTION:
1497 _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,sal_False);
1498 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,sal_True);
1499 _rxInspectorUI->rebuildPropertyUI(PROPERTY_FORMULALIST);
1500 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,sal_False);
1501 break;
1502 case COUNTER:
1503 _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,sal_False);
1504 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,sal_False);
1505 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,sal_True);
1506 break;
1509 break;
1510 case PROPERTY_ID_DATAFIELD:
1512 sal_Bool bEnable = (m_nDataFieldType != DATA_OR_FORMULA && m_nDataFieldType != COUNTER );
1513 if ( bEnable )
1515 ::rtl::OUString sValue;
1516 m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD ) >>= sValue;
1517 bEnable = sValue.getLength() != 0;
1519 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,bEnable);
1520 if ( bEnable )
1522 _rxInspectorUI->rebuildPropertyUI(PROPERTY_DATAFIELD);
1523 _rxInspectorUI->rebuildPropertyUI(PROPERTY_FORMULALIST);
1524 } // if ( bEnable )
1525 m_xFormComponentHandler->actuatingPropertyChanged(ActuatingPropertyName, NewValue, OldValue, _rxInspectorUI, _bFirstTimeInit);
1527 break;
1528 case PROPERTY_ID_FORMULALIST:
1530 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,m_nDataFieldType == FUNCTION || m_nDataFieldType == COUNTER);
1532 break;
1533 case PROPERTY_ID_BACKTRANSPARENT:
1534 case PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT:
1536 sal_Bool bValue = sal_False;
1537 NewValue >>= bValue;
1538 bValue = !bValue;
1539 _rxInspectorUI->enablePropertyUI(PROPERTY_BACKCOLOR,bValue);
1540 _rxInspectorUI->enablePropertyUI(PROPERTY_CONTROLBACKGROUND,bValue);
1542 break;
1543 default:
1544 m_xFormComponentHandler->actuatingPropertyChanged(ActuatingPropertyName, NewValue, OldValue, _rxInspectorUI, _bFirstTimeInit);
1545 break;
1549 ::sal_Bool SAL_CALL GeometryHandler::suspend(::sal_Bool Suspend) throw (uno::RuntimeException)
1551 return m_xFormComponentHandler->suspend(Suspend);
1553 // -----------------------------------------------------------------------------
1554 bool GeometryHandler::impl_dialogFilter_nothrow( ::rtl::OUString& _out_rSelectedClause, ::osl::ClearableMutexGuard& _rClearBeforeDialog ) const
1556 _out_rSelectedClause = ::rtl::OUString();
1557 bool bSuccess = false;
1558 ::dbtools::SQLExceptionInfo aErrorInfo;
1559 uno::Reference< awt::XWindow > xInspectorWindow;
1560 uno::Reference< lang::XMultiComponentFactory > xFactory;
1561 uno::Reference<lang::XMultiServiceFactory> xServiceFactory;
1564 xFactory = m_xContext->getServiceManager();
1565 xServiceFactory.set(xFactory,uno::UNO_QUERY);
1566 xInspectorWindow.set(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DialogParentWindow"))) ,uno::UNO_QUERY);
1567 uno::Reference<sdbc::XConnection> xCon(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ActiveConnection"))) ,uno::UNO_QUERY);
1568 if ( !xCon.is() )
1569 return false;
1571 uno::Reference< beans::XPropertySet> xRowSetProp(m_xRowSet,uno::UNO_QUERY);
1572 if ( !m_xRowSet.is() )
1574 m_xRowSet.set(xFactory->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.RowSet")),m_xContext),uno::UNO_QUERY);
1575 xRowSetProp.set(m_xRowSet,uno::UNO_QUERY);
1576 xRowSetProp->setPropertyValue(PROPERTY_ACTIVECONNECTION,uno::makeAny(xCon));
1577 ::comphelper::copyProperties(m_xReportComponent,xRowSetProp);
1580 // get a composer for the statement which the form is currently based on
1581 uno::Reference< sdb::XSingleSelectQueryComposer > xComposer( ::dbtools::getCurrentSettingsComposer( xRowSetProp, xServiceFactory ) );
1582 OSL_ENSURE( xComposer.is(), "GeometryHandler::impl_dialogFilter_nothrow: could not obtain a composer!" );
1583 if ( !xComposer.is() )
1584 return false;
1586 // create the dialog
1587 uno::Reference< ui::dialogs::XExecutableDialog > xDialog(xFactory->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.FilterDialog")),m_xContext),uno::UNO_QUERY);
1588 if ( !xDialog.is() )
1590 Window* pInspectorWindow = VCLUnoHelper::GetWindow( xInspectorWindow );
1591 ShowServiceNotAvailableError( pInspectorWindow, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.FilterDialog")), sal_True );
1592 return false;
1595 const String aGcc3WorkaroundTemporary( ModuleRes(RID_STR_FILTER));
1596 const ::rtl::OUString sPropertyUIName( aGcc3WorkaroundTemporary );
1597 // initialize the dialog
1598 uno::Reference< beans::XPropertySet > xDialogProps( xDialog, uno::UNO_QUERY_THROW );
1599 xDialogProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "QueryComposer" ) ), uno::makeAny( xComposer ) );
1600 xDialogProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RowSet" ) ), uno::makeAny( m_xRowSet ) );
1601 xDialogProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" ) ), uno::makeAny( xInspectorWindow ) );
1602 xDialogProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ), uno::makeAny( sPropertyUIName ) );
1604 _rClearBeforeDialog.clear();
1605 bSuccess = ( xDialog->execute() != 0 );
1606 if ( bSuccess )
1607 _out_rSelectedClause = xComposer->getFilter();
1609 catch (sdb::SQLContext& e) { aErrorInfo = e; }
1610 catch (sdbc::SQLWarning& e) { aErrorInfo = e; }
1611 catch (sdbc::SQLException& e) { aErrorInfo = e; }
1612 catch( const uno::Exception& )
1614 OSL_ENSURE( sal_False, "GeometryHandler::impl_dialogFilter_nothrow: caught an exception!" );
1617 if ( aErrorInfo.isValid() )
1618 ::dbtools::showError( aErrorInfo, xInspectorWindow, xServiceFactory );
1620 return bSuccess;
1622 // -----------------------------------------------------------------------------
1623 void GeometryHandler::checkPosAndSize( const awt::Point& _aNewPos,
1624 const awt::Size& _aSize)
1626 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY);
1627 const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY);
1628 if ( !xSection.is() || uno::Reference< report::XShape>(xSourceReportComponent,uno::UNO_QUERY).is() ) // shapes can overlap.
1629 return;
1631 ::Point aPos(VCLPoint(_aNewPos));
1632 if ( aPos.X() < 0 || aPos.Y() < 0 ) // TODO: have to check size with pos aka || (aPos.X() + aAwtSize.Width) > m_xSection->getReportDefinition()->
1633 throw beans::PropertyVetoException(String(ModuleRes(RID_STR_ILLEGAL_POSITION)),xSourceReportComponent);
1635 ::Rectangle aSourceRect(aPos,VCLSize(_aSize));
1637 const sal_Int32 nCount = xSection->getCount();
1638 for (sal_Int32 i = 0; i < nCount ; ++i)
1640 const uno::Reference< report::XReportComponent> xReportComponent(xSection->getByIndex(i),uno::UNO_QUERY);
1641 if ( xReportComponent.is() && xReportComponent != xSourceReportComponent )
1643 const ::Rectangle aBoundRect(VCLPoint(xReportComponent->getPosition()),VCLSize(xReportComponent->getSize()));
1644 const ::Rectangle aRect = aSourceRect.GetIntersection(aBoundRect);
1645 if ( !aRect.IsEmpty() && (aRect.Left() != aRect.Right() && aRect.Top() != aRect.Bottom() ) )
1646 throw beans::PropertyVetoException(String(ModuleRes( RID_STR_OVERLAP_OTHER_CONTROL)),xSourceReportComponent);
1650 // -----------------------------------------------------------------------------
1651 void GeometryHandler::impl_fillFormulaList_nothrow(::std::vector< ::rtl::OUString >& _out_rList) const
1653 if ( m_nDataFieldType == FUNCTION )
1654 ::std::transform(m_aDefaultFunctions.begin(),m_aDefaultFunctions.end(),::std::back_inserter(_out_rList),::boost::bind( &DefaultFunction::getName, _1 ));
1655 else if ( m_nDataFieldType == USER_DEF_FUNCTION )
1656 ::std::transform(m_aFunctionNames.begin(),m_aFunctionNames.end(),::std::back_inserter(_out_rList),::std::select1st<TFunctions::value_type>());
1658 // -----------------------------------------------------------------------------
1659 ::rtl::OUString GeometryHandler::impl_ConvertUIToMimeType_nothrow(const ::rtl::OUString& _sUIName) const
1661 ::std::vector< ::rtl::OUString > aList;
1662 impl_fillMimeTypes_nothrow(aList);
1663 ::rtl::OUString sRet;
1664 ::std::vector< ::rtl::OUString >::const_iterator aFind = ::std::find(aList.begin(),aList.end(),_sUIName);
1665 if ( aFind != aList.end() )
1667 const sal_Size nPos = aFind - aList.begin();
1668 const uno::Reference< report::XReportDefinition> xReportDefinition(m_xReportComponent,uno::UNO_QUERY);
1669 if ( xReportDefinition.is() )
1671 const uno::Sequence< ::rtl::OUString > aMimeTypes( xReportDefinition->getAvailableMimeTypes() );
1672 sRet = aMimeTypes[nPos];
1674 } // if ( aFind != aList.end() )
1675 return sRet;
1677 // -----------------------------------------------------------------------------
1678 ::rtl::OUString GeometryHandler::impl_ConvertMimeTypeToUI_nothrow(const ::rtl::OUString& _sMimetype) const
1680 uno::Reference<lang::XMultiServiceFactory> xServiceFactory(m_xContext->getServiceManager(),uno::UNO_QUERY_THROW);
1681 ::comphelper::MimeConfigurationHelper aMimeHelper(xServiceFactory);
1682 ::rtl::OUString sRet;
1683 const SfxFilter* pFilter = SfxFilter::GetDefaultFilter( aMimeHelper.GetDocServiceNameFromMediaType(_sMimetype) );
1684 if ( pFilter )
1685 sRet = pFilter->GetUIName();
1686 if ( !sRet.getLength() )
1687 sRet = _sMimetype;
1688 return sRet;
1690 // -----------------------------------------------------------------------------
1691 void GeometryHandler::impl_fillMimeTypes_nothrow(::std::vector< ::rtl::OUString >& _out_rList) const
1695 const uno::Reference< report::XReportDefinition> xReportDefinition(m_xReportComponent,uno::UNO_QUERY);
1696 if ( xReportDefinition.is() )
1698 uno::Sequence< ::rtl::OUString > aMimeTypes( xReportDefinition->getAvailableMimeTypes() );
1699 const ::rtl::OUString* pIter = aMimeTypes.getConstArray();
1700 const ::rtl::OUString* pEnd = pIter + aMimeTypes.getLength();
1701 for(;pIter != pEnd; ++pIter)
1703 const ::rtl::OUString sDocName( impl_ConvertMimeTypeToUI_nothrow(*pIter) );
1704 if ( sDocName.getLength() )
1705 _out_rList.push_back(sDocName);
1709 catch(uno::Exception&)
1711 OSL_ENSURE(0,"Exception caught!");
1714 // -----------------------------------------------------------------------------
1715 void GeometryHandler::impl_fillScopeList_nothrow(::std::vector< ::rtl::OUString >& _out_rList) const
1719 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY_THROW);
1720 const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY_THROW);
1722 const uno::Reference< report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
1723 const uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups();
1724 sal_Int32 nPos = -1;
1725 uno::Reference< report::XGroup> xGroup = xSection->getGroup();
1726 if ( xGroup.is() )
1727 nPos = getPositionInIndexAccess(xGroups.get(),xGroup);
1728 else if ( xSection == xReportDefinition->getDetail() )
1729 nPos = xGroups->getCount()-1;
1731 const String sGroup = String(ModuleRes(RID_STR_SCOPE_GROUP));
1732 for (sal_Int32 i = 0 ; i <= nPos ; ++i)
1734 xGroup.set(xGroups->getByIndex(i),uno::UNO_QUERY_THROW);
1735 String sGroupName = sGroup;
1736 sGroupName.SearchAndReplaceAscii("%1",xGroup->getExpression());
1737 _out_rList.push_back(sGroupName);
1739 _out_rList.push_back(xReportDefinition->getName());
1741 catch(uno::Exception&)
1743 OSL_ENSURE(0,"Exception caught!");
1746 // -----------------------------------------------------------------------------
1747 uno::Reference< report::XFunctionsSupplier> GeometryHandler::fillScope_throw(::rtl::OUString& _rsNamePostFix)
1749 uno::Reference< report::XFunctionsSupplier> xReturn;
1751 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY_THROW);
1752 const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY_THROW);
1753 const uno::Reference< report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
1754 if ( !m_sScope.getLength() )
1756 const uno::Reference< report::XGroup> xGroup(xSection->getGroup(),uno::UNO_QUERY);
1757 if ( xGroup.is() )
1759 String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP));
1760 _rsNamePostFix = xGroup->getExpression();
1761 sGroupName.SearchAndReplaceAscii("%1",_rsNamePostFix);
1762 m_sScope = sGroupName;
1763 xReturn = xGroup.get();
1765 else if ( xSection == xReportDefinition->getDetail() )
1767 const uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups();
1768 const sal_Int32 nCount = xGroups->getCount();
1769 if ( nCount )
1771 const uno::Reference< report::XGroup> xGroup2(xGroups->getByIndex(nCount - 1),uno::UNO_QUERY_THROW);
1772 String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP));
1773 _rsNamePostFix = xGroup2->getExpression();
1774 sGroupName.SearchAndReplaceAscii("%1",_rsNamePostFix);
1775 m_sScope = sGroupName;
1776 xReturn = xGroup2.get();
1779 if ( !m_sScope.getLength() )
1781 xReturn = xReportDefinition.get();
1782 _rsNamePostFix = m_sScope = xReportDefinition->getName();
1785 else if ( m_sScope == xReportDefinition->getName() )
1787 xReturn = xReportDefinition.get();
1788 _rsNamePostFix = m_sScope;
1790 else
1792 uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups();
1793 const sal_Int32 nCount = xGroups->getCount();
1795 for (sal_Int32 i = 0 ; i < nCount; ++i)
1797 const uno::Reference< report::XGroup> xGroup(xGroups->getByIndex(i),uno::UNO_QUERY_THROW);
1798 String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP));
1799 sGroupName.SearchAndReplaceAscii("%1",xGroup->getExpression());
1800 if ( m_sScope == ::rtl::OUString(sGroupName) )
1802 _rsNamePostFix = xGroup->getExpression();
1803 xReturn = xGroup.get();
1804 break;
1809 OSL_ENSURE(xReturn.is(),"Why don't we have a functionssupplier here!");
1811 return xReturn;
1813 // -----------------------------------------------------------------------------
1814 sal_Bool GeometryHandler::isDefaultFunction( const ::rtl::OUString& _sQuotedFunction
1815 ,::rtl::OUString& _rDataField
1816 ,const uno::Reference< report::XFunctionsSupplier>& _xFunctionsSupplier
1817 ,bool _bSet) const
1819 sal_Bool bDefaultFunction = sal_False;
1822 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY_THROW);
1823 const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY_THROW);
1824 const uno::Reference< report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
1826 ::std::pair<TFunctions::const_iterator,TFunctions::const_iterator> aFind = m_aFunctionNames.equal_range(_sQuotedFunction);
1827 while ( aFind.first != aFind.second )
1829 if ( !_xFunctionsSupplier.is() || _xFunctionsSupplier == aFind.first->second.second )
1831 const beans::Optional< ::rtl::OUString> aInitalFormula = aFind.first->second.first->getInitialFormula();
1832 if ( aInitalFormula.IsPresent )
1834 ::rtl::OUString sDefaultFunctionName;
1835 bDefaultFunction = impl_isDefaultFunction_nothrow(aFind.first->second.first,_rDataField,sDefaultFunctionName);
1836 if ( bDefaultFunction )
1838 m_xFunction = aFind.first->second.first;
1839 if ( _bSet )
1841 m_sDefaultFunction = sDefaultFunctionName;
1842 uno::Reference< report::XGroup> xGroup(aFind.first->second.second,uno::UNO_QUERY);
1843 if ( xGroup.is() )
1845 String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP));
1846 sGroupName.SearchAndReplaceAscii("%1",xGroup->getExpression());
1847 m_sScope = sGroupName;
1849 else
1850 m_sScope = xReportDefinition->getName();
1853 break;
1856 ++(aFind.first);
1859 catch(uno::Exception&)
1861 OSL_ENSURE(0,"Exception caught!");
1863 return bDefaultFunction;
1865 // -----------------------------------------------------------------------------
1866 sal_Bool GeometryHandler::impl_isDefaultFunction_nothrow( const uno::Reference< report::XFunction>& _xFunction
1867 ,::rtl::OUString& _rDataField
1868 ,::rtl::OUString& _rsDefaultFunctionName) const
1870 sal_Bool bDefaultFunction = sal_False;
1873 const String sFormula( _xFunction->getFormula() );
1874 util::SearchOptions aSearchOptions;
1875 aSearchOptions.algorithmType = util::SearchAlgorithms_REGEXP;
1876 aSearchOptions.searchFlag = 0x00000100;
1877 ::std::vector< DefaultFunction >::const_iterator aIter = m_aDefaultFunctions.begin();
1878 ::std::vector< DefaultFunction >::const_iterator aDeEnd = m_aDefaultFunctions.end();
1879 for (; aIter != aDeEnd; ++aIter)
1881 aSearchOptions.searchString = aIter->m_sSearchString;
1882 utl::TextSearch aTextSearch(aSearchOptions);
1883 xub_StrLen start = 0;
1884 xub_StrLen end = sFormula.Len();
1885 if ( aTextSearch.SearchFrwrd(sFormula,&start,&end) && start == 0 && end == sFormula.Len()) // default function found
1887 aSearchOptions.searchString = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]"));
1888 utl::TextSearch aDataSearch(aSearchOptions);
1889 aDataSearch.SearchFrwrd(sFormula,&start,&end );
1890 ++start;
1891 _rDataField = sFormula.Copy(start,end-start-1);
1892 _rsDefaultFunctionName = aIter->m_sName;
1893 break;
1897 bDefaultFunction = aIter != aDeEnd;
1899 catch(uno::Exception&)
1901 OSL_ENSURE(0,"Exception caught!");
1903 return bDefaultFunction;
1905 // -----------------------------------------------------------------------------
1906 void GeometryHandler::loadDefaultFunctions()
1908 if ( m_aDefaultFunctions.empty() )
1910 m_aCounterFunction.m_bPreEvaluated = sal_False;
1911 m_aCounterFunction.m_bDeepTraversing = sal_False;
1912 m_aCounterFunction.m_sName = String(ModuleRes(RID_STR_F_COUNTER));
1913 m_aCounterFunction.m_sFormula = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:[%FunctionName] + 1"));
1914 m_aCounterFunction.m_sSearchString = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:\\[[:alpha:]+([:space:]*[:alnum:]*)*\\][:space:]*\\+[:space:]*[:digit:]*"));
1915 m_aCounterFunction.m_sInitialFormula.IsPresent = sal_True;
1916 m_aCounterFunction.m_sInitialFormula.Value = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:1"));
1918 DefaultFunction aDefault;
1919 aDefault.m_bDeepTraversing = sal_False;
1921 //aDefault.m_sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Counter"));
1922 //aDefault.m_sFormula = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:[%FunctionName] + 1"));
1923 //aDefault.m_sSearchString = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:\\[[:alpha:]+[:alnum:]*\\][:space:]*\\+[:space:]*1"));
1924 //aDefault.m_sInitialFormula.IsPresent = sal_True;
1925 //aDefault.m_sInitialFormula.Value = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:1"));
1926 //m_aDefaultFunctions.push_back(aDefault);
1928 aDefault.m_bPreEvaluated = sal_True;
1930 aDefault.m_sName = String(ModuleRes(RID_STR_F_ACCUMULATION));
1931 aDefault.m_sFormula = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:[%Column] + [%FunctionName]"));
1932 aDefault.m_sSearchString = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:\\[[:alpha:]+([:space:]*[:alnum:]*)*\\][:space:]*\\+[:space:]*\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]"));
1933 aDefault.m_sInitialFormula.IsPresent = sal_True;
1934 aDefault.m_sInitialFormula.Value = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:[%Column]"));
1935 m_aDefaultFunctions.push_back(aDefault);
1937 aDefault.m_sName = String(ModuleRes(RID_STR_F_MINIMUM));
1938 aDefault.m_sFormula = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:IF([%Column] < [%FunctionName];[%Column];[%FunctionName])"));
1939 aDefault.m_sSearchString = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:IF\\((\\[[:alpha:]+([:space:]*[:alnum:]*)*\\])[:space:]*<[:space:]*(\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]);[:space:]*\\1[:space:]*;[:space:]*\\3[:space:]*\\)"));
1940 aDefault.m_sInitialFormula.IsPresent = sal_True;
1941 aDefault.m_sInitialFormula.Value = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:[%Column]"));
1942 m_aDefaultFunctions.push_back(aDefault);
1944 aDefault.m_sName = String(ModuleRes(RID_STR_F_MAXIMUM));
1945 aDefault.m_sFormula = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:IF([%Column] > [%FunctionName];[%Column];[%FunctionName])"));
1946 aDefault.m_sSearchString = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:IF\\((\\[[:alpha:]+([:space:]*[:alnum:]*)*\\])[:space:]*>[:space:]*(\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]);[:space:]*\\1[:space:]*;[:space:]*\\3[:space:]*\\)"));
1947 aDefault.m_sInitialFormula.IsPresent = sal_True;
1948 aDefault.m_sInitialFormula.Value = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:[%Column]"));
1949 m_aDefaultFunctions.push_back(aDefault);
1952 // -----------------------------------------------------------------------------
1953 void GeometryHandler::createDefaultFunction(::osl::ResettableMutexGuard& _aGuard ,const ::rtl::OUString& _sFunction,const ::rtl::OUString& _sDataField)
1957 ::rtl::OUString sNamePostFix;
1958 const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostFix);
1960 ::std::vector< DefaultFunction >::const_iterator aIter = m_aDefaultFunctions.begin();
1961 ::std::vector< DefaultFunction >::const_iterator aDeEnd = m_aDefaultFunctions.end();
1962 for (; aIter != aDeEnd; ++aIter)
1964 if ( aIter->m_sName == _sFunction )
1966 const ::rtl::OUString sFunctionName( _sFunction + _sDataField + sNamePostFix);
1967 const ::rtl::OUString sQuotedFunctionName(lcl_getQuotedFunctionName(sFunctionName));
1969 beans::PropertyChangeEvent aEvent;
1970 aEvent.PropertyName = PROPERTY_SCOPE;
1971 aEvent.OldValue <<= m_sScope;
1973 ::std::pair<TFunctions::const_iterator,TFunctions::const_iterator> aFind = m_aFunctionNames.equal_range(sQuotedFunctionName);
1974 while ( aFind.first != aFind.second )
1976 if ( xFunctionsSupplier == aFind.first->second.second )
1978 m_xFunction = aFind.first->second.first;
1979 ::rtl::OUString sTemp;
1980 isDefaultFunction(sQuotedFunctionName,sTemp,uno::Reference< report::XFunctionsSupplier>(),true); // implicitly sets the m_sScope
1981 break;
1983 ++(aFind.first);
1985 if ( aFind.first == aFind.second )
1986 impl_createFunction(sFunctionName,_sDataField,*aIter);
1988 OBlocker aBlocker(m_bIn);
1989 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny( impl_convertToFormula( uno::makeAny(sQuotedFunctionName) )));
1990 aEvent.NewValue <<= m_sScope;
1991 _aGuard.clear();
1992 m_aPropertyListeners.notify( aEvent, &beans::XPropertyChangeListener::propertyChange );
1993 break;
1997 catch(uno::Exception&)
1999 OSL_ENSURE(0,"Exception caught!");
2002 // -----------------------------------------------------------------------------
2003 void GeometryHandler::removeFunction()
2005 if ( m_xFunction.is() )
2007 const ::rtl::OUString sQuotedFunctionName(lcl_getQuotedFunctionName(m_xFunction));
2008 ::std::pair<TFunctions::iterator,TFunctions::iterator> aFind = m_aFunctionNames.equal_range(sQuotedFunctionName);
2009 while ( aFind.first != aFind.second )
2011 if ( aFind.first->second.first == m_xFunction )
2013 uno::Reference< report::XFunctions> xFunctions = aFind.first->second.second->getFunctions();
2014 xFunctions->removeByIndex(xFunctions->getCount() - 1 ); /// TODO: insert new method in XFunctions: removeFunction(xfunction)
2015 m_aFunctionNames.erase(aFind.first);
2016 m_bNewFunction = false;
2017 break;
2019 ++(aFind.first);
2023 // -----------------------------------------------------------------------------
2024 void GeometryHandler::resetOwnProperties(::osl::ResettableMutexGuard& _aGuard,const ::rtl::OUString& _sOldFunctionName,const ::rtl::OUString& _sOldScope,const sal_uInt32 _nOldDataFieldType)
2026 const ::rtl::OUString sNewFunction = m_sDefaultFunction;
2027 const ::rtl::OUString sNewScope = m_sScope;
2028 const sal_uInt32 nNewDataFieldType = m_nDataFieldType;
2029 _aGuard.clear();
2030 if ( _nOldDataFieldType != nNewDataFieldType )
2032 beans::PropertyChangeEvent aScopeEvent;
2033 aScopeEvent.PropertyName = PROPERTY_TYPE;
2034 aScopeEvent.OldValue <<= _nOldDataFieldType;
2035 aScopeEvent.NewValue <<= nNewDataFieldType;
2036 m_aPropertyListeners.notify( aScopeEvent, &beans::XPropertyChangeListener::propertyChange );
2038 if ( _sOldFunctionName != sNewFunction )
2040 beans::PropertyChangeEvent aFormulaEvent;
2041 aFormulaEvent.PropertyName = PROPERTY_FORMULALIST;
2042 aFormulaEvent.OldValue <<= _sOldFunctionName;
2043 aFormulaEvent.NewValue <<= sNewFunction;
2045 m_aPropertyListeners.notify( aFormulaEvent, &beans::XPropertyChangeListener::propertyChange );
2047 if ( _sOldScope != sNewScope )
2049 beans::PropertyChangeEvent aScopeEvent;
2050 aScopeEvent.PropertyName = PROPERTY_SCOPE;
2051 aScopeEvent.OldValue <<= _sOldScope;
2052 aScopeEvent.NewValue <<= sNewScope;
2053 m_aPropertyListeners.notify( aScopeEvent, &beans::XPropertyChangeListener::propertyChange );
2056 _aGuard.reset();
2058 //------------------------------------------------------------------------
2059 void GeometryHandler::impl_initFieldList_nothrow( uno::Sequence< ::rtl::OUString >& _rFieldNames ) const
2061 _rFieldNames.realloc(0);
2064 uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DialogParentWindow"))) ,uno::UNO_QUERY);
2065 Window* pInspectorWindow = VCLUnoHelper::GetWindow( xInspectorWindow );
2066 WaitObject aWaitCursor( pInspectorWindow );
2068 uno::Reference< sdbc::XPreparedStatement > xStatement;
2070 // get the form of the control we're inspecting
2071 uno::Reference< beans::XPropertySet > xFormSet( m_xRowSet, uno::UNO_QUERY );
2072 if ( !xFormSet.is() )
2073 return;
2075 ::rtl::OUString sObjectName;
2076 OSL_VERIFY( xFormSet->getPropertyValue( PROPERTY_COMMAND ) >>= sObjectName );
2077 // when there is no command we don't need to ask for columns
2078 uno::Reference<sdbc::XConnection> xCon(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ActiveConnection"))) ,uno::UNO_QUERY);
2079 if ( sObjectName.getLength() && xCon.is() )
2081 sal_Int32 nObjectType = sdb::CommandType::COMMAND;
2082 OSL_VERIFY( xFormSet->getPropertyValue( PROPERTY_COMMANDTYPE ) >>= nObjectType );
2084 _rFieldNames = ::dbtools::getFieldNamesByCommandDescriptor( xCon, nObjectType, sObjectName );
2087 catch (uno::Exception&)
2089 DBG_ERROR( "GeometryHandler::impl_initFieldList_nothrow: caught an exception!" );
2092 // -----------------------------------------------------------------------------
2093 bool GeometryHandler::impl_isCounterFunction_throw(const ::rtl::OUString& _sQuotedFunctionName,::rtl::OUString& _Out_sScope) const
2095 ::std::pair<TFunctions::const_iterator,TFunctions::const_iterator> aFind = m_aFunctionNames.equal_range(_sQuotedFunctionName);
2096 while ( aFind.first != aFind.second )
2098 const beans::Optional< ::rtl::OUString> aInitalFormula = aFind.first->second.first->getInitialFormula();
2099 if ( aInitalFormula.IsPresent )
2101 const String sFormula( aFind.first->second.first->getFormula() );
2102 util::SearchOptions aSearchOptions;
2103 aSearchOptions.algorithmType = util::SearchAlgorithms_REGEXP;
2104 aSearchOptions.searchFlag = 0x00000100;
2105 aSearchOptions.searchString = m_aCounterFunction.m_sSearchString;
2106 utl::TextSearch aTextSearch(aSearchOptions);
2107 xub_StrLen start = 0;
2108 xub_StrLen end = sFormula.Len();
2109 if ( aTextSearch.SearchFrwrd(sFormula,&start,&end) && start == 0 && end == sFormula.Len()) // counter function found
2111 const uno::Reference< report::XGroup > xGroup(aFind.first->second.second,uno::UNO_QUERY);
2112 if ( xGroup.is() )
2114 String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP));
2115 sGroupName.SearchAndReplaceAscii("%1",xGroup->getExpression());
2116 _Out_sScope = sGroupName;
2118 else
2119 _Out_sScope = uno::Reference< report::XReportDefinition >(aFind.first->second.second,uno::UNO_QUERY_THROW)->getName();
2120 break;
2123 ++(aFind.first);
2125 return aFind.first != aFind.second;
2127 // -----------------------------------------------------------------------------
2128 void GeometryHandler::impl_createFunction(const ::rtl::OUString& _sFunctionName,const ::rtl::OUString& _sDataField,const DefaultFunction& _aFunction)
2130 if ( m_bNewFunction )
2131 removeFunction();
2133 const ::rtl::OUString sQuotedFunctionName(lcl_getQuotedFunctionName(_sFunctionName));
2134 m_xFunction.set(report::Function::create(m_xContext));
2135 m_xFunction->setName( _sFunctionName );
2137 const String sPlaceHolder1(RTL_CONSTASCII_USTRINGPARAM("%Column"));
2138 const String sPlaceHolder2(RTL_CONSTASCII_USTRINGPARAM("%FunctionName"));
2139 String sFormula(_aFunction.m_sFormula);
2140 sFormula.SearchAndReplaceAll(sPlaceHolder1,_sDataField);
2141 sFormula.SearchAndReplaceAll(sPlaceHolder2,_sFunctionName);
2143 m_xFunction->setFormula(sFormula);
2144 m_xFunction->setPreEvaluated(_aFunction.m_bPreEvaluated);
2145 m_xFunction->setDeepTraversing(_aFunction.m_bDeepTraversing);
2146 if ( _aFunction.m_sInitialFormula.IsPresent )
2148 beans::Optional< ::rtl::OUString> aInitialFormula = _aFunction.m_sInitialFormula;
2149 String sInitialFormula = aInitialFormula.Value;
2150 sInitialFormula.SearchAndReplaceAll(sPlaceHolder1,_sDataField);
2151 sInitialFormula.SearchAndReplaceAll(sPlaceHolder2,_sFunctionName);
2152 aInitialFormula.Value = sInitialFormula;
2153 m_xFunction->setInitialFormula( aInitialFormula );
2155 ::rtl::OUString sNamePostFix;
2156 const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostFix);
2157 const uno::Reference< container::XIndexContainer> xFunctions(xFunctionsSupplier->getFunctions(),uno::UNO_QUERY_THROW);
2158 xFunctions->insertByIndex(xFunctions->getCount(),uno::makeAny(m_xFunction));
2159 m_aFunctionNames.insert(TFunctions::value_type(sQuotedFunctionName,TFunctionPair(m_xFunction,xFunctionsSupplier)));
2160 m_bNewFunction = true;
2162 // -----------------------------------------------------------------------------
2163 void GeometryHandler::impl_setCounterFunction_throw()
2165 ::rtl::OUString sNamePostFix;
2166 fillScope_throw(sNamePostFix);
2167 ::rtl::OUString sFunctionName = m_aCounterFunction.m_sName;
2168 sFunctionName += sNamePostFix;
2169 const ::rtl::OUString sQuotedFunctionName = lcl_getQuotedFunctionName(sFunctionName);
2170 ::rtl::OUString sScope;
2171 if ( !(sFunctionName.getLength() && m_aFunctionNames.find(sQuotedFunctionName) != m_aFunctionNames.end() && impl_isCounterFunction_throw(sQuotedFunctionName,sScope)) )
2172 impl_createFunction(sFunctionName,::rtl::OUString(),m_aCounterFunction);
2174 OBlocker aBlocker(m_bIn);
2175 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(impl_convertToFormula( uno::makeAny(sQuotedFunctionName))));
2177 // -----------------------------------------------------------------------------
2178 sal_uInt32 GeometryHandler::impl_getDataFieldType_throw(const ::rtl::OUString& _sDataField) const
2180 sal_uInt32 nDataFieldType = UNDEF_DATA;
2181 ::rtl::OUString sDataField;
2182 if ( _sDataField.getLength() )
2183 sDataField = _sDataField;
2184 else
2186 uno::Any aDataField( m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD ) );
2187 lcl_convertFormulaTo(aDataField,aDataField);
2188 aDataField >>= sDataField;
2191 if ( sDataField.getLength() )
2193 if ( impl_isDataField(sDataField) )
2194 nDataFieldType = DATA_OR_FORMULA;
2195 else if ( isDefaultFunction(sDataField,sDataField) )
2196 nDataFieldType = FUNCTION;
2197 else if ( m_aFunctionNames.find(sDataField) != m_aFunctionNames.end() )
2199 nDataFieldType = USER_DEF_FUNCTION;
2200 ::rtl::OUString sScope;
2201 if ( impl_isCounterFunction_throw(sDataField,sScope) )
2202 nDataFieldType = COUNTER;
2204 else
2205 nDataFieldType = DATA_OR_FORMULA;
2207 return nDataFieldType;
2209 // -----------------------------------------------------------------------------
2210 // XEventListener
2211 void SAL_CALL GeometryHandler::disposing(const lang::EventObject& ) throw( uno::RuntimeException )
2214 // XPropertyChangeListener
2215 void SAL_CALL GeometryHandler::propertyChange(const beans::PropertyChangeEvent& /*evt*/) throw(uno::RuntimeException)
2217 ::osl::ResettableMutexGuard aGuard( m_aMutex );
2218 if ( !m_bIn )
2220 const sal_uInt32 nOldDataFieldType = m_nDataFieldType;
2221 const ::rtl::OUString sOldFunctionName = m_sDefaultFunction;
2222 const ::rtl::OUString sOldScope = m_sScope;
2223 m_sDefaultFunction = m_sScope = ::rtl::OUString();
2224 m_nDataFieldType = impl_getDataFieldType_throw();
2225 if ( UNDEF_DATA == m_nDataFieldType )
2226 m_nDataFieldType = nOldDataFieldType;
2227 uno::Any aDataField = m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD );
2228 lcl_convertFormulaTo(aDataField,aDataField);
2229 ::rtl::OUString sDataField;
2230 aDataField >>= sDataField;
2231 switch(m_nDataFieldType)
2233 case FUNCTION:
2234 isDefaultFunction(sDataField,sDataField,uno::Reference< report::XFunctionsSupplier>(),true);
2235 break;
2236 case COUNTER:
2237 impl_isCounterFunction_throw(sDataField,m_sScope);
2238 break;
2239 default:
2243 resetOwnProperties(aGuard,sOldFunctionName,sOldScope,nOldDataFieldType);
2246 //........................................................................
2247 } // namespace rptui
2248 //........................................................................