sync master with lastest vba changes
[ooovba.git] / reportdesign / source / ui / inspection / GeometryHandler.cxx
blobe297785005f1d8b2dfb45dde2765f06b941692b5
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/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/util/MeasureUnit.hpp>
69 #include <vcl/msgbox.hxx>
70 #include <vcl/waitobj.hxx>
71 #include <vcl/fldunit.hxx>
72 #include <vcl/stdtext.hxx>
74 #include "ModuleHelper.hxx"
75 #include "RptResId.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 <boost/bind.hpp>
84 #include <tools/string.hxx>
85 #include "metadata.hxx"
86 #include <svtools/itempool.hxx>
87 #include <svtools/itemset.hxx>
89 #define ITEMID_COLOR_TABLE SID_COLOR_TABLE
90 #define ITEMID_DASH_LIST SID_DASH_LIST
91 #define ITEMID_LINEEND_LIST SID_LINEEND_LIST
92 #include <svx/xdef.hxx>
93 #include <svx/xpool.hxx>
94 #include <svx/xtable.hxx>
95 #include <svx/xlnwtit.hxx>
96 #include <svx/xlntrit.hxx>
97 #include <svx/xlnclit.hxx>
98 #include <svx/xlnstit.hxx>
99 #include <svx/xlnedit.hxx>
100 #include <svx/xlnstwit.hxx>
101 #include <svx/xlnedwit.hxx>
102 #include <svx/xlnstcit.hxx>
103 #include <svx/xlnedcit.hxx>
104 #include <svx/xlndsit.hxx>
105 #include <svx/xlineit0.hxx>
106 #include <svx/svxids.hrc>
108 #define ITEMID_COLOR_TABLE SID_COLOR_TABLE
109 #define ITEMID_DASH_LIST SID_DASH_LIST
110 #define ITEMID_LINEEND_LIST SID_LINEEND_LIST
111 #include <svx/drawitem.hxx>
112 #define ITEMID_BRUSH SID_ATTR_BRUSH
113 #include <svx/brshitem.hxx>
114 #include <sfx2/docfilt.hxx>
116 #include "dlgpage.hxx"
117 #include "helpids.hrc"
118 #include <toolkit/helper/convert.hxx>
120 #define DATA_OR_FORMULA 0
121 #define FUNCTION 1
122 #define COUNTER 2
123 #define USER_DEF_FUNCTION 3
124 #define UNDEF_DATA 4
126 //........................................................................
127 namespace rptui
129 //........................................................................
130 using namespace ::com::sun::star;
131 //using namespace formula;
133 // comparing two property instances
134 struct PropertyCompare : public ::std::binary_function< beans::Property, ::rtl::OUString , bool >
136 bool operator() (const beans::Property& x, const ::rtl::OUString& y) const
138 return x.Name.equals(y);// ? true : false;
140 bool operator() (const ::rtl::OUString& x,const beans::Property& y) const
142 return x.equals(y.Name);// ? true : false;
145 // -----------------------------------------------------------------------------
146 ::rtl::OUString lcl_getQuotedFunctionName(const ::rtl::OUString& _sFunction)
148 ::rtl::OUString sQuotedFunctionName(RTL_CONSTASCII_USTRINGPARAM("["));
149 sQuotedFunctionName += _sFunction + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("]"));
150 return sQuotedFunctionName;
152 // -----------------------------------------------------------------------------
153 ::rtl::OUString lcl_getQuotedFunctionName(const uno::Reference< report::XFunction>& _xFunction)
155 return lcl_getQuotedFunctionName(_xFunction->getName());
157 // -----------------------------------------------------------------------------
158 void lcl_collectFunctionNames(const uno::Reference< report::XFunctions>& _xFunctions,TFunctions& _rFunctionNames)
160 uno::Reference< report::XFunctionsSupplier> xParent(_xFunctions->getParent(),uno::UNO_QUERY_THROW);
161 const sal_Int32 nCount = _xFunctions->getCount();
162 for (sal_Int32 i = 0; i < nCount ; ++i)
164 uno::Reference< report::XFunction > xFunction(_xFunctions->getByIndex(i),uno::UNO_QUERY_THROW);
165 _rFunctionNames.insert(TFunctions::value_type(lcl_getQuotedFunctionName(xFunction),TFunctionPair(xFunction,xParent)));
168 // -----------------------------------------------------------------------------
169 void lcl_collectFunctionNames(const uno::Reference< report::XSection>& _xSection,TFunctions& _rFunctionNames)
171 const uno::Reference< report::XReportDefinition> xReportDefinition = _xSection->getReportDefinition();
172 const uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups();
173 sal_Int32 nPos = -1;
174 uno::Reference< report::XGroup> xGroup = _xSection->getGroup();
175 if ( xGroup.is() )
176 nPos = getPositionInIndexAccess(xGroups.get(),xGroup);
177 else if ( _xSection == xReportDefinition->getDetail() )
178 nPos = xGroups->getCount()-1;
180 for (sal_Int32 i = 0 ; i <= nPos ; ++i)
182 xGroup.set(xGroups->getByIndex(i),uno::UNO_QUERY_THROW);
183 lcl_collectFunctionNames(xGroup->getFunctions(),_rFunctionNames);
185 lcl_collectFunctionNames(xReportDefinition->getFunctions(),_rFunctionNames);
187 // -----------------------------------------------------------------------------
188 void lcl_convertFormulaTo(const uno::Any& _aPropertyValue,uno::Any& _rControlValue)
190 ::rtl::OUString sName;
191 _aPropertyValue >>= sName;
192 const sal_Int32 nLen = sName.getLength();
193 if ( nLen )
195 ReportFormula aFormula( sName );
196 _rControlValue <<= aFormula.getUndecoratedContent();
199 // -----------------------------------------------------------------------------
200 bool GeometryHandler::impl_isDataField(const ::rtl::OUString& _sName) const
202 const ::rtl::OUString* pEnd = m_aFieldNames.getConstArray() + m_aFieldNames.getLength();
203 bool bIsField = ( ::std::find( m_aFieldNames.getConstArray(), pEnd, _sName ) != pEnd );
205 if ( !bIsField )
207 pEnd = m_aParamNames.getConstArray() + m_aParamNames.getLength();
208 bIsField = ( ::std::find( m_aParamNames.getConstArray(), pEnd, _sName ) != pEnd );
210 return bIsField;
212 // -----------------------------------------------------------------------------
213 ::rtl::OUString GeometryHandler::impl_convertToFormula( const uno::Any& _rControlValue )
215 ::rtl::OUString sName;
216 _rControlValue >>= sName;
218 if ( !sName.getLength() )
219 return sName;
221 ReportFormula aParser( sName );
222 if ( aParser.isValid() )
223 return sName;
225 aParser = ReportFormula( impl_isDataField(sName) ? ReportFormula::Field : ReportFormula::Expression, sName );
226 return aParser.getCompleteFormula();
228 DBG_NAME(rpt_GeometryHandler)
229 GeometryHandler::GeometryHandler(uno::Reference< uno::XComponentContext > const & context) :
230 GeometryHandler_Base(m_aMutex)
231 ,m_aPropertyListeners( m_aMutex )
232 ,m_xContext(context)
233 ,m_pInfoService(new OPropertyInfoService())
234 ,m_nDataFieldType(0)
235 ,m_bIn(false)
237 DBG_CTOR(rpt_GeometryHandler,NULL);
240 const uno::Reference< lang::XMultiComponentFactory > xFac = m_xContext->getServiceManager();
241 m_xFormComponentHandler.set(xFac->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.inspection.FormComponentPropertyHandler")),m_xContext),uno::UNO_QUERY_THROW);
242 m_xTypeConverter.set(xFac->createInstanceWithContext( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter" )),m_xContext),uno::UNO_QUERY_THROW);
243 loadDefaultFunctions();
245 catch(const uno::Exception&)
249 // -----------------------------------------------------------------------------
250 GeometryHandler::~GeometryHandler()
252 DBG_DTOR(rpt_GeometryHandler,NULL);
254 //------------------------------------------------------------------------
255 ::rtl::OUString SAL_CALL GeometryHandler::getImplementationName( ) throw(uno::RuntimeException)
257 return getImplementationName_Static();
260 //------------------------------------------------------------------------
261 sal_Bool SAL_CALL GeometryHandler::supportsService( const ::rtl::OUString& ServiceName ) throw(uno::RuntimeException)
263 return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_static());
266 //------------------------------------------------------------------------
267 uno::Sequence< ::rtl::OUString > SAL_CALL GeometryHandler::getSupportedServiceNames( ) throw(uno::RuntimeException)
269 return getSupportedServiceNames_static();
272 //------------------------------------------------------------------------
273 ::rtl::OUString GeometryHandler::getImplementationName_Static( ) throw(uno::RuntimeException)
275 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.GeometryHandler"));
278 //------------------------------------------------------------------------
279 uno::Sequence< ::rtl::OUString > GeometryHandler::getSupportedServiceNames_static( ) throw(uno::RuntimeException)
281 uno::Sequence< ::rtl::OUString > aSupported(1);
282 aSupported[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.inspection.GeometryHandler"));
283 return aSupported;
286 //------------------------------------------------------------------------
287 uno::Reference< uno::XInterface > SAL_CALL GeometryHandler::create( const uno::Reference< uno::XComponentContext >& _rxContext )
289 return *(new GeometryHandler( _rxContext ));
291 // overload WeakComponentImplHelperBase::disposing()
292 // This function is called upon disposing the component,
293 // if your component needs special work when it becomes
294 // disposed, do it here.
295 void SAL_CALL GeometryHandler::disposing()
299 ::comphelper::disposeComponent(m_xFormComponentHandler);
300 ::comphelper::disposeComponent(m_xTypeConverter);
301 if ( m_xReportComponent.is() && m_xReportComponent->getPropertySetInfo()->hasPropertyByName(PROPERTY_DATAFIELD) )
302 m_xReportComponent->removePropertyChangeListener(PROPERTY_DATAFIELD,static_cast< beans::XPropertyChangeListener* >( this ));
304 m_xReportComponent.clear();
305 m_xRowSet.clear();
306 m_aPropertyListeners.clear();
308 catch(uno::Exception&)
311 void SAL_CALL GeometryHandler::addEventListener(const uno::Reference< lang::XEventListener > & xListener) throw (uno::RuntimeException)
313 m_xFormComponentHandler->addEventListener(xListener);
316 void SAL_CALL GeometryHandler::removeEventListener(const uno::Reference< lang::XEventListener > & aListener) throw (uno::RuntimeException)
318 m_xFormComponentHandler->removeEventListener(aListener);
321 // inspection::XPropertyHandler:
323 /********************************************************************************/
324 void SAL_CALL GeometryHandler::inspect( const uno::Reference< uno::XInterface > & _rxInspectee ) throw (uno::RuntimeException, lang::NullPointerException)
326 ::osl::MutexGuard aGuard( m_aMutex );
327 m_sScope = m_sDefaultFunction = ::rtl::OUString();
328 m_bNewFunction = false;
329 m_nDataFieldType = 0;
330 m_xFunction.clear();
331 m_aFunctionNames.clear();
334 if ( m_xReportComponent.is() && m_xReportComponent->getPropertySetInfo()->hasPropertyByName(PROPERTY_DATAFIELD) )
335 m_xReportComponent->removePropertyChangeListener(PROPERTY_DATAFIELD,static_cast< beans::XPropertyChangeListener* >( this ));
337 const uno::Reference< container::XNameContainer > xObjectAsContainer( _rxInspectee, uno::UNO_QUERY );
338 m_xReportComponent.set( xObjectAsContainer->getByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ReportComponent" ) ) ), uno::UNO_QUERY );
340 const ::rtl::OUString sRowSet(RTL_CONSTASCII_USTRINGPARAM("RowSet"));
341 if ( xObjectAsContainer->hasByName( sRowSet ) )
343 const uno::Any aRowSet( xObjectAsContainer->getByName(sRowSet) );
344 aRowSet >>= m_xRowSet;
345 // forward the rowset to our delegator handler
346 uno::Reference< beans::XPropertySet > xProp( m_xFormComponentHandler,uno::UNO_QUERY );
347 xProp->setPropertyValue( sRowSet, aRowSet );
349 m_aParamNames = getParameterNames( m_xRowSet );
350 impl_initFieldList_nothrow(m_aFieldNames);
351 if ( m_xReportComponent->getPropertySetInfo()->hasPropertyByName(PROPERTY_DATAFIELD) )
352 m_xReportComponent->addPropertyChangeListener(PROPERTY_DATAFIELD,static_cast< beans::XPropertyChangeListener* >( this ));
355 const uno::Reference< report::XReportComponent> xReportComponent( m_xReportComponent, uno::UNO_QUERY);
356 uno::Reference< report::XSection> xSection( m_xReportComponent, uno::UNO_QUERY );
357 if ( !xSection.is() && xReportComponent.is() )
358 xSection = xReportComponent->getSection();
359 if ( xSection.is() )
360 lcl_collectFunctionNames( xSection, m_aFunctionNames );
362 catch(uno::Exception)
364 throw lang::NullPointerException();
366 m_xFormComponentHandler->inspect(m_xReportComponent);
369 uno::Any SAL_CALL GeometryHandler::getPropertyValue(const ::rtl::OUString & PropertyName) throw (uno::RuntimeException, beans::UnknownPropertyException)
371 ::osl::MutexGuard aGuard( m_aMutex );
372 uno::Any aPropertyValue;
373 const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName);
374 switch(nId)
376 case PROPERTY_ID_CONDITIONALPRINTEXPRESSION:
377 case PROPERTY_ID_INITIALFORMULA:
378 case PROPERTY_ID_FORMULA:
379 case PROPERTY_ID_DATAFIELD:
380 aPropertyValue = m_xReportComponent->getPropertyValue( PropertyName );
381 lcl_convertFormulaTo(aPropertyValue,aPropertyValue);
382 if ( PROPERTY_ID_DATAFIELD == nId )
384 ::rtl::OUString sDataField;
385 aPropertyValue >>= sDataField;
386 switch(m_nDataFieldType)
388 case DATA_OR_FORMULA:
389 break;
390 case FUNCTION:
391 if ( isDefaultFunction(sDataField,sDataField) )
392 aPropertyValue <<= sDataField;
393 else if ( !sDataField.getLength() )
394 aPropertyValue = uno::Any();
395 break;
396 case COUNTER:
397 case USER_DEF_FUNCTION:
398 aPropertyValue = uno::Any();
399 break;
403 break;
404 case PROPERTY_ID_TYPE:
406 const sal_uInt32 nOldDataFieldType = m_nDataFieldType;
407 m_nDataFieldType = impl_getDataFieldType_throw();
408 if ( UNDEF_DATA == m_nDataFieldType )
409 m_nDataFieldType = nOldDataFieldType;
410 aPropertyValue <<= m_nDataFieldType;
412 break;
413 case PROPERTY_ID_FORMULALIST:
414 case PROPERTY_ID_SCOPE:
416 uno::Any aDataField = m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD );
417 lcl_convertFormulaTo(aDataField,aDataField);
418 ::rtl::OUString sDataField;
419 aDataField >>= sDataField;
420 switch(m_nDataFieldType)
422 case DATA_OR_FORMULA:
423 break;
424 case FUNCTION:
425 if ( isDefaultFunction(sDataField,sDataField,uno::Reference< report::XFunctionsSupplier>(),true) )
426 aPropertyValue <<= (PROPERTY_ID_FORMULALIST == nId ? m_sDefaultFunction : m_sScope);
427 break;
428 case USER_DEF_FUNCTION:
429 if ( sDataField.getLength() && PROPERTY_ID_FORMULALIST == nId )
430 aPropertyValue = aDataField;
431 break;
432 case COUNTER:
433 if ( PROPERTY_ID_SCOPE == nId && impl_isCounterFunction_throw(sDataField,m_sScope) )
434 aPropertyValue <<= m_sScope;
435 break;
439 break;
440 case PROPERTY_ID_BACKCOLOR:
441 case PROPERTY_ID_CONTROLBACKGROUND:
443 aPropertyValue = m_xReportComponent->getPropertyValue( PropertyName );
444 sal_Int32 nColor = COL_TRANSPARENT;
445 if ( (aPropertyValue >>= nColor) && static_cast<sal_Int32>(COL_TRANSPARENT) == nColor )
446 aPropertyValue.clear();
448 break;
449 case PROPERTY_ID_MIMETYPE:
451 ::rtl::OUString sValue;
452 m_xReportComponent->getPropertyValue( PropertyName ) >>= sValue;
453 aPropertyValue <<= impl_ConvertMimeTypeToUI_nothrow(sValue);
455 break;
456 default:
457 aPropertyValue = m_xReportComponent->getPropertyValue( PropertyName );
458 break;
460 return aPropertyValue;
463 void SAL_CALL GeometryHandler::setPropertyValue(const ::rtl::OUString & PropertyName, const uno::Any & Value) throw (uno::RuntimeException, beans::UnknownPropertyException)
465 ::osl::ResettableMutexGuard aGuard( m_aMutex );
466 uno::Any aNewValue = Value;
467 const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName);
468 bool bHandled = false;
469 switch(nId)
471 case PROPERTY_ID_INITIALFORMULA:
472 case PROPERTY_ID_FORMULA:
473 break;
474 case PROPERTY_ID_DATAFIELD:
476 OBlocker aBlocker(m_bIn);
477 m_xReportComponent->setPropertyValue(PropertyName, aNewValue);
478 bHandled = true;
479 const ::rtl::OUString sOldFunctionName = m_sDefaultFunction;
480 const ::rtl::OUString sOldScope = m_sScope;
482 uno::Any aPropertyValue;
483 lcl_convertFormulaTo(Value,aPropertyValue);
484 ::rtl::OUString sDataField;
485 aPropertyValue >>= sDataField;
487 m_sScope = m_sDefaultFunction = ::rtl::OUString();
488 m_xFunction.clear();
489 const sal_uInt32 nOldDataFieldType = m_nDataFieldType;
490 if ( sDataField.getLength() )
492 if ( isDefaultFunction(sDataField,sDataField,uno::Reference< report::XFunctionsSupplier>(),true) )
493 m_nDataFieldType = FUNCTION;
494 else if ( m_aFunctionNames.find(sDataField) != m_aFunctionNames.end() )
495 m_nDataFieldType = USER_DEF_FUNCTION;
498 resetOwnProperties(aGuard,sOldFunctionName,sOldScope,nOldDataFieldType);
500 break;
501 case PROPERTY_ID_TYPE:
503 bHandled = true;
504 Value >>= m_nDataFieldType;
506 const ::rtl::OUString sOldFunctionName = m_sDefaultFunction;
507 const ::rtl::OUString sOldScope = m_sScope;
508 m_sDefaultFunction = m_sScope = ::rtl::OUString();
510 if ( m_nDataFieldType == COUNTER )
512 impl_setCounterFunction_throw();
514 else
516 if ( m_bNewFunction )
517 removeFunction();
518 m_xFunction.clear();
519 OBlocker aBlocker(m_bIn);
520 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(::rtl::OUString()));
522 resetOwnProperties(aGuard,sOldFunctionName,sOldScope,m_nDataFieldType);
524 break;
525 case PROPERTY_ID_FORMULALIST:
527 bHandled = true;
528 ::rtl::OUString sFunction;
529 if ( !(Value >>= sFunction) || !sFunction.getLength() )
531 if ( m_nDataFieldType == FUNCTION )
533 m_sDefaultFunction = ::rtl::OUString();
534 if ( m_bNewFunction )
535 removeFunction();
536 m_xFunction.clear();
538 beans::PropertyChangeEvent aEvent;
539 aEvent.PropertyName = PROPERTY_SCOPE;
540 aEvent.OldValue <<= m_sScope;
541 m_sScope = ::rtl::OUString();
542 aEvent.NewValue <<= m_sScope;
543 aGuard.clear();
544 m_aPropertyListeners.notify( aEvent, &beans::XPropertyChangeListener::propertyChange );
546 else if ( m_nDataFieldType == USER_DEF_FUNCTION )
548 OBlocker aBlocker(m_bIn);
549 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(::rtl::OUString()));
552 else if ( m_nDataFieldType == USER_DEF_FUNCTION )
554 ::rtl::OUString sDataField;
555 OBlocker aBlocker(m_bIn);
556 const sal_uInt32 nNewDataType = impl_getDataFieldType_throw(sFunction);
557 if ( nNewDataType != UNDEF_DATA && nNewDataType != m_nDataFieldType )
559 const ::rtl::OUString sOldFunctionName = m_sDefaultFunction;
560 const ::rtl::OUString sOldScope = m_sScope;
561 m_sScope = m_sDefaultFunction = ::rtl::OUString();
562 m_xFunction.clear();
563 if ( nNewDataType == COUNTER )
564 impl_isCounterFunction_throw(sFunction,m_sScope);
565 else
567 ::rtl::OUString sNamePostFix;
568 const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostFix);
569 isDefaultFunction(sFunction,sDataField,xFunctionsSupplier,true);
571 const sal_uInt32 nOldDataFieldType = m_nDataFieldType;
572 m_nDataFieldType = nNewDataType;
573 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(impl_convertToFormula( uno::makeAny(sFunction))));
574 resetOwnProperties(aGuard,sOldFunctionName,sOldScope,nOldDataFieldType);
576 else
577 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(impl_convertToFormula( uno::makeAny(sFunction))));
579 else if ( m_nDataFieldType == FUNCTION )
581 uno::Any aPropertyValue = m_xReportComponent->getPropertyValue(PROPERTY_DATAFIELD);
582 lcl_convertFormulaTo(aPropertyValue,aPropertyValue);
583 ::rtl::OUString sDataField;
584 aPropertyValue >>= sDataField;
585 if ( m_nDataFieldType == FUNCTION && (!isDefaultFunction(sDataField,sDataField) || m_sDefaultFunction != sFunction) )
587 if ( m_bNewFunction )
588 removeFunction();
589 // function currently does not exist
590 createDefaultFunction(aGuard,sFunction,sDataField);
591 m_sDefaultFunction = sFunction;
596 break;
597 case PROPERTY_ID_SCOPE:
598 if ( !(Value >>= m_sScope) )
599 m_sScope = ::rtl::OUString();
600 else
602 if ( m_bNewFunction )
603 removeFunction();
604 if ( m_nDataFieldType == COUNTER )
605 impl_setCounterFunction_throw();
606 else
608 OSL_ENSURE(m_xFunction.is(),"Where is my function gone!");
610 ::rtl::OUString sNamePostFix;
611 const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostFix);
613 ::rtl::OUString sQuotedFunctionName(lcl_getQuotedFunctionName(m_xFunction));
614 if ( isDefaultFunction(sQuotedFunctionName,sQuotedFunctionName,xFunctionsSupplier,true) )
615 m_bNewFunction = false;
616 else
618 ::rtl::OUString sDefaultFunctionName;
619 ::rtl::OUString sDataField;
620 OSL_VERIFY( impl_isDefaultFunction_nothrow(m_xFunction,sDataField,sDefaultFunctionName) );
621 m_sDefaultFunction = sDefaultFunctionName;
622 createDefaultFunction(aGuard,m_sDefaultFunction,sDataField);
626 bHandled = true;
627 break;
628 case PROPERTY_ID_POSITIONX:
629 case PROPERTY_ID_POSITIONY:
630 case PROPERTY_ID_HEIGHT:
631 case PROPERTY_ID_WIDTH:
633 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY);
634 if ( xSourceReportComponent.is() ) // check only report components
636 sal_Int32 nNewValue = 0;
637 Value >>= nNewValue;
638 awt::Point aAwtPoint = xSourceReportComponent->getPosition();
639 awt::Size aAwtSize = xSourceReportComponent->getSize();
640 if ( nId == PROPERTY_ID_POSITIONX )
641 aAwtPoint.X = nNewValue;
642 else if ( nId == PROPERTY_ID_POSITIONY )
643 aAwtPoint.Y = nNewValue;
644 else if ( nId == PROPERTY_ID_HEIGHT )
645 aAwtSize.Height = nNewValue;
646 else if ( nId == PROPERTY_ID_WIDTH )
647 aAwtSize.Width = nNewValue;
649 checkPosAndSize(aAwtPoint,aAwtSize);
652 break;
653 case PROPERTY_ID_CHARFONTNAME:
655 const uno::Reference< report::XReportControlFormat > xReportControlFormat( m_xReportComponent,uno::UNO_QUERY_THROW );
656 uno::Sequence< beans::NamedValue > aFontSettings;
657 OSL_VERIFY( Value >>= aFontSettings );
658 applyCharacterSettings( xReportControlFormat, aFontSettings );
659 bHandled = true;
661 break;
662 case PROPERTY_ID_MIMETYPE:
664 ::rtl::OUString sValue;
665 Value >>= sValue;
666 aNewValue <<= impl_ConvertUIToMimeType_nothrow(sValue);
668 default:
669 break;
672 if ( !bHandled )
673 m_xReportComponent->setPropertyValue(PropertyName, aNewValue);
676 // -----------------------------------------------------------------------------
677 beans::PropertyState SAL_CALL GeometryHandler::getPropertyState(const ::rtl::OUString & PropertyName) throw (uno::RuntimeException, beans::UnknownPropertyException)
679 ::osl::MutexGuard aGuard( m_aMutex );
680 return m_xFormComponentHandler->getPropertyState(PropertyName);
682 // -----------------------------------------------------------------------------
683 void GeometryHandler::implCreateListLikeControl(
684 const uno::Reference< inspection::XPropertyControlFactory >& _rxControlFactory
685 ,inspection::LineDescriptor & out_Descriptor
686 ,sal_uInt16 _nResId
687 ,sal_Bool _bReadOnlyControl
688 ,sal_Bool _bTrueIfListBoxFalseIfComboBox
691 ::std::vector< ::rtl::OUString > aList;
692 tools::StringListResource aRes(ModuleRes(_nResId),aList);
694 implCreateListLikeControl(_rxControlFactory,out_Descriptor,aList,_bReadOnlyControl,_bTrueIfListBoxFalseIfComboBox);
696 // -----------------------------------------------------------------------------
697 void GeometryHandler::implCreateListLikeControl(
698 const uno::Reference< inspection::XPropertyControlFactory >& _rxControlFactory
699 ,inspection::LineDescriptor & out_Descriptor
700 ,const ::std::vector< ::rtl::OUString>& _aEntries
701 ,sal_Bool _bReadOnlyControl
702 ,sal_Bool _bTrueIfListBoxFalseIfComboBox
705 const uno::Reference< inspection::XStringListControl > xListControl(
706 _rxControlFactory->createPropertyControl(
707 _bTrueIfListBoxFalseIfComboBox ? inspection::PropertyControlType::ListBox : inspection::PropertyControlType::ComboBox, _bReadOnlyControl
709 uno::UNO_QUERY_THROW
712 out_Descriptor.Control = xListControl.get();
713 ::std::for_each( _aEntries.begin(), _aEntries.end(),::boost::bind( &inspection::XStringListControl::appendListEntry, xListControl,_1 ));
715 // -----------------------------------------------------------------------------
717 inspection::LineDescriptor SAL_CALL GeometryHandler::describePropertyLine(const ::rtl::OUString & PropertyName, const uno::Reference< inspection::XPropertyControlFactory > & _xControlFactory) throw (beans::UnknownPropertyException, lang::NullPointerException,uno::RuntimeException)
719 inspection::LineDescriptor aOut;
720 const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName);
721 switch(nId)
723 case PROPERTY_ID_FORCENEWPAGE:
724 case PROPERTY_ID_NEWROWORCOL:
725 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_FORCENEWPAGE_CONST,sal_False,sal_True);
726 break;
727 case PROPERTY_ID_GROUPKEEPTOGETHER:
728 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_GROUPKEEPTOGETHER_CONST,sal_False,sal_True);
729 break;
730 case PROPERTY_ID_PAGEHEADEROPTION:
731 case PROPERTY_ID_PAGEFOOTEROPTION:
732 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_REPORTPRINTOPTION_CONST,sal_False,sal_True);
733 break;
734 case PROPERTY_ID_FORMULALIST:
736 ::std::vector< ::rtl::OUString > aList;
737 impl_fillFormulaList_nothrow(aList);
738 implCreateListLikeControl(_xControlFactory,aOut,aList,sal_False,sal_True);
740 break;
741 case PROPERTY_ID_SCOPE:
743 ::std::vector< ::rtl::OUString > aList;
744 impl_fillScopeList_nothrow(aList);
745 implCreateListLikeControl(_xControlFactory,aOut,aList,sal_False,sal_True);
747 break;
748 case PROPERTY_ID_MIMETYPE:
750 ::std::vector< ::rtl::OUString > aList;
751 impl_fillMimeTypes_nothrow(aList);
752 implCreateListLikeControl(_xControlFactory,aOut,aList,sal_False,sal_True);
754 break;
755 case PROPERTY_ID_TYPE:
756 implCreateListLikeControl(_xControlFactory,aOut,RID_STR_TYPE_CONST,sal_False,sal_True);
757 break;
758 case PROPERTY_ID_VISIBLE:
759 case PROPERTY_ID_CANGROW:
760 case PROPERTY_ID_CANSHRINK:
761 case PROPERTY_ID_REPEATSECTION:
762 case PROPERTY_ID_PRINTREPEATEDVALUES:
763 case PROPERTY_ID_STARTNEWCOLUMN:
764 case PROPERTY_ID_RESETPAGENUMBER:
765 case PROPERTY_ID_PRINTWHENGROUPCHANGE:
766 case PROPERTY_ID_KEEPTOGETHER:
767 case PROPERTY_ID_DEEPTRAVERSING:
768 case PROPERTY_ID_PREEVALUATED:
769 case PROPERTY_ID_PRESERVEIRI:
770 case PROPERTY_ID_BACKTRANSPARENT:
771 case PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT:
773 sal_uInt16 nResId = RID_STR_BOOL;
774 if ( PROPERTY_ID_KEEPTOGETHER == nId && uno::Reference< report::XGroup>(m_xReportComponent,uno::UNO_QUERY).is())
775 nResId = RID_STR_KEEPTOGETHER_CONST;
776 implCreateListLikeControl(_xControlFactory,aOut,nResId,sal_False,sal_True);
778 break;
779 case PROPERTY_ID_INITIALFORMULA:
780 case PROPERTY_ID_FORMULA:
781 aOut.PrimaryButtonId = UID_RPT_PROP_FORMULA;
782 aOut.HasPrimaryButton = sal_True;
783 aOut.Control = _xControlFactory->createPropertyControl(inspection::PropertyControlType::MultiLineTextField , sal_False);
784 break;
785 case PROPERTY_ID_CONDITIONALPRINTEXPRESSION:
786 aOut.PrimaryButtonId = UID_RPT_PROP_FORMULA;
787 aOut.HasPrimaryButton = sal_True;
788 aOut.Control = _xControlFactory->createPropertyControl(inspection::PropertyControlType::MultiLineTextField , sal_False);
789 break;
790 case PROPERTY_ID_DATAFIELD:
792 uno::Reference< inspection::XStringListControl > xListControl(
793 _xControlFactory->createPropertyControl(
794 m_nDataFieldType == DATA_OR_FORMULA ? inspection::PropertyControlType::ComboBox : inspection::PropertyControlType::ListBox, sal_False
796 uno::UNO_QUERY_THROW
799 if ( m_nDataFieldType == DATA_OR_FORMULA )
801 aOut.PrimaryButtonId = UID_RPT_PROP_FORMULA;
802 aOut.HasPrimaryButton = sal_True;
805 aOut.Control = xListControl.get();
806 if ( m_nDataFieldType == USER_DEF_FUNCTION )
808 // add function names
809 ::std::for_each( m_aFunctionNames.begin(), m_aFunctionNames.end(),
810 ::std::compose1(
811 ::boost::bind( &inspection::XStringListControl::appendListEntry, xListControl,_1 ),
812 ::std::select1st<TFunctions::value_type>()));
814 else
816 ::std::for_each( m_aFieldNames.getConstArray(), m_aFieldNames.getConstArray() + m_aFieldNames.getLength(),
817 ::boost::bind( &inspection::XStringListControl::appendListEntry, xListControl, _1 ) );
818 ::std::for_each( m_aParamNames.getConstArray(), m_aParamNames.getConstArray() + m_aParamNames.getLength(),
819 ::boost::bind( &inspection::XStringListControl::appendListEntry, xListControl, _1 ) );
822 break;
823 case PROPERTY_ID_BACKCOLOR:
824 case PROPERTY_ID_CONTROLBACKGROUND:
825 aOut.Control = _xControlFactory->createPropertyControl( inspection::PropertyControlType::ColorListBox, sal_False );
826 break;
827 case PROPERTY_ID_CHARFONTNAME:
828 aOut.PrimaryButtonId = UID_RPT_RPT_PROP_DLG_FONT_TYPE;
829 aOut.Control = _xControlFactory->createPropertyControl( inspection::PropertyControlType::TextField, sal_True );
830 aOut.HasPrimaryButton = sal_True;
831 break;
832 case PROPERTY_ID_AREA:
833 aOut.PrimaryButtonId = UID_RPT_RPT_PROP_DLG_AREA;
834 aOut.Control = _xControlFactory->createPropertyControl( inspection::PropertyControlType::TextField, sal_True );
835 aOut.HasPrimaryButton = sal_True;
836 break;
837 default:
839 aOut = m_xFormComponentHandler->describePropertyLine(PropertyName, _xControlFactory);
843 if ( nId != -1 )
845 aOut.Category = ((m_pInfoService->getPropertyUIFlags(nId ) & PROP_FLAG_DATA_PROPERTY) != 0) ?
846 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Data"))
848 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("General"));
849 aOut.HelpURL = HelpIdUrl::getHelpURL( m_pInfoService->getPropertyHelpId( nId ) );
850 aOut.DisplayName = m_pInfoService->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( MEASURE_METRIC == eSystem ? FUNIT_CM : FUNIT_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 xNumericControl->setMinValue(beans::Optional<double>(sal_True,0.0));
865 if ( nDisplayUnit != -1 )
866 xNumericControl->setDisplayUnit( nDisplayUnit );
867 uno::Reference< report::XReportComponent> xComp(m_xReportComponent,uno::UNO_QUERY);
868 if ( xComp.is() && xComp->getSection().is() )
870 uno::Reference< report::XReportDefinition > xReport = xComp->getSection()->getReportDefinition();
871 OSL_ENSURE(xReport.is(),"Why is the report definition NULL!");
872 if ( xReport.is() )
874 const awt::Size aSize = getStyleProperty<awt::Size>(xReport,PROPERTY_PAPERSIZE);
875 const sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReport,PROPERTY_LEFTMARGIN);
876 const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReport,PROPERTY_RIGHTMARGIN);
877 switch(nId)
879 case PROPERTY_ID_POSITIONX:
880 case PROPERTY_ID_POSITIONY:
881 case PROPERTY_ID_WIDTH:
882 xNumericControl->setMinValue(beans::Optional<double>(sal_True,0.0));
883 xNumericControl->setMaxValue(beans::Optional<double>(sal_True,double(aSize.Width - nLeftMargin - nRightMargin)));
884 if ( PROPERTY_ID_WIDTH == nId )
886 uno::Reference<report::XFixedLine> xFixedLine(m_xReportComponent,uno::UNO_QUERY);
887 if ( xFixedLine.is() && xFixedLine->getOrientation() == 1 ) // vertical
888 xNumericControl->setMinValue(beans::Optional<double>(sal_True,0.08 ));
890 break;
891 default:
892 break;
896 else if ( PROPERTY_ID_HEIGHT == nId )
898 const uno::Reference< report::XSection> xSection(m_xReportComponent,uno::UNO_QUERY);
899 if ( xSection.is() )
901 sal_Int32 nHeight = 0;
902 const sal_Int32 nCount = xSection->getCount();
903 for (sal_Int32 i = 0; i < nCount; ++i)
905 uno::Reference<drawing::XShape> xShape(xSection->getByIndex(i),uno::UNO_QUERY);
906 nHeight = ::std::max<sal_Int32>(nHeight,xShape->getPosition().Y + xShape->getSize().Height);
908 xNumericControl->setMinValue(beans::Optional<double>(sal_True,nHeight ));
912 return aOut;
914 // -----------------------------------------------------------------------------
915 beans::Property GeometryHandler::getProperty(const ::rtl::OUString & PropertyName)
917 uno::Sequence< beans::Property > aProps = getSupportedProperties();
918 const beans::Property* pIter = aProps.getConstArray();
919 const beans::Property* pEnd = pIter + aProps.getLength();
920 const beans::Property* pFind = ::std::find_if(pIter,pEnd,::std::bind2nd(PropertyCompare(),boost::cref(PropertyName)));
921 if ( pFind == pEnd )
922 return beans::Property();
923 return *pFind;
925 uno::Any GeometryHandler::getConstantValue(sal_Bool _bToControlValue,sal_uInt16 _nResId,const uno::Any& _aValue,const ::rtl::OUString& _sConstantName,const ::rtl::OUString & PropertyName )
927 ::std::vector< ::rtl::OUString > aList;
928 tools::StringListResource aRes(ModuleRes(_nResId),aList);
929 uno::Sequence< ::rtl::OUString > aSeq(aList.size());
930 ::std::copy( aList.begin(), aList.end(), aSeq.getArray() );
932 uno::Reference< inspection::XStringRepresentation > xConversionHelper = inspection::StringRepresentation::createConstant( m_xContext,m_xTypeConverter,_sConstantName,aSeq);
933 if ( _bToControlValue )
935 return uno::makeAny( xConversionHelper->convertToControlValue( _aValue ) );
937 else
939 ::rtl::OUString sControlValue;
940 _aValue >>= sControlValue;
941 const beans::Property aProp = getProperty(PropertyName);
942 return xConversionHelper->convertToPropertyValue( sControlValue, aProp.Type );
946 uno::Any SAL_CALL GeometryHandler::convertToPropertyValue(const ::rtl::OUString & PropertyName, const uno::Any & _rControlValue) throw (uno::RuntimeException, beans::UnknownPropertyException)
948 ::osl::MutexGuard aGuard( m_aMutex );
949 uno::Any aPropertyValue( _rControlValue );
950 const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName);
951 switch(nId)
953 case PROPERTY_ID_FORCENEWPAGE:
954 case PROPERTY_ID_NEWROWORCOL:
955 aPropertyValue = getConstantValue(sal_False,RID_STR_FORCENEWPAGE_CONST,_rControlValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.ForceNewPage")),PropertyName);
956 break;
957 case PROPERTY_ID_GROUPKEEPTOGETHER:
958 aPropertyValue = getConstantValue(sal_False,RID_STR_GROUPKEEPTOGETHER_CONST,_rControlValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.GroupKeepTogether")),PropertyName);
959 break;
960 case PROPERTY_ID_PAGEHEADEROPTION:
961 case PROPERTY_ID_PAGEFOOTEROPTION:
962 aPropertyValue = getConstantValue(sal_False,RID_STR_REPORTPRINTOPTION_CONST,_rControlValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.ReportPrintOption")),PropertyName);
963 break;
964 case PROPERTY_ID_BACKCOLOR:
965 case PROPERTY_ID_CONTROLBACKGROUND:
966 if ( !_rControlValue.hasValue() )
968 aPropertyValue <<= static_cast<sal_Int32>(COL_TRANSPARENT);
969 break;
971 // run through
973 case PROPERTY_ID_KEEPTOGETHER:
974 if ( uno::Reference< report::XGroup>(m_xReportComponent,uno::UNO_QUERY).is())
976 aPropertyValue = getConstantValue(sal_False,RID_STR_KEEPTOGETHER_CONST,_rControlValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.KeepTogether")),PropertyName);
977 break;
979 // run through
981 case PROPERTY_ID_VISIBLE:
982 case PROPERTY_ID_CANGROW:
983 case PROPERTY_ID_CANSHRINK:
984 case PROPERTY_ID_REPEATSECTION:
985 case PROPERTY_ID_PRINTREPEATEDVALUES:
986 case PROPERTY_ID_STARTNEWCOLUMN:
987 case PROPERTY_ID_RESETPAGENUMBER:
988 case PROPERTY_ID_PRINTWHENGROUPCHANGE:
989 case PROPERTY_ID_DEEPTRAVERSING:
990 case PROPERTY_ID_PREEVALUATED:
991 case PROPERTY_ID_PRESERVEIRI:
992 case PROPERTY_ID_BACKTRANSPARENT:
993 case PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT:
995 if ( aPropertyValue.hasValue() )
997 const beans::Property aProp = getProperty(PropertyName);
998 if ( aPropertyValue.getValueType().equals( aProp.Type ) )
999 // nothing to do, type is already as desired
1000 return aPropertyValue;
1002 if ( _rControlValue.getValueType().getTypeClass() == uno::TypeClass_STRING )
1004 ::rtl::OUString sControlValue;
1005 _rControlValue >>= sControlValue;
1007 const uno::Reference< inspection::XStringRepresentation > xConversionHelper = inspection::StringRepresentation::create( m_xContext,m_xTypeConverter );
1008 aPropertyValue = xConversionHelper->convertToPropertyValue( sControlValue, aProp.Type );
1010 else
1014 aPropertyValue = m_xTypeConverter->convertTo( _rControlValue, aProp.Type );
1016 catch( const uno::Exception& )
1018 OSL_ENSURE( sal_False, "GeometryHandler::convertToPropertyValue: caught an exception while converting via TypeConverter!" );
1023 break;
1025 case PROPERTY_ID_CONDITIONALPRINTEXPRESSION:
1026 case PROPERTY_ID_INITIALFORMULA:
1027 case PROPERTY_ID_FORMULA:
1028 return uno::makeAny( impl_convertToFormula( _rControlValue ) );
1029 case PROPERTY_ID_DATAFIELD:
1031 ::rtl::OUString sDataField;
1032 _rControlValue >>= sDataField;
1033 if ( isDefaultFunction(sDataField,sDataField) )
1035 OSL_ENSURE(m_xFunction.is(),"No function set!");
1036 aPropertyValue <<= impl_convertToFormula( uno::makeAny(lcl_getQuotedFunctionName(m_xFunction)) );
1038 else
1039 aPropertyValue <<= impl_convertToFormula( _rControlValue );
1041 break;
1042 case PROPERTY_ID_POSITIONX:
1044 aPropertyValue = m_xFormComponentHandler->convertToPropertyValue(PropertyName, _rControlValue);
1045 sal_Int32 nPosX = 0;
1046 aPropertyValue >>= nPosX;
1047 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY);
1048 if ( xSourceReportComponent->getSection().is() )
1049 nPosX += getStyleProperty<sal_Int32>(xSourceReportComponent->getSection()->getReportDefinition(),PROPERTY_LEFTMARGIN);
1050 aPropertyValue <<= nPosX;
1052 break;
1053 case PROPERTY_ID_CHARFONTNAME:
1054 return m_xFormComponentHandler->convertToPropertyValue(PROPERTY_FONTNAME, _rControlValue);
1055 case PROPERTY_ID_SCOPE:
1056 case PROPERTY_ID_FORMULALIST:
1057 case PROPERTY_ID_AREA:
1058 aPropertyValue = _rControlValue;
1059 break;
1060 case PROPERTY_ID_TYPE:
1062 ::rtl::OUString sValue;
1063 _rControlValue >>= sValue;
1064 ::std::vector< ::rtl::OUString > aList;
1065 tools::StringListResource aRes(ModuleRes(RID_STR_TYPE_CONST),aList);
1066 ::std::vector< ::rtl::OUString >::iterator aFind = ::std::find(aList.begin(),aList.end(),sValue);
1067 if ( aFind != aList.end() )
1068 aPropertyValue <<= static_cast<sal_uInt32>(aFind - aList.begin());
1070 break;
1071 case PROPERTY_ID_MIMETYPE:
1072 aPropertyValue = _rControlValue;
1073 break;
1074 default:
1075 return m_xFormComponentHandler->convertToPropertyValue(PropertyName, _rControlValue);
1077 return aPropertyValue;
1080 uno::Any SAL_CALL GeometryHandler::convertToControlValue(const ::rtl::OUString & PropertyName, const uno::Any & _rPropertyValue, const uno::Type & _rControlValueType) throw (uno::RuntimeException, beans::UnknownPropertyException)
1082 uno::Any aControlValue( _rPropertyValue );
1083 if ( !aControlValue.hasValue() )
1084 // NULL is converted to NULL
1085 return aControlValue;
1087 uno::Any aPropertyValue(_rPropertyValue);
1089 ::osl::MutexGuard aGuard( m_aMutex );
1090 const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName);
1091 switch(nId)
1093 case PROPERTY_ID_AREA:
1094 break;
1095 case PROPERTY_ID_FORCENEWPAGE:
1096 case PROPERTY_ID_NEWROWORCOL:
1097 aControlValue = getConstantValue(sal_True,RID_STR_FORCENEWPAGE_CONST,aPropertyValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.ForceNewPage")),PropertyName);
1098 break;
1099 case PROPERTY_ID_GROUPKEEPTOGETHER:
1100 aControlValue = getConstantValue(sal_True,RID_STR_GROUPKEEPTOGETHER_CONST,aPropertyValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.GroupKeepTogether")),PropertyName);
1101 break;
1102 case PROPERTY_ID_PAGEHEADEROPTION:
1103 case PROPERTY_ID_PAGEFOOTEROPTION:
1104 aControlValue = getConstantValue(sal_True,RID_STR_REPORTPRINTOPTION_CONST,aPropertyValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.ReportPrintOption")),PropertyName);
1105 break;
1106 case PROPERTY_ID_KEEPTOGETHER:
1107 if ( uno::Reference< report::XGroup>(m_xReportComponent,uno::UNO_QUERY).is())
1109 aControlValue = getConstantValue(sal_True,RID_STR_KEEPTOGETHER_CONST,aPropertyValue,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.KeepTogether")),PropertyName);
1110 break;
1112 // run through
1113 case PROPERTY_ID_VISIBLE:
1114 case PROPERTY_ID_CANGROW:
1115 case PROPERTY_ID_CANSHRINK:
1116 case PROPERTY_ID_REPEATSECTION:
1117 case PROPERTY_ID_PRINTREPEATEDVALUES:
1118 case PROPERTY_ID_STARTNEWCOLUMN:
1119 case PROPERTY_ID_RESETPAGENUMBER:
1120 case PROPERTY_ID_PRINTWHENGROUPCHANGE:
1121 case PROPERTY_ID_DEEPTRAVERSING:
1122 case PROPERTY_ID_PREEVALUATED:
1123 case PROPERTY_ID_PRESERVEIRI:
1124 case PROPERTY_ID_BACKTRANSPARENT:
1125 case PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT:
1127 if ( _rControlValueType.getTypeClass() == uno::TypeClass_STRING )
1129 const uno::Reference< inspection::XStringRepresentation > xConversionHelper = inspection::StringRepresentation::create( m_xContext,m_xTypeConverter );
1130 aControlValue <<= xConversionHelper->convertToControlValue( aPropertyValue );
1132 else
1136 aControlValue = m_xTypeConverter->convertTo( aPropertyValue, _rControlValueType );
1138 catch( const uno::Exception& )
1140 OSL_ENSURE( sal_False, "GeometryHandler::convertToControlValue: caught an exception while converting via TypeConverter!" );
1143 break;
1145 case PROPERTY_ID_CONDITIONALPRINTEXPRESSION:
1146 case PROPERTY_ID_INITIALFORMULA:
1147 case PROPERTY_ID_FORMULA:
1148 lcl_convertFormulaTo(aPropertyValue,aControlValue);
1149 break;
1150 case PROPERTY_ID_DATAFIELD:
1152 ::rtl::OUString sValue;
1153 aControlValue >>= sValue;
1154 if ( isDefaultFunction(sValue,sValue) )
1155 aControlValue <<= sValue;
1156 else
1157 lcl_convertFormulaTo(aPropertyValue,aControlValue);
1159 break;
1160 case PROPERTY_ID_CHARFONTNAME:
1161 aControlValue = m_xFormComponentHandler->convertToControlValue(PROPERTY_FONTNAME, aPropertyValue, _rControlValueType);
1162 break;
1163 case PROPERTY_ID_POSITIONX:
1165 sal_Int32 nPosX = 0;
1166 aPropertyValue >>= nPosX;
1167 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY);
1168 if ( xSourceReportComponent->getSection().is() )
1169 nPosX -= getStyleProperty<sal_Int32>(xSourceReportComponent->getSection()->getReportDefinition(),PROPERTY_LEFTMARGIN);
1170 aPropertyValue <<= nPosX;
1171 aControlValue = m_xFormComponentHandler->convertToControlValue(PropertyName, aPropertyValue, _rControlValueType);
1173 break;
1174 case PROPERTY_ID_FORMULALIST:
1175 aControlValue <<= m_sDefaultFunction;
1176 break;
1177 case PROPERTY_ID_SCOPE:
1178 aControlValue <<= m_sScope;
1179 break;
1180 case PROPERTY_ID_MIMETYPE:
1181 aControlValue = aPropertyValue;
1182 break;
1183 case PROPERTY_ID_TYPE:
1185 ::std::vector< ::rtl::OUString > aList;
1186 tools::StringListResource aRes(ModuleRes(RID_STR_TYPE_CONST),aList);
1187 if ( m_nDataFieldType < aList.size() )
1188 aControlValue <<= aList[m_nDataFieldType];
1190 break;
1191 case PROPERTY_ID_BACKCOLOR:
1192 case PROPERTY_ID_CONTROLBACKGROUND:
1194 sal_Int32 nColor = COL_TRANSPARENT;
1195 if ( (aPropertyValue >>= nColor) && static_cast<sal_Int32>(COL_TRANSPARENT) == nColor )
1196 aPropertyValue.clear();
1198 // run through
1199 default:
1200 aControlValue = m_xFormComponentHandler->convertToControlValue(PropertyName, aPropertyValue, _rControlValueType);
1202 return aControlValue;
1204 void SAL_CALL GeometryHandler::addPropertyChangeListener(const uno::Reference< beans::XPropertyChangeListener > & _rxListener) throw (uno::RuntimeException, lang::NullPointerException)
1206 ::osl::MutexGuard aGuard( m_aMutex );
1207 m_aPropertyListeners.addListener( _rxListener );
1208 m_xFormComponentHandler->addPropertyChangeListener(_rxListener);
1211 void SAL_CALL GeometryHandler::removePropertyChangeListener(const uno::Reference< beans::XPropertyChangeListener > & _rxListener) throw (uno::RuntimeException)
1213 ::osl::MutexGuard aGuard( m_aMutex );
1214 m_aPropertyListeners.removeListener( _rxListener );
1215 m_xFormComponentHandler->removePropertyChangeListener(_rxListener);
1217 // -----------------------------------------------------------------------------
1218 //--------------------------------------------------------------------------
1219 uno::Sequence< beans::Property > SAL_CALL GeometryHandler::getSupportedProperties() throw (uno::RuntimeException)
1221 ::std::vector< beans::Property > aNewProps;
1222 aNewProps.reserve(20); // only a guess
1223 m_pInfoService->getExcludeProperties( aNewProps, m_xFormComponentHandler );
1225 const ::rtl::OUString pIncludeProperties[] =
1227 PROPERTY_FORCENEWPAGE
1228 ,PROPERTY_KEEPTOGETHER
1229 ,PROPERTY_CANGROW
1230 ,PROPERTY_CANSHRINK
1231 ,PROPERTY_REPEATSECTION
1232 ,PROPERTY_PRINTREPEATEDVALUES
1233 ,PROPERTY_CONDITIONALPRINTEXPRESSION
1234 ,PROPERTY_STARTNEWCOLUMN
1235 ,PROPERTY_RESETPAGENUMBER
1236 ,PROPERTY_PRINTWHENGROUPCHANGE
1237 ,PROPERTY_VISIBLE
1238 ,PROPERTY_PAGEHEADEROPTION
1239 ,PROPERTY_PAGEFOOTEROPTION
1240 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlLabel"))
1241 ,PROPERTY_POSITIONX
1242 ,PROPERTY_POSITIONY
1243 ,PROPERTY_WIDTH
1244 ,PROPERTY_HEIGHT
1245 ,PROPERTY_PREEVALUATED
1246 ,PROPERTY_DEEPTRAVERSING
1247 ,PROPERTY_FORMULA
1248 ,PROPERTY_INITIALFORMULA
1249 ,PROPERTY_PRESERVEIRI
1250 ,PROPERTY_DATAFIELD
1251 ,PROPERTY_CHARFONTNAME
1252 ,PROPERTY_BACKCOLOR
1253 ,PROPERTY_BACKTRANSPARENT
1254 ,PROPERTY_CONTROLBACKGROUND
1255 ,PROPERTY_CONTROLBACKGROUNDTRANSPARENT
1256 ,PROPERTY_LABEL
1257 ,PROPERTY_MIMETYPE
1259 const uno::Reference < beans::XPropertySetInfo > xInfo = m_xReportComponent->getPropertySetInfo();
1260 const uno::Sequence< beans::Property> aSeq = xInfo->getProperties();
1261 for (size_t i = 0; i < sizeof(pIncludeProperties)/sizeof(pIncludeProperties[0]) ;++i )
1263 const beans::Property* pIter = aSeq.getConstArray();
1264 const beans::Property* pEnd = pIter + aSeq.getLength();
1265 const beans::Property* pFind = ::std::find_if(pIter,pEnd,::std::bind2nd(PropertyCompare(),boost::cref(pIncludeProperties[i])));
1266 if ( pFind != pEnd )
1268 // special case for controls which contain a data field
1269 if ( PROPERTY_DATAFIELD == pIncludeProperties[i] )
1271 beans::Property aValue;
1272 aValue.Name = PROPERTY_FORMULALIST;
1273 aNewProps.push_back(aValue);
1274 aValue.Name = PROPERTY_SCOPE;
1275 aNewProps.push_back(aValue);
1276 aValue.Name = PROPERTY_TYPE;
1277 aNewProps.push_back(aValue);
1279 aNewProps.push_back(*pFind);
1281 } // for (size_t i = 0; i < sizeof(pIncludeProperties)/sizeof(pIncludeProperties[0]) ;++i )
1283 // special property for shapes
1284 // if ( uno::Reference< report::XShape>(m_xReportComponent,uno::UNO_QUERY).is() )
1285 // {
1286 // beans::Property aValue;
1287 // aValue.Name = PROPERTY_AREA;
1288 // aNewProps.push_back(aValue);
1289 // }
1290 // re-enable when the remaining issues of #i88727# are fixed
1292 return uno::Sequence< beans::Property > (&(*aNewProps.begin()),aNewProps.size());
1295 uno::Sequence< ::rtl::OUString > SAL_CALL GeometryHandler::getSupersededProperties() throw (uno::RuntimeException)
1297 uno::Sequence< ::rtl::OUString > aRet;
1298 const uno::Reference<report::XReportDefinition> xReport(m_xReportComponent,uno::UNO_QUERY);
1299 if ( xReport.is() && !uno::Reference< report::XSection>(xReport->getParent(),uno::UNO_QUERY).is() )
1301 aRet.realloc(5);
1302 ::rtl::OUString* pIter = aRet.getArray();
1303 *pIter++ = PROPERTY_POSITIONX;
1304 *pIter++ = PROPERTY_POSITIONY;
1305 *pIter++ = PROPERTY_WIDTH;
1306 *pIter++ = PROPERTY_HEIGHT;
1307 *pIter++ = PROPERTY_DATAFIELD;
1309 return aRet;
1312 uno::Sequence< ::rtl::OUString > SAL_CALL GeometryHandler::getActuatingProperties() throw (uno::RuntimeException)
1314 ::osl::MutexGuard aGuard( m_aMutex );
1316 uno::Sequence< ::rtl::OUString > aSeq(5);
1317 aSeq[0] = PROPERTY_BACKTRANSPARENT;
1318 aSeq[1] = PROPERTY_CONTROLBACKGROUNDTRANSPARENT;
1319 aSeq[2] = PROPERTY_FORMULALIST;
1320 aSeq[3] = PROPERTY_TYPE;
1321 aSeq[4] = PROPERTY_DATAFIELD;
1323 return ::comphelper::concatSequences(m_xFormComponentHandler->getActuatingProperties(),aSeq);
1326 ::sal_Bool SAL_CALL GeometryHandler::isComposable(const ::rtl::OUString & _rPropertyName) throw (uno::RuntimeException, beans::UnknownPropertyException)
1328 return m_pInfoService->isComposable( _rPropertyName, m_xFormComponentHandler );
1331 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)
1333 if ( !_rxInspectorUI.is() )
1334 throw lang::NullPointerException();
1335 if ( PropertyName.equalsAscii(PROPERTY_FILTER) )
1337 ::osl::ClearableMutexGuard aGuard( m_aMutex );
1339 inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
1340 ::rtl::OUString sClause;
1341 if ( impl_dialogFilter_nothrow( sClause, aGuard ) )
1343 _rData <<= sClause;
1344 eResult = inspection::InteractiveSelectionResult_ObtainedValue;
1346 return eResult;
1348 else if ( PropertyName.equalsAscii(PROPERTY_CHARFONTNAME) )
1350 ::osl::ClearableMutexGuard aGuard( m_aMutex );
1352 inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
1353 const uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DialogParentWindow"))) ,uno::UNO_QUERY);
1354 const uno::Reference< report::XReportControlFormat> xReportControlFormat(m_xReportComponent,uno::UNO_QUERY);
1355 aGuard.clear();
1357 uno::Sequence< beans::NamedValue > aFontSettings;
1358 if ( rptui::openCharDialog( xReportControlFormat, xInspectorWindow, aFontSettings ) )
1360 _rData <<= aFontSettings;
1361 eResult = inspection::InteractiveSelectionResult_ObtainedValue;
1363 return eResult;
1365 else if ( PropertyName.equalsAscii(PROPERTY_FORMULA)
1366 || PropertyName.equalsAscii(PROPERTY_INITIALFORMULA)
1367 || PropertyName.equalsAscii(PROPERTY_DATAFIELD)
1368 || PropertyName.equalsAscii(PROPERTY_CONDITIONALPRINTEXPRESSION))
1370 ::osl::ClearableMutexGuard aGuard( m_aMutex );
1373 ::rtl::OUString sFormula;
1374 m_xReportComponent->getPropertyValue(PropertyName) >>= sFormula;
1375 const uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DialogParentWindow"))) ,uno::UNO_QUERY);
1376 uno::Reference< uno::XComponentContext > xContext = m_xContext;
1377 uno::Reference< beans::XPropertySet > xRowSet( m_xRowSet,uno::UNO_QUERY);
1378 aGuard.clear();
1380 inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
1381 if ( rptui::openDialogFormula_nothrow( sFormula, xContext,xInspectorWindow,xRowSet ) )
1383 _rData <<= sFormula;
1384 eResult = inspection::InteractiveSelectionResult_ObtainedValue;
1386 return eResult;
1388 else if ( PropertyName.equalsAscii(PROPERTY_AREA) )
1390 ::osl::ClearableMutexGuard aGuard( m_aMutex );
1392 inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
1393 const uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DialogParentWindow"))) ,uno::UNO_QUERY);
1394 const uno::Reference< report::XShape> xShape(m_xReportComponent,uno::UNO_QUERY);
1395 aGuard.clear();
1397 if ( rptui::openAreaDialog( xShape, xInspectorWindow) )
1399 eResult = inspection::InteractiveSelectionResult_ObtainedValue;
1400 beans::PropertyChangeEvent aScopeEvent;
1401 aScopeEvent.PropertyName = PROPERTY_FILLCOLOR;
1402 // aScopeEvent.OldValue <<= _nOldDataFieldType;
1403 aScopeEvent.NewValue <<= xShape->getPropertyValue(PROPERTY_FILLCOLOR);
1404 m_aPropertyListeners.notify( aScopeEvent, &beans::XPropertyChangeListener::propertyChange );
1406 return eResult;
1410 return m_xFormComponentHandler->onInteractivePropertySelection(PropertyName, Primary, _rData, _rxInspectorUI);
1413 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)
1415 if ( !_rxInspectorUI.is() )
1416 throw lang::NullPointerException();
1418 ::osl::MutexGuard aGuard( m_aMutex );
1419 const sal_Int32 nId = m_pInfoService->getPropertyId(ActuatingPropertyName);
1420 switch(nId)
1422 case PROPERTY_ID_TYPE:
1424 sal_uInt32 nNewVal = 0;
1425 NewValue >>= nNewVal;
1426 switch(nNewVal)
1428 case DATA_OR_FORMULA:
1429 _rxInspectorUI->rebuildPropertyUI(PROPERTY_DATAFIELD);
1430 _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,sal_True);
1431 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,sal_False);
1432 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,sal_False);
1433 OSL_ENSURE(m_sDefaultFunction.getLength() == 0,"Why is the m_sDefaultFunction set?");
1434 OSL_ENSURE(m_sScope.getLength() == 0,"Why is the m_sScope set?");
1435 break;
1436 case FUNCTION:
1437 _rxInspectorUI->rebuildPropertyUI(PROPERTY_DATAFIELD);
1438 _rxInspectorUI->rebuildPropertyUI(PROPERTY_FORMULALIST);
1439 _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,sal_True);
1440 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,m_sDefaultFunction.getLength() != 0);
1441 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,m_sScope.getLength() != 0);
1442 break;
1443 case USER_DEF_FUNCTION:
1444 _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,sal_False);
1445 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,sal_True);
1446 _rxInspectorUI->rebuildPropertyUI(PROPERTY_FORMULALIST);
1447 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,sal_False);
1448 break;
1449 case COUNTER:
1450 _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,sal_False);
1451 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,sal_False);
1452 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,sal_True);
1453 break;
1456 break;
1457 case PROPERTY_ID_DATAFIELD:
1459 sal_Bool bEnable = (m_nDataFieldType != DATA_OR_FORMULA && m_nDataFieldType != COUNTER );
1460 if ( bEnable )
1462 ::rtl::OUString sValue;
1463 m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD ) >>= sValue;
1464 bEnable = sValue.getLength() != 0;
1466 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,bEnable);
1467 if ( bEnable )
1469 _rxInspectorUI->rebuildPropertyUI(PROPERTY_DATAFIELD);
1470 _rxInspectorUI->rebuildPropertyUI(PROPERTY_FORMULALIST);
1473 break;
1474 case PROPERTY_ID_FORMULALIST:
1476 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,m_nDataFieldType == FUNCTION || m_nDataFieldType == COUNTER);
1478 break;
1479 case PROPERTY_ID_BACKTRANSPARENT:
1480 case PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT:
1482 sal_Bool bValue = sal_False;
1483 NewValue >>= bValue;
1484 bValue = !bValue;
1485 _rxInspectorUI->enablePropertyUI(PROPERTY_BACKCOLOR,bValue);
1486 _rxInspectorUI->enablePropertyUI(PROPERTY_CONTROLBACKGROUND,bValue);
1488 break;
1489 default:
1490 m_xFormComponentHandler->actuatingPropertyChanged(ActuatingPropertyName, NewValue, OldValue, _rxInspectorUI, _bFirstTimeInit);
1491 break;
1495 ::sal_Bool SAL_CALL GeometryHandler::suspend(::sal_Bool Suspend) throw (uno::RuntimeException)
1497 return m_xFormComponentHandler->suspend(Suspend);
1499 // -----------------------------------------------------------------------------
1500 bool GeometryHandler::impl_dialogFilter_nothrow( ::rtl::OUString& _out_rSelectedClause, ::osl::ClearableMutexGuard& _rClearBeforeDialog ) const
1502 _out_rSelectedClause = ::rtl::OUString();
1503 bool bSuccess = false;
1504 ::dbtools::SQLExceptionInfo aErrorInfo;
1505 uno::Reference< awt::XWindow > xInspectorWindow;
1506 uno::Reference< lang::XMultiComponentFactory > xFactory;
1507 uno::Reference<lang::XMultiServiceFactory> xServiceFactory;
1510 xFactory = m_xContext->getServiceManager();
1511 xServiceFactory.set(xFactory,uno::UNO_QUERY);
1512 xInspectorWindow.set(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DialogParentWindow"))) ,uno::UNO_QUERY);
1513 uno::Reference<sdbc::XConnection> xCon(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ActiveConnection"))) ,uno::UNO_QUERY);
1514 if ( !xCon.is() )
1515 return false;
1517 uno::Reference< beans::XPropertySet> xRowSetProp(m_xRowSet,uno::UNO_QUERY);
1518 if ( !m_xRowSet.is() )
1520 m_xRowSet.set(xFactory->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.RowSet")),m_xContext),uno::UNO_QUERY);
1521 xRowSetProp.set(m_xRowSet,uno::UNO_QUERY);
1522 xRowSetProp->setPropertyValue(PROPERTY_ACTIVECONNECTION,uno::makeAny(xCon));
1523 ::comphelper::copyProperties(m_xReportComponent,xRowSetProp);
1526 // get a composer for the statement which the form is currently based on
1527 uno::Reference< sdb::XSingleSelectQueryComposer > xComposer( ::dbtools::getCurrentSettingsComposer( xRowSetProp, xServiceFactory ) );
1528 OSL_ENSURE( xComposer.is(), "GeometryHandler::impl_dialogFilter_nothrow: could not obtain a composer!" );
1529 if ( !xComposer.is() )
1530 return false;
1532 // create the dialog
1533 uno::Reference< ui::dialogs::XExecutableDialog > xDialog(xFactory->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.FilterDialog")),m_xContext),uno::UNO_QUERY);
1534 if ( !xDialog.is() )
1536 Window* pInspectorWindow = VCLUnoHelper::GetWindow( xInspectorWindow );
1537 ShowServiceNotAvailableError( pInspectorWindow, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.FilterDialog")), sal_True );
1538 return false;
1541 const String aGcc3WorkaroundTemporary( ModuleRes(RID_STR_FILTER));
1542 const ::rtl::OUString sPropertyUIName( aGcc3WorkaroundTemporary );
1543 // initialize the dialog
1544 uno::Reference< beans::XPropertySet > xDialogProps( xDialog, uno::UNO_QUERY_THROW );
1545 xDialogProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "QueryComposer" ) ), uno::makeAny( xComposer ) );
1546 xDialogProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RowSet" ) ), uno::makeAny( m_xRowSet ) );
1547 xDialogProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" ) ), uno::makeAny( xInspectorWindow ) );
1548 xDialogProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ), uno::makeAny( sPropertyUIName ) );
1550 _rClearBeforeDialog.clear();
1551 bSuccess = ( xDialog->execute() != 0 );
1552 if ( bSuccess )
1553 _out_rSelectedClause = xComposer->getFilter();
1555 catch (sdb::SQLContext& e) { aErrorInfo = e; }
1556 catch (sdbc::SQLWarning& e) { aErrorInfo = e; }
1557 catch (sdbc::SQLException& e) { aErrorInfo = e; }
1558 catch( const uno::Exception& )
1560 OSL_ENSURE( sal_False, "GeometryHandler::impl_dialogFilter_nothrow: caught an exception!" );
1563 if ( aErrorInfo.isValid() )
1564 ::dbtools::showError( aErrorInfo, xInspectorWindow, xServiceFactory );
1566 return bSuccess;
1568 // -----------------------------------------------------------------------------
1569 void GeometryHandler::checkPosAndSize( const awt::Point& _aNewPos,
1570 const awt::Size& _aSize)
1572 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY);
1573 const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY);
1574 if ( !xSection.is() || uno::Reference< report::XShape>(xSourceReportComponent,uno::UNO_QUERY).is() ) // shapes can overlap.
1575 return;
1577 ::Point aPos(VCLPoint(_aNewPos));
1578 if ( aPos.X() < 0 || aPos.Y() < 0 ) // TODO: have to check size with pos aka || (aPos.X() + aAwtSize.Width) > m_xSection->getReportDefinition()->
1579 throw beans::PropertyVetoException(String(ModuleRes(RID_STR_ILLEGAL_POSITION)),xSourceReportComponent);
1581 ::Rectangle aSourceRect(aPos,VCLSize(_aSize));
1583 const sal_Int32 nCount = xSection->getCount();
1584 for (sal_Int32 i = 0; i < nCount ; ++i)
1586 const uno::Reference< report::XReportComponent> xReportComponent(xSection->getByIndex(i),uno::UNO_QUERY);
1587 if ( xReportComponent.is() && xReportComponent != xSourceReportComponent )
1589 const ::Rectangle aBoundRect(VCLPoint(xReportComponent->getPosition()),VCLSize(xReportComponent->getSize()));
1590 const ::Rectangle aRect = aSourceRect.GetIntersection(aBoundRect);
1591 if ( !aRect.IsEmpty() && (aRect.Left() != aRect.Right() && aRect.Top() != aRect.Bottom() ) )
1592 throw beans::PropertyVetoException(String(ModuleRes( RID_STR_OVERLAP_OTHER_CONTROL)),xSourceReportComponent);
1596 // -----------------------------------------------------------------------------
1597 void GeometryHandler::impl_fillFormulaList_nothrow(::std::vector< ::rtl::OUString >& _out_rList) const
1599 if ( m_nDataFieldType == FUNCTION )
1600 ::std::transform(m_aDefaultFunctions.begin(),m_aDefaultFunctions.end(),::std::back_inserter(_out_rList),::boost::bind( &DefaultFunction::getName, _1 ));
1601 else if ( m_nDataFieldType == USER_DEF_FUNCTION )
1602 ::std::transform(m_aFunctionNames.begin(),m_aFunctionNames.end(),::std::back_inserter(_out_rList),::std::select1st<TFunctions::value_type>());
1604 // -----------------------------------------------------------------------------
1605 ::rtl::OUString GeometryHandler::impl_ConvertUIToMimeType_nothrow(const ::rtl::OUString& _sUIName) const
1607 ::std::vector< ::rtl::OUString > aList;
1608 impl_fillMimeTypes_nothrow(aList);
1609 ::rtl::OUString sRet;
1610 ::std::vector< ::rtl::OUString >::const_iterator aFind = ::std::find(aList.begin(),aList.end(),_sUIName);
1611 if ( aFind != aList.end() )
1613 const sal_Size nPos = aFind - aList.begin();
1614 const uno::Reference< report::XReportDefinition> xReportDefinition(m_xReportComponent,uno::UNO_QUERY);
1615 if ( xReportDefinition.is() )
1617 const uno::Sequence< ::rtl::OUString > aMimeTypes( xReportDefinition->getAvailableMimeTypes() );
1618 sRet = aMimeTypes[nPos];
1620 } // if ( aFind != aList.end() )
1621 return sRet;
1623 // -----------------------------------------------------------------------------
1624 ::rtl::OUString GeometryHandler::impl_ConvertMimeTypeToUI_nothrow(const ::rtl::OUString& _sMimetype) const
1626 uno::Reference<lang::XMultiServiceFactory> xServiceFactory(m_xContext->getServiceManager(),uno::UNO_QUERY_THROW);
1627 ::comphelper::MimeConfigurationHelper aMimeHelper(xServiceFactory);
1628 ::rtl::OUString sRet;
1629 const SfxFilter* pFilter = SfxFilter::GetDefaultFilter( aMimeHelper.GetDocServiceNameFromMediaType(_sMimetype) );
1630 if ( pFilter )
1631 sRet = pFilter->GetUIName();
1632 if ( !sRet.getLength() )
1633 sRet = _sMimetype;
1634 return sRet;
1636 // -----------------------------------------------------------------------------
1637 void GeometryHandler::impl_fillMimeTypes_nothrow(::std::vector< ::rtl::OUString >& _out_rList) const
1641 const uno::Reference< report::XReportDefinition> xReportDefinition(m_xReportComponent,uno::UNO_QUERY);
1642 if ( xReportDefinition.is() )
1644 uno::Sequence< ::rtl::OUString > aMimeTypes( xReportDefinition->getAvailableMimeTypes() );
1645 const ::rtl::OUString* pIter = aMimeTypes.getConstArray();
1646 const ::rtl::OUString* pEnd = pIter + aMimeTypes.getLength();
1647 for(;pIter != pEnd; ++pIter)
1649 const ::rtl::OUString sDocName( impl_ConvertMimeTypeToUI_nothrow(*pIter) );
1650 if ( sDocName.getLength() )
1651 _out_rList.push_back(sDocName);
1655 catch(uno::Exception&)
1657 OSL_ENSURE(0,"Exception caught!");
1660 // -----------------------------------------------------------------------------
1661 void GeometryHandler::impl_fillScopeList_nothrow(::std::vector< ::rtl::OUString >& _out_rList) const
1665 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY_THROW);
1666 const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY_THROW);
1668 const uno::Reference< report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
1669 const uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups();
1670 sal_Int32 nPos = -1;
1671 uno::Reference< report::XGroup> xGroup = xSection->getGroup();
1672 if ( xGroup.is() )
1673 nPos = getPositionInIndexAccess(xGroups.get(),xGroup);
1674 else if ( xSection == xReportDefinition->getDetail() )
1675 nPos = xGroups->getCount()-1;
1677 const String sGroup = String(ModuleRes(RID_STR_SCOPE_GROUP));
1678 for (sal_Int32 i = 0 ; i <= nPos ; ++i)
1680 xGroup.set(xGroups->getByIndex(i),uno::UNO_QUERY_THROW);
1681 String sGroupName = sGroup;
1682 sGroupName.SearchAndReplaceAscii("%1",xGroup->getExpression());
1683 _out_rList.push_back(sGroupName);
1685 _out_rList.push_back(xReportDefinition->getName());
1687 catch(uno::Exception&)
1689 OSL_ENSURE(0,"Exception caught!");
1692 // -----------------------------------------------------------------------------
1693 uno::Reference< report::XFunctionsSupplier> GeometryHandler::fillScope_throw(::rtl::OUString& _rsNamePostFix)
1695 uno::Reference< report::XFunctionsSupplier> xReturn;
1697 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY_THROW);
1698 const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY_THROW);
1699 const uno::Reference< report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
1700 if ( !m_sScope.getLength() )
1702 const uno::Reference< report::XGroup> xGroup(xSection->getGroup(),uno::UNO_QUERY);
1703 if ( xGroup.is() )
1705 String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP));
1706 _rsNamePostFix = xGroup->getExpression();
1707 sGroupName.SearchAndReplaceAscii("%1",_rsNamePostFix);
1708 m_sScope = sGroupName;
1709 xReturn = xGroup.get();
1711 else if ( xSection == xReportDefinition->getDetail() )
1713 const uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups();
1714 const sal_Int32 nCount = xGroups->getCount();
1715 if ( nCount )
1717 const uno::Reference< report::XGroup> xGroup2(xGroups->getByIndex(nCount - 1),uno::UNO_QUERY_THROW);
1718 String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP));
1719 _rsNamePostFix = xGroup2->getExpression();
1720 sGroupName.SearchAndReplaceAscii("%1",_rsNamePostFix);
1721 m_sScope = sGroupName;
1722 xReturn = xGroup2.get();
1725 if ( !m_sScope.getLength() )
1727 xReturn = xReportDefinition.get();
1728 _rsNamePostFix = m_sScope = xReportDefinition->getName();
1731 else if ( m_sScope == xReportDefinition->getName() )
1733 xReturn = xReportDefinition.get();
1734 _rsNamePostFix = m_sScope;
1736 else
1738 uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups();
1739 const sal_Int32 nCount = xGroups->getCount();
1741 for (sal_Int32 i = 0 ; i < nCount; ++i)
1743 const uno::Reference< report::XGroup> xGroup(xGroups->getByIndex(i),uno::UNO_QUERY_THROW);
1744 String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP));
1745 sGroupName.SearchAndReplaceAscii("%1",xGroup->getExpression());
1746 if ( m_sScope == ::rtl::OUString(sGroupName) )
1748 _rsNamePostFix = xGroup->getExpression();
1749 xReturn = xGroup.get();
1750 break;
1755 OSL_ENSURE(xReturn.is(),"Why don't we have a functionssupplier here!");
1757 return xReturn;
1759 // -----------------------------------------------------------------------------
1760 sal_Bool GeometryHandler::isDefaultFunction( const ::rtl::OUString& _sQuotedFunction
1761 ,::rtl::OUString& _rDataField
1762 ,const uno::Reference< report::XFunctionsSupplier>& _xFunctionsSupplier
1763 ,bool _bSet) const
1765 sal_Bool bDefaultFunction = sal_False;
1768 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY_THROW);
1769 const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY_THROW);
1770 const uno::Reference< report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
1772 ::std::pair<TFunctions::const_iterator,TFunctions::const_iterator> aFind = m_aFunctionNames.equal_range(_sQuotedFunction);
1773 while ( aFind.first != aFind.second )
1775 if ( !_xFunctionsSupplier.is() || _xFunctionsSupplier == aFind.first->second.second )
1777 const beans::Optional< ::rtl::OUString> aInitalFormula = aFind.first->second.first->getInitialFormula();
1778 if ( aInitalFormula.IsPresent )
1780 ::rtl::OUString sDefaultFunctionName;
1781 bDefaultFunction = impl_isDefaultFunction_nothrow(aFind.first->second.first,_rDataField,sDefaultFunctionName);
1782 if ( bDefaultFunction )
1784 m_xFunction = aFind.first->second.first;
1785 if ( _bSet )
1787 m_sDefaultFunction = sDefaultFunctionName;
1788 uno::Reference< report::XGroup> xGroup(aFind.first->second.second,uno::UNO_QUERY);
1789 if ( xGroup.is() )
1791 String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP));
1792 sGroupName.SearchAndReplaceAscii("%1",xGroup->getExpression());
1793 m_sScope = sGroupName;
1795 else
1796 m_sScope = xReportDefinition->getName();
1799 break;
1802 ++(aFind.first);
1805 catch(uno::Exception&)
1807 OSL_ENSURE(0,"Exception caught!");
1809 return bDefaultFunction;
1811 // -----------------------------------------------------------------------------
1812 sal_Bool GeometryHandler::impl_isDefaultFunction_nothrow( const uno::Reference< report::XFunction>& _xFunction
1813 ,::rtl::OUString& _rDataField
1814 ,::rtl::OUString& _rsDefaultFunctionName) const
1816 sal_Bool bDefaultFunction = sal_False;
1819 const String sFormula( _xFunction->getFormula() );
1820 util::SearchOptions aSearchOptions;
1821 aSearchOptions.algorithmType = util::SearchAlgorithms_REGEXP;
1822 aSearchOptions.searchFlag = 0x00000100;
1823 ::std::vector< DefaultFunction >::const_iterator aIter = m_aDefaultFunctions.begin();
1824 ::std::vector< DefaultFunction >::const_iterator aDeEnd = m_aDefaultFunctions.end();
1825 for (; aIter != aDeEnd; ++aIter)
1827 aSearchOptions.searchString = aIter->m_sSearchString;
1828 utl::TextSearch aTextSearch(aSearchOptions);
1829 xub_StrLen start = 0;
1830 xub_StrLen end = sFormula.Len();
1831 if ( aTextSearch.SearchFrwrd(sFormula,&start,&end) && start == 0 && end == sFormula.Len()) // default function found
1833 aSearchOptions.searchString = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]"));
1834 utl::TextSearch aDataSearch(aSearchOptions);
1835 aDataSearch.SearchFrwrd(sFormula,&start,&end );
1836 ++start;
1837 _rDataField = sFormula.Copy(start,end-start-1);
1838 _rsDefaultFunctionName = aIter->m_sName;
1839 break;
1843 bDefaultFunction = aIter != aDeEnd;
1845 catch(uno::Exception&)
1847 OSL_ENSURE(0,"Exception caught!");
1849 return bDefaultFunction;
1851 // -----------------------------------------------------------------------------
1852 void GeometryHandler::loadDefaultFunctions()
1854 if ( m_aDefaultFunctions.empty() )
1856 m_aCounterFunction.m_bPreEvaluated = sal_False;
1857 m_aCounterFunction.m_bDeepTraversing = sal_False;
1858 m_aCounterFunction.m_sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Counter"));
1859 m_aCounterFunction.m_sFormula = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:[%FunctionName] + 1"));
1860 m_aCounterFunction.m_sSearchString = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:\\[[:alpha:]+([:space:]*[:alnum:]*)*\\][:space:]*\\+[:space:]*[:digit:]*"));
1861 m_aCounterFunction.m_sInitialFormula.IsPresent = sal_True;
1862 m_aCounterFunction.m_sInitialFormula.Value = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:1"));
1864 DefaultFunction aDefault;
1865 aDefault.m_bDeepTraversing = sal_False;
1867 //aDefault.m_sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Counter"));
1868 //aDefault.m_sFormula = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:[%FunctionName] + 1"));
1869 //aDefault.m_sSearchString = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:\\[[:alpha:]+[:alnum:]*\\][:space:]*\\+[:space:]*1"));
1870 //aDefault.m_sInitialFormula.IsPresent = sal_True;
1871 //aDefault.m_sInitialFormula.Value = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:1"));
1872 //m_aDefaultFunctions.push_back(aDefault);
1874 aDefault.m_bPreEvaluated = sal_True;
1876 aDefault.m_sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Accumulation"));
1877 aDefault.m_sFormula = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:[%Column] + [%FunctionName]"));
1878 aDefault.m_sSearchString = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:\\[[:alpha:]+([:space:]*[:alnum:]*)*\\][:space:]*\\+[:space:]*\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]"));
1879 aDefault.m_sInitialFormula.IsPresent = sal_True;
1880 aDefault.m_sInitialFormula.Value = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:[%Column]"));
1881 m_aDefaultFunctions.push_back(aDefault);
1883 aDefault.m_sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Minimum"));
1884 aDefault.m_sFormula = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:IF([%Column] < [%FunctionName];[%Column];[%FunctionName])"));
1885 aDefault.m_sSearchString = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:IF\\((\\[[:alpha:]+([:space:]*[:alnum:]*)*\\])[:space:]*<[:space:]*(\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]);[:space:]*\\1[:space:]*;[:space:]*\\3[:space:]*\\)"));
1886 aDefault.m_sInitialFormula.IsPresent = sal_True;
1887 aDefault.m_sInitialFormula.Value = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:[%Column]"));
1888 m_aDefaultFunctions.push_back(aDefault);
1890 aDefault.m_sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Maximum"));
1891 aDefault.m_sFormula = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:IF([%Column] > [%FunctionName];[%Column];[%FunctionName])"));
1892 aDefault.m_sSearchString = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:IF\\((\\[[:alpha:]+([:space:]*[:alnum:]*)*\\])[:space:]*>[:space:]*(\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]);[:space:]*\\1[:space:]*;[:space:]*\\3[:space:]*\\)"));
1893 aDefault.m_sInitialFormula.IsPresent = sal_True;
1894 aDefault.m_sInitialFormula.Value = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:[%Column]"));
1895 m_aDefaultFunctions.push_back(aDefault);
1898 // -----------------------------------------------------------------------------
1899 void GeometryHandler::createDefaultFunction(::osl::ResettableMutexGuard& _aGuard ,const ::rtl::OUString& _sFunction,const ::rtl::OUString& _sDataField)
1903 ::rtl::OUString sNamePostFix;
1904 const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostFix);
1906 ::std::vector< DefaultFunction >::const_iterator aIter = m_aDefaultFunctions.begin();
1907 ::std::vector< DefaultFunction >::const_iterator aDeEnd = m_aDefaultFunctions.end();
1908 for (; aIter != aDeEnd; ++aIter)
1910 if ( aIter->m_sName == _sFunction )
1912 const ::rtl::OUString sFunctionName( _sFunction + _sDataField + sNamePostFix);
1913 const ::rtl::OUString sQuotedFunctionName(lcl_getQuotedFunctionName(sFunctionName));
1915 beans::PropertyChangeEvent aEvent;
1916 aEvent.PropertyName = PROPERTY_SCOPE;
1917 aEvent.OldValue <<= m_sScope;
1919 ::std::pair<TFunctions::const_iterator,TFunctions::const_iterator> aFind = m_aFunctionNames.equal_range(sQuotedFunctionName);
1920 while ( aFind.first != aFind.second )
1922 if ( xFunctionsSupplier == aFind.first->second.second )
1924 m_xFunction = aFind.first->second.first;
1925 ::rtl::OUString sTemp;
1926 isDefaultFunction(sQuotedFunctionName,sTemp,uno::Reference< report::XFunctionsSupplier>(),true); // implicitly sets the m_sScope
1927 break;
1929 ++(aFind.first);
1931 if ( aFind.first == aFind.second )
1932 impl_createFunction(sFunctionName,_sDataField,*aIter);
1934 OBlocker aBlocker(m_bIn);
1935 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny( impl_convertToFormula( uno::makeAny(sQuotedFunctionName) )));
1936 aEvent.NewValue <<= m_sScope;
1937 _aGuard.clear();
1938 m_aPropertyListeners.notify( aEvent, &beans::XPropertyChangeListener::propertyChange );
1939 break;
1943 catch(uno::Exception&)
1945 OSL_ENSURE(0,"Exception caught!");
1948 // -----------------------------------------------------------------------------
1949 void GeometryHandler::removeFunction()
1951 if ( m_xFunction.is() )
1953 const ::rtl::OUString sQuotedFunctionName(lcl_getQuotedFunctionName(m_xFunction));
1954 ::std::pair<TFunctions::iterator,TFunctions::iterator> aFind = m_aFunctionNames.equal_range(sQuotedFunctionName);
1955 while ( aFind.first != aFind.second )
1957 if ( aFind.first->second.first == m_xFunction )
1959 uno::Reference< report::XFunctions> xFunctions = aFind.first->second.second->getFunctions();
1960 xFunctions->removeByIndex(xFunctions->getCount() - 1 ); /// TODO: insert new method in XFunctions: removeFunction(xfunction)
1961 m_aFunctionNames.erase(aFind.first);
1962 m_bNewFunction = false;
1963 break;
1965 ++(aFind.first);
1969 // -----------------------------------------------------------------------------
1970 void GeometryHandler::resetOwnProperties(::osl::ResettableMutexGuard& _aGuard,const ::rtl::OUString& _sOldFunctionName,const ::rtl::OUString& _sOldScope,const sal_uInt32 _nOldDataFieldType)
1972 const ::rtl::OUString sNewFunction = m_sDefaultFunction;
1973 const ::rtl::OUString sNewScope = m_sScope;
1974 const sal_uInt32 nNewDataFieldType = m_nDataFieldType;
1975 _aGuard.clear();
1976 if ( _nOldDataFieldType != nNewDataFieldType )
1978 beans::PropertyChangeEvent aScopeEvent;
1979 aScopeEvent.PropertyName = PROPERTY_TYPE;
1980 aScopeEvent.OldValue <<= _nOldDataFieldType;
1981 aScopeEvent.NewValue <<= nNewDataFieldType;
1982 m_aPropertyListeners.notify( aScopeEvent, &beans::XPropertyChangeListener::propertyChange );
1984 if ( _sOldFunctionName != sNewFunction )
1986 beans::PropertyChangeEvent aFormulaEvent;
1987 aFormulaEvent.PropertyName = PROPERTY_FORMULALIST;
1988 aFormulaEvent.OldValue <<= _sOldFunctionName;
1989 aFormulaEvent.NewValue <<= sNewFunction;
1991 m_aPropertyListeners.notify( aFormulaEvent, &beans::XPropertyChangeListener::propertyChange );
1993 if ( _sOldScope != sNewScope )
1995 beans::PropertyChangeEvent aScopeEvent;
1996 aScopeEvent.PropertyName = PROPERTY_SCOPE;
1997 aScopeEvent.OldValue <<= _sOldScope;
1998 aScopeEvent.NewValue <<= sNewScope;
1999 m_aPropertyListeners.notify( aScopeEvent, &beans::XPropertyChangeListener::propertyChange );
2002 _aGuard.reset();
2004 //------------------------------------------------------------------------
2005 void GeometryHandler::impl_initFieldList_nothrow( uno::Sequence< ::rtl::OUString >& _rFieldNames ) const
2007 _rFieldNames.realloc(0);
2010 uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DialogParentWindow"))) ,uno::UNO_QUERY);
2011 Window* pInspectorWindow = VCLUnoHelper::GetWindow( xInspectorWindow );
2012 WaitObject aWaitCursor( pInspectorWindow );
2014 uno::Reference< sdbc::XPreparedStatement > xStatement;
2016 // get the form of the control we're inspecting
2017 uno::Reference< beans::XPropertySet > xFormSet( m_xRowSet, uno::UNO_QUERY );
2018 if ( !xFormSet.is() )
2019 return;
2021 ::rtl::OUString sObjectName;
2022 OSL_VERIFY( xFormSet->getPropertyValue( PROPERTY_COMMAND ) >>= sObjectName );
2023 // when there is no command we don't need to ask for columns
2024 uno::Reference<sdbc::XConnection> xCon(m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ActiveConnection"))) ,uno::UNO_QUERY);
2025 if ( sObjectName.getLength() && xCon.is() )
2027 sal_Int32 nObjectType = sdb::CommandType::COMMAND;
2028 OSL_VERIFY( xFormSet->getPropertyValue( PROPERTY_COMMANDTYPE ) >>= nObjectType );
2030 _rFieldNames = ::dbtools::getFieldNamesByCommandDescriptor( xCon, nObjectType, sObjectName );
2033 catch (uno::Exception&)
2035 DBG_ERROR( "GeometryHandler::impl_initFieldList_nothrow: caught an exception!" );
2038 // -----------------------------------------------------------------------------
2039 bool GeometryHandler::impl_isCounterFunction_throw(const ::rtl::OUString& _sQuotedFunctionName,::rtl::OUString& _Out_sScope) const
2041 ::std::pair<TFunctions::const_iterator,TFunctions::const_iterator> aFind = m_aFunctionNames.equal_range(_sQuotedFunctionName);
2042 while ( aFind.first != aFind.second )
2044 const beans::Optional< ::rtl::OUString> aInitalFormula = aFind.first->second.first->getInitialFormula();
2045 if ( aInitalFormula.IsPresent )
2047 const String sFormula( aFind.first->second.first->getFormula() );
2048 util::SearchOptions aSearchOptions;
2049 aSearchOptions.algorithmType = util::SearchAlgorithms_REGEXP;
2050 aSearchOptions.searchFlag = 0x00000100;
2051 aSearchOptions.searchString = m_aCounterFunction.m_sSearchString;
2052 utl::TextSearch aTextSearch(aSearchOptions);
2053 xub_StrLen start = 0;
2054 xub_StrLen end = sFormula.Len();
2055 if ( aTextSearch.SearchFrwrd(sFormula,&start,&end) && start == 0 && end == sFormula.Len()) // counter function found
2057 const uno::Reference< report::XGroup > xGroup(aFind.first->second.second,uno::UNO_QUERY);
2058 if ( xGroup.is() )
2060 String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP));
2061 sGroupName.SearchAndReplaceAscii("%1",xGroup->getExpression());
2062 _Out_sScope = sGroupName;
2064 else
2065 _Out_sScope = uno::Reference< report::XReportDefinition >(aFind.first->second.second,uno::UNO_QUERY_THROW)->getName();
2066 break;
2069 ++(aFind.first);
2071 return aFind.first != aFind.second;
2073 // -----------------------------------------------------------------------------
2074 void GeometryHandler::impl_createFunction(const ::rtl::OUString& _sFunctionName,const ::rtl::OUString& _sDataField,const DefaultFunction& _aFunction)
2076 if ( m_bNewFunction )
2077 removeFunction();
2079 const ::rtl::OUString sQuotedFunctionName(lcl_getQuotedFunctionName(_sFunctionName));
2080 m_xFunction.set(report::Function::create(m_xContext));
2081 m_xFunction->setName( _sFunctionName );
2083 const String sPlaceHolder1(RTL_CONSTASCII_USTRINGPARAM("%Column"));
2084 const String sPlaceHolder2(RTL_CONSTASCII_USTRINGPARAM("%FunctionName"));
2085 String sFormula(_aFunction.m_sFormula);
2086 sFormula.SearchAndReplaceAll(sPlaceHolder1,_sDataField);
2087 sFormula.SearchAndReplaceAll(sPlaceHolder2,_sFunctionName);
2089 m_xFunction->setFormula(sFormula);
2090 m_xFunction->setPreEvaluated(_aFunction.m_bPreEvaluated);
2091 m_xFunction->setDeepTraversing(_aFunction.m_bDeepTraversing);
2092 if ( _aFunction.m_sInitialFormula.IsPresent )
2094 beans::Optional< ::rtl::OUString> aInitialFormula = _aFunction.m_sInitialFormula;
2095 String sInitialFormula = aInitialFormula.Value;
2096 sInitialFormula.SearchAndReplaceAll(sPlaceHolder1,_sDataField);
2097 sInitialFormula.SearchAndReplaceAll(sPlaceHolder2,_sFunctionName);
2098 aInitialFormula.Value = sInitialFormula;
2099 m_xFunction->setInitialFormula( aInitialFormula );
2101 ::rtl::OUString sNamePostFix;
2102 const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostFix);
2103 const uno::Reference< container::XIndexContainer> xFunctions(xFunctionsSupplier->getFunctions(),uno::UNO_QUERY_THROW);
2104 xFunctions->insertByIndex(xFunctions->getCount(),uno::makeAny(m_xFunction));
2105 m_aFunctionNames.insert(TFunctions::value_type(sQuotedFunctionName,TFunctionPair(m_xFunction,xFunctionsSupplier)));
2106 m_bNewFunction = true;
2108 // -----------------------------------------------------------------------------
2109 void GeometryHandler::impl_setCounterFunction_throw()
2111 ::rtl::OUString sNamePostFix;
2112 fillScope_throw(sNamePostFix);
2113 ::rtl::OUString sFunctionName = m_aCounterFunction.m_sName;
2114 sFunctionName += sNamePostFix;
2115 const ::rtl::OUString sQuotedFunctionName = lcl_getQuotedFunctionName(sFunctionName);
2116 ::rtl::OUString sScope;
2117 if ( !(sFunctionName.getLength() && m_aFunctionNames.find(sQuotedFunctionName) != m_aFunctionNames.end() && impl_isCounterFunction_throw(sQuotedFunctionName,sScope)) )
2118 impl_createFunction(sFunctionName,::rtl::OUString(),m_aCounterFunction);
2120 OBlocker aBlocker(m_bIn);
2121 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(impl_convertToFormula( uno::makeAny(sQuotedFunctionName))));
2123 // -----------------------------------------------------------------------------
2124 sal_uInt32 GeometryHandler::impl_getDataFieldType_throw(const ::rtl::OUString& _sDataField) const
2126 sal_uInt32 nDataFieldType = UNDEF_DATA;
2127 ::rtl::OUString sDataField;
2128 if ( _sDataField.getLength() )
2129 sDataField = _sDataField;
2130 else
2132 uno::Any aDataField( m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD ) );
2133 lcl_convertFormulaTo(aDataField,aDataField);
2134 aDataField >>= sDataField;
2137 if ( sDataField.getLength() )
2139 if ( impl_isDataField(sDataField) )
2140 nDataFieldType = DATA_OR_FORMULA;
2141 else if ( isDefaultFunction(sDataField,sDataField) )
2142 nDataFieldType = FUNCTION;
2143 else if ( m_aFunctionNames.find(sDataField) != m_aFunctionNames.end() )
2145 nDataFieldType = USER_DEF_FUNCTION;
2146 ::rtl::OUString sScope;
2147 if ( impl_isCounterFunction_throw(sDataField,sScope) )
2148 nDataFieldType = COUNTER;
2150 else
2151 nDataFieldType = DATA_OR_FORMULA;
2153 return nDataFieldType;
2155 // -----------------------------------------------------------------------------
2156 // XEventListener
2157 void SAL_CALL GeometryHandler::disposing(const lang::EventObject& ) throw( uno::RuntimeException )
2160 // XPropertyChangeListener
2161 void SAL_CALL GeometryHandler::propertyChange(const beans::PropertyChangeEvent& /*evt*/) throw(uno::RuntimeException)
2163 ::osl::ResettableMutexGuard aGuard( m_aMutex );
2164 if ( !m_bIn )
2166 const sal_uInt32 nOldDataFieldType = m_nDataFieldType;
2167 const ::rtl::OUString sOldFunctionName = m_sDefaultFunction;
2168 const ::rtl::OUString sOldScope = m_sScope;
2169 m_sDefaultFunction = m_sScope = ::rtl::OUString();
2170 m_nDataFieldType = impl_getDataFieldType_throw();
2171 if ( UNDEF_DATA == m_nDataFieldType )
2172 m_nDataFieldType = nOldDataFieldType;
2173 uno::Any aDataField = m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD );
2174 lcl_convertFormulaTo(aDataField,aDataField);
2175 ::rtl::OUString sDataField;
2176 aDataField >>= sDataField;
2177 switch(m_nDataFieldType)
2179 case FUNCTION:
2180 isDefaultFunction(sDataField,sDataField,uno::Reference< report::XFunctionsSupplier>(),true);
2181 break;
2182 case COUNTER:
2183 impl_isCounterFunction_throw(sDataField,m_sScope);
2184 break;
2185 default:
2189 resetOwnProperties(aGuard,sOldFunctionName,sOldScope,nOldDataFieldType);
2192 //........................................................................
2193 } // namespace rptui
2194 //........................................................................