Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / dbaccess / source / ui / inc / sbagrid.hxx
blobae96bb291bbbb705e4245639038debec421e8b5e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
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>
34 #include <map>
35 #include <queue>
37 class SvNumberFormatter;
39 namespace com::sun::star {
40 namespace lang {
41 class XMultiServiceFactory;
45 namespace dbaui
47 struct SbaURLCompare
49 bool operator() (const css::util::URL& x, const css::util::URL& y) const { return x.Complete == y.Complete; }
52 class SbaXStatusMultiplexer;
53 class SbaXGridControl
54 :public FmXGridControl
55 ,public css::frame::XDispatch
57 typedef std::map<css::util::URL, rtl::Reference<SbaXStatusMultiplexer>, SbaURLCompare> StatusMultiplexerArray;
58 StatusMultiplexerArray m_aStatusMultiplexer;
60 public:
61 SbaXGridControl(const css::uno::Reference< css::uno::XComponentContext >&);
62 virtual ~SbaXGridControl() override;
64 // UNO
65 DECLARE_UNO3_AGG_DEFAULTS(SbaXGridControl, FmXGridControl)
66 virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type& _rType) override;
68 // XTypeProvider
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;
86 protected:
87 virtual rtl::Reference<FmXGridPeer> imp_CreatePeer(vcl::Window* pParent) override;
90 // SbaXGridPeer
92 class SbaXGridPeer final
93 :public FmXGridPeer
94 ,public css::frame::XDispatch
96 comphelper::OMultiTypeInterfaceContainerHelperVar4< css::util::URL, css::frame::XStatusListener,
97 SbaURLCompare> m_aStatusListeners;
99 public:
100 SbaXGridPeer(const css::uno::Reference< css::uno::XComponentContext >&);
101 virtual ~SbaXGridPeer() override;
103 // UNO
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;
121 private:
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
126 struct DispatchArgs
128 css::util::URL aURL;
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
135 enum DispatchType
137 dtBrowserAttribs,
138 dtRowHeight,
139 dtColumnAttribs,
140 dtColumnWidth,
142 dtUnknown
144 static DispatchType classifyDispatchURL( const css::util::URL& _rURL );
146 typedef std::map<DispatchType, bool> MapDispatchToBool;
147 MapDispatchToBool m_aDispatchStates;
150 // SbaGridHeader
152 class SbaGridHeader
153 :public FmGridHeader
154 ,public DragSourceHelper
156 public:
157 SbaGridHeader(BrowseBox* pParent);
158 virtual void dispose() override;
159 virtual ~SbaGridHeader() override;
160 protected:
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;
168 private:
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
181 public:
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;
190 protected:
191 ~SbaGridListener() {}
194 // SbaGridControl
195 class SbaGridControl final : public FmGridControl
197 friend class SbaGridHeader;
198 friend class SbaXGridPeer;
200 // Attributes
201 svx::ODataAccessDescriptor m_aDataDescriptor;
202 SbaGridListener* m_pMasterListener;
204 ImplSVEvent * m_nAsyncDropEvent;
206 bool m_bActivatingForDrop;
208 public:
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.
226 @param eObjType
227 The type to ask for
228 @param _nPosition
229 The position of a tablecell (index position), header bar column/row cell
230 @return
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
237 @precond
238 at least one row is selected
240 void CopySelectedRowsToClipboard();
242 private:
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;
269 // drag events
270 void DoColumnDrag(sal_uInt16 nColumnPos);
271 void DoFieldDrag(sal_uInt16 nColumnPos, sal_Int16 nRowPos);
273 void SetBrowserAttrs();
274 void SetColWidth(sal_uInt16 nColId);
275 void SetRowHeight();
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: */