LCOV - code coverage report
Current view: top level - svtools/source/table - tablecontrol_impl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 467 1183 39.5 %
Date: 2015-06-13 12:38:46 Functions: 63 137 46.0 %
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             : 
      21             : #include "table/tablecontrol.hxx"
      22             : #include "table/defaultinputhandler.hxx"
      23             : #include <svtools/table/tablemodel.hxx>
      24             : 
      25             : #include "tabledatawindow.hxx"
      26             : #include "tablecontrol_impl.hxx"
      27             : #include "tablegeometry.hxx"
      28             : 
      29             : #include <com/sun/star/accessibility/XAccessible.hpp>
      30             : #include <com/sun/star/accessibility/AccessibleTableModelChange.hpp>
      31             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      32             : #include <com/sun/star/accessibility/AccessibleTableModelChangeType.hpp>
      33             : 
      34             : #include <comphelper/flagguard.hxx>
      35             : #include <vcl/scrbar.hxx>
      36             : #include <vcl/seleng.hxx>
      37             : #include <vcl/settings.hxx>
      38             : #include <rtl/ref.hxx>
      39             : #include <vcl/image.hxx>
      40             : #include <tools/diagnose_ex.h>
      41             : 
      42             : #include <cstdlib>
      43             : #include <functional>
      44             : #include <numeric>
      45             : 
      46             : #define MIN_COLUMN_WIDTH_PIXEL  4
      47             : 
      48             : 
      49             : namespace svt { namespace table
      50             : {
      51             : 
      52             : 
      53             :     using ::com::sun::star::accessibility::AccessibleTableModelChange;
      54             :     using ::com::sun::star::uno::makeAny;
      55             :     using ::com::sun::star::uno::Any;
      56             :     using ::com::sun::star::accessibility::XAccessible;
      57             :     using ::com::sun::star::uno::Reference;
      58             : 
      59             :     namespace AccessibleEventId = ::com::sun::star::accessibility::AccessibleEventId;
      60             :     namespace AccessibleTableModelChangeType = ::com::sun::star::accessibility::AccessibleTableModelChangeType;
      61             : 
      62             : 
      63             :     //= SuppressCursor
      64             : 
      65             :     class SuppressCursor
      66             :     {
      67             :     private:
      68             :         ITableControl&  m_rTable;
      69             : 
      70             :     public:
      71          21 :         explicit SuppressCursor( ITableControl& _rTable )
      72          21 :             :m_rTable( _rTable )
      73             :         {
      74          21 :             m_rTable.hideCursor();
      75          21 :         }
      76          21 :         ~SuppressCursor()
      77             :         {
      78          21 :             m_rTable.showCursor();
      79          21 :         }
      80             :     };
      81             : 
      82             : 
      83             :     //= EmptyTableModel
      84             : 
      85             :     /** default implementation of an ->ITableModel, used as fallback when no
      86             :         real model is present
      87             : 
      88             :         Instances of this class are static in any way, and provide the least
      89             :         necessary default functionality for a table model.
      90             :     */
      91           4 :     class EmptyTableModel : public ITableModel
      92             :     {
      93             :     public:
      94           2 :         EmptyTableModel()
      95           2 :         {
      96           2 :         }
      97             : 
      98             :         // ITableModel overridables
      99           4 :         virtual TableSize           getColumnCount() const SAL_OVERRIDE
     100             :         {
     101           4 :             return 0;
     102             :         }
     103           1 :         virtual TableSize           getRowCount() const SAL_OVERRIDE
     104             :         {
     105           1 :             return 0;
     106             :         }
     107           1 :         virtual bool                hasColumnHeaders() const SAL_OVERRIDE
     108             :         {
     109           1 :             return false;
     110             :         }
     111           3 :         virtual bool                hasRowHeaders() const SAL_OVERRIDE
     112             :         {
     113           3 :             return false;
     114             :         }
     115           0 :         virtual bool                isCellEditable( ColPos col, RowPos row ) const SAL_OVERRIDE
     116             :         {
     117             :             (void)col;
     118             :             (void)row;
     119           0 :             return false;
     120             :         }
     121           0 :         virtual PColumnModel        getColumnModel( ColPos column ) SAL_OVERRIDE
     122             :         {
     123             :             OSL_FAIL( "EmptyTableModel::getColumnModel: invalid call!" );
     124             :             (void)column;
     125           0 :             return PColumnModel();
     126             :         }
     127           0 :         virtual PTableRenderer      getRenderer() const SAL_OVERRIDE
     128             :         {
     129           0 :             return PTableRenderer();
     130             :         }
     131           1 :         virtual PTableInputHandler  getInputHandler() const SAL_OVERRIDE
     132             :         {
     133           1 :             return PTableInputHandler();
     134             :         }
     135           1 :         virtual TableMetrics        getRowHeight() const SAL_OVERRIDE
     136             :         {
     137           1 :             return 5 * 100;
     138             :         }
     139           0 :         virtual TableMetrics        getColumnHeaderHeight() const SAL_OVERRIDE
     140             :         {
     141           0 :             return 0;
     142             :         }
     143           0 :         virtual TableMetrics        getRowHeaderWidth() const SAL_OVERRIDE
     144             :         {
     145           0 :             return 0;
     146             :         }
     147           2 :         virtual ScrollbarVisibility getVerticalScrollbarVisibility() const SAL_OVERRIDE
     148             :         {
     149           2 :             return ScrollbarShowNever;
     150             :         }
     151           1 :         virtual ScrollbarVisibility getHorizontalScrollbarVisibility() const SAL_OVERRIDE
     152             :         {
     153           1 :             return ScrollbarShowNever;
     154             :         }
     155           1 :         virtual void addTableModelListener( const PTableModelListener& i_listener ) SAL_OVERRIDE
     156             :         {
     157             :             (void)i_listener;
     158           1 :         }
     159           1 :         virtual void removeTableModelListener( const PTableModelListener& i_listener ) SAL_OVERRIDE
     160             :         {
     161             :             (void)i_listener;
     162           1 :         }
     163           0 :         virtual ::boost::optional< ::Color > getLineColor() const SAL_OVERRIDE
     164             :         {
     165           0 :             return ::boost::optional< ::Color >();
     166             :         }
     167           0 :         virtual ::boost::optional< ::Color > getHeaderBackgroundColor() const SAL_OVERRIDE
     168             :         {
     169           0 :             return ::boost::optional< ::Color >();
     170             :         }
     171           0 :         virtual ::boost::optional< ::Color > getHeaderTextColor() const SAL_OVERRIDE
     172             :         {
     173           0 :             return ::boost::optional< ::Color >();
     174             :         }
     175           0 :         virtual ::boost::optional< ::Color >    getActiveSelectionBackColor() const SAL_OVERRIDE
     176             :         {
     177           0 :             return ::boost::optional< ::Color >();
     178             :         }
     179           0 :         virtual ::boost::optional< ::Color >    getInactiveSelectionBackColor() const SAL_OVERRIDE
     180             :         {
     181           0 :             return ::boost::optional< ::Color >();
     182             :         }
     183           0 :         virtual ::boost::optional< ::Color >    getActiveSelectionTextColor() const SAL_OVERRIDE
     184             :         {
     185           0 :             return ::boost::optional< ::Color >();
     186             :         }
     187           0 :         virtual ::boost::optional< ::Color >    getInactiveSelectionTextColor() const SAL_OVERRIDE
     188             :         {
     189           0 :             return ::boost::optional< ::Color >();
     190             :         }
     191           0 :         virtual ::boost::optional< ::Color > getTextColor() const SAL_OVERRIDE
     192             :         {
     193           0 :             return ::boost::optional< ::Color >();
     194             :         }
     195           0 :         virtual ::boost::optional< ::Color > getTextLineColor() const SAL_OVERRIDE
     196             :         {
     197           0 :             return ::boost::optional< ::Color >();
     198             :         }
     199           0 :         virtual ::boost::optional< ::std::vector< ::Color > > getRowBackgroundColors() const SAL_OVERRIDE
     200             :         {
     201           0 :             return ::boost::optional< ::std::vector< ::Color > >();
     202             :         }
     203           0 :         virtual ::com::sun::star::style::VerticalAlignment getVerticalAlign() const SAL_OVERRIDE
     204             :         {
     205           0 :             return com::sun::star::style::VerticalAlignment(0);
     206             :         }
     207           0 :         virtual ITableDataSort* getSortAdapter() SAL_OVERRIDE
     208             :         {
     209           0 :             return NULL;
     210             :         }
     211           0 :         virtual bool isEnabled() const SAL_OVERRIDE
     212             :         {
     213           0 :             return true;
     214             :         }
     215           0 :         virtual void getCellContent( ColPos const i_col, RowPos const i_row, ::com::sun::star::uno::Any& o_cellContent ) SAL_OVERRIDE
     216             :         {
     217             :             (void)i_row;
     218             :             (void)i_col;
     219           0 :             o_cellContent.clear();
     220           0 :         }
     221           0 :         virtual void getCellToolTip( ColPos const, RowPos const, ::com::sun::star::uno::Any& ) SAL_OVERRIDE
     222             :         {
     223           0 :         }
     224           0 :         virtual Any getRowHeading( RowPos const i_rowPos ) const SAL_OVERRIDE
     225             :         {
     226             :             (void)i_rowPos;
     227           0 :             return Any();
     228             :         }
     229             :     };
     230             : 
     231           1 :     TableControl_Impl::TableControl_Impl( TableControl& _rAntiImpl )
     232             :         :m_rAntiImpl            ( _rAntiImpl                    )
     233           1 :         ,m_pModel               ( new EmptyTableModel           )
     234             :         ,m_pInputHandler        (                               )
     235             :         ,m_nRowHeightPixel      ( 15                            )
     236             :         ,m_nColHeaderHeightPixel( 0                             )
     237             :         ,m_nRowHeaderWidthPixel ( 0                             )
     238             :         ,m_nColumnCount         ( 0                             )
     239             :         ,m_nRowCount            ( 0                             )
     240             :         ,m_nCurColumn           ( COL_INVALID                   )
     241             :         ,m_nCurRow              ( ROW_INVALID                   )
     242             :         ,m_nLeftColumn          ( 0                             )
     243             :         ,m_nTopRow              ( 0                             )
     244             :         ,m_nCursorHidden        ( 1                             )
     245             :         ,m_pDataWindow          ( VclPtr<TableDataWindow>::Create( *this )  )
     246             :         ,m_pVScroll             ( NULL                          )
     247             :         ,m_pHScroll             ( NULL                          )
     248             :         ,m_pScrollCorner        ( NULL                          )
     249             :         ,m_pSelEngine           (                               )
     250             :         ,m_aSelectedRows        (                               )
     251           1 :         ,m_pTableFunctionSet    ( new TableFunctionSet( this  ) )
     252             :         ,m_nAnchor              ( -1                            )
     253             :         ,m_bUpdatingColWidths   ( false                         )
     254           3 :         ,m_pAccessibleTable     ( NULL                          )
     255             :     {
     256           1 :         m_pSelEngine = new SelectionEngine( m_pDataWindow.get(), m_pTableFunctionSet );
     257           1 :         m_pSelEngine->SetSelectionMode(SINGLE_SELECTION);
     258           1 :         m_pDataWindow->SetPosPixel( Point( 0, 0 ) );
     259           1 :         m_pDataWindow->Show();
     260           1 :     }
     261             : 
     262           3 :     TableControl_Impl::~TableControl_Impl()
     263             :     {
     264           1 :         m_pVScroll.disposeAndClear();
     265           1 :         m_pHScroll.disposeAndClear();
     266           1 :         m_pScrollCorner.disposeAndClear();
     267           1 :         m_pDataWindow.disposeAndClear();
     268           1 :         DELETEZ( m_pTableFunctionSet );
     269           1 :         DELETEZ( m_pSelEngine );
     270           2 :     }
     271             : 
     272           2 :     void TableControl_Impl::setModel( PTableModel _pModel )
     273             :     {
     274           2 :         SuppressCursor aHideCursor( *this );
     275             : 
     276           2 :         if ( !!m_pModel )
     277           2 :             m_pModel->removeTableModelListener( shared_from_this() );
     278             : 
     279           2 :         m_pModel = _pModel;
     280           2 :         if ( !m_pModel)
     281           1 :             m_pModel.reset( new EmptyTableModel );
     282             : 
     283           2 :         m_pModel->addTableModelListener( shared_from_this() );
     284             : 
     285           2 :         m_nCurRow = ROW_INVALID;
     286           2 :         m_nCurColumn = COL_INVALID;
     287             : 
     288             :         // recalc some model-dependent cached info
     289           2 :         impl_ni_updateCachedModelValues();
     290           2 :         impl_ni_relayout();
     291             : 
     292             :         // completely invalidate
     293           2 :         m_rAntiImpl.Invalidate();
     294             : 
     295             :         // reset cursor to (0,0)
     296           2 :         if ( m_nRowCount ) m_nCurRow = 0;
     297           2 :         if ( m_nColumnCount ) m_nCurColumn = 0;
     298           2 :     }
     299             : 
     300             : 
     301             :     namespace
     302             :     {
     303           3 :         bool lcl_adjustSelectedRows( ::std::vector< RowPos >& io_selectionIndexes, RowPos const i_firstAffectedRowIndex, TableSize const i_offset )
     304             :         {
     305           3 :             bool didChanges = false;
     306           9 :             for (   ::std::vector< RowPos >::iterator selPos = io_selectionIndexes.begin();
     307           6 :                     selPos != io_selectionIndexes.end();
     308             :                     ++selPos
     309             :                 )
     310             :             {
     311           0 :                 if ( *selPos < i_firstAffectedRowIndex )
     312           0 :                     continue;
     313           0 :                 *selPos += i_offset;
     314           0 :                 didChanges = true;
     315             :             }
     316           3 :             return didChanges;
     317             :         }
     318             :     }
     319             : 
     320             : 
     321           2 :     void TableControl_Impl::rowsInserted( RowPos i_first, RowPos i_last )
     322             :     {
     323             :         OSL_PRECOND( i_last >= i_first, "TableControl_Impl::rowsInserted: invalid row indexes!" );
     324             : 
     325           2 :         TableSize const insertedRows = i_last - i_first + 1;
     326             : 
     327             :         // adjust selection, if necessary
     328           2 :         bool const selectionChanged = lcl_adjustSelectedRows( m_aSelectedRows, i_first, insertedRows );
     329             : 
     330             :         // adjust our cached row count
     331           2 :         m_nRowCount = m_pModel->getRowCount();
     332             : 
     333             :         // if the rows have been inserted before the current row, adjust this
     334           2 :         if ( i_first <= m_nCurRow )
     335           0 :             goTo( m_nCurColumn, m_nCurRow + insertedRows );
     336             : 
     337             :         // relayout, since the scrollbar need might have changed
     338           2 :         impl_ni_relayout();
     339             : 
     340             :         // notify A1YY events
     341           2 :         if ( impl_isAccessibleAlive() )
     342             :         {
     343             :             impl_commitAccessibleEvent( AccessibleEventId::TABLE_MODEL_CHANGED,
     344           0 :                 makeAny( AccessibleTableModelChange( AccessibleTableModelChangeType::INSERT, i_first, i_last, 0, m_pModel->getColumnCount() ) ),
     345             :                 Any()
     346           0 :             );
     347             :         }
     348             : 
     349             :         // schedule repaint
     350           2 :         invalidateRowRange( i_first, ROW_INVALID );
     351             : 
     352             :         // call selection handlers, if necessary
     353           2 :         if ( selectionChanged )
     354           0 :             m_rAntiImpl.Select();
     355           2 :     }
     356             : 
     357             : 
     358           1 :     void TableControl_Impl::rowsRemoved( RowPos i_first, RowPos i_last )
     359             :     {
     360           1 :         sal_Int32 firstRemovedRow = i_first;
     361           1 :         sal_Int32 lastRemovedRow = i_last;
     362             : 
     363             :         // adjust selection, if necessary
     364           1 :         bool selectionChanged = false;
     365           1 :         if ( i_first == -1 )
     366             :         {
     367           0 :             selectionChanged = markAllRowsAsDeselected();
     368             : 
     369           0 :             firstRemovedRow = 0;
     370           0 :             lastRemovedRow = m_nRowCount - 1;
     371             :         }
     372             :         else
     373             :         {
     374           1 :             ENSURE_OR_RETURN_VOID( i_last >= i_first, "TableControl_Impl::rowsRemoved: illegal indexes!" );
     375             : 
     376           2 :             for ( sal_Int32 row = i_first; row <= i_last; ++row )
     377             :             {
     378           1 :                 if ( markRowAsDeselected( row ) )
     379           0 :                     selectionChanged = true;
     380             :             }
     381             : 
     382           1 :             if ( lcl_adjustSelectedRows( m_aSelectedRows, i_last + 1, i_first - i_last - 1 ) )
     383           0 :                 selectionChanged = true;
     384             :         }
     385             : 
     386             :         // adjust cached row count
     387           1 :         m_nRowCount = m_pModel->getRowCount();
     388             : 
     389             :         // adjust the current row, if it is larger than the row count now
     390           1 :         if ( m_nCurRow >= m_nRowCount )
     391             :         {
     392           1 :             if ( m_nRowCount > 0 )
     393           1 :                 goTo( m_nCurColumn, m_nRowCount - 1 );
     394             :             else
     395             :             {
     396           0 :                 m_nCurRow = ROW_INVALID;
     397           0 :                 m_nTopRow = 0;
     398             :             }
     399             :         }
     400           0 :         else if ( m_nRowCount == 0 )
     401             :         {
     402           0 :             m_nTopRow = 0;
     403             :         }
     404             : 
     405             : 
     406             :         // relayout, since the scrollbar need might have changed
     407           1 :         impl_ni_relayout();
     408             : 
     409             :         // notify A11Y events
     410           1 :         if ( impl_isAccessibleAlive() )
     411             :         {
     412             :             commitTableEvent(
     413             :                 AccessibleEventId::TABLE_MODEL_CHANGED,
     414             :                 makeAny( AccessibleTableModelChange(
     415             :                     AccessibleTableModelChangeType::DELETE,
     416             :                     firstRemovedRow,
     417             :                     lastRemovedRow,
     418             :                     0,
     419           0 :                     m_pModel->getColumnCount()
     420             :                 ) ),
     421             :                 Any()
     422           0 :             );
     423             :         }
     424             : 
     425             :         // schedule a repaint
     426           1 :         invalidateRowRange( firstRemovedRow, ROW_INVALID );
     427             : 
     428             :         // call selection handlers, if necessary
     429           1 :         if ( selectionChanged )
     430           0 :             m_rAntiImpl.Select();
     431             :     }
     432             : 
     433             : 
     434           3 :     void TableControl_Impl::columnInserted( ColPos const i_colIndex )
     435             :     {
     436           3 :         m_nColumnCount = m_pModel->getColumnCount();
     437           3 :         impl_ni_relayout();
     438             : 
     439           3 :         m_rAntiImpl.Invalidate();
     440             : 
     441             :         OSL_UNUSED( i_colIndex );
     442           3 :    }
     443             : 
     444             : 
     445           1 :     void TableControl_Impl::columnRemoved( ColPos const i_colIndex )
     446             :     {
     447           1 :         m_nColumnCount = m_pModel->getColumnCount();
     448             : 
     449             :         // adjust the current column, if it is larger than the column count now
     450           1 :         if ( m_nCurColumn >= m_nColumnCount )
     451             :         {
     452           1 :             if ( m_nColumnCount > 0 )
     453           1 :                 goTo( m_nCurColumn - 1, m_nCurRow );
     454             :             else
     455           0 :                 m_nCurColumn = COL_INVALID;
     456             :         }
     457             : 
     458           1 :         impl_ni_relayout();
     459             : 
     460           1 :         m_rAntiImpl.Invalidate();
     461             : 
     462             :         OSL_UNUSED( i_colIndex );
     463           1 :     }
     464             : 
     465             : 
     466           0 :     void TableControl_Impl::allColumnsRemoved()
     467             :     {
     468           0 :         m_nColumnCount = m_pModel->getColumnCount();
     469           0 :         impl_ni_relayout();
     470             : 
     471           0 :         m_rAntiImpl.Invalidate();
     472           0 :     }
     473             : 
     474             : 
     475           0 :     void TableControl_Impl::cellsUpdated( ColPos const i_firstCol, ColPos i_lastCol, RowPos const i_firstRow, RowPos const i_lastRow )
     476             :     {
     477           0 :         invalidateRowRange( i_firstRow, i_lastRow );
     478             : 
     479             :         OSL_UNUSED( i_firstCol );
     480             :         OSL_UNUSED( i_lastCol );
     481           0 :     }
     482             : 
     483             : 
     484           0 :     void TableControl_Impl::tableMetricsChanged()
     485             :     {
     486           0 :         impl_ni_updateCachedTableMetrics();
     487           0 :         impl_ni_relayout();
     488           0 :         m_rAntiImpl.Invalidate();
     489           0 :     }
     490             : 
     491             : 
     492           0 :     void TableControl_Impl::impl_invalidateColumn( ColPos const i_column )
     493             :     {
     494           0 :         Rectangle const aAllCellsArea( impl_getAllVisibleCellsArea() );
     495             : 
     496           0 :         const TableColumnGeometry aColumn( *this, aAllCellsArea, i_column );
     497           0 :         if ( aColumn.isValid() )
     498           0 :             m_rAntiImpl.Invalidate( aColumn.getRect() );
     499           0 :     }
     500             : 
     501             : 
     502           8 :     void TableControl_Impl::columnChanged( ColPos const i_column, ColumnAttributeGroup const i_attributeGroup )
     503             :     {
     504           8 :         ColumnAttributeGroup nGroup( i_attributeGroup );
     505           8 :         if ( nGroup & ColumnAttributeGroup::APPEARANCE )
     506             :         {
     507           0 :             impl_invalidateColumn( i_column );
     508           0 :             nGroup &= ~ColumnAttributeGroup::APPEARANCE;
     509             :         }
     510             : 
     511           8 :         if ( nGroup & ColumnAttributeGroup::WIDTH )
     512             :         {
     513           8 :             if ( !m_bUpdatingColWidths )
     514             :             {
     515           0 :                 impl_ni_relayout( i_column );
     516           0 :                 invalidate( TableAreaAll );
     517             :             }
     518             : 
     519           8 :             nGroup &= ~ColumnAttributeGroup::WIDTH;
     520             :         }
     521             : 
     522             :         OSL_ENSURE( ( nGroup == ColumnAttributeGroup::NONE ) || ( i_attributeGroup == ColumnAttributeGroup::ALL ),
     523             :             "TableControl_Impl::columnChanged: don't know how to handle this change!" );
     524           8 :     }
     525             : 
     526             : 
     527          13 :     Rectangle TableControl_Impl::impl_getAllVisibleCellsArea() const
     528             :     {
     529          13 :         Rectangle aArea( Point( 0, 0 ), Size( 0, 0 ) );
     530             : 
     531             :         // determine the right-most border of the last column which is
     532             :         // at least partially visible
     533          13 :         aArea.Right() = m_nRowHeaderWidthPixel;
     534          13 :         if ( !m_aColumnWidths.empty() )
     535             :         {
     536             :             // the number of pixels which are scrolled out of the left hand
     537             :             // side of the window
     538          11 :             const long nScrolledOutLeft = m_nLeftColumn == 0 ? 0 : m_aColumnWidths[ m_nLeftColumn - 1 ].getEnd();
     539             : 
     540          11 :             ColumnPositions::const_reverse_iterator loop = m_aColumnWidths.rbegin();
     541          22 :             do
     542             :             {
     543          11 :                 aArea.Right() = loop->getEnd() - nScrolledOutLeft + m_nRowHeaderWidthPixel;
     544          11 :                 ++loop;
     545             :             }
     546          44 :             while ( (   loop != m_aColumnWidths.rend() )
     547          33 :                  && (   loop->getEnd() - nScrolledOutLeft >= aArea.Right() )
     548             :                  );
     549             :         }
     550             :         // so far, aArea.Right() denotes the first pixel *after* the cell area
     551          13 :         --aArea.Right();
     552             : 
     553             :         // determine the last row which is at least partially visible
     554          13 :         aArea.Bottom() =
     555             :                 m_nColHeaderHeightPixel
     556          13 :             +   impl_getVisibleRows( true ) * m_nRowHeightPixel
     557          13 :             -   1;
     558             : 
     559          13 :         return aArea;
     560             :     }
     561             : 
     562             : 
     563           5 :     Rectangle TableControl_Impl::impl_getAllVisibleDataCellArea() const
     564             :     {
     565           5 :         Rectangle aArea( impl_getAllVisibleCellsArea() );
     566           5 :         aArea.Left() = m_nRowHeaderWidthPixel;
     567           5 :         aArea.Top() = m_nColHeaderHeightPixel;
     568           5 :         return aArea;
     569             :     }
     570             : 
     571             : 
     572           2 :     void TableControl_Impl::impl_ni_updateCachedTableMetrics()
     573             :     {
     574           2 :         m_nRowHeightPixel = m_rAntiImpl.LogicToPixel( Size( 0, m_pModel->getRowHeight() ), MAP_APPFONT ).Height();
     575             : 
     576           2 :         m_nColHeaderHeightPixel = 0;
     577           2 :         if ( m_pModel->hasColumnHeaders() )
     578           1 :            m_nColHeaderHeightPixel = m_rAntiImpl.LogicToPixel( Size( 0, m_pModel->getColumnHeaderHeight() ), MAP_APPFONT ).Height();
     579             : 
     580           2 :         m_nRowHeaderWidthPixel = 0;
     581           2 :         if ( m_pModel->hasRowHeaders() )
     582           0 :             m_nRowHeaderWidthPixel = m_rAntiImpl.LogicToPixel( Size( m_pModel->getRowHeaderWidth(), 0 ), MAP_APPFONT).Width();
     583           2 :     }
     584             : 
     585             : 
     586           2 :     void TableControl_Impl::impl_ni_updateCachedModelValues()
     587             :     {
     588           2 :         m_pInputHandler = m_pModel->getInputHandler();
     589           2 :         if ( !m_pInputHandler )
     590           1 :             m_pInputHandler.reset( new DefaultInputHandler );
     591             : 
     592           2 :         m_nColumnCount = m_pModel->getColumnCount();
     593           2 :         if ( m_nLeftColumn >= m_nColumnCount )
     594           2 :             m_nLeftColumn = ( m_nColumnCount > 0 ) ? m_nColumnCount - 1 : 0;
     595             : 
     596           2 :         m_nRowCount = m_pModel->getRowCount();
     597           2 :         if ( m_nTopRow >= m_nRowCount )
     598           2 :             m_nTopRow = ( m_nRowCount > 0 ) ? m_nRowCount - 1 : 0;
     599             : 
     600           2 :         impl_ni_updateCachedTableMetrics();
     601           2 :     }
     602             : 
     603             : 
     604             :     namespace
     605             :     {
     606             : 
     607             :         /// determines whether a scrollbar is needed for the given values
     608          22 :         bool lcl_determineScrollbarNeed( long const i_position, ScrollbarVisibility const i_visibility,
     609             :             long const i_availableSpace, long const i_neededSpace )
     610             :         {
     611          22 :             if ( i_visibility == ScrollbarShowNever )
     612           4 :                 return false;
     613          18 :             if ( i_visibility == ScrollbarShowAlways )
     614           0 :                 return true;
     615          18 :             if ( i_position > 0 )
     616           0 :                 return true;
     617          18 :             if ( i_availableSpace >= i_neededSpace )
     618          18 :                 return false;
     619           0 :             return true;
     620             :         }
     621             : 
     622             : 
     623           0 :         void lcl_setButtonRepeat( vcl::Window& _rWindow, sal_uLong _nDelay )
     624             :         {
     625           0 :             AllSettings aSettings = _rWindow.GetSettings();
     626           0 :             MouseSettings aMouseSettings = aSettings.GetMouseSettings();
     627             : 
     628           0 :             aMouseSettings.SetButtonRepeat( _nDelay );
     629           0 :             aSettings.SetMouseSettings( aMouseSettings );
     630             : 
     631           0 :             _rWindow.SetSettings( aSettings, true );
     632           0 :         }
     633             : 
     634             : 
     635          22 :         bool lcl_updateScrollbar( vcl::Window& _rParent, VclPtr<ScrollBar>& _rpBar,
     636             :             bool const i_needBar, long _nVisibleUnits,
     637             :             long _nPosition, long _nLineSize, long _nRange,
     638             :             bool _bHorizontal, const Link<>& _rScrollHandler )
     639             :         {
     640             :             // do we currently have the scrollbar?
     641          22 :             bool bHaveBar = _rpBar != nullptr;
     642             : 
     643             :             // do we need to correct the scrollbar visibility?
     644          22 :             if ( bHaveBar && !i_needBar )
     645             :             {
     646           0 :                 if ( _rpBar->IsTracking() )
     647           0 :                     _rpBar->EndTracking();
     648           0 :                 _rpBar.disposeAndClear();
     649             :             }
     650          22 :             else if ( !bHaveBar && i_needBar )
     651             :             {
     652           0 :                 _rpBar = VclPtr<ScrollBar>::Create(
     653             : 
     654             :                     &_rParent,
     655           0 :                     WB_DRAG | ( _bHorizontal ? WB_HSCROLL : WB_VSCROLL )
     656           0 :                 );
     657           0 :                 _rpBar->SetScrollHdl( _rScrollHandler );
     658             :                 // get some speed into the scrolling ....
     659           0 :                 lcl_setButtonRepeat( *_rpBar, 0 );
     660             :             }
     661             : 
     662          22 :             if ( _rpBar )
     663             :             {
     664           0 :                 _rpBar->SetRange( Range( 0, _nRange ) );
     665           0 :                 _rpBar->SetVisibleSize( _nVisibleUnits );
     666           0 :                 _rpBar->SetPageSize( _nVisibleUnits );
     667           0 :                 _rpBar->SetLineSize( _nLineSize );
     668           0 :                 _rpBar->SetThumbPos( _nPosition );
     669           0 :                 _rpBar->Show();
     670             :             }
     671             : 
     672          22 :             return ( bHaveBar != i_needBar );
     673             :         }
     674             : 
     675             : 
     676             :         /** returns the number of rows fitting into the given range,
     677             :             for the given row height. Partially fitting rows are counted, too, if the
     678             :             respective parameter says so.
     679             :         */
     680          33 :         TableSize lcl_getRowsFittingInto( long _nOverallHeight, long _nRowHeightPixel, bool _bAcceptPartialRow = false )
     681             :         {
     682             :             return  _bAcceptPartialRow
     683          18 :                 ?   ( _nOverallHeight + ( _nRowHeightPixel - 1 ) ) / _nRowHeightPixel
     684          51 :                 :   _nOverallHeight / _nRowHeightPixel;
     685             :         }
     686             : 
     687             : 
     688             :         /** returns the number of columns fitting into the given area,
     689             :             with the first visible column as given. Partially fitting columns are counted, too,
     690             :             if the respective parameter says so.
     691             :         */
     692          17 :         TableSize lcl_getColumnsVisibleWithin( const Rectangle& _rArea, ColPos _nFirstVisibleColumn,
     693             :             const TableControl_Impl& _rControl, bool _bAcceptPartialRow )
     694             :         {
     695          17 :             TableSize visibleColumns = 0;
     696          17 :             TableColumnGeometry aColumn( _rControl, _rArea, _nFirstVisibleColumn );
     697          61 :             while ( aColumn.isValid() )
     698             :             {
     699          27 :                 if ( !_bAcceptPartialRow )
     700          27 :                     if ( aColumn.getRect().Right() > _rArea.Right() )
     701             :                         // this column is only partially visible, and this is not allowed
     702           0 :                         break;
     703             : 
     704          27 :                 aColumn.moveRight();
     705          27 :                 ++visibleColumns;
     706             :             }
     707          17 :             return visibleColumns;
     708             :         }
     709             : 
     710             :     }
     711             : 
     712             : 
     713          22 :     long TableControl_Impl::impl_ni_calculateColumnWidths( ColPos const i_assumeInflexibleColumnsUpToIncluding,
     714             :         bool const i_assumeVerticalScrollbar, ::std::vector< long >& o_newColWidthsPixel ) const
     715             :     {
     716             :         // the available horizontal space
     717          22 :         long gridWidthPixel = m_rAntiImpl.GetOutputSizePixel().Width();
     718          22 :         ENSURE_OR_RETURN( !!m_pModel, "TableControl_Impl::impl_ni_calculateColumnWidths: not allowed without a model!", gridWidthPixel );
     719          22 :         if ( m_pModel->hasRowHeaders() && ( gridWidthPixel != 0 ) )
     720             :         {
     721           0 :             gridWidthPixel -= m_nRowHeaderWidthPixel;
     722             :         }
     723             : 
     724          22 :         if ( i_assumeVerticalScrollbar && ( m_pModel->getVerticalScrollbarVisibility() != ScrollbarShowNever ) )
     725             :         {
     726           9 :             long nScrollbarMetrics = m_rAntiImpl.GetSettings().GetStyleSettings().GetScrollBarSize();
     727           9 :             gridWidthPixel -= nScrollbarMetrics;
     728             :         }
     729             : 
     730             :         // no need to do anything without columns
     731          22 :         TableSize const colCount = m_pModel->getColumnCount();
     732          22 :         if ( colCount == 0 )
     733           8 :             return gridWidthPixel;
     734             : 
     735             :         // collect some meta data for our columns:
     736             :         // - their current (pixel) metrics
     737          14 :         long accumulatedCurrentWidth = 0;
     738          14 :         ::std::vector< long > currentColWidths;
     739          14 :         currentColWidths.reserve( colCount );
     740             :         typedef ::std::vector< ::std::pair< long, long > >   ColumnLimits;
     741          28 :         ColumnLimits effectiveColumnLimits;
     742          14 :         effectiveColumnLimits.reserve( colCount );
     743          14 :         long accumulatedMinWidth = 0;
     744          14 :         long accumulatedMaxWidth = 0;
     745             :         // - their relative flexibility
     746          28 :         ::std::vector< ::sal_Int32 > columnFlexibilities;
     747          14 :         columnFlexibilities.reserve( colCount );
     748          14 :         long flexibilityDenominator = 0;
     749          14 :         size_t flexibleColumnCount = 0;
     750          46 :         for ( ColPos col = 0; col < colCount; ++col )
     751             :         {
     752          32 :             PColumnModel const pColumn = m_pModel->getColumnModel( col );
     753          32 :             ENSURE_OR_THROW( !!pColumn, "invalid column returned by the model!" );
     754             : 
     755             :             // current width
     756          32 :             long const currentWidth = appFontWidthToPixel( pColumn->getWidth() );
     757          32 :             currentColWidths.push_back( currentWidth );
     758             : 
     759             :             // accumulated width
     760          32 :             accumulatedCurrentWidth += currentWidth;
     761             : 
     762             :             // flexibility
     763          32 :             ::sal_Int32 flexibility = pColumn->getFlexibility();
     764             :             OSL_ENSURE( flexibility >= 0, "TableControl_Impl::impl_ni_calculateColumnWidths: a column's flexibility should be non-negative." );
     765          64 :             if  (   ( flexibility < 0 )                                 // normalization
     766          32 :                 ||  ( !pColumn->isResizable() )                         // column not resizable => no auto-resize
     767          64 :                 ||  ( col <= i_assumeInflexibleColumnsUpToIncluding )   // column shall be treated as inflexible => respec this
     768             :                 )
     769           0 :                 flexibility = 0;
     770             : 
     771             :             // min/max width
     772          32 :             long effectiveMin = currentWidth, effectiveMax = currentWidth;
     773             :             // if the column is not flexible, it will not be asked for min/max, but we assume the current width as limit then
     774          32 :             if ( flexibility > 0 )
     775             :             {
     776          32 :                 long const minWidth = appFontWidthToPixel( pColumn->getMinWidth() );
     777          32 :                 if ( minWidth > 0 )
     778           0 :                     effectiveMin = minWidth;
     779             :                 else
     780          32 :                     effectiveMin = MIN_COLUMN_WIDTH_PIXEL;
     781             : 
     782          32 :                 long const maxWidth = appFontWidthToPixel( pColumn->getMaxWidth() );
     783             :                 OSL_ENSURE( minWidth <= maxWidth, "TableControl_Impl::impl_ni_calculateColumnWidths: pretty undecided 'bout its width limits, this column!" );
     784          32 :                 if ( ( maxWidth > 0 ) && ( maxWidth >= minWidth ) )
     785           0 :                     effectiveMax = maxWidth;
     786             :                 else
     787          32 :                     effectiveMax = gridWidthPixel; // TODO: any better guess here?
     788             : 
     789          32 :                 if ( effectiveMin == effectiveMax )
     790             :                     // if the min and the max are identical, this implies no flexibility at all
     791           0 :                     flexibility = 0;
     792             :             }
     793             : 
     794          32 :             columnFlexibilities.push_back( flexibility );
     795          32 :             flexibilityDenominator += flexibility;
     796          32 :             if ( flexibility > 0 )
     797          32 :                 ++flexibleColumnCount;
     798             : 
     799          32 :             effectiveColumnLimits.push_back( ::std::pair< long, long >( effectiveMin, effectiveMax ) );
     800          32 :             accumulatedMinWidth += effectiveMin;
     801          32 :             accumulatedMaxWidth += effectiveMax;
     802          32 :         }
     803             : 
     804          14 :         o_newColWidthsPixel = currentColWidths;
     805          14 :         if ( flexibilityDenominator == 0 )
     806             :         {
     807             :             // no column is flexible => don't adjust anything
     808             :         }
     809          14 :         else if ( gridWidthPixel > accumulatedCurrentWidth )
     810             :         {   // we have space to give away ...
     811           6 :             long distributePixel = gridWidthPixel - accumulatedCurrentWidth;
     812           6 :             if ( gridWidthPixel > accumulatedMaxWidth )
     813             :             {
     814             :                 // ... but the column's maximal widths are still less than we have
     815             :                 // => set them all to max
     816           0 :                 for ( size_t i = 0; i < size_t( colCount ); ++i )
     817             :                 {
     818           0 :                     o_newColWidthsPixel[i] = effectiveColumnLimits[i].second;
     819             :                 }
     820             :             }
     821             :             else
     822             :             {
     823           6 :                 bool startOver = false;
     824           6 :                 do
     825             :                 {
     826           6 :                     startOver = false;
     827             :                     // distribute the remaining space amongst all columns with a positive flexibility
     828          18 :                     for ( size_t i=0; i<o_newColWidthsPixel.size() && !startOver; ++i )
     829             :                     {
     830          12 :                         long const columnFlexibility = columnFlexibilities[i];
     831          12 :                         if ( columnFlexibility == 0 )
     832           0 :                             continue;
     833             : 
     834          12 :                         long newColWidth = currentColWidths[i] + columnFlexibility * distributePixel / flexibilityDenominator;
     835             : 
     836          12 :                         if ( newColWidth > effectiveColumnLimits[i].second )
     837             :                         {   // that was too much, we hit the col's maximum
     838             :                             // set the new width to exactly this maximum
     839           0 :                             newColWidth = effectiveColumnLimits[i].second;
     840             :                             // adjust the flexibility denominator ...
     841           0 :                             flexibilityDenominator -= columnFlexibility;
     842           0 :                             columnFlexibilities[i] = 0;
     843           0 :                             --flexibleColumnCount;
     844             :                             // ... and the remaining width ...
     845           0 :                             long const difference = newColWidth - currentColWidths[i];
     846           0 :                             distributePixel -= difference;
     847             :                             // ... this way, we ensure that the width not taken up by this column is consumed by the other
     848             :                             // flexible ones (if there are some)
     849             : 
     850             :                             // and start over with the first column, since there might be earlier columns which need
     851             :                             // to be recalculated now
     852           0 :                             startOver = true;
     853             :                         }
     854             : 
     855          12 :                         o_newColWidthsPixel[i] = newColWidth;
     856             :                     }
     857             :                 }
     858             :                 while ( startOver );
     859             : 
     860             :                 // are there pixels left (might be caused by rounding errors)?
     861           6 :                 distributePixel = gridWidthPixel - ::std::accumulate( o_newColWidthsPixel.begin(), o_newColWidthsPixel.end(), 0 );
     862          14 :                 while ( ( distributePixel > 0 ) && ( flexibleColumnCount > 0 ) )
     863             :                 {
     864             :                     // yes => ignore relative flexibilities, and subsequently distribute single pixels to all flexible
     865             :                     // columns which did not yet reach their maximum.
     866           8 :                     for ( size_t i=0; ( i < o_newColWidthsPixel.size() ) && ( distributePixel > 0 ); ++i )
     867             :                     {
     868           6 :                         if ( columnFlexibilities[i] == 0 )
     869           0 :                             continue;
     870             : 
     871             :                         OSL_ENSURE( o_newColWidthsPixel[i] <= effectiveColumnLimits[i].second,
     872             :                             "TableControl_Impl::impl_ni_calculateColumnWidths: inconsitency!" );
     873           6 :                         if ( o_newColWidthsPixel[i] >= effectiveColumnLimits[i].first )
     874             :                         {
     875           6 :                             columnFlexibilities[i] = 0;
     876           6 :                             --flexibleColumnCount;
     877           6 :                             continue;
     878             :                         }
     879             : 
     880           0 :                         ++o_newColWidthsPixel[i];
     881           0 :                         --distributePixel;
     882             :                     }
     883             :                 }
     884             :             }
     885             :         }
     886           8 :         else if ( gridWidthPixel < accumulatedCurrentWidth )
     887             :         {   // we need to take away some space from the columns which allow it ...
     888           7 :             long takeAwayPixel = accumulatedCurrentWidth - gridWidthPixel;
     889           7 :             if ( gridWidthPixel < accumulatedMinWidth )
     890             :             {
     891             :                 // ... but the column's minimal widths are still more than we have
     892             :                 // => set them all to min
     893           0 :                 for ( size_t i = 0; i < size_t( colCount ); ++i )
     894             :                 {
     895           0 :                     o_newColWidthsPixel[i] = effectiveColumnLimits[i].first;
     896             :                 }
     897             :             }
     898             :             else
     899             :             {
     900           7 :                 bool startOver = false;
     901           7 :                 do
     902             :                 {
     903           7 :                     startOver = false;
     904             :                     // take away the space we need from the columns with a positive flexibility
     905          25 :                     for ( size_t i=0; i<o_newColWidthsPixel.size() && !startOver; ++i )
     906             :                     {
     907          18 :                         long const columnFlexibility = columnFlexibilities[i];
     908          18 :                         if ( columnFlexibility == 0 )
     909           0 :                             continue;
     910             : 
     911          18 :                         long newColWidth = currentColWidths[i] - columnFlexibility * takeAwayPixel / flexibilityDenominator;
     912             : 
     913          18 :                         if ( newColWidth < effectiveColumnLimits[i].first )
     914             :                         {   // that was too much, we hit the col's minimum
     915             :                             // set the new width to exactly this minimum
     916           0 :                             newColWidth = effectiveColumnLimits[i].first;
     917             :                             // adjust the flexibility denominator ...
     918           0 :                             flexibilityDenominator -= columnFlexibility;
     919           0 :                             columnFlexibilities[i] = 0;
     920           0 :                             --flexibleColumnCount;
     921             :                             // ... and the remaining width ...
     922           0 :                             long const difference = currentColWidths[i] - newColWidth;
     923           0 :                             takeAwayPixel -= difference;
     924             : 
     925             :                             // and start over with the first column, since there might be earlier columns which need
     926             :                             // to be recalculated now
     927           0 :                             startOver = true;
     928             :                         }
     929             : 
     930          18 :                         o_newColWidthsPixel[i] = newColWidth;
     931             :                     }
     932             :                 }
     933             :                 while ( startOver );
     934             : 
     935             :                 // are there pixels left (might be caused by rounding errors)?
     936           7 :                 takeAwayPixel = ::std::accumulate( o_newColWidthsPixel.begin(), o_newColWidthsPixel.end(), 0 ) - gridWidthPixel;
     937          18 :                 while ( ( takeAwayPixel > 0 ) && ( flexibleColumnCount > 0 ) )
     938             :                 {
     939             :                     // yes => ignore relative flexibilities, and subsequently take away pixels from all flexible
     940             :                     // columns which did not yet reach their minimum.
     941          11 :                     for ( size_t i=0; ( i < o_newColWidthsPixel.size() ) && ( takeAwayPixel > 0 ); ++i )
     942             :                     {
     943           7 :                         if ( columnFlexibilities[i] == 0 )
     944           0 :                             continue;
     945             : 
     946             :                         OSL_ENSURE( o_newColWidthsPixel[i] >= effectiveColumnLimits[i].first,
     947             :                             "TableControl_Impl::impl_ni_calculateColumnWidths: inconsitency!" );
     948           7 :                         if ( o_newColWidthsPixel[i] <= effectiveColumnLimits[i].first )
     949             :                         {
     950           0 :                             columnFlexibilities[i] = 0;
     951           0 :                             --flexibleColumnCount;
     952           0 :                             continue;
     953             :                         }
     954             : 
     955           7 :                         --o_newColWidthsPixel[i];
     956           7 :                         --takeAwayPixel;
     957             :                     }
     958             :                 }
     959             :             }
     960             :         }
     961             : 
     962          28 :         return gridWidthPixel;
     963             :     }
     964             : 
     965             : 
     966          11 :     void TableControl_Impl::impl_ni_relayout( ColPos const i_assumeInflexibleColumnsUpToIncluding )
     967             :     {
     968          11 :         ENSURE_OR_RETURN_VOID( !m_bUpdatingColWidths, "TableControl_Impl::impl_ni_relayout: recursive call detected!" );
     969             : 
     970          11 :         m_aColumnWidths.resize( 0 );
     971          11 :         if ( !m_pModel )
     972           0 :             return;
     973             : 
     974          11 :         ::comphelper::FlagRestorationGuard const aWidthUpdateFlag( m_bUpdatingColWidths, true );
     975          22 :         SuppressCursor aHideCursor( *this );
     976             : 
     977             :         // layouting steps:
     978             : 
     979             :         // 1. adjust column widths, leaving space for a vertical scrollbar
     980             :         // 2. determine need for a vertical scrollbar
     981             :         //    - V-YES: all fine, result from 1. is still valid
     982             :         //    - V-NO: result from 1. is still under consideration
     983             : 
     984             :         // 3. determine need for a horizontal scrollbar
     985             :         //   - H-NO: all fine, result from 2. is still valid
     986             :         //   - H-YES: reconsider need for a vertical scrollbar, if result of 2. was V-NO
     987             :         //     - V-YES: all fine, result from 1. is still valid
     988             :         //     - V-NO: redistribute the remaining space (if any) amongst all columns which allow it
     989             : 
     990          22 :         ::std::vector< long > newWidthsPixel;
     991          11 :         long gridWidthPixel = impl_ni_calculateColumnWidths( i_assumeInflexibleColumnsUpToIncluding, true, newWidthsPixel );
     992             : 
     993             :         // the width/height of a scrollbar, needed several times below
     994          11 :         long const nScrollbarMetrics = m_rAntiImpl.GetSettings().GetStyleSettings().GetScrollBarSize();
     995             : 
     996             :         // determine the playground for the data cells (excluding headers)
     997             :         // TODO: what if the control is smaller than needed for the headers/scrollbars?
     998          11 :         Rectangle aDataCellPlayground( Point( 0, 0 ), m_rAntiImpl.GetOutputSizePixel() );
     999          11 :         aDataCellPlayground.Left() = m_nRowHeaderWidthPixel;
    1000          11 :         aDataCellPlayground.Top() = m_nColHeaderHeightPixel;
    1001             : 
    1002             :         OSL_ENSURE( ( m_nRowCount == m_pModel->getRowCount() ) && ( m_nColumnCount == m_pModel->getColumnCount() ),
    1003             :             "TableControl_Impl::impl_ni_relayout: how is this expected to work with invalid data?" );
    1004          11 :         long const nAllColumnsWidth = ::std::accumulate( newWidthsPixel.begin(), newWidthsPixel.end(), 0 );
    1005             : 
    1006          11 :         ScrollbarVisibility const eVertScrollbar = m_pModel->getVerticalScrollbarVisibility();
    1007          11 :         ScrollbarVisibility const eHorzScrollbar = m_pModel->getHorizontalScrollbarVisibility();
    1008             : 
    1009             :         // do we need a vertical scrollbar?
    1010             :         bool bNeedVerticalScrollbar = lcl_determineScrollbarNeed(
    1011          11 :             m_nTopRow, eVertScrollbar, aDataCellPlayground.GetHeight(), m_nRowHeightPixel * m_nRowCount );
    1012          11 :         bool bFirstRoundVScrollNeed = false;
    1013          11 :         if ( bNeedVerticalScrollbar )
    1014             :         {
    1015           0 :             aDataCellPlayground.Right() -= nScrollbarMetrics;
    1016           0 :             bFirstRoundVScrollNeed = true;
    1017             :         }
    1018             : 
    1019             :         // do we need a horizontal scrollbar?
    1020             :         bool const bNeedHorizontalScrollbar = lcl_determineScrollbarNeed(
    1021          11 :             m_nLeftColumn, eHorzScrollbar, aDataCellPlayground.GetWidth(), nAllColumnsWidth );
    1022          11 :         if ( bNeedHorizontalScrollbar )
    1023             :         {
    1024           0 :             aDataCellPlayground.Bottom() -= nScrollbarMetrics;
    1025             : 
    1026             :             // now that we just found that we need a horizontal scrollbar,
    1027             :             // the need for a vertical one may have changed, since the horizontal
    1028             :             // SB might just occupy enough space so that not all rows do fit
    1029             :             // anymore
    1030           0 :             if  ( !bFirstRoundVScrollNeed )
    1031             :             {
    1032             :                 bNeedVerticalScrollbar = lcl_determineScrollbarNeed(
    1033           0 :                     m_nTopRow, eVertScrollbar, aDataCellPlayground.GetHeight(), m_nRowHeightPixel * m_nRowCount );
    1034           0 :                 if ( bNeedVerticalScrollbar )
    1035             :                 {
    1036           0 :                     aDataCellPlayground.Right() -= nScrollbarMetrics;
    1037             :                 }
    1038             :             }
    1039             :         }
    1040             : 
    1041             :         // the initial call to impl_ni_calculateColumnWidths assumed that we need a vertical scrollbar. If, by now,
    1042             :         // we know that this is not the case, re-calculate the column widths.
    1043          11 :         if ( !bNeedVerticalScrollbar )
    1044          11 :             gridWidthPixel = impl_ni_calculateColumnWidths( i_assumeInflexibleColumnsUpToIncluding, false, newWidthsPixel );
    1045             : 
    1046             :         // update the column objects with the new widths we finally calculated
    1047          11 :         TableSize const colCount = m_pModel->getColumnCount();
    1048          11 :         m_aColumnWidths.reserve( colCount );
    1049          11 :         long accumulatedWidthPixel = m_nRowHeaderWidthPixel;
    1050          11 :         bool anyColumnWidthChanged = false;
    1051          27 :         for ( ColPos col = 0; col < colCount; ++col )
    1052             :         {
    1053          16 :             const long columnStart = accumulatedWidthPixel;
    1054          16 :             const long columnEnd = columnStart + newWidthsPixel[col];
    1055          16 :             m_aColumnWidths.push_back( MutableColumnMetrics( columnStart, columnEnd ) );
    1056          16 :             accumulatedWidthPixel = columnEnd;
    1057             : 
    1058             :             // and don't forget to forward this to the column models
    1059          16 :             PColumnModel const pColumn = m_pModel->getColumnModel( col );
    1060          16 :             ENSURE_OR_THROW( !!pColumn, "invalid column returned by the model!" );
    1061             : 
    1062          16 :             long const oldColumnWidthAppFont = pColumn->getWidth();
    1063          16 :             long const newColumnWidthAppFont = pixelWidthToAppFont( newWidthsPixel[col] );
    1064          16 :             pColumn->setWidth( newColumnWidthAppFont );
    1065             : 
    1066          16 :             anyColumnWidthChanged |= ( oldColumnWidthAppFont != newColumnWidthAppFont );
    1067          16 :         }
    1068             : 
    1069             :         // if the column widths changed, ensure everything is repainted
    1070          11 :         if ( anyColumnWidthChanged )
    1071           4 :             invalidate( TableAreaAll );
    1072             : 
    1073             :         // if the column resizing happened to leave some space at the right, but there are columns
    1074             :         // scrolled out to the left, scroll them in
    1075          33 :         while   (   ( m_nLeftColumn > 0 )
    1076          11 :                 &&  ( accumulatedWidthPixel - m_aColumnWidths[ m_nLeftColumn - 1 ].getStart() <= gridWidthPixel )
    1077             :                 )
    1078             :         {
    1079           0 :             --m_nLeftColumn;
    1080             :         }
    1081             : 
    1082             :         // now adjust the column metrics, since they currently ignore the horizontal scroll position
    1083          11 :         if ( m_nLeftColumn > 0 )
    1084             :         {
    1085           0 :             const long offsetPixel = m_aColumnWidths[ 0 ].getStart() - m_aColumnWidths[ m_nLeftColumn ].getStart();
    1086           0 :             for (   ColumnPositions::iterator colPos = m_aColumnWidths.begin();
    1087           0 :                     colPos != m_aColumnWidths.end();
    1088             :                     ++colPos
    1089             :                  )
    1090             :             {
    1091           0 :                 colPos->move( offsetPixel );
    1092             :             }
    1093             :         }
    1094             : 
    1095             :         // show or hide the scrollbars as needed, and position the data window
    1096          22 :         impl_ni_positionChildWindows( aDataCellPlayground, bNeedVerticalScrollbar, bNeedHorizontalScrollbar );
    1097             :     }
    1098             : 
    1099             : 
    1100          11 :     void TableControl_Impl::impl_ni_positionChildWindows( Rectangle const & i_dataCellPlayground,
    1101             :         bool const i_verticalScrollbar, bool const i_horizontalScrollbar )
    1102             :     {
    1103          11 :         long const nScrollbarMetrics = m_rAntiImpl.GetSettings().GetStyleSettings().GetScrollBarSize();
    1104             : 
    1105             :         // create or destroy the vertical scrollbar, as needed
    1106             :         lcl_updateScrollbar(
    1107             :             m_rAntiImpl,
    1108             :             m_pVScroll,
    1109             :             i_verticalScrollbar,
    1110          11 :             lcl_getRowsFittingInto( i_dataCellPlayground.GetHeight(), m_nRowHeightPixel ),
    1111             :                                                                     // visible units
    1112             :             m_nTopRow,                                              // current position
    1113             :             1,                                                      // line size
    1114             :             m_nRowCount,                                            // range
    1115             :             false,                                                  // vertical
    1116             :             LINK( this, TableControl_Impl, OnScroll )               // scroll handler
    1117          22 :         );
    1118             : 
    1119             :         // position it
    1120          11 :         if ( m_pVScroll )
    1121             :         {
    1122             :             Rectangle aScrollbarArea(
    1123           0 :                 Point( i_dataCellPlayground.Right() + 1, 0 ),
    1124           0 :                 Size( nScrollbarMetrics, i_dataCellPlayground.Bottom() + 1 )
    1125           0 :             );
    1126           0 :             m_pVScroll->SetPosSizePixel(
    1127           0 :                 aScrollbarArea.TopLeft(), aScrollbarArea.GetSize() );
    1128             :         }
    1129             : 
    1130             :         // create or destroy the horizontal scrollbar, as needed
    1131             :         lcl_updateScrollbar(
    1132             :             m_rAntiImpl,
    1133             :             m_pHScroll,
    1134             :             i_horizontalScrollbar,
    1135          11 :             lcl_getColumnsVisibleWithin( i_dataCellPlayground, m_nLeftColumn, *this, false ),
    1136             :                                                                     // visible units
    1137             :             m_nLeftColumn,                                          // current position
    1138             :             1,                                                      // line size
    1139             :             m_nColumnCount,                                         // range
    1140             :             true,                                                   // horizontal
    1141             :             LINK( this, TableControl_Impl, OnScroll )               // scroll handler
    1142          22 :         );
    1143             : 
    1144             :         // position it
    1145          11 :         if ( m_pHScroll )
    1146             :         {
    1147           0 :             TableSize const nVisibleUnits = lcl_getColumnsVisibleWithin( i_dataCellPlayground, m_nLeftColumn, *this, false );
    1148           0 :             TableMetrics const nRange = m_nColumnCount;
    1149           0 :             if( m_nLeftColumn + nVisibleUnits == nRange - 1 )
    1150             :             {
    1151           0 :                 if ( m_aColumnWidths[ nRange - 1 ].getStart() - m_aColumnWidths[ m_nLeftColumn ].getEnd() + m_aColumnWidths[ nRange-1 ].getWidth() > i_dataCellPlayground.GetWidth() )
    1152             :                 {
    1153           0 :                     m_pHScroll->SetVisibleSize( nVisibleUnits -1 );
    1154           0 :                     m_pHScroll->SetPageSize( nVisibleUnits - 1 );
    1155             :                 }
    1156             :             }
    1157             :             Rectangle aScrollbarArea(
    1158           0 :                 Point( 0, i_dataCellPlayground.Bottom() + 1 ),
    1159           0 :                 Size( i_dataCellPlayground.Right() + 1, nScrollbarMetrics )
    1160           0 :             );
    1161           0 :             m_pHScroll->SetPosSizePixel(
    1162           0 :                 aScrollbarArea.TopLeft(), aScrollbarArea.GetSize() );
    1163             :         }
    1164             : 
    1165             :         // the corner window connecting the two scrollbars in the lower right corner
    1166          11 :         bool bHaveScrollCorner = nullptr != m_pScrollCorner;
    1167          11 :         bool bNeedScrollCorner = ( nullptr != m_pHScroll ) && ( nullptr != m_pVScroll );
    1168          11 :         if ( bHaveScrollCorner && !bNeedScrollCorner )
    1169             :         {
    1170           0 :             m_pScrollCorner.disposeAndClear();
    1171             :         }
    1172          11 :         else if ( !bHaveScrollCorner && bNeedScrollCorner )
    1173             :         {
    1174           0 :             m_pScrollCorner = VclPtr<ScrollBarBox>::Create( &m_rAntiImpl );
    1175           0 :             m_pScrollCorner->SetSizePixel( Size( nScrollbarMetrics, nScrollbarMetrics ) );
    1176           0 :             m_pScrollCorner->SetPosPixel( Point( i_dataCellPlayground.Right() + 1, i_dataCellPlayground.Bottom() + 1 ) );
    1177           0 :             m_pScrollCorner->Show();
    1178             :         }
    1179          11 :         else if(bHaveScrollCorner && bNeedScrollCorner)
    1180             :         {
    1181           0 :             m_pScrollCorner->SetPosPixel( Point( i_dataCellPlayground.Right() + 1, i_dataCellPlayground.Bottom() + 1 ) );
    1182           0 :             m_pScrollCorner->Show();
    1183             :         }
    1184             : 
    1185             :         // resize the data window
    1186          11 :         m_pDataWindow->SetSizePixel( Size(
    1187          11 :             i_dataCellPlayground.GetWidth() + m_nRowHeaderWidthPixel,
    1188          11 :             i_dataCellPlayground.GetHeight() + m_nColHeaderHeightPixel
    1189          33 :         ) );
    1190          11 :     }
    1191             : 
    1192             : 
    1193           2 :     void TableControl_Impl::onResize()
    1194             :     {
    1195           2 :         impl_ni_relayout();
    1196           2 :         checkCursorPosition();
    1197           2 :     }
    1198             : 
    1199             : 
    1200           5 :     void TableControl_Impl::doPaintContent(vcl::RenderContext& rRenderContext, const Rectangle& _rUpdateRect)
    1201             :     {
    1202           5 :         if (!getModel())
    1203           0 :             return;
    1204           5 :         PTableRenderer pRenderer = getModel()->getRenderer();
    1205             :         DBG_ASSERT(!!pRenderer, "TableDataWindow::doPaintContent: invalid renderer!");
    1206           5 :         if (!pRenderer)
    1207           0 :             return;
    1208             : 
    1209             :         // our current style settings, to be passed to the renderer
    1210           5 :         const StyleSettings& rStyle = rRenderContext.GetSettings().GetStyleSettings();
    1211           5 :         m_nRowCount = m_pModel->getRowCount();
    1212             :         // the area occupied by all (at least partially) visible cells, including
    1213             :         // headers
    1214           5 :         Rectangle const aAllCellsWithHeaders( impl_getAllVisibleCellsArea() );
    1215             : 
    1216             :         // draw the header column area
    1217           5 :         if (m_pModel->hasColumnHeaders())
    1218             :         {
    1219           5 :             TableRowGeometry const aHeaderRow(*this, Rectangle(Point(0, 0), aAllCellsWithHeaders.BottomRight()), ROW_COL_HEADERS);
    1220           5 :             Rectangle const aColRect(aHeaderRow.getRect());
    1221           5 :             pRenderer->PaintHeaderArea(rRenderContext, aColRect, true, false, rStyle);
    1222             :             // Note that strictly, aHeaderRow.getRect() also contains the intersection between column
    1223             :             // and row header area. However, below we go to paint this intersection, again,
    1224             :             // so this hopefully doesn't hurt if we already paint it here.
    1225             : 
    1226          15 :             for (TableCellGeometry aCell(aHeaderRow, m_nLeftColumn); aCell.isValid(); aCell.moveRight())
    1227             :             {
    1228          10 :                 if (_rUpdateRect.GetIntersection(aCell.getRect()).IsEmpty())
    1229           5 :                     continue;
    1230             : 
    1231           5 :                 bool isActiveColumn = (aCell.getColumn() == getCurrentColumn());
    1232           5 :                 bool isSelectedColumn = false;
    1233           5 :                 pRenderer->PaintColumnHeader(aCell.getColumn(), isActiveColumn, isSelectedColumn, rRenderContext, aCell.getRect(), rStyle);
    1234             :             }
    1235             :         }
    1236             :         // the area occupied by the row header, if any
    1237           5 :         Rectangle aRowHeaderArea;
    1238           5 :         if (m_pModel->hasRowHeaders())
    1239             :         {
    1240           0 :             aRowHeaderArea = aAllCellsWithHeaders;
    1241           0 :             aRowHeaderArea.Right() = m_nRowHeaderWidthPixel - 1;
    1242             : 
    1243           0 :             TableSize const nVisibleRows = impl_getVisibleRows(true);
    1244           0 :             TableSize nActualRows = nVisibleRows;
    1245           0 :             if (m_nTopRow + nActualRows > m_nRowCount)
    1246           0 :                 nActualRows = m_nRowCount - m_nTopRow;
    1247           0 :             aRowHeaderArea.Bottom() = m_nColHeaderHeightPixel + m_nRowHeightPixel * nActualRows - 1;
    1248             : 
    1249           0 :             pRenderer->PaintHeaderArea(rRenderContext, aRowHeaderArea, false, true, rStyle);
    1250             :             // Note that strictly, aRowHeaderArea also contains the intersection between column
    1251             :             // and row header area. However, below we go to paint this intersection, again,
    1252             :             // so this hopefully doesn't hurt if we already paint it here.
    1253             : 
    1254           0 :             if (m_pModel->hasColumnHeaders())
    1255             :             {
    1256             :                 TableCellGeometry const aIntersection(*this, Rectangle(Point(0, 0), aAllCellsWithHeaders.BottomRight()),
    1257           0 :                                                       COL_ROW_HEADERS, ROW_COL_HEADERS);
    1258           0 :                 Rectangle const aInters(aIntersection.getRect());
    1259           0 :                 pRenderer->PaintHeaderArea(rRenderContext, aInters, true, true, rStyle);
    1260             :             }
    1261             :         }
    1262             : 
    1263             :         // draw the table content row by row
    1264           5 :         TableSize colCount = getModel()->getColumnCount();
    1265             : 
    1266             :         // paint all rows
    1267           5 :         Rectangle const aAllDataCellsArea(impl_getAllVisibleDataCellArea());
    1268          12 :         for (TableRowGeometry aRowIterator(*this, aAllCellsWithHeaders, getTopRow()); aRowIterator.isValid(); aRowIterator.moveDown())
    1269             :         {
    1270           7 :             if (_rUpdateRect.GetIntersection(aRowIterator.getRect() ).IsEmpty())
    1271           4 :                 continue;
    1272             : 
    1273           5 :             bool const isControlFocused = m_rAntiImpl.HasControlFocus();
    1274           5 :             bool const isSelectedRow = isRowSelected(aRowIterator.getRow());
    1275             : 
    1276           5 :             Rectangle const aRect = aRowIterator.getRect().GetIntersection(aAllDataCellsArea);
    1277             : 
    1278             :             // give the redenderer a chance to prepare the row
    1279           5 :             pRenderer->PrepareRow(aRowIterator.getRow(), isControlFocused, isSelectedRow, rRenderContext, aRect, rStyle);
    1280             : 
    1281             :             // paint the row header
    1282           5 :             if (m_pModel->hasRowHeaders())
    1283             :             {
    1284           0 :                 const Rectangle aCurrentRowHeader(aRowHeaderArea.GetIntersection(aRowIterator.getRect()));
    1285           0 :                 pRenderer->PaintRowHeader(isControlFocused, isSelectedRow, rRenderContext, aCurrentRowHeader, rStyle);
    1286             :             }
    1287             : 
    1288           5 :             if (!colCount)
    1289           0 :                 continue;
    1290             : 
    1291             :             // paint all cells in this row
    1292          18 :             for (TableCellGeometry aCell(aRowIterator, m_nLeftColumn); aCell.isValid(); aCell.moveRight())
    1293             :             {
    1294          13 :                 bool isSelectedColumn = false;
    1295          26 :                 pRenderer->PaintCell(aCell.getColumn(), isSelectedRow || isSelectedColumn, isControlFocused,
    1296          26 :                                      rRenderContext, aCell.getRect(), rStyle);
    1297             :             }
    1298           5 :         }
    1299             :     }
    1300             : 
    1301          21 :     void TableControl_Impl::hideCursor()
    1302             :     {
    1303          21 :         if ( ++m_nCursorHidden == 1 )
    1304           0 :             impl_ni_doSwitchCursor( false );
    1305          21 :     }
    1306             : 
    1307             : 
    1308          21 :     void TableControl_Impl::showCursor()
    1309             :     {
    1310             :         DBG_ASSERT( m_nCursorHidden > 0, "TableControl_Impl::showCursor: cursor not hidden!" );
    1311          21 :         if ( --m_nCursorHidden == 0 )
    1312           0 :             impl_ni_doSwitchCursor( true );
    1313          21 :     }
    1314             : 
    1315             : 
    1316           0 :     bool TableControl_Impl::dispatchAction( TableControlAction _eAction )
    1317             :     {
    1318           0 :         bool bSuccess = false;
    1319           0 :         bool selectionChanged = false;
    1320             : 
    1321           0 :         switch ( _eAction )
    1322             :         {
    1323             :         case cursorDown:
    1324           0 :         if ( m_pSelEngine->GetSelectionMode() == SINGLE_SELECTION )
    1325             :         {
    1326             :             //if other rows already selected, deselect them
    1327           0 :             if(!m_aSelectedRows.empty())
    1328             :             {
    1329           0 :                 invalidateSelectedRows();
    1330           0 :                 m_aSelectedRows.clear();
    1331             :             }
    1332           0 :             if ( m_nCurRow < m_nRowCount-1 )
    1333             :             {
    1334           0 :                 ++m_nCurRow;
    1335           0 :                 m_aSelectedRows.push_back(m_nCurRow);
    1336             :             }
    1337             :             else
    1338           0 :                 m_aSelectedRows.push_back(m_nCurRow);
    1339           0 :             invalidateRow( m_nCurRow );
    1340           0 :             ensureVisible(m_nCurColumn,m_nCurRow,false);
    1341           0 :             selectionChanged = true;
    1342           0 :             bSuccess = true;
    1343             :         }
    1344             :         else
    1345             :         {
    1346           0 :             if ( m_nCurRow < m_nRowCount - 1 )
    1347           0 :                 bSuccess = goTo( m_nCurColumn, m_nCurRow + 1 );
    1348             :         }
    1349           0 :             break;
    1350             : 
    1351             :         case cursorUp:
    1352           0 :         if(m_pSelEngine->GetSelectionMode() == SINGLE_SELECTION)
    1353             :         {
    1354           0 :             if(!m_aSelectedRows.empty())
    1355             :             {
    1356           0 :                 invalidateSelectedRows();
    1357           0 :                 m_aSelectedRows.clear();
    1358             :             }
    1359           0 :             if(m_nCurRow>0)
    1360             :             {
    1361           0 :                 --m_nCurRow;
    1362           0 :                 m_aSelectedRows.push_back(m_nCurRow);
    1363           0 :                 invalidateRow( m_nCurRow );
    1364             :             }
    1365             :             else
    1366             :             {
    1367           0 :                 m_aSelectedRows.push_back(m_nCurRow);
    1368           0 :                 invalidateRow( m_nCurRow );
    1369             :             }
    1370           0 :             ensureVisible(m_nCurColumn,m_nCurRow,false);
    1371           0 :             selectionChanged = true;
    1372           0 :             bSuccess = true;
    1373             :         }
    1374             :         else
    1375             :         {
    1376           0 :             if ( m_nCurRow > 0 )
    1377           0 :                 bSuccess = goTo( m_nCurColumn, m_nCurRow - 1 );
    1378             :         }
    1379           0 :         break;
    1380             :         case cursorLeft:
    1381           0 :             if ( m_nCurColumn > 0 )
    1382           0 :                 bSuccess = goTo( m_nCurColumn - 1, m_nCurRow );
    1383             :             else
    1384           0 :                 if ( ( m_nCurColumn == 0) && ( m_nCurRow > 0 ) )
    1385           0 :                     bSuccess = goTo( m_nColumnCount - 1, m_nCurRow - 1 );
    1386           0 :             break;
    1387             : 
    1388             :         case cursorRight:
    1389           0 :             if ( m_nCurColumn < m_nColumnCount - 1 )
    1390           0 :                 bSuccess = goTo( m_nCurColumn + 1, m_nCurRow );
    1391             :             else
    1392           0 :                 if ( ( m_nCurColumn == m_nColumnCount - 1 ) && ( m_nCurRow < m_nRowCount - 1 ) )
    1393           0 :                     bSuccess = goTo( 0, m_nCurRow + 1 );
    1394           0 :             break;
    1395             : 
    1396             :         case cursorToLineStart:
    1397           0 :             bSuccess = goTo( 0, m_nCurRow );
    1398           0 :             break;
    1399             : 
    1400             :         case cursorToLineEnd:
    1401           0 :             bSuccess = goTo( m_nColumnCount - 1, m_nCurRow );
    1402           0 :             break;
    1403             : 
    1404             :         case cursorToFirstLine:
    1405           0 :             bSuccess = goTo( m_nCurColumn, 0 );
    1406           0 :             break;
    1407             : 
    1408             :         case cursorToLastLine:
    1409           0 :             bSuccess = goTo( m_nCurColumn, m_nRowCount - 1 );
    1410           0 :             break;
    1411             : 
    1412             :         case cursorPageUp:
    1413             :         {
    1414           0 :             RowPos nNewRow = ::std::max( (RowPos)0, m_nCurRow - impl_getVisibleRows( false ) );
    1415           0 :             bSuccess = goTo( m_nCurColumn, nNewRow );
    1416             :         }
    1417           0 :         break;
    1418             : 
    1419             :         case cursorPageDown:
    1420             :         {
    1421           0 :             RowPos nNewRow = ::std::min( m_nRowCount - 1, m_nCurRow + impl_getVisibleRows( false ) );
    1422           0 :             bSuccess = goTo( m_nCurColumn, nNewRow );
    1423             :         }
    1424           0 :         break;
    1425             : 
    1426             :         case cursorTopLeft:
    1427           0 :             bSuccess = goTo( 0, 0 );
    1428           0 :             break;
    1429             : 
    1430             :         case cursorBottomRight:
    1431           0 :             bSuccess = goTo( m_nColumnCount - 1, m_nRowCount - 1 );
    1432           0 :             break;
    1433             : 
    1434             :         case cursorSelectRow:
    1435             :         {
    1436           0 :             if(m_pSelEngine->GetSelectionMode() == NO_SELECTION)
    1437           0 :                 return bSuccess = false;
    1438             :             //pos is the position of the current row in the vector of selected rows, if current row is selected
    1439           0 :             int pos = getRowSelectedNumber(m_aSelectedRows, m_nCurRow);
    1440             :             //if current row is selected, it should be deselected, when ALT+SPACE are pressed
    1441           0 :             if(pos>-1)
    1442             :             {
    1443           0 :                 m_aSelectedRows.erase(m_aSelectedRows.begin()+pos);
    1444           0 :                 if(m_aSelectedRows.empty() && m_nAnchor != -1)
    1445           0 :                     m_nAnchor = -1;
    1446             :             }
    1447             :             //else select the row->put it in the vector
    1448             :             else
    1449           0 :                 m_aSelectedRows.push_back(m_nCurRow);
    1450           0 :             invalidateRow( m_nCurRow );
    1451           0 :             selectionChanged = true;
    1452           0 :             bSuccess = true;
    1453             :         }
    1454           0 :             break;
    1455             :         case cursorSelectRowUp:
    1456             :         {
    1457           0 :             if(m_pSelEngine->GetSelectionMode() == NO_SELECTION)
    1458           0 :                 return bSuccess = false;
    1459           0 :             else if(m_pSelEngine->GetSelectionMode() == SINGLE_SELECTION)
    1460             :             {
    1461             :                 //if there are other selected rows, deselect them
    1462           0 :                 return false;
    1463             :             }
    1464             :             else
    1465             :             {
    1466             :                 //there are other selected rows
    1467           0 :                 if(!m_aSelectedRows.empty())
    1468             :                 {
    1469             :                     //the anchor wasn't set -> a region is not selected, that's why clear all selection
    1470             :                     //and select the current row
    1471           0 :                     if(m_nAnchor==-1)
    1472             :                     {
    1473           0 :                         invalidateSelectedRows();
    1474           0 :                         m_aSelectedRows.clear();
    1475           0 :                         m_aSelectedRows.push_back(m_nCurRow);
    1476           0 :                         invalidateRow( m_nCurRow );
    1477             :                     }
    1478             :                     else
    1479             :                     {
    1480             :                         //a region is already selected, prevRow is last selected row and the row above - nextRow - should be selected
    1481           0 :                         int prevRow = getRowSelectedNumber(m_aSelectedRows, m_nCurRow);
    1482           0 :                         int nextRow = getRowSelectedNumber(m_aSelectedRows, m_nCurRow-1);
    1483           0 :                         if(prevRow>-1)
    1484             :                          {
    1485             :                              //if m_nCurRow isn't the upper one, can move up, otherwise not
    1486           0 :                             if(m_nCurRow>0)
    1487           0 :                                  m_nCurRow--;
    1488             :                              else
    1489           0 :                                  return bSuccess = true;
    1490             :                              //if nextRow already selected, deselect it, otherwise select it
    1491           0 :                              if(nextRow>-1 && m_aSelectedRows[nextRow] == m_nCurRow)
    1492             :                              {
    1493           0 :                                  m_aSelectedRows.erase(m_aSelectedRows.begin()+prevRow);
    1494           0 :                                  invalidateRow( m_nCurRow + 1 );
    1495             :                              }
    1496             :                              else
    1497             :                             {
    1498           0 :                                  m_aSelectedRows.push_back(m_nCurRow);
    1499           0 :                                  invalidateRow( m_nCurRow );
    1500             :                              }
    1501             :                          }
    1502             :                         else
    1503             :                         {
    1504           0 :                             if(m_nCurRow>0)
    1505             :                             {
    1506           0 :                                 m_aSelectedRows.push_back(m_nCurRow);
    1507           0 :                                 m_nCurRow--;
    1508           0 :                                 m_aSelectedRows.push_back(m_nCurRow);
    1509           0 :                                 invalidateSelectedRegion( m_nCurRow+1, m_nCurRow );
    1510             :                             }
    1511             :                         }
    1512             :                     }
    1513             :                 }
    1514             :                 else
    1515             :                 {
    1516             :                     //if nothing is selected and the current row isn't the upper one
    1517             :                     //select the current and one row above
    1518             :                     //otherwise select only the upper row
    1519           0 :                     if(m_nCurRow>0)
    1520             :                     {
    1521           0 :                         m_aSelectedRows.push_back(m_nCurRow);
    1522           0 :                         m_nCurRow--;
    1523           0 :                         m_aSelectedRows.push_back(m_nCurRow);
    1524           0 :                         invalidateSelectedRegion( m_nCurRow+1, m_nCurRow );
    1525             :                     }
    1526             :                     else
    1527             :                     {
    1528           0 :                         m_aSelectedRows.push_back(m_nCurRow);
    1529           0 :                         invalidateRow( m_nCurRow );
    1530             :                     }
    1531             :                 }
    1532           0 :                 m_pSelEngine->SetAnchor(true);
    1533           0 :                 m_nAnchor = m_nCurRow;
    1534           0 :                 ensureVisible(m_nCurColumn, m_nCurRow, false);
    1535           0 :                 selectionChanged = true;
    1536           0 :                 bSuccess = true;
    1537             :             }
    1538             :         }
    1539           0 :         break;
    1540             :         case cursorSelectRowDown:
    1541             :         {
    1542           0 :             if(m_pSelEngine->GetSelectionMode() == NO_SELECTION)
    1543           0 :                 bSuccess = false;
    1544           0 :             else if(m_pSelEngine->GetSelectionMode() == SINGLE_SELECTION)
    1545             :             {
    1546           0 :                 bSuccess = false;
    1547             :             }
    1548             :             else
    1549             :             {
    1550           0 :                 if(!m_aSelectedRows.empty())
    1551             :                 {
    1552             :                     //the anchor wasn't set -> a region is not selected, that's why clear all selection
    1553             :                     //and select the current row
    1554           0 :                     if(m_nAnchor==-1)
    1555             :                     {
    1556           0 :                         invalidateSelectedRows();
    1557           0 :                         m_aSelectedRows.clear();
    1558           0 :                         m_aSelectedRows.push_back(m_nCurRow);
    1559           0 :                         invalidateRow( m_nCurRow );
    1560             :                         }
    1561             :                     else
    1562             :                     {
    1563             :                         //a region is already selected, prevRow is last selected row and the row beneath - nextRow - should be selected
    1564           0 :                         int prevRow = getRowSelectedNumber(m_aSelectedRows, m_nCurRow);
    1565           0 :                         int nextRow = getRowSelectedNumber(m_aSelectedRows, m_nCurRow+1);
    1566           0 :                         if(prevRow>-1)
    1567             :                          {
    1568             :                              //if m_nCurRow isn't the last one, can move down, otherwise not
    1569           0 :                              if(m_nCurRow<m_nRowCount-1)
    1570           0 :                                  m_nCurRow++;
    1571             :                              else
    1572           0 :                                 return bSuccess = true;
    1573             :                              //if next row already selected, deselect it, otherwise select it
    1574           0 :                              if(nextRow>-1 && m_aSelectedRows[nextRow] == m_nCurRow)
    1575             :                              {
    1576           0 :                                  m_aSelectedRows.erase(m_aSelectedRows.begin()+prevRow);
    1577           0 :                                  invalidateRow( m_nCurRow - 1 );
    1578             :                              }
    1579             :                              else
    1580             :                              {
    1581           0 :                                  m_aSelectedRows.push_back(m_nCurRow);
    1582           0 :                                  invalidateRow( m_nCurRow );
    1583             :                              }
    1584             :                         }
    1585             :                         else
    1586             :                         {
    1587           0 :                             if(m_nCurRow<m_nRowCount-1)
    1588             :                             {
    1589           0 :                                 m_aSelectedRows.push_back(m_nCurRow);
    1590           0 :                                 m_nCurRow++;
    1591           0 :                                 m_aSelectedRows.push_back(m_nCurRow);
    1592           0 :                                 invalidateSelectedRegion( m_nCurRow-1, m_nCurRow );
    1593             :                             }
    1594             :                         }
    1595             :                     }
    1596             :                 }
    1597             :                 else
    1598             :                 {
    1599             :                     //there wasn't any selection, select current and row beneath, otherwise only row beneath
    1600           0 :                     if(m_nCurRow<m_nRowCount-1)
    1601             :                     {
    1602           0 :                         m_aSelectedRows.push_back(m_nCurRow);
    1603           0 :                         m_nCurRow++;
    1604           0 :                         m_aSelectedRows.push_back(m_nCurRow);
    1605           0 :                         invalidateSelectedRegion( m_nCurRow-1, m_nCurRow );
    1606             :                     }
    1607             :                     else
    1608             :                     {
    1609           0 :                         m_aSelectedRows.push_back(m_nCurRow);
    1610           0 :                         invalidateRow( m_nCurRow );
    1611             :                     }
    1612             :                 }
    1613           0 :                 m_pSelEngine->SetAnchor(true);
    1614           0 :                 m_nAnchor = m_nCurRow;
    1615           0 :                 ensureVisible(m_nCurColumn, m_nCurRow, false);
    1616           0 :                 selectionChanged = true;
    1617           0 :                 bSuccess = true;
    1618             :             }
    1619             :         }
    1620           0 :         break;
    1621             : 
    1622             :         case cursorSelectRowAreaTop:
    1623             :         {
    1624           0 :             if(m_pSelEngine->GetSelectionMode() == NO_SELECTION)
    1625           0 :                 bSuccess = false;
    1626           0 :             else if(m_pSelEngine->GetSelectionMode() == SINGLE_SELECTION)
    1627           0 :                 bSuccess = false;
    1628             :             else
    1629             :             {
    1630             :                 //select the region between the current and the upper row
    1631           0 :                 RowPos iter = m_nCurRow;
    1632           0 :                 invalidateSelectedRegion( m_nCurRow, 0 );
    1633             :                 //put the rows in vector
    1634           0 :                 while(iter>=0)
    1635             :                 {
    1636           0 :                     if ( !isRowSelected( iter ) )
    1637           0 :                         m_aSelectedRows.push_back(iter);
    1638           0 :                     --iter;
    1639             :                 }
    1640           0 :                 m_nCurRow = 0;
    1641           0 :                 m_nAnchor = m_nCurRow;
    1642           0 :                 m_pSelEngine->SetAnchor(true);
    1643           0 :                 ensureVisible(m_nCurColumn, 0, false);
    1644           0 :                 selectionChanged = true;
    1645           0 :                 bSuccess = true;
    1646             :             }
    1647             :         }
    1648           0 :         break;
    1649             : 
    1650             :         case cursorSelectRowAreaBottom:
    1651             :         {
    1652           0 :             if(m_pSelEngine->GetSelectionMode() == NO_SELECTION)
    1653           0 :                 return bSuccess = false;
    1654           0 :             else if(m_pSelEngine->GetSelectionMode() == SINGLE_SELECTION)
    1655           0 :                 return bSuccess = false;
    1656             :             //select the region between the current and the last row
    1657           0 :             RowPos iter = m_nCurRow;
    1658           0 :             invalidateSelectedRegion( m_nCurRow, m_nRowCount-1 );
    1659             :             //put the rows in the vector
    1660           0 :             while(iter<=m_nRowCount)
    1661             :             {
    1662           0 :                 if ( !isRowSelected( iter ) )
    1663           0 :                     m_aSelectedRows.push_back(iter);
    1664           0 :                 ++iter;
    1665             :             }
    1666           0 :             m_nCurRow = m_nRowCount-1;
    1667           0 :             m_nAnchor = m_nCurRow;
    1668           0 :             m_pSelEngine->SetAnchor(true);
    1669           0 :             ensureVisible(m_nCurColumn, m_nRowCount-1, false);
    1670           0 :             selectionChanged = true;
    1671           0 :             bSuccess = true;
    1672             :         }
    1673           0 :         break;
    1674             :         default:
    1675             :             OSL_FAIL( "TableControl_Impl::dispatchAction: unsupported action!" );
    1676           0 :             break;
    1677             :         }
    1678             : 
    1679           0 :         if ( bSuccess && selectionChanged )
    1680             :         {
    1681           0 :             m_rAntiImpl.Select();
    1682             :         }
    1683             : 
    1684           0 :         return bSuccess;
    1685             :     }
    1686             : 
    1687             : 
    1688           0 :     void TableControl_Impl::impl_ni_doSwitchCursor( bool _bShow )
    1689             :     {
    1690           0 :         PTableRenderer pRenderer = !!m_pModel ? m_pModel->getRenderer() : PTableRenderer();
    1691           0 :         if ( !!pRenderer )
    1692             :         {
    1693           0 :             Rectangle aCellRect;
    1694           0 :             impl_getCellRect( m_nCurColumn, m_nCurRow, aCellRect );
    1695           0 :             if ( _bShow )
    1696           0 :                 pRenderer->ShowCellCursor( *m_pDataWindow, aCellRect );
    1697             :             else
    1698           0 :                 pRenderer->HideCellCursor( *m_pDataWindow, aCellRect );
    1699           0 :         }
    1700           0 :     }
    1701             : 
    1702             : 
    1703           0 :     void TableControl_Impl::impl_getCellRect( ColPos _nColumn, RowPos _nRow, Rectangle& _rCellRect ) const
    1704             :     {
    1705           0 :         if  (   !m_pModel
    1706           0 :             ||  ( COL_INVALID == _nColumn )
    1707           0 :             ||  ( ROW_INVALID == _nRow )
    1708             :             )
    1709             :         {
    1710           0 :             _rCellRect.SetEmpty();
    1711           0 :             return;
    1712             :         }
    1713             : 
    1714           0 :         TableCellGeometry aCell( *this, impl_getAllVisibleCellsArea(), _nColumn, _nRow );
    1715           0 :         _rCellRect = aCell.getRect();
    1716             :     }
    1717             : 
    1718             : 
    1719           0 :     RowPos TableControl_Impl::getRowAtPoint( const Point& rPoint ) const
    1720             :     {
    1721           0 :         return impl_getRowForAbscissa( rPoint.Y() );
    1722             :     }
    1723             : 
    1724             : 
    1725           0 :     ColPos TableControl_Impl::getColAtPoint( const Point& rPoint ) const
    1726             :     {
    1727           0 :         return impl_getColumnForOrdinate( rPoint.X() );
    1728             :     }
    1729             : 
    1730             : 
    1731           0 :     TableCell TableControl_Impl::hitTest( Point const & i_point ) const
    1732             :     {
    1733           0 :         TableCell aCell( getColAtPoint( i_point ), getRowAtPoint( i_point ) );
    1734           0 :         if ( aCell.nColumn > COL_ROW_HEADERS )
    1735             :         {
    1736           0 :             PColumnModel const pColumn = m_pModel->getColumnModel( aCell.nColumn );
    1737           0 :             MutableColumnMetrics const & rColInfo( m_aColumnWidths[ aCell.nColumn ] );
    1738           0 :             if  (   ( rColInfo.getEnd() - 3 <= i_point.X() )
    1739           0 :                 &&  ( rColInfo.getEnd() >= i_point.X() )
    1740           0 :                 &&  pColumn->isResizable()
    1741             :                 )
    1742             :             {
    1743           0 :                 aCell.eArea = ColumnDivider;
    1744           0 :             }
    1745             :         }
    1746           0 :         return aCell;
    1747             :     }
    1748             : 
    1749             : 
    1750           0 :     ColumnMetrics TableControl_Impl::getColumnMetrics( ColPos const i_column ) const
    1751             :     {
    1752           0 :         ENSURE_OR_RETURN( ( i_column >= 0 ) && ( i_column < m_pModel->getColumnCount() ),
    1753             :             "TableControl_Impl::getColumnMetrics: illegal column index!", ColumnMetrics() );
    1754           0 :         return (ColumnMetrics const &)m_aColumnWidths[ i_column ];
    1755             :     }
    1756             : 
    1757             : 
    1758          19 :     PTableModel TableControl_Impl::getModel() const
    1759             :     {
    1760          19 :         return m_pModel;
    1761             :     }
    1762             : 
    1763             : 
    1764           8 :     RowPos TableControl_Impl::getCurrentColumn() const
    1765             :     {
    1766           8 :         return m_nCurColumn;
    1767             :     }
    1768             : 
    1769             : 
    1770           3 :     RowPos TableControl_Impl::getCurrentRow() const
    1771             :     {
    1772           3 :         return m_nCurRow;
    1773             :     }
    1774             : 
    1775             : 
    1776           0 :     ::Size TableControl_Impl::getTableSizePixel() const
    1777             :     {
    1778           0 :         return m_pDataWindow->GetOutputSizePixel();
    1779             :     }
    1780             : 
    1781             : 
    1782           0 :     void TableControl_Impl::setPointer( Pointer const & i_pointer )
    1783             :     {
    1784           0 :         m_pDataWindow->SetPointer( i_pointer );
    1785           0 :     }
    1786             : 
    1787             : 
    1788           0 :     void TableControl_Impl::captureMouse()
    1789             :     {
    1790           0 :         m_pDataWindow->CaptureMouse();
    1791           0 :     }
    1792             : 
    1793             : 
    1794           0 :     void TableControl_Impl::releaseMouse()
    1795             :     {
    1796           0 :         m_pDataWindow->ReleaseMouse();
    1797           0 :     }
    1798             : 
    1799             : 
    1800           4 :     void TableControl_Impl::invalidate( TableArea const i_what )
    1801             :     {
    1802           4 :         switch ( i_what )
    1803             :         {
    1804             :         case TableAreaColumnHeaders:
    1805           0 :             m_pDataWindow->Invalidate( calcHeaderRect( true ) );
    1806           0 :             break;
    1807             : 
    1808             :         case TableAreaRowHeaders:
    1809           0 :             m_pDataWindow->Invalidate( calcHeaderRect( false ) );
    1810           0 :             break;
    1811             : 
    1812             :         case TableAreaDataArea:
    1813           0 :             m_pDataWindow->Invalidate( impl_getAllVisibleDataCellArea() );
    1814           0 :             break;
    1815             : 
    1816             :         case TableAreaAll:
    1817           4 :             m_pDataWindow->Invalidate();
    1818           4 :             m_pDataWindow->GetParent()->Invalidate( InvalidateFlags::Transparent );
    1819           4 :             break;
    1820             :         }
    1821           4 :     }
    1822             : 
    1823             : 
    1824          16 :     long TableControl_Impl::pixelWidthToAppFont( long const i_pixels ) const
    1825             :     {
    1826          16 :         return m_pDataWindow->PixelToLogic( Size( i_pixels, 0 ), MAP_APPFONT ).Width();
    1827             :     }
    1828             : 
    1829             : 
    1830          96 :     long TableControl_Impl::appFontWidthToPixel( long const i_appFontUnits ) const
    1831             :     {
    1832          96 :         return m_pDataWindow->LogicToPixel( Size( i_appFontUnits, 0 ), MAP_APPFONT ).Width();
    1833             :     }
    1834             : 
    1835             : 
    1836           0 :     void TableControl_Impl::hideTracking()
    1837             :     {
    1838           0 :         m_pDataWindow->HideTracking();
    1839           0 :     }
    1840             : 
    1841             : 
    1842           0 :     void TableControl_Impl::showTracking( Rectangle const & i_location, sal_uInt16 const i_flags )
    1843             :     {
    1844           0 :         m_pDataWindow->ShowTracking( i_location, i_flags );
    1845           0 :     }
    1846             : 
    1847             : 
    1848           0 :     bool TableControl_Impl::activateCell( ColPos const i_col, RowPos const i_row )
    1849             :     {
    1850           0 :         return goTo( i_col, i_row );
    1851             :     }
    1852             : 
    1853             : 
    1854           0 :     void TableControl_Impl::invalidateSelectedRegion( RowPos _nPrevRow, RowPos _nCurRow )
    1855             :     {
    1856             :         // get the visible area of the table control and set the Left and right border of the region to be repainted
    1857           0 :         Rectangle const aAllCells( impl_getAllVisibleCellsArea() );
    1858             : 
    1859           0 :         Rectangle aInvalidateRect;
    1860           0 :         aInvalidateRect.Left() = aAllCells.Left();
    1861           0 :         aInvalidateRect.Right() = aAllCells.Right();
    1862             :         // if only one row is selected
    1863           0 :         if ( _nPrevRow == _nCurRow )
    1864             :         {
    1865           0 :             Rectangle aCellRect;
    1866           0 :             impl_getCellRect( m_nCurColumn, _nCurRow, aCellRect );
    1867           0 :             aInvalidateRect.Top() = aCellRect.Top();
    1868           0 :             aInvalidateRect.Bottom() = aCellRect.Bottom();
    1869             :         }
    1870             :         //if the region is above the current row
    1871           0 :         else if(_nPrevRow < _nCurRow )
    1872             :         {
    1873           0 :             Rectangle aCellRect;
    1874           0 :             impl_getCellRect( m_nCurColumn, _nPrevRow, aCellRect );
    1875           0 :             aInvalidateRect.Top() = aCellRect.Top();
    1876           0 :             impl_getCellRect( m_nCurColumn, _nCurRow, aCellRect );
    1877           0 :             aInvalidateRect.Bottom() = aCellRect.Bottom();
    1878             :         }
    1879             :         //if the region is beneath the current row
    1880             :         else
    1881             :         {
    1882           0 :             Rectangle aCellRect;
    1883           0 :             impl_getCellRect( m_nCurColumn, _nCurRow, aCellRect );
    1884           0 :             aInvalidateRect.Top() = aCellRect.Top();
    1885           0 :             impl_getCellRect( m_nCurColumn, _nPrevRow, aCellRect );
    1886           0 :             aInvalidateRect.Bottom() = aCellRect.Bottom();
    1887             :         }
    1888             : 
    1889           0 :         invalidateRect(aInvalidateRect);
    1890           0 :     }
    1891             : 
    1892           3 :     void TableControl_Impl::invalidateRect(const Rectangle &rInvalidateRect)
    1893             :     {
    1894           3 :         m_pDataWindow->Invalidate( rInvalidateRect,
    1895           3 :             m_pDataWindow->GetControlBackground().GetTransparency() ? InvalidateFlags::Transparent : InvalidateFlags::NONE );
    1896           3 :     }
    1897             : 
    1898             : 
    1899           0 :     void TableControl_Impl::invalidateSelectedRows()
    1900             :     {
    1901           0 :         for (   ::std::vector< RowPos >::iterator selRow = m_aSelectedRows.begin();
    1902           0 :                 selRow != m_aSelectedRows.end();
    1903             :                 ++selRow
    1904             :             )
    1905             :         {
    1906           0 :             invalidateRow( *selRow );
    1907             :         }
    1908           0 :     }
    1909             : 
    1910             : 
    1911           3 :     void TableControl_Impl::invalidateRowRange( RowPos const i_firstRow, RowPos const i_lastRow )
    1912             :     {
    1913           3 :         RowPos const firstRow = i_firstRow < m_nTopRow ? m_nTopRow : i_firstRow;
    1914           3 :         RowPos const lastVisibleRow = m_nTopRow + impl_getVisibleRows( true ) - 1;
    1915           3 :         RowPos const lastRow = ( ( i_lastRow == ROW_INVALID ) || ( i_lastRow > lastVisibleRow ) ) ? lastVisibleRow : i_lastRow;
    1916             : 
    1917           3 :         Rectangle aInvalidateRect;
    1918             : 
    1919           3 :         Rectangle const aVisibleCellsArea( impl_getAllVisibleCellsArea() );
    1920           3 :         TableRowGeometry aRow( *this, aVisibleCellsArea, firstRow, true );
    1921          28 :         while ( aRow.isValid() && ( aRow.getRow() <= lastRow ) )
    1922             :         {
    1923          22 :             aInvalidateRect.Union( aRow.getRect() );
    1924          22 :             aRow.moveDown();
    1925             :         }
    1926             : 
    1927           3 :         if ( i_lastRow == ROW_INVALID )
    1928           3 :             aInvalidateRect.Bottom() = m_pDataWindow->GetOutputSizePixel().Height();
    1929             : 
    1930           3 :         invalidateRect(aInvalidateRect);
    1931           3 :     }
    1932             : 
    1933             : 
    1934           2 :     void TableControl_Impl::checkCursorPosition()
    1935             :     {
    1936             : 
    1937           2 :         TableSize nVisibleRows = impl_getVisibleRows(true);
    1938           2 :         TableSize nVisibleCols = impl_getVisibleColumns(true);
    1939           2 :         if  (   ( m_nTopRow + nVisibleRows > m_nRowCount )
    1940           1 :             &&  ( m_nRowCount >= nVisibleRows )
    1941             :             )
    1942             :         {
    1943           0 :             --m_nTopRow;
    1944             :         }
    1945             :         else
    1946             :         {
    1947           2 :             m_nTopRow = 0;
    1948             :         }
    1949             : 
    1950           2 :         if  (   ( m_nLeftColumn + nVisibleCols > m_nColumnCount )
    1951           0 :             &&  ( m_nColumnCount >= nVisibleCols )
    1952             :             )
    1953             :         {
    1954           0 :             --m_nLeftColumn;
    1955             :         }
    1956             :         else
    1957             :         {
    1958           2 :             m_nLeftColumn = 0;
    1959             :         }
    1960             : 
    1961           2 :         m_pDataWindow->Invalidate();
    1962           2 :     }
    1963             : 
    1964             : 
    1965          22 :     TableSize TableControl_Impl::impl_getVisibleRows( bool _bAcceptPartialRow ) const
    1966             :     {
    1967             :         DBG_ASSERT( m_pDataWindow, "TableControl_Impl::impl_getVisibleRows: no data window!" );
    1968             : 
    1969             :         return lcl_getRowsFittingInto(
    1970          44 :             m_pDataWindow->GetOutputSizePixel().Height() - m_nColHeaderHeightPixel,
    1971             :             m_nRowHeightPixel,
    1972             :             _bAcceptPartialRow
    1973          66 :         );
    1974             :     }
    1975             : 
    1976             : 
    1977           6 :     TableSize TableControl_Impl::impl_getVisibleColumns( bool _bAcceptPartialCol ) const
    1978             :     {
    1979             :         DBG_ASSERT( m_pDataWindow, "TableControl_Impl::impl_getVisibleColumns: no data window!" );
    1980             : 
    1981             :         return lcl_getColumnsVisibleWithin(
    1982           6 :             Rectangle( Point( 0, 0 ), m_pDataWindow->GetOutputSizePixel() ),
    1983             :             m_nLeftColumn,
    1984             :             *this,
    1985             :             _bAcceptPartialCol
    1986          12 :         );
    1987             :     }
    1988             : 
    1989             : 
    1990           4 :     bool TableControl_Impl::goTo( ColPos _nColumn, RowPos _nRow )
    1991             :     {
    1992             :         // TODO: give veto listeners a chance
    1993             : 
    1994           4 :         if  (  ( _nColumn < 0 ) || ( _nColumn >= m_nColumnCount )
    1995           4 :             || ( _nRow < 0 ) || ( _nRow >= m_nRowCount )
    1996             :             )
    1997             :         {
    1998             :             OSL_ENSURE( false, "TableControl_Impl::goTo: invalid row or column index!" );
    1999           0 :             return false;
    2000             :         }
    2001             : 
    2002           4 :         SuppressCursor aHideCursor( *this );
    2003           4 :         m_nCurColumn = _nColumn;
    2004           4 :         m_nCurRow = _nRow;
    2005             : 
    2006             :         // ensure that the new cell is visible
    2007           4 :         ensureVisible( m_nCurColumn, m_nCurRow, false );
    2008           4 :         return true;
    2009             :     }
    2010             : 
    2011             : 
    2012           4 :     void TableControl_Impl::ensureVisible( ColPos _nColumn, RowPos _nRow, bool _bAcceptPartialVisibility )
    2013             :     {
    2014             :         DBG_ASSERT( ( _nColumn >= 0 ) && ( _nColumn < m_nColumnCount )
    2015             :                  && ( _nRow >= 0 ) && ( _nRow < m_nRowCount ),
    2016             :                  "TableControl_Impl::ensureVisible: invalid coordinates!" );
    2017             : 
    2018           4 :         SuppressCursor aHideCursor( *this );
    2019             : 
    2020           4 :         if ( _nColumn < m_nLeftColumn )
    2021           0 :             impl_scrollColumns( _nColumn - m_nLeftColumn );
    2022             :         else
    2023             :         {
    2024           4 :             TableSize nVisibleColumns = impl_getVisibleColumns( _bAcceptPartialVisibility );
    2025           4 :             if ( _nColumn > m_nLeftColumn + nVisibleColumns - 1 )
    2026             :             {
    2027           0 :                 impl_scrollColumns( _nColumn - ( m_nLeftColumn + nVisibleColumns - 1 ) );
    2028             :                 // TODO: since not all columns have the same width, this might in theory result
    2029             :                 // in the column still not being visible.
    2030             :             }
    2031             :         }
    2032             : 
    2033           4 :         if ( _nRow < m_nTopRow )
    2034           0 :             impl_scrollRows( _nRow - m_nTopRow );
    2035             :         else
    2036             :         {
    2037           4 :             TableSize nVisibleRows = impl_getVisibleRows( _bAcceptPartialVisibility );
    2038           4 :             if ( _nRow > m_nTopRow + nVisibleRows - 1 )
    2039           0 :                 impl_scrollRows( _nRow - ( m_nTopRow + nVisibleRows - 1 ) );
    2040           4 :         }
    2041           4 :     }
    2042             : 
    2043             : 
    2044           0 :     OUString TableControl_Impl::getCellContentAsString( RowPos const i_row, ColPos const i_col )
    2045             :     {
    2046           0 :         Any aCellValue;
    2047           0 :         m_pModel->getCellContent( i_col, i_row, aCellValue );
    2048             : 
    2049           0 :         OUString sCellStringContent;
    2050           0 :         m_pModel->getRenderer()->GetFormattedCellString( aCellValue, i_col, i_row, sCellStringContent );
    2051             : 
    2052           0 :         return sCellStringContent;
    2053             :     }
    2054             : 
    2055             : 
    2056           0 :     TableSize TableControl_Impl::impl_ni_ScrollRows( TableSize _nRowDelta )
    2057             :     {
    2058             :         // compute new top row
    2059             :         RowPos nNewTopRow =
    2060             :             ::std::max(
    2061           0 :                 ::std::min( (RowPos)( m_nTopRow + _nRowDelta ), (RowPos)( m_nRowCount - 1 ) ),
    2062             :                 (RowPos)0
    2063           0 :             );
    2064             : 
    2065           0 :         RowPos nOldTopRow = m_nTopRow;
    2066           0 :         m_nTopRow = nNewTopRow;
    2067             : 
    2068             :         // if updates are enabled currently, scroll the viewport
    2069           0 :         if ( m_nTopRow != nOldTopRow )
    2070             :         {
    2071           0 :             SuppressCursor aHideCursor( *this );
    2072             :             // TODO: call a onStartScroll at our listener (or better an own onStartScroll,
    2073             :             // which hides the cursor and then calls the listener)
    2074             :             // Same for onEndScroll
    2075             : 
    2076             :             // scroll the view port, if possible
    2077           0 :             long nPixelDelta = m_nRowHeightPixel * ( m_nTopRow - nOldTopRow );
    2078             : 
    2079           0 :             Rectangle aDataArea( Point( 0, m_nColHeaderHeightPixel ), m_pDataWindow->GetOutputSizePixel() );
    2080             : 
    2081           0 :             if  (   m_pDataWindow->GetBackground().IsScrollable()
    2082           0 :                 &&  std::abs( nPixelDelta ) < aDataArea.GetHeight()
    2083             :                 )
    2084             :             {
    2085           0 :                 m_pDataWindow->Scroll( 0, (long)-nPixelDelta, aDataArea, ScrollFlags::Clip | ScrollFlags::Update | ScrollFlags::Children);
    2086             :             }
    2087             :             else
    2088             :             {
    2089           0 :                 m_pDataWindow->Invalidate( InvalidateFlags::Update );
    2090           0 :                 m_pDataWindow->GetParent()->Invalidate( InvalidateFlags::Transparent );
    2091             :             }
    2092             : 
    2093             :             // update the position at the vertical scrollbar
    2094           0 :             if ( m_pVScroll != nullptr )
    2095           0 :                 m_pVScroll->SetThumbPos( m_nTopRow );
    2096             :         }
    2097             : 
    2098             :         // The scroll bar availaility might change when we scrolled.
    2099             :         // For instance, imagine a view with 10 rows, if which 5 fit into the window, numbered 1 to 10.
    2100             :         // Now let
    2101             :         // - the user scroll to row number 6, so the last 5 rows are visible
    2102             :         // - somebody remove the last 4 rows
    2103             :         // - the user scroll to row number 5 being the top row, so the last two rows are visible
    2104             :         // - somebody remove row number 6
    2105             :         // - the user scroll to row number 1
    2106             :         // => in this case, the need for the scrollbar vanishes immediately.
    2107           0 :         if ( m_nTopRow == 0 )
    2108           0 :             m_rAntiImpl.PostUserEvent( LINK( this, TableControl_Impl, OnUpdateScrollbars ) );
    2109             : 
    2110           0 :         return (TableSize)( m_nTopRow - nOldTopRow );
    2111             :     }
    2112             : 
    2113             : 
    2114           0 :     TableSize TableControl_Impl::impl_scrollRows( TableSize const i_rowDelta )
    2115             :     {
    2116           0 :         return impl_ni_ScrollRows( i_rowDelta );
    2117             :     }
    2118             : 
    2119             : 
    2120           0 :     TableSize TableControl_Impl::impl_ni_ScrollColumns( TableSize _nColumnDelta )
    2121             :     {
    2122             :         // compute new left column
    2123             :         const ColPos nNewLeftColumn =
    2124             :             ::std::max(
    2125           0 :                 ::std::min( (ColPos)( m_nLeftColumn + _nColumnDelta ), (ColPos)( m_nColumnCount - 1 ) ),
    2126             :                 (ColPos)0
    2127           0 :             );
    2128             : 
    2129           0 :         const ColPos nOldLeftColumn = m_nLeftColumn;
    2130           0 :         m_nLeftColumn = nNewLeftColumn;
    2131             : 
    2132             :         // if updates are enabled currently, scroll the viewport
    2133           0 :         if ( m_nLeftColumn != nOldLeftColumn )
    2134             :         {
    2135           0 :             SuppressCursor aHideCursor( *this );
    2136             :             // TODO: call a onStartScroll at our listener (or better an own onStartScroll,
    2137             :             // which hides the cursor and then calls the listener)
    2138             :             // Same for onEndScroll
    2139             : 
    2140             :             // scroll the view port, if possible
    2141           0 :             const Rectangle aDataArea( Point( m_nRowHeaderWidthPixel, 0 ), m_pDataWindow->GetOutputSizePixel() );
    2142             : 
    2143             :             long nPixelDelta =
    2144           0 :                     m_aColumnWidths[ nOldLeftColumn ].getStart()
    2145           0 :                 -   m_aColumnWidths[ m_nLeftColumn ].getStart();
    2146             : 
    2147             :             // update our column positions
    2148             :             // Do this *before* scrolling, as ScrollFlags::Update will trigger a paint, which already needs the correct
    2149             :             // information in m_aColumnWidths
    2150           0 :             for (   ColumnPositions::iterator colPos = m_aColumnWidths.begin();
    2151           0 :                     colPos != m_aColumnWidths.end();
    2152             :                     ++colPos
    2153             :                  )
    2154             :             {
    2155           0 :                 colPos->move( nPixelDelta );
    2156             :             }
    2157             : 
    2158             :             // scroll the window content (if supported and possible), or invalidate the complete window
    2159           0 :             if  (   m_pDataWindow->GetBackground().IsScrollable()
    2160           0 :                 &&  std::abs( nPixelDelta ) < aDataArea.GetWidth()
    2161             :                 )
    2162             :             {
    2163           0 :                 m_pDataWindow->Scroll( nPixelDelta, 0, aDataArea, ScrollFlags::Clip | ScrollFlags::Update );
    2164             :             }
    2165             :             else
    2166             :             {
    2167           0 :                 m_pDataWindow->Invalidate( InvalidateFlags::Update );
    2168           0 :                 m_pDataWindow->GetParent()->Invalidate( InvalidateFlags::Transparent );
    2169             :             }
    2170             : 
    2171             :             // update the position at the horizontal scrollbar
    2172           0 :             if ( m_pHScroll != nullptr )
    2173           0 :                 m_pHScroll->SetThumbPos( m_nLeftColumn );
    2174             :         }
    2175             : 
    2176             :         // The scroll bar availaility might change when we scrolled. This is because we do not hide
    2177             :         // the scrollbar when it is, in theory, unnecessary, but currently at a position > 0. In this case, it will
    2178             :         // be auto-hidden when it's scrolled back to pos 0.
    2179           0 :         if ( m_nLeftColumn == 0 )
    2180           0 :             m_rAntiImpl.PostUserEvent( LINK( this, TableControl_Impl, OnUpdateScrollbars ) );
    2181             : 
    2182           0 :         return (TableSize)( m_nLeftColumn - nOldLeftColumn );
    2183             :     }
    2184             : 
    2185             : 
    2186           0 :     TableSize TableControl_Impl::impl_scrollColumns( TableSize const i_columnDelta )
    2187             :     {
    2188           0 :         return impl_ni_ScrollColumns( i_columnDelta );
    2189             :     }
    2190             : 
    2191             : 
    2192           1 :     SelectionEngine* TableControl_Impl::getSelEngine()
    2193             :     {
    2194           1 :         return m_pSelEngine;
    2195             :     }
    2196             : 
    2197           5 :     bool TableControl_Impl::isRowSelected( RowPos i_row ) const
    2198             :     {
    2199           5 :         return ::std::find( m_aSelectedRows.begin(), m_aSelectedRows.end(), i_row ) != m_aSelectedRows.end();
    2200             :     }
    2201             : 
    2202             : 
    2203           0 :     RowPos TableControl_Impl::getSelectedRowIndex( size_t const i_selectionIndex ) const
    2204             :     {
    2205           0 :         if ( i_selectionIndex < m_aSelectedRows.size() )
    2206           0 :             return m_aSelectedRows[ i_selectionIndex ];
    2207           0 :         return ROW_INVALID;
    2208             :     }
    2209             : 
    2210             : 
    2211           0 :     int TableControl_Impl::getRowSelectedNumber(const ::std::vector<RowPos>& selectedRows, RowPos current)
    2212             :     {
    2213           0 :         std::vector<RowPos>::const_iterator it = ::std::find(selectedRows.begin(),selectedRows.end(),current);
    2214           0 :         if ( it != selectedRows.end() )
    2215             :         {
    2216           0 :             return it - selectedRows.begin();
    2217             :         }
    2218           0 :         return -1;
    2219             :     }
    2220             : 
    2221             : 
    2222           0 :     ColPos TableControl_Impl::impl_getColumnForOrdinate( long const i_ordinate ) const
    2223             :     {
    2224           0 :         if ( ( m_aColumnWidths.empty() ) || ( i_ordinate < 0 ) )
    2225           0 :             return COL_INVALID;
    2226             : 
    2227           0 :         if ( i_ordinate < m_nRowHeaderWidthPixel )
    2228           0 :             return COL_ROW_HEADERS;
    2229             : 
    2230             :         ColumnPositions::const_iterator lowerBound = ::std::lower_bound(
    2231             :             m_aColumnWidths.begin(),
    2232             :             m_aColumnWidths.end(),
    2233             :             MutableColumnMetrics(i_ordinate+1, i_ordinate+1),
    2234             :             ColumnInfoPositionLess()
    2235           0 :         );
    2236           0 :         if ( lowerBound == m_aColumnWidths.end() )
    2237             :         {
    2238             :             // point is *behind* the start of the last column ...
    2239           0 :             if ( i_ordinate < m_aColumnWidths.rbegin()->getEnd() )
    2240             :                 // ... but still before its end
    2241           0 :                 return m_nColumnCount - 1;
    2242           0 :             return COL_INVALID;
    2243             :         }
    2244           0 :         return lowerBound - m_aColumnWidths.begin();
    2245             :     }
    2246             : 
    2247             : 
    2248           0 :     RowPos TableControl_Impl::impl_getRowForAbscissa( long const i_abscissa ) const
    2249             :     {
    2250           0 :         if ( i_abscissa < 0 )
    2251           0 :             return ROW_INVALID;
    2252             : 
    2253           0 :         if ( i_abscissa < m_nColHeaderHeightPixel )
    2254           0 :             return ROW_COL_HEADERS;
    2255             : 
    2256           0 :         long const abscissa = i_abscissa - m_nColHeaderHeightPixel;
    2257           0 :         long const row = m_nTopRow + abscissa / m_nRowHeightPixel;
    2258           0 :         return row < m_pModel->getRowCount() ? row : ROW_INVALID;
    2259             :     }
    2260             : 
    2261             : 
    2262           1 :     bool TableControl_Impl::markRowAsDeselected( RowPos const i_rowIndex )
    2263             :     {
    2264           1 :         ::std::vector< RowPos >::iterator selPos = ::std::find( m_aSelectedRows.begin(), m_aSelectedRows.end(), i_rowIndex );
    2265           1 :         if ( selPos == m_aSelectedRows.end() )
    2266           1 :             return false;
    2267             : 
    2268           0 :         m_aSelectedRows.erase( selPos );
    2269           0 :         return true;
    2270             :     }
    2271             : 
    2272             : 
    2273           0 :     bool TableControl_Impl::markRowAsSelected( RowPos const i_rowIndex )
    2274             :     {
    2275           0 :         if ( isRowSelected( i_rowIndex ) )
    2276           0 :             return false;
    2277             : 
    2278           0 :         SelectionMode const eSelMode = getSelEngine()->GetSelectionMode();
    2279           0 :         switch ( eSelMode )
    2280             :         {
    2281             :         case SINGLE_SELECTION:
    2282           0 :             if ( !m_aSelectedRows.empty() )
    2283             :             {
    2284             :                 OSL_ENSURE( m_aSelectedRows.size() == 1, "TableControl::markRowAsSelected: SingleSelection with more than one selected element?" );
    2285           0 :                 m_aSelectedRows[0] = i_rowIndex;
    2286           0 :                 break;
    2287             :             }
    2288             :             // fall through
    2289             : 
    2290             :         case MULTIPLE_SELECTION:
    2291           0 :             m_aSelectedRows.push_back( i_rowIndex );
    2292           0 :             break;
    2293             : 
    2294             :         default:
    2295             :             OSL_ENSURE( false, "TableControl_Impl::markRowAsSelected: unsupported selection mode!" );
    2296           0 :             return false;
    2297             :         }
    2298             : 
    2299           0 :         return true;
    2300             :     }
    2301             : 
    2302             : 
    2303           0 :     bool TableControl_Impl::markAllRowsAsDeselected()
    2304             :     {
    2305           0 :         if ( m_aSelectedRows.empty() )
    2306           0 :             return false;
    2307             : 
    2308           0 :         m_aSelectedRows.clear();
    2309           0 :         return true;
    2310             :     }
    2311             : 
    2312             : 
    2313           0 :     bool TableControl_Impl::markAllRowsAsSelected()
    2314             :     {
    2315           0 :         SelectionMode const eSelMode = getSelEngine()->GetSelectionMode();
    2316           0 :         ENSURE_OR_RETURN_FALSE( eSelMode == MULTIPLE_SELECTION, "TableControl_Impl::markAllRowsAsSelected: unsupported selection mode!" );
    2317             : 
    2318           0 :         if ( m_aSelectedRows.size() == size_t( m_pModel->getRowCount() ) )
    2319             :         {
    2320             :         #if OSL_DEBUG_LEVEL > 0
    2321             :             for ( TableSize row = 0; row < m_pModel->getRowCount(); ++row )
    2322             :             {
    2323             :                 OSL_ENSURE( isRowSelected( row ), "TableControl_Impl::markAllRowsAsSelected: inconsistency in the selected rows!" );
    2324             :             }
    2325             :         #endif
    2326             :             // already all rows marked as selected
    2327           0 :             return false;
    2328             :         }
    2329             : 
    2330           0 :         m_aSelectedRows.clear();
    2331           0 :         for ( RowPos i=0; i < m_pModel->getRowCount(); ++i )
    2332           0 :             m_aSelectedRows.push_back(i);
    2333             : 
    2334           0 :         return true;
    2335             :     }
    2336             : 
    2337             : 
    2338           0 :     void TableControl_Impl::commitAccessibleEvent( sal_Int16 const i_eventID, const Any& i_newValue, const Any& i_oldValue )
    2339             :     {
    2340           0 :         impl_commitAccessibleEvent( i_eventID, i_newValue, i_oldValue );
    2341           0 :     }
    2342             : 
    2343             : 
    2344           0 :     void TableControl_Impl::commitCellEvent( sal_Int16 const i_eventID, const Any& i_newValue, const Any& i_oldValue )
    2345             :     {
    2346           0 :         if ( impl_isAccessibleAlive() )
    2347           0 :              m_pAccessibleTable->commitCellEvent( i_eventID, i_newValue, i_oldValue );
    2348           0 :     }
    2349             : 
    2350             : 
    2351           0 :     void TableControl_Impl::commitTableEvent( sal_Int16 const i_eventID, const Any& i_newValue, const Any& i_oldValue )
    2352             :     {
    2353           0 :         if ( impl_isAccessibleAlive() )
    2354           0 :              m_pAccessibleTable->commitTableEvent( i_eventID, i_newValue, i_oldValue );
    2355           0 :     }
    2356             : 
    2357             : 
    2358           0 :     Rectangle TableControl_Impl::calcHeaderRect(bool bColHeader)
    2359             :     {
    2360           0 :         Rectangle const aRectTableWithHeaders( impl_getAllVisibleCellsArea() );
    2361           0 :         Size const aSizeTableWithHeaders( aRectTableWithHeaders.GetSize() );
    2362           0 :         if ( bColHeader )
    2363           0 :             return Rectangle( aRectTableWithHeaders.TopLeft(), Size( aSizeTableWithHeaders.Width(), m_nColHeaderHeightPixel ) );
    2364             :         else
    2365           0 :             return Rectangle( aRectTableWithHeaders.TopLeft(), Size( m_nRowHeaderWidthPixel, aSizeTableWithHeaders.Height() ) );
    2366             :     }
    2367             : 
    2368             : 
    2369           0 :     Rectangle TableControl_Impl::calcHeaderCellRect( bool bColHeader, sal_Int32 nPos )
    2370             :     {
    2371           0 :         Rectangle const aHeaderRect = calcHeaderRect( bColHeader );
    2372             :         TableCellGeometry const aGeometry(
    2373             :             *this, aHeaderRect,
    2374             :             bColHeader ? nPos : COL_ROW_HEADERS,
    2375             :             bColHeader ? ROW_COL_HEADERS : nPos
    2376           0 :         );
    2377           0 :         return aGeometry.getRect();
    2378             :     }
    2379             : 
    2380             : 
    2381           0 :     Rectangle TableControl_Impl::calcTableRect()
    2382             :     {
    2383           0 :         return impl_getAllVisibleDataCellArea();
    2384             :     }
    2385             : 
    2386             : 
    2387           0 :     Rectangle TableControl_Impl::calcCellRect( sal_Int32 nRow, sal_Int32 nCol )
    2388             :     {
    2389           0 :         Rectangle aCellRect;
    2390           0 :         impl_getCellRect( nRow, nCol, aCellRect );
    2391           0 :         return aCellRect;
    2392             :     }
    2393             : 
    2394             : 
    2395           0 :     IMPL_LINK_NOARG( TableControl_Impl, OnUpdateScrollbars )
    2396             :     {
    2397             :         // TODO: can't we simply use lcl_updateScrollbar here, so the scrollbars ranges are updated, instead of
    2398             :         // doing a complete re-layout?
    2399           0 :         impl_ni_relayout();
    2400           0 :         return 1L;
    2401             :     }
    2402             : 
    2403             : 
    2404           0 :     IMPL_LINK( TableControl_Impl, OnScroll, ScrollBar*, _pScrollbar )
    2405             :     {
    2406             :         DBG_ASSERT( ( _pScrollbar == m_pVScroll ) || ( _pScrollbar == m_pHScroll ),
    2407             :             "TableControl_Impl::OnScroll: where did this come from?" );
    2408             : 
    2409           0 :         if ( _pScrollbar == m_pVScroll )
    2410           0 :             impl_ni_ScrollRows( _pScrollbar->GetDelta() );
    2411             :         else
    2412           0 :             impl_ni_ScrollColumns( _pScrollbar->GetDelta() );
    2413             : 
    2414           0 :         return 0L;
    2415             :     }
    2416             : 
    2417             : 
    2418           0 :     Reference< XAccessible > TableControl_Impl::getAccessible( vcl::Window& i_parentWindow )
    2419             :     {
    2420             :         DBG_TESTSOLARMUTEX();
    2421           0 :         if ( m_pAccessibleTable == NULL )
    2422             :         {
    2423           0 :             Reference< XAccessible > const xAccParent = i_parentWindow.GetAccessible();
    2424           0 :             if ( xAccParent.is() )
    2425             :             {
    2426           0 :                 m_pAccessibleTable = m_aFactoryAccess.getFactory().createAccessibleTableControl(
    2427             :                     xAccParent, m_rAntiImpl
    2428           0 :                 );
    2429           0 :             }
    2430             :         }
    2431             : 
    2432           0 :         Reference< XAccessible > xAccessible;
    2433           0 :         if ( m_pAccessibleTable )
    2434           0 :             xAccessible = m_pAccessibleTable->getMyself();
    2435           0 :         return xAccessible;
    2436             :     }
    2437             : 
    2438             : 
    2439           1 :     void TableControl_Impl::disposeAccessible()
    2440             :     {
    2441           1 :         if ( m_pAccessibleTable )
    2442           0 :             m_pAccessibleTable->DisposeAccessImpl();
    2443           1 :         m_pAccessibleTable = NULL;
    2444           1 :     }
    2445             : 
    2446             : 
    2447           3 :     bool TableControl_Impl::impl_isAccessibleAlive() const
    2448             :     {
    2449           3 :         return ( NULL != m_pAccessibleTable ) && m_pAccessibleTable->isAlive();
    2450             :     }
    2451             : 
    2452             : 
    2453           0 :     void TableControl_Impl::impl_commitAccessibleEvent( sal_Int16 const i_eventID, Any const & i_newValue, Any const & i_oldValue )
    2454             :     {
    2455           0 :         if ( impl_isAccessibleAlive() )
    2456           0 :              m_pAccessibleTable->commitEvent( i_eventID, i_newValue, i_oldValue );
    2457           0 :     }
    2458             : 
    2459             : 
    2460             :     //= TableFunctionSet
    2461             : 
    2462             : 
    2463           1 :     TableFunctionSet::TableFunctionSet(TableControl_Impl* _pTableControl)
    2464             :         :m_pTableControl( _pTableControl)
    2465           1 :         ,m_nCurrentRow( ROW_INVALID )
    2466             :     {
    2467           1 :     }
    2468             : 
    2469           2 :     TableFunctionSet::~TableFunctionSet()
    2470             :     {
    2471           2 :     }
    2472             : 
    2473           0 :     void TableFunctionSet::BeginDrag()
    2474             :     {
    2475           0 :     }
    2476             : 
    2477           0 :     void TableFunctionSet::CreateAnchor()
    2478             :     {
    2479           0 :         m_pTableControl->setAnchor( m_pTableControl->getCurRow() );
    2480           0 :     }
    2481             : 
    2482             : 
    2483           0 :     void TableFunctionSet::DestroyAnchor()
    2484             :     {
    2485           0 :         m_pTableControl->setAnchor( ROW_INVALID );
    2486           0 :     }
    2487             : 
    2488             : 
    2489           0 :     bool TableFunctionSet::SetCursorAtPoint(const Point& rPoint, bool bDontSelectAtCursor)
    2490             :     {
    2491           0 :         bool bHandled = false;
    2492             :         // newRow is the row which includes the point, getCurRow() is the last selected row, before the mouse click
    2493           0 :         RowPos newRow = m_pTableControl->getRowAtPoint( rPoint );
    2494           0 :         if ( newRow == ROW_COL_HEADERS )
    2495           0 :             newRow = m_pTableControl->getTopRow();
    2496             : 
    2497           0 :         ColPos newCol = m_pTableControl->getColAtPoint( rPoint );
    2498           0 :         if ( newCol == COL_ROW_HEADERS )
    2499           0 :             newCol = m_pTableControl->getLeftColumn();
    2500             : 
    2501           0 :         if ( ( newRow == ROW_INVALID ) || ( newCol == COL_INVALID ) )
    2502           0 :             return false;
    2503             : 
    2504           0 :         if ( bDontSelectAtCursor )
    2505             :         {
    2506           0 :             if ( m_pTableControl->getSelectedRowCount() > 1 )
    2507           0 :                 m_pTableControl->getSelEngine()->AddAlways(true);
    2508           0 :             bHandled = true;
    2509             :         }
    2510           0 :         else if ( m_pTableControl->getAnchor() == m_pTableControl->getCurRow() )
    2511             :         {
    2512             :             //selecting region,
    2513           0 :             int diff = m_pTableControl->getCurRow() - newRow;
    2514             :             //selected region lies above the last selection
    2515           0 :             if( diff >= 0)
    2516             :             {
    2517             :                 //put selected rows in vector
    2518           0 :                 while ( m_pTableControl->getAnchor() >= newRow )
    2519             :                 {
    2520           0 :                     m_pTableControl->markRowAsSelected( m_pTableControl->getAnchor() );
    2521           0 :                     m_pTableControl->setAnchor( m_pTableControl->getAnchor() - 1 );
    2522           0 :                     diff--;
    2523             :                 }
    2524           0 :                 m_pTableControl->setAnchor( m_pTableControl->getAnchor() + 1 );
    2525             :             }
    2526             :             //selected region lies beneath the last selected row
    2527             :             else
    2528             :             {
    2529           0 :                 while ( m_pTableControl->getAnchor() <= newRow )
    2530             :                 {
    2531           0 :                     m_pTableControl->markRowAsSelected( m_pTableControl->getAnchor() );
    2532           0 :                     m_pTableControl->setAnchor( m_pTableControl->getAnchor() + 1 );
    2533           0 :                     diff++;
    2534             :                 }
    2535           0 :                 m_pTableControl->setAnchor( m_pTableControl->getAnchor() - 1 );
    2536             :             }
    2537           0 :             m_pTableControl->invalidateSelectedRegion( m_pTableControl->getCurRow(), newRow );
    2538           0 :             bHandled = true;
    2539             :         }
    2540             :         //no region selected
    2541             :         else
    2542             :         {
    2543           0 :             if ( !m_pTableControl->hasRowSelection() )
    2544           0 :                 m_pTableControl->markRowAsSelected( newRow );
    2545             :             else
    2546             :             {
    2547           0 :                 if ( m_pTableControl->getSelEngine()->GetSelectionMode() == SINGLE_SELECTION )
    2548             :                 {
    2549           0 :                     DeselectAll();
    2550           0 :                     m_pTableControl->markRowAsSelected( newRow );
    2551             :                 }
    2552             :                 else
    2553             :                 {
    2554           0 :                     m_pTableControl->markRowAsSelected( newRow );
    2555             :                 }
    2556             :             }
    2557           0 :             if ( m_pTableControl->getSelectedRowCount() > 1 && m_pTableControl->getSelEngine()->GetSelectionMode() != SINGLE_SELECTION )
    2558           0 :                 m_pTableControl->getSelEngine()->AddAlways(true);
    2559             : 
    2560           0 :             m_pTableControl->invalidateRow( newRow );
    2561           0 :             bHandled = true;
    2562             :         }
    2563           0 :         m_pTableControl->goTo( newCol, newRow );
    2564           0 :         return bHandled;
    2565             :     }
    2566             : 
    2567           0 :     bool TableFunctionSet::IsSelectionAtPoint( const Point& rPoint )
    2568             :     {
    2569           0 :         m_pTableControl->getSelEngine()->AddAlways(false);
    2570           0 :         if ( !m_pTableControl->hasRowSelection() )
    2571           0 :             return false;
    2572             :         else
    2573             :         {
    2574           0 :             RowPos curRow = m_pTableControl->getRowAtPoint( rPoint );
    2575           0 :             m_pTableControl->setAnchor( ROW_INVALID );
    2576           0 :             bool selected = m_pTableControl->isRowSelected( curRow );
    2577           0 :             m_nCurrentRow = curRow;
    2578           0 :             return selected;
    2579             :         }
    2580             :     }
    2581             : 
    2582           0 :     void TableFunctionSet::DeselectAtPoint( const Point& rPoint )
    2583             :     {
    2584             :         (void)rPoint;
    2585           0 :         m_pTableControl->invalidateRow( m_nCurrentRow );
    2586           0 :         m_pTableControl->markRowAsDeselected( m_nCurrentRow );
    2587           0 :     }
    2588             : 
    2589             : 
    2590           0 :     void TableFunctionSet::DeselectAll()
    2591             :     {
    2592           0 :         if ( m_pTableControl->hasRowSelection() )
    2593             :         {
    2594           0 :             for ( size_t i=0; i<m_pTableControl->getSelectedRowCount(); ++i )
    2595             :             {
    2596           0 :                 RowPos const rowIndex = m_pTableControl->getSelectedRowIndex(i);
    2597           0 :                 m_pTableControl->invalidateRow( rowIndex );
    2598             :             }
    2599             : 
    2600           0 :             m_pTableControl->markAllRowsAsDeselected();
    2601             :         }
    2602           0 :     }
    2603             : 
    2604             : 
    2605         798 : } } // namespace svt::table
    2606             : 
    2607             : 
    2608             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11