1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
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
;
95 ModellListeners m_aListeners
;
96 WeakReference
< XGridDataModel
> m_aDataModel
;
97 WeakReference
< XGridColumnModel
> m_aColumnModel
;
99 UnoControlTableModel_Impl()
101 ,bHasColumnHeaders ( true )
102 ,bHasRowHeaders ( false )
103 ,eVScrollMode ( ScrollbarShowNever
)
104 ,eHScrollMode ( ScrollbarShowNever
)
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 ( )
118 ,m_aTextLineColor ( )
120 ,m_eVerticalAlign ( VerticalAlignment_TOP
)
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()
147 TableSize
UnoControlTableModel::getColumnCount() const
150 return (TableSize
)m_pImpl
->aColumns
.size();
154 TableSize
UnoControlTableModel::getRowCount() const
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();
173 bool UnoControlTableModel::hasColumnHeaders() const
176 return m_pImpl
->bHasColumnHeaders
;
180 bool UnoControlTableModel::hasRowHeaders() const
183 return m_pImpl
->bHasRowHeaders
;
187 void UnoControlTableModel::setRowHeaders(bool _bRowHeaders
)
190 if ( m_pImpl
->bHasRowHeaders
== _bRowHeaders
)
193 m_pImpl
->bHasRowHeaders
= _bRowHeaders
;
194 impl_notifyTableMetricsChanged();
198 void UnoControlTableModel::setColumnHeaders(bool _bColumnHeaders
)
201 if ( m_pImpl
->bHasColumnHeaders
== _bColumnHeaders
)
204 m_pImpl
->bHasColumnHeaders
= _bColumnHeaders
;
205 impl_notifyTableMetricsChanged();
209 bool UnoControlTableModel::isCellEditable( ColPos col
, RowPos row
) const
218 PColumnModel
UnoControlTableModel::getColumnModel( ColPos column
)
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
)
230 insertColumn( m_pImpl
->aColumns
.size(), i_column
);
234 void UnoControlTableModel::insertColumn( ColPos
const i_position
, Reference
< XGridColumn
> const & i_column
)
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
);
244 ModellListeners
aListeners( m_pImpl
->m_aListeners
);
245 for ( ModellListeners::const_iterator loop
= aListeners
.begin();
246 loop
!= aListeners
.end();
250 (*loop
)->columnInserted( i_position
);
255 void UnoControlTableModel::removeColumn( ColPos
const i_position
)
258 ENSURE_OR_RETURN_VOID( ( i_position
>= 0 ) && ( size_t( i_position
) <= m_pImpl
->aColumns
.size() ),
259 "UnoControlTableModel::removeColumn: illegal position!" );
262 ColumnModels::iterator pos
= m_pImpl
->aColumns
.begin() + i_position
;
263 const PColumnModel pColumn
= *pos
;
264 m_pImpl
->aColumns
.erase( pos
);
267 ModellListeners
aListeners( m_pImpl
->m_aListeners
);
268 for ( ModellListeners::const_iterator loop
= aListeners
.begin();
269 loop
!= aListeners
.end();
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!" );
280 pColumnImpl
->dispose();
284 void UnoControlTableModel::removeAllColumns()
287 if ( m_pImpl
->aColumns
.empty() )
290 // dispose the column instances
291 for ( ColumnModels::const_iterator col
= m_pImpl
->aColumns
.begin();
292 col
!= m_pImpl
->aColumns
.end();
296 UnoGridColumnFacade
* pColumn
= dynamic_cast< UnoGridColumnFacade
* >( col
->get() );
299 SAL_WARN( "svtools.uno", "UnoControlTableModel::removeAllColumns: illegal column implementation!" );
305 m_pImpl
->aColumns
.clear();
308 ModellListeners
aListeners( m_pImpl
->m_aListeners
);
309 for ( ModellListeners::const_iterator loop
= aListeners
.begin();
310 loop
!= aListeners
.end();
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();
327 (*loop
)->tableMetricsChanged();
332 PTableRenderer
UnoControlTableModel::getRenderer() const
335 return m_pImpl
->pRenderer
;
339 PTableInputHandler
UnoControlTableModel::getInputHandler() const
342 return m_pImpl
->pInputHandler
;
346 TableMetrics
UnoControlTableModel::getRowHeight() const
349 return m_pImpl
->nRowHeight
;
353 void UnoControlTableModel::setRowHeight(TableMetrics _nRowHeight
)
356 if ( m_pImpl
->nRowHeight
== _nRowHeight
)
359 m_pImpl
->nRowHeight
= _nRowHeight
;
360 impl_notifyTableMetricsChanged();
364 TableMetrics
UnoControlTableModel::getColumnHeaderHeight() const
367 DBG_ASSERT( hasColumnHeaders(), "DefaultTableModel::getColumnHeaderHeight: invalid call!" );
368 return m_pImpl
->nColumnHeaderHeight
;
372 TableMetrics
UnoControlTableModel::getRowHeaderWidth() const
375 DBG_ASSERT( hasRowHeaders(), "DefaultTableModel::getRowHeaderWidth: invalid call!" );
376 return m_pImpl
->nRowHeaderWidth
;
379 void UnoControlTableModel::setColumnHeaderHeight(TableMetrics _nHeight
)
382 if ( m_pImpl
->nColumnHeaderHeight
== _nHeight
)
385 m_pImpl
->nColumnHeaderHeight
= _nHeight
;
386 impl_notifyTableMetricsChanged();
390 void UnoControlTableModel::setRowHeaderWidth(TableMetrics _nWidth
)
393 if ( m_pImpl
->nRowHeaderWidth
== _nWidth
)
396 m_pImpl
->nRowHeaderWidth
= _nWidth
;
397 impl_notifyTableMetricsChanged();
401 ScrollbarVisibility
UnoControlTableModel::getVerticalScrollbarVisibility() const
404 return m_pImpl
->eVScrollMode
;
408 ScrollbarVisibility
UnoControlTableModel::getHorizontalScrollbarVisibility() const
411 return m_pImpl
->eHScrollMode
;
415 void UnoControlTableModel::addTableModelListener( const PTableModelListener
& i_listener
)
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
)
426 for ( ModellListeners::iterator lookup
= m_pImpl
->m_aListeners
.begin();
427 lookup
!= m_pImpl
->m_aListeners
.end();
431 if ( *lookup
== i_listener
)
433 m_pImpl
->m_aListeners
.erase( lookup
);
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
444 m_pImpl
->eVScrollMode
= i_visibility
;
448 void UnoControlTableModel::setHorizontalScrollbarVisibility( ScrollbarVisibility
const i_visibility
) const
451 m_pImpl
->eHScrollMode
= i_visibility
;
455 void UnoControlTableModel::setDataModel( Reference
< XGridDataModel
> const & i_gridDataModel
)
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
464 Reference
< XGridDataModel
> UnoControlTableModel::getDataModel() const
466 Reference
< XGridDataModel
> const xDataModel( m_pImpl
->m_aDataModel
);
471 bool UnoControlTableModel::hasDataModel() const
473 return getDataModel().is();
477 void UnoControlTableModel::setColumnModel( Reference
< XGridColumnModel
> const & i_gridColumnModel
)
480 m_pImpl
->m_aColumnModel
= i_gridColumnModel
;
484 Reference
< XGridColumnModel
> UnoControlTableModel::getColumnModel() const
486 Reference
< XGridColumnModel
> const xColumnModel( m_pImpl
->m_aColumnModel
);
491 bool UnoControlTableModel::hasColumnModel() const
493 return getColumnModel().is();
497 void UnoControlTableModel::getCellContent( ColPos
const i_col
, RowPos
const i_row
, Any
& o_cellContent
)
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!" );
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
)
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
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();
577 void lcl_setColor( Any
const & i_color
, ::boost::optional
< ::Color
> & o_convertedColor
)
579 if ( !i_color
.hasValue() )
580 o_convertedColor
.reset();
583 sal_Int32 nColor
= COL_TRANSPARENT
;
584 if ( i_color
>>= nColor
)
586 o_convertedColor
.reset( ::Color( nColor
) );
590 OSL_ENSURE( false, "lcl_setColor: could not extract color value!" );
597 ::boost::optional
< ::Color
> UnoControlTableModel::getLineColor() const
600 return m_pImpl
->m_aGridLineColor
;
604 void UnoControlTableModel::setLineColor( Any
const & i_color
)
607 lcl_setColor( i_color
, m_pImpl
->m_aGridLineColor
);
611 ::boost::optional
< ::Color
> UnoControlTableModel::getHeaderBackgroundColor() const
614 return m_pImpl
->m_aHeaderBackgroundColor
;
618 void UnoControlTableModel::setHeaderBackgroundColor( Any
const & i_color
)
621 lcl_setColor( i_color
, m_pImpl
->m_aHeaderBackgroundColor
);
625 ::boost::optional
< ::Color
> UnoControlTableModel::getHeaderTextColor() const
628 return m_pImpl
->m_aHeaderTextColor
;
632 ::boost::optional
< ::Color
> UnoControlTableModel::getActiveSelectionBackColor() const
635 return m_pImpl
->m_aActiveSelectionBackColor
;
639 ::boost::optional
< ::Color
> UnoControlTableModel::getInactiveSelectionBackColor() const
642 return m_pImpl
->m_aInactiveSelectionBackColor
;
646 ::boost::optional
< ::Color
> UnoControlTableModel::getActiveSelectionTextColor() const
649 return m_pImpl
->m_aActiveSelectionTextColor
;
653 ::boost::optional
< ::Color
> UnoControlTableModel::getInactiveSelectionTextColor() const
656 return m_pImpl
->m_aInactiveSelectionTextColor
;
660 void UnoControlTableModel::setHeaderTextColor( Any
const & i_color
)
663 lcl_setColor( i_color
, m_pImpl
->m_aHeaderTextColor
);
667 void UnoControlTableModel::setActiveSelectionBackColor( Any
const & i_color
)
670 lcl_setColor( i_color
, m_pImpl
->m_aActiveSelectionBackColor
);
674 void UnoControlTableModel::setInactiveSelectionBackColor( Any
const & i_color
)
677 lcl_setColor( i_color
, m_pImpl
->m_aInactiveSelectionBackColor
);
681 void UnoControlTableModel::setActiveSelectionTextColor( Any
const & i_color
)
684 lcl_setColor( i_color
, m_pImpl
->m_aActiveSelectionTextColor
);
688 void UnoControlTableModel::setInactiveSelectionTextColor( Any
const & i_color
)
691 lcl_setColor( i_color
, m_pImpl
->m_aInactiveSelectionTextColor
);
695 ::boost::optional
< ::Color
> UnoControlTableModel::getTextColor() const
698 return m_pImpl
->m_aTextColor
;
702 void UnoControlTableModel::setTextColor( Any
const & i_color
)
705 lcl_setColor( i_color
, m_pImpl
->m_aTextColor
);
709 ::boost::optional
< ::Color
> UnoControlTableModel::getTextLineColor() const
712 return m_pImpl
->m_aTextColor
;
716 void UnoControlTableModel::setTextLineColor( Any
const & i_color
)
719 lcl_setColor( i_color
, m_pImpl
->m_aTextLineColor
);
723 ::boost::optional
< ::std::vector
< ::Color
> > UnoControlTableModel::getRowBackgroundColors() const
726 return m_pImpl
->m_aRowColors
;
730 void UnoControlTableModel::setRowBackgroundColors( ::com::sun::star::uno::Any
const & i_APIValue
)
733 Sequence
< ::com::sun::star::util::Color
> aAPIColors
;
734 if ( !( i_APIValue
>>= aAPIColors
) )
735 m_pImpl
->m_aRowColors
.reset();
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
751 return m_pImpl
->m_eVerticalAlign
;
755 void UnoControlTableModel::setVerticalAlign( VerticalAlignment _xAlign
)
758 m_pImpl
->m_eVerticalAlign
= _xAlign
;
762 ColPos
UnoControlTableModel::getColumnPos( UnoGridColumnFacade
const & i_column
) const
765 for ( ColumnModels::const_iterator col
= m_pImpl
->aColumns
.begin();
766 col
!= m_pImpl
->aColumns
.end();
770 if ( &i_column
== col
->get() )
771 return col
- m_pImpl
->aColumns
.begin();
773 OSL_ENSURE( false, "UnoControlTableModel::getColumnPos: column not found!" );
778 ITableDataSort
* UnoControlTableModel::getSortAdapter()
782 Reference
< XSortableGridData
> const xSortAccess( getDataModel(), UNO_QUERY
);
783 if ( xSortAccess
.is() )
789 bool UnoControlTableModel::isEnabled() const
792 return m_pImpl
->bEnabled
;
796 void UnoControlTableModel::setEnabled( bool _bEnabled
)
799 m_pImpl
->bEnabled
= _bEnabled
;
803 void UnoControlTableModel::sortByColumn( ColPos
const i_column
, ColumnSortDirection
const i_sortDirection
)
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
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();
839 void UnoControlTableModel::notifyColumnChange( ColPos
const i_columnPos
, ColumnAttributeGroup
const i_attributeGroup
) const
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();
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!" );
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();
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();
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();
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();
932 (*loop
)->cellsUpdated( 0, getColumnCount() - 1, 0, getRowCount() - 1 );
939 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */