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