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