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