xref: /aoo41x/main/svx/inc/svx/fmtools.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _SVX_FMTOOLS_HXX
28 #define _SVX_FMTOOLS_HXX
29 
30 #include "svx/svxdllapi.h"
31 
32 #include <com/sun/star/sdb/SQLContext.hpp>
33 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
34 #include <com/sun/star/sdbcx/Privilege.hpp>
35 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
36 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
37 #include <com/sun/star/sdbc/XRowSet.hpp>
38 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
39 #include <com/sun/star/sdb/XColumn.hpp>
40 #include <com/sun/star/sdb/XColumnUpdate.hpp>
41 #include <com/sun/star/sdb/SQLErrorEvent.hpp>
42 #include <com/sun/star/sdbc/XConnection.hpp>
43 #include <com/sun/star/sdbc/XResultSet.hpp>
44 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
45 #include <com/sun/star/sdbcx/XRowLocate.hpp>
46 #include <com/sun/star/sdbc/XDataSource.hpp>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
49 #include <com/sun/star/frame/XDispatchProviderInterceptor.hpp>
50 #include <com/sun/star/container/XIndexContainer.hpp>
51 #include <com/sun/star/frame/XDispatch.hpp>
52 #include <com/sun/star/frame/XStatusListener.hpp>
53 #include <com/sun/star/frame/FeatureStateEvent.hpp>
54 #include <com/sun/star/frame/XModel.hpp>
55 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
56 #include <com/sun/star/container/XNameAccess.hpp>
57 #include <com/sun/star/container/XEnumeration.hpp>
58 #include <com/sun/star/container/XIndexAccess.hpp>
59 #include <com/sun/star/awt/XControlModel.hpp>
60 #include <com/sun/star/awt/XControl.hpp>
61 #include <com/sun/star/awt/FontSlant.hpp>
62 #include <com/sun/star/awt/FontDescriptor.hpp>
63 #include <com/sun/star/awt/FontUnderline.hpp>
64 #include <com/sun/star/awt/FontStrikeout.hpp>
65 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
66 #include <com/sun/star/lang/XServiceInfo.hpp>
67 #include <com/sun/star/sdbc/XConnection.hpp>
68 #include <com/sun/star/io/XObjectInputStream.hpp>
69 #include <com/sun/star/io/XObjectOutputStream.hpp>
70 #include <com/sun/star/io/XPersistObject.hpp>
71 #include <com/sun/star/util/XNumberFormatter.hpp>
72 #include <com/sun/star/util/XNumberFormats.hpp>
73 
74 #include <tools/wintypes.hxx>
75 #include <cppuhelper/weakref.hxx>
76 #include <comphelper/uno3.hxx>
77 #include <comphelper/stl_types.hxx>
78 #include <cppuhelper/implbase1.hxx>
79 #include <svl/svstdarr.hxx>
80 
81 #include <set>
82 
83 class Window;
84 
85 //==================================================================
86 // allgemeine Typen
87 //==================================================================
88 // displaying a database exception for the user
89 // display info about a simple ::com::sun::star::sdbc::SQLException
90 void displayException(const ::com::sun::star::sdbc::SQLException&, Window* _pParent = NULL);
91 void displayException(const ::com::sun::star::sdbc::SQLWarning&, Window* _pParent = NULL);
92 SVX_DLLPUBLIC void displayException(const ::com::sun::star::sdb::SQLContext&, Window* _pParent = NULL);
93 void displayException(const ::com::sun::star::sdb::SQLErrorEvent&, Window* _pParent = NULL);
94 void displayException(const ::com::sun::star::uno::Any&, Window* _pParent = NULL);
95 
96 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);
97 
98 SVX_DLLPUBLIC ::rtl::OUString getLabelName(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& xControlModel);
99 
100 // ===================================================================================================
101 // = class CursorWrapper - eine Hilfsklasse, die parallel mit je einem ::com::sun::star::uno::Reference<XDatabaseUpdateCursor>,
102 //							XDatabaseBookmarkCursor und XDatabaseDirectCursor arbeitet
103 // ===================================================================================================
104 
105 class CursorWrapper
106 {
107 private:
108 	::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>				m_xGeneric;
109 	::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>				m_xMoveOperations;
110 	::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XRowLocate>				m_xBookmarkOperations;
111 	::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier>		m_xColumnsSupplier;
112 	::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>			m_xPropertyAccess;
113 
114 public:
115 	// Construction/Destruction
116 	CursorWrapper() { }
117 	CursorWrapper(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet>& _rxCursor, sal_Bool bUseCloned = sal_False);
118 	SVX_DLLPUBLIC CursorWrapper(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _rxCursor, sal_Bool bUseCloned = sal_False);
119 		// bei bUseCloned == sal_True wird der Cursor ueber das XCloneable-Interface (dass er besitzen muss) gedoubled und
120 		// erst dann benutzt
121 
122 	friend bool operator==(const CursorWrapper& lhs, const CursorWrapper& rhs)
123 	{
124 		return lhs.m_xGeneric.get() == rhs.m_xGeneric.get();
125 	}
126 
127 	sal_Bool is() const { return m_xMoveOperations.is(); }
128 	sal_Bool Is() const { return m_xMoveOperations.is(); }
129 
130 	CursorWrapper* operator ->() { return this; }
131 	operator const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& () const{ return m_xGeneric; }
132 
133 	// 'Konvertierungen'
134 	const CursorWrapper& operator=(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet>& xCursor);
135 	operator const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& () const			{ return m_xMoveOperations; }
136 	operator const ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XRowLocate>& () const 		{ return m_xBookmarkOperations; }
137 	operator const ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier>& () const	{ return m_xColumnsSupplier; }
138 
139 	const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >&		getPropertySet() const		{ return m_xPropertyAccess; }
140 	const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet >&			getResultSet() const		{ return m_xMoveOperations; }
141 	const ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XRowLocate >&			getRowLocate() const		{ return m_xBookmarkOperations; }
142 	const ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier >&	getColumnsSupplier() const	{ return m_xColumnsSupplier; }
143 
144 	// das normale queryInterface
145 	::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& type) throw ( ::com::sun::star::uno::RuntimeException )
146 	{ return m_xMoveOperations->queryInterface(type); }
147 
148 	// ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XRowLocate>
149 	::com::sun::star::uno::Any getBookmark(void)
150 		throw( ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException )
151 	{ return m_xBookmarkOperations->getBookmark(); }
152 	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); }
153 	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); }
154 	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); }
155 	sal_Int32 hasOrderedBookmarks(void) const throw( ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException ) { return m_xBookmarkOperations->hasOrderedBookmarks(); }
156 	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); }
157 
158 	// ::com::sun::star::sdbc::XResultSet
159 	sal_Bool isBeforeFirst() const				{ return m_xMoveOperations->isBeforeFirst(); }
160 	sal_Bool isAfterLast() const				{ return m_xMoveOperations->isAfterLast(); }
161 	sal_Bool isFirst() const					{ return m_xMoveOperations->isFirst(); }
162 	sal_Bool isLast() const 					{ return m_xMoveOperations->isLast(); }
163 	void beforeFirst()							{ m_xMoveOperations->beforeFirst(); }
164 	sal_Bool first()							{ return m_xMoveOperations->first(); }
165 	sal_Bool last() 							{ return m_xMoveOperations->last(); }
166 	sal_Int32 getRow() const					{ return m_xMoveOperations->getRow(); }
167 	sal_Bool absolute(sal_Int32 nPosition)			{ return m_xMoveOperations->absolute(nPosition); }
168 	sal_Bool relative(sal_Int32 nCount) 			{ return m_xMoveOperations->relative(nCount); }
169 	sal_Bool previous() 						{ return m_xMoveOperations->previous(); }
170 	sal_Bool next() 							{ return m_xMoveOperations->next(); }
171 	void refreshRow()						{ m_xMoveOperations->refreshRow(); }
172 	sal_Bool rowUpdated()						{ return m_xMoveOperations->rowUpdated(); }
173 	sal_Bool rowInserted()						{ return m_xMoveOperations->rowInserted(); }
174 	sal_Bool rowDeleted()						{ return m_xMoveOperations->rowDeleted(); }
175 	::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> getStatement() 		{ return m_xMoveOperations->getStatement(); }
176 	// ::com::sun::star::sdbcx::XColumnsSupplier
177 	::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> getColumns() const throw( ::com::sun::star::uno::RuntimeException ) { return m_xColumnsSupplier->getColumns(); }
178 private:
179 	void ImplConstruct(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _rxCursor, sal_Bool bUseCloned);
180 };
181 
182 
183 class FmXDisposeMultiplexer;
184 class FmXDisposeListener
185 {
186 	friend class FmXDisposeMultiplexer;
187 
188 	FmXDisposeMultiplexer*	m_pAdapter;
189 	::osl::Mutex&	m_rMutex;
190 
191 public:
192 	FmXDisposeListener(::osl::Mutex& _rMutex) : m_pAdapter(NULL), m_rMutex(_rMutex) { }
193 	virtual ~FmXDisposeListener();
194 
195 	virtual void disposing(const ::com::sun::star::lang::EventObject& _rEvent, sal_Int16 _nId) throw( ::com::sun::star::uno::RuntimeException ) = 0;
196 
197 protected:
198 	void setAdapter(FmXDisposeMultiplexer* pAdapter);
199 };
200 
201 //==============================================================================
202 
203 class FmXDisposeMultiplexer :public ::cppu::WeakImplHelper1< ::com::sun::star::lang::XEventListener>
204 {
205 	::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>		m_xObject;
206 	FmXDisposeListener* m_pListener;
207 	sal_Int16           m_nId;
208 
209 	virtual ~FmXDisposeMultiplexer();
210 public:
211 	FmXDisposeMultiplexer(FmXDisposeListener* _pListener, const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>& _rxObject, sal_Int16 _nId = -1);
212 
213 // ::com::sun::star::lang::XEventListener
214 	virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
215 
216 	void dispose();
217 };
218 
219 //	==================================================================
220 
221 sal_Int16		getControlTypeByObject(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XServiceInfo>& _rxObject);
222 	// get the object type (OBJ_FM_...) from the services the object supports
223 
224 //==================================================================
225 sal_Bool isRowSetAlive(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& _rxRowSet);
226 	// checks if the ::com::sun::star::sdbcx::XColumnsSupplier provided by _rxRowSet supllies any columns
227 
228 //==================================================================
229 typedef ::std::set  < ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
230                     , ::comphelper::OInterfaceCompare< ::com::sun::star::uno::XInterface >
231                     > InterfaceBag;
232 
233 #endif // _SVX_FMTOOLS_HXX
234 
235