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 .
22 #include <svx/fmgridcl.hxx>
24 #include <svx/fmgridif.hxx>
26 #include <com/sun/star/frame/XDispatch.hpp>
27 #include <com/sun/star/util/URL.hpp>
28 #include <comphelper/multiinterfacecontainer4.hxx>
29 #include <comphelper/servicehelper.hxx>
30 #include <comphelper/uno3.hxx>
31 #include "sbamultiplex.hxx"
32 #include <svx/dataaccessdescriptor.hxx>
33 #include <rtl/ref.hxx>
37 class SvNumberFormatter
;
39 namespace com::sun::star
{
41 class XMultiServiceFactory
;
49 bool operator() (const css::util::URL
& x
, const css::util::URL
& y
) const { return x
.Complete
== y
.Complete
; }
52 class SbaXStatusMultiplexer
;
54 :public FmXGridControl
55 ,public css::frame::XDispatch
57 typedef std::map
<css::util::URL
, rtl::Reference
<SbaXStatusMultiplexer
>, SbaURLCompare
> StatusMultiplexerArray
;
58 StatusMultiplexerArray m_aStatusMultiplexer
;
61 SbaXGridControl(const css::uno::Reference
< css::uno::XComponentContext
>&);
62 virtual ~SbaXGridControl() override
;
65 DECLARE_UNO3_AGG_DEFAULTS(SbaXGridControl
, FmXGridControl
)
66 virtual css::uno::Any SAL_CALL
queryAggregation(const css::uno::Type
& _rType
) override
;
69 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes( ) override
;
70 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId( ) override
;
72 // css::lang::XServiceInfo
73 OUString SAL_CALL
getImplementationName() override
;
74 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
76 // css::frame::XDispatch
77 virtual void SAL_CALL
dispatch(const css::util::URL
& aURL
, const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
) override
;
78 virtual void SAL_CALL
addStatusListener(const css::uno::Reference
< css::frame::XStatusListener
> & xControl
, const css::util::URL
& aURL
) override
;
79 virtual void SAL_CALL
removeStatusListener(const css::uno::Reference
< css::frame::XStatusListener
> & xControl
, const css::util::URL
& aURL
) override
;
81 // css::lang::XComponent
82 virtual void SAL_CALL
dispose() override
;
84 virtual void SAL_CALL
createPeer(const css::uno::Reference
< css::awt::XToolkit
> & rToolkit
, const css::uno::Reference
< css::awt::XWindowPeer
> & rParentPeer
) override
;
87 virtual rtl::Reference
<FmXGridPeer
> imp_CreatePeer(vcl::Window
* pParent
) override
;
92 class SbaXGridPeer final
94 ,public css::frame::XDispatch
96 comphelper::OMultiTypeInterfaceContainerHelperVar4
< css::util::URL
, css::frame::XStatusListener
,
97 SbaURLCompare
> m_aStatusListeners
;
100 SbaXGridPeer(const css::uno::Reference
< css::uno::XComponentContext
>&);
101 virtual ~SbaXGridPeer() override
;
104 virtual void SAL_CALL
acquire() noexcept override
{ FmXGridPeer::acquire(); }
105 virtual void SAL_CALL
release() noexcept override
{ FmXGridPeer::release(); }
106 virtual css::uno::Any SAL_CALL
queryInterface(const css::uno::Type
& _rType
) override
;
108 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes() override
;
110 // css::frame::XDispatch
111 virtual void SAL_CALL
dispatch(const css::util::URL
& aURL
, const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
) override
;
112 virtual void SAL_CALL
addStatusListener(const css::uno::Reference
< css::frame::XStatusListener
> & xControl
, const css::util::URL
& aURL
) override
;
113 virtual void SAL_CALL
removeStatusListener(const css::uno::Reference
< css::frame::XStatusListener
> & xControl
, const css::util::URL
& aURL
) override
;
115 // css::frame::XDispatchProvider
116 virtual css::uno::Reference
< css::frame::XDispatch
> SAL_CALL
queryDispatch(const css::util::URL
& aURL
, const OUString
& aTargetFrameName
, sal_Int32 nSearchFlags
) override
;
118 // css::lang::XComponent
119 virtual void SAL_CALL
dispose() override
;
122 virtual VclPtr
<FmGridControl
> imp_CreateControl(vcl::Window
* pParent
, WinBits nStyle
) override
;
123 void NotifyStatusChanged(const css::util::URL
& aUrl
, const css::uno::Reference
< css::frame::XStatusListener
> & xControl
);
125 // for any execution of XDispatch::dispatch
129 css::uno::Sequence
< css::beans::PropertyValue
> aArgs
;
131 std::queue
< DispatchArgs
> m_aDispatchArgs
;
132 DECL_LINK( OnDispatchEvent
, void*, void );
134 // for dynamic states of our 4 dispatchable URLs
144 static DispatchType
classifyDispatchURL( const css::util::URL
& _rURL
);
146 typedef std::map
<DispatchType
, bool> MapDispatchToBool
;
147 MapDispatchToBool m_aDispatchStates
;
154 ,public DragSourceHelper
157 SbaGridHeader(BrowseBox
* pParent
);
158 virtual void dispose() override
;
159 virtual ~SbaGridHeader() override
;
162 // FmGridHeader overridables
163 virtual void PreExecuteColumnContextMenu(sal_uInt16 nColId
, weld::Menu
& rMenu
,
164 weld::Menu
& rInsertMenu
, weld::Menu
& rChangeMenu
,
165 weld::Menu
& rShowMenu
) override
;
166 virtual void PostExecuteColumnContextMenu(sal_uInt16 nColId
, const weld::Menu
& rMenu
, const OUString
& rExecutionResult
) override
;
169 // DragSourceHelper overridables
170 virtual void StartDrag( sal_Int8 _nAction
, const Point
& _rPosPixel
) override
;
172 // Window overridables
173 virtual void MouseButtonDown( const MouseEvent
& rMEvt
) override
;
175 void ImplStartColumnDrag(sal_Int8 _nAction
, const Point
& _rMousePos
);
178 // interfaces for communication between the vcl grid control and a controller
179 class SbaGridListener
182 virtual void RowChanged() = 0;
183 virtual void ColumnChanged() = 0;
184 virtual void SelectionChanged() = 0;
185 virtual void CellActivated() = 0;
186 virtual void CellDeactivated() = 0;
187 virtual void BeforeDrop() = 0;
188 virtual void AfterDrop() = 0;
191 ~SbaGridListener() {}
195 class SbaGridControl final
: public FmGridControl
197 friend class SbaGridHeader
;
198 friend class SbaXGridPeer
;
201 svx::ODataAccessDescriptor m_aDataDescriptor
;
202 SbaGridListener
* m_pMasterListener
;
204 ImplSVEvent
* m_nAsyncDropEvent
;
206 bool m_bActivatingForDrop
;
209 SbaGridControl(css::uno::Reference
< css::uno::XComponentContext
> const & _rM
, Window
* pParent
, FmXGridPeer
* _pPeer
, WinBits nBits
);
210 virtual ~SbaGridControl() override
;
211 virtual void dispose() override
;
213 virtual void Select() override
;
215 void SetMasterListener(SbaGridListener
* pListener
) { m_pMasterListener
= pListener
; }
217 virtual void ActivateCell(sal_Int32 nRow
, sal_uInt16 nCol
, bool bSetCellFocus
= true) override
;
218 virtual void DeactivateCell(bool bUpdate
= true) override
;
219 using FmGridControl::ActivateCell
;
221 bool IsAllSelected() const { return (GetSelectRowCount() == GetRowCount()) && (GetRowCount() > 0); }
223 HeaderBar
* GetHeaderBar() const { return FmGridControl::GetHeaderBar(); }
225 /** return the description of the specified object.
229 The position of a tablecell (index position), header bar column/row cell
231 The description of the specified object.
233 virtual OUString
GetAccessibleObjectDescription( AccessibleBrowseBoxObjType eObjType
,sal_Int32 _nPosition
= -1) const override
;
235 using FmGridControl::DeleteSelectedRows
;
236 /** copies the currently selected rows to the clipboard
238 at least one row is selected
240 void CopySelectedRowsToClipboard();
243 // DragSourceHelper overridables
244 virtual void StartDrag( sal_Int8 _nAction
, const Point
& _rPosPixel
) override
;
246 // BrowseBox overridables
247 virtual sal_Int8
AcceptDrop( const BrowserAcceptDropEvent
& rEvt
) override
;
248 virtual sal_Int8
ExecuteDrop( const BrowserExecuteDropEvent
& rEvt
) override
;
249 virtual void MouseButtonDown( const BrowserMouseEvent
& rMEvt
) override
;
251 // EditBrowseBox overridables
252 virtual VclPtr
<BrowserHeader
> imp_CreateHeaderBar(BrowseBox
* pParent
) override
;
253 virtual ::svt::CellController
* GetController(sal_Int32 nRow
, sal_uInt16 nCol
) override
;
255 // DbGridControl overridables
256 virtual void PreExecuteRowContextMenu(weld::Menu
& rMenu
) override
;
257 virtual void PostExecuteRowContextMenu(const OUString
& rExecutionResult
) override
;
259 // DbGridControl overridables
260 virtual void onRowChange() override
;
261 virtual void onColumnChange() override
;
263 // get a fields property set from a model pos
264 css::uno::Reference
< css::beans::XPropertySet
> getField(sal_uInt16 nModelPos
);
266 // get my data source
267 css::uno::Reference
< css::beans::XPropertySet
> getDataSource() const;
270 void DoColumnDrag(sal_uInt16 nColumnPos
);
271 void DoFieldDrag(sal_uInt16 nColumnPos
, sal_Int16 nRowPos
);
273 void SetBrowserAttrs();
274 void SetColWidth(sal_uInt16 nColId
);
276 void SetColAttrs(sal_uInt16 nColId
);
278 SvNumberFormatter
* GetDatasourceFormatter();
280 DECL_LINK(AsynchDropEvent
, void*, void);
282 bool IsReadOnlyDB() const;
283 void implTransferSelectedRows( sal_Int16 nRowPos
, bool _bTrueIfClipboardFalseIfDrag
);
285 using FmGridControl::AcceptDrop
;
286 using FmGridControl::ExecuteDrop
;
287 using FmGridControl::MouseButtonDown
;
291 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */