1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 28*cdf0e10cSrcweir #include "precompiled_svtools.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include "svtxgridcontrol.hxx" 31*cdf0e10cSrcweir #include <com/sun/star/view/SelectionType.hpp> 32*cdf0e10cSrcweir #include "svtools/table/tablecontrolinterface.hxx" 33*cdf0e10cSrcweir #include "svtools/table/gridtablerenderer.hxx" 34*cdf0e10cSrcweir #include "svtools/table/tablecontrol.hxx" 35*cdf0e10cSrcweir #include "unocontroltablemodel.hxx" 36*cdf0e10cSrcweir #include <comphelper/sequence.hxx> 37*cdf0e10cSrcweir #include <rtl/ref.hxx> 38*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 39*cdf0e10cSrcweir #include <toolkit/helper/property.hxx> 40*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 41*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 42*cdf0e10cSrcweir #include <com/sun/star/awt/grid/XGridColumn.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/awt/XControl.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/awt/grid/GridInvalidDataException.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/awt/grid/GridInvalidModelException.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/util/Color.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/awt/FontDescriptor.hpp> 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir /** === begin UNO using === **/ 52*cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 53*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 54*cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 55*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 56*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 57*cdf0e10cSrcweir using ::com::sun::star::uno::Any; 58*cdf0e10cSrcweir using ::com::sun::star::uno::makeAny; 59*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 60*cdf0e10cSrcweir using ::com::sun::star::awt::grid::XGridSelectionListener; 61*cdf0e10cSrcweir using ::com::sun::star::style::VerticalAlignment; 62*cdf0e10cSrcweir using ::com::sun::star::style::VerticalAlignment_TOP; 63*cdf0e10cSrcweir using ::com::sun::star::view::SelectionType; 64*cdf0e10cSrcweir using ::com::sun::star::view::SelectionType_NONE; 65*cdf0e10cSrcweir using ::com::sun::star::view::SelectionType_RANGE; 66*cdf0e10cSrcweir using ::com::sun::star::view::SelectionType_SINGLE; 67*cdf0e10cSrcweir using ::com::sun::star::view::SelectionType_MULTI; 68*cdf0e10cSrcweir using ::com::sun::star::awt::grid::XGridDataModel; 69*cdf0e10cSrcweir using ::com::sun::star::awt::grid::GridInvalidDataException; 70*cdf0e10cSrcweir using ::com::sun::star::lang::EventObject; 71*cdf0e10cSrcweir using ::com::sun::star::lang::IndexOutOfBoundsException; 72*cdf0e10cSrcweir using ::com::sun::star::awt::grid::XGridColumnModel; 73*cdf0e10cSrcweir using ::com::sun::star::awt::grid::GridSelectionEvent; 74*cdf0e10cSrcweir using ::com::sun::star::awt::grid::XGridColumn; 75*cdf0e10cSrcweir using ::com::sun::star::container::ContainerEvent; 76*cdf0e10cSrcweir using ::com::sun::star::awt::grid::GridDataEvent; 77*cdf0e10cSrcweir using ::com::sun::star::awt::grid::GridInvalidModelException; 78*cdf0e10cSrcweir using ::com::sun::star::util::VetoException; 79*cdf0e10cSrcweir /** === end UNO using === **/ 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir namespace AccessibleEventId = ::com::sun::star::accessibility::AccessibleEventId; 82*cdf0e10cSrcweir namespace AccessibleStateType = ::com::sun::star::accessibility::AccessibleStateType; 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir using namespace ::svt::table; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir typedef ::com::sun::star::util::Color UnoColor; 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------- 89*cdf0e10cSrcweir SVTXGridControl::SVTXGridControl() 90*cdf0e10cSrcweir :m_pTableModel( new UnoControlTableModel() ) 91*cdf0e10cSrcweir ,m_bTableModelInitCompleted( false ) 92*cdf0e10cSrcweir ,m_aSelectionListeners( *this ) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------- 97*cdf0e10cSrcweir SVTXGridControl::~SVTXGridControl() 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------- 102*cdf0e10cSrcweir void SVTXGridControl::SetWindow( Window* pWindow ) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir SVTXGridControl_Base::SetWindow( pWindow ); 105*cdf0e10cSrcweir impl_checkTableModelInit(); 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------- 109*cdf0e10cSrcweir void SVTXGridControl::impl_checkColumnIndex_throw( ::svt::table::TableControl const & i_table, sal_Int32 const i_columnIndex ) const 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir if ( ( i_columnIndex < 0 ) || ( i_columnIndex >= i_table.GetColumnCount() ) ) 112*cdf0e10cSrcweir throw IndexOutOfBoundsException( ::rtl::OUString(), *const_cast< SVTXGridControl* >( this ) ); 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------- 116*cdf0e10cSrcweir void SVTXGridControl::impl_checkRowIndex_throw( ::svt::table::TableControl const & i_table, sal_Int32 const i_rowIndex ) const 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir if ( ( i_rowIndex < 0 ) || ( i_rowIndex >= i_table.GetRowCount() ) ) 119*cdf0e10cSrcweir throw IndexOutOfBoundsException( ::rtl::OUString(), *const_cast< SVTXGridControl* >( this ) ); 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------- 123*cdf0e10cSrcweir sal_Int32 SAL_CALL SVTXGridControl::getRowAtPoint(::sal_Int32 x, ::sal_Int32 y) throw (RuntimeException) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 128*cdf0e10cSrcweir ENSURE_OR_RETURN( pTable != NULL, "SVTXGridControl::getRowAtPoint: no control (anymore)!", -1 ); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir TableCell const tableCell = pTable->getTableControlInterface().hitTest( Point( x, y ) ); 131*cdf0e10cSrcweir return ( tableCell.nRow >= 0 ) ? tableCell.nRow : -1; 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------- 135*cdf0e10cSrcweir sal_Int32 SAL_CALL SVTXGridControl::getColumnAtPoint(::sal_Int32 x, ::sal_Int32 y) throw (RuntimeException) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 140*cdf0e10cSrcweir ENSURE_OR_RETURN( pTable != NULL, "SVTXGridControl::getColumnAtPoint: no control (anymore)!", -1 ); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir TableCell const tableCell = pTable->getTableControlInterface().hitTest( Point( x, y ) ); 143*cdf0e10cSrcweir return ( tableCell.nColumn >= 0 ) ? tableCell.nColumn : -1; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------- 147*cdf0e10cSrcweir sal_Int32 SAL_CALL SVTXGridControl::getCurrentColumn( ) throw (RuntimeException) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 152*cdf0e10cSrcweir ENSURE_OR_RETURN( pTable != NULL, "SVTXGridControl::getCurrentColumn: no control (anymore)!", -1 ); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir sal_Int32 const nColumn = pTable->GetCurrentColumn(); 155*cdf0e10cSrcweir return ( nColumn >= 0 ) ? nColumn : -1; 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------- 159*cdf0e10cSrcweir sal_Int32 SAL_CALL SVTXGridControl::getCurrentRow( ) throw (RuntimeException) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 164*cdf0e10cSrcweir ENSURE_OR_RETURN( pTable != NULL, "SVTXGridControl::getCurrentRow: no control (anymore)!", -1 ); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir sal_Int32 const nRow = pTable->GetCurrentRow(); 167*cdf0e10cSrcweir return ( nRow >= 0 ) ? nRow : -1; 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 171*cdf0e10cSrcweir void SAL_CALL SVTXGridControl::goToCell( ::sal_Int32 i_columnIndex, ::sal_Int32 i_rowIndex ) throw (RuntimeException, IndexOutOfBoundsException, VetoException) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 176*cdf0e10cSrcweir ENSURE_OR_RETURN_VOID( pTable != NULL, "SVTXGridControl::getCurrentRow: no control (anymore)!" ); 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir impl_checkColumnIndex_throw( *pTable, i_columnIndex ); 179*cdf0e10cSrcweir impl_checkRowIndex_throw( *pTable, i_rowIndex ); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir pTable->GoTo( i_columnIndex, i_rowIndex ); 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------- 185*cdf0e10cSrcweir void SAL_CALL SVTXGridControl::addSelectionListener(const Reference< XGridSelectionListener > & listener) throw (RuntimeException) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir m_aSelectionListeners.addInterface(listener); 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------- 191*cdf0e10cSrcweir void SAL_CALL SVTXGridControl::removeSelectionListener(const Reference< XGridSelectionListener > & listener) throw (RuntimeException) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir m_aSelectionListeners.removeInterface(listener); 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------- 197*cdf0e10cSrcweir void SVTXGridControl::setProperty( const ::rtl::OUString& PropertyName, const Any& aValue) throw(RuntimeException) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 202*cdf0e10cSrcweir ENSURE_OR_RETURN_VOID( pTable != NULL, "SVTXGridControl::setProperty: no control (anymore)!" ); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir switch( GetPropertyId( PropertyName ) ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir case BASEPROPERTY_ROW_HEADER_WIDTH: 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir sal_Int32 rowHeaderWidth( -1 ); 209*cdf0e10cSrcweir aValue >>= rowHeaderWidth; 210*cdf0e10cSrcweir ENSURE_OR_BREAK( rowHeaderWidth > 0, "SVTXGridControl::setProperty: illegal row header width!" ); 211*cdf0e10cSrcweir m_pTableModel->setRowHeaderWidth( rowHeaderWidth ); 212*cdf0e10cSrcweir // TODO: the model should broadcast this change itself, and the table should invalidate itself as needed 213*cdf0e10cSrcweir pTable->Invalidate(); 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir break; 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir case BASEPROPERTY_COLUMN_HEADER_HEIGHT: 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir sal_Int32 columnHeaderHeight = 0; 220*cdf0e10cSrcweir if ( !aValue.hasValue() ) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir columnHeaderHeight = pTable->PixelToLogic( Size( 0, pTable->GetTextHeight() + 3 ), MAP_APPFONT ).Height(); 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir else 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir aValue >>= columnHeaderHeight; 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir ENSURE_OR_BREAK( columnHeaderHeight > 0, "SVTXGridControl::setProperty: illegal column header height!" ); 229*cdf0e10cSrcweir m_pTableModel->setColumnHeaderHeight( columnHeaderHeight ); 230*cdf0e10cSrcweir // TODO: the model should broadcast this change itself, and the table should invalidate itself as needed 231*cdf0e10cSrcweir pTable->Invalidate(); 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir break; 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir case BASEPROPERTY_USE_GRID_LINES: 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir GridTableRenderer* pGridRenderer = dynamic_cast< GridTableRenderer* >( 238*cdf0e10cSrcweir m_pTableModel->getRenderer().get() ); 239*cdf0e10cSrcweir ENSURE_OR_BREAK( pGridRenderer != NULL, "SVTXGridControl::setProperty(UseGridLines): invalid renderer!" ); 240*cdf0e10cSrcweir sal_Bool bUseGridLines = sal_False; 241*cdf0e10cSrcweir OSL_VERIFY( aValue >>= bUseGridLines ); 242*cdf0e10cSrcweir pGridRenderer->useGridLines( bUseGridLines ); 243*cdf0e10cSrcweir pTable->Invalidate(); 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir break; 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir case BASEPROPERTY_ROW_HEIGHT: 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir sal_Int32 rowHeight = 0; 250*cdf0e10cSrcweir if ( !aValue.hasValue() ) 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir rowHeight = pTable->PixelToLogic( Size( 0, pTable->GetTextHeight() + 3 ), MAP_APPFONT ).Height(); 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir else 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir aValue >>= rowHeight; 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir m_pTableModel->setRowHeight( rowHeight ); 259*cdf0e10cSrcweir ENSURE_OR_BREAK( rowHeight > 0, "SVTXGridControl::setProperty: illegal row height!" ); 260*cdf0e10cSrcweir // TODO: the model should broadcast this change itself, and the table should invalidate itself as needed 261*cdf0e10cSrcweir pTable->Invalidate(); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir break; 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir case BASEPROPERTY_BACKGROUNDCOLOR: 266*cdf0e10cSrcweir { 267*cdf0e10cSrcweir // let the base class handle this for the TableControl 268*cdf0e10cSrcweir VCLXWindow::setProperty( PropertyName, aValue ); 269*cdf0e10cSrcweir // and forward to the grid control's data window 270*cdf0e10cSrcweir if ( pTable->IsBackground() ) 271*cdf0e10cSrcweir pTable->getDataWindow().SetBackground( pTable->GetBackground() ); 272*cdf0e10cSrcweir else 273*cdf0e10cSrcweir pTable->getDataWindow().SetBackground(); 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir break; 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir case BASEPROPERTY_GRID_SELECTIONMODE: 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir SelectionType eSelectionType; 280*cdf0e10cSrcweir if( aValue >>= eSelectionType ) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir SelectionMode eSelMode; 283*cdf0e10cSrcweir switch( eSelectionType ) 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir case SelectionType_SINGLE: eSelMode = SINGLE_SELECTION; break; 286*cdf0e10cSrcweir case SelectionType_RANGE: eSelMode = RANGE_SELECTION; break; 287*cdf0e10cSrcweir case SelectionType_MULTI: eSelMode = MULTIPLE_SELECTION; break; 288*cdf0e10cSrcweir default: eSelMode = NO_SELECTION; break; 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir if( pTable->getSelEngine()->GetSelectionMode() != eSelMode ) 291*cdf0e10cSrcweir pTable->getSelEngine()->SetSelectionMode( eSelMode ); 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir break; 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir case BASEPROPERTY_HSCROLL: 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir sal_Bool bHScroll = true; 298*cdf0e10cSrcweir if( aValue >>= bHScroll ) 299*cdf0e10cSrcweir m_pTableModel->setHorizontalScrollbarVisibility( bHScroll ? ScrollbarShowAlways : ScrollbarShowSmart ); 300*cdf0e10cSrcweir break; 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir case BASEPROPERTY_VSCROLL: 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir sal_Bool bVScroll = true; 306*cdf0e10cSrcweir if( aValue >>= bVScroll ) 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir m_pTableModel->setVerticalScrollbarVisibility( bVScroll ? ScrollbarShowAlways : ScrollbarShowSmart ); 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir break; 311*cdf0e10cSrcweir } 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir case BASEPROPERTY_GRID_SHOWROWHEADER: 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir sal_Bool rowHeader = true; 316*cdf0e10cSrcweir if( aValue >>= rowHeader ) 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir m_pTableModel->setRowHeaders(rowHeader); 319*cdf0e10cSrcweir } 320*cdf0e10cSrcweir break; 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir case BASEPROPERTY_GRID_ROW_BACKGROUND_COLORS: 324*cdf0e10cSrcweir m_pTableModel->setRowBackgroundColors( aValue ); 325*cdf0e10cSrcweir pTable->Invalidate(); 326*cdf0e10cSrcweir break; 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir case BASEPROPERTY_GRID_LINE_COLOR: 329*cdf0e10cSrcweir m_pTableModel->setLineColor( aValue ); 330*cdf0e10cSrcweir pTable->Invalidate(); 331*cdf0e10cSrcweir break; 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir case BASEPROPERTY_GRID_HEADER_BACKGROUND: 334*cdf0e10cSrcweir m_pTableModel->setHeaderBackgroundColor( aValue ); 335*cdf0e10cSrcweir pTable->Invalidate(); 336*cdf0e10cSrcweir break; 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir case BASEPROPERTY_GRID_HEADER_TEXT_COLOR: 339*cdf0e10cSrcweir m_pTableModel->setHeaderTextColor( aValue ); 340*cdf0e10cSrcweir pTable->Invalidate(); 341*cdf0e10cSrcweir break; 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir case BASEPROPERTY_ACTIVE_SEL_BACKGROUND_COLOR: 344*cdf0e10cSrcweir m_pTableModel->setActiveSelectionBackColor( aValue ); 345*cdf0e10cSrcweir pTable->Invalidate(); 346*cdf0e10cSrcweir break; 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir case BASEPROPERTY_INACTIVE_SEL_BACKGROUND_COLOR: 349*cdf0e10cSrcweir m_pTableModel->setInactiveSelectionBackColor( aValue ); 350*cdf0e10cSrcweir pTable->Invalidate(); 351*cdf0e10cSrcweir break; 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir case BASEPROPERTY_ACTIVE_SEL_TEXT_COLOR: 354*cdf0e10cSrcweir m_pTableModel->setActiveSelectionTextColor( aValue ); 355*cdf0e10cSrcweir pTable->Invalidate(); 356*cdf0e10cSrcweir break; 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir case BASEPROPERTY_INACTIVE_SEL_TEXT_COLOR: 359*cdf0e10cSrcweir m_pTableModel->setInactiveSelectionTextColor( aValue ); 360*cdf0e10cSrcweir pTable->Invalidate(); 361*cdf0e10cSrcweir break; 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir case BASEPROPERTY_TEXTCOLOR: 365*cdf0e10cSrcweir m_pTableModel->setTextColor( aValue ); 366*cdf0e10cSrcweir pTable->Invalidate(); 367*cdf0e10cSrcweir break; 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir case BASEPROPERTY_TEXTLINECOLOR: 370*cdf0e10cSrcweir m_pTableModel->setTextLineColor( aValue ); 371*cdf0e10cSrcweir pTable->Invalidate(); 372*cdf0e10cSrcweir break; 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir case BASEPROPERTY_VERTICALALIGN: 375*cdf0e10cSrcweir { 376*cdf0e10cSrcweir VerticalAlignment eAlign( VerticalAlignment_TOP ); 377*cdf0e10cSrcweir if ( aValue >>= eAlign ) 378*cdf0e10cSrcweir m_pTableModel->setVerticalAlign( eAlign ); 379*cdf0e10cSrcweir break; 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir case BASEPROPERTY_GRID_SHOWCOLUMNHEADER: 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir sal_Bool colHeader = true; 385*cdf0e10cSrcweir if( aValue >>= colHeader ) 386*cdf0e10cSrcweir { 387*cdf0e10cSrcweir m_pTableModel->setColumnHeaders(colHeader); 388*cdf0e10cSrcweir } 389*cdf0e10cSrcweir break; 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir case BASEPROPERTY_GRID_DATAMODEL: 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir Reference< XGridDataModel > const xDataModel( aValue, UNO_QUERY ); 394*cdf0e10cSrcweir if ( !xDataModel.is() ) 395*cdf0e10cSrcweir throw GridInvalidDataException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid data model." ) ), *this ); 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir m_pTableModel->setDataModel( xDataModel ); 398*cdf0e10cSrcweir impl_checkTableModelInit(); 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir break; 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir case BASEPROPERTY_GRID_COLUMNMODEL: 403*cdf0e10cSrcweir { 404*cdf0e10cSrcweir // obtain new col model 405*cdf0e10cSrcweir Reference< XGridColumnModel > const xColumnModel( aValue, UNO_QUERY ); 406*cdf0e10cSrcweir if ( !xColumnModel.is() ) 407*cdf0e10cSrcweir throw GridInvalidModelException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid column model." ) ), *this ); 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir // remove all old columns 410*cdf0e10cSrcweir m_pTableModel->removeAllColumns(); 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir // announce to the TableModel 413*cdf0e10cSrcweir m_pTableModel->setColumnModel( xColumnModel ); 414*cdf0e10cSrcweir impl_checkTableModelInit(); 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir // add new columns 417*cdf0e10cSrcweir impl_updateColumnsFromModel_nothrow(); 418*cdf0e10cSrcweir break; 419*cdf0e10cSrcweir } 420*cdf0e10cSrcweir default: 421*cdf0e10cSrcweir VCLXWindow::setProperty( PropertyName, aValue ); 422*cdf0e10cSrcweir break; 423*cdf0e10cSrcweir } 424*cdf0e10cSrcweir } 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir void SVTXGridControl::impl_checkTableModelInit() 428*cdf0e10cSrcweir { 429*cdf0e10cSrcweir if ( !m_bTableModelInitCompleted && m_pTableModel->hasColumnModel() && m_pTableModel->hasDataModel() ) 430*cdf0e10cSrcweir { 431*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 432*cdf0e10cSrcweir if ( pTable ) 433*cdf0e10cSrcweir { 434*cdf0e10cSrcweir pTable->SetModel( PTableModel( m_pTableModel ) ); 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir m_bTableModelInitCompleted = true; 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir // ensure default columns exist, if they have not previously been added 439*cdf0e10cSrcweir Reference< XGridDataModel > const xDataModel( m_pTableModel->getDataModel(), UNO_QUERY_THROW ); 440*cdf0e10cSrcweir Reference< XGridColumnModel > const xColumnModel( m_pTableModel->getColumnModel(), UNO_QUERY_THROW ); 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir sal_Int32 const nDataColumnCount = xDataModel->getColumnCount(); 443*cdf0e10cSrcweir if ( ( nDataColumnCount > 0 ) && ( xColumnModel->getColumnCount() == 0 ) ) 444*cdf0e10cSrcweir xColumnModel->setDefaultColumns( nDataColumnCount ); 445*cdf0e10cSrcweir // this will trigger notifications, which in turn will let us update our m_pTableModel 446*cdf0e10cSrcweir } 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir } 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir namespace 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir void lcl_convertColor( ::boost::optional< ::Color > const & i_color, Any & o_colorValue ) 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir if ( !i_color ) 455*cdf0e10cSrcweir o_colorValue.clear(); 456*cdf0e10cSrcweir else 457*cdf0e10cSrcweir o_colorValue <<= i_color->GetColor(); 458*cdf0e10cSrcweir } 459*cdf0e10cSrcweir } 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir Any SVTXGridControl::getProperty( const ::rtl::OUString& PropertyName ) throw(RuntimeException) 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 466*cdf0e10cSrcweir ENSURE_OR_RETURN( pTable != NULL, "SVTXGridControl::getProperty: no control (anymore)!", Any() ); 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir Any aPropertyValue; 469*cdf0e10cSrcweir 470*cdf0e10cSrcweir const sal_uInt16 nPropId = GetPropertyId( PropertyName ); 471*cdf0e10cSrcweir switch(nPropId) 472*cdf0e10cSrcweir { 473*cdf0e10cSrcweir case BASEPROPERTY_GRID_SELECTIONMODE: 474*cdf0e10cSrcweir { 475*cdf0e10cSrcweir SelectionType eSelectionType; 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir SelectionMode eSelMode = pTable->getSelEngine()->GetSelectionMode(); 478*cdf0e10cSrcweir switch( eSelMode ) 479*cdf0e10cSrcweir { 480*cdf0e10cSrcweir case SINGLE_SELECTION: eSelectionType = SelectionType_SINGLE; break; 481*cdf0e10cSrcweir case RANGE_SELECTION: eSelectionType = SelectionType_RANGE; break; 482*cdf0e10cSrcweir case MULTIPLE_SELECTION:eSelectionType = SelectionType_MULTI; break; 483*cdf0e10cSrcweir default: eSelectionType = SelectionType_NONE; break; 484*cdf0e10cSrcweir } 485*cdf0e10cSrcweir aPropertyValue <<= eSelectionType; 486*cdf0e10cSrcweir break; 487*cdf0e10cSrcweir } 488*cdf0e10cSrcweir 489*cdf0e10cSrcweir case BASEPROPERTY_GRID_SHOWROWHEADER: 490*cdf0e10cSrcweir aPropertyValue <<= sal_Bool( m_pTableModel->hasRowHeaders() ); 491*cdf0e10cSrcweir break; 492*cdf0e10cSrcweir 493*cdf0e10cSrcweir case BASEPROPERTY_GRID_SHOWCOLUMNHEADER: 494*cdf0e10cSrcweir aPropertyValue <<= sal_Bool( m_pTableModel->hasColumnHeaders() ); 495*cdf0e10cSrcweir break; 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir case BASEPROPERTY_GRID_DATAMODEL: 498*cdf0e10cSrcweir aPropertyValue <<= m_pTableModel->getDataModel(); 499*cdf0e10cSrcweir break; 500*cdf0e10cSrcweir 501*cdf0e10cSrcweir case BASEPROPERTY_GRID_COLUMNMODEL: 502*cdf0e10cSrcweir aPropertyValue <<= m_pTableModel->getColumnModel(); 503*cdf0e10cSrcweir break; 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir case BASEPROPERTY_HSCROLL: 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir sal_Bool const bHasScrollbar = ( m_pTableModel->getHorizontalScrollbarVisibility() != ScrollbarShowNever ); 508*cdf0e10cSrcweir aPropertyValue <<= bHasScrollbar; 509*cdf0e10cSrcweir break; 510*cdf0e10cSrcweir } 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir case BASEPROPERTY_VSCROLL: 513*cdf0e10cSrcweir { 514*cdf0e10cSrcweir sal_Bool const bHasScrollbar = ( m_pTableModel->getVerticalScrollbarVisibility() != ScrollbarShowNever ); 515*cdf0e10cSrcweir aPropertyValue <<= bHasScrollbar; 516*cdf0e10cSrcweir break; 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir case BASEPROPERTY_USE_GRID_LINES: 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir GridTableRenderer* pGridRenderer = dynamic_cast< GridTableRenderer* >( 522*cdf0e10cSrcweir m_pTableModel->getRenderer().get() ); 523*cdf0e10cSrcweir ENSURE_OR_BREAK( pGridRenderer != NULL, "SVTXGridControl::getProperty(UseGridLines): invalid renderer!" ); 524*cdf0e10cSrcweir aPropertyValue <<= pGridRenderer->useGridLines(); 525*cdf0e10cSrcweir } 526*cdf0e10cSrcweir break; 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir case BASEPROPERTY_GRID_ROW_BACKGROUND_COLORS: 529*cdf0e10cSrcweir { 530*cdf0e10cSrcweir ::boost::optional< ::std::vector< ::Color > > aColors( m_pTableModel->getRowBackgroundColors() ); 531*cdf0e10cSrcweir if ( !aColors ) 532*cdf0e10cSrcweir aPropertyValue.clear(); 533*cdf0e10cSrcweir else 534*cdf0e10cSrcweir { 535*cdf0e10cSrcweir Sequence< UnoColor > aAPIColors( aColors->size() ); 536*cdf0e10cSrcweir for ( size_t i=0; i<aColors->size(); ++i ) 537*cdf0e10cSrcweir { 538*cdf0e10cSrcweir aAPIColors[i] = aColors->at(i).GetColor(); 539*cdf0e10cSrcweir } 540*cdf0e10cSrcweir aPropertyValue <<= aAPIColors; 541*cdf0e10cSrcweir } 542*cdf0e10cSrcweir } 543*cdf0e10cSrcweir break; 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir case BASEPROPERTY_GRID_LINE_COLOR: 546*cdf0e10cSrcweir lcl_convertColor( m_pTableModel->getLineColor(), aPropertyValue ); 547*cdf0e10cSrcweir break; 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir case BASEPROPERTY_GRID_HEADER_BACKGROUND: 550*cdf0e10cSrcweir lcl_convertColor( m_pTableModel->getHeaderBackgroundColor(), aPropertyValue ); 551*cdf0e10cSrcweir break; 552*cdf0e10cSrcweir 553*cdf0e10cSrcweir case BASEPROPERTY_GRID_HEADER_TEXT_COLOR: 554*cdf0e10cSrcweir lcl_convertColor( m_pTableModel->getHeaderTextColor(), aPropertyValue ); 555*cdf0e10cSrcweir break; 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir case BASEPROPERTY_ACTIVE_SEL_BACKGROUND_COLOR: 558*cdf0e10cSrcweir lcl_convertColor( m_pTableModel->getActiveSelectionBackColor(), aPropertyValue ); 559*cdf0e10cSrcweir break; 560*cdf0e10cSrcweir 561*cdf0e10cSrcweir case BASEPROPERTY_INACTIVE_SEL_BACKGROUND_COLOR: 562*cdf0e10cSrcweir lcl_convertColor( m_pTableModel->getInactiveSelectionBackColor(), aPropertyValue ); 563*cdf0e10cSrcweir break; 564*cdf0e10cSrcweir 565*cdf0e10cSrcweir case BASEPROPERTY_ACTIVE_SEL_TEXT_COLOR: 566*cdf0e10cSrcweir lcl_convertColor( m_pTableModel->getActiveSelectionTextColor(), aPropertyValue ); 567*cdf0e10cSrcweir break; 568*cdf0e10cSrcweir 569*cdf0e10cSrcweir case BASEPROPERTY_INACTIVE_SEL_TEXT_COLOR: 570*cdf0e10cSrcweir lcl_convertColor( m_pTableModel->getInactiveSelectionTextColor(), aPropertyValue ); 571*cdf0e10cSrcweir break; 572*cdf0e10cSrcweir 573*cdf0e10cSrcweir case BASEPROPERTY_TEXTCOLOR: 574*cdf0e10cSrcweir lcl_convertColor( m_pTableModel->getTextColor(), aPropertyValue ); 575*cdf0e10cSrcweir break; 576*cdf0e10cSrcweir 577*cdf0e10cSrcweir case BASEPROPERTY_TEXTLINECOLOR: 578*cdf0e10cSrcweir lcl_convertColor( m_pTableModel->getTextLineColor(), aPropertyValue ); 579*cdf0e10cSrcweir break; 580*cdf0e10cSrcweir 581*cdf0e10cSrcweir default: 582*cdf0e10cSrcweir aPropertyValue = VCLXWindow::getProperty( PropertyName ); 583*cdf0e10cSrcweir break; 584*cdf0e10cSrcweir } 585*cdf0e10cSrcweir 586*cdf0e10cSrcweir return aPropertyValue; 587*cdf0e10cSrcweir } 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir void SVTXGridControl::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) 590*cdf0e10cSrcweir { 591*cdf0e10cSrcweir PushPropertyIds( rIds, 592*cdf0e10cSrcweir BASEPROPERTY_GRID_SHOWROWHEADER, 593*cdf0e10cSrcweir BASEPROPERTY_GRID_SHOWCOLUMNHEADER, 594*cdf0e10cSrcweir BASEPROPERTY_GRID_DATAMODEL, 595*cdf0e10cSrcweir BASEPROPERTY_GRID_COLUMNMODEL, 596*cdf0e10cSrcweir BASEPROPERTY_GRID_SELECTIONMODE, 597*cdf0e10cSrcweir BASEPROPERTY_GRID_HEADER_BACKGROUND, 598*cdf0e10cSrcweir BASEPROPERTY_GRID_HEADER_TEXT_COLOR, 599*cdf0e10cSrcweir BASEPROPERTY_GRID_LINE_COLOR, 600*cdf0e10cSrcweir BASEPROPERTY_GRID_ROW_BACKGROUND_COLORS, 601*cdf0e10cSrcweir BASEPROPERTY_ACTIVE_SEL_BACKGROUND_COLOR, 602*cdf0e10cSrcweir BASEPROPERTY_INACTIVE_SEL_BACKGROUND_COLOR, 603*cdf0e10cSrcweir BASEPROPERTY_ACTIVE_SEL_TEXT_COLOR, 604*cdf0e10cSrcweir BASEPROPERTY_INACTIVE_SEL_TEXT_COLOR, 605*cdf0e10cSrcweir 0 606*cdf0e10cSrcweir ); 607*cdf0e10cSrcweir VCLXWindow::ImplGetPropertyIds( rIds, true ); 608*cdf0e10cSrcweir } 609*cdf0e10cSrcweir 610*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 611*cdf0e10cSrcweir void SAL_CALL SVTXGridControl::rowsInserted( const GridDataEvent& i_event ) throw (RuntimeException) 612*cdf0e10cSrcweir { 613*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 614*cdf0e10cSrcweir m_pTableModel->notifyRowsInserted( i_event ); 615*cdf0e10cSrcweir } 616*cdf0e10cSrcweir 617*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 618*cdf0e10cSrcweir void SAL_CALL//---------------------------------------------------------------------------------------------------------------------- 619*cdf0e10cSrcweir SVTXGridControl::rowsRemoved( const GridDataEvent& i_event ) throw (RuntimeException) 620*cdf0e10cSrcweir { 621*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 622*cdf0e10cSrcweir m_pTableModel->notifyRowsRemoved( i_event ); 623*cdf0e10cSrcweir } 624*cdf0e10cSrcweir 625*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 626*cdf0e10cSrcweir void SAL_CALL SVTXGridControl::dataChanged( const GridDataEvent& i_event ) throw (RuntimeException) 627*cdf0e10cSrcweir { 628*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 629*cdf0e10cSrcweir 630*cdf0e10cSrcweir m_pTableModel->notifyDataChanged( i_event ); 631*cdf0e10cSrcweir 632*cdf0e10cSrcweir // if the data model is sortable, a dataChanged event is also fired in case the sort order changed. 633*cdf0e10cSrcweir // So, just in case, invalidate the column header area, too. 634*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 635*cdf0e10cSrcweir ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::dataChanged: no control (anymore)!" ); 636*cdf0e10cSrcweir pTable->getTableControlInterface().invalidate( TableAreaColumnHeaders ); 637*cdf0e10cSrcweir } 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 640*cdf0e10cSrcweir void SAL_CALL SVTXGridControl::rowHeadingChanged( const GridDataEvent& i_event ) throw (RuntimeException) 641*cdf0e10cSrcweir { 642*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 643*cdf0e10cSrcweir OSL_UNUSED( i_event ); 644*cdf0e10cSrcweir 645*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 646*cdf0e10cSrcweir ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::rowHeadingChanged: no control (anymore)!" ); 647*cdf0e10cSrcweir 648*cdf0e10cSrcweir // TODO: we could do better than this - invalidate the header area only 649*cdf0e10cSrcweir pTable->getTableControlInterface().invalidate( TableAreaRowHeaders ); 650*cdf0e10cSrcweir } 651*cdf0e10cSrcweir 652*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 653*cdf0e10cSrcweir void SAL_CALL SVTXGridControl::elementInserted( const ContainerEvent& i_event ) throw (RuntimeException) 654*cdf0e10cSrcweir { 655*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 656*cdf0e10cSrcweir 657*cdf0e10cSrcweir Reference< XGridColumn > const xGridColumn( i_event.Element, UNO_QUERY_THROW ); 658*cdf0e10cSrcweir 659*cdf0e10cSrcweir sal_Int32 nIndex( m_pTableModel->getColumnCount() ); 660*cdf0e10cSrcweir OSL_VERIFY( i_event.Accessor >>= nIndex ); 661*cdf0e10cSrcweir m_pTableModel->insertColumn( nIndex, xGridColumn ); 662*cdf0e10cSrcweir } 663*cdf0e10cSrcweir 664*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 665*cdf0e10cSrcweir void SAL_CALL SVTXGridControl::elementRemoved( const ContainerEvent& i_event ) throw (RuntimeException) 666*cdf0e10cSrcweir { 667*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 668*cdf0e10cSrcweir 669*cdf0e10cSrcweir sal_Int32 nIndex( -1 ); 670*cdf0e10cSrcweir OSL_VERIFY( i_event.Accessor >>= nIndex ); 671*cdf0e10cSrcweir m_pTableModel->removeColumn( nIndex ); 672*cdf0e10cSrcweir } 673*cdf0e10cSrcweir 674*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 675*cdf0e10cSrcweir void SAL_CALL SVTXGridControl::elementReplaced( const ContainerEvent& i_event ) throw (RuntimeException) 676*cdf0e10cSrcweir { 677*cdf0e10cSrcweir OSL_ENSURE( false, "SVTXGridControl::elementReplaced: not implemented!" ); 678*cdf0e10cSrcweir // at the moment, the XGridColumnModel API does not allow replacing columns 679*cdf0e10cSrcweir OSL_UNUSED( i_event ); 680*cdf0e10cSrcweir // TODO: replace the respective column in our table model 681*cdf0e10cSrcweir } 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir 684*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 685*cdf0e10cSrcweir void SAL_CALL SVTXGridControl::disposing( const EventObject& Source ) throw(RuntimeException) 686*cdf0e10cSrcweir { 687*cdf0e10cSrcweir VCLXWindow::disposing( Source ); 688*cdf0e10cSrcweir } 689*cdf0e10cSrcweir 690*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 691*cdf0e10cSrcweir void SAL_CALL SVTXGridControl::selectRow( ::sal_Int32 i_rowIndex ) throw (RuntimeException, IndexOutOfBoundsException ) 692*cdf0e10cSrcweir { 693*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 694*cdf0e10cSrcweir 695*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 696*cdf0e10cSrcweir ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::selectRow: no control (anymore)!" ); 697*cdf0e10cSrcweir 698*cdf0e10cSrcweir impl_checkRowIndex_throw( *pTable, i_rowIndex ); 699*cdf0e10cSrcweir 700*cdf0e10cSrcweir pTable->SelectRow( i_rowIndex, true ); 701*cdf0e10cSrcweir } 702*cdf0e10cSrcweir 703*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 704*cdf0e10cSrcweir void SAL_CALL SVTXGridControl::selectAllRows() throw (RuntimeException) 705*cdf0e10cSrcweir { 706*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 707*cdf0e10cSrcweir 708*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 709*cdf0e10cSrcweir ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::selectAllRows: no control (anymore)!" ); 710*cdf0e10cSrcweir 711*cdf0e10cSrcweir pTable->SelectAllRows( true ); 712*cdf0e10cSrcweir } 713*cdf0e10cSrcweir 714*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 715*cdf0e10cSrcweir void SAL_CALL SVTXGridControl::deselectRow( ::sal_Int32 i_rowIndex ) throw (RuntimeException, IndexOutOfBoundsException ) 716*cdf0e10cSrcweir { 717*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 718*cdf0e10cSrcweir 719*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 720*cdf0e10cSrcweir ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::deselectRow: no control (anymore)!" ); 721*cdf0e10cSrcweir 722*cdf0e10cSrcweir impl_checkRowIndex_throw( *pTable, i_rowIndex ); 723*cdf0e10cSrcweir 724*cdf0e10cSrcweir pTable->SelectRow( i_rowIndex, false ); 725*cdf0e10cSrcweir } 726*cdf0e10cSrcweir 727*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 728*cdf0e10cSrcweir void SAL_CALL SVTXGridControl::deselectAllRows() throw (RuntimeException) 729*cdf0e10cSrcweir { 730*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 731*cdf0e10cSrcweir 732*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 733*cdf0e10cSrcweir ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::deselectAllRows: no control (anymore)!" ); 734*cdf0e10cSrcweir 735*cdf0e10cSrcweir pTable->SelectAllRows( false ); 736*cdf0e10cSrcweir } 737*cdf0e10cSrcweir 738*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 739*cdf0e10cSrcweir Sequence< ::sal_Int32 > SAL_CALL SVTXGridControl::getSelectedRows() throw (RuntimeException) 740*cdf0e10cSrcweir { 741*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 742*cdf0e10cSrcweir 743*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 744*cdf0e10cSrcweir ENSURE_OR_RETURN( pTable, "SVTXGridControl::getSelectedRows: no control (anymore)!", Sequence< sal_Int32 >() ); 745*cdf0e10cSrcweir 746*cdf0e10cSrcweir sal_Int32 selectionCount = pTable->GetSelectedRowCount(); 747*cdf0e10cSrcweir Sequence< sal_Int32 > selectedRows( selectionCount ); 748*cdf0e10cSrcweir for ( sal_Int32 i=0; i<selectionCount; ++i ) 749*cdf0e10cSrcweir selectedRows[i] = pTable->GetSelectedRowIndex(i); 750*cdf0e10cSrcweir return selectedRows; 751*cdf0e10cSrcweir } 752*cdf0e10cSrcweir 753*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 754*cdf0e10cSrcweir ::sal_Bool SAL_CALL SVTXGridControl::hasSelectedRows() throw (RuntimeException) 755*cdf0e10cSrcweir { 756*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 757*cdf0e10cSrcweir 758*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 759*cdf0e10cSrcweir ENSURE_OR_RETURN( pTable, "SVTXGridControl::hasSelectedRows: no control (anymore)!", sal_True ); 760*cdf0e10cSrcweir 761*cdf0e10cSrcweir return pTable->GetSelectedRowCount() > 0; 762*cdf0e10cSrcweir } 763*cdf0e10cSrcweir 764*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 765*cdf0e10cSrcweir ::sal_Bool SAL_CALL SVTXGridControl::isRowSelected( ::sal_Int32 index ) throw (RuntimeException) 766*cdf0e10cSrcweir { 767*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 768*cdf0e10cSrcweir 769*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 770*cdf0e10cSrcweir ENSURE_OR_RETURN( pTable, "SVTXGridControl::isRowSelected: no control (anymore)!", sal_False ); 771*cdf0e10cSrcweir 772*cdf0e10cSrcweir return pTable->IsRowSelected( index ); 773*cdf0e10cSrcweir } 774*cdf0e10cSrcweir 775*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 776*cdf0e10cSrcweir void SVTXGridControl::dispose() throw(RuntimeException) 777*cdf0e10cSrcweir { 778*cdf0e10cSrcweir EventObject aObj; 779*cdf0e10cSrcweir aObj.Source = (::cppu::OWeakObject*)this; 780*cdf0e10cSrcweir m_aSelectionListeners.disposeAndClear( aObj ); 781*cdf0e10cSrcweir VCLXWindow::dispose(); 782*cdf0e10cSrcweir } 783*cdf0e10cSrcweir 784*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 785*cdf0e10cSrcweir void SVTXGridControl::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) 786*cdf0e10cSrcweir { 787*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 788*cdf0e10cSrcweir 789*cdf0e10cSrcweir Reference< XWindow > xKeepAlive( this ); 790*cdf0e10cSrcweir 791*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 792*cdf0e10cSrcweir ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::ProcessWindowEvent: no control (anymore)!" ); 793*cdf0e10cSrcweir 794*cdf0e10cSrcweir bool handled = false; 795*cdf0e10cSrcweir switch ( rVclWindowEvent.GetId() ) 796*cdf0e10cSrcweir { 797*cdf0e10cSrcweir case VCLEVENT_TABLEROW_SELECT: 798*cdf0e10cSrcweir { 799*cdf0e10cSrcweir if ( m_aSelectionListeners.getLength() ) 800*cdf0e10cSrcweir ImplCallItemListeners(); 801*cdf0e10cSrcweir handled = true; 802*cdf0e10cSrcweir } 803*cdf0e10cSrcweir break; 804*cdf0e10cSrcweir 805*cdf0e10cSrcweir case VCLEVENT_CONTROL_GETFOCUS: 806*cdf0e10cSrcweir { 807*cdf0e10cSrcweir // TODO: this doesn't belong here. It belongs into the TableControl/_Impl, so A11Y also 808*cdf0e10cSrcweir // works when the control is used outside the UNO context 809*cdf0e10cSrcweir if ( pTable->GetRowCount()>0 ) 810*cdf0e10cSrcweir { 811*cdf0e10cSrcweir pTable->commitCellEventIfAccessibleAlive( 812*cdf0e10cSrcweir AccessibleEventId::STATE_CHANGED, 813*cdf0e10cSrcweir makeAny( AccessibleStateType::FOCUSED ), 814*cdf0e10cSrcweir Any() 815*cdf0e10cSrcweir ); 816*cdf0e10cSrcweir pTable->commitTableEventIfAccessibleAlive( 817*cdf0e10cSrcweir AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, 818*cdf0e10cSrcweir Any(), 819*cdf0e10cSrcweir Any() 820*cdf0e10cSrcweir ); 821*cdf0e10cSrcweir } 822*cdf0e10cSrcweir else 823*cdf0e10cSrcweir { 824*cdf0e10cSrcweir pTable->commitTableEventIfAccessibleAlive( 825*cdf0e10cSrcweir AccessibleEventId::STATE_CHANGED, 826*cdf0e10cSrcweir makeAny( AccessibleStateType::FOCUSED ), 827*cdf0e10cSrcweir Any() 828*cdf0e10cSrcweir ); 829*cdf0e10cSrcweir } 830*cdf0e10cSrcweir } 831*cdf0e10cSrcweir break; 832*cdf0e10cSrcweir 833*cdf0e10cSrcweir case VCLEVENT_CONTROL_LOSEFOCUS: 834*cdf0e10cSrcweir { 835*cdf0e10cSrcweir // TODO: this doesn't belong here. It belongs into the TableControl/_Impl, so A11Y also 836*cdf0e10cSrcweir // works when the control is used outside the UNO context 837*cdf0e10cSrcweir if ( pTable->GetRowCount()>0 ) 838*cdf0e10cSrcweir { 839*cdf0e10cSrcweir pTable->commitCellEventIfAccessibleAlive( 840*cdf0e10cSrcweir AccessibleEventId::STATE_CHANGED, 841*cdf0e10cSrcweir Any(), 842*cdf0e10cSrcweir makeAny( AccessibleStateType::FOCUSED ) 843*cdf0e10cSrcweir ); 844*cdf0e10cSrcweir } 845*cdf0e10cSrcweir else 846*cdf0e10cSrcweir { 847*cdf0e10cSrcweir pTable->commitTableEventIfAccessibleAlive( 848*cdf0e10cSrcweir AccessibleEventId::STATE_CHANGED, 849*cdf0e10cSrcweir Any(), 850*cdf0e10cSrcweir makeAny( AccessibleStateType::FOCUSED ) 851*cdf0e10cSrcweir ); 852*cdf0e10cSrcweir } 853*cdf0e10cSrcweir } 854*cdf0e10cSrcweir break; 855*cdf0e10cSrcweir } 856*cdf0e10cSrcweir 857*cdf0e10cSrcweir if ( !handled ) 858*cdf0e10cSrcweir VCLXWindow::ProcessWindowEvent( rVclWindowEvent ); 859*cdf0e10cSrcweir } 860*cdf0e10cSrcweir 861*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 862*cdf0e10cSrcweir void SVTXGridControl::ImplCallItemListeners() 863*cdf0e10cSrcweir { 864*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 865*cdf0e10cSrcweir ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::ImplCallItemListeners: no control (anymore)!" ); 866*cdf0e10cSrcweir 867*cdf0e10cSrcweir if ( m_aSelectionListeners.getLength() ) 868*cdf0e10cSrcweir { 869*cdf0e10cSrcweir GridSelectionEvent aEvent; 870*cdf0e10cSrcweir aEvent.Source = (::cppu::OWeakObject*)this; 871*cdf0e10cSrcweir 872*cdf0e10cSrcweir sal_Int32 const nSelectedRowCount( pTable->GetSelectedRowCount() ); 873*cdf0e10cSrcweir aEvent.SelectedRowIndexes.realloc( nSelectedRowCount ); 874*cdf0e10cSrcweir for ( sal_Int32 i=0; i<nSelectedRowCount; ++i ) 875*cdf0e10cSrcweir aEvent.SelectedRowIndexes[i] = pTable->GetSelectedRowIndex( i ); 876*cdf0e10cSrcweir m_aSelectionListeners.selectionChanged( aEvent ); 877*cdf0e10cSrcweir } 878*cdf0e10cSrcweir } 879*cdf0e10cSrcweir 880*cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------------------- 881*cdf0e10cSrcweir void SVTXGridControl::impl_updateColumnsFromModel_nothrow() 882*cdf0e10cSrcweir { 883*cdf0e10cSrcweir Reference< XGridColumnModel > const xColumnModel( m_pTableModel->getColumnModel() ); 884*cdf0e10cSrcweir ENSURE_OR_RETURN_VOID( xColumnModel.is(), "no model!" ); 885*cdf0e10cSrcweir TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); 886*cdf0e10cSrcweir ENSURE_OR_RETURN_VOID( pTable != NULL, "no table!" ); 887*cdf0e10cSrcweir 888*cdf0e10cSrcweir try 889*cdf0e10cSrcweir { 890*cdf0e10cSrcweir const Sequence< Reference< XGridColumn > > columns = xColumnModel->getColumns(); 891*cdf0e10cSrcweir for ( const Reference< XGridColumn >* colRef = columns.getConstArray(); 892*cdf0e10cSrcweir colRef != columns.getConstArray() + columns.getLength(); 893*cdf0e10cSrcweir ++colRef 894*cdf0e10cSrcweir ) 895*cdf0e10cSrcweir { 896*cdf0e10cSrcweir ENSURE_OR_CONTINUE( colRef->is(), "illegal column!" ); 897*cdf0e10cSrcweir 898*cdf0e10cSrcweir m_pTableModel->appendColumn( *colRef ); 899*cdf0e10cSrcweir } 900*cdf0e10cSrcweir } 901*cdf0e10cSrcweir catch( const Exception& ) 902*cdf0e10cSrcweir { 903*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 904*cdf0e10cSrcweir } 905*cdf0e10cSrcweir } 906