xref: /aoo41x/main/svx/inc/svx/fmtools.hxx (revision 3334a7e6)
1*3334a7e6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*3334a7e6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*3334a7e6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*3334a7e6SAndrew Rist  * distributed with this work for additional information
6*3334a7e6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*3334a7e6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*3334a7e6SAndrew Rist  * "License"); you may not use this file except in compliance
9*3334a7e6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*3334a7e6SAndrew Rist  *
11*3334a7e6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*3334a7e6SAndrew Rist  *
13*3334a7e6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*3334a7e6SAndrew Rist  * software distributed under the License is distributed on an
15*3334a7e6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3334a7e6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*3334a7e6SAndrew Rist  * specific language governing permissions and limitations
18*3334a7e6SAndrew Rist  * under the License.
19*3334a7e6SAndrew Rist  *
20*3334a7e6SAndrew Rist  *************************************************************/
21*3334a7e6SAndrew Rist 
22*3334a7e6SAndrew Rist 
23cdf0e10cSrcweir #ifndef _SVX_FMTOOLS_HXX
24cdf0e10cSrcweir #define _SVX_FMTOOLS_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "svx/svxdllapi.h"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
29cdf0e10cSrcweir #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
30cdf0e10cSrcweir #include <com/sun/star/sdbcx/Privilege.hpp>
31cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
32cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
33cdf0e10cSrcweir #include <com/sun/star/sdbc/XRowSet.hpp>
34cdf0e10cSrcweir #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
35cdf0e10cSrcweir #include <com/sun/star/sdb/XColumn.hpp>
36cdf0e10cSrcweir #include <com/sun/star/sdb/XColumnUpdate.hpp>
37cdf0e10cSrcweir #include <com/sun/star/sdb/SQLErrorEvent.hpp>
38cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
39cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
40cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
41cdf0e10cSrcweir #include <com/sun/star/sdbcx/XRowLocate.hpp>
42cdf0e10cSrcweir #include <com/sun/star/sdbc/XDataSource.hpp>
43cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
44cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
45cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProviderInterceptor.hpp>
46cdf0e10cSrcweir #include <com/sun/star/container/XIndexContainer.hpp>
47cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp>
48cdf0e10cSrcweir #include <com/sun/star/frame/XStatusListener.hpp>
49cdf0e10cSrcweir #include <com/sun/star/frame/FeatureStateEvent.hpp>
50cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
51cdf0e10cSrcweir #include <com/sun/star/script/ScriptEventDescriptor.hpp>
52cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
53cdf0e10cSrcweir #include <com/sun/star/container/XEnumeration.hpp>
54cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp>
55cdf0e10cSrcweir #include <com/sun/star/awt/XControlModel.hpp>
56cdf0e10cSrcweir #include <com/sun/star/awt/XControl.hpp>
57cdf0e10cSrcweir #include <com/sun/star/awt/FontSlant.hpp>
58cdf0e10cSrcweir #include <com/sun/star/awt/FontDescriptor.hpp>
59cdf0e10cSrcweir #include <com/sun/star/awt/FontUnderline.hpp>
60cdf0e10cSrcweir #include <com/sun/star/awt/FontStrikeout.hpp>
61cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
62cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
63cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
64cdf0e10cSrcweir #include <com/sun/star/io/XObjectInputStream.hpp>
65cdf0e10cSrcweir #include <com/sun/star/io/XObjectOutputStream.hpp>
66cdf0e10cSrcweir #include <com/sun/star/io/XPersistObject.hpp>
67cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatter.hpp>
68cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormats.hpp>
69cdf0e10cSrcweir 
70cdf0e10cSrcweir #include <tools/wintypes.hxx>
71cdf0e10cSrcweir #include <cppuhelper/weakref.hxx>
72cdf0e10cSrcweir #include <comphelper/uno3.hxx>
73cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
74cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
75cdf0e10cSrcweir #include <svl/svstdarr.hxx>
76cdf0e10cSrcweir 
77cdf0e10cSrcweir #include <set>
78cdf0e10cSrcweir 
79cdf0e10cSrcweir class Window;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir //==================================================================
82cdf0e10cSrcweir // allgemeine Typen
83cdf0e10cSrcweir //==================================================================
84cdf0e10cSrcweir // displaying a database exception for the user
85cdf0e10cSrcweir // display info about a simple ::com::sun::star::sdbc::SQLException
86cdf0e10cSrcweir void displayException(const ::com::sun::star::sdbc::SQLException&, Window* _pParent = NULL);
87cdf0e10cSrcweir void displayException(const ::com::sun::star::sdbc::SQLWarning&, Window* _pParent = NULL);
88cdf0e10cSrcweir SVX_DLLPUBLIC void displayException(const ::com::sun::star::sdb::SQLContext&, Window* _pParent = NULL);
89cdf0e10cSrcweir void displayException(const ::com::sun::star::sdb::SQLErrorEvent&, Window* _pParent = NULL);
90cdf0e10cSrcweir void displayException(const ::com::sun::star::uno::Any&, Window* _pParent = NULL);
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 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);
93cdf0e10cSrcweir 
94cdf0e10cSrcweir SVX_DLLPUBLIC ::rtl::OUString getLabelName(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& xControlModel);
95cdf0e10cSrcweir 
96cdf0e10cSrcweir // ===================================================================================================
97cdf0e10cSrcweir // = class CursorWrapper - eine Hilfsklasse, die parallel mit je einem ::com::sun::star::uno::Reference<XDatabaseUpdateCursor>,
98cdf0e10cSrcweir //							XDatabaseBookmarkCursor und XDatabaseDirectCursor arbeitet
99cdf0e10cSrcweir // ===================================================================================================
100cdf0e10cSrcweir 
101cdf0e10cSrcweir class CursorWrapper
102cdf0e10cSrcweir {
103cdf0e10cSrcweir private:
104cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>				m_xGeneric;
105cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>				m_xMoveOperations;
106cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XRowLocate>				m_xBookmarkOperations;
107cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier>		m_xColumnsSupplier;
108cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>			m_xPropertyAccess;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir public:
111cdf0e10cSrcweir 	// Construction/Destruction
CursorWrapper()112cdf0e10cSrcweir 	CursorWrapper() { }
113cdf0e10cSrcweir 	CursorWrapper(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet>& _rxCursor, sal_Bool bUseCloned = sal_False);
114cdf0e10cSrcweir 	SVX_DLLPUBLIC CursorWrapper(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _rxCursor, sal_Bool bUseCloned = sal_False);
115cdf0e10cSrcweir 		// bei bUseCloned == sal_True wird der Cursor ueber das XCloneable-Interface (dass er besitzen muss) gedoubled und
116cdf0e10cSrcweir 		// erst dann benutzt
117cdf0e10cSrcweir 
operator ==(const CursorWrapper & lhs,const CursorWrapper & rhs)118cdf0e10cSrcweir 	friend bool operator==(const CursorWrapper& lhs, const CursorWrapper& rhs)
119cdf0e10cSrcweir 	{
120cdf0e10cSrcweir 		return lhs.m_xGeneric.get() == rhs.m_xGeneric.get();
121cdf0e10cSrcweir 	}
122cdf0e10cSrcweir 
is() const123cdf0e10cSrcweir 	sal_Bool is() const { return m_xMoveOperations.is(); }
Is() const124cdf0e10cSrcweir 	sal_Bool Is() const { return m_xMoveOperations.is(); }
125cdf0e10cSrcweir 
operator ->()126cdf0e10cSrcweir 	CursorWrapper* operator ->() { return this; }
127cdf0e10cSrcweir 	operator const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& () const{ return m_xGeneric; }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	// 'Konvertierungen'
130cdf0e10cSrcweir 	const CursorWrapper& operator=(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet>& xCursor);
131cdf0e10cSrcweir 	operator const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& () const			{ return m_xMoveOperations; }
132cdf0e10cSrcweir 	operator const ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XRowLocate>& () const 		{ return m_xBookmarkOperations; }
133cdf0e10cSrcweir 	operator const ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier>& () const	{ return m_xColumnsSupplier; }
134cdf0e10cSrcweir 
getPropertySet() const135cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >&		getPropertySet() const		{ return m_xPropertyAccess; }
getResultSet() const136cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet >&			getResultSet() const		{ return m_xMoveOperations; }
getRowLocate() const137cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XRowLocate >&			getRowLocate() const		{ return m_xBookmarkOperations; }
getColumnsSupplier() const138cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier >&	getColumnsSupplier() const	{ return m_xColumnsSupplier; }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	// das normale queryInterface
queryInterface(const::com::sun::star::uno::Type & type)141cdf0e10cSrcweir 	::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& type) throw ( ::com::sun::star::uno::RuntimeException )
142cdf0e10cSrcweir 	{ return m_xMoveOperations->queryInterface(type); }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	// ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XRowLocate>
getBookmark(void)145cdf0e10cSrcweir 	::com::sun::star::uno::Any getBookmark(void)
146cdf0e10cSrcweir 		throw( ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException )
147cdf0e10cSrcweir 	{ return m_xBookmarkOperations->getBookmark(); }
moveToBookmark(const::com::sun::star::uno::Any & bookmark)148cdf0e10cSrcweir 	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); }
moveRelativeToBookmark(const::com::sun::star::uno::Any & bookmark,sal_Int32 rows)149cdf0e10cSrcweir 	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); }
compareBookmarks(const::com::sun::star::uno::Any & lhs,const::com::sun::star::uno::Any & rhs) const150cdf0e10cSrcweir 	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); }
hasOrderedBookmarks(void) const151cdf0e10cSrcweir 	sal_Int32 hasOrderedBookmarks(void) const throw( ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException ) { return m_xBookmarkOperations->hasOrderedBookmarks(); }
hashBookmark(const::com::sun::star::uno::Any & bookmark) const152cdf0e10cSrcweir 	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); }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 	// ::com::sun::star::sdbc::XResultSet
isBeforeFirst() const155cdf0e10cSrcweir 	sal_Bool isBeforeFirst() const				{ return m_xMoveOperations->isBeforeFirst(); }
isAfterLast() const156cdf0e10cSrcweir 	sal_Bool isAfterLast() const				{ return m_xMoveOperations->isAfterLast(); }
isFirst() const157cdf0e10cSrcweir 	sal_Bool isFirst() const					{ return m_xMoveOperations->isFirst(); }
isLast() const158cdf0e10cSrcweir 	sal_Bool isLast() const 					{ return m_xMoveOperations->isLast(); }
beforeFirst()159cdf0e10cSrcweir 	void beforeFirst()							{ m_xMoveOperations->beforeFirst(); }
first()160cdf0e10cSrcweir 	sal_Bool first()							{ return m_xMoveOperations->first(); }
last()161cdf0e10cSrcweir 	sal_Bool last() 							{ return m_xMoveOperations->last(); }
getRow() const162cdf0e10cSrcweir 	sal_Int32 getRow() const					{ return m_xMoveOperations->getRow(); }
absolute(sal_Int32 nPosition)163cdf0e10cSrcweir 	sal_Bool absolute(sal_Int32 nPosition)			{ return m_xMoveOperations->absolute(nPosition); }
relative(sal_Int32 nCount)164cdf0e10cSrcweir 	sal_Bool relative(sal_Int32 nCount) 			{ return m_xMoveOperations->relative(nCount); }
previous()165cdf0e10cSrcweir 	sal_Bool previous() 						{ return m_xMoveOperations->previous(); }
next()166cdf0e10cSrcweir 	sal_Bool next() 							{ return m_xMoveOperations->next(); }
refreshRow()167cdf0e10cSrcweir 	void refreshRow()						{ m_xMoveOperations->refreshRow(); }
rowUpdated()168cdf0e10cSrcweir 	sal_Bool rowUpdated()						{ return m_xMoveOperations->rowUpdated(); }
rowInserted()169cdf0e10cSrcweir 	sal_Bool rowInserted()						{ return m_xMoveOperations->rowInserted(); }
rowDeleted()170cdf0e10cSrcweir 	sal_Bool rowDeleted()						{ return m_xMoveOperations->rowDeleted(); }
getStatement()171cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> getStatement() 		{ return m_xMoveOperations->getStatement(); }
172cdf0e10cSrcweir 	// ::com::sun::star::sdbcx::XColumnsSupplier
getColumns() const173cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> getColumns() const throw( ::com::sun::star::uno::RuntimeException ) { return m_xColumnsSupplier->getColumns(); }
174cdf0e10cSrcweir private:
175cdf0e10cSrcweir 	void ImplConstruct(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _rxCursor, sal_Bool bUseCloned);
176cdf0e10cSrcweir };
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 
179cdf0e10cSrcweir class FmXDisposeMultiplexer;
180cdf0e10cSrcweir class FmXDisposeListener
181cdf0e10cSrcweir {
182cdf0e10cSrcweir 	friend class FmXDisposeMultiplexer;
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	FmXDisposeMultiplexer*	m_pAdapter;
185cdf0e10cSrcweir 	::osl::Mutex&	m_rMutex;
186cdf0e10cSrcweir 
187cdf0e10cSrcweir public:
FmXDisposeListener(::osl::Mutex & _rMutex)188cdf0e10cSrcweir 	FmXDisposeListener(::osl::Mutex& _rMutex) : m_pAdapter(NULL), m_rMutex(_rMutex) { }
189cdf0e10cSrcweir 	virtual ~FmXDisposeListener();
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 	virtual void disposing(const ::com::sun::star::lang::EventObject& _rEvent, sal_Int16 _nId) throw( ::com::sun::star::uno::RuntimeException ) = 0;
192cdf0e10cSrcweir 
193cdf0e10cSrcweir protected:
194cdf0e10cSrcweir 	void setAdapter(FmXDisposeMultiplexer* pAdapter);
195cdf0e10cSrcweir };
196cdf0e10cSrcweir 
197cdf0e10cSrcweir //==============================================================================
198cdf0e10cSrcweir 
199cdf0e10cSrcweir class FmXDisposeMultiplexer :public ::cppu::WeakImplHelper1< ::com::sun::star::lang::XEventListener>
200cdf0e10cSrcweir {
201cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>		m_xObject;
202cdf0e10cSrcweir 	FmXDisposeListener* m_pListener;
203cdf0e10cSrcweir 	sal_Int16           m_nId;
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 	virtual ~FmXDisposeMultiplexer();
206cdf0e10cSrcweir public:
207cdf0e10cSrcweir 	FmXDisposeMultiplexer(FmXDisposeListener* _pListener, const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>& _rxObject, sal_Int16 _nId = -1);
208cdf0e10cSrcweir 
209cdf0e10cSrcweir // ::com::sun::star::lang::XEventListener
210cdf0e10cSrcweir 	virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 	void dispose();
213cdf0e10cSrcweir };
214cdf0e10cSrcweir 
215cdf0e10cSrcweir //	==================================================================
216cdf0e10cSrcweir 
217cdf0e10cSrcweir sal_Int16		getControlTypeByObject(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XServiceInfo>& _rxObject);
218cdf0e10cSrcweir 	// get the object type (OBJ_FM_...) from the services the object supports
219cdf0e10cSrcweir 
220cdf0e10cSrcweir //==================================================================
221cdf0e10cSrcweir sal_Bool isRowSetAlive(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& _rxRowSet);
222cdf0e10cSrcweir 	// checks if the ::com::sun::star::sdbcx::XColumnsSupplier provided by _rxRowSet supllies any columns
223cdf0e10cSrcweir 
224cdf0e10cSrcweir //==================================================================
225cdf0e10cSrcweir typedef ::std::set  < ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
226cdf0e10cSrcweir                     , ::comphelper::OInterfaceCompare< ::com::sun::star::uno::XInterface >
227cdf0e10cSrcweir                     > InterfaceBag;
228cdf0e10cSrcweir 
229cdf0e10cSrcweir #endif // _SVX_FMTOOLS_HXX
230cdf0e10cSrcweir 
231