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