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