1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef _SVX_FMTOOLS_HXX
20 #define _SVX_FMTOOLS_HXX
22 #include "svx/svxdllapi.h"
24 #include <com/sun/star/sdb/SQLContext.hpp>
25 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
26 #include <com/sun/star/sdbcx/Privilege.hpp>
27 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
28 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
29 #include <com/sun/star/sdbc/XRowSet.hpp>
30 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
31 #include <com/sun/star/sdb/XColumn.hpp>
32 #include <com/sun/star/sdb/XColumnUpdate.hpp>
33 #include <com/sun/star/sdb/SQLErrorEvent.hpp>
34 #include <com/sun/star/sdbc/XConnection.hpp>
35 #include <com/sun/star/sdbc/XResultSet.hpp>
36 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
37 #include <com/sun/star/sdbcx/XRowLocate.hpp>
38 #include <com/sun/star/sdbc/XDataSource.hpp>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
41 #include <com/sun/star/frame/XDispatchProviderInterceptor.hpp>
42 #include <com/sun/star/container/XIndexContainer.hpp>
43 #include <com/sun/star/frame/XDispatch.hpp>
44 #include <com/sun/star/frame/XStatusListener.hpp>
45 #include <com/sun/star/frame/FeatureStateEvent.hpp>
46 #include <com/sun/star/frame/XModel.hpp>
47 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
48 #include <com/sun/star/container/XNameAccess.hpp>
49 #include <com/sun/star/container/XEnumeration.hpp>
50 #include <com/sun/star/container/XIndexAccess.hpp>
51 #include <com/sun/star/awt/XControlModel.hpp>
52 #include <com/sun/star/awt/XControl.hpp>
53 #include <com/sun/star/awt/FontSlant.hpp>
54 #include <com/sun/star/awt/FontDescriptor.hpp>
55 #include <com/sun/star/awt/FontUnderline.hpp>
56 #include <com/sun/star/awt/FontStrikeout.hpp>
57 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
58 #include <com/sun/star/lang/XServiceInfo.hpp>
59 #include <com/sun/star/io/XObjectInputStream.hpp>
60 #include <com/sun/star/io/XObjectOutputStream.hpp>
61 #include <com/sun/star/io/XPersistObject.hpp>
62 #include <com/sun/star/util/XNumberFormatter.hpp>
63 #include <com/sun/star/util/XNumberFormats.hpp>
65 #include <tools/wintypes.hxx>
66 #include <cppuhelper/weakref.hxx>
67 #include <comphelper/uno3.hxx>
68 #include <comphelper/stl_types.hxx>
69 #include <cppuhelper/implbase1.hxx>
75 //==================================================================
77 //==================================================================
78 // displaying a database exception for the user
79 // display info about a simple ::com::sun::star::sdbc::SQLException
80 void displayException(const ::com::sun::star::sdbc::SQLException
&, Window
* _pParent
= NULL
);
81 void displayException(const ::com::sun::star::sdbc::SQLWarning
&, Window
* _pParent
= NULL
);
82 SVX_DLLPUBLIC
void displayException(const ::com::sun::star::sdb::SQLContext
&, Window
* _pParent
= NULL
);
83 void displayException(const ::com::sun::star::sdb::SQLErrorEvent
&, Window
* _pParent
= NULL
);
84 void displayException(const ::com::sun::star::uno::Any
&, Window
* _pParent
= NULL
);
86 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
);
88 SVX_DLLPUBLIC OUString
getLabelName(const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xControlModel
);
90 // ===================================================================================================
91 // = class CursorWrapper - a helper class which works in common with a ::com::sun::star::uno::Reference<XDatabaseUpdateCursor>,
92 // XDatabaseBookmarkCursor and XDatabaseDirectCursor each
93 // ===================================================================================================
98 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> m_xGeneric
;
99 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
> m_xMoveOperations
;
100 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbcx::XRowLocate
> m_xBookmarkOperations
;
101 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbcx::XColumnsSupplier
> m_xColumnsSupplier
;
102 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> m_xPropertyAccess
;
105 // Construction/Destruction
107 CursorWrapper(const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRowSet
>& _rxCursor
, sal_Bool bUseCloned
= sal_False
);
108 SVX_DLLPUBLIC
CursorWrapper(const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
>& _rxCursor
, sal_Bool bUseCloned
= sal_False
);
109 // if bUseCloned == sal_True, the cursor is first doubled over the XCloneable interface (which it must implement)
112 friend bool operator==(const CursorWrapper
& lhs
, const CursorWrapper
& rhs
)
114 return lhs
.m_xGeneric
.get() == rhs
.m_xGeneric
.get();
117 sal_Bool
is() const { return m_xMoveOperations
.is(); }
118 sal_Bool
Is() const { return m_xMoveOperations
.is(); }
120 CursorWrapper
* operator ->() { return this; }
121 operator const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& () const{ return m_xGeneric
; }
124 const CursorWrapper
& operator=(const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRowSet
>& xCursor
);
125 operator const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
>& () const { return m_xMoveOperations
; }
126 operator const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbcx::XRowLocate
>& () const { return m_xBookmarkOperations
; }
127 operator const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbcx::XColumnsSupplier
>& () const { return m_xColumnsSupplier
; }
129 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& getPropertySet() const { return m_xPropertyAccess
; }
130 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
>& getResultSet() const { return m_xMoveOperations
; }
131 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbcx::XRowLocate
>& getRowLocate() const { return m_xBookmarkOperations
; }
132 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbcx::XColumnsSupplier
>& getColumnsSupplier() const { return m_xColumnsSupplier
; }
134 // the usual queryInterface
135 ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& type
) throw ( ::com::sun::star::uno::RuntimeException
)
136 { return m_xMoveOperations
->queryInterface(type
); }
138 // ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XRowLocate>
139 ::com::sun::star::uno::Any
getBookmark(void)
140 throw( ::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
141 { return m_xBookmarkOperations
->getBookmark(); }
142 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
); }
143 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
); }
144 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
); }
145 sal_Int32
hasOrderedBookmarks(void) const throw( ::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
) { return m_xBookmarkOperations
->hasOrderedBookmarks(); }
146 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
); }
148 // ::com::sun::star::sdbc::XResultSet
149 sal_Bool
isBeforeFirst() const { return m_xMoveOperations
->isBeforeFirst(); }
150 sal_Bool
isAfterLast() const { return m_xMoveOperations
->isAfterLast(); }
151 sal_Bool
isFirst() const { return m_xMoveOperations
->isFirst(); }
152 sal_Bool
isLast() const { return m_xMoveOperations
->isLast(); }
153 void beforeFirst() { m_xMoveOperations
->beforeFirst(); }
154 sal_Bool
first() { return m_xMoveOperations
->first(); }
155 sal_Bool
last() { return m_xMoveOperations
->last(); }
156 sal_Int32
getRow() const { return m_xMoveOperations
->getRow(); }
157 sal_Bool
absolute(sal_Int32 nPosition
) { return m_xMoveOperations
->absolute(nPosition
); }
158 sal_Bool
relative(sal_Int32 nCount
) { return m_xMoveOperations
->relative(nCount
); }
159 sal_Bool
previous() { return m_xMoveOperations
->previous(); }
160 sal_Bool
next() { return m_xMoveOperations
->next(); }
161 void refreshRow() { m_xMoveOperations
->refreshRow(); }
162 sal_Bool
rowUpdated() { return m_xMoveOperations
->rowUpdated(); }
163 sal_Bool
rowInserted() { return m_xMoveOperations
->rowInserted(); }
164 sal_Bool
rowDeleted() { return m_xMoveOperations
->rowDeleted(); }
165 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> getStatement() { return m_xMoveOperations
->getStatement(); }
166 // ::com::sun::star::sdbcx::XColumnsSupplier
167 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
> getColumns() const throw( ::com::sun::star::uno::RuntimeException
) { return m_xColumnsSupplier
->getColumns(); }
169 void ImplConstruct(const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
>& _rxCursor
, sal_Bool bUseCloned
);
173 class FmXDisposeMultiplexer
;
174 class FmXDisposeListener
176 friend class FmXDisposeMultiplexer
;
178 FmXDisposeMultiplexer
* m_pAdapter
;
179 ::osl::Mutex
& m_rMutex
;
182 FmXDisposeListener(::osl::Mutex
& _rMutex
) : m_pAdapter(NULL
), m_rMutex(_rMutex
) { }
183 virtual ~FmXDisposeListener();
185 virtual void disposing(const ::com::sun::star::lang::EventObject
& _rEvent
, sal_Int16 _nId
) throw( ::com::sun::star::uno::RuntimeException
) = 0;
188 void setAdapter(FmXDisposeMultiplexer
* pAdapter
);
191 //==============================================================================
193 class FmXDisposeMultiplexer
:public ::cppu::WeakImplHelper1
< ::com::sun::star::lang::XEventListener
>
195 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XComponent
> m_xObject
;
196 FmXDisposeListener
* m_pListener
;
199 virtual ~FmXDisposeMultiplexer();
201 FmXDisposeMultiplexer(FmXDisposeListener
* _pListener
, const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XComponent
>& _rxObject
, sal_Int16 _nId
= -1);
203 // ::com::sun::star::lang::XEventListener
204 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw(::com::sun::star::uno::RuntimeException
);
209 // ==================================================================
211 sal_Int16
getControlTypeByObject(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XServiceInfo
>& _rxObject
);
212 // get the object type (OBJ_FM_...) from the services the object supports
214 //==================================================================
215 sal_Bool
isRowSetAlive(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxRowSet
);
216 // checks if the ::com::sun::star::sdbcx::XColumnsSupplier provided by _rxRowSet supllies any columns
218 //==================================================================
219 typedef ::std::set
< ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
220 , ::comphelper::OInterfaceCompare
< ::com::sun::star::uno::XInterface
>
223 #endif // _SVX_FMTOOLS_HXX
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */