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 .
23 #include <svx/fmgridcl.hxx>
25 #include <svx/fmgridif.hxx>
27 #include <com/sun/star/sdb/XSQLQueryComposer.hpp>
28 #include <com/sun/star/frame/XDispatch.hpp>
29 #include <com/sun/star/util/URL.hpp>
30 #include <comphelper/uno3.hxx>
31 #include <comphelper/stl_types.hxx>
32 #include "sbamultiplex.hxx"
33 #include <svx/dataaccessdescriptor.hxx>
36 class SvNumberFormatter
;
38 namespace com
{ namespace sun
{ namespace star
{
40 class XMultiServiceFactory
;
46 //------------------------------------------------------------------
47 struct SbaURLCompare
: public ::std::binary_function
< ::com::sun::star::util::URL
, ::com::sun::star::util::URL
, bool>
49 bool operator() (const ::com::sun::star::util::URL
& x
, const ::com::sun::star::util::URL
& y
) const {return x
.Complete
== y
.Complete
? true : false;}
54 sal_Int32
operator() (const ::com::sun::star::util::URL
& x
) const {return x
.Complete
.hashCode();}
56 //==================================================================
58 //==================================================================
60 class SbaXStatusMultiplexer
;
62 :public FmXGridControl
63 ,public ::com::sun::star::frame::XDispatch
65 DECLARE_STL_MAP(::com::sun::star::util::URL
, SbaXStatusMultiplexer
*, SbaURLCompare
,StatusMultiplexerArray
);
66 StatusMultiplexerArray m_aStatusMultiplexer
;
69 SbaXGridControl(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>&);
70 virtual ~SbaXGridControl();
73 DECLARE_UNO3_DEFAULTS(SbaXGridControl
, FmXGridControl
);
74 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface(const ::com::sun::star::uno::Type
& _rType
) throw (::com::sun::star::uno::RuntimeException
);
77 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
getTypes( ) throw (::com::sun::star::uno::RuntimeException
);
78 virtual ::com::sun::star::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId( ) throw (::com::sun::star::uno::RuntimeException
);
80 // ::com::sun::star::lang::XServiceInfo
81 OUString SAL_CALL
getImplementationName() throw();
82 virtual ::comphelper::StringSequence SAL_CALL
getSupportedServiceNames() throw();
83 // need by registration
84 static OUString
getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException
);
85 static ::com::sun::star::uno::Sequence
< OUString
> getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException
);
86 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
87 SAL_CALL
Create(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>&);
89 // ::com::sun::star::frame::XDispatch
90 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
);
91 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
);
92 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
);
94 // ::com::sun::star::lang::XComponent
95 virtual void SAL_CALL
dispose(void) throw( ::com::sun::star::uno::RuntimeException
);
97 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
);
100 virtual FmXGridPeer
* imp_CreatePeer(Window
* pParent
);
103 //==================================================================
105 //==================================================================
109 ,public ::com::sun::star::frame::XDispatch
111 ::cppu::OMultiTypeInterfaceContainerHelperVar
< ::com::sun::star::util::URL
,SbaURLHash
, SbaURLCompare
> m_aStatusListeners
;
114 SbaXGridPeer(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>&);
115 virtual ~SbaXGridPeer();
118 virtual void SAL_CALL
acquire() throw() { FmXGridPeer::acquire(); }
119 virtual void SAL_CALL
release() throw() { FmXGridPeer::release(); }
120 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface(const ::com::sun::star::uno::Type
& _rType
) throw (::com::sun::star::uno::RuntimeException
);
122 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
getTypes() throw (::com::sun::star::uno::RuntimeException
);
124 static const ::com::sun::star::uno::Sequence
< sal_Int8
>& getUnoTunnelId();
125 sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
> & rId
) throw (::com::sun::star::uno::RuntimeException
);
126 static SbaXGridPeer
* getImplementation(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxIFace
);
128 // ::com::sun::star::frame::XDispatch
129 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
);
130 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
);
131 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
);
133 // ::com::sun::star::frame::XDispatchProvider
134 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatch
> SAL_CALL
queryDispatch(const ::com::sun::star::util::URL
& aURL
, const OUString
& aTargetFrameName
, sal_Int32 nSearchFlags
) throw( ::com::sun::star::uno::RuntimeException
);
136 // ::com::sun::star::lang::XComponent
137 virtual void SAL_CALL
dispose(void) throw( ::com::sun::star::uno::RuntimeException
);
140 virtual FmGridControl
* imp_CreateControl(Window
* pParent
, WinBits nStyle
);
142 typedef ::com::sun::star::frame::XStatusListener xstlist_type
;
143 typedef ::com::sun::star::uno::Reference
< xstlist_type
> xlistener_type
;
144 void NotifyStatusChanged(const ::com::sun::star::util::URL
& aUrl
, const xlistener_type
& xControl
= xlistener_type() );
146 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
> ());
150 // for asny execution of XDispatch::dispatch
153 ::com::sun::star::util::URL aURL
;
154 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aArgs
;
156 ::std::queue
< DispatchArgs
> m_aDispatchArgs
;
157 DECL_LINK( OnDispatchEvent
, void* );
159 // for dynamic states of our 4 dispatchable URLs
169 DispatchType
classifyDispatchURL( const ::com::sun::star::util::URL
& _rURL
);
171 DECLARE_STL_STDKEY_MAP( DispatchType
, sal_Bool
, MapDispatchToBool
);
172 MapDispatchToBool m_aDispatchStates
;
175 //==================================================================
177 //==================================================================
181 ,public DragSourceHelper
184 SbaGridHeader(BrowseBox
* pParent
, WinBits nWinBits
= WB_STDHEADERBAR
| WB_DRAG
);
188 // FmGridHeader overridables
189 virtual void PreExecuteColumnContextMenu(sal_uInt16 nColId
, PopupMenu
& rMenu
);
190 virtual void PostExecuteColumnContextMenu(sal_uInt16 nColId
, const PopupMenu
& rMenu
, sal_uInt16 nExecutionResult
);
193 // DragSourceHelper overridables
194 virtual void StartDrag( sal_Int8 _nAction
, const Point
& _rPosPixel
);
196 // Window overridables
197 virtual void MouseButtonDown( const MouseEvent
& rMEvt
);
199 sal_Bool
ImplStartColumnDrag(sal_Int8 _nAction
, const Point
& _rMousePos
);
202 using FmGridHeader::StartDrag
;
205 // =========================================================================
206 // interfaces for communication between the vcl grid control and a controller
207 // -------------------------------------------------------------------------
208 class SbaGridListener
211 virtual void RowChanged() = 0;
212 virtual void ColumnChanged() = 0;
213 virtual void SelectionChanged() = 0;
214 virtual void CellActivated() = 0;
215 virtual void CellDeactivated() = 0;
216 virtual void BeforeDrop() = 0;
217 virtual void AfterDrop() = 0;
220 ~SbaGridListener() {}
223 //==================================================================
225 //==================================================================
226 //------------------------------------------------------------------
227 class SbaGridControl
: public FmGridControl
229 friend class SbaGridHeader
;
230 friend class SbaXGridPeer
;
234 ::svx::ODataAccessDescriptor m_aDataDescriptor
;
235 SbaGridListener
* m_pMasterListener
;
237 sal_Int32 m_nAsyncDropEvent
;
239 sal_uInt16 m_nCurrentActionColId
;
240 // ui actions (e.g. a context menu) may be performed on columns which aren't the current one
241 // and aren't selected, so we have to track this column id
243 sal_Bool m_bActivatingForDrop
;
246 sal_uInt16
GetCurrentActionColumn() const { return m_nCurrentActionColId
; }
249 SbaGridControl(::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>,Window
* pParent
, FmXGridPeer
* _pPeer
, WinBits nBits
= WB_TABSTOP
);
250 virtual ~SbaGridControl();
252 virtual void Command( const CommandEvent
& rCEvt
);
253 virtual void Select();
255 void SetMasterListener(SbaGridListener
* pListener
) { m_pMasterListener
= pListener
; }
257 virtual void ActivateCell(long nRow
, sal_uInt16 nCol
, sal_Bool bSetCellFocus
= sal_True
);
258 virtual void DeactivateCell(sal_Bool bUpdate
= sal_True
);
259 void ActivateCell() { FmGridControl::ActivateCell(); }
261 sal_Bool
IsAllSelected() const { return (GetSelectRowCount() == GetRowCount()) && (GetRowCount() > 0); }
263 HeaderBar
* GetHeaderBar() const { return FmGridControl::GetHeaderBar(); }
265 /** return the description of the specified object.
269 The position of a tablecell (index position), header bar colum/row cell
271 The description of the specified object.
273 virtual OUString
GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType eObjType
,sal_Int32 _nPosition
= -1) const;
275 virtual void DeleteSelectedRows();
276 /** copies the currently selected rows to the clipboard
278 at least one row is selected
280 void CopySelectedRowsToClipboard();
284 // DragSourceHelper overridables
285 virtual void StartDrag( sal_Int8 _nAction
, const Point
& _rPosPixel
);
287 // BrowseBox overridables
288 virtual void CursorMoved();
289 virtual sal_Int8
AcceptDrop( const BrowserAcceptDropEvent
& rEvt
);
290 virtual sal_Int8
ExecuteDrop( const BrowserExecuteDropEvent
& rEvt
);
291 virtual void MouseButtonDown( const BrowserMouseEvent
& rMEvt
);
293 // EditBrowseBox overridables
294 virtual BrowserHeader
* imp_CreateHeaderBar(BrowseBox
* pParent
);
295 virtual ::svt::CellController
* GetController(long nRow
, sal_uInt16 nCol
);
297 // DbGridControl overridables
298 virtual void PreExecuteRowContextMenu(sal_uInt16 nRow
, PopupMenu
& rMenu
);
299 virtual void PostExecuteRowContextMenu(sal_uInt16 nRow
, const PopupMenu
& rMenu
, sal_uInt16 nExecutionResult
);
301 // DbGridControl overridables
302 virtual void onRowChange();
303 virtual void onColumnChange();
305 // my own overridables
306 virtual void BeforeDrop();
307 virtual void AfterDrop();
309 // get a fields property set from a model pos
310 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> getField(sal_uInt16 nModelPos
);
312 // get my data source
313 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> getDataSource() const;
316 virtual void DoColumnDrag(sal_uInt16 nColumnPos
);
317 virtual void DoRowDrag(sal_Int16 nRowPos
);
318 virtual void DoFieldDrag(sal_uInt16 nColumnPos
, sal_Int16 nRowPos
);
320 void SetBrowserAttrs();
321 void SetColWidth(sal_uInt16 nColId
);
323 void SetColAttrs(sal_uInt16 nColId
);
325 SvNumberFormatter
* GetDatasourceFormatter();
327 DECL_LINK(AsynchDropEvent
, void*);
330 sal_Bool
IsReadOnlyDB() const;
331 void implTransferSelectedRows( sal_Int16 nRowPos
, bool _bTrueIfClipboardFalseIfDrag
);
334 using FmGridControl::AcceptDrop
;
335 using FmGridControl::ExecuteDrop
;
336 using FmGridControl::MouseButtonDown
;
339 #endif // _SBA_GRID_HXX
341 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */