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 .
20 #ifndef INCLUDED_DBACCESS_SOURCE_UI_INC_SBAGRID_HXX
21 #define INCLUDED_DBACCESS_SOURCE_UI_INC_SBAGRID_HXX
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 "sbamultiplex.hxx"
32 #include <svx/dataaccessdescriptor.hxx>
36 class SvNumberFormatter
;
38 namespace com
{ namespace sun
{ namespace star
{
40 class XMultiServiceFactory
;
46 struct SbaURLCompare
: public ::std::binary_function
< css::util::URL
, css::util::URL
, bool>
48 bool operator() (const css::util::URL
& x
, const css::util::URL
& y
) const { return x
.Complete
== y
.Complete
; }
51 class SbaXStatusMultiplexer
;
53 :public FmXGridControl
54 ,public css::frame::XDispatch
56 typedef std::map
<css::util::URL
, SbaXStatusMultiplexer
*, SbaURLCompare
> StatusMultiplexerArray
;
57 StatusMultiplexerArray m_aStatusMultiplexer
;
60 SbaXGridControl(const css::uno::Reference
< css::uno::XComponentContext
>&);
61 virtual ~SbaXGridControl();
64 DECLARE_UNO3_DEFAULTS(SbaXGridControl
, FmXGridControl
)
65 virtual css::uno::Any SAL_CALL
queryInterface(const css::uno::Type
& _rType
) throw (css::uno::RuntimeException
, std::exception
) override
;
68 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes( ) throw (css::uno::RuntimeException
, std::exception
) override
;
69 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId( ) throw (css::uno::RuntimeException
, std::exception
) override
;
71 // css::lang::XServiceInfo
72 OUString SAL_CALL
getImplementationName() throw(std::exception
) override
;
73 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() throw(std::exception
) override
;
74 // need by registration
75 static OUString
getImplementationName_Static() throw( css::uno::RuntimeException
);
76 static css::uno::Sequence
< OUString
> getSupportedServiceNames_Static() throw( css::uno::RuntimeException
);
77 static css::uno::Reference
< css::uno::XInterface
>
78 SAL_CALL
Create(const css::uno::Reference
< css::lang::XMultiServiceFactory
>&);
80 // css::frame::XDispatch
81 virtual void SAL_CALL
dispatch(const css::util::URL
& aURL
, const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
) throw( css::uno::RuntimeException
, std::exception
) override
;
82 virtual void SAL_CALL
addStatusListener(const css::uno::Reference
< css::frame::XStatusListener
> & xControl
, const css::util::URL
& aURL
) throw( css::uno::RuntimeException
, std::exception
) override
;
83 virtual void SAL_CALL
removeStatusListener(const css::uno::Reference
< css::frame::XStatusListener
> & xControl
, const css::util::URL
& aURL
) throw( css::uno::RuntimeException
, std::exception
) override
;
85 // css::lang::XComponent
86 virtual void SAL_CALL
dispose() throw( css::uno::RuntimeException
, std::exception
) override
;
88 virtual void SAL_CALL
createPeer(const css::uno::Reference
< css::awt::XToolkit
> & rToolkit
, const css::uno::Reference
< css::awt::XWindowPeer
> & rParentPeer
) throw( css::uno::RuntimeException
, std::exception
) override
;
91 virtual FmXGridPeer
* imp_CreatePeer(vcl::Window
* pParent
) override
;
98 ,public css::frame::XDispatch
100 cppu::OMultiTypeInterfaceContainerHelperVar
<
101 css::util::URL
, void, SbaURLCompare
> m_aStatusListeners
;
104 SbaXGridPeer(const css::uno::Reference
< css::uno::XComponentContext
>&);
105 virtual ~SbaXGridPeer();
108 virtual void SAL_CALL
acquire() throw() override
{ FmXGridPeer::acquire(); }
109 virtual void SAL_CALL
release() throw() override
{ FmXGridPeer::release(); }
110 virtual css::uno::Any SAL_CALL
queryInterface(const css::uno::Type
& _rType
) throw (css::uno::RuntimeException
, std::exception
) override
;
112 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes() throw (css::uno::RuntimeException
, std::exception
) override
;
114 static const css::uno::Sequence
< sal_Int8
>& getUnoTunnelId();
115 sal_Int64 SAL_CALL
getSomething( const css::uno::Sequence
< sal_Int8
> & rId
) throw (css::uno::RuntimeException
, std::exception
) override
;
116 static SbaXGridPeer
* getImplementation(const css::uno::Reference
< css::uno::XInterface
>& _rxIFace
);
118 // css::frame::XDispatch
119 virtual void SAL_CALL
dispatch(const css::util::URL
& aURL
, const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
) throw( css::uno::RuntimeException
, std::exception
) override
;
120 virtual void SAL_CALL
addStatusListener(const css::uno::Reference
< css::frame::XStatusListener
> & xControl
, const css::util::URL
& aURL
) throw( css::uno::RuntimeException
, std::exception
) override
;
121 virtual void SAL_CALL
removeStatusListener(const css::uno::Reference
< css::frame::XStatusListener
> & xControl
, const css::util::URL
& aURL
) throw( css::uno::RuntimeException
, std::exception
) override
;
123 // css::frame::XDispatchProvider
124 virtual css::uno::Reference
< css::frame::XDispatch
> SAL_CALL
queryDispatch(const css::util::URL
& aURL
, const OUString
& aTargetFrameName
, sal_Int32 nSearchFlags
) throw( css::uno::RuntimeException
, std::exception
) override
;
126 // css::lang::XComponent
127 virtual void SAL_CALL
dispose() throw( css::uno::RuntimeException
, std::exception
) override
;
130 virtual VclPtr
<FmGridControl
> imp_CreateControl(vcl::Window
* pParent
, WinBits nStyle
) override
;
132 typedef css::frame::XStatusListener xstlist_type
;
133 typedef css::uno::Reference
< xstlist_type
> xlistener_type
;
134 void NotifyStatusChanged(const css::util::URL
& aUrl
, const xlistener_type
& xControl
= xlistener_type() );
136 void NotifyStatusChanged(const css::util::URL
& aUrl
, const css::uno::Reference
< css::frame::XStatusListener
> & xControl
= css::uno::Reference
< css::frame::XStatusListener
> ());
140 // for any execution of XDispatch::dispatch
144 css::uno::Sequence
< css::beans::PropertyValue
> aArgs
;
146 ::std::queue
< DispatchArgs
> m_aDispatchArgs
;
147 DECL_LINK_TYPED( OnDispatchEvent
, void*, void );
149 // for dynamic states of our 4 dispatchable URLs
159 static DispatchType
classifyDispatchURL( const css::util::URL
& _rURL
);
161 typedef std::map
<DispatchType
, sal_Bool
> MapDispatchToBool
;
162 MapDispatchToBool m_aDispatchStates
;
169 ,public DragSourceHelper
172 SbaGridHeader(BrowseBox
* pParent
, WinBits nWinBits
= WB_STDHEADERBAR
| WB_DRAG
);
176 // FmGridHeader overridables
177 virtual void PreExecuteColumnContextMenu(sal_uInt16 nColId
, PopupMenu
& rMenu
) override
;
178 virtual void PostExecuteColumnContextMenu(sal_uInt16 nColId
, const PopupMenu
& rMenu
, sal_uInt16 nExecutionResult
) override
;
181 // DragSourceHelper overridables
182 virtual void StartDrag( sal_Int8 _nAction
, const Point
& _rPosPixel
) override
;
184 // Window overridables
185 virtual void MouseButtonDown( const MouseEvent
& rMEvt
) override
;
187 void ImplStartColumnDrag(sal_Int8 _nAction
, const Point
& _rMousePos
);
190 using FmGridHeader::StartDrag
;
193 // interfaces for communication between the vcl grid control and a controller
194 class SbaGridListener
197 virtual void RowChanged() = 0;
198 virtual void ColumnChanged() = 0;
199 virtual void SelectionChanged() = 0;
200 virtual void CellActivated() = 0;
201 virtual void CellDeactivated() = 0;
202 virtual void BeforeDrop() = 0;
203 virtual void AfterDrop() = 0;
206 ~SbaGridListener() {}
210 class SbaGridControl
: public FmGridControl
212 friend class SbaGridHeader
;
213 friend class SbaXGridPeer
;
217 svx::ODataAccessDescriptor m_aDataDescriptor
;
218 SbaGridListener
* m_pMasterListener
;
220 ImplSVEvent
* m_nAsyncDropEvent
;
222 bool m_bActivatingForDrop
;
225 SbaGridControl(css::uno::Reference
< css::uno::XComponentContext
>,Window
* pParent
, FmXGridPeer
* _pPeer
, WinBits nBits
= WB_TABSTOP
);
226 virtual ~SbaGridControl();
227 virtual void dispose() override
;
229 virtual void Command( const CommandEvent
& rCEvt
) override
;
230 virtual void Select() override
;
232 void SetMasterListener(SbaGridListener
* pListener
) { m_pMasterListener
= pListener
; }
234 virtual void ActivateCell(long nRow
, sal_uInt16 nCol
, bool bSetCellFocus
= true) override
;
235 virtual void DeactivateCell(bool bUpdate
= true) override
;
236 void ActivateCell() { FmGridControl::ActivateCell(); }
238 bool IsAllSelected() const { return (GetSelectRowCount() == GetRowCount()) && (GetRowCount() > 0); }
240 HeaderBar
* GetHeaderBar() const { return FmGridControl::GetHeaderBar(); }
242 /** return the description of the specified object.
246 The position of a tablecell (index position), header bar column/row cell
248 The description of the specified object.
250 virtual OUString
GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType eObjType
,sal_Int32 _nPosition
= -1) const override
;
252 virtual void DeleteSelectedRows() override
;
253 /** copies the currently selected rows to the clipboard
255 at least one row is selected
257 void CopySelectedRowsToClipboard();
260 // DragSourceHelper overridables
261 virtual void StartDrag( sal_Int8 _nAction
, const Point
& _rPosPixel
) override
;
263 // BrowseBox overridables
264 virtual void CursorMoved() override
;
265 virtual sal_Int8
AcceptDrop( const BrowserAcceptDropEvent
& rEvt
) override
;
266 virtual sal_Int8
ExecuteDrop( const BrowserExecuteDropEvent
& rEvt
) override
;
267 virtual void MouseButtonDown( const BrowserMouseEvent
& rMEvt
) override
;
269 // EditBrowseBox overridables
270 virtual VclPtr
<BrowserHeader
> imp_CreateHeaderBar(BrowseBox
* pParent
) override
;
271 virtual ::svt::CellController
* GetController(long nRow
, sal_uInt16 nCol
) override
;
273 // DbGridControl overridables
274 virtual void PreExecuteRowContextMenu(sal_uInt16 nRow
, PopupMenu
& rMenu
) override
;
275 virtual void PostExecuteRowContextMenu(sal_uInt16 nRow
, const PopupMenu
& rMenu
, sal_uInt16 nExecutionResult
) override
;
277 // DbGridControl overridables
278 virtual void onRowChange() override
;
279 virtual void onColumnChange() override
;
281 // my own overridables
285 // get a fields property set from a model pos
286 css::uno::Reference
< css::beans::XPropertySet
> getField(sal_uInt16 nModelPos
);
288 // get my data source
289 css::uno::Reference
< css::beans::XPropertySet
> getDataSource() const;
292 void DoColumnDrag(sal_uInt16 nColumnPos
);
293 void DoRowDrag(sal_Int16 nRowPos
);
294 void DoFieldDrag(sal_uInt16 nColumnPos
, sal_Int16 nRowPos
);
296 void SetBrowserAttrs();
297 void SetColWidth(sal_uInt16 nColId
);
299 void SetColAttrs(sal_uInt16 nColId
);
301 SvNumberFormatter
* GetDatasourceFormatter();
303 DECL_LINK_TYPED(AsynchDropEvent
, void*, void);
306 bool IsReadOnlyDB() const;
307 void implTransferSelectedRows( sal_Int16 nRowPos
, bool _bTrueIfClipboardFalseIfDrag
);
310 using FmGridControl::AcceptDrop
;
311 using FmGridControl::ExecuteDrop
;
312 using FmGridControl::MouseButtonDown
;
315 #endif // INCLUDED_DBACCESS_SOURCE_UI_INC_SBAGRID_HXX
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */