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 "svtools/table/defaultinputhandler.hxx"
24 #include "svtools/table/gridtablerenderer.hxx"
25 #include "svtools/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>
38 // .....................................................................................................................
39 namespace svt
{ namespace table
41 // .....................................................................................................................
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
;
66 //==================================================================================================================
67 //= UnoControlTableModel_Impl
68 //==================================================================================================================
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
;
94 ModellListeners m_aListeners
;
95 WeakReference
< XGridDataModel
> m_aDataModel
;
96 WeakReference
< XGridColumnModel
> m_aColumnModel
;
98 UnoControlTableModel_Impl()
100 ,bHasColumnHeaders ( true )
101 ,bHasRowHeaders ( false )
102 ,eVScrollMode ( ScrollbarShowNever
)
103 ,eHScrollMode ( ScrollbarShowNever
)
107 ,nColumnHeaderHeight ( 10 )
108 ,nRowHeaderWidth ( 10 )
109 ,m_aGridLineColor ( )
110 ,m_aHeaderBackgroundColor ( )
111 ,m_aHeaderTextColor ( )
112 ,m_aActiveSelectionBackColor ( )
113 ,m_aInactiveSelectionBackColor ( )
114 ,m_aActiveSelectionTextColor ( )
115 ,m_aInactiveSelectionTextColor ( )
117 ,m_aTextLineColor ( )
119 ,m_eVerticalAlign ( VerticalAlignment_TOP
)
124 //==================================================================================================================
125 //= UnoControlTableModel
126 //==================================================================================================================
128 const char* UnoControlTableModel_checkInvariants( const void* _pInstance
)
130 return static_cast< const UnoControlTableModel
* >( _pInstance
)->checkInvariants();
133 //------------------------------------------------------------------------------------------------------------------
134 const char* UnoControlTableModel::checkInvariants() const
136 Reference
< XGridDataModel
> const xDataModel( m_pImpl
->m_aDataModel
);
137 if ( !xDataModel
.is() )
138 return "data model anymore";
146 #define DBG_CHECK_ME() \
147 DBG_TESTSOLARMUTEX(); \
148 DBG_CHKTHIS( UnoControlTableModel, UnoControlTableModel_checkInvariants )
150 //------------------------------------------------------------------------------------------------------------------
151 DBG_NAME( UnoControlTableModel
)
152 UnoControlTableModel::UnoControlTableModel()
153 :m_pImpl( new UnoControlTableModel_Impl
)
155 DBG_CTOR( UnoControlTableModel
, UnoControlTableModel_checkInvariants
);
156 m_pImpl
->bHasColumnHeaders
= true;
157 m_pImpl
->bHasRowHeaders
= false;
158 m_pImpl
->pRenderer
.reset( new GridTableRenderer( *this ) );
159 m_pImpl
->pInputHandler
.reset( new DefaultInputHandler
);
162 //------------------------------------------------------------------------------------------------------------------
163 UnoControlTableModel::~UnoControlTableModel()
165 DBG_DTOR( UnoControlTableModel
, UnoControlTableModel_checkInvariants
);
169 //------------------------------------------------------------------------------------------------------------------
170 TableSize
UnoControlTableModel::getColumnCount() const
173 return (TableSize
)m_pImpl
->aColumns
.size();
176 //------------------------------------------------------------------------------------------------------------------
177 TableSize
UnoControlTableModel::getRowCount() const
181 TableSize nRowCount
= 0;
184 Reference
< XGridDataModel
> const xDataModel( m_pImpl
->m_aDataModel
);
185 ENSURE_OR_THROW( xDataModel
.is(), "no data model anymore!" );
186 nRowCount
= xDataModel
->getRowCount();
188 catch( const Exception
& )
190 DBG_UNHANDLED_EXCEPTION();
195 //------------------------------------------------------------------------------------------------------------------
196 bool UnoControlTableModel::hasColumnHeaders() const
199 return m_pImpl
->bHasColumnHeaders
;
202 //------------------------------------------------------------------------------------------------------------------
203 bool UnoControlTableModel::hasRowHeaders() const
206 return m_pImpl
->bHasRowHeaders
;
209 //------------------------------------------------------------------------------------------------------------------
210 void UnoControlTableModel::setRowHeaders(bool _bRowHeaders
)
213 if ( m_pImpl
->bHasRowHeaders
== _bRowHeaders
)
216 m_pImpl
->bHasRowHeaders
= _bRowHeaders
;
217 impl_notifyTableMetricsChanged();
220 //------------------------------------------------------------------------------------------------------------------
221 void UnoControlTableModel::setColumnHeaders(bool _bColumnHeaders
)
224 if ( m_pImpl
->bHasColumnHeaders
== _bColumnHeaders
)
227 m_pImpl
->bHasColumnHeaders
= _bColumnHeaders
;
228 impl_notifyTableMetricsChanged();
231 //------------------------------------------------------------------------------------------------------------------
232 bool UnoControlTableModel::isCellEditable( ColPos col
, RowPos row
) const
240 //------------------------------------------------------------------------------------------------------------------
241 PColumnModel
UnoControlTableModel::getColumnModel( ColPos column
)
244 ENSURE_OR_RETURN( ( column
>= 0 ) && ( column
< getColumnCount() ),
245 "DefaultTableModel::getColumnModel: invalid index!", PColumnModel() );
246 return m_pImpl
->aColumns
[ column
];
249 //------------------------------------------------------------------------------------------------------------------
250 void UnoControlTableModel::appendColumn( Reference
< XGridColumn
> const & i_column
)
253 insertColumn( m_pImpl
->aColumns
.size(), i_column
);
256 //------------------------------------------------------------------------------------------------------------------
257 void UnoControlTableModel::insertColumn( ColPos
const i_position
, Reference
< XGridColumn
> const & i_column
)
260 ENSURE_OR_RETURN_VOID( ( i_position
>= 0 ) && ( size_t( i_position
) <= m_pImpl
->aColumns
.size() ),
261 "UnoControlTableModel::insertColumn: illegal position!" );
263 const PColumnModel
pColumn( new UnoGridColumnFacade( *this, i_column
) );
264 m_pImpl
->aColumns
.insert( m_pImpl
->aColumns
.begin() + i_position
, pColumn
);
267 ModellListeners
aListeners( m_pImpl
->m_aListeners
);
268 for ( ModellListeners::const_iterator loop
= aListeners
.begin();
269 loop
!= aListeners
.end();
273 (*loop
)->columnInserted( i_position
);
277 //------------------------------------------------------------------------------------------------------------------
278 void UnoControlTableModel::removeColumn( ColPos
const i_position
)
281 ENSURE_OR_RETURN_VOID( ( i_position
>= 0 ) && ( size_t( i_position
) <= m_pImpl
->aColumns
.size() ),
282 "UnoControlTableModel::removeColumn: illegal position!" );
285 ColumnModels::iterator pos
= m_pImpl
->aColumns
.begin() + i_position
;
286 const PColumnModel pColumn
= *pos
;
287 m_pImpl
->aColumns
.erase( pos
);
290 ModellListeners
aListeners( m_pImpl
->m_aListeners
);
291 for ( ModellListeners::const_iterator loop
= aListeners
.begin();
292 loop
!= aListeners
.end();
296 (*loop
)->columnRemoved( i_position
);
299 // dispose the column
300 UnoGridColumnFacade
* pColumnImpl
= dynamic_cast< UnoGridColumnFacade
* >( pColumn
.get() );
301 OSL_ENSURE( pColumnImpl
!= NULL
, "UnoControlTableModel::removeColumn: illegal column implementation!" );
303 pColumnImpl
->dispose();
306 //------------------------------------------------------------------------------------------------------------------
307 void UnoControlTableModel::removeAllColumns()
310 if ( m_pImpl
->aColumns
.empty() )
313 // dispose the column instances
314 for ( ColumnModels::const_iterator col
= m_pImpl
->aColumns
.begin();
315 col
!= m_pImpl
->aColumns
.end();
319 UnoGridColumnFacade
* pColumn
= dynamic_cast< UnoGridColumnFacade
* >( col
->get() );
322 SAL_WARN( "svtools.uno", "UnoControlTableModel::removeAllColumns: illegal column implementation!" );
328 m_pImpl
->aColumns
.clear();
331 ModellListeners
aListeners( m_pImpl
->m_aListeners
);
332 for ( ModellListeners::const_iterator loop
= aListeners
.begin();
333 loop
!= aListeners
.end();
337 (*loop
)->allColumnsRemoved();
341 //------------------------------------------------------------------------------------------------------------------
342 void UnoControlTableModel::impl_notifyTableMetricsChanged() const
344 ModellListeners
aListeners( m_pImpl
->m_aListeners
);
345 for ( ModellListeners::const_iterator loop
= aListeners
.begin();
346 loop
!= aListeners
.end();
350 (*loop
)->tableMetricsChanged();
354 //------------------------------------------------------------------------------------------------------------------
355 PTableRenderer
UnoControlTableModel::getRenderer() const
358 return m_pImpl
->pRenderer
;
361 //------------------------------------------------------------------------------------------------------------------
362 PTableInputHandler
UnoControlTableModel::getInputHandler() const
365 return m_pImpl
->pInputHandler
;
368 //------------------------------------------------------------------------------------------------------------------
369 TableMetrics
UnoControlTableModel::getRowHeight() const
372 return m_pImpl
->nRowHeight
;
375 //------------------------------------------------------------------------------------------------------------------
376 void UnoControlTableModel::setRowHeight(TableMetrics _nRowHeight
)
379 if ( m_pImpl
->nRowHeight
== _nRowHeight
)
382 m_pImpl
->nRowHeight
= _nRowHeight
;
383 impl_notifyTableMetricsChanged();
386 //------------------------------------------------------------------------------------------------------------------
387 TableMetrics
UnoControlTableModel::getColumnHeaderHeight() const
390 DBG_ASSERT( hasColumnHeaders(), "DefaultTableModel::getColumnHeaderHeight: invalid call!" );
391 return m_pImpl
->nColumnHeaderHeight
;
394 //------------------------------------------------------------------------------------------------------------------
395 TableMetrics
UnoControlTableModel::getRowHeaderWidth() const
398 DBG_ASSERT( hasRowHeaders(), "DefaultTableModel::getRowHeaderWidth: invalid call!" );
399 return m_pImpl
->nRowHeaderWidth
;
401 //------------------------------------------------------------------------------------------------------------------
402 void UnoControlTableModel::setColumnHeaderHeight(TableMetrics _nHeight
)
405 if ( m_pImpl
->nColumnHeaderHeight
== _nHeight
)
408 m_pImpl
->nColumnHeaderHeight
= _nHeight
;
409 impl_notifyTableMetricsChanged();
412 //------------------------------------------------------------------------------------------------------------------
413 void UnoControlTableModel::setRowHeaderWidth(TableMetrics _nWidth
)
416 if ( m_pImpl
->nRowHeaderWidth
== _nWidth
)
419 m_pImpl
->nRowHeaderWidth
= _nWidth
;
420 impl_notifyTableMetricsChanged();
423 //------------------------------------------------------------------------------------------------------------------
424 ScrollbarVisibility
UnoControlTableModel::getVerticalScrollbarVisibility() const
427 return m_pImpl
->eVScrollMode
;
430 //------------------------------------------------------------------------------------------------------------------
431 ScrollbarVisibility
UnoControlTableModel::getHorizontalScrollbarVisibility() const
434 return m_pImpl
->eHScrollMode
;
437 //------------------------------------------------------------------------------------------------------------------
438 void UnoControlTableModel::addTableModelListener( const PTableModelListener
& i_listener
)
441 ENSURE_OR_RETURN_VOID( !!i_listener
, "illegal NULL listener" );
442 m_pImpl
->m_aListeners
.push_back( i_listener
);
445 //------------------------------------------------------------------------------------------------------------------
446 void UnoControlTableModel::removeTableModelListener( const PTableModelListener
& i_listener
)
449 for ( ModellListeners::iterator lookup
= m_pImpl
->m_aListeners
.begin();
450 lookup
!= m_pImpl
->m_aListeners
.end();
454 if ( *lookup
== i_listener
)
456 m_pImpl
->m_aListeners
.erase( lookup
);
460 OSL_ENSURE( false, "UnoControlTableModel::removeTableModelListener: listener is not registered - sure you're doing the right thing here?" );
463 //------------------------------------------------------------------------------------------------------------------
464 void UnoControlTableModel::setVerticalScrollbarVisibility( ScrollbarVisibility
const i_visibility
) const
467 m_pImpl
->eVScrollMode
= i_visibility
;
470 //------------------------------------------------------------------------------------------------------------------
471 void UnoControlTableModel::setHorizontalScrollbarVisibility( ScrollbarVisibility
const i_visibility
) const
474 m_pImpl
->eHScrollMode
= i_visibility
;
477 //------------------------------------------------------------------------------------------------------------------
478 void UnoControlTableModel::setDataModel( Reference
< XGridDataModel
> const & i_gridDataModel
)
481 m_pImpl
->m_aDataModel
= i_gridDataModel
;
482 // TODO: register as listener, so we're notified of row/data changes, and can multiplex them to our
486 //------------------------------------------------------------------------------------------------------------------
487 Reference
< XGridDataModel
> UnoControlTableModel::getDataModel() const
489 Reference
< XGridDataModel
> const xDataModel( m_pImpl
->m_aDataModel
);
493 //------------------------------------------------------------------------------------------------------------------
494 bool UnoControlTableModel::hasDataModel() const
496 return getDataModel().is();
499 //------------------------------------------------------------------------------------------------------------------
500 void UnoControlTableModel::setColumnModel( Reference
< XGridColumnModel
> const & i_gridColumnModel
)
503 m_pImpl
->m_aColumnModel
= i_gridColumnModel
;
506 //------------------------------------------------------------------------------------------------------------------
507 Reference
< XGridColumnModel
> UnoControlTableModel::getColumnModel() const
509 Reference
< XGridColumnModel
> const xColumnModel( m_pImpl
->m_aColumnModel
);
513 //------------------------------------------------------------------------------------------------------------------
514 bool UnoControlTableModel::hasColumnModel() const
516 return getColumnModel().is();
519 //------------------------------------------------------------------------------------------------------------------
520 void UnoControlTableModel::getCellContent( ColPos
const i_col
, RowPos
const i_row
, Any
& o_cellContent
)
524 o_cellContent
.clear();
527 Reference
< XGridDataModel
> const xDataModel( m_pImpl
->m_aDataModel
);
528 ENSURE_OR_RETURN_VOID( xDataModel
.is(), "UnoControlTableModel::getCellContent: no data model anymore!" );
530 PColumnModel
const pColumn
= getColumnModel( i_col
);
531 UnoGridColumnFacade
* pColumnImpl
= dynamic_cast< UnoGridColumnFacade
* >( pColumn
.get() );
532 ENSURE_OR_RETURN_VOID( pColumnImpl
!= NULL
, "UnoControlTableModel::getCellContent: no (valid) column at this position!" );
533 sal_Int32
const nDataColumnIndex
= pColumnImpl
->getDataColumnIndex() >= 0 ? pColumnImpl
->getDataColumnIndex() : i_col
;
535 if ( nDataColumnIndex
>= xDataModel
->getColumnCount() )
537 // this is allowed, in case the column model has been dynamically extended, but the data model does
538 // not (yet?) know about it.
539 // So, handle it gracefully.
540 #if OSL_DEBUG_LEVEL > 0
542 Reference
< XGridColumnModel
> const xColumnModel( m_pImpl
->m_aColumnModel
);
543 OSL_ENSURE( xColumnModel
.is() && i_col
< xColumnModel
->getColumnCount(),
544 "UnoControlTableModel::getCellContent: request a column's value which the ColumnModel doesn't know about!" );
550 o_cellContent
= xDataModel
->getCellData( nDataColumnIndex
, i_row
);
553 catch( const Exception
& )
555 DBG_UNHANDLED_EXCEPTION();
559 //------------------------------------------------------------------------------------------------------------------
560 void UnoControlTableModel::getCellToolTip( ColPos
const i_col
, RowPos
const i_row
, Any
& o_cellToolTip
)
565 Reference
< XGridDataModel
> const xDataModel( m_pImpl
->m_aDataModel
);
566 ENSURE_OR_THROW( xDataModel
.is(), "no data model anymore!" );
568 o_cellToolTip
= xDataModel
->getCellToolTip( i_col
, i_row
);
570 catch( const Exception
& )
572 DBG_UNHANDLED_EXCEPTION();
576 //------------------------------------------------------------------------------------------------------------------
577 Any
UnoControlTableModel::getRowHeading( RowPos
const i_rowPos
) const
583 Reference
< XGridDataModel
> const xDataModel( m_pImpl
->m_aDataModel
);
584 ENSURE_OR_RETURN( xDataModel
.is(), "UnoControlTableModel::getRowHeading: no data model anymore!", aRowHeading
);
588 aRowHeading
= xDataModel
->getRowHeading( i_rowPos
);
590 catch( const Exception
& )
592 DBG_UNHANDLED_EXCEPTION();
597 //------------------------------------------------------------------------------------------------------------------
600 void lcl_setColor( Any
const & i_color
, ::boost::optional
< ::Color
> & o_convertedColor
)
602 if ( !i_color
.hasValue() )
603 o_convertedColor
.reset();
606 sal_Int32 nColor
= COL_TRANSPARENT
;
607 if ( i_color
>>= nColor
)
609 o_convertedColor
.reset( ::Color( nColor
) );
613 OSL_ENSURE( false, "lcl_setColor: could not extract color value!" );
619 //------------------------------------------------------------------------------------------------------------------
620 ::boost::optional
< ::Color
> UnoControlTableModel::getLineColor() const
623 return m_pImpl
->m_aGridLineColor
;
626 //------------------------------------------------------------------------------------------------------------------
627 void UnoControlTableModel::setLineColor( Any
const & i_color
)
630 lcl_setColor( i_color
, m_pImpl
->m_aGridLineColor
);
633 //------------------------------------------------------------------------------------------------------------------
634 ::boost::optional
< ::Color
> UnoControlTableModel::getHeaderBackgroundColor() const
637 return m_pImpl
->m_aHeaderBackgroundColor
;
640 //------------------------------------------------------------------------------------------------------------------
641 void UnoControlTableModel::setHeaderBackgroundColor( Any
const & i_color
)
644 lcl_setColor( i_color
, m_pImpl
->m_aHeaderBackgroundColor
);
647 //------------------------------------------------------------------------------------------------------------------
648 ::boost::optional
< ::Color
> UnoControlTableModel::getHeaderTextColor() const
651 return m_pImpl
->m_aHeaderTextColor
;
654 //------------------------------------------------------------------------------------------------------------------
655 ::boost::optional
< ::Color
> UnoControlTableModel::getActiveSelectionBackColor() const
658 return m_pImpl
->m_aActiveSelectionBackColor
;
661 //------------------------------------------------------------------------------------------------------------------
662 ::boost::optional
< ::Color
> UnoControlTableModel::getInactiveSelectionBackColor() const
665 return m_pImpl
->m_aInactiveSelectionBackColor
;
668 //------------------------------------------------------------------------------------------------------------------
669 ::boost::optional
< ::Color
> UnoControlTableModel::getActiveSelectionTextColor() const
672 return m_pImpl
->m_aActiveSelectionTextColor
;
675 //------------------------------------------------------------------------------------------------------------------
676 ::boost::optional
< ::Color
> UnoControlTableModel::getInactiveSelectionTextColor() const
679 return m_pImpl
->m_aInactiveSelectionTextColor
;
682 //------------------------------------------------------------------------------------------------------------------
683 void UnoControlTableModel::setHeaderTextColor( Any
const & i_color
)
686 lcl_setColor( i_color
, m_pImpl
->m_aHeaderTextColor
);
689 //------------------------------------------------------------------------------------------------------------------
690 void UnoControlTableModel::setActiveSelectionBackColor( Any
const & i_color
)
693 lcl_setColor( i_color
, m_pImpl
->m_aActiveSelectionBackColor
);
696 //------------------------------------------------------------------------------------------------------------------
697 void UnoControlTableModel::setInactiveSelectionBackColor( Any
const & i_color
)
700 lcl_setColor( i_color
, m_pImpl
->m_aInactiveSelectionBackColor
);
703 //------------------------------------------------------------------------------------------------------------------
704 void UnoControlTableModel::setActiveSelectionTextColor( Any
const & i_color
)
707 lcl_setColor( i_color
, m_pImpl
->m_aActiveSelectionTextColor
);
710 //------------------------------------------------------------------------------------------------------------------
711 void UnoControlTableModel::setInactiveSelectionTextColor( Any
const & i_color
)
714 lcl_setColor( i_color
, m_pImpl
->m_aInactiveSelectionTextColor
);
717 //------------------------------------------------------------------------------------------------------------------
718 ::boost::optional
< ::Color
> UnoControlTableModel::getTextColor() const
721 return m_pImpl
->m_aTextColor
;
724 //------------------------------------------------------------------------------------------------------------------
725 void UnoControlTableModel::setTextColor( Any
const & i_color
)
728 lcl_setColor( i_color
, m_pImpl
->m_aTextColor
);
731 //------------------------------------------------------------------------------------------------------------------
732 ::boost::optional
< ::Color
> UnoControlTableModel::getTextLineColor() const
735 return m_pImpl
->m_aTextColor
;
738 //------------------------------------------------------------------------------------------------------------------
739 void UnoControlTableModel::setTextLineColor( Any
const & i_color
)
742 lcl_setColor( i_color
, m_pImpl
->m_aTextLineColor
);
745 //------------------------------------------------------------------------------------------------------------------
746 ::boost::optional
< ::std::vector
< ::Color
> > UnoControlTableModel::getRowBackgroundColors() const
749 return m_pImpl
->m_aRowColors
;
752 //------------------------------------------------------------------------------------------------------------------
753 void UnoControlTableModel::setRowBackgroundColors( ::com::sun::star::uno::Any
const & i_APIValue
)
756 Sequence
< ::com::sun::star::util::Color
> aAPIColors
;
757 if ( !( i_APIValue
>>= aAPIColors
) )
758 m_pImpl
->m_aRowColors
.reset();
761 ::std::vector
< ::Color
> aColors( aAPIColors
.getLength() );
762 for ( sal_Int32 i
=0; i
<aAPIColors
.getLength(); ++i
)
764 aColors
[i
] = ::Color( aAPIColors
[i
] );
766 m_pImpl
->m_aRowColors
.reset( aColors
);
770 //------------------------------------------------------------------------------------------------------------------
771 VerticalAlignment
UnoControlTableModel::getVerticalAlign() const
774 return m_pImpl
->m_eVerticalAlign
;
777 //------------------------------------------------------------------------------------------------------------------
778 void UnoControlTableModel::setVerticalAlign( VerticalAlignment _xAlign
)
781 m_pImpl
->m_eVerticalAlign
= _xAlign
;
784 //------------------------------------------------------------------------------------------------------------------
785 ColPos
UnoControlTableModel::getColumnPos( UnoGridColumnFacade
const & i_column
) const
788 for ( ColumnModels::const_iterator col
= m_pImpl
->aColumns
.begin();
789 col
!= m_pImpl
->aColumns
.end();
793 if ( &i_column
== col
->get() )
794 return col
- m_pImpl
->aColumns
.begin();
796 OSL_ENSURE( false, "UnoControlTableModel::getColumnPos: column not found!" );
800 //------------------------------------------------------------------------------------------------------------------
801 ITableDataSort
* UnoControlTableModel::getSortAdapter()
805 Reference
< XSortableGridData
> const xSortAccess( getDataModel(), UNO_QUERY
);
806 if ( xSortAccess
.is() )
811 //------------------------------------------------------------------------------------------------------------------
812 void UnoControlTableModel::sortByColumn( ColPos
const i_column
, ColumnSortDirection
const i_sortDirection
)
818 Reference
< XSortableGridData
> const xSortAccess( getDataModel(), UNO_QUERY_THROW
);
819 xSortAccess
->sortByColumn( i_column
, i_sortDirection
== ColumnSortAscending
);
821 catch( const Exception
& )
823 DBG_UNHANDLED_EXCEPTION();
827 //------------------------------------------------------------------------------------------------------------------
828 ColumnSort
UnoControlTableModel::getCurrentSortOrder() const
832 ColumnSort currentSort
;
835 Reference
< XSortableGridData
> const xSortAccess( getDataModel(), UNO_QUERY_THROW
);
836 Pair
< ::sal_Int32
, ::sal_Bool
> const aCurrentSortOrder( xSortAccess
->getCurrentSortOrder() );
837 currentSort
.nColumnPos
= aCurrentSortOrder
.First
;
838 currentSort
.eSortDirection
= aCurrentSortOrder
.Second
? ColumnSortAscending
: ColumnSortDescending
;
840 catch( const Exception
& )
842 DBG_UNHANDLED_EXCEPTION();
847 //--------------------------------------------------------------------
848 void UnoControlTableModel::notifyColumnChange( ColPos
const i_columnPos
, ColumnAttributeGroup
const i_attributeGroup
) const
851 ENSURE_OR_RETURN_VOID( ( i_columnPos
>= 0 ) && ( i_columnPos
< getColumnCount() ),
852 "UnoControlTableModel::notifyColumnChange: invalid column index!" );
854 ModellListeners
aListeners( m_pImpl
->m_aListeners
);
855 for ( ModellListeners::const_iterator loop
= aListeners
.begin();
856 loop
!= aListeners
.end();
860 (*loop
)->columnChanged( i_columnPos
, i_attributeGroup
);
864 //------------------------------------------------------------------------------------------------------------------
865 void UnoControlTableModel::notifyRowsInserted( GridDataEvent
const & i_event
) const
867 // check sanity of the event
868 ENSURE_OR_RETURN_VOID( i_event
.FirstRow
>= 0, "UnoControlTableModel::notifyRowsInserted: invalid first row!" );
869 ENSURE_OR_RETURN_VOID( i_event
.LastRow
>= i_event
.FirstRow
, "UnoControlTableModel::notifyRowsInserted: invalid row indexes!" );
872 Reference
< XGridColumnModel
> const xColumnModel( m_pImpl
->m_aColumnModel
);
873 ENSURE_OR_RETURN_VOID( xColumnModel
.is(), "UnoControlTableModel::notifyRowsInserted: no column model anymore!" );
875 Reference
< XGridDataModel
> const xDataModel( m_pImpl
->m_aDataModel
);
876 ENSURE_OR_RETURN_VOID( xDataModel
.is(), "UnoControlTableModel::notifyRowsInserted: no data model anymore!" );
878 // implicitly add columns to the column model
879 // TODO: is this really a good idea?
880 sal_Int32
const dataColumnCount
= xDataModel
->getColumnCount();
881 OSL_ENSURE( dataColumnCount
> 0, "UnoControlTableModel::notifyRowsInserted: no columns at all?" );
883 sal_Int32
const modelColumnCount
= xColumnModel
->getColumnCount();
884 if ( ( modelColumnCount
== 0 ) && ( dataColumnCount
> 0 ) )
886 // TODO: shouldn't we clear the mutexes guard for this call?
887 xColumnModel
->setDefaultColumns( dataColumnCount
);
890 // multiplex the event to our own listeners
891 ModellListeners
aListeners( m_pImpl
->m_aListeners
);
892 for ( ModellListeners::const_iterator loop
= aListeners
.begin();
893 loop
!= aListeners
.end();
897 (*loop
)->rowsInserted( i_event
.FirstRow
, i_event
.LastRow
);
901 //------------------------------------------------------------------------------------------------------------------
902 void UnoControlTableModel::notifyRowsRemoved( GridDataEvent
const & i_event
) const
904 ModellListeners
aListeners( m_pImpl
->m_aListeners
);
905 for ( ModellListeners::const_iterator loop
= aListeners
.begin();
906 loop
!= aListeners
.end();
910 (*loop
)->rowsRemoved( i_event
.FirstRow
, i_event
.LastRow
);
914 //------------------------------------------------------------------------------------------------------------------
915 void UnoControlTableModel::notifyDataChanged( ::com::sun::star::awt::grid::GridDataEvent
const & i_event
) const
917 ColPos
const firstCol
= i_event
.FirstColumn
== -1 ? 0 : i_event
.FirstColumn
;
918 ColPos
const lastCol
= i_event
.FirstColumn
== -1 ? getColumnCount() - 1 : i_event
.LastColumn
;
919 RowPos
const firstRow
= i_event
.FirstRow
== -1 ? 0 : i_event
.FirstRow
;
920 RowPos
const lastRow
= i_event
.FirstRow
== -1 ? getRowCount() - 1 : i_event
.LastRow
;
922 ModellListeners
aListeners( m_pImpl
->m_aListeners
);
923 for ( ModellListeners::const_iterator loop
= aListeners
.begin();
924 loop
!= aListeners
.end();
928 (*loop
)->cellsUpdated( firstCol
, lastCol
, firstRow
, lastRow
);
932 //------------------------------------------------------------------------------------------------------------------
933 void UnoControlTableModel::notifyAllDataChanged() const
935 ModellListeners
aListeners( m_pImpl
->m_aListeners
);
936 for ( ModellListeners::const_iterator loop
= aListeners
.begin();
937 loop
!= aListeners
.end();
941 (*loop
)->cellsUpdated( 0, getColumnCount() - 1, 0, getRowCount() - 1 );
945 // .....................................................................................................................
947 // .....................................................................................................................
948 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */