tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / reportdesign / source / ui / inc / GeometryHandler.hxx
blob13d08414c48248455536eb7d4ac7f9f8f9fc5775
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
36 #include <unotools/resmgr.hxx>
37 #include <map>
38 #include <memory>
39 #include <string_view>
41 #include <comphelper/interfacecontainer3.hxx>
42 #include <comphelper/stl_types.hxx>
45 namespace rptui
49 struct DefaultFunction
51 css::beans::Optional< OUString> m_sInitialFormula;
52 OUString m_sName;
53 OUString m_sSearchString;
54 OUString m_sFormula;
55 bool m_bPreEvaluated;
57 const OUString& getName() const { return m_sName; }
58 } ;
60 class OPropertyInfoService;
61 typedef ::std::pair< css::uno::Reference< css::report::XFunction>, css::uno::Reference< css::report::XFunctionsSupplier> > TFunctionPair;
62 typedef ::std::multimap< OUString,TFunctionPair, ::comphelper::UStringMixLess > TFunctions;
63 typedef ::comphelper::OInterfaceContainerHelper3< css::beans::XPropertyChangeListener > PropertyChangeListeners;
64 typedef ::cppu::WeakComponentImplHelper< css::inspection::XPropertyHandler
65 , css::beans::XPropertyChangeListener
66 , css::lang::XServiceInfo> GeometryHandler_Base;
68 class GeometryHandler:
69 private ::cppu::BaseMutex,
70 public GeometryHandler_Base
72 /** sets the counter function at the data field.
73 * If the counter function doesn't exist it will be created.
75 void impl_setCounterFunction_throw();
77 /** executes a dialog for choosing a filter criterion for a database report
78 @param _out_rSelectedClause
79 the filter or order clause as chosen by the user
80 @precond
81 we're really inspecting a database form (well, a RowSet at least)
82 @return
83 <TRUE/> if and only if the user successfully chose a clause
85 bool impl_dialogFilter_nothrow( OUString& _out_rSelectedClause, ::osl::ClearableMutexGuard& _rClearBeforeDialog ) const;
87 /** returns the data field type depending on the data field of the report control
89 * \param _sDataField if the data field is not empty it will be used as data field, otherwise the data field will be used.
90 * \return the data field type
92 sal_uInt32 impl_getDataFieldType_throw(const OUString& _sDataField = OUString()) const;
94 css::uno::Any getConstantValue(bool bToControlValue,const TranslateId* pResId,const css::uno::Any& _aValue,const OUString& _sConstantName,const OUString & PropertyName );
95 css::beans::Property getProperty(const OUString & PropertyName);
96 static void implCreateListLikeControl(
97 const css::uno::Reference< css::inspection::XPropertyControlFactory >& _rxControlFactory
98 ,css::inspection::LineDescriptor & out_Descriptor
99 ,const TranslateId* pResId
100 ,bool _bReadOnlyControl
101 ,bool _bTrueIfListBoxFalseIfComboBox
103 static void implCreateListLikeControl(
104 const css::uno::Reference< css::inspection::XPropertyControlFactory >& _rxControlFactory
105 ,css::inspection::LineDescriptor & out_Descriptor
106 ,const ::std::vector< OUString>& _aEntries
107 ,bool _bReadOnlyControl
108 ,bool _bTrueIfListBoxFalseIfComboBox
110 void checkPosAndSize( const css::awt::Point& _aNewPos,
111 const css::awt::Size& _aSize);
113 OUString impl_convertToFormula( const css::uno::Any& _rControlValue );
115 void impl_initFieldList_nothrow( css::uno::Sequence< OUString >& _rFieldNames ) const;
117 /** Creates the function defined by the function template
119 * \param _sFunctionName the function name
120 * \param _sDataField the data field
121 * \param _aFunction the function template
123 void impl_createFunction(const OUString& _sFunctionName,std::u16string_view _sDataField,const DefaultFunction& _aFunction);
125 /** check whether the given function name is a counter function.
127 * \param _sQuotedFunctionName the quoted function name to check
128 * \param Out_sScope the scope of the function
129 * \return When true it is a counter functions otherwise false.
131 bool impl_isCounterFunction_throw(const OUString& _sQuotedFunctionName,OUString& Out_sScope) const;
133 /** clear the own properties like function and scope and send a notification
135 * \param _aGuard
136 * \param _sOldFunctionName
137 * \param _sOldScope
138 * \param _nOldDataFieldType
140 void resetOwnProperties(::osl::ResettableMutexGuard& _aGuard,const OUString& _sOldFunctionName,const OUString& _sOldScope,const sal_uInt32 _nOldDataFieldType);
142 /** checks whether the name is a field or a parameter
144 * \param _sName the name to check
145 * \return true when it is a field or parameter otherwise false
147 bool impl_isDataField(const OUString& _sName) const;
149 /**return all formula in a semicolon separated list
151 * \param _rList the localized function names
153 void impl_fillFormulaList_nothrow(::std::vector< OUString >& _out_rList) const;
155 /** return all group names in a semicolon separated list starting with the group where this control is contained in.
157 * \param _rList fills the list with all scope names.
159 void impl_fillScopeList_nothrow(::std::vector< OUString >& _out_rList) const;
161 /** return all supported output formats of the report definition
163 * \param _rList fills the list with all mime types
165 void impl_fillMimeTypes_nothrow(::std::vector< OUString >& _out_rList) const;
167 /** return the one supported output formats of the report definition
169 * \param _sMimetype the mimetype
171 OUString impl_ConvertMimeTypeToUI_nothrow(const OUString& _sMimetype) const;
173 /** return the MimeType for the given UI Name
175 * \param _sUIName the doc ui name
177 OUString impl_ConvertUIToMimeType_nothrow(const OUString& _sUIName) const;
179 /** get the functions supplier for the set scope, default is the surrounding group.
181 * \param _rsNamePostfix the name postfix which can be used when the scope as name part is needed
182 * \return the function supplier
184 css::uno::Reference< css::report::XFunctionsSupplier> fillScope_throw(OUString& _rsNamePostfix);
186 /** checks if the given function is a default function we know.
188 * \param _sQuotedFunction the quoted function name
189 * \param Out_rDataField the data field which is used in the function
190 * \param _xFunctionsSupplier the function supplier to search or empty if not used
191 * \param _bSet If set to sal_True than the m_sDefaultFunction and m_sScope vars will be set if successful.
192 * \return sal_True with known otherwise sal_False
194 bool isDefaultFunction(const OUString& _sQuotedFunction
195 ,OUString& Out_rDataField
196 ,const css::uno::Reference< css::report::XFunctionsSupplier>& _xFunctionsSupplier = css::uno::Reference< css::report::XFunctionsSupplier>()
197 ,bool _bSet = false) const;
199 /** checks if the given function is a default function we know.
201 * \param _xFunction
202 * \param _rDataField
203 * \param _rsDefaultFunctionName
204 * \return
206 bool impl_isDefaultFunction_nothrow( const css::uno::Reference< css::report::XFunction>& _xFunction
207 ,OUString& _rDataField
208 ,OUString& _rsDefaultFunctionName) const;
210 /** fills the member m_aDefaultFunctions
213 void loadDefaultFunctions();
215 /** creates a default function of the _sFunction for the data field _sDataField
216 * The new function will only be created if it didn't exist.
218 * \param _aGuard Will be cleared, when a new function was created.
219 * \param _sFunction The name of the function.
220 * \param _sDataField The name of the data field.
222 void createDefaultFunction(::osl::ResettableMutexGuard& _aGuard ,const OUString& _sFunction,std::u16string_view _sDataField);
224 void removeFunction();
226 class OBlocker
228 bool& m_bIn;
229 public:
230 OBlocker(bool& _bIn) : m_bIn(_bIn){ m_bIn = true; }
231 ~OBlocker() { m_bIn = false; }
235 // XEventListener
236 virtual void SAL_CALL disposing(const css::lang::EventObject& Source) override;
237 // XPropertyChangeListener
238 virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent& evt) override;
240 public:
241 explicit GeometryHandler(css::uno::Reference< css::uno::XComponentContext > const & context);
243 // XServiceInfo
244 virtual OUString SAL_CALL getImplementationName( ) override;
245 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
246 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
248 // css::lang::XComponent:
249 virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > & xListener) override;
250 virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > & aListener) override;
252 // css::inspection::XPropertyHandler:
253 virtual void SAL_CALL inspect(const css::uno::Reference< css::uno::XInterface > & Component) override;
254 virtual css::uno::Any SAL_CALL getPropertyValue(const OUString & PropertyName) override;
255 virtual void SAL_CALL setPropertyValue(const OUString & PropertyName, const css::uno::Any & Value) override;
256 virtual css::beans::PropertyState SAL_CALL getPropertyState(const OUString & PropertyName) override;
257 virtual css::inspection::LineDescriptor SAL_CALL describePropertyLine(const OUString& PropertyName, const css::uno::Reference< css::inspection::XPropertyControlFactory >& ControlFactory ) override;
258 virtual css::uno::Any SAL_CALL convertToPropertyValue(const OUString & PropertyName, const css::uno::Any & ControlValue) override;
259 virtual css::uno::Any SAL_CALL convertToControlValue(const OUString & PropertyName, const css::uno::Any & PropertyValue, const css::uno::Type & ControlValueType) override;
260 virtual void SAL_CALL addPropertyChangeListener(const css::uno::Reference< css::beans::XPropertyChangeListener > & Listener) override;
261 virtual void SAL_CALL removePropertyChangeListener(const css::uno::Reference< css::beans::XPropertyChangeListener > & _rxListener) override;
262 virtual css::uno::Sequence< css::beans::Property > SAL_CALL getSupportedProperties() override;
263 virtual css::uno::Sequence< OUString > SAL_CALL getSupersededProperties() override;
264 virtual css::uno::Sequence< OUString > SAL_CALL getActuatingProperties() override;
265 virtual sal_Bool SAL_CALL isComposable(const OUString & PropertyName) override;
266 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;
267 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;
268 virtual sal_Bool SAL_CALL suspend(sal_Bool Suspend) override;
270 protected:
271 virtual ~GeometryHandler() override;
272 private:
273 GeometryHandler(GeometryHandler const &) = delete;
274 void operator =(GeometryHandler const &) = delete;
276 // override WeakComponentImplHelperBase::disposing()
277 // This function is called upon disposing the component,
278 // if your component needs special work when it becomes
279 // disposed, do it here.
280 virtual void SAL_CALL disposing() override;
282 PropertyChangeListeners m_aPropertyListeners;
283 css::uno::Sequence< OUString > m_aFieldNames;
284 css::uno::Sequence< OUString > m_aParamNames;
285 TFunctions m_aFunctionNames;
286 ::std::vector< DefaultFunction > m_aDefaultFunctions;
287 DefaultFunction m_aCounterFunction;
288 css::uno::Reference< css::uno::XComponentContext > m_xContext;
289 mutable css::uno::Reference< css::report::XFunction> m_xFunction;
290 css::uno::Reference< css::inspection::XPropertyHandler > m_xFormComponentHandler; /// delegatee
291 css::uno::Reference< css::beans::XPropertySet > m_xReportComponent; /// inspectee
292 mutable css::uno::Reference< css::sdbc::XRowSet > m_xRowSet;
293 /// type converter, needed on various occasions
294 css::uno::Reference< css::script::XTypeConverter > m_xTypeConverter;
295 mutable OUString m_sDefaultFunction;
296 mutable OUString m_sScope;
297 sal_uInt32 m_nDataFieldType;
298 mutable bool m_bNewFunction;
299 bool m_bIn;
302 } // namespace rptui
305 #endif // RPT_GeometryHandler_HXX
307 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */