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