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: sbagrid.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 ************************************************************************/
34 // #include <sdb/tools.hxx>
36 #ifndef _SVX_FMGRIDCL_HXX
37 #include <svx/fmgridcl.hxx>
40 #ifndef _SVX_FMGRIDIF_HXX
41 #include <svx/fmgridif.hxx>
44 #ifndef _COM_SUN_STAR_SDB_XSQLQUERYCOMPOSER_HPP_
45 #include <com/sun/star/sdb/XSQLQueryComposer.hpp>
47 #ifndef _COM_SUN_STAR_FRAME_XDISPATCH_HPP_
48 #include <com/sun/star/frame/XDispatch.hpp>
50 #ifndef _COM_SUN_STAR_UTIL_URL_HPP_
51 #include <com/sun/star/util/URL.hpp>
53 #ifndef _COMPHELPER_UNO3_HXX_
54 #include <comphelper/uno3.hxx>
56 #ifndef _COMPHELPER_STLTYPES_HXX_
57 #include <comphelper/stl_types.hxx>
59 #ifndef _SBA_MULTIPLEX_HXX
60 #include "sbamultiplex.hxx"
62 #ifndef _SVX_DATACCESSDESCRIPTOR_HXX_
63 #include <svx/dataaccessdescriptor.hxx>
67 class SvNumberFormatter
;
71 //------------------------------------------------------------------
72 struct SbaURLCompare
: public ::std::binary_function
< ::com::sun::star::util::URL
, ::com::sun::star::util::URL
, bool>
74 bool operator() (const ::com::sun::star::util::URL
& x
, const ::com::sun::star::util::URL
& y
) const {return x
.Complete
== y
.Complete
? true : false;}
79 sal_Int32
operator() (const ::com::sun::star::util::URL
& x
) const {return x
.Complete
.hashCode();}
81 //==================================================================
83 //==================================================================
85 // class ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > ;
86 FORWARD_DECLARE_INTERFACE(lang
,XMultiServiceFactory
)
88 class SbaXStatusMultiplexer
;
90 :public FmXGridControl
91 ,public ::com::sun::star::frame::XDispatch
93 DECLARE_STL_MAP(::com::sun::star::util::URL
, SbaXStatusMultiplexer
*, SbaURLCompare
,StatusMultiplexerArray
);
94 StatusMultiplexerArray m_aStatusMultiplexer
;
97 SbaXGridControl(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>&);
98 virtual ~SbaXGridControl();
101 DECLARE_UNO3_DEFAULTS(SbaXGridControl
, FmXGridControl
);
102 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface(const ::com::sun::star::uno::Type
& _rType
) throw (::com::sun::star::uno::RuntimeException
);
105 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
getTypes( ) throw (::com::sun::star::uno::RuntimeException
);
106 virtual ::com::sun::star::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId( ) throw (::com::sun::star::uno::RuntimeException
);
108 // ::com::sun::star::lang::XServiceInfo
109 ::rtl::OUString SAL_CALL
getImplementationName() throw();
110 virtual ::comphelper::StringSequence SAL_CALL
getSupportedServiceNames() throw();
111 // need by registration
112 static ::rtl::OUString
getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException
);
113 static ::com::sun::star::uno::Sequence
< ::rtl::OUString
> getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException
);
114 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
115 SAL_CALL
Create(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>&);
117 // ::com::sun::star::frame::XDispatch
118 virtual void SAL_CALL
dispatch(const ::com::sun::star::util::URL
& aURL
, const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aArgs
) throw( ::com::sun::star::uno::RuntimeException
);
119 virtual void SAL_CALL
addStatusListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XStatusListener
> & xControl
, const ::com::sun::star::util::URL
& aURL
) throw( ::com::sun::star::uno::RuntimeException
);
120 virtual void SAL_CALL
removeStatusListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XStatusListener
> & xControl
, const ::com::sun::star::util::URL
& aURL
) throw( ::com::sun::star::uno::RuntimeException
);
122 // ::com::sun::star::lang::XComponent
123 virtual void SAL_CALL
dispose(void) throw( ::com::sun::star::uno::RuntimeException
);
125 virtual void SAL_CALL
createPeer(const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XToolkit
> & rToolkit
, const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
> & rParentPeer
) throw( ::com::sun::star::uno::RuntimeException
);
128 virtual FmXGridPeer
* imp_CreatePeer(Window
* pParent
);
131 //==================================================================
133 //==================================================================
137 ,public ::com::sun::star::frame::XDispatch
139 ::cppu::OMultiTypeInterfaceContainerHelperVar
< ::com::sun::star::util::URL
,SbaURLHash
, SbaURLCompare
> m_aStatusListeners
;
142 SbaXGridPeer(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>&);
143 virtual ~SbaXGridPeer();
146 virtual void SAL_CALL
acquire() throw() { FmXGridPeer::acquire(); }
147 virtual void SAL_CALL
release() throw() { FmXGridPeer::release(); }
148 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface(const ::com::sun::star::uno::Type
& _rType
) throw (::com::sun::star::uno::RuntimeException
);
150 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
getTypes() throw (::com::sun::star::uno::RuntimeException
);
152 static const ::com::sun::star::uno::Sequence
< sal_Int8
>& getUnoTunnelId();
153 sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
> & rId
) throw (::com::sun::star::uno::RuntimeException
);
154 static SbaXGridPeer
* getImplementation(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxIFace
);
156 // ::com::sun::star::frame::XDispatch
157 virtual void SAL_CALL
dispatch(const ::com::sun::star::util::URL
& aURL
, const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aArgs
) throw( ::com::sun::star::uno::RuntimeException
);
158 virtual void SAL_CALL
addStatusListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XStatusListener
> & xControl
, const ::com::sun::star::util::URL
& aURL
) throw( ::com::sun::star::uno::RuntimeException
);
159 virtual void SAL_CALL
removeStatusListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XStatusListener
> & xControl
, const ::com::sun::star::util::URL
& aURL
) throw( ::com::sun::star::uno::RuntimeException
);
161 // ::com::sun::star::frame::XDispatchProvider
162 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
);
164 // ::com::sun::star::lang::XComponent
165 virtual void SAL_CALL
dispose(void) throw( ::com::sun::star::uno::RuntimeException
);
168 virtual FmGridControl
* imp_CreateControl(Window
* pParent
, WinBits nStyle
);
169 #if defined(_MSC_VER) && (_MSC_VER >= 1310 )
170 typedef ::com::sun::star::frame::XStatusListener xstlist_type
;
171 typedef ::com::sun::star::uno::Reference
< xstlist_type
> xlistener_type
;
172 void NotifyStatusChanged(const ::com::sun::star::util::URL
& aUrl
, const xlistener_type
& xControl
= xlistener_type() );
174 void NotifyStatusChanged(const ::com::sun::star::util::URL
& aUrl
, const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XStatusListener
> & xControl
= ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XStatusListener
> ());
175 #endif // # _MSC_VER>=1310
178 // for asny execution of XDispatch::dispatch
181 ::com::sun::star::util::URL aURL
;
182 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aArgs
;
184 ::std::queue
< DispatchArgs
> m_aDispatchArgs
;
185 DECL_LINK( OnDispatchEvent
, void* );
187 // for dynamic states of our 4 dispatchable URLs
197 DispatchType
classifyDispatchURL( const ::com::sun::star::util::URL
& _rURL
);
199 DECLARE_STL_STDKEY_MAP( DispatchType
, sal_Bool
, MapDispatchToBool
);
200 MapDispatchToBool m_aDispatchStates
;
203 //==================================================================
205 //==================================================================
209 ,public DragSourceHelper
212 SbaGridHeader(BrowseBox
* pParent
, WinBits nWinBits
= WB_STDHEADERBAR
| WB_DRAG
);
216 // FmGridHeader overridables
217 virtual void PreExecuteColumnContextMenu(sal_uInt16 nColId
, PopupMenu
& rMenu
);
218 virtual void PostExecuteColumnContextMenu(sal_uInt16 nColId
, const PopupMenu
& rMenu
, sal_uInt16 nExecutionResult
);
221 // DragSourceHelper overridables
222 virtual void StartDrag( sal_Int8 _nAction
, const Point
& _rPosPixel
);
224 // Window overridables
225 virtual void MouseButtonDown( const MouseEvent
& rMEvt
);
227 sal_Bool
ImplStartColumnDrag(sal_Int8 _nAction
, const Point
& _rMousePos
);
230 using FmGridHeader::StartDrag
;
233 // =========================================================================
234 // interfaces for communication between the vcl grid control and a controller
235 // -------------------------------------------------------------------------
236 class SbaGridListener
239 virtual void RowChanged() = 0;
240 virtual void ColumnChanged() = 0;
241 virtual void SelectionChanged() = 0;
242 virtual void CellActivated() = 0;
243 virtual void CellDeactivated() = 0;
244 virtual void BeforeDrop() = 0;
245 virtual void AfterDrop() = 0;
248 //==================================================================
250 //==================================================================
251 //------------------------------------------------------------------
252 class UnoDataBrowserController
;
253 class SbaGridControl
: public FmGridControl
255 friend class SbaGridHeader
;
256 friend class SbaXGridPeer
;
260 ::svx::ODataAccessDescriptor m_aDataDescriptor
;
261 SbaGridListener
* m_pMasterListener
;
263 sal_Int32 m_nAsyncDropEvent
;
265 USHORT m_nCurrentActionColId
;
266 // ui actions (e.g. a context menu) may be performed on columns which aren't the current one
267 // and aren't selected, so we have to track this column id
269 sal_Bool m_bActivatingForDrop
;
272 sal_uInt16
GetCurrentActionColumn() const { return m_nCurrentActionColId
; }
275 SbaGridControl(::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>,Window
* pParent
, FmXGridPeer
* _pPeer
, WinBits nBits
= WB_TABSTOP
);
276 virtual ~SbaGridControl();
278 virtual void Command( const CommandEvent
& rCEvt
);
279 virtual void Select();
281 void SetMasterListener(SbaGridListener
* pListener
) { m_pMasterListener
= pListener
; }
283 virtual void ActivateCell(long nRow
, sal_uInt16 nCol
, sal_Bool bSetCellFocus
= sal_True
);
284 virtual void DeactivateCell(sal_Bool bUpdate
= sal_True
);
285 void ActivateCell() { FmGridControl::ActivateCell(); }
287 sal_Bool
IsAllSelected() const { return (GetSelectRowCount() == GetRowCount()) && (GetRowCount() > 0); }
289 HeaderBar
* GetHeaderBar() const { return FmGridControl::GetHeaderBar(); }
291 /** return the description of the specified object.
295 The position of a tablecell (index position), header bar colum/row cell
297 The description of the specified object.
299 virtual ::rtl::OUString
GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType eObjType
,sal_Int32 _nPosition
= -1) const;
301 virtual void DeleteSelectedRows();
302 /** copies the currently selected rows to the clipboard
304 at least one row is selected
306 void CopySelectedRowsToClipboard();
310 // DragSourceHelper overridables
311 virtual void StartDrag( sal_Int8 _nAction
, const Point
& _rPosPixel
);
313 // BrowseBox overridables
314 virtual void CursorMoved();
315 virtual sal_Int8
AcceptDrop( const BrowserAcceptDropEvent
& rEvt
);
316 virtual sal_Int8
ExecuteDrop( const BrowserExecuteDropEvent
& rEvt
);
317 virtual void MouseButtonDown( const BrowserMouseEvent
& rMEvt
);
319 // EditBrowseBox overridables
320 virtual BrowserHeader
* imp_CreateHeaderBar(BrowseBox
* pParent
);
321 virtual ::svt::CellController
* GetController(long nRow
, sal_uInt16 nCol
);
323 // DbGridControl overridables
324 virtual void PreExecuteRowContextMenu(sal_uInt16 nRow
, PopupMenu
& rMenu
);
325 virtual void PostExecuteRowContextMenu(sal_uInt16 nRow
, const PopupMenu
& rMenu
, sal_uInt16 nExecutionResult
);
327 // DbGridControl overridables
328 virtual void onRowChange();
329 virtual void onColumnChange();
331 // my own overridables
332 virtual void BeforeDrop();
333 virtual void AfterDrop();
335 // get a fields property set from a model pos
336 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> getField(sal_uInt16 nModelPos
);
338 // get my data source
339 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> getDataSource() const;
342 virtual void DoColumnDrag(sal_uInt16 nColumnPos
);
343 virtual void DoRowDrag(sal_Int16 nRowPos
);
344 virtual void DoFieldDrag(sal_uInt16 nColumnPos
, sal_Int16 nRowPos
);
346 void SetBrowserAttrs();
347 void SetColWidth(sal_uInt16 nColId
);
349 void SetColAttrs(sal_uInt16 nColId
);
351 SvNumberFormatter
* GetDatasourceFormatter();
353 DECL_LINK(AsynchDropEvent
, void*);
356 sal_Bool
IsReadOnlyDB() const;
357 void implTransferSelectedRows( sal_Int16 nRowPos
, bool _bTrueIfClipboardFalseIfDrag
);
360 using FmGridControl::AcceptDrop
;
361 using FmGridControl::ExecuteDrop
;
362 using FmGridControl::MouseButtonDown
;
365 #endif // _SBA_GRID_HXX