LCOV - code coverage report
Current view: top level - svtools/source/table - tablecontrol_impl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 425 1189 35.7 %
Date: 2014-11-03 Functions: 60 138 43.5 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10