Line data Source code
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 : #ifndef INCLUDED_REPORTDESIGN_SOURCE_UI_INC_GEOMETRYHANDLER_HXX
21 : #define INCLUDED_REPORTDESIGN_SOURCE_UI_INC_GEOMETRYHANDLER_HXX
22 :
23 : #include <sal/config.h>
24 : #include <com/sun/star/uno/XComponentContext.hpp>
25 : #include <cppuhelper/compbase3.hxx>
26 : #include <cppuhelper/basemutex.hxx>
27 : #include <com/sun/star/inspection/XPropertyHandler.hpp>
28 : #include <com/sun/star/script/XTypeConverter.hpp>
29 : #include <com/sun/star/beans/XPropertySet.hpp>
30 : #include <com/sun/star/lang/XServiceInfo.hpp>
31 : #include <com/sun/star/report/XReportComponent.hpp>
32 : #include <com/sun/star/report/XFunction.hpp>
33 : #include <com/sun/star/beans/XPropertyChangeListener.hpp>
34 : #include <com/sun/star/sdbc/XRowSet.hpp>
35 : #include <memory>
36 : #include <comphelper/stl_types.hxx>
37 : #include <comphelper/listenernotification.hxx>
38 : #include "metadata.hxx"
39 :
40 :
41 : namespace rptui
42 : {
43 :
44 :
45 0 : struct DefaultFunction
46 : {
47 : com::sun::star::beans::Optional< OUString> m_sInitialFormula;
48 : OUString m_sName;
49 : OUString m_sSearchString;
50 : OUString m_sFormula;
51 : bool m_bPreEvaluated;
52 : bool m_bDeepTraversing;
53 :
54 0 : inline OUString getName() const { return m_sName; }
55 : } ;
56 :
57 : class OPropertyInfoService;
58 : typedef ::std::pair< ::com::sun::star::uno::Reference< ::com::sun::star::report::XFunction>, ::com::sun::star::uno::Reference< ::com::sun::star::report::XFunctionsSupplier> > TFunctionPair;
59 : typedef ::std::multimap< OUString,TFunctionPair, ::comphelper::UStringMixLess > TFunctions;
60 : typedef ::comphelper::OSimpleListenerContainer < ::com::sun::star::beans::XPropertyChangeListener
61 : , ::com::sun::star::beans::PropertyChangeEvent
62 : > PropertyChangeListeners;
63 : typedef ::cppu::WeakComponentImplHelper3< ::com::sun::star::inspection::XPropertyHandler
64 : , ::com::sun::star::beans::XPropertyChangeListener
65 : , ::com::sun::star::lang::XServiceInfo> GeometryHandler_Base;
66 :
67 : class GeometryHandler:
68 : private ::cppu::BaseMutex,
69 : public GeometryHandler_Base
70 : {
71 : /** sets the counter function at the data field.
72 : * If the counter function doesn't exist it will be created.
73 : */
74 : void impl_setCounterFunction_throw();
75 :
76 : /** executes a dialog for chosing a filter criterion for a database report
77 : @param _out_rSelectedClause
78 : the filter or order clause as chosen by the user
79 : @precond
80 : we're really inspecting a database form (well, a RowSet at least)
81 : @return
82 : <TRUE/> if and only if the user successfully chose a clause
83 : */
84 : bool impl_dialogFilter_nothrow( OUString& _out_rSelectedClause, ::osl::ClearableMutexGuard& _rClearBeforeDialog ) const;
85 :
86 : /** returns the data field type depending on the data field of the report control
87 : *
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
90 : */
91 : sal_uInt32 impl_getDataFieldType_throw(const OUString& _sDataField = OUString()) const;
92 :
93 : ::com::sun::star::uno::Any getConstantValue(bool bToControlValue,sal_uInt16 nResId,const ::com::sun::star::uno::Any& _aValue,const OUString& _sConstantName,const OUString & PropertyName );
94 : ::com::sun::star::beans::Property getProperty(const OUString & PropertyName);
95 : void implCreateListLikeControl(
96 : const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlFactory >& _rxControlFactory
97 : ,::com::sun::star::inspection::LineDescriptor & out_Descriptor
98 : ,sal_uInt16 _nResId
99 : ,bool _bReadOnlyControl
100 : ,bool _bTrueIfListBoxFalseIfComboBox
101 : );
102 : void implCreateListLikeControl(
103 : const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlFactory >& _rxControlFactory
104 : ,::com::sun::star::inspection::LineDescriptor & out_Descriptor
105 : ,const ::std::vector< OUString>& _aEntries
106 : ,bool _bReadOnlyControl
107 : ,bool _bTrueIfListBoxFalseIfComboBox
108 : );
109 : void checkPosAndSize( const ::com::sun::star::awt::Point& _aNewPos,
110 : const ::com::sun::star::awt::Size& _aSize);
111 :
112 : OUString impl_convertToFormula( const ::com::sun::star::uno::Any& _rControlValue );
113 :
114 : void impl_initFieldList_nothrow( ::com::sun::star::uno::Sequence< OUString >& _rFieldNames ) const;
115 :
116 : /** Creates the function defined by the function template
117 : *
118 : * \param _sFunctionName the function name
119 : * \param _sDataField the data field
120 : * \param _aFunction the function template
121 : */
122 : void impl_createFunction(const OUString& _sFunctionName,const OUString& _sDataField,const DefaultFunction& _aFunction);
123 :
124 : /** check whether the given function name is a countr function.
125 : *
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.
129 : */
130 : bool impl_isCounterFunction_throw(const OUString& _sQuotedFunctionName,OUString& _Out_sScope) const;
131 :
132 : /** clear the own properties like function and scope and send a notification
133 : *
134 : * \param _aGuard
135 : * \param _sOldFunctionName
136 : * \param _sOldScope
137 : * \param _nOldDataFieldType
138 : */
139 : void resetOwnProperties(::osl::ResettableMutexGuard& _aGuard,const OUString& _sOldFunctionName,const OUString& _sOldScope,const sal_uInt32 _nOldDataFieldType);
140 :
141 : /** checks whether the name is a field or a parameter
142 : *
143 : * \param _sName the name to check
144 : * \return true when it is a field or parameter otherwise false
145 : */
146 : bool impl_isDataField(const OUString& _sName) const;
147 :
148 : /**return all formula in a semicolon separated list
149 : *
150 : * \param _rList the localized function names
151 : */
152 : void impl_fillFormulaList_nothrow(::std::vector< OUString >& _out_rList) const;
153 :
154 : /** return all group names in a semicolon separated list starting with the group where this control is contained in.
155 : *
156 : * \param _rList fills the list with all scope names.
157 : */
158 : void impl_fillScopeList_nothrow(::std::vector< OUString >& _out_rList) const;
159 :
160 : /** return all supported output formats of the report definition
161 : *
162 : * \param _rList fills the list with all mime types
163 : */
164 : void impl_fillMimeTypes_nothrow(::std::vector< OUString >& _out_rList) const;
165 :
166 : /** return the one supported output formats of the report definition
167 : *
168 : * \param _sMimetype the mimetype
169 : */
170 : OUString impl_ConvertMimeTypeToUI_nothrow(const OUString& _sMimetype) const;
171 :
172 : /** return the MimeType for the given UI Name
173 : *
174 : * \param _sUIName the doc ui name
175 : */
176 : OUString impl_ConvertUIToMimeType_nothrow(const OUString& _sUIName) const;
177 :
178 : /** get the functions supplier for the set scope, default is the surrounding group.
179 : *
180 : * \param _rsNamePostfix the name postfix which can be used when the scope as name part is needed
181 : * \return the function supplier
182 : */
183 : ::com::sun::star::uno::Reference< ::com::sun::star::report::XFunctionsSupplier> fillScope_throw(OUString& _rsNamePostfix);
184 :
185 : /** checks if the given function is a default function we know.
186 : *
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
192 : */
193 : bool isDefaultFunction(const OUString& _sQuotedFunction
194 : ,OUString& _Out_rDataField
195 : ,const ::com::sun::star::uno::Reference< ::com::sun::star::report::XFunctionsSupplier>& _xFunctionsSupplier = ::com::sun::star::uno::Reference< ::com::sun::star::report::XFunctionsSupplier>()
196 : ,bool _bSet = false) const;
197 :
198 : /** checks if the given function is a default function we know.
199 : *
200 : * \param _xFunction
201 : * \param _rDataField
202 : * \param _rsDefaultFunctionName
203 : * \return
204 : */
205 : bool impl_isDefaultFunction_nothrow( const ::com::sun::star::uno::Reference< ::com::sun::star::report::XFunction>& _xFunction
206 : ,OUString& _rDataField
207 : ,OUString& _rsDefaultFunctionName) const;
208 :
209 : /** fills the member m_aDefaultFunctions
210 : *
211 : */
212 : void loadDefaultFunctions();
213 :
214 : /** creates a default functionof the _sFunction for the data field _sDataField
215 : * The new function will only be created if it didn't exist.
216 : *
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.
220 : */
221 : void createDefaultFunction(::osl::ResettableMutexGuard& _aGuard ,const OUString& _sFunction,const OUString& _sDataField);
222 :
223 : void removeFunction();
224 :
225 : class OBlocker
226 : {
227 : bool& m_bIn;
228 : public:
229 0 : OBlocker(bool& _bIn) : m_bIn(_bIn){ m_bIn = true; }
230 0 : ~OBlocker() { m_bIn = false; }
231 : };
232 :
233 :
234 : // XEventListener
235 : virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
236 : // XPropertyChangeListener
237 : virtual void SAL_CALL propertyChange(const ::com::sun::star::beans::PropertyChangeEvent& evt) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
238 :
239 : public:
240 : // XServiceInfo - static versions
241 : static OUString getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException);
242 : static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_static( ) throw(::com::sun::star::uno::RuntimeException);
243 : static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
244 : create(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&);
245 :
246 : public:
247 : explicit GeometryHandler(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & context);
248 :
249 : // XServiceInfo
250 : virtual OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
251 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
252 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
253 :
254 : // ::com::sun::star::lang::XComponent:
255 : virtual void SAL_CALL addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & xListener) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
256 : virtual void SAL_CALL removeEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & aListener) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
257 :
258 : // ::com::sun::star::inspection::XPropertyHandler:
259 : virtual void SAL_CALL inspect(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & Component) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::NullPointerException, std::exception) SAL_OVERRIDE;
260 : virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(const OUString & PropertyName) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::beans::UnknownPropertyException, std::exception) SAL_OVERRIDE;
261 : virtual void SAL_CALL setPropertyValue(const OUString & PropertyName, const ::com::sun::star::uno::Any & Value) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, std::exception) SAL_OVERRIDE;
262 : virtual ::com::sun::star::beans::PropertyState SAL_CALL getPropertyState(const OUString & PropertyName) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::beans::UnknownPropertyException, std::exception) SAL_OVERRIDE;
263 : virtual ::com::sun::star::inspection::LineDescriptor SAL_CALL describePropertyLine(const OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlFactory >& ControlFactory ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::NullPointerException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
264 : virtual ::com::sun::star::uno::Any SAL_CALL convertToPropertyValue(const OUString & PropertyName, const ::com::sun::star::uno::Any & ControlValue) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::beans::UnknownPropertyException, std::exception) SAL_OVERRIDE;
265 : virtual ::com::sun::star::uno::Any SAL_CALL convertToControlValue(const OUString & PropertyName, const ::com::sun::star::uno::Any & PropertyValue, const ::com::sun::star::uno::Type & ControlValueType) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::beans::UnknownPropertyException, std::exception) SAL_OVERRIDE;
266 : virtual void SAL_CALL addPropertyChangeListener(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & Listener) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::NullPointerException, std::exception) SAL_OVERRIDE;
267 : virtual void SAL_CALL removePropertyChangeListener(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & _rxListener) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
268 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > SAL_CALL getSupportedProperties() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
269 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupersededProperties() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
270 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getActuatingProperties() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
271 : virtual sal_Bool SAL_CALL isComposable(const OUString & PropertyName) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::beans::UnknownPropertyException, std::exception) SAL_OVERRIDE;
272 : virtual ::com::sun::star::inspection::InteractiveSelectionResult SAL_CALL onInteractivePropertySelection(const OUString & PropertyName, sal_Bool Primary, ::com::sun::star::uno::Any & out_Data, const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI > & InspectorUI) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::NullPointerException, std::exception) SAL_OVERRIDE;
273 : virtual void SAL_CALL actuatingPropertyChanged(const OUString & ActuatingPropertyName, const ::com::sun::star::uno::Any & NewValue, const ::com::sun::star::uno::Any & OldValue, const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI > & InspectorUI, sal_Bool FirstTimeInit) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::NullPointerException, std::exception) SAL_OVERRIDE;
274 : virtual sal_Bool SAL_CALL suspend(sal_Bool Suspend) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
275 :
276 : protected:
277 : virtual ~GeometryHandler();
278 : private:
279 : GeometryHandler(GeometryHandler &); // not defined
280 : void operator =(GeometryHandler &); // not defined
281 :
282 : // overload WeakComponentImplHelperBase::disposing()
283 : // This function is called upon disposing the component,
284 : // if your component needs special work when it becomes
285 : // disposed, do it here.
286 : virtual void SAL_CALL disposing() SAL_OVERRIDE;
287 :
288 : PropertyChangeListeners m_aPropertyListeners;
289 : ::com::sun::star::uno::Sequence< OUString > m_aFieldNames;
290 : ::com::sun::star::uno::Sequence< OUString > m_aParamNames;
291 : TFunctions m_aFunctionNames;
292 : ::std::vector< DefaultFunction > m_aDefaultFunctions;
293 : DefaultFunction m_aCounterFunction;
294 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
295 : mutable ::com::sun::star::uno::Reference< ::com::sun::star::report::XFunction> m_xFunction;
296 : ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler > m_xFormComponentHandler; /// delegatee
297 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xReportComponent; /// inspectee
298 : mutable ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > m_xRowSet;
299 : /// type converter, needed on various occasions
300 : ::com::sun::star::uno::Reference< ::com::sun::star::script::XTypeConverter > m_xTypeConverter;
301 : /// access to property meta data
302 : ::std::unique_ptr< OPropertyInfoService > m_pInfoService;
303 : mutable OUString m_sDefaultFunction;
304 : mutable OUString m_sScope;
305 : sal_uInt32 m_nDataFieldType;
306 : mutable bool m_bNewFunction;
307 : bool m_bIn;
308 : };
309 :
310 : } // namespace rptui
311 :
312 :
313 : #endif // RPT_GeometryHandler_HXX
314 :
315 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|