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: fmtools.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 ************************************************************************/
30 #ifndef _SVX_FMTOOLS_HXX
31 #define _SVX_FMTOOLS_HXX
33 #include <com/sun/star/sdb/SQLContext.hpp>
34 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
35 #include <com/sun/star/sdbcx/Privilege.hpp>
36 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
37 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
38 #include <com/sun/star/sdbc/XRowSet.hpp>
39 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
40 #include <com/sun/star/sdb/XColumn.hpp>
41 #include <com/sun/star/sdb/XColumnUpdate.hpp>
42 #include <com/sun/star/sdb/SQLErrorEvent.hpp>
43 #include <com/sun/star/sdbc/XConnection.hpp>
44 #include <com/sun/star/sdbc/XResultSet.hpp>
45 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
46 #include <com/sun/star/sdbcx/XRowLocate.hpp>
47 #include <com/sun/star/sdbc/XDataSource.hpp>
48 #include <com/sun/star/beans/XPropertySet.hpp>
49 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
50 #include <com/sun/star/frame/XDispatchProviderInterceptor.hpp>
51 #include <com/sun/star/frame/XInterceptorInfo.hpp>
52 #include <com/sun/star/container/XIndexContainer.hpp>
53 #include <com/sun/star/frame/XDispatch.hpp>
54 #include <com/sun/star/frame/XStatusListener.hpp>
55 #include <com/sun/star/frame/FeatureStateEvent.hpp>
56 #include <com/sun/star/frame/XModel.hpp>
57 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
58 #include <com/sun/star/container/XNameAccess.hpp>
59 #include <com/sun/star/container/XEnumeration.hpp>
60 #include <com/sun/star/container/XIndexAccess.hpp>
61 #include <com/sun/star/awt/XControlModel.hpp>
62 #include <com/sun/star/awt/XControl.hpp>
63 #include <com/sun/star/awt/FontSlant.hpp>
64 #include <com/sun/star/awt/FontDescriptor.hpp>
65 #include <com/sun/star/awt/FontUnderline.hpp>
66 #include <com/sun/star/awt/FontStrikeout.hpp>
67 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
68 #include <com/sun/star/lang/XServiceInfo.hpp>
69 #include <vcl/wintypes.hxx>
70 #include <vos/mutex.hxx>
72 #ifndef _SVSTDARR_ULONGS
73 #define _SVSTDARR_ULONGS
74 #include <svtools/svstdarr.hxx>
76 #include <sfx2/ctrlitem.hxx>
77 #include <tools/link.hxx>
78 #include <tools/date.hxx>
79 #include <tools/time.hxx>
80 #include <tools/datetime.hxx>
83 #include <com/sun/star/sdbc/XConnection.hpp>
84 #include <com/sun/star/io/XObjectInputStream.hpp>
85 #include <com/sun/star/io/XObjectOutputStream.hpp>
86 #include <com/sun/star/io/XPersistObject.hpp>
87 #include <com/sun/star/util/XNumberFormatter.hpp>
88 #include <com/sun/star/util/XNumberFormats.hpp>
89 #include <cppuhelper/interfacecontainer.h>
90 #include <cppuhelper/compbase2.hxx>
91 #include <cppuhelper/compbase3.hxx>
92 #include <cppuhelper/weakref.hxx>
93 #include <comphelper/uno3.hxx>
94 #include <comphelper/stl_types.hxx>
95 #include <cppuhelper/implbase1.hxx>
96 #include <cppuhelper/implbase2.hxx>
97 #include <cppuhelper/implbase3.hxx>
98 #include <cppuhelper/component.hxx>
100 #include <svx/svxdllapi.h>
106 //==================================================================
108 //==================================================================
109 // displaying a database exception for the user
110 // display info about a simple ::com::sun::star::sdbc::SQLException
111 void displayException(const ::com::sun::star::sdbc::SQLException
&, Window
* _pParent
= NULL
);
112 void displayException(const ::com::sun::star::sdbc::SQLWarning
&, Window
* _pParent
= NULL
);
113 SVX_DLLPUBLIC
void displayException(const ::com::sun::star::sdb::SQLContext
&, Window
* _pParent
= NULL
);
114 void displayException(const ::com::sun::star::sdb::SQLErrorEvent
&, Window
* _pParent
= NULL
);
115 void displayException(const ::com::sun::star::uno::Any
&, Window
* _pParent
= NULL
);
117 #define DATA_MODE rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DataMode" ) )
118 #define FILTER_MODE rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterMode" ) )
120 // Kopieren von Persistenten Objecten
121 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> cloneUsingProperties(const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XPersistObject
>& _xObj
);
123 sal_Int32
findPos(const ::rtl::OUString
& aStr
, const ::com::sun::star::uno::Sequence
< ::rtl::OUString
>& rList
);
125 // Suchen in einer Indexliste nach einem Element
126 sal_Bool
searchElement(const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XIndexAccess
>& xCont
, const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xElement
);
128 sal_Int32
getElementPos(const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XIndexAccess
>& xCont
, const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xElement
);
129 String
getFormComponentAccessPath(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xElement
);
130 String
getFormComponentAccessPath(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xElement
, ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rTopLevelElement
);
131 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> getElementFromAccessPath(const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XIndexAccess
>& _xParent
, const String
& _rRelativePath
);
134 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> getXModel(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xIface
);
136 SVX_DLLPUBLIC ::rtl::OUString
getLabelName(const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xControlModel
);
138 // ===================================================================================================
139 // = class CursorWrapper - eine Hilfsklasse, die parallel mit je einem ::com::sun::star::uno::Reference<XDatabaseUpdateCursor>,
140 // XDatabaseBookmarkCursor und XDatabaseDirectCursor arbeitet
141 // ===================================================================================================
146 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> m_xGeneric
;
147 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
> m_xMoveOperations
;
148 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbcx::XRowLocate
> m_xBookmarkOperations
;
149 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbcx::XColumnsSupplier
> m_xColumnsSupplier
;
150 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> m_xPropertyAccess
;
153 // Construction/Destruction
155 CursorWrapper(const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRowSet
>& _rxCursor
, sal_Bool bUseCloned
= sal_False
);
156 SVX_DLLPUBLIC
CursorWrapper(const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
>& _rxCursor
, sal_Bool bUseCloned
= sal_False
);
157 // bei bUseCloned == sal_True wird der Cursor ueber das XCloneable-Interface (dass er besitzen muss) gedoubled und
160 friend bool operator==(const CursorWrapper
& lhs
, const CursorWrapper
& rhs
)
162 return lhs
.m_xGeneric
.get() == rhs
.m_xGeneric
.get();
165 sal_Bool
is() const { return m_xMoveOperations
.is(); }
166 sal_Bool
Is() const { return m_xMoveOperations
.is(); }
168 CursorWrapper
* operator ->() { return this; }
169 operator const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& () const{ return m_xGeneric
; }
172 const CursorWrapper
& operator=(const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRowSet
>& xCursor
);
173 operator const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
>& () const { return m_xMoveOperations
; }
174 operator const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbcx::XRowLocate
>& () const { return m_xBookmarkOperations
; }
175 operator const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbcx::XColumnsSupplier
>& () const { return m_xColumnsSupplier
; }
177 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& getPropertySet() const { return m_xPropertyAccess
; }
178 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
>& getResultSet() const { return m_xMoveOperations
; }
179 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbcx::XRowLocate
>& getRowLocate() const { return m_xBookmarkOperations
; }
180 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbcx::XColumnsSupplier
>& getColumnsSupplier() const { return m_xColumnsSupplier
; }
182 // das normale queryInterface
183 ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& type
) throw ( ::com::sun::star::uno::RuntimeException
)
184 { return m_xMoveOperations
->queryInterface(type
); }
186 // ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XRowLocate>
187 ::com::sun::star::uno::Any
getBookmark(void)
188 throw( ::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
189 { return m_xBookmarkOperations
->getBookmark(); }
190 sal_Bool
moveToBookmark(const ::com::sun::star::uno::Any
& bookmark
) throw( ::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
) { return m_xBookmarkOperations
->moveToBookmark(bookmark
); }
191 sal_Bool
moveRelativeToBookmark(const ::com::sun::star::uno::Any
& bookmark
, sal_Int32 rows
) throw( ::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
) { return m_xBookmarkOperations
->moveRelativeToBookmark(bookmark
, rows
); }
192 sal_Int32
compareBookmarks(const ::com::sun::star::uno::Any
& lhs
, const ::com::sun::star::uno::Any
& rhs
) const throw( ::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
) { return m_xBookmarkOperations
->compareBookmarks(lhs
, rhs
); }
193 sal_Int32
hasOrderedBookmarks(void) const throw( ::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
) { return m_xBookmarkOperations
->hasOrderedBookmarks(); }
194 sal_Int32
hashBookmark(const ::com::sun::star::uno::Any
& bookmark
) const throw( ::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
) { return m_xBookmarkOperations
->hashBookmark(bookmark
); }
196 // ::com::sun::star::sdbc::XResultSet
197 sal_Bool
isBeforeFirst() const { return m_xMoveOperations
->isBeforeFirst(); }
198 sal_Bool
isAfterLast() const { return m_xMoveOperations
->isAfterLast(); }
199 sal_Bool
isFirst() const { return m_xMoveOperations
->isFirst(); }
200 sal_Bool
isLast() const { return m_xMoveOperations
->isLast(); }
201 void beforeFirst() { m_xMoveOperations
->beforeFirst(); }
202 sal_Bool
first() { return m_xMoveOperations
->first(); }
203 sal_Bool
last() { return m_xMoveOperations
->last(); }
204 sal_Int32
getRow() const { return m_xMoveOperations
->getRow(); }
205 sal_Bool
absolute(sal_Int32 nPosition
) { return m_xMoveOperations
->absolute(nPosition
); }
206 sal_Bool
relative(sal_Int32 nCount
) { return m_xMoveOperations
->relative(nCount
); }
207 sal_Bool
previous() { return m_xMoveOperations
->previous(); }
208 sal_Bool
next() { return m_xMoveOperations
->next(); }
209 void refreshRow() { m_xMoveOperations
->refreshRow(); }
210 sal_Bool
rowUpdated() { return m_xMoveOperations
->rowUpdated(); }
211 sal_Bool
rowInserted() { return m_xMoveOperations
->rowInserted(); }
212 sal_Bool
rowDeleted() { return m_xMoveOperations
->rowDeleted(); }
213 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> getStatement() { return m_xMoveOperations
->getStatement(); }
214 // ::com::sun::star::sdbcx::XColumnsSupplier
215 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
> getColumns() const throw( ::com::sun::star::uno::RuntimeException
) { return m_xColumnsSupplier
->getColumns(); }
217 void ImplConstruct(const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
>& _rxCursor
, sal_Bool bUseCloned
);
221 class FmXDisposeMultiplexer
;
222 class FmXDisposeListener
224 friend class FmXDisposeMultiplexer
;
226 FmXDisposeMultiplexer
* m_pAdapter
;
227 ::osl::Mutex
& m_rMutex
;
230 FmXDisposeListener(::osl::Mutex
& _rMutex
) : m_pAdapter(NULL
), m_rMutex(_rMutex
) { }
231 virtual ~FmXDisposeListener();
233 virtual void disposing(const ::com::sun::star::lang::EventObject
& _rEvent
, sal_Int16 _nId
) throw( ::com::sun::star::uno::RuntimeException
) = 0;
236 void setAdapter(FmXDisposeMultiplexer
* pAdapter
);
239 typedef ::cppu::WeakImplHelper1
< ::com::sun::star::lang::XEventListener
> FmXDisposeMultiplexer_x
;
240 //==============================================================================
243 class FmXDisposeMultiplexer
:public ::cppu::WeakImplHelper1
< ::com::sun::star::lang::XEventListener
>
245 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XComponent
> m_xObject
;
246 FmXDisposeListener
* m_pListener
;
249 virtual ~FmXDisposeMultiplexer();
251 FmXDisposeMultiplexer(FmXDisposeListener
* _pListener
, const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XComponent
>& _rxObject
, sal_Int16 _nId
= -1);
253 // ::com::sun::star::lang::XEventListener
254 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw(::com::sun::star::uno::RuntimeException
);
259 // ==================================================================
261 //========================================================================
262 //= dispatch interception helper classes
263 //========================================================================
265 //------------------------------------------------------------------------
266 //- FmDispatchInterceptor
267 //------------------------------------------------------------------------
268 class FmDispatchInterceptor
271 FmDispatchInterceptor() { }
273 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatch
> interceptedQueryDispatch(sal_uInt16 _nId
,
274 const ::com::sun::star::util::URL
& aURL
, const ::rtl::OUString
& aTargetFrameName
, sal_Int32 nSearchFlags
) throw( ::com::sun::star::uno::RuntimeException
) = 0;
276 virtual ::osl::Mutex
* getInterceptorMutex() = 0;
279 //------------------------------------------------------------------------
280 //- FmXDispatchInterceptorImpl
281 //------------------------------------------------------------------------
282 typedef ::cppu::WeakComponentImplHelper3
< ::com::sun::star::frame::XDispatchProviderInterceptor
283 , ::com::sun::star::lang::XEventListener
284 , ::com::sun::star::frame::XInterceptorInfo
285 > FmXDispatchInterceptorImpl_BASE
;
287 class FmXDispatchInterceptorImpl
: public FmXDispatchInterceptorImpl_BASE
289 ::osl::Mutex m_aFallback
;
291 // the component which's dispatches we're intercepting
292 ::com::sun::star::uno::WeakReference
< ::com::sun::star::frame::XDispatchProviderInterception
>
294 sal_Bool m_bListening
;
296 // the real interceptor
297 FmDispatchInterceptor
* m_pMaster
;
300 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatchProvider
> m_xSlaveDispatcher
;
301 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatchProvider
> m_xMasterDispatcher
;
306 ::com::sun::star::uno::Sequence
< ::rtl::OUString
>
307 m_aInterceptedURLSchemes
;
309 virtual ~FmXDispatchInterceptorImpl();
312 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatchProviderInterception
> getIntercepted() const { return m_xIntercepted
; }
315 FmXDispatchInterceptorImpl(
316 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatchProviderInterception
>& _rToIntercept
,
317 FmDispatchInterceptor
* _pMaster
,
319 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> _rInterceptedSchemes
/// if not empty, this will be used for getInterceptedURLs
323 DECLARE_UNO3_DEFAULTS(FmXDispatchInterceptorImpl
, FmXDispatchInterceptorImpl_BASE
);
324 // virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& type) throw ( ::com::sun::star::uno::RuntimeException );
325 virtual ::com::sun::star::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId() throw(::com::sun::star::uno::RuntimeException
);
326 // ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw(::com::sun::star::uno::RuntimeException);
329 // ::com::sun::star::frame::XDispatchProvider
330 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatch
> SAL_CALL
queryDispatch( const ::com::sun::star::util::URL
& aURL
, const ::rtl::OUString
& aTargetFrameName
, sal_Int32 nSearchFlags
) throw(::com::sun::star::uno::RuntimeException
);
331 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatch
> > SAL_CALL
queryDispatches( const ::com::sun::star::uno::Sequence
< ::com::sun::star::frame::DispatchDescriptor
>& aDescripts
) throw(::com::sun::star::uno::RuntimeException
);
333 // ::com::sun::star::frame::XDispatchProviderInterceptor
334 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatchProvider
> SAL_CALL
getSlaveDispatchProvider( ) throw(::com::sun::star::uno::RuntimeException
);
335 virtual void SAL_CALL
setSlaveDispatchProvider( const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatchProvider
>& xNewDispatchProvider
) throw(::com::sun::star::uno::RuntimeException
);
336 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatchProvider
> SAL_CALL
getMasterDispatchProvider( ) throw(::com::sun::star::uno::RuntimeException
);
337 virtual void SAL_CALL
setMasterDispatchProvider( const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatchProvider
>& xNewSupplier
) throw(::com::sun::star::uno::RuntimeException
);
339 // ::com::sun::star::frame::XInterceptorInfo
340 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getInterceptedURLs( ) throw(::com::sun::star::uno::RuntimeException
);
342 // ::com::sun::star::lang::XEventListener
343 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw(::com::sun::star::uno::RuntimeException
);
346 virtual void SAL_CALL
disposing();
351 ::osl::Mutex
& getAccessSafety()
353 if (m_pMaster
&& m_pMaster
->getInterceptorMutex())
354 return *m_pMaster
->getInterceptorMutex();
359 //==================================================================
361 //==================================================================
362 ::rtl::OUString
getServiceNameByControlType(sal_Int16 nType
);
363 // get a service name to create a model of the given type (OBJ_FM_...)
364 sal_Int16
getControlTypeByObject(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XServiceInfo
>& _rxObject
);
365 // get the object type (OBJ_FM_...) from the services the object supports
367 void TransferEventScripts(const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControlModel
>& xModel
, const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControl
>& xControl
,
368 const ::com::sun::star::uno::Sequence
< ::com::sun::star::script::ScriptEventDescriptor
>& rTransferIfAvailable
);
370 sal_Int16
GridView2ModelPos(const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XIndexAccess
>& rColumns
, sal_Int16 nViewPos
);
372 //==================================================================
373 sal_Bool
isLoadable(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xLoad
);
374 sal_Bool
isRowSetAlive(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxRowSet
);
375 // checks if the ::com::sun::star::sdbcx::XColumnsSupplier provided by _rxRowSet supllies any columns
377 //==================================================================
378 typedef ::std::set
< ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
379 , ::comphelper::OInterfaceCompare
< ::com::sun::star::uno::XInterface
>
382 #endif // _SVX_FMTOOLS_HXX