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