1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: GeometryHandler.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef RPT_GEOMETRYHANDLER_HXX
32 #define RPT_GEOMETRYHANDLER_HXX
34 #include "sal/config.h"
35 #include "com/sun/star/uno/XComponentContext.hpp"
36 #include "cppuhelper/compbase3.hxx"
37 #include "cppuhelper/basemutex.hxx"
38 #include "com/sun/star/inspection/XPropertyHandler.hpp"
39 #include "com/sun/star/script/XTypeConverter.hpp"
40 #include "com/sun/star/beans/XPropertySet.hpp"
41 #include "com/sun/star/lang/XServiceInfo.hpp"
42 #include "com/sun/star/report/XReportComponent.hpp"
43 #include "com/sun/star/report/XFunction.hpp"
44 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
45 #include <com/sun/star/sdbc/XRowSet.hpp>
47 #include <comphelper/stl_types.hxx>
48 #include <comphelper/listenernotification.hxx>
49 #include "metadata.hxx"
51 //........................................................................
54 //........................................................................
56 struct DefaultFunction
58 com::sun::star::beans::Optional
< ::rtl::OUString
> m_sInitialFormula
;
59 ::rtl::OUString m_sName
;
60 ::rtl::OUString m_sSearchString
;
61 ::rtl::OUString m_sFormula
;
62 ::sal_Bool m_bPreEvaluated
;
63 ::sal_Bool m_bDeepTraversing
;
65 inline ::rtl::OUString
getName() const { return m_sName
; }
68 class OPropertyInfoService
;
69 typedef ::std::pair
< ::com::sun::star::uno::Reference
< ::com::sun::star::report::XFunction
>, ::com::sun::star::uno::Reference
< ::com::sun::star::report::XFunctionsSupplier
> > TFunctionPair
;
70 typedef ::std::multimap
< ::rtl::OUString
,TFunctionPair
, ::comphelper::UStringMixLess
> TFunctions
;
71 typedef ::comphelper::OSimpleListenerContainer
< ::com::sun::star::beans::XPropertyChangeListener
72 , ::com::sun::star::beans::PropertyChangeEvent
73 > PropertyChangeListeners
;
74 typedef ::cppu::WeakComponentImplHelper3
< ::com::sun::star::inspection::XPropertyHandler
75 , ::com::sun::star::beans::XPropertyChangeListener
76 , ::com::sun::star::lang::XServiceInfo
> GeometryHandler_Base
;
78 class GeometryHandler
:
79 private ::cppu::BaseMutex
,
80 public GeometryHandler_Base
82 /** sets the counter function at the data field.
83 * If the counter function doesn't exist it will be created.
85 void impl_setCounterFunction_throw();
87 /** executes a dialog for chosing a filter criterion for a database report
88 @param _out_rSelectedClause
89 the filter or order clause as chosen by the user
91 we're really inspecting a database form (well, a RowSet at least)
93 <TRUE/> if and only if the user successfully chose a clause
95 bool impl_dialogFilter_nothrow( ::rtl::OUString
& _out_rSelectedClause
, ::osl::ClearableMutexGuard
& _rClearBeforeDialog
) const;
97 /** returns the data field type depending on the data field of the report control
99 * \param _sDataField if the data field is not empty it will be used as data field, otherwise the data field will be used.
100 * \return the data field type
102 sal_uInt32
impl_getDataFieldType_throw(const ::rtl::OUString
& _sDataField
= ::rtl::OUString()) const;
104 ::com::sun::star::uno::Any
getConstantValue(sal_Bool bToControlValue
,sal_uInt16 nResId
,const ::com::sun::star::uno::Any
& _aValue
,const ::rtl::OUString
& _sConstantName
,const ::rtl::OUString
& PropertyName
);
105 ::com::sun::star::beans::Property
getProperty(const ::rtl::OUString
& PropertyName
);
106 void implCreateListLikeControl(
107 const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlFactory
>& _rxControlFactory
108 ,::com::sun::star::inspection::LineDescriptor
& out_Descriptor
110 ,sal_Bool _bReadOnlyControl
111 ,sal_Bool _bTrueIfListBoxFalseIfComboBox
113 void implCreateListLikeControl(
114 const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlFactory
>& _rxControlFactory
115 ,::com::sun::star::inspection::LineDescriptor
& out_Descriptor
116 ,const ::std::vector
< ::rtl::OUString
>& _aEntries
117 ,sal_Bool _bReadOnlyControl
118 ,sal_Bool _bTrueIfListBoxFalseIfComboBox
120 void checkPosAndSize( const ::com::sun::star::awt::Point
& _aNewPos
,
121 const ::com::sun::star::awt::Size
& _aSize
);
123 ::rtl::OUString
impl_convertToFormula( const ::com::sun::star::uno::Any
& _rControlValue
);
125 void impl_initFieldList_nothrow( ::com::sun::star::uno::Sequence
< ::rtl::OUString
>& _rFieldNames
) const;
127 /** Creates the function defined by the function template
129 * \param _sFunctionName the function name
130 * \param _sDataField the data field
131 * \param _aFunction the function template
133 void impl_createFunction(const ::rtl::OUString
& _sFunctionName
,const ::rtl::OUString
& _sDataField
,const DefaultFunction
& _aFunction
);
135 /** check whether the given function name is a countr function.
137 * \param _sQuotedFunctionName the quoted function name to check
138 * \param _Out_sScope the scope of the function
139 * \return When true it is a counter functions otherwise false.
141 bool impl_isCounterFunction_throw(const ::rtl::OUString
& _sQuotedFunctionName
,::rtl::OUString
& _Out_sScope
) const;
143 /** clear the own properties like function and scope and send a notification
146 * \param _sOldFunctionName
148 * \param _nOldDataFieldType
150 void resetOwnProperties(::osl::ResettableMutexGuard
& _aGuard
,const ::rtl::OUString
& _sOldFunctionName
,const ::rtl::OUString
& _sOldScope
,const sal_uInt32 _nOldDataFieldType
);
152 /** checks whether the name is a field or a parameter
154 * \param _sName the name to check
155 * \return true when it is a field or parameter otherwise false
157 bool impl_isDataField(const ::rtl::OUString
& _sName
) const;
159 /**return all formula in a semicolon seperated list
161 * \param _rList the localized function names
163 void impl_fillFormulaList_nothrow(::std::vector
< ::rtl::OUString
>& _out_rList
) const;
165 /** return all group names in a semicolon seperated list starting with the group where this control is contained in.
167 * \param _rList fills the list with all scope names.
169 void impl_fillScopeList_nothrow(::std::vector
< ::rtl::OUString
>& _out_rList
) const;
171 /** return all supported output formats of the report definition
173 * \param _rList fills the list with all mime types
175 void impl_fillMimeTypes_nothrow(::std::vector
< ::rtl::OUString
>& _out_rList
) const;
177 /** return the one supported output formats of the report definition
179 * \param _sMimetype the mimetype
181 ::rtl::OUString
impl_ConvertMimeTypeToUI_nothrow(const ::rtl::OUString
& _sMimetype
) const;
183 /** return the MimeType for the given UI Name
185 * \param _sUIName the doc ui name
187 ::rtl::OUString
impl_ConvertUIToMimeType_nothrow(const ::rtl::OUString
& _sUIName
) const;
189 /** get the functions supplier for the set scope, default is the surrounding group.
191 * \param _rsNamePostFix the name post fix which canbe used when the scope as name part is needed
192 * \return the function supplier
194 ::com::sun::star::uno::Reference
< ::com::sun::star::report::XFunctionsSupplier
> fillScope_throw(::rtl::OUString
& _rsNamePostFix
);
196 /** checks if the given function is a default function we know.
198 * \param _sQuotedFunction the quoted function name
199 * \param _Out_rDataField the data field which is used in the function
200 * \param _xFunctionsSupplier teh function supplier to search or empty if not used
201 * \param _bSet If set to TRUE than the m_sDefaultFunction and m_sScope vars will be set if successful.
202 * \return sal_True with known otherwise sal_False
204 sal_Bool
isDefaultFunction(const ::rtl::OUString
& _sQuotedFunction
205 ,::rtl::OUString
& _Out_rDataField
206 ,const ::com::sun::star::uno::Reference
< ::com::sun::star::report::XFunctionsSupplier
>& _xFunctionsSupplier
= ::com::sun::star::uno::Reference
< ::com::sun::star::report::XFunctionsSupplier
>()
207 ,bool _bSet
= false) const;
209 /** checks if the given function is a default function we know.
213 * \param _rsDefaultFunctionName
216 sal_Bool
impl_isDefaultFunction_nothrow( const ::com::sun::star::uno::Reference
< ::com::sun::star::report::XFunction
>& _xFunction
217 ,::rtl::OUString
& _rDataField
218 ,::rtl::OUString
& _rsDefaultFunctionName
) const;
220 /** fills the memeber m_aDefaultFunctions
223 void loadDefaultFunctions();
225 /** creates a default functionof the _sFunction for the data field _sDataField
226 * The new function will only be created if it didn't exist.
228 * \param _aGuard Will be cleared, when a new function was created.
229 * \param _sFunction The name of the function.
230 * \param _sDataField The name of the data field.
232 void createDefaultFunction(::osl::ResettableMutexGuard
& _aGuard
,const ::rtl::OUString
& _sFunction
,const ::rtl::OUString
& _sDataField
);
234 void removeFunction();
240 OBlocker(bool& _bIn
) : m_bIn(_bIn
){ m_bIn
= true; }
241 ~OBlocker() { m_bIn
= false; }
246 virtual void SAL_CALL
disposing(const ::com::sun::star::lang::EventObject
& Source
) throw( ::com::sun::star::uno::RuntimeException
);
247 // XPropertyChangeListener
248 virtual void SAL_CALL
propertyChange(const ::com::sun::star::beans::PropertyChangeEvent
& evt
) throw(::com::sun::star::uno::RuntimeException
);
251 // XServiceInfo - static versions
252 static ::rtl::OUString
getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException
);
253 static ::com::sun::star::uno::Sequence
< ::rtl::OUString
> getSupportedServiceNames_static( ) throw(::com::sun::star::uno::RuntimeException
);
254 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
255 create(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>&);
258 explicit GeometryHandler(::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> const & context
);
261 virtual ::rtl::OUString SAL_CALL
getImplementationName( ) throw(::com::sun::star::uno::RuntimeException
);
262 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
) throw(::com::sun::star::uno::RuntimeException
);
263 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
);
265 // ::com::sun::star::lang::XComponent:
266 virtual void SAL_CALL
addEventListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
> & xListener
) throw (::com::sun::star::uno::RuntimeException
);
267 virtual void SAL_CALL
removeEventListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
> & aListener
) throw (::com::sun::star::uno::RuntimeException
);
269 // ::com::sun::star::inspection::XPropertyHandler:
270 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
);
271 virtual ::com::sun::star::uno::Any SAL_CALL
getPropertyValue(const ::rtl::OUString
& PropertyName
) throw (::com::sun::star::uno::RuntimeException
, ::com::sun::star::beans::UnknownPropertyException
);
272 virtual void SAL_CALL
setPropertyValue(const ::rtl::OUString
& PropertyName
, const ::com::sun::star::uno::Any
& Value
) throw (::com::sun::star::uno::RuntimeException
, ::com::sun::star::beans::UnknownPropertyException
);
273 virtual ::com::sun::star::beans::PropertyState SAL_CALL
getPropertyState(const ::rtl::OUString
& PropertyName
) throw (::com::sun::star::uno::RuntimeException
, ::com::sun::star::beans::UnknownPropertyException
);
274 virtual ::com::sun::star::inspection::LineDescriptor SAL_CALL
describePropertyLine(const ::rtl::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
);
275 virtual ::com::sun::star::uno::Any SAL_CALL
convertToPropertyValue(const ::rtl::OUString
& PropertyName
, const ::com::sun::star::uno::Any
& ControlValue
) throw (::com::sun::star::uno::RuntimeException
, ::com::sun::star::beans::UnknownPropertyException
);
276 virtual ::com::sun::star::uno::Any SAL_CALL
convertToControlValue(const ::rtl::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
);
277 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
);
278 virtual void SAL_CALL
removePropertyChangeListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyChangeListener
> & _rxListener
) throw (::com::sun::star::uno::RuntimeException
);
279 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::Property
> SAL_CALL
getSupportedProperties() throw (::com::sun::star::uno::RuntimeException
);
280 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupersededProperties() throw (::com::sun::star::uno::RuntimeException
);
281 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getActuatingProperties() throw (::com::sun::star::uno::RuntimeException
);
282 virtual ::sal_Bool SAL_CALL
isComposable(const ::rtl::OUString
& PropertyName
) throw (::com::sun::star::uno::RuntimeException
, ::com::sun::star::beans::UnknownPropertyException
);
283 virtual ::com::sun::star::inspection::InteractiveSelectionResult SAL_CALL
onInteractivePropertySelection(const ::rtl::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
);
284 virtual void SAL_CALL
actuatingPropertyChanged(const ::rtl::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
);
285 virtual ::sal_Bool SAL_CALL
suspend(::sal_Bool Suspend
) throw (::com::sun::star::uno::RuntimeException
);
288 virtual ~GeometryHandler();
290 GeometryHandler(GeometryHandler
&); // not defined
291 void operator =(GeometryHandler
&); // not defined
293 // overload WeakComponentImplHelperBase::disposing()
294 // This function is called upon disposing the component,
295 // if your component needs special work when it becomes
296 // disposed, do it here.
297 virtual void SAL_CALL
disposing();
299 PropertyChangeListeners m_aPropertyListeners
;
300 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> m_aFieldNames
;
301 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> m_aParamNames
;
302 TFunctions m_aFunctionNames
;
303 ::std::vector
< DefaultFunction
> m_aDefaultFunctions
;
304 DefaultFunction m_aCounterFunction
;
305 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> m_xContext
;
306 mutable ::com::sun::star::uno::Reference
< ::com::sun::star::report::XFunction
> m_xFunction
;
307 ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyHandler
> m_xFormComponentHandler
; /// delegatee
308 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> m_xReportComponent
; /// inspectee
309 mutable ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRowSet
> m_xRowSet
;
310 /// type converter, needed on various occasions
311 ::com::sun::star::uno::Reference
< ::com::sun::star::script::XTypeConverter
> m_xTypeConverter
;
312 /// access to property meta data
313 ::std::auto_ptr
< OPropertyInfoService
> m_pInfoService
;
314 mutable ::rtl::OUString m_sDefaultFunction
;
315 mutable ::rtl::OUString m_sScope
;
316 sal_uInt32 m_nDataFieldType
;
317 mutable bool m_bNewFunction
;
320 //........................................................................
322 //........................................................................
324 #endif // RPT_GeometryHandler_HXX