Bump version to 5.0-14
[LibreOffice.git] / svtools / source / uno / unocontroltablemodel.cxx
blob395737c90d68efb3ed4c3150345bba3bb704f8f8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "unocontroltablemodel.hxx"
21 #include "unogridcolumnfacade.hxx"
23 #include "table/defaultinputhandler.hxx"
24 #include "table/gridtablerenderer.hxx"
25 #include "table/tablecontrol.hxx"
27 #include <com/sun/star/awt/grid/XGridColumn.hpp>
28 #include <com/sun/star/view/SelectionType.hpp>
29 #include <com/sun/star/awt/grid/XGridColumnListener.hpp>
30 #include <com/sun/star/awt/grid/XSortableGridData.hpp>
32 #include <cppuhelper/weakref.hxx>
33 #include <tools/debug.hxx>
34 #include <tools/diagnose_ex.h>
35 #include <vcl/svapp.hxx>
36 #include <osl/mutex.hxx>
39 namespace svt { namespace table
43 using ::com::sun::star::uno::Reference;
44 using ::com::sun::star::uno::RuntimeException;
45 using ::com::sun::star::uno::Sequence;
46 using ::com::sun::star::uno::UNO_QUERY_THROW;
47 using ::com::sun::star::uno::UNO_QUERY;
48 using ::com::sun::star::awt::grid::XGridColumn;
49 using ::com::sun::star::uno::XInterface;
50 using ::com::sun::star::uno::Exception;
51 using ::com::sun::star::awt::grid::XGridColumnListener;
52 using ::com::sun::star::lang::EventObject;
53 using ::com::sun::star::awt::grid::GridColumnEvent;
54 using ::com::sun::star::awt::grid::XGridDataModel;
55 using ::com::sun::star::awt::grid::XGridColumnModel;
56 using ::com::sun::star::uno::Any;
57 using ::com::sun::star::style::HorizontalAlignment_LEFT;
58 using ::com::sun::star::style::HorizontalAlignment;
59 using ::com::sun::star::style::VerticalAlignment_TOP;
60 using ::com::sun::star::style::VerticalAlignment;
61 using ::com::sun::star::uno::WeakReference;
62 using ::com::sun::star::awt::grid::GridDataEvent;
63 using ::com::sun::star::awt::grid::XSortableGridData;
64 using ::com::sun::star::beans::Pair;
67 //= UnoControlTableModel_Impl
69 typedef ::std::vector< PTableModelListener > ModellListeners;
70 typedef ::std::vector< PColumnModel > ColumnModels;
71 struct UnoControlTableModel_Impl
73 ColumnModels aColumns;
74 bool bHasColumnHeaders;
75 bool bHasRowHeaders;
76 ScrollbarVisibility eVScrollMode;
77 ScrollbarVisibility eHScrollMode;
78 PTableRenderer pRenderer;
79 PTableInputHandler pInputHandler;
80 TableMetrics nRowHeight;
81 TableMetrics nColumnHeaderHeight;
82 TableMetrics nRowHeaderWidth;
83 ::boost::optional< ::Color > m_aGridLineColor;
84 ::boost::optional< ::Color > m_aHeaderBackgroundColor;
85 ::boost::optional< ::Color > m_aHeaderTextColor;
86 ::boost::optional< ::Color > m_aActiveSelectionBackColor;
87 ::boost::optional< ::Color > m_aInactiveSelectionBackColor;
88 ::boost::optional< ::Color > m_aActiveSelectionTextColor;
89 ::boost::optional< ::Color > m_aInactiveSelectionTextColor;
90 ::boost::optional< ::Color > m_aTextColor;
91 ::boost::optional< ::Color > m_aTextLineColor;
92 ::boost::optional< ::std::vector< ::Color > > m_aRowColors;
93 VerticalAlignment m_eVerticalAlign;
94 bool bEnabled;
95 ModellListeners m_aListeners;
96 WeakReference< XGridDataModel > m_aDataModel;
97 WeakReference< XGridColumnModel > m_aColumnModel;
99 UnoControlTableModel_Impl()
100 :aColumns ( )
101 ,bHasColumnHeaders ( true )
102 ,bHasRowHeaders ( false )
103 ,eVScrollMode ( ScrollbarShowNever )
104 ,eHScrollMode ( ScrollbarShowNever )
105 ,pRenderer ( )
106 ,pInputHandler ( )
107 ,nRowHeight ( 10 )
108 ,nColumnHeaderHeight ( 10 )
109 ,nRowHeaderWidth ( 10 )
110 ,m_aGridLineColor ( )
111 ,m_aHeaderBackgroundColor ( )
112 ,m_aHeaderTextColor ( )
113 ,m_aActiveSelectionBackColor ( )
114 ,m_aInactiveSelectionBackColor ( )
115 ,m_aActiveSelectionTextColor ( )
116 ,m_aInactiveSelectionTextColor ( )
117 ,m_aTextColor ( )
118 ,m_aTextLineColor ( )
119 ,m_aRowColors ( )
120 ,m_eVerticalAlign ( VerticalAlignment_TOP )
121 ,bEnabled ( true )
126 //= UnoControlTableModel
127 #define DBG_CHECK_ME() \
128 DBG_TESTSOLARMUTEX(); \
130 UnoControlTableModel::UnoControlTableModel()
131 :m_pImpl( new UnoControlTableModel_Impl )
133 m_pImpl->bHasColumnHeaders = true;
134 m_pImpl->bHasRowHeaders = false;
135 m_pImpl->bEnabled = true;
136 m_pImpl->pRenderer.reset( new GridTableRenderer( *this ) );
137 m_pImpl->pInputHandler.reset( new DefaultInputHandler );
141 UnoControlTableModel::~UnoControlTableModel()
143 DELETEZ( m_pImpl );
147 TableSize UnoControlTableModel::getColumnCount() const
149 DBG_CHECK_ME();
150 return (TableSize)m_pImpl->aColumns.size();
154 TableSize UnoControlTableModel::getRowCount() const
156 DBG_CHECK_ME();
158 TableSize nRowCount = 0;
161 Reference< XGridDataModel > const xDataModel( m_pImpl->m_aDataModel );
162 ENSURE_OR_THROW( xDataModel.is(), "no data model anymore!" );
163 nRowCount = xDataModel->getRowCount();
165 catch( const Exception& )
167 DBG_UNHANDLED_EXCEPTION();
169 return nRowCount;
173 bool UnoControlTableModel::hasColumnHeaders() const
175 DBG_CHECK_ME();
176 return m_pImpl->bHasColumnHeaders;
180 bool UnoControlTableModel::hasRowHeaders() const
182 DBG_CHECK_ME();
183 return m_pImpl->bHasRowHeaders;
187 void UnoControlTableModel::setRowHeaders(bool _bRowHeaders)
189 DBG_CHECK_ME();
190 if ( m_pImpl->bHasRowHeaders == _bRowHeaders )
191 return;
193 m_pImpl->bHasRowHeaders = _bRowHeaders;
194 impl_notifyTableMetricsChanged();
198 void UnoControlTableModel::setColumnHeaders(bool _bColumnHeaders)
200 DBG_CHECK_ME();
201 if ( m_pImpl->bHasColumnHeaders == _bColumnHeaders )
202 return;
204 m_pImpl->bHasColumnHeaders = _bColumnHeaders;
205 impl_notifyTableMetricsChanged();
209 bool UnoControlTableModel::isCellEditable( ColPos col, RowPos row ) const
211 DBG_CHECK_ME();
212 (void)col;
213 (void)row;
214 return false;
218 PColumnModel UnoControlTableModel::getColumnModel( ColPos column )
220 DBG_CHECK_ME();
221 ENSURE_OR_RETURN( ( column >= 0 ) && ( column < getColumnCount() ),
222 "DefaultTableModel::getColumnModel: invalid index!", PColumnModel() );
223 return m_pImpl->aColumns[ column ];
227 void UnoControlTableModel::appendColumn( Reference< XGridColumn > const & i_column )
229 DBG_CHECK_ME();
230 insertColumn( m_pImpl->aColumns.size(), i_column );
234 void UnoControlTableModel::insertColumn( ColPos const i_position, Reference< XGridColumn > const & i_column )
236 DBG_CHECK_ME();
237 ENSURE_OR_RETURN_VOID( ( i_position >= 0 ) && ( size_t( i_position ) <= m_pImpl->aColumns.size() ),
238 "UnoControlTableModel::insertColumn: illegal position!" );
240 const PColumnModel pColumn( new UnoGridColumnFacade( *this, i_column ) );
241 m_pImpl->aColumns.insert( m_pImpl->aColumns.begin() + i_position, pColumn );
243 // notify listeners
244 ModellListeners aListeners( m_pImpl->m_aListeners );
245 for ( ModellListeners::const_iterator loop = aListeners.begin();
246 loop != aListeners.end();
247 ++loop
250 (*loop)->columnInserted( i_position );
255 void UnoControlTableModel::removeColumn( ColPos const i_position )
257 DBG_CHECK_ME();
258 ENSURE_OR_RETURN_VOID( ( i_position >= 0 ) && ( size_t( i_position ) <= m_pImpl->aColumns.size() ),
259 "UnoControlTableModel::removeColumn: illegal position!" );
261 // remove the column
262 ColumnModels::iterator pos = m_pImpl->aColumns.begin() + i_position;
263 const PColumnModel pColumn = *pos;
264 m_pImpl->aColumns.erase( pos );
266 // notify listeners
267 ModellListeners aListeners( m_pImpl->m_aListeners );
268 for ( ModellListeners::const_iterator loop = aListeners.begin();
269 loop != aListeners.end();
270 ++loop
273 (*loop)->columnRemoved( i_position );
276 // dispose the column
277 UnoGridColumnFacade* pColumnImpl = dynamic_cast< UnoGridColumnFacade* >( pColumn.get() );
278 OSL_ENSURE( pColumnImpl != NULL, "UnoControlTableModel::removeColumn: illegal column implementation!" );
279 if ( pColumnImpl )
280 pColumnImpl->dispose();
284 void UnoControlTableModel::removeAllColumns()
286 DBG_CHECK_ME();
287 if ( m_pImpl->aColumns.empty() )
288 return;
290 // dispose the column instances
291 for ( ColumnModels::const_iterator col = m_pImpl->aColumns.begin();
292 col != m_pImpl->aColumns.end();
293 ++col
296 UnoGridColumnFacade* pColumn = dynamic_cast< UnoGridColumnFacade* >( col->get() );
297 if ( !pColumn )
299 SAL_WARN( "svtools.uno", "UnoControlTableModel::removeAllColumns: illegal column implementation!" );
300 continue;
303 pColumn->dispose();
305 m_pImpl->aColumns.clear();
307 // notify listeners
308 ModellListeners aListeners( m_pImpl->m_aListeners );
309 for ( ModellListeners::const_iterator loop = aListeners.begin();
310 loop != aListeners.end();
311 ++loop
314 (*loop)->allColumnsRemoved();
319 void UnoControlTableModel::impl_notifyTableMetricsChanged() const
321 ModellListeners aListeners( m_pImpl->m_aListeners );
322 for ( ModellListeners::const_iterator loop = aListeners.begin();
323 loop != aListeners.end();
324 ++loop
327 (*loop)->tableMetricsChanged();
332 PTableRenderer UnoControlTableModel::getRenderer() const
334 DBG_CHECK_ME();
335 return m_pImpl->pRenderer;
339 PTableInputHandler UnoControlTableModel::getInputHandler() const
341 DBG_CHECK_ME();
342 return m_pImpl->pInputHandler;
346 TableMetrics UnoControlTableModel::getRowHeight() const
348 DBG_CHECK_ME();
349 return m_pImpl->nRowHeight;
353 void UnoControlTableModel::setRowHeight(TableMetrics _nRowHeight)
355 DBG_CHECK_ME();
356 if ( m_pImpl->nRowHeight == _nRowHeight )
357 return;
359 m_pImpl->nRowHeight = _nRowHeight;
360 impl_notifyTableMetricsChanged();
364 TableMetrics UnoControlTableModel::getColumnHeaderHeight() const
366 DBG_CHECK_ME();
367 DBG_ASSERT( hasColumnHeaders(), "DefaultTableModel::getColumnHeaderHeight: invalid call!" );
368 return m_pImpl->nColumnHeaderHeight;
372 TableMetrics UnoControlTableModel::getRowHeaderWidth() const
374 DBG_CHECK_ME();
375 DBG_ASSERT( hasRowHeaders(), "DefaultTableModel::getRowHeaderWidth: invalid call!" );
376 return m_pImpl->nRowHeaderWidth;
379 void UnoControlTableModel::setColumnHeaderHeight(TableMetrics _nHeight)
381 DBG_CHECK_ME();
382 if ( m_pImpl->nColumnHeaderHeight == _nHeight )
383 return;
385 m_pImpl->nColumnHeaderHeight = _nHeight;
386 impl_notifyTableMetricsChanged();
390 void UnoControlTableModel::setRowHeaderWidth(TableMetrics _nWidth)
392 DBG_CHECK_ME();
393 if ( m_pImpl->nRowHeaderWidth == _nWidth )
394 return;
396 m_pImpl->nRowHeaderWidth = _nWidth;
397 impl_notifyTableMetricsChanged();
401 ScrollbarVisibility UnoControlTableModel::getVerticalScrollbarVisibility() const
403 DBG_CHECK_ME();
404 return m_pImpl->eVScrollMode;
408 ScrollbarVisibility UnoControlTableModel::getHorizontalScrollbarVisibility() const
410 DBG_CHECK_ME();
411 return m_pImpl->eHScrollMode;
415 void UnoControlTableModel::addTableModelListener( const PTableModelListener& i_listener )
417 DBG_CHECK_ME();
418 ENSURE_OR_RETURN_VOID( !!i_listener, "illegal NULL listener" );
419 m_pImpl->m_aListeners.push_back( i_listener );
423 void UnoControlTableModel::removeTableModelListener( const PTableModelListener& i_listener )
425 DBG_CHECK_ME();
426 for ( ModellListeners::iterator lookup = m_pImpl->m_aListeners.begin();
427 lookup != m_pImpl->m_aListeners.end();
428 ++lookup
431 if ( *lookup == i_listener )
433 m_pImpl->m_aListeners.erase( lookup );
434 return;
437 OSL_ENSURE( false, "UnoControlTableModel::removeTableModelListener: listener is not registered - sure you're doing the right thing here?" );
441 void UnoControlTableModel::setVerticalScrollbarVisibility( ScrollbarVisibility const i_visibility ) const
443 DBG_CHECK_ME();
444 m_pImpl->eVScrollMode = i_visibility;
448 void UnoControlTableModel::setHorizontalScrollbarVisibility( ScrollbarVisibility const i_visibility ) const
450 DBG_CHECK_ME();
451 m_pImpl->eHScrollMode = i_visibility;
455 void UnoControlTableModel::setDataModel( Reference< XGridDataModel > const & i_gridDataModel )
457 DBG_CHECK_ME();
458 m_pImpl->m_aDataModel = i_gridDataModel;
459 // TODO: register as listener, so we're notified of row/data changes, and can multiplex them to our
460 // own listeners
464 Reference< XGridDataModel > UnoControlTableModel::getDataModel() const
466 Reference< XGridDataModel > const xDataModel( m_pImpl->m_aDataModel );
467 return xDataModel;
471 bool UnoControlTableModel::hasDataModel() const
473 return getDataModel().is();
477 void UnoControlTableModel::setColumnModel( Reference< XGridColumnModel > const & i_gridColumnModel )
479 DBG_CHECK_ME();
480 m_pImpl->m_aColumnModel = i_gridColumnModel;
484 Reference< XGridColumnModel > UnoControlTableModel::getColumnModel() const
486 Reference< XGridColumnModel > const xColumnModel( m_pImpl->m_aColumnModel );
487 return xColumnModel;
491 bool UnoControlTableModel::hasColumnModel() const
493 return getColumnModel().is();
497 void UnoControlTableModel::getCellContent( ColPos const i_col, RowPos const i_row, Any& o_cellContent )
499 DBG_CHECK_ME();
501 o_cellContent.clear();
504 Reference< XGridDataModel > const xDataModel( m_pImpl->m_aDataModel );
505 ENSURE_OR_RETURN_VOID( xDataModel.is(), "UnoControlTableModel::getCellContent: no data model anymore!" );
507 PColumnModel const pColumn = getColumnModel( i_col );
508 UnoGridColumnFacade* pColumnImpl = dynamic_cast< UnoGridColumnFacade* >( pColumn.get() );
509 ENSURE_OR_RETURN_VOID( pColumnImpl != NULL, "UnoControlTableModel::getCellContent: no (valid) column at this position!" );
510 sal_Int32 const nDataColumnIndex = pColumnImpl->getDataColumnIndex() >= 0 ? pColumnImpl->getDataColumnIndex() : i_col;
512 if ( nDataColumnIndex >= xDataModel->getColumnCount() )
514 // this is allowed, in case the column model has been dynamically extended, but the data model does
515 // not (yet?) know about it.
516 // So, handle it gracefully.
517 #if OSL_DEBUG_LEVEL > 0
519 Reference< XGridColumnModel > const xColumnModel( m_pImpl->m_aColumnModel );
520 OSL_ENSURE( xColumnModel.is() && i_col < xColumnModel->getColumnCount(),
521 "UnoControlTableModel::getCellContent: request a column's value which the ColumnModel doesn't know about!" );
523 #endif
525 else
527 o_cellContent = xDataModel->getCellData( nDataColumnIndex, i_row );
530 catch( const Exception& )
532 DBG_UNHANDLED_EXCEPTION();
537 void UnoControlTableModel::getCellToolTip( ColPos const i_col, RowPos const i_row, Any& o_cellToolTip )
539 DBG_CHECK_ME();
542 Reference< XGridDataModel > const xDataModel( m_pImpl->m_aDataModel );
543 ENSURE_OR_THROW( xDataModel.is(), "no data model anymore!" );
545 o_cellToolTip = xDataModel->getCellToolTip( i_col, i_row );
547 catch( const Exception& )
549 DBG_UNHANDLED_EXCEPTION();
554 Any UnoControlTableModel::getRowHeading( RowPos const i_rowPos ) const
556 DBG_CHECK_ME();
558 Any aRowHeading;
560 Reference< XGridDataModel > const xDataModel( m_pImpl->m_aDataModel );
561 ENSURE_OR_RETURN( xDataModel.is(), "UnoControlTableModel::getRowHeading: no data model anymore!", aRowHeading );
565 aRowHeading = xDataModel->getRowHeading( i_rowPos );
567 catch( const Exception& )
569 DBG_UNHANDLED_EXCEPTION();
571 return aRowHeading;
575 namespace
577 void lcl_setColor( Any const & i_color, ::boost::optional< ::Color > & o_convertedColor )
579 if ( !i_color.hasValue() )
580 o_convertedColor.reset();
581 else
583 sal_Int32 nColor = COL_TRANSPARENT;
584 if ( i_color >>= nColor )
586 o_convertedColor.reset( ::Color( nColor ) );
588 else
590 OSL_ENSURE( false, "lcl_setColor: could not extract color value!" );
597 ::boost::optional< ::Color > UnoControlTableModel::getLineColor() const
599 DBG_CHECK_ME();
600 return m_pImpl->m_aGridLineColor;
604 void UnoControlTableModel::setLineColor( Any const & i_color )
606 DBG_CHECK_ME();
607 lcl_setColor( i_color, m_pImpl->m_aGridLineColor );
611 ::boost::optional< ::Color > UnoControlTableModel::getHeaderBackgroundColor() const
613 DBG_CHECK_ME();
614 return m_pImpl->m_aHeaderBackgroundColor;
618 void UnoControlTableModel::setHeaderBackgroundColor( Any const & i_color )
620 DBG_CHECK_ME();
621 lcl_setColor( i_color, m_pImpl->m_aHeaderBackgroundColor );
625 ::boost::optional< ::Color > UnoControlTableModel::getHeaderTextColor() const
627 DBG_CHECK_ME();
628 return m_pImpl->m_aHeaderTextColor;
632 ::boost::optional< ::Color > UnoControlTableModel::getActiveSelectionBackColor() const
634 DBG_CHECK_ME();
635 return m_pImpl->m_aActiveSelectionBackColor;
639 ::boost::optional< ::Color > UnoControlTableModel::getInactiveSelectionBackColor() const
641 DBG_CHECK_ME();
642 return m_pImpl->m_aInactiveSelectionBackColor;
646 ::boost::optional< ::Color > UnoControlTableModel::getActiveSelectionTextColor() const
648 DBG_CHECK_ME();
649 return m_pImpl->m_aActiveSelectionTextColor;
653 ::boost::optional< ::Color > UnoControlTableModel::getInactiveSelectionTextColor() const
655 DBG_CHECK_ME();
656 return m_pImpl->m_aInactiveSelectionTextColor;
660 void UnoControlTableModel::setHeaderTextColor( Any const & i_color )
662 DBG_CHECK_ME();
663 lcl_setColor( i_color, m_pImpl->m_aHeaderTextColor );
667 void UnoControlTableModel::setActiveSelectionBackColor( Any const & i_color )
669 DBG_CHECK_ME();
670 lcl_setColor( i_color, m_pImpl->m_aActiveSelectionBackColor );
674 void UnoControlTableModel::setInactiveSelectionBackColor( Any const & i_color )
676 DBG_CHECK_ME();
677 lcl_setColor( i_color, m_pImpl->m_aInactiveSelectionBackColor );
681 void UnoControlTableModel::setActiveSelectionTextColor( Any const & i_color )
683 DBG_CHECK_ME();
684 lcl_setColor( i_color, m_pImpl->m_aActiveSelectionTextColor );
688 void UnoControlTableModel::setInactiveSelectionTextColor( Any const & i_color )
690 DBG_CHECK_ME();
691 lcl_setColor( i_color, m_pImpl->m_aInactiveSelectionTextColor );
695 ::boost::optional< ::Color > UnoControlTableModel::getTextColor() const
697 DBG_CHECK_ME();
698 return m_pImpl->m_aTextColor;
702 void UnoControlTableModel::setTextColor( Any const & i_color )
704 DBG_CHECK_ME();
705 lcl_setColor( i_color, m_pImpl->m_aTextColor );
709 ::boost::optional< ::Color > UnoControlTableModel::getTextLineColor() const
711 DBG_CHECK_ME();
712 return m_pImpl->m_aTextColor;
716 void UnoControlTableModel::setTextLineColor( Any const & i_color )
718 DBG_CHECK_ME();
719 lcl_setColor( i_color, m_pImpl->m_aTextLineColor );
723 ::boost::optional< ::std::vector< ::Color > > UnoControlTableModel::getRowBackgroundColors() const
725 DBG_CHECK_ME();
726 return m_pImpl->m_aRowColors;
730 void UnoControlTableModel::setRowBackgroundColors( ::com::sun::star::uno::Any const & i_APIValue )
732 DBG_CHECK_ME();
733 Sequence< ::com::sun::star::util::Color > aAPIColors;
734 if ( !( i_APIValue >>= aAPIColors ) )
735 m_pImpl->m_aRowColors.reset();
736 else
738 ::std::vector< ::Color > aColors( aAPIColors.getLength() );
739 for ( sal_Int32 i=0; i<aAPIColors.getLength(); ++i )
741 aColors[i] = ::Color( aAPIColors[i] );
743 m_pImpl->m_aRowColors.reset( aColors );
748 VerticalAlignment UnoControlTableModel::getVerticalAlign() const
750 DBG_CHECK_ME();
751 return m_pImpl->m_eVerticalAlign;
755 void UnoControlTableModel::setVerticalAlign( VerticalAlignment _xAlign )
757 DBG_CHECK_ME();
758 m_pImpl->m_eVerticalAlign = _xAlign;
762 ColPos UnoControlTableModel::getColumnPos( UnoGridColumnFacade const & i_column ) const
764 DBG_CHECK_ME();
765 for ( ColumnModels::const_iterator col = m_pImpl->aColumns.begin();
766 col != m_pImpl->aColumns.end();
767 ++col
770 if ( &i_column == col->get() )
771 return col - m_pImpl->aColumns.begin();
773 OSL_ENSURE( false, "UnoControlTableModel::getColumnPos: column not found!" );
774 return COL_INVALID;
778 ITableDataSort* UnoControlTableModel::getSortAdapter()
780 DBG_CHECK_ME();
782 Reference< XSortableGridData > const xSortAccess( getDataModel(), UNO_QUERY );
783 if ( xSortAccess.is() )
784 return this;
785 return NULL;
789 bool UnoControlTableModel::isEnabled() const
791 DBG_CHECK_ME();
792 return m_pImpl->bEnabled;
796 void UnoControlTableModel::setEnabled( bool _bEnabled )
798 DBG_CHECK_ME();
799 m_pImpl->bEnabled = _bEnabled;
803 void UnoControlTableModel::sortByColumn( ColPos const i_column, ColumnSortDirection const i_sortDirection )
805 DBG_CHECK_ME();
809 Reference< XSortableGridData > const xSortAccess( getDataModel(), UNO_QUERY_THROW );
810 xSortAccess->sortByColumn( i_column, i_sortDirection == ColumnSortAscending );
812 catch( const Exception& )
814 DBG_UNHANDLED_EXCEPTION();
819 ColumnSort UnoControlTableModel::getCurrentSortOrder() const
821 DBG_CHECK_ME();
823 ColumnSort currentSort;
826 Reference< XSortableGridData > const xSortAccess( getDataModel(), UNO_QUERY_THROW );
827 Pair< ::sal_Int32, sal_Bool > const aCurrentSortOrder( xSortAccess->getCurrentSortOrder() );
828 currentSort.nColumnPos = aCurrentSortOrder.First;
829 currentSort.eSortDirection = aCurrentSortOrder.Second ? ColumnSortAscending : ColumnSortDescending;
831 catch( const Exception& )
833 DBG_UNHANDLED_EXCEPTION();
835 return currentSort;
839 void UnoControlTableModel::notifyColumnChange( ColPos const i_columnPos, ColumnAttributeGroup const i_attributeGroup ) const
841 DBG_CHECK_ME();
842 ENSURE_OR_RETURN_VOID( ( i_columnPos >= 0 ) && ( i_columnPos < getColumnCount() ),
843 "UnoControlTableModel::notifyColumnChange: invalid column index!" );
845 ModellListeners aListeners( m_pImpl->m_aListeners );
846 for ( ModellListeners::const_iterator loop = aListeners.begin();
847 loop != aListeners.end();
848 ++loop
851 (*loop)->columnChanged( i_columnPos, i_attributeGroup );
856 void UnoControlTableModel::notifyRowsInserted( GridDataEvent const & i_event ) const
858 // check sanity of the event
859 ENSURE_OR_RETURN_VOID( i_event.FirstRow >= 0, "UnoControlTableModel::notifyRowsInserted: invalid first row!" );
860 ENSURE_OR_RETURN_VOID( i_event.LastRow >= i_event.FirstRow, "UnoControlTableModel::notifyRowsInserted: invalid row indexes!" );
862 // check own sanity
863 Reference< XGridColumnModel > const xColumnModel( m_pImpl->m_aColumnModel );
864 ENSURE_OR_RETURN_VOID( xColumnModel.is(), "UnoControlTableModel::notifyRowsInserted: no column model anymore!" );
866 Reference< XGridDataModel > const xDataModel( m_pImpl->m_aDataModel );
867 ENSURE_OR_RETURN_VOID( xDataModel.is(), "UnoControlTableModel::notifyRowsInserted: no data model anymore!" );
869 // implicitly add columns to the column model
870 // TODO: is this really a good idea?
871 sal_Int32 const dataColumnCount = xDataModel->getColumnCount();
872 OSL_ENSURE( dataColumnCount > 0, "UnoControlTableModel::notifyRowsInserted: no columns at all?" );
874 sal_Int32 const modelColumnCount = xColumnModel->getColumnCount();
875 if ( ( modelColumnCount == 0 ) && ( dataColumnCount > 0 ) )
877 // TODO: shouldn't we clear the mutexes guard for this call?
878 xColumnModel->setDefaultColumns( dataColumnCount );
881 // multiplex the event to our own listeners
882 ModellListeners aListeners( m_pImpl->m_aListeners );
883 for ( ModellListeners::const_iterator loop = aListeners.begin();
884 loop != aListeners.end();
885 ++loop
888 (*loop)->rowsInserted( i_event.FirstRow, i_event.LastRow );
893 void UnoControlTableModel::notifyRowsRemoved( GridDataEvent const & i_event ) const
895 ModellListeners aListeners( m_pImpl->m_aListeners );
896 for ( ModellListeners::const_iterator loop = aListeners.begin();
897 loop != aListeners.end();
898 ++loop
901 (*loop)->rowsRemoved( i_event.FirstRow, i_event.LastRow );
906 void UnoControlTableModel::notifyDataChanged( ::com::sun::star::awt::grid::GridDataEvent const & i_event ) const
908 ColPos const firstCol = i_event.FirstColumn == -1 ? 0 : i_event.FirstColumn;
909 ColPos const lastCol = i_event.FirstColumn == -1 ? getColumnCount() - 1 : i_event.LastColumn;
910 RowPos const firstRow = i_event.FirstRow == -1 ? 0 : i_event.FirstRow;
911 RowPos const lastRow = i_event.FirstRow == -1 ? getRowCount() - 1 : i_event.LastRow;
913 ModellListeners aListeners( m_pImpl->m_aListeners );
914 for ( ModellListeners::const_iterator loop = aListeners.begin();
915 loop != aListeners.end();
916 ++loop
919 (*loop)->cellsUpdated( firstCol, lastCol, firstRow, lastRow );
924 void UnoControlTableModel::notifyAllDataChanged() const
926 ModellListeners aListeners( m_pImpl->m_aListeners );
927 for ( ModellListeners::const_iterator loop = aListeners.begin();
928 loop != aListeners.end();
929 ++loop
932 (*loop)->cellsUpdated( 0, getColumnCount() - 1, 0, getRowCount() - 1 );
937 } } // svt::table
939 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */