Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "svtxgridcontrol.hxx"
30 : : #include <com/sun/star/view/SelectionType.hpp>
31 : : #include "svtools/table/tablecontrolinterface.hxx"
32 : : #include "svtools/table/gridtablerenderer.hxx"
33 : : #include "svtools/table/tablecontrol.hxx"
34 : : #include "unocontroltablemodel.hxx"
35 : : #include <comphelper/sequence.hxx>
36 : : #include <rtl/ref.hxx>
37 : : #include <tools/diagnose_ex.h>
38 : : #include <toolkit/helper/property.hxx>
39 : : #include <toolkit/helper/vclunohelper.hxx>
40 : : #include <comphelper/processfactory.hxx>
41 : : #include <com/sun/star/awt/grid/XGridColumn.hpp>
42 : : #include <com/sun/star/awt/XControl.hpp>
43 : : #include <com/sun/star/awt/grid/GridInvalidDataException.hpp>
44 : : #include <com/sun/star/awt/grid/GridInvalidModelException.hpp>
45 : : #include <com/sun/star/util/Color.hpp>
46 : : #include <com/sun/star/awt/FontDescriptor.hpp>
47 : :
48 : : #include <vcl/svapp.hxx>
49 : :
50 : : using namespace ::svt::table;
51 : : using namespace ::com::sun::star::uno;
52 : : using namespace ::com::sun::star::awt::grid;
53 : : using namespace ::com::sun::star::view;
54 : : using namespace ::com::sun::star::style;
55 : : using namespace ::com::sun::star::container;
56 : : using namespace ::com::sun::star::accessibility;
57 : :
58 : :
59 : 0 : SVTXGridControl::SVTXGridControl()
60 : 0 : :m_pTableModel( new UnoControlTableModel() )
61 : : ,m_bTableModelInitCompleted( false )
62 : : ,m_nSelectedRowCount( 0 )
63 [ # # ][ # # ]: 0 : ,m_aSelectionListeners( *this )
[ # # ][ # # ]
64 : : {
65 : 0 : }
66 : :
67 : : // ---------------------------------------------------------------------------------------------------------------------
68 [ # # ][ # # ]: 0 : SVTXGridControl::~SVTXGridControl()
69 : : {
70 [ # # ]: 0 : }
71 : :
72 : : // ---------------------------------------------------------------------------------------------------------------------
73 : 0 : void SVTXGridControl::SetWindow( Window* pWindow )
74 : : {
75 : 0 : SVTXGridControl_Base::SetWindow( pWindow );
76 : 0 : impl_checkTableModelInit();
77 : 0 : }
78 : :
79 : : // ---------------------------------------------------------------------------------------------------------------------
80 : 0 : sal_Int32 SAL_CALL SVTXGridControl::getRowAtPoint(::sal_Int32 x, ::sal_Int32 y) throw (::com::sun::star::uno::RuntimeException)
81 : : {
82 [ # # ]: 0 : SolarMutexGuard aGuard;
83 : :
84 [ # # ]: 0 : TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() );
85 [ # # ]: 0 : ENSURE_OR_RETURN( pTable != NULL, "SVTXGridControl::getRowAtPoint: no control (anymore)!", -1 );
86 : :
87 [ # # ][ # # ]: 0 : TableCell const tableCell = pTable->getTableControlInterface().hitTest( Point( x, y ) );
88 [ # # ]: 0 : return ( tableCell.nRow >= 0 ) ? tableCell.nRow : -1;
89 : : }
90 : :
91 : : // ---------------------------------------------------------------------------------------------------------------------
92 : 0 : sal_Int32 SAL_CALL SVTXGridControl::getColumnAtPoint(::sal_Int32 x, ::sal_Int32 y) throw (::com::sun::star::uno::RuntimeException)
93 : : {
94 [ # # ]: 0 : SolarMutexGuard aGuard;
95 : :
96 [ # # ]: 0 : TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() );
97 [ # # ]: 0 : ENSURE_OR_RETURN( pTable != NULL, "SVTXGridControl::getColumnAtPoint: no control (anymore)!", -1 );
98 : :
99 [ # # ][ # # ]: 0 : TableCell const tableCell = pTable->getTableControlInterface().hitTest( Point( x, y ) );
100 [ # # ]: 0 : return ( tableCell.nColumn >= 0 ) ? tableCell.nColumn : -1;
101 : : }
102 : :
103 : : // ---------------------------------------------------------------------------------------------------------------------
104 : 0 : sal_Int32 SAL_CALL SVTXGridControl::getCurrentColumn( ) throw (RuntimeException)
105 : : {
106 [ # # ]: 0 : SolarMutexGuard aGuard;
107 : :
108 [ # # ]: 0 : TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() );
109 [ # # ]: 0 : ENSURE_OR_RETURN( pTable != NULL, "SVTXGridControl::getCurrentColumn: no control (anymore)!", -1 );
110 : :
111 [ # # ]: 0 : sal_Int32 const nColumn = pTable->GetCurrentColumn();
112 [ # # ]: 0 : return ( nColumn >= 0 ) ? nColumn : -1;
113 : : }
114 : :
115 : : // ---------------------------------------------------------------------------------------------------------------------
116 : 0 : sal_Int32 SAL_CALL SVTXGridControl::getCurrentRow( ) throw (RuntimeException)
117 : : {
118 [ # # ]: 0 : SolarMutexGuard aGuard;
119 : :
120 [ # # ]: 0 : TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() );
121 [ # # ]: 0 : ENSURE_OR_RETURN( pTable != NULL, "SVTXGridControl::getCurrentRow: no control (anymore)!", -1 );
122 : :
123 [ # # ]: 0 : sal_Int32 const nRow = pTable->GetCurrentRow();
124 [ # # ]: 0 : return ( nRow >= 0 ) ? nRow : -1;
125 : : }
126 : :
127 : : // ---------------------------------------------------------------------------------------------------------------------
128 : 0 : void SAL_CALL SVTXGridControl::addSelectionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridSelectionListener > & listener) throw (::com::sun::star::uno::RuntimeException)
129 : : {
130 : 0 : m_aSelectionListeners.addInterface(listener);
131 : 0 : }
132 : :
133 : : // ---------------------------------------------------------------------------------------------------------------------
134 : 0 : void SAL_CALL SVTXGridControl::removeSelectionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridSelectionListener > & listener) throw (::com::sun::star::uno::RuntimeException)
135 : : {
136 : 0 : m_aSelectionListeners.removeInterface(listener);
137 : 0 : }
138 : :
139 : : // ---------------------------------------------------------------------------------------------------------------------
140 : 0 : void SVTXGridControl::setProperty( const ::rtl::OUString& PropertyName, const Any& aValue) throw(RuntimeException)
141 : : {
142 [ # # ]: 0 : SolarMutexGuard aGuard;
143 : :
144 [ # # ]: 0 : TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() );
145 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( pTable != NULL, "SVTXGridControl::setProperty: no control (anymore)!" );
146 : :
147 [ # # ][ # # : 0 : switch( GetPropertyId( PropertyName ) )
# # # # #
# # # # #
# # # # #
# # # ]
148 : : {
149 : : case BASEPROPERTY_ROW_HEADER_WIDTH:
150 : : {
151 : 0 : sal_Int32 rowHeaderWidth( -1 );
152 : 0 : aValue >>= rowHeaderWidth;
153 [ # # ]: 0 : if ( rowHeaderWidth <= 0 )
154 : : {
155 : : SAL_WARN( "svtools.uno", "SVTXGridControl::setProperty: illegal row header width!" );
156 : : break;
157 : : }
158 : :
159 [ # # ]: 0 : m_pTableModel->setRowHeaderWidth( rowHeaderWidth );
160 : : // TODO: the model should broadcast this change itself, and the table should invalidate itself as needed
161 [ # # ]: 0 : pTable->Invalidate();
162 : : }
163 : 0 : break;
164 : :
165 : : case BASEPROPERTY_COLUMN_HEADER_HEIGHT:
166 : : {
167 : 0 : sal_Int32 columnHeaderHeight = 0;
168 [ # # ]: 0 : if ( !aValue.hasValue() )
169 : : {
170 [ # # ][ # # ]: 0 : columnHeaderHeight = pTable->PixelToLogic( Size( 0, pTable->GetTextHeight() + 3 ), MAP_APPFONT ).Height();
[ # # ][ # # ]
171 : : }
172 : : else
173 : : {
174 : 0 : aValue >>= columnHeaderHeight;
175 : : }
176 [ # # ]: 0 : if ( columnHeaderHeight <= 0 )
177 : : {
178 : : SAL_WARN( "svtools.uno", "SVTXGridControl::setProperty: illegal column header width!" );
179 : : break;
180 : : }
181 : :
182 [ # # ]: 0 : m_pTableModel->setColumnHeaderHeight( columnHeaderHeight );
183 : : // TODO: the model should broadcast this change itself, and the table should invalidate itself as needed
184 [ # # ]: 0 : pTable->Invalidate();
185 : : }
186 : 0 : break;
187 : :
188 : : case BASEPROPERTY_USE_GRID_LINES:
189 : : {
190 : : GridTableRenderer* pGridRenderer = dynamic_cast< GridTableRenderer* >(
191 [ # # ][ # # ]: 0 : m_pTableModel->getRenderer().get() );
[ # # ]
192 [ # # ]: 0 : if ( !pGridRenderer )
193 : : {
194 : : SAL_WARN( "svtools.uno", "SVTXGridControl::setProperty(UseGridLines): invalid renderer!" );
195 : : break;
196 : : }
197 : :
198 : 0 : sal_Bool bUseGridLines = sal_False;
199 : 0 : OSL_VERIFY( aValue >>= bUseGridLines );
200 [ # # ]: 0 : pGridRenderer->useGridLines( bUseGridLines );
201 [ # # ]: 0 : pTable->Invalidate();
202 : : }
203 : 0 : break;
204 : :
205 : : case BASEPROPERTY_ROW_HEIGHT:
206 : : {
207 : 0 : sal_Int32 rowHeight = 0;
208 [ # # ]: 0 : if ( !aValue.hasValue() )
209 : : {
210 [ # # ][ # # ]: 0 : rowHeight = pTable->PixelToLogic( Size( 0, pTable->GetTextHeight() + 3 ), MAP_APPFONT ).Height();
[ # # ][ # # ]
211 : : }
212 : : else
213 : : {
214 : 0 : aValue >>= rowHeight;
215 : : }
216 [ # # ]: 0 : m_pTableModel->setRowHeight( rowHeight );
217 [ # # ]: 0 : if ( rowHeight <= 0 )
218 : : {
219 : : SAL_WARN( "svtools.uno", "SVTXGridControl::setProperty: illegal row height!" );
220 : : break;
221 : : }
222 : :
223 : : // TODO: the model should broadcast this change itself, and the table should invalidate itself as needed
224 [ # # ]: 0 : pTable->Invalidate();
225 : : }
226 : 0 : break;
227 : :
228 : : case BASEPROPERTY_BACKGROUNDCOLOR:
229 : : {
230 : : // let the base class handle this for the TableControl
231 [ # # ]: 0 : VCLXWindow::setProperty( PropertyName, aValue );
232 : : // and forward to the grid control's data window
233 [ # # ]: 0 : if ( pTable->IsBackground() )
234 [ # # ][ # # ]: 0 : pTable->getDataWindow().SetBackground( pTable->GetBackground() );
235 : : else
236 [ # # ][ # # ]: 0 : pTable->getDataWindow().SetBackground();
237 : : }
238 : 0 : break;
239 : :
240 : : case BASEPROPERTY_GRID_SELECTIONMODE:
241 : : {
242 : : SelectionType eSelectionType;
243 [ # # ][ # # ]: 0 : if( aValue >>= eSelectionType )
244 : : {
245 : : SelectionMode eSelMode;
246 [ # # # # ]: 0 : switch( eSelectionType )
247 : : {
248 : 0 : case SelectionType_SINGLE: eSelMode = SINGLE_SELECTION; break;
249 : 0 : case SelectionType_RANGE: eSelMode = RANGE_SELECTION; break;
250 : 0 : case SelectionType_MULTI: eSelMode = MULTIPLE_SELECTION; break;
251 : 0 : default: eSelMode = NO_SELECTION; break;
252 : : }
253 [ # # ][ # # ]: 0 : if( pTable->getSelEngine()->GetSelectionMode() != eSelMode )
254 [ # # ][ # # ]: 0 : pTable->getSelEngine()->SetSelectionMode( eSelMode );
255 : : }
256 : : break;
257 : : }
258 : : case BASEPROPERTY_HSCROLL:
259 : : {
260 : 0 : sal_Bool bHScroll = true;
261 [ # # ]: 0 : if( aValue >>= bHScroll )
262 [ # # ][ # # ]: 0 : m_pTableModel->setHorizontalScrollbarVisibility( bHScroll ? ScrollbarShowAlways : ScrollbarShowSmart );
263 : : break;
264 : : }
265 : :
266 : : case BASEPROPERTY_VSCROLL:
267 : : {
268 : 0 : sal_Bool bVScroll = true;
269 [ # # ]: 0 : if( aValue >>= bVScroll )
270 : : {
271 [ # # ][ # # ]: 0 : m_pTableModel->setVerticalScrollbarVisibility( bVScroll ? ScrollbarShowAlways : ScrollbarShowSmart );
272 : : }
273 : : break;
274 : : }
275 : :
276 : : case BASEPROPERTY_GRID_SHOWROWHEADER:
277 : : {
278 : 0 : sal_Bool rowHeader = true;
279 [ # # ]: 0 : if( aValue >>= rowHeader )
280 : : {
281 [ # # ]: 0 : m_pTableModel->setRowHeaders(rowHeader);
282 : : }
283 : : break;
284 : : }
285 : :
286 : : case BASEPROPERTY_GRID_ROW_BACKGROUND_COLORS:
287 [ # # ]: 0 : m_pTableModel->setRowBackgroundColors( aValue );
288 [ # # ]: 0 : pTable->Invalidate();
289 : 0 : break;
290 : :
291 : : case BASEPROPERTY_GRID_LINE_COLOR:
292 [ # # ]: 0 : m_pTableModel->setLineColor( aValue );
293 [ # # ]: 0 : pTable->Invalidate();
294 : 0 : break;
295 : :
296 : : case BASEPROPERTY_GRID_HEADER_BACKGROUND:
297 [ # # ]: 0 : m_pTableModel->setHeaderBackgroundColor( aValue );
298 [ # # ]: 0 : pTable->Invalidate();
299 : 0 : break;
300 : :
301 : : case BASEPROPERTY_GRID_HEADER_TEXT_COLOR:
302 [ # # ]: 0 : m_pTableModel->setHeaderTextColor( aValue );
303 [ # # ]: 0 : pTable->Invalidate();
304 : 0 : break;
305 : :
306 : : case BASEPROPERTY_TEXTCOLOR:
307 [ # # ]: 0 : m_pTableModel->setTextColor( aValue );
308 [ # # ]: 0 : pTable->Invalidate();
309 : 0 : break;
310 : :
311 : : case BASEPROPERTY_TEXTLINECOLOR:
312 [ # # ]: 0 : m_pTableModel->setTextLineColor( aValue );
313 [ # # ]: 0 : pTable->Invalidate();
314 : 0 : break;
315 : :
316 : : case BASEPROPERTY_VERTICALALIGN:
317 : : {
318 : 0 : VerticalAlignment eAlign( VerticalAlignment_TOP );
319 [ # # ][ # # ]: 0 : if ( aValue >>= eAlign )
320 [ # # ]: 0 : m_pTableModel->setVerticalAlign( eAlign );
321 : : break;
322 : : }
323 : :
324 : : case BASEPROPERTY_GRID_SHOWCOLUMNHEADER:
325 : : {
326 : 0 : sal_Bool colHeader = true;
327 [ # # ]: 0 : if( aValue >>= colHeader )
328 : : {
329 [ # # ]: 0 : m_pTableModel->setColumnHeaders(colHeader);
330 : : }
331 : : break;
332 : : }
333 : : case BASEPROPERTY_GRID_DATAMODEL:
334 : : {
335 [ # # ]: 0 : Reference< XGridDataModel > const xDataModel( aValue, UNO_QUERY );
336 [ # # ]: 0 : if ( !xDataModel.is() )
337 [ # # ][ # # ]: 0 : throw GridInvalidDataException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid data model." ) ), *this );
[ # # ]
338 : :
339 [ # # ]: 0 : m_pTableModel->setDataModel( xDataModel );
340 [ # # ]: 0 : impl_checkTableModelInit();
341 : : }
342 : 0 : break;
343 : :
344 : : case BASEPROPERTY_GRID_COLUMNMODEL:
345 : : {
346 : : // obtain new col model
347 [ # # ]: 0 : Reference< XGridColumnModel > const xColumnModel( aValue, UNO_QUERY );
348 [ # # ]: 0 : if ( !xColumnModel.is() )
349 [ # # ][ # # ]: 0 : throw GridInvalidModelException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid column model." ) ), *this );
[ # # ]
350 : :
351 : : // remove all old columns
352 [ # # ]: 0 : m_pTableModel->removeAllColumns();
353 : :
354 : : // announce to the TableModel
355 [ # # ]: 0 : m_pTableModel->setColumnModel( xColumnModel );
356 [ # # ]: 0 : impl_checkTableModelInit();
357 : :
358 : : // add new columns
359 [ # # ]: 0 : impl_updateColumnsFromModel_nothrow();
360 : 0 : break;
361 : : }
362 : : default:
363 [ # # ]: 0 : VCLXWindow::setProperty( PropertyName, aValue );
364 : 0 : break;
365 [ # # ][ # # ]: 0 : }
366 : : }
367 : :
368 : :
369 : 0 : void SVTXGridControl::impl_checkTableModelInit()
370 : : {
371 [ # # ][ # # ]: 0 : if ( !m_bTableModelInitCompleted && m_pTableModel->hasColumnModel() && m_pTableModel->hasDataModel() )
[ # # ][ # # ]
372 : : {
373 [ # # ]: 0 : TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() );
374 [ # # ]: 0 : if ( pTable )
375 : : {
376 [ # # ][ # # ]: 0 : pTable->SetModel( PTableModel( m_pTableModel ) );
[ # # ]
377 : :
378 : 0 : m_bTableModelInitCompleted = true;
379 : :
380 : : // ensure default columns exist, if they have not previously been added
381 [ # # ][ # # ]: 0 : Reference< XGridDataModel > const xDataModel( m_pTableModel->getDataModel(), UNO_QUERY_THROW );
382 [ # # ][ # # ]: 0 : Reference< XGridColumnModel > const xColumnModel( m_pTableModel->getColumnModel(), UNO_QUERY_THROW );
383 : :
384 [ # # ][ # # ]: 0 : sal_Int32 const nDataColumnCount = xDataModel->getColumnCount();
385 [ # # ][ # # ]: 0 : if ( ( nDataColumnCount > 0 ) && ( xColumnModel->getColumnCount() == 0 ) )
[ # # ][ # # ]
[ # # ]
386 [ # # ][ # # ]: 0 : xColumnModel->setDefaultColumns( nDataColumnCount );
387 : : // this will trigger notifications, which in turn will let us update our m_pTableModel
388 : : }
389 : : }
390 : 0 : }
391 : :
392 : : namespace
393 : : {
394 : 0 : void lcl_convertColor( ::boost::optional< ::Color > const & i_color, Any & o_colorValue )
395 : : {
396 [ # # ]: 0 : if ( !i_color )
397 : 0 : o_colorValue.clear();
398 : : else
399 [ # # ]: 0 : o_colorValue <<= i_color->GetColor();
400 : 0 : }
401 : : }
402 : :
403 : 0 : Any SVTXGridControl::getProperty( const ::rtl::OUString& PropertyName ) throw(RuntimeException)
404 : : {
405 [ # # ]: 0 : SolarMutexGuard aGuard;
406 : :
407 [ # # ]: 0 : TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() );
408 [ # # ]: 0 : ENSURE_OR_RETURN( pTable != NULL, "SVTXGridControl::getProperty: no control (anymore)!", Any() );
409 : :
410 : 0 : Any aPropertyValue;
411 : :
412 [ # # ]: 0 : const sal_uInt16 nPropId = GetPropertyId( PropertyName );
413 [ # # # # : 0 : switch(nPropId)
# # # # #
# # # # #
# ]
414 : : {
415 : : case BASEPROPERTY_GRID_SELECTIONMODE:
416 : : {
417 : : SelectionType eSelectionType;
418 : :
419 [ # # ]: 0 : SelectionMode eSelMode = pTable->getSelEngine()->GetSelectionMode();
420 [ # # # # ]: 0 : switch( eSelMode )
421 : : {
422 : 0 : case SINGLE_SELECTION: eSelectionType = SelectionType_SINGLE; break;
423 : 0 : case RANGE_SELECTION: eSelectionType = SelectionType_RANGE; break;
424 : 0 : case MULTIPLE_SELECTION:eSelectionType = SelectionType_MULTI; break;
425 : 0 : default: eSelectionType = SelectionType_NONE; break;
426 : : }
427 [ # # ]: 0 : aPropertyValue <<= eSelectionType;
428 : : break;
429 : : }
430 : :
431 : : case BASEPROPERTY_GRID_SHOWROWHEADER:
432 [ # # ][ # # ]: 0 : aPropertyValue <<= sal_Bool( m_pTableModel->hasRowHeaders() );
433 : 0 : break;
434 : :
435 : : case BASEPROPERTY_GRID_SHOWCOLUMNHEADER:
436 [ # # ][ # # ]: 0 : aPropertyValue <<= sal_Bool( m_pTableModel->hasColumnHeaders() );
437 : 0 : break;
438 : :
439 : : case BASEPROPERTY_GRID_DATAMODEL:
440 [ # # ][ # # ]: 0 : aPropertyValue <<= m_pTableModel->getDataModel();
441 : 0 : break;
442 : :
443 : : case BASEPROPERTY_GRID_COLUMNMODEL:
444 [ # # ][ # # ]: 0 : aPropertyValue <<= m_pTableModel->getColumnModel();
445 : 0 : break;
446 : :
447 : : case BASEPROPERTY_HSCROLL:
448 : : {
449 [ # # ]: 0 : sal_Bool const bHasScrollbar = ( m_pTableModel->getHorizontalScrollbarVisibility() != ScrollbarShowNever );
450 [ # # ]: 0 : aPropertyValue <<= bHasScrollbar;
451 : : break;
452 : : }
453 : :
454 : : case BASEPROPERTY_VSCROLL:
455 : : {
456 [ # # ]: 0 : sal_Bool const bHasScrollbar = ( m_pTableModel->getVerticalScrollbarVisibility() != ScrollbarShowNever );
457 [ # # ]: 0 : aPropertyValue <<= bHasScrollbar;
458 : : break;
459 : : }
460 : :
461 : : case BASEPROPERTY_USE_GRID_LINES:
462 : : {
463 : : GridTableRenderer* pGridRenderer = dynamic_cast< GridTableRenderer* >(
464 [ # # ][ # # ]: 0 : m_pTableModel->getRenderer().get() );
[ # # ]
465 [ # # ]: 0 : if ( !pGridRenderer )
466 : : {
467 : : SAL_WARN( "svtools.uno", "SVTXGridControl::getProperty(UseGridLines): invalid renderer!" );
468 : 0 : break;
469 : : }
470 : :
471 [ # # ][ # # ]: 0 : aPropertyValue <<= pGridRenderer->useGridLines();
472 : : }
473 : 0 : break;
474 : :
475 : : case BASEPROPERTY_GRID_ROW_BACKGROUND_COLORS:
476 : : {
477 [ # # ]: 0 : ::boost::optional< ::std::vector< ::Color > > aColors( m_pTableModel->getRowBackgroundColors() );
478 [ # # ][ # # ]: 0 : if ( !aColors )
479 : 0 : aPropertyValue.clear();
480 : : else
481 : : {
482 [ # # ][ # # ]: 0 : Sequence< ::com::sun::star::util::Color > aAPIColors( aColors->size() );
483 [ # # ][ # # ]: 0 : for ( size_t i=0; i<aColors->size(); ++i )
484 : : {
485 [ # # ][ # # ]: 0 : aAPIColors[i] = aColors->at(i).GetColor();
[ # # ]
486 : : }
487 [ # # ][ # # ]: 0 : aPropertyValue <<= aAPIColors;
488 [ # # ]: 0 : }
489 : : }
490 : 0 : break;
491 : :
492 : : case BASEPROPERTY_GRID_LINE_COLOR:
493 [ # # ][ # # ]: 0 : lcl_convertColor( m_pTableModel->getLineColor(), aPropertyValue );
[ # # ]
494 : 0 : break;
495 : :
496 : : case BASEPROPERTY_GRID_HEADER_BACKGROUND:
497 [ # # ][ # # ]: 0 : lcl_convertColor( m_pTableModel->getHeaderBackgroundColor(), aPropertyValue );
[ # # ]
498 : 0 : break;
499 : :
500 : : case BASEPROPERTY_GRID_HEADER_TEXT_COLOR:
501 [ # # ][ # # ]: 0 : lcl_convertColor( m_pTableModel->getHeaderTextColor(), aPropertyValue );
[ # # ]
502 : 0 : break;
503 : :
504 : : case BASEPROPERTY_TEXTCOLOR:
505 [ # # ][ # # ]: 0 : lcl_convertColor( m_pTableModel->getTextColor(), aPropertyValue );
[ # # ]
506 : 0 : break;
507 : :
508 : : case BASEPROPERTY_TEXTLINECOLOR:
509 [ # # ][ # # ]: 0 : lcl_convertColor( m_pTableModel->getTextLineColor(), aPropertyValue );
[ # # ]
510 : 0 : break;
511 : :
512 : : default:
513 [ # # ]: 0 : aPropertyValue = VCLXWindow::getProperty( PropertyName );
514 : 0 : break;
515 : : }
516 : :
517 [ # # ]: 0 : return aPropertyValue;
518 : : }
519 : :
520 : : //----------------------------------------------------------------------------------------------------------------------
521 : 0 : void SAL_CALL SVTXGridControl::rowsInserted( const GridDataEvent& i_event ) throw (RuntimeException)
522 : : {
523 [ # # ]: 0 : SolarMutexGuard aGuard;
524 [ # # ][ # # ]: 0 : m_pTableModel->notifyRowsInserted( i_event );
525 : 0 : }
526 : :
527 : : //----------------------------------------------------------------------------------------------------------------------
528 : : void SAL_CALL//----------------------------------------------------------------------------------------------------------------------
529 : 0 : SVTXGridControl::rowsRemoved( const GridDataEvent& i_event ) throw (RuntimeException)
530 : : {
531 [ # # ]: 0 : SolarMutexGuard aGuard;
532 [ # # ][ # # ]: 0 : m_pTableModel->notifyRowsRemoved( i_event );
533 : 0 : }
534 : :
535 : : //----------------------------------------------------------------------------------------------------------------------
536 : 0 : void SAL_CALL SVTXGridControl::dataChanged( const GridDataEvent& i_event ) throw (RuntimeException)
537 : : {
538 [ # # ]: 0 : SolarMutexGuard aGuard;
539 : :
540 [ # # ]: 0 : m_pTableModel->notifyDataChanged( i_event );
541 : :
542 : : // if the data model is sortable, a dataChanged event is also fired in case the sort order changed.
543 : : // So, just in case, invalidate the column header area, too.
544 [ # # ]: 0 : TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() );
545 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::dataChanged: no control (anymore)!" );
546 [ # # ][ # # ]: 0 : pTable->getTableControlInterface().invalidate( TableAreaColumnHeaders );
[ # # ][ # # ]
547 : : }
548 : :
549 : : //----------------------------------------------------------------------------------------------------------------------
550 : 0 : void SAL_CALL SVTXGridControl::rowHeadingChanged( const GridDataEvent& i_event ) throw (RuntimeException)
551 : : {
552 [ # # ]: 0 : SolarMutexGuard aGuard;
553 : : OSL_UNUSED( i_event );
554 : :
555 [ # # ]: 0 : TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() );
556 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::rowHeadingChanged: no control (anymore)!" );
557 : :
558 : : // TODO: we could do better than this - invalidate the header area only
559 [ # # ][ # # ]: 0 : pTable->getTableControlInterface().invalidate( TableAreaRowHeaders );
[ # # ][ # # ]
560 : : }
561 : :
562 : : //----------------------------------------------------------------------------------------------------------------------
563 : 0 : void SAL_CALL SVTXGridControl::elementInserted( const ContainerEvent& i_event ) throw (RuntimeException)
564 : : {
565 [ # # ]: 0 : SolarMutexGuard aGuard;
566 : :
567 [ # # ]: 0 : Reference< XGridColumn > const xGridColumn( i_event.Element, UNO_QUERY_THROW );
568 : :
569 [ # # ]: 0 : sal_Int32 nIndex( m_pTableModel->getColumnCount() );
570 : 0 : OSL_VERIFY( i_event.Accessor >>= nIndex );
571 [ # # ][ # # ]: 0 : m_pTableModel->insertColumn( nIndex, xGridColumn );
572 : 0 : }
573 : :
574 : : //----------------------------------------------------------------------------------------------------------------------
575 : 0 : void SAL_CALL SVTXGridControl::elementRemoved( const ContainerEvent& i_event ) throw (RuntimeException)
576 : : {
577 [ # # ]: 0 : SolarMutexGuard aGuard;
578 : :
579 : 0 : sal_Int32 nIndex( -1 );
580 : 0 : OSL_VERIFY( i_event.Accessor >>= nIndex );
581 [ # # ][ # # ]: 0 : m_pTableModel->removeColumn( nIndex );
582 : 0 : }
583 : :
584 : : //----------------------------------------------------------------------------------------------------------------------
585 : 0 : void SAL_CALL SVTXGridControl::elementReplaced( const ContainerEvent& i_event ) throw (RuntimeException)
586 : : {
587 : : OSL_ENSURE( false, "SVTXGridControl::elementReplaced: not implemented!" );
588 : : // at the moment, the XGridColumnModel API does not allow replacing columns
589 : : OSL_UNUSED( i_event );
590 : : // TODO: replace the respective column in our table model
591 : 0 : }
592 : :
593 : :
594 : : //----------------------------------------------------------------------------------------------------------------------
595 : 0 : void SAL_CALL SVTXGridControl::disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException)
596 : : {
597 : 0 : VCLXWindow::disposing( Source );
598 : 0 : }
599 : :
600 : : //----------------------------------------------------------------------------------------------------------------------
601 : 0 : void SAL_CALL SVTXGridControl::selectRow( ::sal_Int32 i_rowIndex ) throw (::com::sun::star::uno::RuntimeException)
602 : : {
603 [ # # ]: 0 : SolarMutexGuard aGuard;
604 : :
605 [ # # ]: 0 : TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() );
606 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::selectRow: no control (anymore)!" );
607 : :
608 [ # # ][ # # ]: 0 : pTable->SelectRow( i_rowIndex, true );
[ # # ]
609 : : }
610 : :
611 : : //----------------------------------------------------------------------------------------------------------------------
612 : 0 : void SAL_CALL SVTXGridControl::selectAllRows() throw (::com::sun::star::uno::RuntimeException)
613 : : {
614 [ # # ]: 0 : SolarMutexGuard aGuard;
615 : :
616 [ # # ]: 0 : TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() );
617 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::selectAllRows: no control (anymore)!" );
618 : :
619 [ # # ][ # # ]: 0 : pTable->SelectAllRows( true );
[ # # ]
620 : : }
621 : :
622 : : //----------------------------------------------------------------------------------------------------------------------
623 : 0 : void SAL_CALL SVTXGridControl::deselectRow( ::sal_Int32 i_rowIndex ) throw (::com::sun::star::uno::RuntimeException)
624 : : {
625 [ # # ]: 0 : SolarMutexGuard aGuard;
626 : :
627 [ # # ]: 0 : TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() );
628 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::deselectRow: no control (anymore)!" );
629 : :
630 [ # # ][ # # ]: 0 : pTable->SelectRow( i_rowIndex, false );
[ # # ]
631 : : }
632 : :
633 : : //----------------------------------------------------------------------------------------------------------------------
634 : 0 : void SAL_CALL SVTXGridControl::deselectAllRows() throw (::com::sun::star::uno::RuntimeException)
635 : : {
636 [ # # ]: 0 : SolarMutexGuard aGuard;
637 : :
638 [ # # ]: 0 : TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() );
639 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::deselectAllRows: no control (anymore)!" );
640 : :
641 [ # # ][ # # ]: 0 : pTable->SelectAllRows( false );
[ # # ]
642 : : }
643 : :
644 : : //----------------------------------------------------------------------------------------------------------------------
645 : 0 : ::com::sun::star::uno::Sequence< ::sal_Int32 > SAL_CALL SVTXGridControl::getSelection() throw (::com::sun::star::uno::RuntimeException)
646 : : {
647 [ # # ]: 0 : SolarMutexGuard aGuard;
648 : :
649 [ # # ]: 0 : TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() );
650 [ # # ][ # # ]: 0 : ENSURE_OR_RETURN( pTable, "SVTXGridControl::getSelection: no control (anymore)!", Sequence< sal_Int32 >() );
651 : :
652 [ # # ]: 0 : sal_Int32 selectionCount = pTable->GetSelectedRowCount();
653 [ # # ]: 0 : Sequence< sal_Int32 > selectedRows( selectionCount );
654 [ # # ]: 0 : for ( sal_Int32 i=0; i<selectionCount; ++i )
655 [ # # ][ # # ]: 0 : selectedRows[i] = pTable->GetSelectedRowIndex(i);
656 [ # # ][ # # ]: 0 : return selectedRows;
[ # # ]
657 : : }
658 : :
659 : : //----------------------------------------------------------------------------------------------------------------------
660 : 0 : ::sal_Bool SAL_CALL SVTXGridControl::isSelectionEmpty() throw (::com::sun::star::uno::RuntimeException)
661 : : {
662 [ # # ]: 0 : SolarMutexGuard aGuard;
663 : :
664 [ # # ]: 0 : TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() );
665 [ # # ]: 0 : ENSURE_OR_RETURN( pTable, "SVTXGridControl::getSelection: no control (anymore)!", sal_True );
666 : :
667 [ # # ][ # # ]: 0 : return pTable->GetSelectedRowCount() > 0;
668 : : }
669 : :
670 : : //----------------------------------------------------------------------------------------------------------------------
671 : 0 : ::sal_Bool SAL_CALL SVTXGridControl::isSelectedIndex( ::sal_Int32 index ) throw (::com::sun::star::uno::RuntimeException)
672 : : {
673 [ # # ]: 0 : SolarMutexGuard aGuard;
674 : :
675 [ # # ]: 0 : TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() );
676 [ # # ]: 0 : ENSURE_OR_RETURN( pTable, "SVTXGridControl::isSelectedIndex: no control (anymore)!", sal_False );
677 : :
678 [ # # ][ # # ]: 0 : return pTable->IsRowSelected( index );
679 : : }
680 : :
681 : : //----------------------------------------------------------------------------------------------------------------------
682 : 0 : void SVTXGridControl::dispose() throw(::com::sun::star::uno::RuntimeException)
683 : : {
684 [ # # ]: 0 : ::com::sun::star::lang::EventObject aObj;
685 [ # # ]: 0 : aObj.Source = (::cppu::OWeakObject*)this;
686 [ # # ]: 0 : m_aSelectionListeners.disposeAndClear( aObj );
687 [ # # ][ # # ]: 0 : VCLXWindow::dispose();
688 : 0 : }
689 : :
690 : : //----------------------------------------------------------------------------------------------------------------------
691 : 0 : void SVTXGridControl::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
692 : : {
693 [ # # ]: 0 : SolarMutexGuard aGuard;
694 : :
695 [ # # ]: 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xKeepAlive( this );
696 [ # # ]: 0 : switch ( rVclWindowEvent.GetId() )
697 : : {
698 : : case VCLEVENT_TABLEROW_SELECT:
699 : : {
700 [ # # ]: 0 : TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() );
701 [ # # ]: 0 : if ( !pTable )
702 : : {
703 : : SAL_WARN( "svtools.uno", "SVTXGridControl::ProcessWindowEvent: no control (anymore)!" );
704 : 0 : break;
705 : : }
706 : :
707 [ # # ][ # # ]: 0 : if ( m_aSelectionListeners.getLength() )
708 [ # # ]: 0 : ImplCallItemListeners();
709 : : }
710 : 0 : break;
711 : :
712 : : default:
713 [ # # ]: 0 : VCLXWindow::ProcessWindowEvent( rVclWindowEvent );
714 : 0 : break;
715 [ # # ]: 0 : }
716 : 0 : }
717 : :
718 : : //----------------------------------------------------------------------------------------------------------------------
719 : 0 : void SVTXGridControl::ImplCallItemListeners()
720 : : {
721 [ # # ]: 0 : TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() );
722 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::ImplCallItemListeners: no control (anymore)!" );
723 : :
724 [ # # ]: 0 : if ( m_aSelectionListeners.getLength() )
725 : : {
726 [ # # ]: 0 : sal_Int32 const actSelRowCount = pTable->GetSelectedRowCount();
727 [ # # ]: 0 : ::com::sun::star::awt::grid::GridSelectionEvent aEvent;
728 [ # # ]: 0 : aEvent.Source = (::cppu::OWeakObject*)this;
729 : 0 : aEvent.Column = 0;
730 : 0 : sal_Int32 diff = actSelRowCount - m_nSelectedRowCount;
731 : : //row added to selection
732 [ # # ]: 0 : if(diff >= 1)
733 : : {
734 : 0 : aEvent.Action = com::sun::star::awt::grid::SelectionEventType(0);
735 [ # # ]: 0 : aEvent.Row = pTable->GetSelectedRowIndex( actSelRowCount - 1 );
736 : 0 : aEvent.Range = diff;
737 : : }
738 : : //selected row changed
739 [ # # ][ # # ]: 0 : else if(diff == 0 && actSelRowCount != 0)
740 : : {
741 [ # # ]: 0 : aEvent.Row = pTable->GetSelectedRowIndex( actSelRowCount - 1 );
742 : 0 : aEvent.Action = com::sun::star::awt::grid::SelectionEventType(2);
743 : 0 : aEvent.Range = 0;
744 : : }
745 : : else
746 : : {
747 : : //selection changed: multiple row deselected, only 1 row is selected
748 [ # # ]: 0 : if(actSelRowCount == 1)
749 : : {
750 [ # # ]: 0 : aEvent.Row = pTable->GetSelectedRowIndex( actSelRowCount - 1 );
751 : 0 : aEvent.Action = com::sun::star::awt::grid::SelectionEventType(2);
752 : : }
753 : : //row is deselected
754 : : else
755 : : {
756 [ # # ]: 0 : aEvent.Row = pTable->GetCurrentRow();
757 : 0 : aEvent.Action = com::sun::star::awt::grid::SelectionEventType(1);
758 : : }
759 : 0 : aEvent.Range = 0;
760 : : }
761 : 0 : m_nSelectedRowCount=actSelRowCount;
762 [ # # ][ # # ]: 0 : m_aSelectionListeners.selectionChanged( aEvent );
763 : : }
764 : : }
765 : :
766 : : //----------------------------------------------------------------------------------------------------------------------
767 : 0 : void SVTXGridControl::impl_updateColumnsFromModel_nothrow()
768 : : {
769 [ # # ]: 0 : Reference< XGridColumnModel > const xColumnModel( m_pTableModel->getColumnModel() );
770 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( xColumnModel.is(), "no model!" );
771 [ # # ]: 0 : TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() );
772 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( pTable != NULL, "no table!" );
773 : :
774 : : try
775 : : {
776 [ # # ][ # # ]: 0 : const Sequence< Reference< XGridColumn > > columns = xColumnModel->getColumns();
777 [ # # ]: 0 : for ( const Reference< XGridColumn >* colRef = columns.getConstArray();
778 : 0 : colRef != columns.getConstArray() + columns.getLength();
779 : : ++colRef
780 : : )
781 : : {
782 [ # # ]: 0 : if ( !colRef->is() )
783 : : {
784 : : SAL_WARN( "svtools.uno", "illegal column!" );
785 : 0 : continue;
786 : : }
787 : :
788 [ # # ]: 0 : m_pTableModel->appendColumn( *colRef );
789 [ # # ][ # # ]: 0 : }
790 : : }
791 [ # # ]: 0 : catch( const Exception& )
792 : : {
793 : : DBG_UNHANDLED_EXCEPTION();
794 [ # # ]: 0 : }
795 : : }
796 : :
797 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|