LCOV - code coverage report
Current view: top level - dbaccess/source/ui/inc - sbagrid.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 8 12 66.7 %
Date: 2012-08-25 Functions: 10 16 62.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 14 14.3 %

           Branch data     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 _SBA_GRID_HXX
      21                 :            : #define _SBA_GRID_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 <comphelper/stl_types.hxx>
      32                 :            : #include "sbamultiplex.hxx"
      33                 :            : #include <svx/dataaccessdescriptor.hxx>
      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                 :            :     //------------------------------------------------------------------
      47                 :            :     struct SbaURLCompare : public ::std::binary_function< ::com::sun::star::util::URL, ::com::sun::star::util::URL, bool>
      48                 :            :     {
      49                 :          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;}
      50                 :            :     };
      51                 :            : 
      52                 :            :     struct SbaURLHash
      53                 :            :     {
      54                 :            :         sal_Int32 operator() (const ::com::sun::star::util::URL& x) const {return x.Complete.hashCode();}
      55                 :            :     };
      56                 :            :     //==================================================================
      57                 :            :     // SbaXGridControl
      58                 :            :     //==================================================================
      59                 :            : 
      60                 :            :     class SbaXStatusMultiplexer;
      61                 :            :     class SbaXGridControl
      62                 :            :                 :public FmXGridControl
      63                 :            :                 ,public ::com::sun::star::frame::XDispatch
      64                 :            :     {
      65                 :            :         DECLARE_STL_MAP(::com::sun::star::util::URL, SbaXStatusMultiplexer*, SbaURLCompare,StatusMultiplexerArray);
      66                 :            :         StatusMultiplexerArray      m_aStatusMultiplexer;
      67                 :            : 
      68                 :            :     public:
      69                 :            :         SbaXGridControl(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
      70                 :            :         virtual ~SbaXGridControl();
      71                 :            : 
      72                 :            :         // UNO
      73                 :       7886 :         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);
      75                 :            : 
      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);
      79                 :            : 
      80                 :            :         // ::com::sun::star::lang::XServiceInfo
      81                 :            :         ::rtl::OUString SAL_CALL getImplementationName() throw();
      82                 :            :         virtual ::comphelper::StringSequence SAL_CALL getSupportedServiceNames() throw();
      83                 :            :         // need by registration
      84                 :            :         static ::rtl::OUString getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException );
      85                 :            :         static ::com::sun::star::uno::Sequence< ::rtl::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 >&);
      88                 :            : 
      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 );
      93                 :            : 
      94                 :            :         // ::com::sun::star::lang::XComponent
      95                 :            :         virtual void SAL_CALL dispose(void) throw( ::com::sun::star::uno::RuntimeException );
      96                 :            : 
      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 );
      98                 :            : 
      99                 :            :     protected:
     100                 :            :         virtual FmXGridPeer*    imp_CreatePeer(Window* pParent);
     101                 :            :     };
     102                 :            : 
     103                 :            :     //==================================================================
     104                 :            :     // SbaXGridPeer
     105                 :            :     //==================================================================
     106                 :            : 
     107                 :            :     class SbaXGridPeer
     108                 :            :                 :public FmXGridPeer
     109                 :            :                 ,public ::com::sun::star::frame::XDispatch
     110                 :            :     {
     111                 :            :         ::cppu::OMultiTypeInterfaceContainerHelperVar< ::com::sun::star::util::URL,SbaURLHash , SbaURLCompare>  m_aStatusListeners;
     112                 :            : 
     113                 :            :     public:
     114                 :            :         SbaXGridPeer(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
     115                 :            :         virtual ~SbaXGridPeer();
     116                 :            : 
     117                 :            :         // UNO
     118                 :      16078 :         virtual void SAL_CALL  acquire() throw() { FmXGridPeer::acquire(); }
     119                 :      16078 :         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);
     121                 :            : 
     122                 :            :         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException);
     123                 :            : 
     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);
     127                 :            : 
     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 );
     132                 :            : 
     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 ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags) throw( ::com::sun::star::uno::RuntimeException );
     135                 :            : 
     136                 :            :         // ::com::sun::star::lang::XComponent
     137                 :            :         virtual void SAL_CALL dispose(void) throw( ::com::sun::star::uno::RuntimeException );
     138                 :            : 
     139                 :            :     protected:
     140                 :            :         virtual FmGridControl*  imp_CreateControl(Window* pParent, WinBits nStyle);
     141                 :            : #if defined(_MSC_VER) && (_MSC_VER >= 1310 )
     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>=1310
     148                 :            : 
     149                 :            :     private:
     150                 :            :         // for asny execution of XDispatch::dispatch
     151 [ #  # ][ #  # ]:          0 :         struct DispatchArgs
                 [ #  # ]
     152                 :            :         {
     153                 :            :             ::com::sun::star::util::URL                                                 aURL;
     154                 :            :             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >   aArgs;
     155                 :            :         };
     156                 :            :         ::std::queue< DispatchArgs >    m_aDispatchArgs;
     157                 :            :         DECL_LINK( OnDispatchEvent, void* );
     158                 :            : 
     159                 :            :         // for dynamic states of our 4 dispatchable URLs
     160                 :            :         enum DispatchType
     161                 :            :         {
     162                 :            :             dtBrowserAttribs,
     163                 :            :             dtRowHeight,
     164                 :            :             dtColumnAttribs,
     165                 :            :             dtColumnWidth,
     166                 :            : 
     167                 :            :             dtUnknown
     168                 :            :         };
     169                 :            :         DispatchType classifyDispatchURL( const ::com::sun::star::util::URL& _rURL );
     170                 :            : 
     171                 :            :         DECLARE_STL_STDKEY_MAP( DispatchType, sal_Bool, MapDispatchToBool );
     172                 :            :         MapDispatchToBool   m_aDispatchStates;
     173                 :            :     };
     174                 :            : 
     175                 :            :     //==================================================================
     176                 :            :     // SbaGridHeader
     177                 :            :     //==================================================================
     178                 :            : 
     179 [ +  - ][ -  + ]:         80 :     class SbaGridHeader
     180                 :            :                 :public FmGridHeader
     181                 :            :                 ,public DragSourceHelper
     182                 :            :     {
     183                 :            :     public:
     184                 :            :         SbaGridHeader(BrowseBox* pParent, WinBits nWinBits = WB_STDHEADERBAR | WB_DRAG);
     185                 :            : 
     186                 :            :     protected:
     187                 :            : 
     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);
     191                 :            : 
     192                 :            :     private:
     193                 :            :         // DragSourceHelper overridables
     194                 :            :         virtual void StartDrag( sal_Int8 _nAction, const Point& _rPosPixel );
     195                 :            : 
     196                 :            :         // Window overridables
     197                 :            :         virtual void MouseButtonDown( const MouseEvent& rMEvt );
     198                 :            : 
     199                 :            :         sal_Bool ImplStartColumnDrag(sal_Int8 _nAction, const Point& _rMousePos);
     200                 :            : 
     201                 :            :     private:
     202                 :            :         using FmGridHeader::StartDrag;
     203                 :            :     };
     204                 :            : 
     205                 :            :     // =========================================================================
     206                 :            :     // interfaces for communication between the vcl grid control and a controller
     207                 :            :     // -------------------------------------------------------------------------
     208                 :          2 :     class SbaGridListener
     209                 :            :     {
     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;
     218                 :            : 
     219                 :            :     protected:
     220                 :          2 :         ~SbaGridListener() {}
     221                 :            :     };
     222                 :            : 
     223                 :            :     //==================================================================
     224                 :            :     // SbaGridControl
     225                 :            :     //==================================================================
     226                 :            :     //------------------------------------------------------------------
     227                 :            :     class SbaGridControl : public FmGridControl
     228                 :            :     {
     229                 :            :         friend class SbaGridHeader;
     230                 :            :         friend class SbaXGridPeer;
     231                 :            : 
     232                 :            :     // Attributes
     233                 :            :     protected:
     234                 :            :         ::svx::ODataAccessDescriptor    m_aDataDescriptor;
     235                 :            :         SbaGridListener*                m_pMasterListener;
     236                 :            : 
     237                 :            :         sal_Int32                       m_nAsyncDropEvent;
     238                 :            : 
     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
     242                 :            : 
     243                 :            :         sal_Bool                        m_bActivatingForDrop;
     244                 :            :     // Attribute Access
     245                 :            :     public:
     246                 :            :         sal_uInt16  GetCurrentActionColumn() const  { return m_nCurrentActionColId; }
     247                 :            : 
     248                 :            :     public:
     249                 :            :         SbaGridControl(::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >,Window* pParent, FmXGridPeer* _pPeer, WinBits nBits = WB_TABSTOP);
     250                 :            :         virtual ~SbaGridControl();
     251                 :            : 
     252                 :            :         virtual void Command( const CommandEvent& rCEvt );
     253                 :            :         virtual void Select();
     254                 :            : 
     255                 :          2 :         void SetMasterListener(SbaGridListener* pListener)  { m_pMasterListener = pListener; }
     256                 :            : 
     257                 :            :         virtual void ActivateCell(long nRow, sal_uInt16 nCol, sal_Bool bSetCellFocus = sal_True);
     258                 :            :         virtual void DeactivateCell(sal_Bool bUpdate = sal_True);
     259                 :          0 :         void ActivateCell() { FmGridControl::ActivateCell(); }
     260                 :            : 
     261 [ #  # ][ #  # ]:          0 :         sal_Bool IsAllSelected() const { return (GetSelectRowCount() == GetRowCount()) && (GetRowCount() > 0); }
     262                 :            : 
     263                 :          4 :         HeaderBar* GetHeaderBar() const { return FmGridControl::GetHeaderBar(); }
     264                 :            : 
     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.
     272                 :            :         */
     273                 :            :         virtual ::rtl::OUString GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition = -1) const;
     274                 :            : 
     275                 :            :         virtual void DeleteSelectedRows();
     276                 :            :         /** copies the currently selected rows to the clipboard
     277                 :            :             @precond
     278                 :            :                 at least one row is selected
     279                 :            :         */
     280                 :            :         void CopySelectedRowsToClipboard();
     281                 :            : 
     282                 :            : 
     283                 :            :     protected:
     284                 :            :         // DragSourceHelper overridables
     285                 :            :         virtual void StartDrag( sal_Int8 _nAction, const Point& _rPosPixel );
     286                 :            : 
     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);
     292                 :            : 
     293                 :            :         // EditBrowseBox overridables
     294                 :            :         virtual BrowserHeader* imp_CreateHeaderBar(BrowseBox* pParent);
     295                 :            :         virtual ::svt::CellController* GetController(long nRow, sal_uInt16 nCol);
     296                 :            : 
     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);
     300                 :            : 
     301                 :            :         // DbGridControl overridables
     302                 :            :         virtual void onRowChange();
     303                 :            :         virtual void onColumnChange();
     304                 :            : 
     305                 :            :         // my own overridables
     306                 :            :         virtual void BeforeDrop();
     307                 :            :         virtual void AfterDrop();
     308                 :            : 
     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);
     311                 :            : 
     312                 :            :         // get my data source
     313                 :            :         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >  getDataSource() const;
     314                 :            : 
     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);
     319                 :            : 
     320                 :            :         void SetBrowserAttrs();
     321                 :            :         void SetColWidth(sal_uInt16 nColId);
     322                 :            :         void SetRowHeight();
     323                 :            :         void SetColAttrs(sal_uInt16 nColId);
     324                 :            : 
     325                 :            :         SvNumberFormatter* GetDatasourceFormatter();
     326                 :            : 
     327                 :            :         DECL_LINK(AsynchDropEvent, void*);
     328                 :            : 
     329                 :            :     private:
     330                 :            :         sal_Bool    IsReadOnlyDB() const;
     331                 :            :         void implTransferSelectedRows( sal_Int16 nRowPos, bool _bTrueIfClipboardFalseIfDrag );
     332                 :            : 
     333                 :            :     private:
     334                 :            :         using FmGridControl::AcceptDrop;
     335                 :            :         using FmGridControl::ExecuteDrop;
     336                 :            :         using FmGridControl::MouseButtonDown;
     337                 :            :     };
     338                 :            : }
     339                 :            : #endif // _SBA_GRID_HXX
     340                 :            : 
     341                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10