bump product version to 4.1.6.2
[LibreOffice.git] / dbaccess / source / ui / inc / sbagrid.hxx
blobd930cc08cf865d753ad758d4607c944ac3c163a4
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 #ifndef _SBA_GRID_HXX
21 #define _SBA_GRID_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 <comphelper/stl_types.hxx>
32 #include "sbamultiplex.hxx"
33 #include <svx/dataaccessdescriptor.hxx>
34 #include <queue>
36 class SvNumberFormatter;
38 namespace com { namespace sun { namespace star {
39 namespace lang {
40 class XMultiServiceFactory;
42 }}}
44 namespace dbaui
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;}
52 struct SbaURLHash
54 sal_Int32 operator() (const ::com::sun::star::util::URL& x) const {return x.Complete.hashCode();}
56 //==================================================================
57 // SbaXGridControl
58 //==================================================================
60 class SbaXStatusMultiplexer;
61 class SbaXGridControl
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;
68 public:
69 SbaXGridControl(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&);
70 virtual ~SbaXGridControl();
72 // UNO
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);
76 // XTypeProvider
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 );
99 protected:
100 virtual FmXGridPeer* imp_CreatePeer(Window* pParent);
103 //==================================================================
104 // SbaXGridPeer
105 //==================================================================
107 class SbaXGridPeer
108 :public FmXGridPeer
109 ,public ::com::sun::star::frame::XDispatch
111 ::cppu::OMultiTypeInterfaceContainerHelperVar< ::com::sun::star::util::URL,SbaURLHash , SbaURLCompare> m_aStatusListeners;
113 public:
114 SbaXGridPeer(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&);
115 virtual ~SbaXGridPeer();
117 // UNO
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 );
139 protected:
140 virtual FmGridControl* imp_CreateControl(Window* pParent, WinBits nStyle);
141 #ifdef _MSC_VER
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() );
145 #else
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 > ());
147 #endif // # _MSC_VER
149 private:
150 // for asny execution of XDispatch::dispatch
151 struct DispatchArgs
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
160 enum DispatchType
162 dtBrowserAttribs,
163 dtRowHeight,
164 dtColumnAttribs,
165 dtColumnWidth,
167 dtUnknown
169 DispatchType classifyDispatchURL( const ::com::sun::star::util::URL& _rURL );
171 DECLARE_STL_STDKEY_MAP( DispatchType, sal_Bool, MapDispatchToBool );
172 MapDispatchToBool m_aDispatchStates;
175 //==================================================================
176 // SbaGridHeader
177 //==================================================================
179 class SbaGridHeader
180 :public FmGridHeader
181 ,public DragSourceHelper
183 public:
184 SbaGridHeader(BrowseBox* pParent, WinBits nWinBits = WB_STDHEADERBAR | WB_DRAG);
186 protected:
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);
192 private:
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);
201 private:
202 using FmGridHeader::StartDrag;
205 // =========================================================================
206 // interfaces for communication between the vcl grid control and a controller
207 // -------------------------------------------------------------------------
208 class SbaGridListener
210 public:
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;
219 protected:
220 ~SbaGridListener() {}
223 //==================================================================
224 // SbaGridControl
225 //==================================================================
226 //------------------------------------------------------------------
227 class SbaGridControl : public FmGridControl
229 friend class SbaGridHeader;
230 friend class SbaXGridPeer;
232 // Attributes
233 protected:
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;
244 // Attribute Access
245 public:
246 sal_uInt16 GetCurrentActionColumn() const { return m_nCurrentActionColId; }
248 public:
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.
266 @param eObjType
267 The type to ask for
268 @param _nPosition
269 The position of a tablecell (index position), header bar colum/row cell
270 @return
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
277 @precond
278 at least one row is selected
280 void CopySelectedRowsToClipboard();
283 protected:
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;
315 // drag events
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);
322 void SetRowHeight();
323 void SetColAttrs(sal_uInt16 nColId);
325 SvNumberFormatter* GetDatasourceFormatter();
327 DECL_LINK(AsynchDropEvent, void*);
329 private:
330 sal_Bool IsReadOnlyDB() const;
331 void implTransferSelectedRows( sal_Int16 nRowPos, bool _bTrueIfClipboardFalseIfDrag );
333 private:
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: */