LCOV - code coverage report
Current view: top level - dbaccess/source/ui/inc - sbagrid.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 8 12 66.7 %
Date: 2015-06-13 12:38:46 Functions: 10 16 62.5 %
Legend: Lines: hit not hit

          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        4740 :         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() 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() 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        9047 :         virtual void SAL_CALL  acquire() throw() SAL_OVERRIDE { FmXGridPeer::acquire(); }
     109        9047 :         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() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     128             : 
     129             :     protected:
     130             :         virtual VclPtr<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             :         static 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          40 :     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             :         virtual void dispose() SAL_OVERRIDE;
     235             : 
     236             :         virtual void Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
     237             :         virtual void Select() SAL_OVERRIDE;
     238             : 
     239           1 :         void SetMasterListener(SbaGridListener* pListener)  { m_pMasterListener = pListener; }
     240             : 
     241             :         virtual void ActivateCell(long nRow, sal_uInt16 nCol, bool bSetCellFocus = true) SAL_OVERRIDE;
     242             :         virtual void DeactivateCell(bool bUpdate = true) SAL_OVERRIDE;
     243           0 :         void ActivateCell() { FmGridControl::ActivateCell(); }
     244             : 
     245           0 :         bool IsAllSelected() const { return (GetSelectRowCount() == GetRowCount()) && (GetRowCount() > 0); }
     246             : 
     247           2 :         HeaderBar* GetHeaderBar() const { return FmGridControl::GetHeaderBar(); }
     248             : 
     249             :         /** return the description of the specified object.
     250             :             @param  eObjType
     251             :                 The type to ask for
     252             :             @param  _nPosition
     253             :                 The position of a tablecell (index position), header bar  column/row cell
     254             :             @return
     255             :                 The description of the specified object.
     256             :         */
     257             :         virtual OUString GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition = -1) const SAL_OVERRIDE;
     258             : 
     259             :         virtual void DeleteSelectedRows() SAL_OVERRIDE;
     260             :         /** copies the currently selected rows to the clipboard
     261             :             @precond
     262             :                 at least one row is selected
     263             :         */
     264             :         void CopySelectedRowsToClipboard();
     265             : 
     266             :     protected:
     267             :         // DragSourceHelper overridables
     268             :         virtual void StartDrag( sal_Int8 _nAction, const Point& _rPosPixel ) SAL_OVERRIDE;
     269             : 
     270             :         // BrowseBox overridables
     271             :         virtual void    CursorMoved() SAL_OVERRIDE;
     272             :         virtual sal_Int8 AcceptDrop( const BrowserAcceptDropEvent& rEvt ) SAL_OVERRIDE;
     273             :         virtual sal_Int8 ExecuteDrop( const BrowserExecuteDropEvent& rEvt ) SAL_OVERRIDE;
     274             :         virtual void    MouseButtonDown( const BrowserMouseEvent& rMEvt) SAL_OVERRIDE;
     275             : 
     276             :         // EditBrowseBox overridables
     277             :         virtual VclPtr<BrowserHeader> imp_CreateHeaderBar(BrowseBox* pParent) SAL_OVERRIDE;
     278             :         virtual ::svt::CellController* GetController(long nRow, sal_uInt16 nCol) SAL_OVERRIDE;
     279             : 
     280             :         // DbGridControl overridables
     281             :         virtual void PreExecuteRowContextMenu(sal_uInt16 nRow, PopupMenu& rMenu) SAL_OVERRIDE;
     282             :         virtual void PostExecuteRowContextMenu(sal_uInt16 nRow, const PopupMenu& rMenu, sal_uInt16 nExecutionResult) SAL_OVERRIDE;
     283             : 
     284             :         // DbGridControl overridables
     285             :         virtual void onRowChange() SAL_OVERRIDE;
     286             :         virtual void onColumnChange() SAL_OVERRIDE;
     287             : 
     288             :         // my own overridables
     289             :         void BeforeDrop();
     290             :         void AfterDrop();
     291             : 
     292             :         // get a fields property set from a model pos
     293             :         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >  getField(sal_uInt16 nModelPos);
     294             : 
     295             :         // get my data source
     296             :         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >  getDataSource() const;
     297             : 
     298             :         // drag events
     299             :         void DoColumnDrag(sal_uInt16 nColumnPos);
     300             :         void DoRowDrag(sal_Int16 nRowPos);
     301             :         void DoFieldDrag(sal_uInt16 nColumnPos, sal_Int16 nRowPos);
     302             : 
     303             :         void SetBrowserAttrs();
     304             :         void SetColWidth(sal_uInt16 nColId);
     305             :         void SetRowHeight();
     306             :         void SetColAttrs(sal_uInt16 nColId);
     307             : 
     308             :         SvNumberFormatter* GetDatasourceFormatter();
     309             : 
     310             :         DECL_LINK(AsynchDropEvent, void*);
     311             : 
     312             :     private:
     313             :         bool IsReadOnlyDB() const;
     314             :         void implTransferSelectedRows( sal_Int16 nRowPos, bool _bTrueIfClipboardFalseIfDrag );
     315             : 
     316             :     private:
     317             :         using FmGridControl::AcceptDrop;
     318             :         using FmGridControl::ExecuteDrop;
     319             :         using FmGridControl::MouseButtonDown;
     320             :     };
     321             : }
     322             : #endif // INCLUDED_DBACCESS_SOURCE_UI_INC_SBAGRID_HXX
     323             : 
     324             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11