xref: /AOO41X/main/dbaccess/source/ui/inc/sbagrid.hxx (revision 2e2212a7c22e96cf6f6fab0dd042c34a45a64bd6)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SBA_GRID_HXX
25 #define _SBA_GRID_HXX
26 
27 //  #include <sdb/tools.hxx>
28 
29 #ifndef _SVX_FMGRIDCL_HXX
30 #include <svx/fmgridcl.hxx>
31 #endif
32 
33 #ifndef _SVX_FMGRIDIF_HXX
34 #include <svx/fmgridif.hxx>
35 #endif
36 
37 #ifndef _COM_SUN_STAR_SDB_XSQLQUERYCOMPOSER_HPP_
38 #include <com/sun/star/sdb/XSQLQueryComposer.hpp>
39 #endif
40 #ifndef _COM_SUN_STAR_FRAME_XDISPATCH_HPP_
41 #include <com/sun/star/frame/XDispatch.hpp>
42 #endif
43 #ifndef _COM_SUN_STAR_UTIL_URL_HPP_
44 #include <com/sun/star/util/URL.hpp>
45 #endif
46 #ifndef _COMPHELPER_UNO3_HXX_
47 #include <comphelper/uno3.hxx>
48 #endif
49 #ifndef _COMPHELPER_STLTYPES_HXX_
50 #include <comphelper/stl_types.hxx>
51 #endif
52 #ifndef _SBA_MULTIPLEX_HXX
53 #include "sbamultiplex.hxx"
54 #endif
55 #ifndef _SVX_DATACCESSDESCRIPTOR_HXX_
56 #include <svx/dataaccessdescriptor.hxx>
57 #endif
58 #include <queue>
59 
60 class SvNumberFormatter;
61 
62 namespace dbaui
63 {
64     //------------------------------------------------------------------
65     struct SbaURLCompare : public ::std::binary_function< ::com::sun::star::util::URL, ::com::sun::star::util::URL, bool>
66     {
operator ()dbaui::SbaURLCompare67         bool operator() (const ::com::sun::star::util::URL& x, const ::com::sun::star::util::URL& y) const {return x.Complete == y.Complete ? true : false;}
68     };
69 
70     struct SbaURLHash
71     {
operator ()dbaui::SbaURLHash72         sal_Int32 operator() (const ::com::sun::star::util::URL& x) const {return x.Complete.hashCode();}
73     };
74     //==================================================================
75     // SbaXGridControl
76     //==================================================================
77 
78     //  class ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > ;
79     FORWARD_DECLARE_INTERFACE(lang,XMultiServiceFactory)
80 
81     class SbaXStatusMultiplexer;
82     class SbaXGridControl
83                 :public FmXGridControl
84                 ,public ::com::sun::star::frame::XDispatch
85     {
86         DECLARE_STL_MAP(::com::sun::star::util::URL, SbaXStatusMultiplexer*, SbaURLCompare,StatusMultiplexerArray);
87         StatusMultiplexerArray      m_aStatusMultiplexer;
88 
89     public:
90         SbaXGridControl(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
91         virtual ~SbaXGridControl();
92 
93         // UNO
94         DECLARE_UNO3_DEFAULTS(SbaXGridControl, FmXGridControl);
95         virtual ::com::sun::star::uno::Any  SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException);
96 
97         // XTypeProvider
98         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  ) throw (::com::sun::star::uno::RuntimeException);
99         virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId(  ) throw (::com::sun::star::uno::RuntimeException);
100 
101         // ::com::sun::star::lang::XServiceInfo
102         ::rtl::OUString SAL_CALL getImplementationName() throw();
103         virtual ::comphelper::StringSequence SAL_CALL getSupportedServiceNames() throw();
104         // need by registration
105         static ::rtl::OUString getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException );
106         static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException );
107         static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
108                 SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
109 
110         // ::com::sun::star::frame::XDispatch
111         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 );
112         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 );
113         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 );
114 
115         // ::com::sun::star::lang::XComponent
116         virtual void SAL_CALL dispose(void) throw( ::com::sun::star::uno::RuntimeException );
117 
118         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 );
119 
120     protected:
121         virtual FmXGridPeer*    imp_CreatePeer(Window* pParent);
122     };
123 
124     //==================================================================
125     // SbaXGridPeer
126     //==================================================================
127 
128     class SbaXGridPeer
129                 :public FmXGridPeer
130                 ,public ::com::sun::star::frame::XDispatch
131     {
132         ::cppu::OMultiTypeInterfaceContainerHelperVar< ::com::sun::star::util::URL,SbaURLHash , SbaURLCompare>  m_aStatusListeners;
133 
134     public:
135         SbaXGridPeer(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
136         virtual ~SbaXGridPeer();
137 
138         // UNO
acquire()139         virtual void SAL_CALL  acquire() throw() { FmXGridPeer::acquire(); }
release()140         virtual void SAL_CALL release() throw() { FmXGridPeer::release(); }
141         virtual ::com::sun::star::uno::Any  SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException);
142 
143         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException);
144 
145         static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId();
146         sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 > & rId ) throw (::com::sun::star::uno::RuntimeException);
147         static SbaXGridPeer* getImplementation(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& _rxIFace);
148 
149         // ::com::sun::star::frame::XDispatch
150         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 );
151         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 );
152         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 );
153 
154         // ::com::sun::star::frame::XDispatchProvider
155         virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >  SAL_CALL queryDispatch(const ::com::sun::star::util::URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags) throw( ::com::sun::star::uno::RuntimeException );
156 
157         // ::com::sun::star::lang::XComponent
158         virtual void SAL_CALL dispose(void) throw( ::com::sun::star::uno::RuntimeException );
159 
160     protected:
161         virtual FmGridControl*  imp_CreateControl(Window* pParent, WinBits nStyle);
162 #if defined(_MSC_VER) && (_MSC_VER >= 1310 )
163         typedef ::com::sun::star::frame::XStatusListener xstlist_type;
164         typedef ::com::sun::star::uno::Reference< xstlist_type > xlistener_type;
165         void NotifyStatusChanged(const ::com::sun::star::util::URL& aUrl, const xlistener_type & xControl = xlistener_type() );
166 #else
167         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 > ());
168 #endif // # _MSC_VER>=1310
169 
170     private:
171         // for asny execution of XDispatch::dispatch
172         struct DispatchArgs
173         {
174             ::com::sun::star::util::URL                                                 aURL;
175             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >   aArgs;
176         };
177         ::std::queue< DispatchArgs >    m_aDispatchArgs;
178         DECL_LINK( OnDispatchEvent, void* );
179 
180         // for dynamic states of our 4 dispatchable URLs
181         enum DispatchType
182         {
183             dtBrowserAttribs,
184             dtRowHeight,
185             dtColumnAttribs,
186             dtColumnWidth,
187 
188             dtUnknown
189         };
190         DispatchType classifyDispatchURL( const ::com::sun::star::util::URL& _rURL );
191 
192         DECLARE_STL_STDKEY_MAP( DispatchType, sal_Bool, MapDispatchToBool );
193         MapDispatchToBool   m_aDispatchStates;
194     };
195 
196     //==================================================================
197     // SbaGridHeader
198     //==================================================================
199 
200     class SbaGridHeader
201                 :public FmGridHeader
202                 ,public DragSourceHelper
203     {
204     public:
205         SbaGridHeader(BrowseBox* pParent, WinBits nWinBits = WB_STDHEADERBAR | WB_DRAG);
206 
207     protected:
208 
209         // FmGridHeader overridables
210         virtual void    PreExecuteColumnContextMenu(sal_uInt16 nColId, PopupMenu& rMenu);
211         virtual void    PostExecuteColumnContextMenu(sal_uInt16 nColId, const PopupMenu& rMenu, sal_uInt16 nExecutionResult);
212 
213     private:
214         // DragSourceHelper overridables
215         virtual void StartDrag( sal_Int8 _nAction, const Point& _rPosPixel );
216 
217         // Window overridables
218         virtual void MouseButtonDown( const MouseEvent& rMEvt );
219 
220         sal_Bool ImplStartColumnDrag(sal_Int8 _nAction, const Point& _rMousePos);
221 
222     private:
223         using FmGridHeader::StartDrag;
224     };
225 
226     // =========================================================================
227     // interfaces for communication between the vcl grid control and a controller
228     // -------------------------------------------------------------------------
229     class SbaGridListener
230     {
231     public:
232         virtual void RowChanged()       = 0;
233         virtual void ColumnChanged()    = 0;
234         virtual void SelectionChanged() = 0;
235         virtual void CellActivated()    = 0;
236         virtual void CellDeactivated()  = 0;
237         virtual void BeforeDrop()       = 0;
238         virtual void AfterDrop()        = 0;
239     };
240 
241     //==================================================================
242     // SbaGridControl
243     //==================================================================
244     //------------------------------------------------------------------
245     class UnoDataBrowserController;
246     class SbaGridControl : public FmGridControl
247     {
248         friend class SbaGridHeader;
249         friend class SbaXGridPeer;
250 
251     // Attributes
252     protected:
253         ::svx::ODataAccessDescriptor    m_aDataDescriptor;
254         SbaGridListener*                m_pMasterListener;
255 
256         sal_Int32                       m_nAsyncDropEvent;
257 
258         sal_uInt16                          m_nCurrentActionColId;
259             // ui actions (e.g. a context menu) may be performed on columns which aren't the current one
260             // and aren't selected, so we have to track this column id
261 
262         sal_Bool                        m_bActivatingForDrop;
263     // Attribute Access
264     public:
GetCurrentActionColumn() const265         sal_uInt16  GetCurrentActionColumn() const  { return m_nCurrentActionColId; }
266 
267     public:
268         SbaGridControl(::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >,Window* pParent, FmXGridPeer* _pPeer, WinBits nBits = WB_TABSTOP);
269         virtual ~SbaGridControl();
270 
271         virtual void Command( const CommandEvent& rCEvt );
272         virtual void Select();
273 
SetMasterListener(SbaGridListener * pListener)274         void SetMasterListener(SbaGridListener* pListener)  { m_pMasterListener = pListener; }
275 
276         virtual void ActivateCell(long nRow, sal_uInt16 nCol, sal_Bool bSetCellFocus = sal_True);
277         virtual void DeactivateCell(sal_Bool bUpdate = sal_True);
ActivateCell()278         void ActivateCell() { FmGridControl::ActivateCell(); }
279 
IsAllSelected() const280         sal_Bool IsAllSelected() const { return (GetSelectRowCount() == GetRowCount()) && (GetRowCount() > 0); }
281 
GetHeaderBar() const282         HeaderBar* GetHeaderBar() const { return FmGridControl::GetHeaderBar(); }
283 
284         /** return the description of the specified object.
285             @param  eObjType
286                 The type to ask for
287             @param  _nPosition
288                 The position of a tablecell (index position), header bar  colum/row cell
289             @return
290                 The description of the specified object.
291         */
292         virtual ::rtl::OUString GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition = -1) const;
293 
294         virtual void DeleteSelectedRows();
295         /** copies the currently selected rows to the clipboard
296             @precond
297                 at least one row is selected
298         */
299         void CopySelectedRowsToClipboard();
300 
301 
302     protected:
303         // DragSourceHelper overridables
304         virtual void StartDrag( sal_Int8 _nAction, const Point& _rPosPixel );
305 
306         // BrowseBox overridables
307         virtual void    CursorMoved();
308         virtual sal_Int8 AcceptDrop( const BrowserAcceptDropEvent& rEvt );
309         virtual sal_Int8 ExecuteDrop( const BrowserExecuteDropEvent& rEvt );
310         virtual void    MouseButtonDown( const BrowserMouseEvent& rMEvt);
311 
312         // EditBrowseBox overridables
313         virtual BrowserHeader* imp_CreateHeaderBar(BrowseBox* pParent);
314         virtual ::svt::CellController* GetController(long nRow, sal_uInt16 nCol);
315 
316         // DbGridControl overridables
317         virtual void PreExecuteRowContextMenu(sal_uInt16 nRow, PopupMenu& rMenu);
318         virtual void PostExecuteRowContextMenu(sal_uInt16 nRow, const PopupMenu& rMenu, sal_uInt16 nExecutionResult);
319 
320         // DbGridControl overridables
321         virtual void onRowChange();
322         virtual void onColumnChange();
323 
324         // my own overridables
325         virtual void BeforeDrop();
326         virtual void AfterDrop();
327 
328         // get a fields property set from a model pos
329         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >  getField(sal_uInt16 nModelPos);
330 
331         // get my data source
332         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >  getDataSource() const;
333 
334         // drag events
335         virtual void DoColumnDrag(sal_uInt16 nColumnPos);
336         virtual void DoRowDrag(sal_Int16 nRowPos);
337         virtual void DoFieldDrag(sal_uInt16 nColumnPos, sal_Int16 nRowPos);
338 
339         void SetBrowserAttrs();
340         void SetColWidth(sal_uInt16 nColId);
341         void SetRowHeight();
342         void SetColAttrs(sal_uInt16 nColId);
343 
344         SvNumberFormatter* GetDatasourceFormatter();
345 
346         DECL_LINK(AsynchDropEvent, void*);
347 
348     private:
349         sal_Bool    IsReadOnlyDB() const;
350         void implTransferSelectedRows( sal_Int16 nRowPos, bool _bTrueIfClipboardFalseIfDrag );
351 
352     private:
353         using FmGridControl::AcceptDrop;
354         using FmGridControl::ExecuteDrop;
355         using FmGridControl::MouseButtonDown;
356     };
357 }
358 #endif // _SBA_GRID_HXX
359 
360