1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_REPORTDESIGN_SOURCE_UI_INC_GEOMETRYHANDLER_HXX
21 #define INCLUDED_REPORTDESIGN_SOURCE_UI_INC_GEOMETRYHANDLER_HXX
23 #include <sal/config.h>
24 #include <com/sun/star/uno/XComponentContext.hpp>
25 #include <cppuhelper/compbase.hxx>
26 #include <cppuhelper/basemutex.hxx>
27 #include <com/sun/star/awt/Point.hpp>
28 #include <com/sun/star/awt/Size.hpp>
29 #include <com/sun/star/inspection/XPropertyHandler.hpp>
30 #include <com/sun/star/script/XTypeConverter.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/lang/XServiceInfo.hpp>
33 #include <com/sun/star/report/XFunctionsSupplier.hpp>
34 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
35 #include <com/sun/star/sdbc/XRowSet.hpp>
37 #include <comphelper/stl_types.hxx>
38 #include <comphelper/listenernotification.hxx>
39 #include "metadata.hxx"
46 struct DefaultFunction
48 css::beans::Optional
< OUString
> m_sInitialFormula
;
50 OUString m_sSearchString
;
54 const OUString
& getName() const { return m_sName
; }
57 class OPropertyInfoService
;
58 typedef ::std::pair
< css::uno::Reference
< css::report::XFunction
>, css::uno::Reference
< css::report::XFunctionsSupplier
> > TFunctionPair
;
59 typedef ::std::multimap
< OUString
,TFunctionPair
, ::comphelper::UStringMixLess
> TFunctions
;
60 typedef ::comphelper::OSimpleListenerContainer
< css::beans::XPropertyChangeListener
61 , css::beans::PropertyChangeEvent
62 > PropertyChangeListeners
;
63 typedef ::cppu::WeakComponentImplHelper
< css::inspection::XPropertyHandler
64 , css::beans::XPropertyChangeListener
65 , css::lang::XServiceInfo
> GeometryHandler_Base
;
67 class GeometryHandler
:
68 private ::cppu::BaseMutex
,
69 public GeometryHandler_Base
71 /** sets the counter function at the data field.
72 * If the counter function doesn't exist it will be created.
74 void impl_setCounterFunction_throw();
76 /** executes a dialog for choosing a filter criterion for a database report
77 @param _out_rSelectedClause
78 the filter or order clause as chosen by the user
80 we're really inspecting a database form (well, a RowSet at least)
82 <TRUE/> if and only if the user successfully chose a clause
84 bool impl_dialogFilter_nothrow( OUString
& _out_rSelectedClause
, ::osl::ClearableMutexGuard
& _rClearBeforeDialog
) const;
86 /** returns the data field type depending on the data field of the report control
88 * \param _sDataField if the data field is not empty it will be used as data field, otherwise the data field will be used.
89 * \return the data field type
91 sal_uInt32
impl_getDataFieldType_throw(const OUString
& _sDataField
= OUString()) const;
93 css::uno::Any
getConstantValue(bool bToControlValue
,const char** pResId
,const css::uno::Any
& _aValue
,const OUString
& _sConstantName
,const OUString
& PropertyName
);
94 css::beans::Property
getProperty(const OUString
& PropertyName
);
95 static void implCreateListLikeControl(
96 const css::uno::Reference
< css::inspection::XPropertyControlFactory
>& _rxControlFactory
97 ,css::inspection::LineDescriptor
& out_Descriptor
99 ,bool _bReadOnlyControl
100 ,bool _bTrueIfListBoxFalseIfComboBox
102 static void implCreateListLikeControl(
103 const css::uno::Reference
< css::inspection::XPropertyControlFactory
>& _rxControlFactory
104 ,css::inspection::LineDescriptor
& out_Descriptor
105 ,const ::std::vector
< OUString
>& _aEntries
106 ,bool _bReadOnlyControl
107 ,bool _bTrueIfListBoxFalseIfComboBox
109 void checkPosAndSize( const css::awt::Point
& _aNewPos
,
110 const css::awt::Size
& _aSize
);
112 OUString
impl_convertToFormula( const css::uno::Any
& _rControlValue
);
114 void impl_initFieldList_nothrow( css::uno::Sequence
< OUString
>& _rFieldNames
) const;
116 /** Creates the function defined by the function template
118 * \param _sFunctionName the function name
119 * \param _sDataField the data field
120 * \param _aFunction the function template
122 void impl_createFunction(const OUString
& _sFunctionName
,const OUString
& _sDataField
,const DefaultFunction
& _aFunction
);
124 /** check whether the given function name is a counter function.
126 * \param _sQuotedFunctionName the quoted function name to check
127 * \param Out_sScope the scope of the function
128 * \return When true it is a counter functions otherwise false.
130 bool impl_isCounterFunction_throw(const OUString
& _sQuotedFunctionName
,OUString
& Out_sScope
) const;
132 /** clear the own properties like function and scope and send a notification
135 * \param _sOldFunctionName
137 * \param _nOldDataFieldType
139 void resetOwnProperties(::osl::ResettableMutexGuard
& _aGuard
,const OUString
& _sOldFunctionName
,const OUString
& _sOldScope
,const sal_uInt32 _nOldDataFieldType
);
141 /** checks whether the name is a field or a parameter
143 * \param _sName the name to check
144 * \return true when it is a field or parameter otherwise false
146 bool impl_isDataField(const OUString
& _sName
) const;
148 /**return all formula in a semicolon separated list
150 * \param _rList the localized function names
152 void impl_fillFormulaList_nothrow(::std::vector
< OUString
>& _out_rList
) const;
154 /** return all group names in a semicolon separated list starting with the group where this control is contained in.
156 * \param _rList fills the list with all scope names.
158 void impl_fillScopeList_nothrow(::std::vector
< OUString
>& _out_rList
) const;
160 /** return all supported output formats of the report definition
162 * \param _rList fills the list with all mime types
164 void impl_fillMimeTypes_nothrow(::std::vector
< OUString
>& _out_rList
) const;
166 /** return the one supported output formats of the report definition
168 * \param _sMimetype the mimetype
170 OUString
impl_ConvertMimeTypeToUI_nothrow(const OUString
& _sMimetype
) const;
172 /** return the MimeType for the given UI Name
174 * \param _sUIName the doc ui name
176 OUString
impl_ConvertUIToMimeType_nothrow(const OUString
& _sUIName
) const;
178 /** get the functions supplier for the set scope, default is the surrounding group.
180 * \param _rsNamePostfix the name postfix which can be used when the scope as name part is needed
181 * \return the function supplier
183 css::uno::Reference
< css::report::XFunctionsSupplier
> fillScope_throw(OUString
& _rsNamePostfix
);
185 /** checks if the given function is a default function we know.
187 * \param _sQuotedFunction the quoted function name
188 * \param Out_rDataField the data field which is used in the function
189 * \param _xFunctionsSupplier the function supplier to search or empty if not used
190 * \param _bSet If set to sal_True than the m_sDefaultFunction and m_sScope vars will be set if successful.
191 * \return sal_True with known otherwise sal_False
193 bool isDefaultFunction(const OUString
& _sQuotedFunction
194 ,OUString
& Out_rDataField
195 ,const css::uno::Reference
< css::report::XFunctionsSupplier
>& _xFunctionsSupplier
= css::uno::Reference
< css::report::XFunctionsSupplier
>()
196 ,bool _bSet
= false) const;
198 /** checks if the given function is a default function we know.
202 * \param _rsDefaultFunctionName
205 bool impl_isDefaultFunction_nothrow( const css::uno::Reference
< css::report::XFunction
>& _xFunction
206 ,OUString
& _rDataField
207 ,OUString
& _rsDefaultFunctionName
) const;
209 /** fills the member m_aDefaultFunctions
212 void loadDefaultFunctions();
214 /** creates a default function of the _sFunction for the data field _sDataField
215 * The new function will only be created if it didn't exist.
217 * \param _aGuard Will be cleared, when a new function was created.
218 * \param _sFunction The name of the function.
219 * \param _sDataField The name of the data field.
221 void createDefaultFunction(::osl::ResettableMutexGuard
& _aGuard
,const OUString
& _sFunction
,const OUString
& _sDataField
);
223 void removeFunction();
229 OBlocker(bool& _bIn
) : m_bIn(_bIn
){ m_bIn
= true; }
230 ~OBlocker() { m_bIn
= false; }
235 virtual void SAL_CALL
disposing(const css::lang::EventObject
& Source
) override
;
236 // XPropertyChangeListener
237 virtual void SAL_CALL
propertyChange(const css::beans::PropertyChangeEvent
& evt
) override
;
240 // XServiceInfo - static versions
241 /// @throws css::uno::RuntimeException
242 static OUString
getImplementationName_Static( );
243 /// @throws css::uno::RuntimeException
244 static css::uno::Sequence
< OUString
> getSupportedServiceNames_static( );
245 static css::uno::Reference
< css::uno::XInterface
>
246 create(const css::uno::Reference
< css::uno::XComponentContext
>&);
249 explicit GeometryHandler(css::uno::Reference
< css::uno::XComponentContext
> const & context
);
252 virtual OUString SAL_CALL
getImplementationName( ) override
;
253 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
254 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
256 // css::lang::XComponent:
257 virtual void SAL_CALL
addEventListener(const css::uno::Reference
< css::lang::XEventListener
> & xListener
) override
;
258 virtual void SAL_CALL
removeEventListener(const css::uno::Reference
< css::lang::XEventListener
> & aListener
) override
;
260 // css::inspection::XPropertyHandler:
261 virtual void SAL_CALL
inspect(const css::uno::Reference
< css::uno::XInterface
> & Component
) override
;
262 virtual css::uno::Any SAL_CALL
getPropertyValue(const OUString
& PropertyName
) override
;
263 virtual void SAL_CALL
setPropertyValue(const OUString
& PropertyName
, const css::uno::Any
& Value
) override
;
264 virtual css::beans::PropertyState SAL_CALL
getPropertyState(const OUString
& PropertyName
) override
;
265 virtual css::inspection::LineDescriptor SAL_CALL
describePropertyLine(const OUString
& PropertyName
, const css::uno::Reference
< css::inspection::XPropertyControlFactory
>& ControlFactory
) override
;
266 virtual css::uno::Any SAL_CALL
convertToPropertyValue(const OUString
& PropertyName
, const css::uno::Any
& ControlValue
) override
;
267 virtual css::uno::Any SAL_CALL
convertToControlValue(const OUString
& PropertyName
, const css::uno::Any
& PropertyValue
, const css::uno::Type
& ControlValueType
) override
;
268 virtual void SAL_CALL
addPropertyChangeListener(const css::uno::Reference
< css::beans::XPropertyChangeListener
> & Listener
) override
;
269 virtual void SAL_CALL
removePropertyChangeListener(const css::uno::Reference
< css::beans::XPropertyChangeListener
> & _rxListener
) override
;
270 virtual css::uno::Sequence
< css::beans::Property
> SAL_CALL
getSupportedProperties() override
;
271 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupersededProperties() override
;
272 virtual css::uno::Sequence
< OUString
> SAL_CALL
getActuatingProperties() override
;
273 virtual sal_Bool SAL_CALL
isComposable(const OUString
& PropertyName
) override
;
274 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
;
275 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
;
276 virtual sal_Bool SAL_CALL
suspend(sal_Bool Suspend
) override
;
279 virtual ~GeometryHandler() override
;
281 GeometryHandler(GeometryHandler
const &) = delete;
282 void operator =(GeometryHandler
const &) = delete;
284 // override WeakComponentImplHelperBase::disposing()
285 // This function is called upon disposing the component,
286 // if your component needs special work when it becomes
287 // disposed, do it here.
288 virtual void SAL_CALL
disposing() override
;
290 PropertyChangeListeners m_aPropertyListeners
;
291 css::uno::Sequence
< OUString
> m_aFieldNames
;
292 css::uno::Sequence
< OUString
> m_aParamNames
;
293 TFunctions m_aFunctionNames
;
294 ::std::vector
< DefaultFunction
> m_aDefaultFunctions
;
295 DefaultFunction m_aCounterFunction
;
296 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
297 mutable css::uno::Reference
< css::report::XFunction
> m_xFunction
;
298 css::uno::Reference
< css::inspection::XPropertyHandler
> m_xFormComponentHandler
; /// delegatee
299 css::uno::Reference
< css::beans::XPropertySet
> m_xReportComponent
; /// inspectee
300 mutable css::uno::Reference
< css::sdbc::XRowSet
> m_xRowSet
;
301 /// type converter, needed on various occasions
302 css::uno::Reference
< css::script::XTypeConverter
> m_xTypeConverter
;
303 mutable OUString m_sDefaultFunction
;
304 mutable OUString m_sScope
;
305 sal_uInt32 m_nDataFieldType
;
306 mutable bool m_bNewFunction
;
313 #endif // RPT_GeometryHandler_HXX
315 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */