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