15900e8ecSAndrew Rist /**************************************************************
25900e8ecSAndrew Rist  *
35900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
45900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
55900e8ecSAndrew Rist  * distributed with this work for additional information
65900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
75900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
85900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
95900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
105900e8ecSAndrew Rist  *
115900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
125900e8ecSAndrew Rist  *
135900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
145900e8ecSAndrew Rist  * software distributed under the License is distributed on an
155900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
175900e8ecSAndrew Rist  * specific language governing permissions and limitations
185900e8ecSAndrew Rist  * under the License.
195900e8ecSAndrew Rist  *
205900e8ecSAndrew Rist  *************************************************************/
215900e8ecSAndrew Rist 
225900e8ecSAndrew Rist 
23cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
24cdf0e10cSrcweir #include "precompiled_svtools.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "unocontroltablemodel.hxx"
27cdf0e10cSrcweir #include "unogridcolumnfacade.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "svtools/table/defaultinputhandler.hxx"
30cdf0e10cSrcweir #include "svtools/table/gridtablerenderer.hxx"
31cdf0e10cSrcweir #include "svtools/table/tablecontrol.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir /** === begin UNO includes === **/
34cdf0e10cSrcweir #include <com/sun/star/awt/grid/XGridColumn.hpp>
35cdf0e10cSrcweir #include <com/sun/star/view/SelectionType.hpp>
36cdf0e10cSrcweir #include <com/sun/star/awt/grid/XGridColumnListener.hpp>
37cdf0e10cSrcweir #include <com/sun/star/awt/grid/XSortableGridData.hpp>
38cdf0e10cSrcweir /** === end UNO includes === **/
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <comphelper/stlunosequence.hxx>
41cdf0e10cSrcweir #include <cppuhelper/weakref.hxx>
42cdf0e10cSrcweir #include <tools/debug.hxx>
43cdf0e10cSrcweir #include <tools/diagnose_ex.h>
44cdf0e10cSrcweir #include <vcl/svapp.hxx>
45cdf0e10cSrcweir #include <vos/mutex.hxx>
46cdf0e10cSrcweir 
47cdf0e10cSrcweir // .....................................................................................................................
48cdf0e10cSrcweir namespace svt { namespace table
49cdf0e10cSrcweir {
50cdf0e10cSrcweir // .....................................................................................................................
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     /** === begin UNO using === **/
53cdf0e10cSrcweir     using ::com::sun::star::uno::Reference;
54cdf0e10cSrcweir     using ::com::sun::star::uno::RuntimeException;
55cdf0e10cSrcweir     using ::com::sun::star::uno::Sequence;
56cdf0e10cSrcweir     using ::com::sun::star::uno::UNO_QUERY_THROW;
57cdf0e10cSrcweir     using ::com::sun::star::uno::UNO_QUERY;
58cdf0e10cSrcweir     using ::com::sun::star::awt::grid::XGridColumn;
59cdf0e10cSrcweir     using ::com::sun::star::uno::XInterface;
60cdf0e10cSrcweir     using ::com::sun::star::uno::Exception;
61cdf0e10cSrcweir     using ::com::sun::star::awt::grid::XGridColumnListener;
62cdf0e10cSrcweir     using ::com::sun::star::lang::EventObject;
63cdf0e10cSrcweir     using ::com::sun::star::awt::grid::GridColumnEvent;
64cdf0e10cSrcweir     using ::com::sun::star::awt::grid::XGridDataModel;
65cdf0e10cSrcweir     using ::com::sun::star::awt::grid::XGridColumnModel;
66cdf0e10cSrcweir     using ::com::sun::star::uno::Any;
67cdf0e10cSrcweir     using ::com::sun::star::style::HorizontalAlignment_LEFT;
68cdf0e10cSrcweir     using ::com::sun::star::style::HorizontalAlignment;
69cdf0e10cSrcweir     using ::com::sun::star::style::VerticalAlignment_TOP;
70cdf0e10cSrcweir     using ::com::sun::star::style::VerticalAlignment;
71cdf0e10cSrcweir     using ::com::sun::star::uno::WeakReference;
72cdf0e10cSrcweir     using ::com::sun::star::awt::grid::GridDataEvent;
73cdf0e10cSrcweir     using ::com::sun::star::awt::grid::XSortableGridData;
74cdf0e10cSrcweir     using ::com::sun::star::beans::Pair;
75cdf0e10cSrcweir     /** === end UNO using === **/
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	//==================================================================================================================
78cdf0e10cSrcweir 	//= UnoControlTableModel_Impl
79cdf0e10cSrcweir 	//==================================================================================================================
80cdf0e10cSrcweir     typedef ::std::vector< PTableModelListener >    ModellListeners;
81cdf0e10cSrcweir     typedef ::std::vector< PColumnModel >           ColumnModels;
82cdf0e10cSrcweir     struct UnoControlTableModel_Impl
83cdf0e10cSrcweir     {
84cdf0e10cSrcweir         ColumnModels                                    aColumns;
85cdf0e10cSrcweir         bool                                            bHasColumnHeaders;
86cdf0e10cSrcweir         bool                                            bHasRowHeaders;
87cdf0e10cSrcweir         ScrollbarVisibility                             eVScrollMode;
88cdf0e10cSrcweir         ScrollbarVisibility                             eHScrollMode;
89cdf0e10cSrcweir         PTableRenderer                                  pRenderer;
90cdf0e10cSrcweir         PTableInputHandler                              pInputHandler;
91cdf0e10cSrcweir         TableMetrics                                    nRowHeight;
92cdf0e10cSrcweir         TableMetrics                                    nColumnHeaderHeight;
93cdf0e10cSrcweir         TableMetrics                                    nRowHeaderWidth;
94cdf0e10cSrcweir         ::boost::optional< ::Color >                    m_aGridLineColor;
95cdf0e10cSrcweir         ::boost::optional< ::Color >                    m_aHeaderBackgroundColor;
96cdf0e10cSrcweir         ::boost::optional< ::Color >                    m_aHeaderTextColor;
97cdf0e10cSrcweir         ::boost::optional< ::Color >                    m_aActiveSelectionBackColor;
98cdf0e10cSrcweir         ::boost::optional< ::Color >                    m_aInactiveSelectionBackColor;
99cdf0e10cSrcweir         ::boost::optional< ::Color >                    m_aActiveSelectionTextColor;
100cdf0e10cSrcweir         ::boost::optional< ::Color >                    m_aInactiveSelectionTextColor;
101cdf0e10cSrcweir         ::boost::optional< ::Color >                    m_aTextColor;
102cdf0e10cSrcweir         ::boost::optional< ::Color >                    m_aTextLineColor;
103cdf0e10cSrcweir         ::boost::optional< ::std::vector< ::Color > >   m_aRowColors;
104cdf0e10cSrcweir         VerticalAlignment                               m_eVerticalAlign;
105*d5c88d43SJürgen Schmidt         bool                                            bEnabled;
106cdf0e10cSrcweir         ModellListeners                                 m_aListeners;
107cdf0e10cSrcweir         WeakReference< XGridDataModel >                 m_aDataModel;
108cdf0e10cSrcweir         WeakReference< XGridColumnModel >               m_aColumnModel;
109cdf0e10cSrcweir 
UnoControlTableModel_Implsvt::table::UnoControlTableModel_Impl110cdf0e10cSrcweir         UnoControlTableModel_Impl()
111cdf0e10cSrcweir             :aColumns                       ( )
112cdf0e10cSrcweir             ,bHasColumnHeaders              ( true      )
113cdf0e10cSrcweir             ,bHasRowHeaders                 ( false     )
114cdf0e10cSrcweir             ,eVScrollMode                   ( ScrollbarShowNever )
115cdf0e10cSrcweir             ,eHScrollMode                   ( ScrollbarShowNever )
116cdf0e10cSrcweir             ,pRenderer                      ( )
117cdf0e10cSrcweir             ,pInputHandler                  ( )
118cdf0e10cSrcweir             ,nRowHeight                     ( 10 )
119cdf0e10cSrcweir             ,nColumnHeaderHeight            ( 10 )
120cdf0e10cSrcweir             ,nRowHeaderWidth                ( 10 )
121cdf0e10cSrcweir             ,m_aGridLineColor               ( )
122cdf0e10cSrcweir             ,m_aHeaderBackgroundColor       ( )
123cdf0e10cSrcweir             ,m_aHeaderTextColor             ( )
124cdf0e10cSrcweir             ,m_aActiveSelectionBackColor    ( )
125cdf0e10cSrcweir             ,m_aInactiveSelectionBackColor  ( )
126cdf0e10cSrcweir             ,m_aActiveSelectionTextColor    ( )
127cdf0e10cSrcweir             ,m_aInactiveSelectionTextColor  ( )
128cdf0e10cSrcweir             ,m_aTextColor                   ( )
129cdf0e10cSrcweir             ,m_aTextLineColor               ( )
130cdf0e10cSrcweir             ,m_aRowColors                   ( )
131cdf0e10cSrcweir             ,m_eVerticalAlign               ( VerticalAlignment_TOP )
132*d5c88d43SJürgen Schmidt             ,bEnabled                       ( true )
133cdf0e10cSrcweir         {
134cdf0e10cSrcweir         }
135cdf0e10cSrcweir     };
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	//==================================================================================================================
138cdf0e10cSrcweir 	//= UnoControlTableModel
139cdf0e10cSrcweir 	//==================================================================================================================
140cdf0e10cSrcweir #ifdef DBG_UTIL
UnoControlTableModel_checkInvariants(const void * _pInstance)141cdf0e10cSrcweir     const char* UnoControlTableModel_checkInvariants( const void* _pInstance )
142cdf0e10cSrcweir     {
143cdf0e10cSrcweir         return static_cast< const UnoControlTableModel* >( _pInstance )->checkInvariants();
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
checkInvariants() const147cdf0e10cSrcweir     const char* UnoControlTableModel::checkInvariants() const
148cdf0e10cSrcweir     {
149cdf0e10cSrcweir         Reference< XGridDataModel > const xDataModel( m_pImpl->m_aDataModel );
150cdf0e10cSrcweir         if ( !xDataModel.is() )
151cdf0e10cSrcweir             return "data model anymore";
152cdf0e10cSrcweir 
153cdf0e10cSrcweir         // TODO: more?
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         return NULL;
156cdf0e10cSrcweir     }
157cdf0e10cSrcweir #endif
158cdf0e10cSrcweir 
159cdf0e10cSrcweir #define DBG_CHECK_ME() \
160cdf0e10cSrcweir     DBG_TESTSOLARMUTEX(); \
161cdf0e10cSrcweir     DBG_CHKTHIS( UnoControlTableModel, UnoControlTableModel_checkInvariants )
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
DBG_NAME(UnoControlTableModel)164cdf0e10cSrcweir     DBG_NAME( UnoControlTableModel )
165cdf0e10cSrcweir     UnoControlTableModel::UnoControlTableModel()
166cdf0e10cSrcweir         :m_pImpl( new UnoControlTableModel_Impl )
167cdf0e10cSrcweir 	{
168cdf0e10cSrcweir         DBG_CTOR( UnoControlTableModel, UnoControlTableModel_checkInvariants );
169cdf0e10cSrcweir         m_pImpl->bHasColumnHeaders = true;
170cdf0e10cSrcweir         m_pImpl->bHasRowHeaders = false;
171*d5c88d43SJürgen Schmidt         m_pImpl->bEnabled = true;
172cdf0e10cSrcweir         m_pImpl->pRenderer.reset( new GridTableRenderer( *this ) );
173cdf0e10cSrcweir         m_pImpl->pInputHandler.reset( new DefaultInputHandler );
174cdf0e10cSrcweir     }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
~UnoControlTableModel()177cdf0e10cSrcweir     UnoControlTableModel::~UnoControlTableModel()
178cdf0e10cSrcweir     {
179cdf0e10cSrcweir         DBG_DTOR( UnoControlTableModel, UnoControlTableModel_checkInvariants );
180cdf0e10cSrcweir         DELETEZ( m_pImpl );
181cdf0e10cSrcweir     }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
getColumnCount() const184cdf0e10cSrcweir     TableSize UnoControlTableModel::getColumnCount() const
185cdf0e10cSrcweir     {
186cdf0e10cSrcweir         DBG_CHECK_ME();
187cdf0e10cSrcweir 		return (TableSize)m_pImpl->aColumns.size();
188cdf0e10cSrcweir     }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
getRowCount() const191cdf0e10cSrcweir     TableSize UnoControlTableModel::getRowCount() const
192cdf0e10cSrcweir     {
193cdf0e10cSrcweir         DBG_CHECK_ME();
194cdf0e10cSrcweir 
195cdf0e10cSrcweir         TableSize nRowCount = 0;
196cdf0e10cSrcweir         try
197cdf0e10cSrcweir         {
198cdf0e10cSrcweir             Reference< XGridDataModel > const xDataModel( m_pImpl->m_aDataModel );
199cdf0e10cSrcweir             ENSURE_OR_THROW( xDataModel.is(), "no data model anymore!" );
200cdf0e10cSrcweir             nRowCount = xDataModel->getRowCount();
201cdf0e10cSrcweir         }
202cdf0e10cSrcweir         catch( const Exception& )
203cdf0e10cSrcweir         {
204cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
205cdf0e10cSrcweir         }
206cdf0e10cSrcweir         return nRowCount;
207cdf0e10cSrcweir     }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
hasColumnHeaders() const210cdf0e10cSrcweir     bool UnoControlTableModel::hasColumnHeaders() const
211cdf0e10cSrcweir     {
212cdf0e10cSrcweir         DBG_CHECK_ME();
213cdf0e10cSrcweir         return m_pImpl->bHasColumnHeaders;
214cdf0e10cSrcweir     }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
hasRowHeaders() const217cdf0e10cSrcweir     bool UnoControlTableModel::hasRowHeaders() const
218cdf0e10cSrcweir     {
219cdf0e10cSrcweir         DBG_CHECK_ME();
220cdf0e10cSrcweir         return m_pImpl->bHasRowHeaders;
221cdf0e10cSrcweir     }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
setRowHeaders(bool _bRowHeaders)224cdf0e10cSrcweir     void UnoControlTableModel::setRowHeaders(bool _bRowHeaders)
225cdf0e10cSrcweir     {
226cdf0e10cSrcweir         DBG_CHECK_ME();
227cdf0e10cSrcweir         if ( m_pImpl->bHasRowHeaders == _bRowHeaders )
228cdf0e10cSrcweir             return;
229cdf0e10cSrcweir 
230cdf0e10cSrcweir         m_pImpl->bHasRowHeaders = _bRowHeaders;
231cdf0e10cSrcweir         impl_notifyTableMetricsChanged();
232cdf0e10cSrcweir     }
233cdf0e10cSrcweir 
234cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
setColumnHeaders(bool _bColumnHeaders)235cdf0e10cSrcweir     void UnoControlTableModel::setColumnHeaders(bool _bColumnHeaders)
236cdf0e10cSrcweir     {
237cdf0e10cSrcweir         DBG_CHECK_ME();
238cdf0e10cSrcweir         if ( m_pImpl->bHasColumnHeaders == _bColumnHeaders )
239cdf0e10cSrcweir             return;
240cdf0e10cSrcweir 
241cdf0e10cSrcweir         m_pImpl->bHasColumnHeaders = _bColumnHeaders;
242cdf0e10cSrcweir         impl_notifyTableMetricsChanged();
243cdf0e10cSrcweir     }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
isCellEditable(ColPos col,RowPos row) const246cdf0e10cSrcweir     bool UnoControlTableModel::isCellEditable( ColPos col, RowPos row ) const
247cdf0e10cSrcweir     {
248cdf0e10cSrcweir         DBG_CHECK_ME();
249cdf0e10cSrcweir         (void)col;
250cdf0e10cSrcweir         (void)row;
251cdf0e10cSrcweir         return false;
252cdf0e10cSrcweir     }
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
getColumnModel(ColPos column)255cdf0e10cSrcweir     PColumnModel UnoControlTableModel::getColumnModel( ColPos column )
256cdf0e10cSrcweir     {
257cdf0e10cSrcweir         DBG_CHECK_ME();
258cdf0e10cSrcweir         ENSURE_OR_RETURN( ( column >= 0 ) && ( column < getColumnCount() ),
259cdf0e10cSrcweir             "DefaultTableModel::getColumnModel: invalid index!", PColumnModel() );
260cdf0e10cSrcweir         return m_pImpl->aColumns[ column ];
261cdf0e10cSrcweir     }
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
appendColumn(Reference<XGridColumn> const & i_column)264cdf0e10cSrcweir     void UnoControlTableModel::appendColumn( Reference< XGridColumn > const & i_column )
265cdf0e10cSrcweir     {
266cdf0e10cSrcweir         DBG_CHECK_ME();
267cdf0e10cSrcweir         insertColumn( m_pImpl->aColumns.size(), i_column );
268cdf0e10cSrcweir     }
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
insertColumn(ColPos const i_position,Reference<XGridColumn> const & i_column)271cdf0e10cSrcweir     void UnoControlTableModel::insertColumn( ColPos const i_position, Reference< XGridColumn > const & i_column )
272cdf0e10cSrcweir     {
273cdf0e10cSrcweir         DBG_CHECK_ME();
274cdf0e10cSrcweir         ENSURE_OR_RETURN_VOID( ( i_position >= 0 ) && ( size_t( i_position ) <= m_pImpl->aColumns.size() ),
275cdf0e10cSrcweir             "UnoControlTableModel::insertColumn: illegal position!" );
276cdf0e10cSrcweir 
277cdf0e10cSrcweir         const PColumnModel pColumn( new UnoGridColumnFacade( *this, i_column ) );
278cdf0e10cSrcweir         m_pImpl->aColumns.insert( m_pImpl->aColumns.begin() + i_position, pColumn );
279cdf0e10cSrcweir 
280cdf0e10cSrcweir         // notify listeners
281cdf0e10cSrcweir         ModellListeners aListeners( m_pImpl->m_aListeners );
282cdf0e10cSrcweir         for (   ModellListeners::const_iterator loop = aListeners.begin();
283cdf0e10cSrcweir                 loop != aListeners.end();
284cdf0e10cSrcweir                 ++loop
285cdf0e10cSrcweir             )
286cdf0e10cSrcweir         {
287cdf0e10cSrcweir             (*loop)->columnInserted( i_position );
288cdf0e10cSrcweir         }
289cdf0e10cSrcweir     }
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
removeColumn(ColPos const i_position)292cdf0e10cSrcweir     void UnoControlTableModel::removeColumn( ColPos const i_position )
293cdf0e10cSrcweir     {
294cdf0e10cSrcweir         DBG_CHECK_ME();
295cdf0e10cSrcweir         ENSURE_OR_RETURN_VOID( ( i_position >= 0 ) && ( size_t( i_position ) <= m_pImpl->aColumns.size() ),
296cdf0e10cSrcweir             "UnoControlTableModel::removeColumn: illegal position!" );
297cdf0e10cSrcweir 
298cdf0e10cSrcweir         // remove the column
299cdf0e10cSrcweir         ColumnModels::iterator pos = m_pImpl->aColumns.begin() + i_position;
300cdf0e10cSrcweir         const PColumnModel pColumn = *pos;
301cdf0e10cSrcweir         m_pImpl->aColumns.erase( pos );
302cdf0e10cSrcweir 
303cdf0e10cSrcweir         // notify listeners
304cdf0e10cSrcweir         ModellListeners aListeners( m_pImpl->m_aListeners );
305cdf0e10cSrcweir         for (   ModellListeners::const_iterator loop = aListeners.begin();
306cdf0e10cSrcweir                 loop != aListeners.end();
307cdf0e10cSrcweir                 ++loop
308cdf0e10cSrcweir             )
309cdf0e10cSrcweir         {
310cdf0e10cSrcweir             (*loop)->columnRemoved( i_position );
311cdf0e10cSrcweir         }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir         // dispose the column
314cdf0e10cSrcweir         UnoGridColumnFacade* pColumnImpl = dynamic_cast< UnoGridColumnFacade* >( pColumn.get() );
315cdf0e10cSrcweir         OSL_ENSURE( pColumnImpl != NULL, "UnoControlTableModel::removeColumn: illegal column implementation!" );
316cdf0e10cSrcweir         if ( pColumnImpl )
317cdf0e10cSrcweir             pColumnImpl->dispose();
318cdf0e10cSrcweir     }
319cdf0e10cSrcweir 
320cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
removeAllColumns()321cdf0e10cSrcweir     void UnoControlTableModel::removeAllColumns()
322cdf0e10cSrcweir     {
323cdf0e10cSrcweir         DBG_CHECK_ME();
324cdf0e10cSrcweir         if ( m_pImpl->aColumns.empty() )
325cdf0e10cSrcweir             return;
326cdf0e10cSrcweir 
327cdf0e10cSrcweir         // dispose the column instances
328cdf0e10cSrcweir         for (   ColumnModels::const_iterator col = m_pImpl->aColumns.begin();
329cdf0e10cSrcweir                 col != m_pImpl->aColumns.end();
330cdf0e10cSrcweir                 ++col
331cdf0e10cSrcweir             )
332cdf0e10cSrcweir         {
333cdf0e10cSrcweir             UnoGridColumnFacade* pColumn = dynamic_cast< UnoGridColumnFacade* >( col->get() );
334cdf0e10cSrcweir             ENSURE_OR_CONTINUE( pColumn != NULL, "UnoControlTableModel::removeAllColumns: illegal column implementation!" );
335cdf0e10cSrcweir             pColumn->dispose();
336cdf0e10cSrcweir         }
337cdf0e10cSrcweir         m_pImpl->aColumns.clear();
338cdf0e10cSrcweir 
339cdf0e10cSrcweir         // notify listeners
340cdf0e10cSrcweir         ModellListeners aListeners( m_pImpl->m_aListeners );
341cdf0e10cSrcweir         for (   ModellListeners::const_iterator loop = aListeners.begin();
342cdf0e10cSrcweir                 loop != aListeners.end();
343cdf0e10cSrcweir                 ++loop
344cdf0e10cSrcweir             )
345cdf0e10cSrcweir         {
346cdf0e10cSrcweir             (*loop)->allColumnsRemoved();
347cdf0e10cSrcweir         }
348cdf0e10cSrcweir     }
349cdf0e10cSrcweir 
350cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
impl_notifyTableMetricsChanged() const351cdf0e10cSrcweir     void UnoControlTableModel::impl_notifyTableMetricsChanged() const
352cdf0e10cSrcweir     {
353cdf0e10cSrcweir         ModellListeners aListeners( m_pImpl->m_aListeners );
354cdf0e10cSrcweir         for (   ModellListeners::const_iterator loop = aListeners.begin();
355cdf0e10cSrcweir                 loop != aListeners.end();
356cdf0e10cSrcweir                 ++loop
357cdf0e10cSrcweir             )
358cdf0e10cSrcweir         {
359cdf0e10cSrcweir             (*loop)->tableMetricsChanged();
360cdf0e10cSrcweir         }
361cdf0e10cSrcweir     }
362cdf0e10cSrcweir 
363cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getRenderer() const364cdf0e10cSrcweir     PTableRenderer UnoControlTableModel::getRenderer() const
365cdf0e10cSrcweir     {
366cdf0e10cSrcweir         DBG_CHECK_ME();
367cdf0e10cSrcweir         return m_pImpl->pRenderer;
368cdf0e10cSrcweir     }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getInputHandler() const371cdf0e10cSrcweir     PTableInputHandler UnoControlTableModel::getInputHandler() const
372cdf0e10cSrcweir     {
373cdf0e10cSrcweir         DBG_CHECK_ME();
374cdf0e10cSrcweir         return m_pImpl->pInputHandler;
375cdf0e10cSrcweir     }
376cdf0e10cSrcweir 
377cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getRowHeight() const378cdf0e10cSrcweir     TableMetrics UnoControlTableModel::getRowHeight() const
379cdf0e10cSrcweir     {
380cdf0e10cSrcweir         DBG_CHECK_ME();
381cdf0e10cSrcweir         return m_pImpl->nRowHeight;
382cdf0e10cSrcweir     }
383cdf0e10cSrcweir 
384cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
setRowHeight(TableMetrics _nRowHeight)385cdf0e10cSrcweir     void UnoControlTableModel::setRowHeight(TableMetrics _nRowHeight)
386cdf0e10cSrcweir     {
387cdf0e10cSrcweir         DBG_CHECK_ME();
388cdf0e10cSrcweir         if ( m_pImpl->nRowHeight == _nRowHeight )
389cdf0e10cSrcweir             return;
390cdf0e10cSrcweir 
391cdf0e10cSrcweir         m_pImpl->nRowHeight = _nRowHeight;
392cdf0e10cSrcweir         impl_notifyTableMetricsChanged();
393cdf0e10cSrcweir     }
394cdf0e10cSrcweir 
395cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getColumnHeaderHeight() const396cdf0e10cSrcweir     TableMetrics UnoControlTableModel::getColumnHeaderHeight() const
397cdf0e10cSrcweir     {
398cdf0e10cSrcweir         DBG_CHECK_ME();
399cdf0e10cSrcweir         DBG_ASSERT( hasColumnHeaders(), "DefaultTableModel::getColumnHeaderHeight: invalid call!" );
400cdf0e10cSrcweir         return m_pImpl->nColumnHeaderHeight;
401cdf0e10cSrcweir     }
402cdf0e10cSrcweir 
403cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getRowHeaderWidth() const404cdf0e10cSrcweir     TableMetrics UnoControlTableModel::getRowHeaderWidth() const
405cdf0e10cSrcweir     {
406cdf0e10cSrcweir         DBG_CHECK_ME();
407cdf0e10cSrcweir         DBG_ASSERT( hasRowHeaders(), "DefaultTableModel::getRowHeaderWidth: invalid call!" );
408cdf0e10cSrcweir         return m_pImpl->nRowHeaderWidth;
409cdf0e10cSrcweir     }
410cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
setColumnHeaderHeight(TableMetrics _nHeight)411cdf0e10cSrcweir     void UnoControlTableModel::setColumnHeaderHeight(TableMetrics _nHeight)
412cdf0e10cSrcweir     {
413cdf0e10cSrcweir         DBG_CHECK_ME();
414cdf0e10cSrcweir         if ( m_pImpl->nColumnHeaderHeight == _nHeight )
415cdf0e10cSrcweir             return;
416cdf0e10cSrcweir 
417cdf0e10cSrcweir         m_pImpl->nColumnHeaderHeight = _nHeight;
418cdf0e10cSrcweir         impl_notifyTableMetricsChanged();
419cdf0e10cSrcweir     }
420cdf0e10cSrcweir 
421cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
setRowHeaderWidth(TableMetrics _nWidth)422cdf0e10cSrcweir     void UnoControlTableModel::setRowHeaderWidth(TableMetrics _nWidth)
423cdf0e10cSrcweir     {
424cdf0e10cSrcweir         DBG_CHECK_ME();
425cdf0e10cSrcweir         if ( m_pImpl->nRowHeaderWidth == _nWidth )
426cdf0e10cSrcweir             return;
427cdf0e10cSrcweir 
428cdf0e10cSrcweir         m_pImpl->nRowHeaderWidth = _nWidth;
429cdf0e10cSrcweir         impl_notifyTableMetricsChanged();
430cdf0e10cSrcweir     }
431cdf0e10cSrcweir 
432cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getVerticalScrollbarVisibility() const433cdf0e10cSrcweir     ScrollbarVisibility UnoControlTableModel::getVerticalScrollbarVisibility() const
434cdf0e10cSrcweir     {
435cdf0e10cSrcweir         DBG_CHECK_ME();
436cdf0e10cSrcweir         return m_pImpl->eVScrollMode;
437cdf0e10cSrcweir     }
438cdf0e10cSrcweir 
439cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getHorizontalScrollbarVisibility() const440cdf0e10cSrcweir     ScrollbarVisibility UnoControlTableModel::getHorizontalScrollbarVisibility() const
441cdf0e10cSrcweir     {
442cdf0e10cSrcweir         DBG_CHECK_ME();
443cdf0e10cSrcweir         return m_pImpl->eHScrollMode;
444cdf0e10cSrcweir     }
445cdf0e10cSrcweir 
446cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
addTableModelListener(const PTableModelListener & i_listener)447cdf0e10cSrcweir     void UnoControlTableModel::addTableModelListener( const PTableModelListener& i_listener )
448cdf0e10cSrcweir     {
449cdf0e10cSrcweir         DBG_CHECK_ME();
450cdf0e10cSrcweir         ENSURE_OR_RETURN_VOID( !!i_listener, "illegal NULL listener" );
451cdf0e10cSrcweir         m_pImpl->m_aListeners.push_back( i_listener );
452cdf0e10cSrcweir     }
453cdf0e10cSrcweir 
454cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
removeTableModelListener(const PTableModelListener & i_listener)455cdf0e10cSrcweir     void UnoControlTableModel::removeTableModelListener( const PTableModelListener& i_listener )
456cdf0e10cSrcweir     {
457cdf0e10cSrcweir         DBG_CHECK_ME();
458cdf0e10cSrcweir         for (   ModellListeners::iterator lookup = m_pImpl->m_aListeners.begin();
459cdf0e10cSrcweir                 lookup != m_pImpl->m_aListeners.end();
460cdf0e10cSrcweir                 ++lookup
461cdf0e10cSrcweir             )
462cdf0e10cSrcweir         {
463cdf0e10cSrcweir             if ( *lookup == i_listener )
464cdf0e10cSrcweir             {
465cdf0e10cSrcweir                 m_pImpl->m_aListeners.erase( lookup );
466cdf0e10cSrcweir                 return;
467cdf0e10cSrcweir             }
468cdf0e10cSrcweir         }
469cdf0e10cSrcweir         OSL_ENSURE( false, "UnoControlTableModel::removeTableModelListener: listener is not registered - sure you're doing the right thing here?" );
470cdf0e10cSrcweir     }
471cdf0e10cSrcweir 
472cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
setVerticalScrollbarVisibility(ScrollbarVisibility const i_visibility) const473cdf0e10cSrcweir     void UnoControlTableModel::setVerticalScrollbarVisibility( ScrollbarVisibility const i_visibility ) const
474cdf0e10cSrcweir     {
475cdf0e10cSrcweir         DBG_CHECK_ME();
476cdf0e10cSrcweir 		m_pImpl->eVScrollMode = i_visibility;
477cdf0e10cSrcweir     }
478cdf0e10cSrcweir 
479cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
setHorizontalScrollbarVisibility(ScrollbarVisibility const i_visibility) const480cdf0e10cSrcweir     void UnoControlTableModel::setHorizontalScrollbarVisibility( ScrollbarVisibility const i_visibility ) const
481cdf0e10cSrcweir     {
482cdf0e10cSrcweir         DBG_CHECK_ME();
483cdf0e10cSrcweir 		m_pImpl->eHScrollMode = i_visibility;
484cdf0e10cSrcweir     }
485cdf0e10cSrcweir 
486cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
setDataModel(Reference<XGridDataModel> const & i_gridDataModel)487cdf0e10cSrcweir     void UnoControlTableModel::setDataModel( Reference< XGridDataModel > const & i_gridDataModel )
488cdf0e10cSrcweir     {
489cdf0e10cSrcweir         DBG_CHECK_ME();
490cdf0e10cSrcweir         m_pImpl->m_aDataModel = i_gridDataModel;
491cdf0e10cSrcweir         // TODO: register as listener, so we're notified of row/data changes, and can multiplex them to our
492cdf0e10cSrcweir         // own listeners
493cdf0e10cSrcweir     }
494cdf0e10cSrcweir 
495cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getDataModel() const496cdf0e10cSrcweir     Reference< XGridDataModel > UnoControlTableModel::getDataModel() const
497cdf0e10cSrcweir     {
498cdf0e10cSrcweir         Reference< XGridDataModel > const xDataModel( m_pImpl->m_aDataModel );
499cdf0e10cSrcweir         return xDataModel;
500cdf0e10cSrcweir     }
501cdf0e10cSrcweir 
502cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
hasDataModel() const503cdf0e10cSrcweir     bool UnoControlTableModel::hasDataModel() const
504cdf0e10cSrcweir     {
505cdf0e10cSrcweir         return getDataModel().is();
506cdf0e10cSrcweir     }
507cdf0e10cSrcweir 
508cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
setColumnModel(Reference<XGridColumnModel> const & i_gridColumnModel)509cdf0e10cSrcweir     void UnoControlTableModel::setColumnModel( Reference< XGridColumnModel > const & i_gridColumnModel )
510cdf0e10cSrcweir     {
511cdf0e10cSrcweir         DBG_CHECK_ME();
512cdf0e10cSrcweir         m_pImpl->m_aColumnModel = i_gridColumnModel;
513cdf0e10cSrcweir     }
514cdf0e10cSrcweir 
515cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getColumnModel() const516cdf0e10cSrcweir     Reference< XGridColumnModel > UnoControlTableModel::getColumnModel() const
517cdf0e10cSrcweir     {
518cdf0e10cSrcweir         Reference< XGridColumnModel > const xColumnModel( m_pImpl->m_aColumnModel );
519cdf0e10cSrcweir         return xColumnModel;
520cdf0e10cSrcweir     }
521cdf0e10cSrcweir 
522cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
hasColumnModel() const523cdf0e10cSrcweir     bool UnoControlTableModel::hasColumnModel() const
524cdf0e10cSrcweir     {
525cdf0e10cSrcweir         return getColumnModel().is();
526cdf0e10cSrcweir     }
527cdf0e10cSrcweir 
528cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getCellContent(ColPos const i_col,RowPos const i_row,Any & o_cellContent)529cdf0e10cSrcweir     void UnoControlTableModel::getCellContent( ColPos const i_col, RowPos const i_row, Any& o_cellContent )
530cdf0e10cSrcweir     {
531cdf0e10cSrcweir         DBG_CHECK_ME();
532cdf0e10cSrcweir 
533cdf0e10cSrcweir         o_cellContent.clear();
534cdf0e10cSrcweir         try
535cdf0e10cSrcweir         {
536cdf0e10cSrcweir             Reference< XGridDataModel > const xDataModel( m_pImpl->m_aDataModel );
537cdf0e10cSrcweir             ENSURE_OR_RETURN_VOID( xDataModel.is(), "UnoControlTableModel::getCellContent: no data model anymore!" );
538cdf0e10cSrcweir 
539cdf0e10cSrcweir             PColumnModel const pColumn = getColumnModel( i_col );
540cdf0e10cSrcweir             UnoGridColumnFacade* pColumnImpl = dynamic_cast< UnoGridColumnFacade* >( pColumn.get() );
541cdf0e10cSrcweir             ENSURE_OR_RETURN_VOID( pColumnImpl != NULL, "UnoControlTableModel::getCellContent: no (valid) column at this position!" );
542cdf0e10cSrcweir             sal_Int32 const nDataColumnIndex = pColumnImpl->getDataColumnIndex() >= 0 ? pColumnImpl->getDataColumnIndex() : i_col;
543cdf0e10cSrcweir 
544cdf0e10cSrcweir             if ( nDataColumnIndex >= xDataModel->getColumnCount() )
545cdf0e10cSrcweir             {
546cdf0e10cSrcweir                 // this is allowed, in case the column model has been dynamically extended, but the data model does
547cdf0e10cSrcweir                 // not (yet?) know about it.
548cdf0e10cSrcweir                 // So, handle it gracefully.
549cdf0e10cSrcweir             #if OSL_DEBUG_LEVEL > 0
550cdf0e10cSrcweir                 {
551cdf0e10cSrcweir                     Reference< XGridColumnModel > const xColumnModel( m_pImpl->m_aColumnModel );
552cdf0e10cSrcweir                     OSL_ENSURE( xColumnModel.is() && i_col < xColumnModel->getColumnCount(),
553cdf0e10cSrcweir                         "UnoControlTableModel::getCellContent: request a column's value which the ColumnModel doesn't know about!" );
554cdf0e10cSrcweir                 }
555cdf0e10cSrcweir             #endif
556cdf0e10cSrcweir             }
557cdf0e10cSrcweir             else
558cdf0e10cSrcweir             {
559cdf0e10cSrcweir                 o_cellContent = xDataModel->getCellData( nDataColumnIndex, i_row );
560cdf0e10cSrcweir             }
561cdf0e10cSrcweir         }
562cdf0e10cSrcweir         catch( const Exception& )
563cdf0e10cSrcweir         {
564cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
565cdf0e10cSrcweir         }
566cdf0e10cSrcweir     }
567cdf0e10cSrcweir 
568cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getCellToolTip(ColPos const i_col,RowPos const i_row,Any & o_cellToolTip)569cdf0e10cSrcweir     void UnoControlTableModel::getCellToolTip( ColPos const i_col, RowPos const i_row, Any& o_cellToolTip )
570cdf0e10cSrcweir     {
571cdf0e10cSrcweir         DBG_CHECK_ME();
572cdf0e10cSrcweir         try
573cdf0e10cSrcweir         {
574cdf0e10cSrcweir             Reference< XGridDataModel > const xDataModel( m_pImpl->m_aDataModel );
575cdf0e10cSrcweir             ENSURE_OR_THROW( xDataModel.is(), "no data model anymore!" );
576cdf0e10cSrcweir 
577cdf0e10cSrcweir             o_cellToolTip = xDataModel->getCellToolTip( i_col, i_row );
578cdf0e10cSrcweir         }
579cdf0e10cSrcweir         catch( const Exception& )
580cdf0e10cSrcweir         {
581cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
582cdf0e10cSrcweir         }
583cdf0e10cSrcweir     }
584cdf0e10cSrcweir 
585cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getRowHeading(RowPos const i_rowPos) const586cdf0e10cSrcweir     Any UnoControlTableModel::getRowHeading( RowPos const i_rowPos ) const
587cdf0e10cSrcweir     {
588cdf0e10cSrcweir         DBG_CHECK_ME();
589cdf0e10cSrcweir 
590cdf0e10cSrcweir         Any aRowHeading;
591cdf0e10cSrcweir 
592cdf0e10cSrcweir         Reference< XGridDataModel > const xDataModel( m_pImpl->m_aDataModel );
593cdf0e10cSrcweir         ENSURE_OR_RETURN( xDataModel.is(), "UnoControlTableModel::getRowHeading: no data model anymore!", aRowHeading );
594cdf0e10cSrcweir 
595cdf0e10cSrcweir         try
596cdf0e10cSrcweir         {
597cdf0e10cSrcweir             aRowHeading = xDataModel->getRowHeading( i_rowPos );
598cdf0e10cSrcweir         }
599cdf0e10cSrcweir         catch( const Exception& )
600cdf0e10cSrcweir         {
601cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
602cdf0e10cSrcweir         }
603cdf0e10cSrcweir         return aRowHeading;
604cdf0e10cSrcweir     }
605cdf0e10cSrcweir 
606cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
607cdf0e10cSrcweir     namespace
608cdf0e10cSrcweir     {
lcl_setColor(Any const & i_color,::boost::optional<::Color> & o_convertedColor)609cdf0e10cSrcweir         void lcl_setColor( Any const & i_color, ::boost::optional< ::Color > & o_convertedColor )
610cdf0e10cSrcweir         {
611cdf0e10cSrcweir             if ( !i_color.hasValue() )
612cdf0e10cSrcweir                 o_convertedColor.reset();
613cdf0e10cSrcweir             else
614cdf0e10cSrcweir             {
615cdf0e10cSrcweir                 sal_Int32 nColor = COL_TRANSPARENT;
616cdf0e10cSrcweir                 if ( i_color >>= nColor )
617cdf0e10cSrcweir                 {
618cdf0e10cSrcweir                     o_convertedColor.reset( ::Color( nColor ) );
619cdf0e10cSrcweir                 }
620cdf0e10cSrcweir                 else
621cdf0e10cSrcweir                 {
622cdf0e10cSrcweir                     OSL_ENSURE( false, "lcl_setColor: could not extract color value!" );
623cdf0e10cSrcweir                 }
624cdf0e10cSrcweir             }
625cdf0e10cSrcweir         }
626cdf0e10cSrcweir     }
627cdf0e10cSrcweir 
628cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getLineColor() const629cdf0e10cSrcweir     ::boost::optional< ::Color > UnoControlTableModel::getLineColor() const
630cdf0e10cSrcweir     {
631cdf0e10cSrcweir         DBG_CHECK_ME();
632cdf0e10cSrcweir         return m_pImpl->m_aGridLineColor;
633cdf0e10cSrcweir     }
634cdf0e10cSrcweir 
635cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
setLineColor(Any const & i_color)636cdf0e10cSrcweir     void UnoControlTableModel::setLineColor( Any const & i_color )
637cdf0e10cSrcweir     {
638cdf0e10cSrcweir         DBG_CHECK_ME();
639cdf0e10cSrcweir         lcl_setColor( i_color, m_pImpl->m_aGridLineColor );
640cdf0e10cSrcweir     }
641cdf0e10cSrcweir 
642cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getHeaderBackgroundColor() const643cdf0e10cSrcweir     ::boost::optional< ::Color > UnoControlTableModel::getHeaderBackgroundColor() const
644cdf0e10cSrcweir     {
645cdf0e10cSrcweir         DBG_CHECK_ME();
646cdf0e10cSrcweir         return m_pImpl->m_aHeaderBackgroundColor;
647cdf0e10cSrcweir     }
648cdf0e10cSrcweir 
649cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
setHeaderBackgroundColor(Any const & i_color)650cdf0e10cSrcweir     void UnoControlTableModel::setHeaderBackgroundColor( Any const & i_color )
651cdf0e10cSrcweir     {
652cdf0e10cSrcweir         DBG_CHECK_ME();
653cdf0e10cSrcweir         lcl_setColor( i_color, m_pImpl->m_aHeaderBackgroundColor );
654cdf0e10cSrcweir     }
655cdf0e10cSrcweir 
656cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getHeaderTextColor() const657cdf0e10cSrcweir     ::boost::optional< ::Color > UnoControlTableModel::getHeaderTextColor() const
658cdf0e10cSrcweir     {
659cdf0e10cSrcweir         DBG_CHECK_ME();
660cdf0e10cSrcweir         return m_pImpl->m_aHeaderTextColor;
661cdf0e10cSrcweir     }
662cdf0e10cSrcweir 
663cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getActiveSelectionBackColor() const664cdf0e10cSrcweir     ::boost::optional< ::Color > UnoControlTableModel::getActiveSelectionBackColor() const
665cdf0e10cSrcweir     {
666cdf0e10cSrcweir         DBG_CHECK_ME();
667cdf0e10cSrcweir         return m_pImpl->m_aActiveSelectionBackColor;
668cdf0e10cSrcweir     }
669cdf0e10cSrcweir 
670cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getInactiveSelectionBackColor() const671cdf0e10cSrcweir     ::boost::optional< ::Color > UnoControlTableModel::getInactiveSelectionBackColor() const
672cdf0e10cSrcweir     {
673cdf0e10cSrcweir         DBG_CHECK_ME();
674cdf0e10cSrcweir         return m_pImpl->m_aInactiveSelectionBackColor;
675cdf0e10cSrcweir     }
676cdf0e10cSrcweir 
677cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getActiveSelectionTextColor() const678cdf0e10cSrcweir     ::boost::optional< ::Color > UnoControlTableModel::getActiveSelectionTextColor() const
679cdf0e10cSrcweir     {
680cdf0e10cSrcweir         DBG_CHECK_ME();
681cdf0e10cSrcweir         return m_pImpl->m_aActiveSelectionTextColor;
682cdf0e10cSrcweir     }
683cdf0e10cSrcweir 
684cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getInactiveSelectionTextColor() const685cdf0e10cSrcweir     ::boost::optional< ::Color > UnoControlTableModel::getInactiveSelectionTextColor() const
686cdf0e10cSrcweir     {
687cdf0e10cSrcweir         DBG_CHECK_ME();
688cdf0e10cSrcweir         return m_pImpl->m_aInactiveSelectionTextColor;
689cdf0e10cSrcweir     }
690cdf0e10cSrcweir 
691cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
setHeaderTextColor(Any const & i_color)692cdf0e10cSrcweir     void UnoControlTableModel::setHeaderTextColor( Any const & i_color )
693cdf0e10cSrcweir     {
694cdf0e10cSrcweir         DBG_CHECK_ME();
695cdf0e10cSrcweir         lcl_setColor( i_color, m_pImpl->m_aHeaderTextColor );
696cdf0e10cSrcweir     }
697cdf0e10cSrcweir 
698cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
setActiveSelectionBackColor(Any const & i_color)699cdf0e10cSrcweir     void UnoControlTableModel::setActiveSelectionBackColor( Any const & i_color )
700cdf0e10cSrcweir     {
701cdf0e10cSrcweir         DBG_CHECK_ME();
702cdf0e10cSrcweir         lcl_setColor( i_color, m_pImpl->m_aActiveSelectionBackColor );
703cdf0e10cSrcweir     }
704cdf0e10cSrcweir 
705cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
setInactiveSelectionBackColor(Any const & i_color)706cdf0e10cSrcweir     void UnoControlTableModel::setInactiveSelectionBackColor( Any const & i_color )
707cdf0e10cSrcweir     {
708cdf0e10cSrcweir         DBG_CHECK_ME();
709cdf0e10cSrcweir         lcl_setColor( i_color, m_pImpl->m_aInactiveSelectionBackColor );
710cdf0e10cSrcweir     }
711cdf0e10cSrcweir 
712cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
setActiveSelectionTextColor(Any const & i_color)713cdf0e10cSrcweir     void UnoControlTableModel::setActiveSelectionTextColor( Any const & i_color )
714cdf0e10cSrcweir     {
715cdf0e10cSrcweir         DBG_CHECK_ME();
716cdf0e10cSrcweir         lcl_setColor( i_color, m_pImpl->m_aActiveSelectionTextColor );
717cdf0e10cSrcweir     }
718cdf0e10cSrcweir 
719cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
setInactiveSelectionTextColor(Any const & i_color)720cdf0e10cSrcweir     void UnoControlTableModel::setInactiveSelectionTextColor( Any const & i_color )
721cdf0e10cSrcweir     {
722cdf0e10cSrcweir         DBG_CHECK_ME();
723cdf0e10cSrcweir         lcl_setColor( i_color, m_pImpl->m_aInactiveSelectionTextColor );
724cdf0e10cSrcweir     }
725cdf0e10cSrcweir 
726cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getTextColor() const727cdf0e10cSrcweir     ::boost::optional< ::Color > UnoControlTableModel::getTextColor() const
728cdf0e10cSrcweir     {
729cdf0e10cSrcweir         DBG_CHECK_ME();
730cdf0e10cSrcweir         return m_pImpl->m_aTextColor;
731cdf0e10cSrcweir     }
732cdf0e10cSrcweir 
733cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
setTextColor(Any const & i_color)734cdf0e10cSrcweir     void UnoControlTableModel::setTextColor( Any const & i_color )
735cdf0e10cSrcweir     {
736cdf0e10cSrcweir         DBG_CHECK_ME();
737cdf0e10cSrcweir         lcl_setColor( i_color, m_pImpl->m_aTextColor );
738cdf0e10cSrcweir     }
739cdf0e10cSrcweir 
740cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getTextLineColor() const741cdf0e10cSrcweir     ::boost::optional< ::Color > UnoControlTableModel::getTextLineColor() const
742cdf0e10cSrcweir     {
743cdf0e10cSrcweir         DBG_CHECK_ME();
744cdf0e10cSrcweir         return m_pImpl->m_aTextColor;
745cdf0e10cSrcweir     }
746cdf0e10cSrcweir 
747cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
setTextLineColor(Any const & i_color)748cdf0e10cSrcweir     void UnoControlTableModel::setTextLineColor( Any const & i_color )
749cdf0e10cSrcweir     {
750cdf0e10cSrcweir         DBG_CHECK_ME();
751cdf0e10cSrcweir         lcl_setColor( i_color, m_pImpl->m_aTextLineColor );
752cdf0e10cSrcweir     }
753cdf0e10cSrcweir 
754cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getRowBackgroundColors() const755cdf0e10cSrcweir     ::boost::optional< ::std::vector< ::Color > > UnoControlTableModel::getRowBackgroundColors() const
756cdf0e10cSrcweir     {
757cdf0e10cSrcweir         DBG_CHECK_ME();
758cdf0e10cSrcweir         return m_pImpl->m_aRowColors;
759cdf0e10cSrcweir     }
760cdf0e10cSrcweir 
761cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
setRowBackgroundColors(::com::sun::star::uno::Any const & i_APIValue)762cdf0e10cSrcweir     void UnoControlTableModel::setRowBackgroundColors( ::com::sun::star::uno::Any const & i_APIValue )
763cdf0e10cSrcweir     {
764cdf0e10cSrcweir         DBG_CHECK_ME();
765cdf0e10cSrcweir         Sequence< ::com::sun::star::util::Color > aAPIColors;
766cdf0e10cSrcweir         if ( !( i_APIValue >>= aAPIColors ) )
767cdf0e10cSrcweir             m_pImpl->m_aRowColors.reset();
768cdf0e10cSrcweir         else
769cdf0e10cSrcweir         {
770cdf0e10cSrcweir             ::std::vector< ::Color > aColors( aAPIColors.getLength() );
771cdf0e10cSrcweir             for ( sal_Int32 i=0; i<aAPIColors.getLength(); ++i )
772cdf0e10cSrcweir             {
773cdf0e10cSrcweir                 aColors[i] = ::Color( aAPIColors[i] );
774cdf0e10cSrcweir             }
775cdf0e10cSrcweir             m_pImpl->m_aRowColors.reset( aColors );
776cdf0e10cSrcweir         }
777cdf0e10cSrcweir     }
778cdf0e10cSrcweir 
779cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getVerticalAlign() const780cdf0e10cSrcweir     VerticalAlignment UnoControlTableModel::getVerticalAlign() const
781cdf0e10cSrcweir     {
782cdf0e10cSrcweir         DBG_CHECK_ME();
783cdf0e10cSrcweir         return  m_pImpl->m_eVerticalAlign;
784cdf0e10cSrcweir     }
785cdf0e10cSrcweir 
786cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
setVerticalAlign(VerticalAlignment _xAlign)787cdf0e10cSrcweir     void UnoControlTableModel::setVerticalAlign( VerticalAlignment _xAlign )
788cdf0e10cSrcweir     {
789cdf0e10cSrcweir         DBG_CHECK_ME();
790cdf0e10cSrcweir         m_pImpl->m_eVerticalAlign = _xAlign;
791cdf0e10cSrcweir     }
792cdf0e10cSrcweir 
793cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getColumnPos(UnoGridColumnFacade const & i_column) const794cdf0e10cSrcweir     ColPos UnoControlTableModel::getColumnPos( UnoGridColumnFacade const & i_column ) const
795cdf0e10cSrcweir     {
796cdf0e10cSrcweir         DBG_CHECK_ME();
797cdf0e10cSrcweir         for (   ColumnModels::const_iterator col = m_pImpl->aColumns.begin();
798cdf0e10cSrcweir                 col != m_pImpl->aColumns.end();
799cdf0e10cSrcweir                 ++col
800cdf0e10cSrcweir             )
801cdf0e10cSrcweir         {
802cdf0e10cSrcweir             if ( &i_column == col->get() )
803cdf0e10cSrcweir                 return col - m_pImpl->aColumns.begin();
804cdf0e10cSrcweir         }
805cdf0e10cSrcweir         OSL_ENSURE( false, "UnoControlTableModel::getColumnPos: column not found!" );
806cdf0e10cSrcweir         return COL_INVALID;
807cdf0e10cSrcweir     }
808cdf0e10cSrcweir 
809cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getSortAdapter()810cdf0e10cSrcweir     ITableDataSort* UnoControlTableModel::getSortAdapter()
811cdf0e10cSrcweir     {
812cdf0e10cSrcweir         DBG_CHECK_ME();
813cdf0e10cSrcweir 
814cdf0e10cSrcweir         Reference< XSortableGridData > const xSortAccess( getDataModel(), UNO_QUERY );
815cdf0e10cSrcweir         if ( xSortAccess.is() )
816cdf0e10cSrcweir             return this;
817cdf0e10cSrcweir         return NULL;
818cdf0e10cSrcweir     }
819*d5c88d43SJürgen Schmidt 
820*d5c88d43SJürgen Schmidt     //------------------------------------------------------------------------------------------------------------------
isEnabled() const821*d5c88d43SJürgen Schmidt     bool UnoControlTableModel::isEnabled() const
822*d5c88d43SJürgen Schmidt     {
823*d5c88d43SJürgen Schmidt         DBG_CHECK_ME();
824*d5c88d43SJürgen Schmidt         return m_pImpl->bEnabled;
825*d5c88d43SJürgen Schmidt     }
826*d5c88d43SJürgen Schmidt 
827*d5c88d43SJürgen Schmidt     //------------------------------------------------------------------------------------------------------------------
setEnabled(bool _bEnabled)828*d5c88d43SJürgen Schmidt     void UnoControlTableModel::setEnabled( bool _bEnabled )
829*d5c88d43SJürgen Schmidt     {
830*d5c88d43SJürgen Schmidt         DBG_CHECK_ME();
831*d5c88d43SJürgen Schmidt         m_pImpl->bEnabled = _bEnabled;
832*d5c88d43SJürgen Schmidt     }
833cdf0e10cSrcweir 
834cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
sortByColumn(ColPos const i_column,ColumnSortDirection const i_sortDirection)835cdf0e10cSrcweir     void UnoControlTableModel::sortByColumn( ColPos const i_column, ColumnSortDirection const i_sortDirection )
836cdf0e10cSrcweir     {
837cdf0e10cSrcweir         DBG_CHECK_ME();
838cdf0e10cSrcweir 
839cdf0e10cSrcweir         try
840cdf0e10cSrcweir         {
841cdf0e10cSrcweir             Reference< XSortableGridData > const xSortAccess( getDataModel(), UNO_QUERY_THROW );
842cdf0e10cSrcweir             xSortAccess->sortByColumn( i_column, i_sortDirection == ColumnSortAscending );
843cdf0e10cSrcweir         }
844cdf0e10cSrcweir         catch( const Exception& )
845cdf0e10cSrcweir         {
846cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
847cdf0e10cSrcweir         }
848cdf0e10cSrcweir     }
849cdf0e10cSrcweir 
850cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getCurrentSortOrder() const851cdf0e10cSrcweir     ColumnSort UnoControlTableModel::getCurrentSortOrder() const
852cdf0e10cSrcweir     {
853cdf0e10cSrcweir         DBG_CHECK_ME();
854cdf0e10cSrcweir 
855cdf0e10cSrcweir         ColumnSort currentSort;
856cdf0e10cSrcweir         try
857cdf0e10cSrcweir         {
858cdf0e10cSrcweir             Reference< XSortableGridData > const xSortAccess( getDataModel(), UNO_QUERY_THROW );
859cdf0e10cSrcweir             Pair< ::sal_Int32, ::sal_Bool > const aCurrentSortOrder( xSortAccess->getCurrentSortOrder() );
860cdf0e10cSrcweir             currentSort.nColumnPos = aCurrentSortOrder.First;
861cdf0e10cSrcweir             currentSort.eSortDirection = aCurrentSortOrder.Second ? ColumnSortAscending : ColumnSortDescending;
862cdf0e10cSrcweir         }
863cdf0e10cSrcweir         catch( const Exception& )
864cdf0e10cSrcweir         {
865cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
866cdf0e10cSrcweir         }
867cdf0e10cSrcweir         return currentSort;
868cdf0e10cSrcweir     }
869cdf0e10cSrcweir 
870cdf0e10cSrcweir     //--------------------------------------------------------------------
notifyColumnChange(ColPos const i_columnPos,ColumnAttributeGroup const i_attributeGroup) const871cdf0e10cSrcweir     void UnoControlTableModel::notifyColumnChange( ColPos const i_columnPos, ColumnAttributeGroup const i_attributeGroup ) const
872cdf0e10cSrcweir     {
873cdf0e10cSrcweir         DBG_CHECK_ME();
874cdf0e10cSrcweir         ENSURE_OR_RETURN_VOID( ( i_columnPos >= 0 ) && ( i_columnPos < getColumnCount() ),
875cdf0e10cSrcweir             "UnoControlTableModel::notifyColumnChange: invalid column index!" );
876cdf0e10cSrcweir 
877cdf0e10cSrcweir         ModellListeners aListeners( m_pImpl->m_aListeners );
878cdf0e10cSrcweir         for (   ModellListeners::const_iterator loop = aListeners.begin();
879cdf0e10cSrcweir                 loop != aListeners.end();
880cdf0e10cSrcweir                 ++loop
881cdf0e10cSrcweir             )
882cdf0e10cSrcweir         {
883cdf0e10cSrcweir             (*loop)->columnChanged( i_columnPos, i_attributeGroup );
884cdf0e10cSrcweir         }
885cdf0e10cSrcweir     }
886cdf0e10cSrcweir 
887cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
notifyRowsInserted(GridDataEvent const & i_event) const888cdf0e10cSrcweir     void UnoControlTableModel::notifyRowsInserted( GridDataEvent const & i_event ) const
889cdf0e10cSrcweir     {
890cdf0e10cSrcweir         // check sanity of the event
891cdf0e10cSrcweir         ENSURE_OR_RETURN_VOID( i_event.FirstRow >= 0, "UnoControlTableModel::notifyRowsInserted: invalid first row!" );
892cdf0e10cSrcweir         ENSURE_OR_RETURN_VOID( i_event.LastRow >= i_event.FirstRow, "UnoControlTableModel::notifyRowsInserted: invalid row indexes!" );
893cdf0e10cSrcweir 
894cdf0e10cSrcweir         // check own sanity
895cdf0e10cSrcweir         Reference< XGridColumnModel > const xColumnModel( m_pImpl->m_aColumnModel );
896cdf0e10cSrcweir         ENSURE_OR_RETURN_VOID( xColumnModel.is(), "UnoControlTableModel::notifyRowsInserted: no column model anymore!" );
897cdf0e10cSrcweir 
898cdf0e10cSrcweir         Reference< XGridDataModel > const xDataModel( m_pImpl->m_aDataModel );
899cdf0e10cSrcweir         ENSURE_OR_RETURN_VOID( xDataModel.is(), "UnoControlTableModel::notifyRowsInserted: no data model anymore!" );
900cdf0e10cSrcweir 
901cdf0e10cSrcweir         // implicitly add columns to the column model
902cdf0e10cSrcweir         // TODO: is this really a good idea?
903cdf0e10cSrcweir         sal_Int32 const dataColumnCount = xDataModel->getColumnCount();
904cdf0e10cSrcweir         OSL_ENSURE( dataColumnCount > 0, "UnoControlTableModel::notifyRowsInserted: no columns at all?" );
905cdf0e10cSrcweir 
906cdf0e10cSrcweir         sal_Int32 const modelColumnCount = xColumnModel->getColumnCount();
907cdf0e10cSrcweir         if ( ( modelColumnCount == 0 ) && ( dataColumnCount > 0 ) )
908cdf0e10cSrcweir         {
909cdf0e10cSrcweir             // TODO: shouldn't we clear the mutexes guard for this call?
910cdf0e10cSrcweir 		    xColumnModel->setDefaultColumns( dataColumnCount );
911cdf0e10cSrcweir         }
912cdf0e10cSrcweir 
913cdf0e10cSrcweir         // multiplex the event to our own listeners
914cdf0e10cSrcweir         ModellListeners aListeners( m_pImpl->m_aListeners );
915cdf0e10cSrcweir         for (   ModellListeners::const_iterator loop = aListeners.begin();
916cdf0e10cSrcweir                 loop != aListeners.end();
917cdf0e10cSrcweir                 ++loop
918cdf0e10cSrcweir             )
919cdf0e10cSrcweir         {
920cdf0e10cSrcweir             (*loop)->rowsInserted( i_event.FirstRow, i_event.LastRow );
921cdf0e10cSrcweir         }
922cdf0e10cSrcweir     }
923cdf0e10cSrcweir 
924cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
notifyRowsRemoved(GridDataEvent const & i_event) const925cdf0e10cSrcweir     void UnoControlTableModel::notifyRowsRemoved( GridDataEvent const & i_event ) const
926cdf0e10cSrcweir     {
927cdf0e10cSrcweir         ModellListeners aListeners( m_pImpl->m_aListeners );
928cdf0e10cSrcweir         for (   ModellListeners::const_iterator loop = aListeners.begin();
929cdf0e10cSrcweir                 loop != aListeners.end();
930cdf0e10cSrcweir                 ++loop
931cdf0e10cSrcweir             )
932cdf0e10cSrcweir         {
933cdf0e10cSrcweir             (*loop)->rowsRemoved( i_event.FirstRow, i_event.LastRow );
934cdf0e10cSrcweir         }
935cdf0e10cSrcweir     }
936cdf0e10cSrcweir 
937cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
notifyDataChanged(::com::sun::star::awt::grid::GridDataEvent const & i_event) const938cdf0e10cSrcweir     void UnoControlTableModel::notifyDataChanged( ::com::sun::star::awt::grid::GridDataEvent const & i_event ) const
939cdf0e10cSrcweir     {
940cdf0e10cSrcweir         ColPos const firstCol = i_event.FirstColumn == -1 ? 0 : i_event.FirstColumn;
941cdf0e10cSrcweir         ColPos const lastCol = i_event.FirstColumn == -1 ? getColumnCount() - 1 : i_event.LastColumn;
942cdf0e10cSrcweir         RowPos const firstRow = i_event.FirstRow == -1 ? 0 : i_event.FirstRow;
943cdf0e10cSrcweir         RowPos const lastRow = i_event.FirstRow == -1 ? getRowCount() - 1 : i_event.LastRow;
944cdf0e10cSrcweir 
945cdf0e10cSrcweir         ModellListeners aListeners( m_pImpl->m_aListeners );
946cdf0e10cSrcweir         for (   ModellListeners::const_iterator loop = aListeners.begin();
947cdf0e10cSrcweir                 loop != aListeners.end();
948cdf0e10cSrcweir                 ++loop
949cdf0e10cSrcweir             )
950cdf0e10cSrcweir         {
951cdf0e10cSrcweir             (*loop)->cellsUpdated( firstCol, lastCol, firstRow, lastRow );
952cdf0e10cSrcweir         }
953cdf0e10cSrcweir     }
954cdf0e10cSrcweir 
955cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
notifyAllDataChanged() const956cdf0e10cSrcweir     void UnoControlTableModel::notifyAllDataChanged() const
957cdf0e10cSrcweir     {
958cdf0e10cSrcweir         ModellListeners aListeners( m_pImpl->m_aListeners );
959cdf0e10cSrcweir         for (   ModellListeners::const_iterator loop = aListeners.begin();
960cdf0e10cSrcweir                 loop != aListeners.end();
961cdf0e10cSrcweir                 ++loop
962cdf0e10cSrcweir             )
963cdf0e10cSrcweir         {
964cdf0e10cSrcweir             (*loop)->cellsUpdated( 0, getColumnCount() - 1, 0, getRowCount() - 1 );
965cdf0e10cSrcweir         }
966cdf0e10cSrcweir     }
967cdf0e10cSrcweir 
968cdf0e10cSrcweir // .....................................................................................................................
969cdf0e10cSrcweir } } // svt::table
970cdf0e10cSrcweir // .....................................................................................................................
971