GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svtools / source / uno / unocontroltablemodel.cxx
blob3c135ebc2e1d32dc101af433de909d05dc0616d4
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 "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;
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 ModellListeners m_aListeners;
95 WeakReference< XGridDataModel > m_aDataModel;
96 WeakReference< XGridColumnModel > m_aColumnModel;
98 UnoControlTableModel_Impl()
99 :aColumns ( )
100 ,bHasColumnHeaders ( true )
101 ,bHasRowHeaders ( false )
102 ,eVScrollMode ( ScrollbarShowNever )
103 ,eHScrollMode ( ScrollbarShowNever )
104 ,pRenderer ( )
105 ,pInputHandler ( )
106 ,nRowHeight ( 10 )
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 ( )
116 ,m_aTextColor ( )
117 ,m_aTextLineColor ( )
118 ,m_aRowColors ( )
119 ,m_eVerticalAlign ( VerticalAlignment_TOP )
124 //==================================================================================================================
125 //= UnoControlTableModel
126 //==================================================================================================================
127 #ifdef DBG_UTIL
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";
140 // TODO: more?
142 return NULL;
144 #endif
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 );
166 DELETEZ( m_pImpl );
169 //------------------------------------------------------------------------------------------------------------------
170 TableSize UnoControlTableModel::getColumnCount() const
172 DBG_CHECK_ME();
173 return (TableSize)m_pImpl->aColumns.size();
176 //------------------------------------------------------------------------------------------------------------------
177 TableSize UnoControlTableModel::getRowCount() const
179 DBG_CHECK_ME();
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();
192 return nRowCount;
195 //------------------------------------------------------------------------------------------------------------------
196 bool UnoControlTableModel::hasColumnHeaders() const
198 DBG_CHECK_ME();
199 return m_pImpl->bHasColumnHeaders;
202 //------------------------------------------------------------------------------------------------------------------
203 bool UnoControlTableModel::hasRowHeaders() const
205 DBG_CHECK_ME();
206 return m_pImpl->bHasRowHeaders;
209 //------------------------------------------------------------------------------------------------------------------
210 void UnoControlTableModel::setRowHeaders(bool _bRowHeaders)
212 DBG_CHECK_ME();
213 if ( m_pImpl->bHasRowHeaders == _bRowHeaders )
214 return;
216 m_pImpl->bHasRowHeaders = _bRowHeaders;
217 impl_notifyTableMetricsChanged();
220 //------------------------------------------------------------------------------------------------------------------
221 void UnoControlTableModel::setColumnHeaders(bool _bColumnHeaders)
223 DBG_CHECK_ME();
224 if ( m_pImpl->bHasColumnHeaders == _bColumnHeaders )
225 return;
227 m_pImpl->bHasColumnHeaders = _bColumnHeaders;
228 impl_notifyTableMetricsChanged();
231 //------------------------------------------------------------------------------------------------------------------
232 bool UnoControlTableModel::isCellEditable( ColPos col, RowPos row ) const
234 DBG_CHECK_ME();
235 (void)col;
236 (void)row;
237 return false;
240 //------------------------------------------------------------------------------------------------------------------
241 PColumnModel UnoControlTableModel::getColumnModel( ColPos column )
243 DBG_CHECK_ME();
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 )
252 DBG_CHECK_ME();
253 insertColumn( m_pImpl->aColumns.size(), i_column );
256 //------------------------------------------------------------------------------------------------------------------
257 void UnoControlTableModel::insertColumn( ColPos const i_position, Reference< XGridColumn > const & i_column )
259 DBG_CHECK_ME();
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 );
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)->columnInserted( i_position );
277 //------------------------------------------------------------------------------------------------------------------
278 void UnoControlTableModel::removeColumn( ColPos const i_position )
280 DBG_CHECK_ME();
281 ENSURE_OR_RETURN_VOID( ( i_position >= 0 ) && ( size_t( i_position ) <= m_pImpl->aColumns.size() ),
282 "UnoControlTableModel::removeColumn: illegal position!" );
284 // remove the column
285 ColumnModels::iterator pos = m_pImpl->aColumns.begin() + i_position;
286 const PColumnModel pColumn = *pos;
287 m_pImpl->aColumns.erase( pos );
289 // notify listeners
290 ModellListeners aListeners( m_pImpl->m_aListeners );
291 for ( ModellListeners::const_iterator loop = aListeners.begin();
292 loop != aListeners.end();
293 ++loop
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!" );
302 if ( pColumnImpl )
303 pColumnImpl->dispose();
306 //------------------------------------------------------------------------------------------------------------------
307 void UnoControlTableModel::removeAllColumns()
309 DBG_CHECK_ME();
310 if ( m_pImpl->aColumns.empty() )
311 return;
313 // dispose the column instances
314 for ( ColumnModels::const_iterator col = m_pImpl->aColumns.begin();
315 col != m_pImpl->aColumns.end();
316 ++col
319 UnoGridColumnFacade* pColumn = dynamic_cast< UnoGridColumnFacade* >( col->get() );
320 if ( !pColumn )
322 SAL_WARN( "svtools.uno", "UnoControlTableModel::removeAllColumns: illegal column implementation!" );
323 continue;
326 pColumn->dispose();
328 m_pImpl->aColumns.clear();
330 // notify listeners
331 ModellListeners aListeners( m_pImpl->m_aListeners );
332 for ( ModellListeners::const_iterator loop = aListeners.begin();
333 loop != aListeners.end();
334 ++loop
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();
347 ++loop
350 (*loop)->tableMetricsChanged();
354 //------------------------------------------------------------------------------------------------------------------
355 PTableRenderer UnoControlTableModel::getRenderer() const
357 DBG_CHECK_ME();
358 return m_pImpl->pRenderer;
361 //------------------------------------------------------------------------------------------------------------------
362 PTableInputHandler UnoControlTableModel::getInputHandler() const
364 DBG_CHECK_ME();
365 return m_pImpl->pInputHandler;
368 //------------------------------------------------------------------------------------------------------------------
369 TableMetrics UnoControlTableModel::getRowHeight() const
371 DBG_CHECK_ME();
372 return m_pImpl->nRowHeight;
375 //------------------------------------------------------------------------------------------------------------------
376 void UnoControlTableModel::setRowHeight(TableMetrics _nRowHeight)
378 DBG_CHECK_ME();
379 if ( m_pImpl->nRowHeight == _nRowHeight )
380 return;
382 m_pImpl->nRowHeight = _nRowHeight;
383 impl_notifyTableMetricsChanged();
386 //------------------------------------------------------------------------------------------------------------------
387 TableMetrics UnoControlTableModel::getColumnHeaderHeight() const
389 DBG_CHECK_ME();
390 DBG_ASSERT( hasColumnHeaders(), "DefaultTableModel::getColumnHeaderHeight: invalid call!" );
391 return m_pImpl->nColumnHeaderHeight;
394 //------------------------------------------------------------------------------------------------------------------
395 TableMetrics UnoControlTableModel::getRowHeaderWidth() const
397 DBG_CHECK_ME();
398 DBG_ASSERT( hasRowHeaders(), "DefaultTableModel::getRowHeaderWidth: invalid call!" );
399 return m_pImpl->nRowHeaderWidth;
401 //------------------------------------------------------------------------------------------------------------------
402 void UnoControlTableModel::setColumnHeaderHeight(TableMetrics _nHeight)
404 DBG_CHECK_ME();
405 if ( m_pImpl->nColumnHeaderHeight == _nHeight )
406 return;
408 m_pImpl->nColumnHeaderHeight = _nHeight;
409 impl_notifyTableMetricsChanged();
412 //------------------------------------------------------------------------------------------------------------------
413 void UnoControlTableModel::setRowHeaderWidth(TableMetrics _nWidth)
415 DBG_CHECK_ME();
416 if ( m_pImpl->nRowHeaderWidth == _nWidth )
417 return;
419 m_pImpl->nRowHeaderWidth = _nWidth;
420 impl_notifyTableMetricsChanged();
423 //------------------------------------------------------------------------------------------------------------------
424 ScrollbarVisibility UnoControlTableModel::getVerticalScrollbarVisibility() const
426 DBG_CHECK_ME();
427 return m_pImpl->eVScrollMode;
430 //------------------------------------------------------------------------------------------------------------------
431 ScrollbarVisibility UnoControlTableModel::getHorizontalScrollbarVisibility() const
433 DBG_CHECK_ME();
434 return m_pImpl->eHScrollMode;
437 //------------------------------------------------------------------------------------------------------------------
438 void UnoControlTableModel::addTableModelListener( const PTableModelListener& i_listener )
440 DBG_CHECK_ME();
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 )
448 DBG_CHECK_ME();
449 for ( ModellListeners::iterator lookup = m_pImpl->m_aListeners.begin();
450 lookup != m_pImpl->m_aListeners.end();
451 ++lookup
454 if ( *lookup == i_listener )
456 m_pImpl->m_aListeners.erase( lookup );
457 return;
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
466 DBG_CHECK_ME();
467 m_pImpl->eVScrollMode = i_visibility;
470 //------------------------------------------------------------------------------------------------------------------
471 void UnoControlTableModel::setHorizontalScrollbarVisibility( ScrollbarVisibility const i_visibility ) const
473 DBG_CHECK_ME();
474 m_pImpl->eHScrollMode = i_visibility;
477 //------------------------------------------------------------------------------------------------------------------
478 void UnoControlTableModel::setDataModel( Reference< XGridDataModel > const & i_gridDataModel )
480 DBG_CHECK_ME();
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
483 // own listeners
486 //------------------------------------------------------------------------------------------------------------------
487 Reference< XGridDataModel > UnoControlTableModel::getDataModel() const
489 Reference< XGridDataModel > const xDataModel( m_pImpl->m_aDataModel );
490 return xDataModel;
493 //------------------------------------------------------------------------------------------------------------------
494 bool UnoControlTableModel::hasDataModel() const
496 return getDataModel().is();
499 //------------------------------------------------------------------------------------------------------------------
500 void UnoControlTableModel::setColumnModel( Reference< XGridColumnModel > const & i_gridColumnModel )
502 DBG_CHECK_ME();
503 m_pImpl->m_aColumnModel = i_gridColumnModel;
506 //------------------------------------------------------------------------------------------------------------------
507 Reference< XGridColumnModel > UnoControlTableModel::getColumnModel() const
509 Reference< XGridColumnModel > const xColumnModel( m_pImpl->m_aColumnModel );
510 return xColumnModel;
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 )
522 DBG_CHECK_ME();
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!" );
546 #endif
548 else
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 )
562 DBG_CHECK_ME();
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
579 DBG_CHECK_ME();
581 Any aRowHeading;
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();
594 return aRowHeading;
597 //------------------------------------------------------------------------------------------------------------------
598 namespace
600 void lcl_setColor( Any const & i_color, ::boost::optional< ::Color > & o_convertedColor )
602 if ( !i_color.hasValue() )
603 o_convertedColor.reset();
604 else
606 sal_Int32 nColor = COL_TRANSPARENT;
607 if ( i_color >>= nColor )
609 o_convertedColor.reset( ::Color( nColor ) );
611 else
613 OSL_ENSURE( false, "lcl_setColor: could not extract color value!" );
619 //------------------------------------------------------------------------------------------------------------------
620 ::boost::optional< ::Color > UnoControlTableModel::getLineColor() const
622 DBG_CHECK_ME();
623 return m_pImpl->m_aGridLineColor;
626 //------------------------------------------------------------------------------------------------------------------
627 void UnoControlTableModel::setLineColor( Any const & i_color )
629 DBG_CHECK_ME();
630 lcl_setColor( i_color, m_pImpl->m_aGridLineColor );
633 //------------------------------------------------------------------------------------------------------------------
634 ::boost::optional< ::Color > UnoControlTableModel::getHeaderBackgroundColor() const
636 DBG_CHECK_ME();
637 return m_pImpl->m_aHeaderBackgroundColor;
640 //------------------------------------------------------------------------------------------------------------------
641 void UnoControlTableModel::setHeaderBackgroundColor( Any const & i_color )
643 DBG_CHECK_ME();
644 lcl_setColor( i_color, m_pImpl->m_aHeaderBackgroundColor );
647 //------------------------------------------------------------------------------------------------------------------
648 ::boost::optional< ::Color > UnoControlTableModel::getHeaderTextColor() const
650 DBG_CHECK_ME();
651 return m_pImpl->m_aHeaderTextColor;
654 //------------------------------------------------------------------------------------------------------------------
655 ::boost::optional< ::Color > UnoControlTableModel::getActiveSelectionBackColor() const
657 DBG_CHECK_ME();
658 return m_pImpl->m_aActiveSelectionBackColor;
661 //------------------------------------------------------------------------------------------------------------------
662 ::boost::optional< ::Color > UnoControlTableModel::getInactiveSelectionBackColor() const
664 DBG_CHECK_ME();
665 return m_pImpl->m_aInactiveSelectionBackColor;
668 //------------------------------------------------------------------------------------------------------------------
669 ::boost::optional< ::Color > UnoControlTableModel::getActiveSelectionTextColor() const
671 DBG_CHECK_ME();
672 return m_pImpl->m_aActiveSelectionTextColor;
675 //------------------------------------------------------------------------------------------------------------------
676 ::boost::optional< ::Color > UnoControlTableModel::getInactiveSelectionTextColor() const
678 DBG_CHECK_ME();
679 return m_pImpl->m_aInactiveSelectionTextColor;
682 //------------------------------------------------------------------------------------------------------------------
683 void UnoControlTableModel::setHeaderTextColor( Any const & i_color )
685 DBG_CHECK_ME();
686 lcl_setColor( i_color, m_pImpl->m_aHeaderTextColor );
689 //------------------------------------------------------------------------------------------------------------------
690 void UnoControlTableModel::setActiveSelectionBackColor( Any const & i_color )
692 DBG_CHECK_ME();
693 lcl_setColor( i_color, m_pImpl->m_aActiveSelectionBackColor );
696 //------------------------------------------------------------------------------------------------------------------
697 void UnoControlTableModel::setInactiveSelectionBackColor( Any const & i_color )
699 DBG_CHECK_ME();
700 lcl_setColor( i_color, m_pImpl->m_aInactiveSelectionBackColor );
703 //------------------------------------------------------------------------------------------------------------------
704 void UnoControlTableModel::setActiveSelectionTextColor( Any const & i_color )
706 DBG_CHECK_ME();
707 lcl_setColor( i_color, m_pImpl->m_aActiveSelectionTextColor );
710 //------------------------------------------------------------------------------------------------------------------
711 void UnoControlTableModel::setInactiveSelectionTextColor( Any const & i_color )
713 DBG_CHECK_ME();
714 lcl_setColor( i_color, m_pImpl->m_aInactiveSelectionTextColor );
717 //------------------------------------------------------------------------------------------------------------------
718 ::boost::optional< ::Color > UnoControlTableModel::getTextColor() const
720 DBG_CHECK_ME();
721 return m_pImpl->m_aTextColor;
724 //------------------------------------------------------------------------------------------------------------------
725 void UnoControlTableModel::setTextColor( Any const & i_color )
727 DBG_CHECK_ME();
728 lcl_setColor( i_color, m_pImpl->m_aTextColor );
731 //------------------------------------------------------------------------------------------------------------------
732 ::boost::optional< ::Color > UnoControlTableModel::getTextLineColor() const
734 DBG_CHECK_ME();
735 return m_pImpl->m_aTextColor;
738 //------------------------------------------------------------------------------------------------------------------
739 void UnoControlTableModel::setTextLineColor( Any const & i_color )
741 DBG_CHECK_ME();
742 lcl_setColor( i_color, m_pImpl->m_aTextLineColor );
745 //------------------------------------------------------------------------------------------------------------------
746 ::boost::optional< ::std::vector< ::Color > > UnoControlTableModel::getRowBackgroundColors() const
748 DBG_CHECK_ME();
749 return m_pImpl->m_aRowColors;
752 //------------------------------------------------------------------------------------------------------------------
753 void UnoControlTableModel::setRowBackgroundColors( ::com::sun::star::uno::Any const & i_APIValue )
755 DBG_CHECK_ME();
756 Sequence< ::com::sun::star::util::Color > aAPIColors;
757 if ( !( i_APIValue >>= aAPIColors ) )
758 m_pImpl->m_aRowColors.reset();
759 else
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
773 DBG_CHECK_ME();
774 return m_pImpl->m_eVerticalAlign;
777 //------------------------------------------------------------------------------------------------------------------
778 void UnoControlTableModel::setVerticalAlign( VerticalAlignment _xAlign )
780 DBG_CHECK_ME();
781 m_pImpl->m_eVerticalAlign = _xAlign;
784 //------------------------------------------------------------------------------------------------------------------
785 ColPos UnoControlTableModel::getColumnPos( UnoGridColumnFacade const & i_column ) const
787 DBG_CHECK_ME();
788 for ( ColumnModels::const_iterator col = m_pImpl->aColumns.begin();
789 col != m_pImpl->aColumns.end();
790 ++col
793 if ( &i_column == col->get() )
794 return col - m_pImpl->aColumns.begin();
796 OSL_ENSURE( false, "UnoControlTableModel::getColumnPos: column not found!" );
797 return COL_INVALID;
800 //------------------------------------------------------------------------------------------------------------------
801 ITableDataSort* UnoControlTableModel::getSortAdapter()
803 DBG_CHECK_ME();
805 Reference< XSortableGridData > const xSortAccess( getDataModel(), UNO_QUERY );
806 if ( xSortAccess.is() )
807 return this;
808 return NULL;
811 //------------------------------------------------------------------------------------------------------------------
812 void UnoControlTableModel::sortByColumn( ColPos const i_column, ColumnSortDirection const i_sortDirection )
814 DBG_CHECK_ME();
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
830 DBG_CHECK_ME();
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();
844 return currentSort;
847 //--------------------------------------------------------------------
848 void UnoControlTableModel::notifyColumnChange( ColPos const i_columnPos, ColumnAttributeGroup const i_attributeGroup ) const
850 DBG_CHECK_ME();
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();
857 ++loop
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!" );
871 // check own sanity
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();
894 ++loop
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();
907 ++loop
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();
925 ++loop
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();
938 ++loop
941 (*loop)->cellsUpdated( 0, getColumnCount() - 1, 0, getRowCount() - 1 );
945 // .....................................................................................................................
946 } } // svt::table
947 // .....................................................................................................................
948 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */