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.notifyEach( &beans::XPropertyChangeListener::propertyChange, aEvent );
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 TranslateId* pResId
638  ,bool _bReadOnlyControl
639  ,bool _bTrueIfListBoxFalseIfComboBox
640  )
641 {
642  std::vector<OUString> aList;
643  for (const TranslateId* 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 TranslateId* 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 TranslateId* pResId,const uno::Any& _aValue,const OUString& _sConstantName,const OUString & PropertyName )
896 {
897  std::vector<OUString> aList;
898  for (const TranslateId* pItem = pResId; *pItem; ++pItem)
899  aList.push_back(RptResId(*pItem));
900  uno::Sequence< OUString > aSeq(aList.size());
901  auto aSeqRange = asNonConstRange(aSeq);
902  for (size_t i = 0; i < aList.size(); ++i)
903  aSeqRange[i] = aList[i];
904 
905  uno::Reference< inspection::XStringRepresentation > xConversionHelper = inspection::StringRepresentation::createConstant( m_xContext,m_xTypeConverter,_sConstantName,aSeq);
906  if ( _bToControlValue )
907  {
908  return uno::makeAny( xConversionHelper->convertToControlValue( _aValue ) );
909  }
910  else
911  {
912  OUString sControlValue;
913  _aValue >>= sControlValue;
914  const beans::Property aProp = getProperty(PropertyName);
915  return xConversionHelper->convertToPropertyValue( sControlValue, aProp.Type );
916  }
917 }
918 
919 uno::Any SAL_CALL GeometryHandler::convertToPropertyValue(const OUString & PropertyName, const uno::Any & _rControlValue)
920 {
921  ::osl::MutexGuard aGuard( m_aMutex );
922  uno::Any aPropertyValue( _rControlValue );
923  const sal_Int32 nId = OPropertyInfoService::getPropertyId(PropertyName);
924  switch(nId)
925  {
928  aPropertyValue = getConstantValue(false,RID_STR_FORCENEWPAGE_CONST,_rControlValue,"com.sun.star.report.ForceNewPage",PropertyName);
929  break;
931  aPropertyValue = getConstantValue(false,RID_STR_GROUPKEEPTOGETHER_CONST,_rControlValue,"com.sun.star.report.GroupKeepTogether",PropertyName);
932  break;
935  aPropertyValue = getConstantValue(false,RID_STR_REPORTPRINTOPTION_CONST,_rControlValue,"com.sun.star.report.ReportPrintOption",PropertyName);
936  break;
939  if ( !_rControlValue.hasValue() )
940  {
941  aPropertyValue <<= COL_TRANSPARENT;
942  break;
943  }
944  [[fallthrough]];
945 
947  if ( uno::Reference< report::XGroup>(m_xReportComponent,uno::UNO_QUERY).is())
948  {
949  aPropertyValue = getConstantValue(false,RID_STR_KEEPTOGETHER_CONST,_rControlValue,"com.sun.star.report.KeepTogether",PropertyName);
950  break;
951  }
952  [[fallthrough]];
953 
954  case PROPERTY_ID_VISIBLE:
955  case PROPERTY_ID_CANGROW:
967  {
968  if ( aPropertyValue.hasValue() )
969  {
970  const beans::Property aProp = getProperty(PropertyName);
971  if ( aPropertyValue.getValueType().equals( aProp.Type ) )
972  // nothing to do, type is already as desired
973  return aPropertyValue;
974 
975  if ( _rControlValue.getValueType().getTypeClass() == uno::TypeClass_STRING )
976  {
977  OUString sControlValue;
978  _rControlValue >>= sControlValue;
979 
980  const uno::Reference< inspection::XStringRepresentation > xConversionHelper = inspection::StringRepresentation::create( m_xContext,m_xTypeConverter );
981  aPropertyValue = xConversionHelper->convertToPropertyValue( sControlValue, aProp.Type );
982  }
983  else
984  {
985  try
986  {
987  aPropertyValue = m_xTypeConverter->convertTo( _rControlValue, aProp.Type );
988  }
989  catch( const uno::Exception& )
990  {
991  TOOLS_WARN_EXCEPTION( "reportdesign", "GeometryHandler::convertToPropertyValue: caught an exception while converting via TypeConverter!" );
992  }
993  }
994  }
995 
996  break;
997  }
1000  case PROPERTY_ID_FORMULA:
1001  return uno::makeAny( impl_convertToFormula( _rControlValue ) );
1002  case PROPERTY_ID_DATAFIELD:
1003  {
1004  OUString sDataField;
1005  _rControlValue >>= sDataField;
1006  if ( isDefaultFunction(sDataField,sDataField) )
1007  {
1008  OSL_ENSURE(m_xFunction.is(),"No function set!");
1009  aPropertyValue <<= impl_convertToFormula( uno::makeAny(lcl_getQuotedFunctionName(m_xFunction)) );
1010  }
1011  else
1012  aPropertyValue <<= impl_convertToFormula( _rControlValue );
1013  }
1014  break;
1015  case PROPERTY_ID_POSITIONX:
1016  {
1017  aPropertyValue = m_xFormComponentHandler->convertToPropertyValue(PropertyName, _rControlValue);
1018  sal_Int32 nPosX = 0;
1019  aPropertyValue >>= nPosX;
1020  const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY);
1021  if ( xSourceReportComponent->getSection().is() )
1022  nPosX += getStyleProperty<sal_Int32>(xSourceReportComponent->getSection()->getReportDefinition(),PROPERTY_LEFTMARGIN);
1023  aPropertyValue <<= nPosX;
1024  }
1025  break;
1026  case PROPERTY_ID_FONT:
1027  aPropertyValue = m_xFormComponentHandler->convertToPropertyValue(PROPERTY_FONT, _rControlValue);
1028  break;
1029  case PROPERTY_ID_SCOPE:
1031  case PROPERTY_ID_AREA:
1032  aPropertyValue = _rControlValue;
1033  break;
1034  case PROPERTY_ID_TYPE:
1035  {
1036  OUString sValue;
1037  _rControlValue >>= sValue;
1038 
1039  sal_uInt32 nFound(RESARRAY_INDEX_NOTFOUND);
1040  sal_uInt32 i = 0;
1041  for (const TranslateId* pItem = RID_STR_TYPE_CONST; *pItem; ++pItem)
1042  {
1043  if (sValue == RptResId(*pItem))
1044  {
1045  nFound = i;
1046  break;
1047  }
1048  ++i;
1049  }
1050  if (nFound != RESARRAY_INDEX_NOTFOUND)
1051  aPropertyValue <<= nFound;
1052  }
1053  break;
1054  case PROPERTY_ID_MIMETYPE:
1055  aPropertyValue = _rControlValue;
1056  break;
1058  {
1059  OUString sValue;
1060  _rControlValue >>= sValue;
1061 
1062  sal_uInt32 nFound(RESARRAY_INDEX_NOTFOUND);
1063  sal_uInt32 i = 0;
1064  for (const TranslateId* pItem = RID_STR_VERTICAL_ALIGN_CONST; *pItem; ++pItem)
1065  {
1066  if (sValue == RptResId(*pItem))
1067  {
1068  nFound = i;
1069  break;
1070  }
1071  ++i;
1072  }
1073  if (nFound != RESARRAY_INDEX_NOTFOUND)
1074  aPropertyValue <<= static_cast<style::VerticalAlignment>(nFound);
1075  }
1076  break;
1078  {
1079  OUString sValue;
1080  _rControlValue >>= sValue;
1081 
1082  sal_uInt32 nFound(RESARRAY_INDEX_NOTFOUND);
1083  sal_uInt32 i = 0;
1084  for (const TranslateId* pItem = RID_STR_PARAADJUST_CONST; *pItem; ++pItem)
1085  {
1086  if (sValue == RptResId(*pItem))
1087  {
1088  nFound = i;
1089  break;
1090  }
1091  ++i;
1092  }
1093 
1094  if (nFound != RESARRAY_INDEX_NOTFOUND)
1095  aPropertyValue <<= static_cast<sal_Int16>(nFound);
1096  }
1097  break;
1098  default:
1099  return m_xFormComponentHandler->convertToPropertyValue(PropertyName, _rControlValue);
1100  }
1101  return aPropertyValue;
1102 }
1103 
1104 uno::Any SAL_CALL GeometryHandler::convertToControlValue(const OUString & PropertyName, const uno::Any & _rPropertyValue, const uno::Type & _rControlValueType)
1105 {
1106  uno::Any aControlValue( _rPropertyValue );
1107  if ( !aControlValue.hasValue() )
1108  // NULL is converted to NULL
1109  return aControlValue;
1110 
1111  uno::Any aPropertyValue(_rPropertyValue);
1112 
1113  ::osl::MutexGuard aGuard( m_aMutex );
1114  const sal_Int32 nId = OPropertyInfoService::getPropertyId(PropertyName);
1115  switch(nId)
1116  {
1117  case PROPERTY_ID_AREA:
1118  break;
1121  aControlValue = getConstantValue(true,RID_STR_FORCENEWPAGE_CONST,aPropertyValue,"com.sun.star.report.ForceNewPage",PropertyName);
1122  break;
1124  aControlValue = getConstantValue(true,RID_STR_GROUPKEEPTOGETHER_CONST,aPropertyValue,"com.sun.star.report.GroupKeepTogether",PropertyName);
1125  break;
1128  aControlValue = getConstantValue(true,RID_STR_REPORTPRINTOPTION_CONST,aPropertyValue,"com.sun.star.report.ReportPrintOption",PropertyName);
1129  break;
1131  if ( uno::Reference< report::XGroup>(m_xReportComponent,uno::UNO_QUERY).is())
1132  {
1133  aControlValue = getConstantValue(true,RID_STR_KEEPTOGETHER_CONST,aPropertyValue,"com.sun.star.report.KeepTogether",PropertyName);
1134  break;
1135  }
1136  [[fallthrough]];
1137  case PROPERTY_ID_VISIBLE:
1138  case PROPERTY_ID_CANGROW:
1139  case PROPERTY_ID_CANSHRINK:
1150  {
1151  if ( _rControlValueType.getTypeClass() == uno::TypeClass_STRING )
1152  {
1153  const uno::Reference< inspection::XStringRepresentation > xConversionHelper = inspection::StringRepresentation::create( m_xContext,m_xTypeConverter );
1154  aControlValue <<= xConversionHelper->convertToControlValue( aPropertyValue );
1155  }
1156  else
1157  {
1158  try
1159  {
1160  aControlValue = m_xTypeConverter->convertTo( aPropertyValue, _rControlValueType );
1161  }
1162  catch( const uno::Exception& )
1163  {
1164  TOOLS_WARN_EXCEPTION( "reportdesign", "GeometryHandler::convertToControlValue: caught an exception while converting via TypeConverter!" );
1165  }
1166  }
1167  break;
1168  }
1171  case PROPERTY_ID_FORMULA:
1172  lcl_convertFormulaTo(aPropertyValue,aControlValue);
1173  break;
1174  case PROPERTY_ID_DATAFIELD:
1175  {
1176  OUString sValue;
1177  aControlValue >>= sValue;
1178  if ( isDefaultFunction(sValue,sValue) )
1179  aControlValue <<= sValue;
1180  else
1181  lcl_convertFormulaTo(aPropertyValue,aControlValue);
1182  }
1183  break;
1184  case PROPERTY_ID_FONT:
1185  aControlValue = m_xFormComponentHandler->convertToControlValue(PROPERTY_FONT, aPropertyValue, _rControlValueType);
1186  break;
1187  case PROPERTY_ID_POSITIONX:
1188  {
1189  sal_Int32 nPosX = 0;
1190  aPropertyValue >>= nPosX;
1191  const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY);
1192  if ( xSourceReportComponent->getSection().is() )
1193  nPosX -= getStyleProperty<sal_Int32>(xSourceReportComponent->getSection()->getReportDefinition(),PROPERTY_LEFTMARGIN);
1194  aPropertyValue <<= nPosX;
1195  aControlValue = m_xFormComponentHandler->convertToControlValue(PropertyName, aPropertyValue, _rControlValueType);
1196  }
1197  break;
1199  aControlValue <<= m_sDefaultFunction;
1200  break;
1201  case PROPERTY_ID_SCOPE:
1202  aControlValue <<= m_sScope;
1203  break;
1204  case PROPERTY_ID_MIMETYPE:
1205  aControlValue = aPropertyValue;
1206  break;
1207  case PROPERTY_ID_TYPE:
1208  {
1209  if (m_nDataFieldType < SAL_N_ELEMENTS(RID_STR_TYPE_CONST) - 1)
1210  aControlValue <<= RptResId(RID_STR_TYPE_CONST[m_nDataFieldType]);
1211  }
1212  break;
1214  {
1215  style::VerticalAlignment nParagraphVertAlign = style::VerticalAlignment_TOP;
1216  aPropertyValue >>= nParagraphVertAlign;
1217  if (sal_uInt32(nParagraphVertAlign) < SAL_N_ELEMENTS(RID_STR_VERTICAL_ALIGN_CONST) - 1)
1218  aControlValue <<= RptResId(RID_STR_VERTICAL_ALIGN_CONST[static_cast<sal_uInt32>(nParagraphVertAlign)]);
1219  }
1220  break;
1222  {
1223  sal_Int16 nParagraphAdjust = sal_Int16(style::ParagraphAdjust_LEFT);
1224  aPropertyValue >>= nParagraphAdjust;
1225  if (o3tl::make_unsigned(nParagraphAdjust) < SAL_N_ELEMENTS(RID_STR_PARAADJUST_CONST) - 1)
1226  aControlValue <<= RptResId(RID_STR_PARAADJUST_CONST[nParagraphAdjust]);
1227  }
1228  break;
1229  case PROPERTY_ID_BACKCOLOR:
1231  {
1232  Color nColor = COL_TRANSPARENT;
1233  if ( (aPropertyValue >>= nColor) && COL_TRANSPARENT == nColor )
1234  aPropertyValue.clear();
1235  }
1236  [[fallthrough]];
1237  default:
1238  aControlValue = m_xFormComponentHandler->convertToControlValue(PropertyName, aPropertyValue, _rControlValueType);
1239  }
1240  return aControlValue;
1241 }
1242 void SAL_CALL GeometryHandler::addPropertyChangeListener(const uno::Reference< beans::XPropertyChangeListener > & _rxListener)
1243 {
1244  ::osl::MutexGuard aGuard( m_aMutex );
1245  m_aPropertyListeners.addInterface( _rxListener );
1246  m_xFormComponentHandler->addPropertyChangeListener(_rxListener);
1247 }
1248 
1249 void SAL_CALL GeometryHandler::removePropertyChangeListener(const uno::Reference< beans::XPropertyChangeListener > & _rxListener)
1250 {
1251  ::osl::MutexGuard aGuard( m_aMutex );
1252  m_aPropertyListeners.removeInterface( _rxListener );
1253  m_xFormComponentHandler->removePropertyChangeListener(_rxListener);
1254 }
1255 
1256 
1257 uno::Sequence< beans::Property > SAL_CALL GeometryHandler::getSupportedProperties()
1258 {
1259  ::std::vector< beans::Property > aNewProps;
1260  aNewProps.reserve(20); // only a guess
1262 
1263  const OUString pIncludeProperties[] =
1264  {
1265  OUString(PROPERTY_FORCENEWPAGE)
1266  ,OUString(PROPERTY_KEEPTOGETHER)
1267  ,OUString(PROPERTY_CANGROW)
1268  ,OUString(PROPERTY_CANSHRINK)
1269  ,OUString(PROPERTY_REPEATSECTION)
1270  ,OUString(PROPERTY_PRINTREPEATEDVALUES)
1272  ,OUString(PROPERTY_STARTNEWCOLUMN)
1273  ,OUString(PROPERTY_RESETPAGENUMBER)
1275  ,OUString(PROPERTY_VISIBLE)
1276  ,OUString(PROPERTY_PAGEHEADEROPTION)
1277  ,OUString(PROPERTY_PAGEFOOTEROPTION)
1278  ,OUString("ControlLabel")
1279  ,OUString(PROPERTY_POSITIONX)
1280  ,OUString(PROPERTY_POSITIONY)
1281  ,OUString(PROPERTY_WIDTH)
1282  ,OUString(PROPERTY_HEIGHT)
1283  ,OUString(PROPERTY_AUTOGROW)
1284  ,OUString(PROPERTY_PREEVALUATED)
1285  ,OUString(PROPERTY_DEEPTRAVERSING)
1286  ,OUString(PROPERTY_FORMULA)
1287  ,OUString(PROPERTY_INITIALFORMULA)
1288  ,OUString(PROPERTY_PRESERVEIRI)
1289  ,OUString(PROPERTY_DATAFIELD)
1290  ,OUString(PROPERTY_FONT)
1291  ,OUString(PROPERTY_BACKCOLOR)
1292  ,OUString(PROPERTY_BACKTRANSPARENT)
1293  ,OUString(PROPERTY_CONTROLBACKGROUND)
1295  ,OUString(PROPERTY_LABEL)
1296  ,OUString(PROPERTY_MIMETYPE)
1297  ,OUString(PROPERTY_VERTICALALIGN)
1298  ,OUString(PROPERTY_PARAADJUST)
1299  };
1300  const uno::Reference < beans::XPropertySetInfo > xInfo = m_xReportComponent->getPropertySetInfo();
1301  const uno::Sequence< beans::Property> aSeq = xInfo->getProperties();
1302  for (const auto & rIncludeProp : pIncludeProperties)
1303  {
1304  const beans::Property* pFind = ::std::find_if(aSeq.begin(), aSeq.end(),
1305  [&rIncludeProp] (const beans::Property& x) -> bool {
1306  return x.Name == rIncludeProp;
1307  });
1308  if ( pFind != aSeq.end() )
1309  {
1310  // special case for controls which contain a data field
1311  if ( PROPERTY_DATAFIELD == rIncludeProp )
1312  {
1313  beans::Property aValue;
1314  aValue.Name = PROPERTY_FORMULALIST;
1315  aNewProps.push_back(aValue);
1316  aValue.Name = PROPERTY_SCOPE;
1317  aNewProps.push_back(aValue);
1318  aValue.Name = PROPERTY_TYPE;
1319  aNewProps.push_back(aValue);
1320  }
1321  aNewProps.push_back(*pFind);
1322  }
1323  }
1324 
1325  // special property for shapes
1326 // if ( uno::Reference< report::XShape>(m_xReportComponent,uno::UNO_QUERY).is() )
1327 // {
1328 // beans::Property aValue;
1329 // aValue.Name = PROPERTY_AREA;
1330 // aNewProps.push_back(aValue);
1331 // }
1332  // re-enable when the remaining issues of #i88727# are fixed
1333 
1334  return uno::Sequence< beans::Property > (&(*aNewProps.begin()),aNewProps.size());
1335 }
1336 
1337 uno::Sequence< OUString > SAL_CALL GeometryHandler::getSupersededProperties()
1338 {
1339  uno::Sequence< OUString > aRet;
1340  const uno::Reference<report::XReportDefinition> xReport(m_xReportComponent,uno::UNO_QUERY);
1341  if ( xReport.is() && !uno::Reference< report::XSection>(xReport->getParent(),uno::UNO_QUERY).is() )
1342  {
1343  aRet.realloc(5);
1344  OUString* pIter = aRet.getArray();
1345  *pIter++ = PROPERTY_POSITIONX;
1346  *pIter++ = PROPERTY_POSITIONY;
1347  *pIter++ = PROPERTY_WIDTH;
1348  *pIter++ = PROPERTY_HEIGHT;
1349  *pIter++ = PROPERTY_DATAFIELD;
1350  }
1351  return aRet;
1352 }
1353 
1354 uno::Sequence< OUString > SAL_CALL GeometryHandler::getActuatingProperties()
1355 {
1356  ::osl::MutexGuard aGuard( m_aMutex );
1357 
1358  uno::Sequence< OUString > aSeq
1359  {
1363  PROPERTY_TYPE,
1365  };
1366 
1367  return ::comphelper::concatSequences(m_xFormComponentHandler->getActuatingProperties(),aSeq);
1368 }
1369 
1370 sal_Bool SAL_CALL GeometryHandler::isComposable(const OUString & _rPropertyName)
1371 {
1373 }
1374 
1375 inspection::InteractiveSelectionResult SAL_CALL GeometryHandler::onInteractivePropertySelection(const OUString & PropertyName, sal_Bool Primary, uno::Any & _rData, const uno::Reference< inspection::XObjectInspectorUI > & _rxInspectorUI)
1376 {
1377  if ( !_rxInspectorUI.is() )
1378  throw lang::NullPointerException();
1379  if (PropertyName == PROPERTY_FILTER)
1380  {
1381  ::osl::ClearableMutexGuard aGuard( m_aMutex );
1382 
1383  inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
1384  OUString sClause;
1385  if ( impl_dialogFilter_nothrow( sClause, aGuard ) )
1386  {
1387  _rData <<= sClause;
1388  eResult = inspection::InteractiveSelectionResult_ObtainedValue;
1389  }
1390  return eResult;
1391  }
1392  else if (PropertyName == PROPERTY_FONT)
1393  {
1394  ::osl::ClearableMutexGuard aGuard( m_aMutex );
1395 
1396  inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
1397  const uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName("DialogParentWindow") ,uno::UNO_QUERY);
1398  const uno::Reference< report::XReportControlFormat> xReportControlFormat(m_xReportComponent,uno::UNO_QUERY);
1399  aGuard.clear();
1400 
1401  uno::Sequence< beans::NamedValue > aFontSettings;
1402  if ( rptui::openCharDialog( xReportControlFormat, xInspectorWindow, aFontSettings ) )
1403  {
1404  _rData <<= aFontSettings;
1405  eResult = inspection::InteractiveSelectionResult_ObtainedValue;
1406  }
1407  return eResult;
1408  }
1409  else if ( PropertyName == PROPERTY_FORMULA
1410  || PropertyName == PROPERTY_INITIALFORMULA
1411  || PropertyName == PROPERTY_DATAFIELD
1412  || PropertyName == PROPERTY_CONDITIONALPRINTEXPRESSION)
1413  {
1414  ::osl::ClearableMutexGuard aGuard( m_aMutex );
1415 
1416 
1417  OUString sFormula;
1418  m_xReportComponent->getPropertyValue(PropertyName) >>= sFormula;
1419  const uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName("DialogParentWindow") ,uno::UNO_QUERY);
1420  uno::Reference< uno::XComponentContext > xContext = m_xContext;
1421  uno::Reference< beans::XPropertySet > xRowSet( m_xRowSet,uno::UNO_QUERY);
1422  aGuard.clear();
1423 
1424  inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
1425  if ( rptui::openDialogFormula_nothrow( sFormula, xContext,xInspectorWindow,xRowSet ) )
1426  {
1427  _rData <<= sFormula;
1428  eResult = inspection::InteractiveSelectionResult_ObtainedValue;
1429  }
1430  return eResult;
1431  }
1432  else if (PropertyName == PROPERTY_AREA)
1433  {
1434  ::osl::ClearableMutexGuard aGuard( m_aMutex );
1435 
1436  inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
1437  const uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName("DialogParentWindow") ,uno::UNO_QUERY);
1438  const uno::Reference< report::XShape> xShape(m_xReportComponent,uno::UNO_QUERY);
1439  aGuard.clear();
1440 
1441  if ( rptui::openAreaDialog( xShape, xInspectorWindow) )
1442  {
1443  eResult = inspection::InteractiveSelectionResult_ObtainedValue;
1444  beans::PropertyChangeEvent aScopeEvent;
1445  aScopeEvent.PropertyName = PROPERTY_FILLCOLOR;
1446  aScopeEvent.NewValue = xShape->getPropertyValue(PROPERTY_FILLCOLOR);
1447  m_aPropertyListeners.notifyEach( &beans::XPropertyChangeListener::propertyChange, aScopeEvent );
1448  }
1449  return eResult;
1450  }
1451 
1452 
1453  return m_xFormComponentHandler->onInteractivePropertySelection(PropertyName, Primary, _rData, _rxInspectorUI);
1454 }
1455 
1456 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)
1457 {
1458  if ( !_rxInspectorUI.is() )
1459  throw lang::NullPointerException();
1460 
1461  ::osl::MutexGuard aGuard( m_aMutex );
1462  const sal_Int32 nId = OPropertyInfoService::getPropertyId(ActuatingPropertyName);
1463  switch(nId)
1464  {
1465  case PROPERTY_ID_TYPE:
1466  {
1467  sal_uInt32 nNewVal = 0;
1468  NewValue >>= nNewVal;
1469  switch(nNewVal)
1470  {
1471  case DATA_OR_FORMULA:
1472  _rxInspectorUI->rebuildPropertyUI(PROPERTY_DATAFIELD);
1473  _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,true);
1474  _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,false);
1475  _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,false);
1476  OSL_ENSURE(m_sDefaultFunction.isEmpty(),"Why is the m_sDefaultFunction set?");
1477  OSL_ENSURE(m_sScope.isEmpty(),"Why is the m_sScope set?");
1478  break;
1479  case FUNCTION:
1480  _rxInspectorUI->rebuildPropertyUI(PROPERTY_DATAFIELD);
1481  _rxInspectorUI->rebuildPropertyUI(PROPERTY_FORMULALIST);
1482  _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,true);
1483  _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,!m_sDefaultFunction.isEmpty());
1484  _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,!m_sScope.isEmpty());
1485  break;
1486  case USER_DEF_FUNCTION:
1487  _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,false);
1488  _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,true);
1489  _rxInspectorUI->rebuildPropertyUI(PROPERTY_FORMULALIST);
1490  _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,false);
1491  break;
1492  case COUNTER:
1493  _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,false);
1494  _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,false);
1495  _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,true);
1496  break;
1497  }
1498  }
1499  break;
1500  case PROPERTY_ID_DATAFIELD:
1501  {
1502  bool bEnable = (m_nDataFieldType != DATA_OR_FORMULA && m_nDataFieldType != COUNTER );
1503  if ( bEnable )
1504  {
1505  OUString sValue;
1506  m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD ) >>= sValue;
1507  bEnable = !sValue.isEmpty();
1508  }
1509  _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,bEnable);
1510  if ( bEnable )
1511  {
1512  _rxInspectorUI->rebuildPropertyUI(PROPERTY_DATAFIELD);
1513  _rxInspectorUI->rebuildPropertyUI(PROPERTY_FORMULALIST);
1514  }
1515  m_xFormComponentHandler->actuatingPropertyChanged(ActuatingPropertyName, NewValue, OldValue, _rxInspectorUI, _bFirstTimeInit);
1516  }
1517  break;
1519  {
1520  _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,m_nDataFieldType == FUNCTION || m_nDataFieldType == COUNTER);
1521  }
1522  break;
1525  {
1526  bool bValue = false;
1527  NewValue >>= bValue;
1528  bValue = !bValue;
1529  _rxInspectorUI->enablePropertyUI(PROPERTY_BACKCOLOR,bValue);
1530  _rxInspectorUI->enablePropertyUI(PROPERTY_CONTROLBACKGROUND,bValue);
1531  }
1532  break;
1533  default:
1534  m_xFormComponentHandler->actuatingPropertyChanged(ActuatingPropertyName, NewValue, OldValue, _rxInspectorUI, _bFirstTimeInit);
1535  break;
1536  }
1537 }
1538 
1540 {
1541  return m_xFormComponentHandler->suspend(Suspend);
1542 }
1543 
1544 bool GeometryHandler::impl_dialogFilter_nothrow( OUString& _out_rSelectedClause, ::osl::ClearableMutexGuard& _rClearBeforeDialog ) const
1545 {
1546  _out_rSelectedClause.clear();
1547  bool bSuccess = false;
1548  ::dbtools::SQLExceptionInfo aErrorInfo;
1549  uno::Reference< awt::XWindow > xInspectorWindow;
1550  uno::Reference< lang::XMultiComponentFactory > xFactory;
1551  try
1552  {
1553  xFactory = m_xContext->getServiceManager();
1554  xInspectorWindow.set(m_xContext->getValueByName("DialogParentWindow") ,uno::UNO_QUERY);
1555  uno::Reference<sdbc::XConnection> xCon(m_xContext->getValueByName("ActiveConnection") ,uno::UNO_QUERY);
1556  if ( !xCon.is() )
1557  return false;
1558 
1559  uno::Reference< beans::XPropertySet> xRowSetProp(m_xRowSet,uno::UNO_QUERY);
1560  if ( !m_xRowSet.is() )
1561  {
1562  m_xRowSet.set(xFactory->createInstanceWithContext("com.sun.star.sdb.RowSet",m_xContext),uno::UNO_QUERY);
1563  xRowSetProp.set(m_xRowSet,uno::UNO_QUERY);
1564  xRowSetProp->setPropertyValue(PROPERTY_ACTIVECONNECTION,uno::makeAny(xCon));
1565  ::comphelper::copyProperties(m_xReportComponent,xRowSetProp);
1566  }
1567 
1568  // get a composer for the statement which the form is currently based on
1569  uno::Reference< sdb::XSingleSelectQueryComposer > xComposer( ::dbtools::getCurrentSettingsComposer( xRowSetProp, m_xContext, nullptr ) );
1570  OSL_ENSURE( xComposer.is(), "GeometryHandler::impl_dialogFilter_nothrow: could not obtain a composer!" );
1571  if ( !xComposer.is() )
1572  return false;
1573 
1574  // create the dialog
1575  uno::Reference< ui::dialogs::XExecutableDialog > xDialog = sdb::FilterDialog::createWithQuery(m_xContext, xComposer, m_xRowSet, xInspectorWindow);
1576 
1577  const OUString sPropertyUIName(RptResId(RID_STR_FILTER));
1578  // initialize the dialog
1579  xDialog->setTitle( sPropertyUIName );
1580 
1581  _rClearBeforeDialog.clear();
1582  bSuccess = ( xDialog->execute() != 0 );
1583  if ( bSuccess )
1584  _out_rSelectedClause = xComposer->getFilter();
1585  }
1586  catch (const sdb::SQLContext& e) { aErrorInfo = e; }
1587  catch (const sdbc::SQLWarning& e) { aErrorInfo = e; }
1588  catch (const sdbc::SQLException& e) { aErrorInfo = e; }
1589  catch( const uno::Exception& )
1590  {
1591  TOOLS_WARN_EXCEPTION( "reportdesign", "GeometryHandler::impl_dialogFilter_nothrow" );
1592  }
1593 
1594  if ( aErrorInfo.isValid() )
1595  ::dbtools::showError( aErrorInfo, xInspectorWindow, m_xContext );
1596 
1597  return bSuccess;
1598 }
1599 
1600 void GeometryHandler::checkPosAndSize( const awt::Point& _aNewPos,
1601  const awt::Size& _aSize)
1602 {
1603  const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY);
1604  const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY);
1605  if ( !xSection.is() || uno::Reference< report::XShape>(xSourceReportComponent,uno::UNO_QUERY).is() ) // shapes can overlap.
1606  return;
1607 
1608  ::Point aPos(VCLPoint(_aNewPos));
1609  if ( aPos.X() < 0 || aPos.Y() < 0 ) // TODO: have to check size with pos aka || (aPos.X() + aAwtSize.Width) > m_xSection->getReportDefinition()->
1610  throw beans::PropertyVetoException(RptResId(RID_STR_ILLEGAL_POSITION),xSourceReportComponent);
1611 
1612  ::tools::Rectangle aSourceRect(aPos,VCLSize(_aSize));
1613 
1614  const sal_Int32 nCount = xSection->getCount();
1615  for (sal_Int32 i = 0; i < nCount ; ++i)
1616  {
1617  const uno::Reference< report::XReportComponent> xReportComponent(xSection->getByIndex(i),uno::UNO_QUERY);
1618  if ( xReportComponent.is() && xReportComponent != xSourceReportComponent )
1619  {
1620  const ::tools::Rectangle aBoundRect(VCLPoint(xReportComponent->getPosition()),VCLSize(xReportComponent->getSize()));
1621  const ::tools::Rectangle aRect = aSourceRect.GetIntersection(aBoundRect);
1622  if ( !aRect.IsEmpty() && (aRect.Left() != aRect.Right() && aRect.Top() != aRect.Bottom() ) )
1623  throw beans::PropertyVetoException(RptResId( RID_STR_OVERLAP_OTHER_CONTROL),xSourceReportComponent);
1624  }
1625  }
1626 }
1627 
1628 void GeometryHandler::impl_fillFormulaList_nothrow(::std::vector< OUString >& out_rList) const
1629 {
1630  if ( m_nDataFieldType == FUNCTION )
1631  {
1632  for (auto const& it : m_aDefaultFunctions)
1633  {
1634  out_rList.push_back(it.getName());
1635  }
1636  }
1637  else if ( m_nDataFieldType == USER_DEF_FUNCTION )
1638  ::std::transform( m_aFunctionNames.begin(),
1639  m_aFunctionNames.end(),
1640  ::std::back_inserter(out_rList),
1642 }
1643 
1644 OUString GeometryHandler::impl_ConvertUIToMimeType_nothrow(const OUString& _sUIName) const
1645 {
1646  ::std::vector< OUString > aList;
1648  OUString sRet;
1649  ::std::vector< OUString >::const_iterator aFind = ::std::find(aList.begin(),aList.end(),_sUIName);
1650  if ( aFind != aList.end() )
1651  {
1652  const std::size_t nPos = aFind - aList.begin();
1653  const uno::Reference< report::XReportDefinition> xReportDefinition(m_xReportComponent,uno::UNO_QUERY);
1654  if ( xReportDefinition.is() )
1655  {
1656  const uno::Sequence< OUString > aMimeTypes( xReportDefinition->getAvailableMimeTypes() );
1657  sRet = aMimeTypes[nPos];
1658  }
1659  }
1660  return sRet;
1661 }
1662 
1663 OUString GeometryHandler::impl_ConvertMimeTypeToUI_nothrow(const OUString& _sMimetype) const
1664 {
1666  OUString sRet;
1667  std::shared_ptr<const SfxFilter> pFilter = SfxFilter::GetDefaultFilter( aMimeHelper.GetDocServiceNameFromMediaType(_sMimetype) );
1668  if ( pFilter )
1669  sRet = pFilter->GetUIName();
1670  if ( sRet.isEmpty() )
1671  sRet = _sMimetype;
1672  return sRet;
1673 }
1674 
1675 void GeometryHandler::impl_fillMimeTypes_nothrow(::std::vector< OUString >& _out_rList) const
1676 {
1677  try
1678  {
1679  const uno::Reference< report::XReportDefinition> xReportDefinition(m_xReportComponent,uno::UNO_QUERY);
1680  if ( xReportDefinition.is() )
1681  {
1682  const uno::Sequence< OUString > aMimeTypes( xReportDefinition->getAvailableMimeTypes() );
1683  for(const OUString& rMimeType : aMimeTypes)
1684  {
1685  const OUString sDocName( impl_ConvertMimeTypeToUI_nothrow(rMimeType) );
1686  if ( !sDocName.isEmpty() )
1687  _out_rList.push_back(sDocName);
1688  }
1689  }
1690  }
1691  catch(uno::Exception&)
1692  {
1693  TOOLS_WARN_EXCEPTION( "reportdesign", "");
1694  }
1695 }
1696 
1697 void GeometryHandler::impl_fillScopeList_nothrow(::std::vector< OUString >& _out_rList) const
1698 {
1699  try
1700  {
1701  const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY_THROW);
1702  const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY_THROW);
1703 
1704  const uno::Reference< report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
1705  const uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups();
1706  sal_Int32 nPos = -1;
1707  uno::Reference< report::XGroup> xGroup = xSection->getGroup();
1708  if ( xGroup.is() )
1709  nPos = getPositionInIndexAccess(xGroups,xGroup);
1710  else if ( xSection == xReportDefinition->getDetail() )
1711  nPos = xGroups->getCount()-1;
1712 
1713  const OUString sGroup = RptResId(RID_STR_SCOPE_GROUP);
1714  for (sal_Int32 i = 0 ; i <= nPos ; ++i)
1715  {
1716  xGroup.set(xGroups->getByIndex(i),uno::UNO_QUERY_THROW);
1717  OUString sGroupName = sGroup.replaceFirst("%1",xGroup->getExpression());
1718  _out_rList.push_back(sGroupName);
1719  }
1720  _out_rList.push_back(xReportDefinition->getName());
1721  }
1722  catch(uno::Exception&)
1723  {
1724  TOOLS_WARN_EXCEPTION( "reportdesign", "");
1725  }
1726 }
1727 
1728 uno::Reference< report::XFunctionsSupplier> GeometryHandler::fillScope_throw(OUString& _rsNamePostfix)
1729 {
1730  uno::Reference< report::XFunctionsSupplier> xReturn;
1731 
1732  const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY_THROW);
1733  const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY_THROW);
1734  const uno::Reference< report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
1735  if ( m_sScope.isEmpty() )
1736  {
1737  const uno::Reference< report::XGroup> xGroup = xSection->getGroup();
1738  if ( xGroup.is() )
1739  {
1740  OUString sGroupName = RptResId(RID_STR_SCOPE_GROUP);
1741  _rsNamePostfix = xGroup->getExpression();
1742  m_sScope = sGroupName.replaceFirst("%1",_rsNamePostfix);
1743  xReturn = xGroup.get();
1744  }
1745  else if ( xSection == xReportDefinition->getDetail() )
1746  {
1747  const uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups();
1748  const sal_Int32 nCount = xGroups->getCount();
1749  if ( nCount )
1750  {
1751  const uno::Reference< report::XGroup> xGroup2(xGroups->getByIndex(nCount - 1),uno::UNO_QUERY_THROW);
1752  OUString sGroupName = RptResId(RID_STR_SCOPE_GROUP);
1753  _rsNamePostfix = xGroup2->getExpression();
1754  m_sScope = sGroupName.replaceFirst("%1",_rsNamePostfix);
1755  xReturn = xGroup2.get();
1756  }
1757  }
1758  if ( m_sScope.isEmpty() )
1759  {
1760  xReturn = xReportDefinition.get();
1761  _rsNamePostfix = m_sScope = xReportDefinition->getName();
1762  }
1763  }
1764  else if ( m_sScope == xReportDefinition->getName() )
1765  {
1766  xReturn = xReportDefinition.get();
1767  _rsNamePostfix = m_sScope;
1768  }
1769  else
1770  {
1771  uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups();
1772  const sal_Int32 nCount = xGroups->getCount();
1773 
1774  for (sal_Int32 i = 0 ; i < nCount; ++i)
1775  {
1776  const uno::Reference< report::XGroup> xGroup(xGroups->getByIndex(i),uno::UNO_QUERY_THROW);
1777  OUString sGroupName = RptResId(RID_STR_SCOPE_GROUP);
1778  if ( m_sScope == sGroupName.replaceFirst("%1",xGroup->getExpression()) )
1779  {
1780  _rsNamePostfix = xGroup->getExpression();
1781  xReturn = xGroup.get();
1782  break;
1783  }
1784  }
1785 
1786  }
1787  OSL_ENSURE(xReturn.is(),"Why don't we have a functionssupplier here!");
1788 
1789  return xReturn;
1790 }
1791 
1792 bool GeometryHandler::isDefaultFunction( const OUString& _sQuotedFunction
1793  ,OUString& _rDataField
1794  ,const uno::Reference< report::XFunctionsSupplier>& _xFunctionsSupplier
1795  ,bool _bSet) const
1796 {
1797  bool bDefaultFunction = false;
1798  try
1799  {
1800  const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY_THROW);
1801  const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY_THROW);
1802  const uno::Reference< report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
1803 
1804  ::std::pair<TFunctions::const_iterator,TFunctions::const_iterator> aFind = m_aFunctionNames.equal_range(_sQuotedFunction);
1805  while ( aFind.first != aFind.second )
1806  {
1807  if ( !_xFunctionsSupplier.is() || _xFunctionsSupplier == aFind.first->second.second )
1808  {
1809  const beans::Optional< OUString> aInitialFormula = aFind.first->second.first->getInitialFormula();
1810  if ( aInitialFormula.IsPresent )
1811  {
1812  OUString sDefaultFunctionName;
1813  bDefaultFunction = impl_isDefaultFunction_nothrow(aFind.first->second.first,_rDataField,sDefaultFunctionName);
1814  if ( bDefaultFunction )
1815  {
1816  m_xFunction = aFind.first->second.first;
1817  if ( _bSet )
1818  {
1819  m_sDefaultFunction = sDefaultFunctionName;
1820  uno::Reference< report::XGroup> xGroup(aFind.first->second.second,uno::UNO_QUERY);
1821  if ( xGroup.is() )
1822  {
1823  OUString sGroupName = RptResId(RID_STR_SCOPE_GROUP);
1824  m_sScope = sGroupName.replaceFirst("%1",xGroup->getExpression());
1825  }
1826  else
1827  m_sScope = xReportDefinition->getName();
1828  }
1829  }
1830  break;
1831  }
1832  }
1833  ++(aFind.first);
1834  }
1835  }
1836  catch(uno::Exception&)
1837  {
1838  TOOLS_WARN_EXCEPTION( "reportdesign", "");
1839  }
1840  return bDefaultFunction;
1841 }
1842 
1843 bool GeometryHandler::impl_isDefaultFunction_nothrow( const uno::Reference< report::XFunction>& _xFunction
1844  ,OUString& _rDataField
1845  ,OUString& _rsDefaultFunctionName) const
1846 {
1847  bool bDefaultFunction = false;
1848  try
1849  {
1850  const OUString sFormula( _xFunction->getFormula() );
1851  i18nutil::SearchOptions2 aSearchOptions;
1852  aSearchOptions.AlgorithmType2 = util::SearchAlgorithms2::REGEXP;
1853  aSearchOptions.searchFlag = 0x00000100;
1854  auto aIter = std::find_if(m_aDefaultFunctions.begin(), m_aDefaultFunctions.end(),
1855  [&aSearchOptions, &sFormula](const DefaultFunction& rDefaultFunction) {
1856  aSearchOptions.searchString = rDefaultFunction.m_sSearchString;
1857  utl::TextSearch aTextSearch( aSearchOptions);
1858  sal_Int32 start = 0;
1859  sal_Int32 end = sFormula.getLength();
1860  return aTextSearch.SearchForward(sFormula, &start, &end) && start == 0 && end == sFormula.getLength();
1861  });
1862  if (aIter != m_aDefaultFunctions.end()) // default function found
1863  {
1864  sal_Int32 start = 0;
1865  sal_Int32 end = sFormula.getLength();
1866  aSearchOptions.searchString = "\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]";
1867  utl::TextSearch aDataSearch( aSearchOptions);
1868  (void)aDataSearch.SearchForward(sFormula, &start, &end);
1869  ++start;
1870  _rDataField = sFormula.copy(start,end-start-1);
1871  _rsDefaultFunctionName = aIter->m_sName;
1872  bDefaultFunction = true;
1873  }
1874  }
1875  catch(uno::Exception&)
1876  {
1877  TOOLS_WARN_EXCEPTION( "reportdesign", "");
1878  }
1879  return bDefaultFunction;
1880 }
1881 
1883 {
1884  if ( !m_aDefaultFunctions.empty() )
1885  return;
1886 
1888  m_aCounterFunction.m_sName = RptResId(RID_STR_F_COUNTER);
1889  m_aCounterFunction.m_sFormula = "rpt:[%FunctionName] + 1";
1890  m_aCounterFunction.m_sSearchString = "rpt:\\[[:alpha:]+([:space:]*[:alnum:]*)*\\][:space:]*\\+[:space:]*[:digit:]*";
1891  m_aCounterFunction.m_sInitialFormula.IsPresent = true;
1892  m_aCounterFunction.m_sInitialFormula.Value = "rpt:1";
1893 
1894  DefaultFunction aDefault;
1895 
1896  aDefault.m_bPreEvaluated = true;
1897 
1898  aDefault.m_sName = RptResId(RID_STR_F_ACCUMULATION);
1899  aDefault.m_sFormula = "rpt:[%Column] + [%FunctionName]";
1900  aDefault.m_sSearchString = "rpt:\\[[:alpha:]+([:space:]*[:alnum:]*)*\\][:space:]*\\+[:space:]*\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]";
1901  aDefault.m_sInitialFormula.IsPresent = true;
1902  aDefault.m_sInitialFormula.Value = "rpt:[%Column]";
1903  m_aDefaultFunctions.push_back(aDefault);
1904 
1905  aDefault.m_sName = RptResId(RID_STR_F_MINIMUM);
1906  aDefault.m_sFormula = "rpt:IF([%Column] < [%FunctionName];[%Column];[%FunctionName])";
1907  aDefault.m_sSearchString = "rpt:IF\\((\\[[:alpha:]+([:space:]*[:alnum:]*)*\\])[:space:]*<[:space:]*(\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]);[:space:]*\\1[:space:]*;[:space:]*\\3[:space:]*\\)";
1908  aDefault.m_sInitialFormula.IsPresent = true;
1909  aDefault.m_sInitialFormula.Value = "rpt:[%Column]";
1910  m_aDefaultFunctions.push_back(aDefault);
1911 
1912  aDefault.m_sName = RptResId(RID_STR_F_MAXIMUM);
1913  aDefault.m_sFormula = "rpt:IF([%Column] > [%FunctionName];[%Column];[%FunctionName])";
1914  aDefault.m_sSearchString = "rpt:IF\\((\\[[:alpha:]+([:space:]*[:alnum:]*)*\\])[:space:]*>[:space:]*(\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]);[:space:]*\\1[:space:]*;[:space:]*\\3[:space:]*\\)";
1915  aDefault.m_sInitialFormula.IsPresent = true;
1916  aDefault.m_sInitialFormula.Value = "rpt:[%Column]";
1917  m_aDefaultFunctions.push_back(aDefault);
1918 }
1919 
1920 void GeometryHandler::createDefaultFunction(::osl::ResettableMutexGuard& _aGuard ,const OUString& _sFunction,std::u16string_view _sDataField)
1921 {
1922  try
1923  {
1924  OUString sNamePostfix;
1925  const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostfix);
1926 
1927  auto aIter = std::find_if(m_aDefaultFunctions.begin(), m_aDefaultFunctions.end(),
1928  [&_sFunction](const DefaultFunction& rDefaultFunction) { return rDefaultFunction.m_sName == _sFunction; });
1929  if (aIter != m_aDefaultFunctions.end())
1930  {
1931  const OUString sFunctionName( _sFunction + _sDataField + sNamePostfix);
1932  const OUString sQuotedFunctionName(lcl_getQuotedFunctionName(sFunctionName));
1933 
1934  beans::PropertyChangeEvent aEvent;
1935  aEvent.PropertyName = PROPERTY_SCOPE;
1936  aEvent.OldValue <<= m_sScope;
1937 
1938  ::std::pair<TFunctions::const_iterator,TFunctions::const_iterator> aFind = m_aFunctionNames.equal_range(sQuotedFunctionName);
1939  while ( aFind.first != aFind.second )
1940  {
1941  if ( xFunctionsSupplier == aFind.first->second.second )
1942  {
1943  m_xFunction = aFind.first->second.first;
1944  OUString sTemp;
1945  isDefaultFunction(sQuotedFunctionName,sTemp,uno::Reference< report::XFunctionsSupplier>(),true); // implicitly sets the m_sScope
1946  break;
1947  }
1948  ++(aFind.first);
1949  }
1950  if ( aFind.first == aFind.second )
1951  impl_createFunction(sFunctionName,_sDataField,*aIter);
1952 
1953  OBlocker aBlocker(m_bIn);
1954  m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny( impl_convertToFormula( uno::makeAny(sQuotedFunctionName) )));
1955  aEvent.NewValue <<= m_sScope;
1956  _aGuard.clear();
1957  m_aPropertyListeners.notifyEach( &beans::XPropertyChangeListener::propertyChange, aEvent );
1958  }
1959  }
1960  catch(uno::Exception&)
1961  {
1962  TOOLS_WARN_EXCEPTION( "reportdesign", "");
1963  }
1964 }
1965 
1967 {
1968  if ( !m_xFunction.is() )
1969  return;
1970 
1971  const OUString sQuotedFunctionName(lcl_getQuotedFunctionName(m_xFunction));
1972  ::std::pair<TFunctions::iterator,TFunctions::iterator> aFind = m_aFunctionNames.equal_range(sQuotedFunctionName);
1973  while ( aFind.first != aFind.second )
1974  {
1975  if ( aFind.first->second.first == m_xFunction )
1976  {
1977  uno::Reference< report::XFunctions> xFunctions = aFind.first->second.second->getFunctions();
1978  xFunctions->removeByIndex(xFunctions->getCount() - 1 );
1979  m_aFunctionNames.erase(aFind.first);
1980  m_bNewFunction = false;
1981  break;
1982  }
1983  ++(aFind.first);
1984  }
1985 }
1986 
1987 void GeometryHandler::resetOwnProperties(::osl::ResettableMutexGuard& _aGuard,const OUString& _sOldFunctionName,const OUString& _sOldScope,const sal_uInt32 _nOldDataFieldType)
1988 {
1989  const OUString sNewFunction = m_sDefaultFunction;
1990  const OUString sNewScope = m_sScope;
1991  const sal_uInt32 nNewDataFieldType = m_nDataFieldType;
1992  _aGuard.clear();
1993  if ( _nOldDataFieldType != nNewDataFieldType )
1994  {
1995  beans::PropertyChangeEvent aScopeEvent;
1996  aScopeEvent.PropertyName = PROPERTY_TYPE;
1997  aScopeEvent.OldValue <<= _nOldDataFieldType;
1998  aScopeEvent.NewValue <<= nNewDataFieldType;
1999  m_aPropertyListeners.notifyEach( &beans::XPropertyChangeListener::propertyChange, aScopeEvent );
2000  }
2001  if ( _sOldFunctionName != sNewFunction )
2002  {
2003  beans::PropertyChangeEvent aFormulaEvent;
2004  aFormulaEvent.PropertyName = PROPERTY_FORMULALIST;
2005  aFormulaEvent.OldValue <<= _sOldFunctionName;
2006  aFormulaEvent.NewValue <<= sNewFunction;
2007 
2008  m_aPropertyListeners.notifyEach( &beans::XPropertyChangeListener::propertyChange, aFormulaEvent );
2009  }
2010  if ( _sOldScope != sNewScope )
2011  {
2012  beans::PropertyChangeEvent aScopeEvent;
2013  aScopeEvent.PropertyName = PROPERTY_SCOPE;
2014  aScopeEvent.OldValue <<= _sOldScope;
2015  aScopeEvent.NewValue <<= sNewScope;
2016  m_aPropertyListeners.notifyEach( &beans::XPropertyChangeListener::propertyChange, aScopeEvent );
2017  }
2018 
2019  _aGuard.reset();
2020 }
2021 
2022 void GeometryHandler::impl_initFieldList_nothrow( uno::Sequence< OUString >& _rFieldNames ) const
2023 {
2024  _rFieldNames.realloc(0);
2025  try
2026  {
2027  uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName("DialogParentWindow") ,uno::UNO_QUERY);
2028  weld::WaitObject aWaitCursor(Application::GetFrameWeld(xInspectorWindow));
2029 
2030  // get the form of the control we're inspecting
2031  uno::Reference< beans::XPropertySet > xFormSet( m_xRowSet, uno::UNO_QUERY );
2032  if ( !xFormSet.is() )
2033  return;
2034 
2035  OUString sObjectName;
2036  OSL_VERIFY( xFormSet->getPropertyValue( PROPERTY_COMMAND ) >>= sObjectName );
2037  // when there is no command we don't need to ask for columns
2038  uno::Reference<sdbc::XConnection> xCon(m_xContext->getValueByName("ActiveConnection") ,uno::UNO_QUERY);
2039  if ( !sObjectName.isEmpty() && xCon.is() )
2040  {
2041  sal_Int32 nObjectType = sdb::CommandType::COMMAND;
2042  OSL_VERIFY( xFormSet->getPropertyValue( PROPERTY_COMMANDTYPE ) >>= nObjectType );
2043 
2044  _rFieldNames = ::dbtools::getFieldNamesByCommandDescriptor( xCon, nObjectType, sObjectName );
2045  }
2046  }
2047  catch (uno::Exception&)
2048  {
2049  TOOLS_WARN_EXCEPTION( "reportdesign", "GeometryHandler::impl_initFieldList_nothrow" );
2050  }
2051 }
2052 
2053 bool GeometryHandler::impl_isCounterFunction_throw(const OUString& _sQuotedFunctionName,OUString& Out_sScope) const
2054 {
2055  ::std::pair<TFunctions::const_iterator,TFunctions::const_iterator> aFind = m_aFunctionNames.equal_range(_sQuotedFunctionName);
2056  while ( aFind.first != aFind.second )
2057  {
2058  const beans::Optional< OUString> aInitialFormula = aFind.first->second.first->getInitialFormula();
2059  if ( aInitialFormula.IsPresent )
2060  {
2061  const OUString sFormula( aFind.first->second.first->getFormula() );
2062  i18nutil::SearchOptions2 aSearchOptions;
2063  aSearchOptions.AlgorithmType2 = util::SearchAlgorithms2::REGEXP;
2064  aSearchOptions.searchFlag = 0x00000100;
2065  aSearchOptions.searchString = m_aCounterFunction.m_sSearchString;
2066  utl::TextSearch aTextSearch( aSearchOptions);
2067  sal_Int32 start = 0;
2068  sal_Int32 end = sFormula.getLength();
2069  if ( aTextSearch.SearchForward(sFormula,&start,&end) && start == 0 && end == sFormula.getLength()) // counter function found
2070  {
2071  const uno::Reference< report::XGroup > xGroup(aFind.first->second.second,uno::UNO_QUERY);
2072  if ( xGroup.is() )
2073  {
2074  OUString sGroupName = RptResId(RID_STR_SCOPE_GROUP);
2075  Out_sScope = sGroupName.replaceFirst("%1",xGroup->getExpression());
2076  }
2077  else
2078  Out_sScope = uno::Reference< report::XReportDefinition >(aFind.first->second.second,uno::UNO_QUERY_THROW)->getName();
2079  break;
2080  }
2081  }
2082  ++(aFind.first);
2083  }
2084  return aFind.first != aFind.second;
2085 }
2086 
2087 void GeometryHandler::impl_createFunction(const OUString& _sFunctionName,std::u16string_view _sDataField,const DefaultFunction& _aFunction)
2088 {
2089  if ( m_bNewFunction )
2090  removeFunction();
2091 
2092  const OUString sQuotedFunctionName(lcl_getQuotedFunctionName(_sFunctionName));
2093  m_xFunction.set(report::Function::create(m_xContext));
2094  m_xFunction->setName( _sFunctionName );
2095 
2096  static const OUStringLiteral sPlaceHolder1(u"%Column");
2097  static const OUStringLiteral sPlaceHolder2(u"%FunctionName");
2098  OUString sFormula(_aFunction.m_sFormula);
2099  sFormula = sFormula.replaceAll(sPlaceHolder1,_sDataField);
2100  sFormula = sFormula.replaceAll(sPlaceHolder2,_sFunctionName);
2101 
2102  m_xFunction->setFormula(sFormula);
2103  m_xFunction->setPreEvaluated(_aFunction.m_bPreEvaluated);
2104  m_xFunction->setDeepTraversing(false);
2105  if ( _aFunction.m_sInitialFormula.IsPresent )
2106  {
2107  beans::Optional< OUString> aInitialFormula = _aFunction.m_sInitialFormula;
2108  OUString sInitialFormula = aInitialFormula.Value;
2109  sInitialFormula = sInitialFormula.replaceAll(sPlaceHolder1,_sDataField);
2110  sInitialFormula = sInitialFormula.replaceAll(sPlaceHolder2,_sFunctionName);
2111  aInitialFormula.Value = sInitialFormula;
2112  m_xFunction->setInitialFormula( aInitialFormula );
2113  }
2114  OUString sNamePostfix;
2115  const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostfix);
2116  const uno::Reference< container::XIndexContainer> xFunctions(xFunctionsSupplier->getFunctions(),uno::UNO_QUERY_THROW);
2117  xFunctions->insertByIndex(xFunctions->getCount(),uno::makeAny(m_xFunction));
2118  m_aFunctionNames.emplace(sQuotedFunctionName,TFunctionPair(m_xFunction,xFunctionsSupplier));
2119  m_bNewFunction = true;
2120 }
2121 
2123 {
2124  OUString sNamePostfix;
2125  fillScope_throw(sNamePostfix);
2126  OUString sFunctionName = m_aCounterFunction.m_sName + sNamePostfix;
2127  const OUString sQuotedFunctionName = lcl_getQuotedFunctionName(sFunctionName);
2128  OUString sScope;
2129  if ( !(!sFunctionName.isEmpty() && m_aFunctionNames.find(sQuotedFunctionName) != m_aFunctionNames.end() && impl_isCounterFunction_throw(sQuotedFunctionName,sScope)) )
2130  impl_createFunction(sFunctionName,{},m_aCounterFunction);
2131 
2132  OBlocker aBlocker(m_bIn);
2133  m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(impl_convertToFormula( uno::makeAny(sQuotedFunctionName))));
2134 }
2135 
2136 sal_uInt32 GeometryHandler::impl_getDataFieldType_throw(const OUString& _sDataField) const
2137 {
2138  sal_uInt32 nDataFieldType = UNDEF_DATA;
2139  OUString sDataField;
2140  if ( !_sDataField.isEmpty() )
2141  sDataField = _sDataField;
2142  else
2143  {
2144  uno::Any aDataField( m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD ) );
2145  lcl_convertFormulaTo(aDataField,aDataField);
2146  aDataField >>= sDataField;
2147  }
2148 
2149  if ( !sDataField.isEmpty() )
2150  {
2151  if ( impl_isDataField(sDataField) )
2152  nDataFieldType = DATA_OR_FORMULA;
2153  else if ( isDefaultFunction(sDataField,sDataField) )
2154  nDataFieldType = FUNCTION;
2155  else if ( m_aFunctionNames.find(sDataField) != m_aFunctionNames.end() )
2156  {
2157  nDataFieldType = USER_DEF_FUNCTION;
2158  OUString sScope;
2159  if ( impl_isCounterFunction_throw(sDataField,sScope) )
2160  nDataFieldType = COUNTER;
2161  }
2162  else
2163  nDataFieldType = DATA_OR_FORMULA;
2164  }
2165  return nDataFieldType;
2166 }
2167 
2168 // XEventListener
2169 void SAL_CALL GeometryHandler::disposing(const lang::EventObject& )
2170 {
2171 }
2172 // XPropertyChangeListener
2173 void SAL_CALL GeometryHandler::propertyChange(const beans::PropertyChangeEvent& /*evt*/)
2174 {
2175  ::osl::ResettableMutexGuard aGuard( m_aMutex );
2176  if ( m_bIn )
2177  return;
2178 
2179  const sal_uInt32 nOldDataFieldType = m_nDataFieldType;
2180  const OUString sOldFunctionName = m_sDefaultFunction;
2181  const OUString sOldScope = m_sScope;
2182  m_sDefaultFunction.clear();
2183  m_sScope.clear();
2185  if ( UNDEF_DATA == m_nDataFieldType )
2186  m_nDataFieldType = nOldDataFieldType;
2187  uno::Any aDataField = m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD );
2188  lcl_convertFormulaTo(aDataField,aDataField);
2189  OUString sDataField;
2190  aDataField >>= sDataField;
2191  switch(m_nDataFieldType)
2192  {
2193  case FUNCTION:
2194  isDefaultFunction(sDataField,sDataField,uno::Reference< report::XFunctionsSupplier>(),true);
2195  break;
2196  case COUNTER:
2198  break;
2199  default:
2200  ;
2201  }
2202 
2203  resetOwnProperties(aGuard,sOldFunctionName,sOldScope,nOldDataFieldType);
2204 }
2205 
2206 } // namespace rptui
2207 
2208 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
2210  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
2211 {
2212  return cppu::acquire(new rptui::GeometryHandler(context));
2213 }
2214 
2215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define PROPERTY_DEEPTRAVERSING
Definition: strings.hxx:192
static OUString getPropertyTranslation(sal_Int32 _nId)
Definition: metadata.cxx:152
#define PROPERTY_LABEL
Definition: strings.hxx:89
static OString getPropertyHelpId(sal_Int32 _nId)
Definition: metadata.cxx:159
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:103
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...
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
tools::Long const nLeftMargin
sal_Int32 addInterface(const css::uno::Reference< ListenerT > &rxIFace)
#define PROPERTY_ID_FORMULA
Definition: metadata.hxx:111
static OUString getHelpURL(std::string_view _sHelpId)
#define PROPERTY_FORMULALIST
Definition: strings.hxx:261
css::uno::Reference< css::report::XFunction > m_xFunction
#define PROPERTY_VISIBLE
Definition: strings.hxx:35
#define PROPERTY_PRESERVEIRI
Definition: strings.hxx:213
constexpr OUStringLiteral UID_RPT_RPT_PROP_DLG_FONT_TYPE
Definition: helpids.h:22
constexpr::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
constexpr OUStringLiteral UID_RPT_PROP_FORMULA
Definition: helpids.h:21
void checkPosAndSize(const css::awt::Point &_aNewPos, const css::awt::Size &_aSize)
#define PROPERTY_PRINTREPEATEDVALUES
Definition: strings.hxx:107
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:121
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:111
float x
#define RESARRAY_INDEX_NOTFOUND
#define PROPERTY_FILLCOLOR
Definition: strings.hxx:267
#define PROPERTY_WIDTH
Definition: strings.hxx:73
OUString impl_convertToFormula(const css::uno::Any &_rControlValue)
MeasurementSystem
#define PROPERTY_AREA
Definition: strings.hxx:266
#define PROPERTY_RESETPAGENUMBER
Definition: strings.hxx:110
#define PROPERTY_PAGEFOOTEROPTION
Definition: strings.hxx:65
#define PROPERTY_ID_PARAADJUST
Definition: metadata.hxx:139
#define PROPERTY_REPEATSECTION
Definition: strings.hxx:47
css::uno::Any getConstantValue(bool bToControlValue, const TranslateId *pResId, const css::uno::Any &_aValue, const OUString &_sConstantName, const OUString &PropertyName)
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:102
#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:145
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:211
#define PROPERTY_ID_FORMULALIST
Definition: metadata.hxx:128
std::mutex m_aMutex
#define PROPERTY_STARTNEWCOLUMN
Definition: strings.hxx:109
#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:205
#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
OUString RptResId(TranslateId aId)
#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
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
sal_Int32 removeInterface(const css::uno::Reference< ListenerT > &rxIFace)
#define PROPERTY_FORMULA
Definition: strings.hxx:189
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:262
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
css::uno::Reference< css::script::XTypeConverter > m_xTypeConverter
type converter, needed on various occasions
#define PROPERTY_PARAADJUST
Definition: strings.hxx:79
constexpr OUStringLiteral UID_RPT_RPT_PROP_DLG_AREA
Definition: helpids.h:23
virtual void SAL_CALL inspect(const css::uno::Reference< css::uno::XInterface > &Component) override
#define PROPERTY_FILTER
Definition: strings.hxx:183
::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
void notifyEach(void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
enumrange< T >::Iterator end(enumrange< T >)
#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:218
#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
static void implCreateListLikeControl(const css::uno::Reference< css::inspection::XPropertyControlFactory > &_rxControlFactory, css::inspection::LineDescriptor &out_Descriptor, const TranslateId *pResId, bool _bReadOnlyControl, bool _bTrueIfListBoxFalseIfComboBox)
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:193
inline::Size VCLSize(const css::awt::Size &rAWTSize)
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 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:166
static sal_Int16 ConvertToMeasurementUnit(FieldUnit _nFieldUnit, sal_Int16 _rFieldToUNOValueFactor)
#define PROPERTY_PREEVALUATED
Definition: strings.hxx:191
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
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:108
#define PROPERTY_ID_VERTICALALIGN
Definition: metadata.hxx:140
#define PROPERTY_ID_HEIGHT
Definition: xmlColumn.cxx:38
#define PROPERTY_ACTIVECONNECTION
Definition: strings.hxx:187
#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:190
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