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