Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_DBACCESS_SOURCE_UI_INC_SBAGRID_HXX
21 : #define INCLUDED_DBACCESS_SOURCE_UI_INC_SBAGRID_HXX
22 :
23 : #include <svx/fmgridcl.hxx>
24 :
25 : #include <svx/fmgridif.hxx>
26 :
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>
33 : #include <map>
34 : #include <queue>
35 :
36 : class SvNumberFormatter;
37 :
38 : namespace com { namespace sun { namespace star {
39 : namespace lang {
40 : class XMultiServiceFactory;
41 : }
42 : }}}
43 :
44 : namespace dbaui
45 : {
46 : struct SbaURLCompare : public ::std::binary_function< ::com::sun::star::util::URL, ::com::sun::star::util::URL, bool>
47 : {
48 0 : bool operator() (const ::com::sun::star::util::URL& x, const ::com::sun::star::util::URL& y) const {return x.Complete == y.Complete ? true : false;}
49 : };
50 :
51 : struct SbaURLHash
52 : {
53 : sal_Int32 operator() (const ::com::sun::star::util::URL& x) const {return x.Complete.hashCode();}
54 : };
55 : // SbaXGridControl
56 :
57 : class SbaXStatusMultiplexer;
58 : class SbaXGridControl
59 : :public FmXGridControl
60 : ,public ::com::sun::star::frame::XDispatch
61 : {
62 : typedef std::map<css::util::URL, SbaXStatusMultiplexer*, SbaURLCompare> StatusMultiplexerArray;
63 : StatusMultiplexerArray m_aStatusMultiplexer;
64 :
65 : public:
66 : SbaXGridControl(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&);
67 : virtual ~SbaXGridControl();
68 :
69 : // UNO
70 0 : DECLARE_UNO3_DEFAULTS(SbaXGridControl, FmXGridControl)
71 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
72 :
73 : // XTypeProvider
74 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
75 : virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
76 :
77 : // ::com::sun::star::lang::XServiceInfo
78 : OUString SAL_CALL getImplementationName() throw(std::exception) SAL_OVERRIDE;
79 : virtual ::comphelper::StringSequence SAL_CALL getSupportedServiceNames() throw(std::exception) SAL_OVERRIDE;
80 : // need by registration
81 : static OUString getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException );
82 : static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException );
83 : static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
84 : SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
85 :
86 : // ::com::sun::star::frame::XDispatch
87 : 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, std::exception ) SAL_OVERRIDE;
88 : 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, std::exception ) SAL_OVERRIDE;
89 : 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, std::exception ) SAL_OVERRIDE;
90 :
91 : // ::com::sun::star::lang::XComponent
92 : virtual void SAL_CALL dispose(void) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
93 :
94 : 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, std::exception ) SAL_OVERRIDE;
95 :
96 : protected:
97 : virtual FmXGridPeer* imp_CreatePeer(Window* pParent) SAL_OVERRIDE;
98 : };
99 :
100 : // SbaXGridPeer
101 :
102 : class SbaXGridPeer
103 : :public FmXGridPeer
104 : ,public ::com::sun::star::frame::XDispatch
105 : {
106 : ::cppu::OMultiTypeInterfaceContainerHelperVar< ::com::sun::star::util::URL,SbaURLHash , SbaURLCompare> m_aStatusListeners;
107 :
108 : public:
109 : SbaXGridPeer(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&);
110 : virtual ~SbaXGridPeer();
111 :
112 : // UNO
113 0 : virtual void SAL_CALL acquire() throw() SAL_OVERRIDE { FmXGridPeer::acquire(); }
114 0 : virtual void SAL_CALL release() throw() SAL_OVERRIDE { FmXGridPeer::release(); }
115 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
116 :
117 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
118 :
119 : static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId();
120 : sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 > & rId ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
121 : static SbaXGridPeer* getImplementation(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& _rxIFace);
122 :
123 : // ::com::sun::star::frame::XDispatch
124 : 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, std::exception ) SAL_OVERRIDE;
125 : 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, std::exception ) SAL_OVERRIDE;
126 : 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, std::exception ) SAL_OVERRIDE;
127 :
128 : // ::com::sun::star::frame::XDispatchProvider
129 : 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, std::exception ) SAL_OVERRIDE;
130 :
131 : // ::com::sun::star::lang::XComponent
132 : virtual void SAL_CALL dispose(void) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
133 :
134 : protected:
135 : virtual FmGridControl* imp_CreateControl(Window* pParent, WinBits nStyle) SAL_OVERRIDE;
136 : #ifdef _MSC_VER
137 : typedef ::com::sun::star::frame::XStatusListener xstlist_type;
138 : typedef ::com::sun::star::uno::Reference< xstlist_type > xlistener_type;
139 : void NotifyStatusChanged(const ::com::sun::star::util::URL& aUrl, const xlistener_type & xControl = xlistener_type() );
140 : #else
141 : 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 > ());
142 : #endif // # _MSC_VER
143 :
144 : private:
145 : // for asny execution of XDispatch::dispatch
146 0 : struct DispatchArgs
147 : {
148 : ::com::sun::star::util::URL aURL;
149 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs;
150 : };
151 : ::std::queue< DispatchArgs > m_aDispatchArgs;
152 : DECL_LINK( OnDispatchEvent, void* );
153 :
154 : // for dynamic states of our 4 dispatchable URLs
155 : enum DispatchType
156 : {
157 : dtBrowserAttribs,
158 : dtRowHeight,
159 : dtColumnAttribs,
160 : dtColumnWidth,
161 :
162 : dtUnknown
163 : };
164 : DispatchType classifyDispatchURL( const ::com::sun::star::util::URL& _rURL );
165 :
166 : typedef std::map<DispatchType, sal_Bool> MapDispatchToBool;
167 : MapDispatchToBool m_aDispatchStates;
168 : };
169 :
170 : // SbaGridHeader
171 :
172 0 : class SbaGridHeader
173 : :public FmGridHeader
174 : ,public DragSourceHelper
175 : {
176 : public:
177 : SbaGridHeader(BrowseBox* pParent, WinBits nWinBits = WB_STDHEADERBAR | WB_DRAG);
178 :
179 : protected:
180 :
181 : // FmGridHeader overridables
182 : virtual void PreExecuteColumnContextMenu(sal_uInt16 nColId, PopupMenu& rMenu) SAL_OVERRIDE;
183 : virtual void PostExecuteColumnContextMenu(sal_uInt16 nColId, const PopupMenu& rMenu, sal_uInt16 nExecutionResult) SAL_OVERRIDE;
184 :
185 : private:
186 : // DragSourceHelper overridables
187 : virtual void StartDrag( sal_Int8 _nAction, const Point& _rPosPixel ) SAL_OVERRIDE;
188 :
189 : // Window overridables
190 : virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
191 :
192 : sal_Bool ImplStartColumnDrag(sal_Int8 _nAction, const Point& _rMousePos);
193 :
194 : private:
195 : using FmGridHeader::StartDrag;
196 : };
197 :
198 : // interfaces for communication between the vcl grid control and a controller
199 0 : class SbaGridListener
200 : {
201 : public:
202 : virtual void RowChanged() = 0;
203 : virtual void ColumnChanged() = 0;
204 : virtual void SelectionChanged() = 0;
205 : virtual void CellActivated() = 0;
206 : virtual void CellDeactivated() = 0;
207 : virtual void BeforeDrop() = 0;
208 : virtual void AfterDrop() = 0;
209 :
210 : protected:
211 0 : ~SbaGridListener() {}
212 : };
213 :
214 : // SbaGridControl
215 : class SbaGridControl : public FmGridControl
216 : {
217 : friend class SbaGridHeader;
218 : friend class SbaXGridPeer;
219 :
220 : // Attributes
221 : protected:
222 : ::svx::ODataAccessDescriptor m_aDataDescriptor;
223 : SbaGridListener* m_pMasterListener;
224 :
225 : sal_Int32 m_nAsyncDropEvent;
226 :
227 : sal_uInt16 m_nCurrentActionColId;
228 : // ui actions (e.g. a context menu) may be performed on columns which aren't the current one
229 : // and aren't selected, so we have to track this column id
230 :
231 : sal_Bool m_bActivatingForDrop;
232 : // Attribute Access
233 : public:
234 : sal_uInt16 GetCurrentActionColumn() const { return m_nCurrentActionColId; }
235 :
236 : public:
237 : SbaGridControl(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >,Window* pParent, FmXGridPeer* _pPeer, WinBits nBits = WB_TABSTOP);
238 : virtual ~SbaGridControl();
239 :
240 : virtual void Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
241 : virtual void Select() SAL_OVERRIDE;
242 :
243 0 : void SetMasterListener(SbaGridListener* pListener) { m_pMasterListener = pListener; }
244 :
245 : virtual void ActivateCell(long nRow, sal_uInt16 nCol, bool bSetCellFocus = true) SAL_OVERRIDE;
246 : virtual void DeactivateCell(bool bUpdate = true) SAL_OVERRIDE;
247 0 : void ActivateCell() { FmGridControl::ActivateCell(); }
248 :
249 0 : sal_Bool IsAllSelected() const { return (GetSelectRowCount() == GetRowCount()) && (GetRowCount() > 0); }
250 :
251 0 : HeaderBar* GetHeaderBar() const { return FmGridControl::GetHeaderBar(); }
252 :
253 : /** return the description of the specified object.
254 : @param eObjType
255 : The type to ask for
256 : @param _nPosition
257 : The position of a tablecell (index position), header bar column/row cell
258 : @return
259 : The description of the specified object.
260 : */
261 : virtual OUString GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition = -1) const SAL_OVERRIDE;
262 :
263 : virtual void DeleteSelectedRows() SAL_OVERRIDE;
264 : /** copies the currently selected rows to the clipboard
265 : @precond
266 : at least one row is selected
267 : */
268 : void CopySelectedRowsToClipboard();
269 :
270 : protected:
271 : // DragSourceHelper overridables
272 : virtual void StartDrag( sal_Int8 _nAction, const Point& _rPosPixel ) SAL_OVERRIDE;
273 :
274 : // BrowseBox overridables
275 : virtual void CursorMoved() SAL_OVERRIDE;
276 : virtual sal_Int8 AcceptDrop( const BrowserAcceptDropEvent& rEvt ) SAL_OVERRIDE;
277 : virtual sal_Int8 ExecuteDrop( const BrowserExecuteDropEvent& rEvt ) SAL_OVERRIDE;
278 : virtual void MouseButtonDown( const BrowserMouseEvent& rMEvt) SAL_OVERRIDE;
279 :
280 : // EditBrowseBox overridables
281 : virtual BrowserHeader* imp_CreateHeaderBar(BrowseBox* pParent) SAL_OVERRIDE;
282 : virtual ::svt::CellController* GetController(long nRow, sal_uInt16 nCol) SAL_OVERRIDE;
283 :
284 : // DbGridControl overridables
285 : virtual void PreExecuteRowContextMenu(sal_uInt16 nRow, PopupMenu& rMenu) SAL_OVERRIDE;
286 : virtual void PostExecuteRowContextMenu(sal_uInt16 nRow, const PopupMenu& rMenu, sal_uInt16 nExecutionResult) SAL_OVERRIDE;
287 :
288 : // DbGridControl overridables
289 : virtual void onRowChange() SAL_OVERRIDE;
290 : virtual void onColumnChange() SAL_OVERRIDE;
291 :
292 : // my own overridables
293 : virtual void BeforeDrop();
294 : virtual void AfterDrop();
295 :
296 : // get a fields property set from a model pos
297 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getField(sal_uInt16 nModelPos);
298 :
299 : // get my data source
300 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getDataSource() const;
301 :
302 : // drag events
303 : virtual void DoColumnDrag(sal_uInt16 nColumnPos);
304 : virtual void DoRowDrag(sal_Int16 nRowPos);
305 : virtual void DoFieldDrag(sal_uInt16 nColumnPos, sal_Int16 nRowPos);
306 :
307 : void SetBrowserAttrs();
308 : void SetColWidth(sal_uInt16 nColId);
309 : void SetRowHeight();
310 : void SetColAttrs(sal_uInt16 nColId);
311 :
312 : SvNumberFormatter* GetDatasourceFormatter();
313 :
314 : DECL_LINK(AsynchDropEvent, void*);
315 :
316 : private:
317 : sal_Bool IsReadOnlyDB() const;
318 : void implTransferSelectedRows( sal_Int16 nRowPos, bool _bTrueIfClipboardFalseIfDrag );
319 :
320 : private:
321 : using FmGridControl::AcceptDrop;
322 : using FmGridControl::ExecuteDrop;
323 : using FmGridControl::MouseButtonDown;
324 : };
325 : }
326 : #endif // INCLUDED_DBACCESS_SOURCE_UI_INC_SBAGRID_HXX
327 :
328 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|