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