GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svtools / source / table / gridtablerenderer.cxx
blobca99192f9fcd97f78dceffbbdcad2c51bc0206d3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "cellvalueconversion.hxx"
22 #include "svtools/table/gridtablerenderer.hxx"
23 #include "svtools/colorcfg.hxx"
25 #include <com/sun/star/graphic/XGraphic.hpp>
27 #include <comphelper/processfactory.hxx>
28 #include <tools/debug.hxx>
29 #include <tools/diagnose_ex.h>
30 #include <vcl/window.hxx>
31 #include <vcl/image.hxx>
32 #include <vcl/virdev.hxx>
33 #include <vcl/decoview.hxx>
35 //......................................................................................................................
36 namespace svt { namespace table
38 //......................................................................................................................
40 using ::com::sun::star::uno::Any;
41 using ::com::sun::star::uno::Reference;
42 using ::com::sun::star::uno::UNO_QUERY;
43 using ::com::sun::star::uno::XInterface;
44 using ::com::sun::star::uno::TypeClass_INTERFACE;
45 using ::com::sun::star::graphic::XGraphic;
46 using ::com::sun::star::style::HorizontalAlignment;
47 using ::com::sun::star::style::HorizontalAlignment_LEFT;
48 using ::com::sun::star::style::HorizontalAlignment_CENTER;
49 using ::com::sun::star::style::HorizontalAlignment_RIGHT;
50 using ::com::sun::star::style::VerticalAlignment;
51 using ::com::sun::star::style::VerticalAlignment_TOP;
52 using ::com::sun::star::style::VerticalAlignment_MIDDLE;
53 using ::com::sun::star::style::VerticalAlignment_BOTTOM;
55 //==================================================================================================================
56 //= CachedSortIndicator
57 //==================================================================================================================
58 class CachedSortIndicator
60 public:
61 CachedSortIndicator()
62 :m_lastHeaderHeight( 0 )
63 ,m_lastArrowColor( COL_TRANSPARENT )
67 BitmapEx const & getBitmapFor( OutputDevice const & i_device, long const i_headerHeight, StyleSettings const & i_style, bool const i_sortAscending );
69 private:
70 long m_lastHeaderHeight;
71 Color m_lastArrowColor;
72 BitmapEx m_sortAscending;
73 BitmapEx m_sortDescending;
76 //------------------------------------------------------------------------------------------------------------------
77 BitmapEx const & CachedSortIndicator::getBitmapFor( OutputDevice const & i_device, long const i_headerHeight,
78 StyleSettings const & i_style, bool const i_sortAscending )
80 BitmapEx & rBitmap( i_sortAscending ? m_sortAscending : m_sortDescending );
81 if ( !rBitmap || ( i_headerHeight != m_lastHeaderHeight ) || ( i_style.GetActiveColor() != m_lastArrowColor ) )
83 long const nSortIndicatorWidth = 2 * i_headerHeight / 3;
84 long const nSortIndicatorHeight = 2 * nSortIndicatorWidth / 3;
86 Point const aBitmapPos( 0, 0 );
87 Size const aBitmapSize( nSortIndicatorWidth, nSortIndicatorHeight );
88 VirtualDevice aDevice( i_device, 0, 0 );
89 aDevice.SetOutputSizePixel( aBitmapSize );
91 DecorationView aDecoView( &aDevice );
92 aDecoView.DrawSymbol(
93 Rectangle( aBitmapPos, aBitmapSize ),
94 i_sortAscending ? SYMBOL_SPIN_UP : SYMBOL_SPIN_DOWN,
95 i_style.GetActiveColor()
98 rBitmap = aDevice.GetBitmapEx( aBitmapPos, aBitmapSize );
99 m_lastHeaderHeight = i_headerHeight;
100 m_lastArrowColor = i_style.GetActiveColor();
102 return rBitmap;
105 //==================================================================================================================
106 //= GridTableRenderer_Impl
107 //==================================================================================================================
108 struct GridTableRenderer_Impl
110 ITableModel& rModel;
111 RowPos nCurrentRow;
112 bool bUseGridLines;
113 CachedSortIndicator aSortIndicator;
114 CellValueConversion aStringConverter;
116 GridTableRenderer_Impl( ITableModel& _rModel )
117 :rModel( _rModel )
118 ,nCurrentRow( ROW_INVALID )
119 ,bUseGridLines( true )
120 ,aSortIndicator( )
121 ,aStringConverter()
126 //==================================================================================================================
127 //= helper
128 //==================================================================================================================
129 namespace
131 static Rectangle lcl_getContentArea( GridTableRenderer_Impl const & i_impl, Rectangle const & i_cellArea )
133 Rectangle aContentArea( i_cellArea );
134 if ( i_impl.bUseGridLines )
136 --aContentArea.Right();
137 --aContentArea.Bottom();
139 return aContentArea;
141 static Rectangle lcl_getTextRenderingArea( Rectangle const & i_contentArea )
143 Rectangle aTextArea( i_contentArea );
144 aTextArea.Left() += 2; aTextArea.Right() -= 2;
145 ++aTextArea.Top(); --aTextArea.Bottom();
146 return aTextArea;
149 static sal_uLong lcl_getAlignmentTextDrawFlags( GridTableRenderer_Impl const & i_impl, ColPos const i_columnPos )
151 sal_uLong nVertFlag = TEXT_DRAW_TOP;
152 VerticalAlignment const eVertAlign = i_impl.rModel.getVerticalAlign();
153 switch ( eVertAlign )
155 case VerticalAlignment_MIDDLE: nVertFlag = TEXT_DRAW_VCENTER; break;
156 case VerticalAlignment_BOTTOM: nVertFlag = TEXT_DRAW_BOTTOM; break;
157 default:
158 break;
161 sal_uLong nHorzFlag = TEXT_DRAW_LEFT;
162 HorizontalAlignment const eHorzAlign = i_impl.rModel.getColumnCount() > 0
163 ? i_impl.rModel.getColumnModel( i_columnPos )->getHorizontalAlign()
164 : HorizontalAlignment_CENTER;
165 switch ( eHorzAlign )
167 case HorizontalAlignment_CENTER: nHorzFlag = TEXT_DRAW_CENTER; break;
168 case HorizontalAlignment_RIGHT: nHorzFlag = TEXT_DRAW_RIGHT; break;
169 default:
170 break;
173 return nVertFlag | nHorzFlag;
178 //==================================================================================================================
179 //= GridTableRenderer
180 //==================================================================================================================
181 //------------------------------------------------------------------------------------------------------------------
182 GridTableRenderer::GridTableRenderer( ITableModel& _rModel )
183 :m_pImpl( new GridTableRenderer_Impl( _rModel ) )
187 //------------------------------------------------------------------------------------------------------------------
188 GridTableRenderer::~GridTableRenderer()
192 //------------------------------------------------------------------------------------------------------------------
193 bool GridTableRenderer::useGridLines() const
195 return m_pImpl->bUseGridLines;
198 //------------------------------------------------------------------------------------------------------------------
199 void GridTableRenderer::useGridLines( bool const i_use )
201 m_pImpl->bUseGridLines = i_use;
204 //------------------------------------------------------------------------------------------------------------------
205 namespace
207 Color lcl_getEffectiveColor(
208 ::boost::optional< ::Color > const & i_modelColor,
209 StyleSettings const & i_styleSettings,
210 ::Color const & ( StyleSettings::*i_getDefaultColor ) () const
213 if ( !!i_modelColor )
214 return *i_modelColor;
215 return ( i_styleSettings.*i_getDefaultColor )();
219 //------------------------------------------------------------------------------------------------------------------
220 void GridTableRenderer::PaintHeaderArea(
221 OutputDevice& _rDevice, const Rectangle& _rArea, bool _bIsColHeaderArea, bool _bIsRowHeaderArea,
222 const StyleSettings& _rStyle )
224 OSL_PRECOND( _bIsColHeaderArea || _bIsRowHeaderArea,
225 "GridTableRenderer::PaintHeaderArea: invalid area flags!" );
227 _rDevice.Push( PUSH_FILLCOLOR | PUSH_LINECOLOR );
229 Color const background = lcl_getEffectiveColor( m_pImpl->rModel.getHeaderBackgroundColor(), _rStyle, &StyleSettings::GetDialogColor );
230 _rDevice.SetFillColor( background );
232 _rDevice.SetLineColor();
233 _rDevice.DrawRect( _rArea );
235 // delimiter lines at bottom/right
236 ::boost::optional< ::Color > aLineColor( m_pImpl->rModel.getLineColor() );
237 ::Color const lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : *aLineColor;
238 _rDevice.SetLineColor( lineColor );
239 _rDevice.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() );
240 _rDevice.DrawLine( _rArea.BottomRight(), _rArea.TopRight() );
242 _rDevice.Pop();
243 (void)_bIsColHeaderArea;
244 (void)_bIsRowHeaderArea;
247 //------------------------------------------------------------------------------------------------------------------
248 void GridTableRenderer::PaintColumnHeader( ColPos _nCol, bool _bActive, bool _bSelected,
249 OutputDevice& _rDevice, const Rectangle& _rArea, const StyleSettings& _rStyle )
251 _rDevice.Push( PUSH_LINECOLOR);
253 OUString sHeaderText;
254 PColumnModel const pColumn = m_pImpl->rModel.getColumnModel( _nCol );
255 DBG_ASSERT( !!pColumn, "GridTableRenderer::PaintColumnHeader: invalid column model object!" );
256 if ( !!pColumn )
257 sHeaderText = pColumn->getName();
259 ::Color const textColor = lcl_getEffectiveColor( m_pImpl->rModel.getTextColor(), _rStyle, &StyleSettings::GetFieldTextColor );
260 _rDevice.SetTextColor( textColor );
262 Rectangle const aTextRect( lcl_getTextRenderingArea( lcl_getContentArea( *m_pImpl, _rArea ) ) );
263 sal_uLong const nDrawTextFlags = lcl_getAlignmentTextDrawFlags( *m_pImpl, _nCol ) | TEXT_DRAW_CLIP;
264 _rDevice.DrawText( aTextRect, sHeaderText, nDrawTextFlags );
266 ::boost::optional< ::Color > const aLineColor( m_pImpl->rModel.getLineColor() );
267 ::Color const lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : *aLineColor;
268 _rDevice.SetLineColor( lineColor );
269 _rDevice.DrawLine( _rArea.BottomRight(), _rArea.TopRight());
270 _rDevice.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() );
272 // draw sort indicator if the model data is sorted by the given column
273 ITableDataSort const * pSortAdapter = m_pImpl->rModel.getSortAdapter();
274 ColumnSort aCurrentSortOrder;
275 if ( pSortAdapter != NULL )
276 aCurrentSortOrder = pSortAdapter->getCurrentSortOrder();
277 if ( aCurrentSortOrder.nColumnPos == _nCol )
279 long const nHeaderHeight( _rArea.GetHeight() );
280 BitmapEx const aIndicatorBitmap = m_pImpl->aSortIndicator.getBitmapFor( _rDevice, nHeaderHeight, _rStyle,
281 aCurrentSortOrder.eSortDirection == ColumnSortAscending );
282 Size const aBitmapSize( aIndicatorBitmap.GetSizePixel() );
283 long const nSortIndicatorPaddingX = 2;
284 long const nSortIndicatorPaddingY = ( nHeaderHeight - aBitmapSize.Height() ) / 2;
286 if ( ( nDrawTextFlags & TEXT_DRAW_RIGHT ) != 0 )
288 // text is right aligned => draw the sort indicator at the left hand side
289 _rDevice.DrawBitmapEx(
290 Point( _rArea.Left() + nSortIndicatorPaddingX, _rArea.Top() + nSortIndicatorPaddingY ),
291 aIndicatorBitmap
294 else
296 // text is left-aligned or centered => draw the sort indicator at the right hand side
297 _rDevice.DrawBitmapEx(
298 Point( _rArea.Right() - nSortIndicatorPaddingX - aBitmapSize.Width(), nSortIndicatorPaddingY ),
299 aIndicatorBitmap
304 _rDevice.Pop();
306 (void)_bActive;
307 // no special painting for the active column at the moment
309 (void)_bSelected;
310 // selection for column header not yet implemented
313 //------------------------------------------------------------------------------------------------------------------
314 void GridTableRenderer::PrepareRow( RowPos _nRow, bool i_hasControlFocus, bool _bSelected,
315 OutputDevice& _rDevice, const Rectangle& _rRowArea, const StyleSettings& _rStyle )
317 // remember the row for subsequent calls to the other ->ITableRenderer methods
318 m_pImpl->nCurrentRow = _nRow;
320 _rDevice.Push( PUSH_FILLCOLOR | PUSH_LINECOLOR);
322 ::Color backgroundColor = _rStyle.GetFieldColor();
324 ::boost::optional< ::Color > const aLineColor( m_pImpl->rModel.getLineColor() );
325 ::Color lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : *aLineColor;
327 ::Color const activeSelectionBackColor =
328 lcl_getEffectiveColor( m_pImpl->rModel.getActiveSelectionBackColor(), _rStyle, &StyleSettings::GetHighlightColor );
329 if ( _bSelected )
331 // selected rows use the background color from the style
332 backgroundColor = i_hasControlFocus
333 ? activeSelectionBackColor
334 : lcl_getEffectiveColor( m_pImpl->rModel.getInactiveSelectionBackColor(), _rStyle, &StyleSettings::GetDeactiveColor );
335 if ( !aLineColor )
336 lineColor = backgroundColor;
338 else
340 ::boost::optional< ::std::vector< ::Color > > aRowColors = m_pImpl->rModel.getRowBackgroundColors();
341 if ( !aRowColors )
343 // use alternating default colors
344 Color const fieldColor = _rStyle.GetFieldColor();
345 if ( _rStyle.GetHighContrastMode() || ( ( m_pImpl->nCurrentRow % 2 ) == 0 ) )
347 backgroundColor = fieldColor;
349 else
351 Color hilightColor = activeSelectionBackColor;
352 hilightColor.SetRed( 9 * ( fieldColor.GetRed() - hilightColor.GetRed() ) / 10 + hilightColor.GetRed() );
353 hilightColor.SetGreen( 9 * ( fieldColor.GetGreen() - hilightColor.GetGreen() ) / 10 + hilightColor.GetGreen() );
354 hilightColor.SetBlue( 9 * ( fieldColor.GetBlue() - hilightColor.GetBlue() ) / 10 + hilightColor.GetBlue() );
355 backgroundColor = hilightColor;
358 else
360 if ( aRowColors->empty() )
362 // all colors have the same background color
363 backgroundColor = _rStyle.GetFieldColor();
365 else
367 backgroundColor = aRowColors->at( m_pImpl->nCurrentRow % aRowColors->size() );
372 //m_pImpl->bUseGridLines ? _rDevice.SetLineColor( lineColor ) : _rDevice.SetLineColor();
373 _rDevice.SetLineColor();
374 _rDevice.SetFillColor( backgroundColor );
375 _rDevice.DrawRect( _rRowArea );
377 _rDevice.Pop();
380 //------------------------------------------------------------------------------------------------------------------
381 void GridTableRenderer::PaintRowHeader( bool i_hasControlFocus, bool _bSelected, OutputDevice& _rDevice, const Rectangle& _rArea,
382 const StyleSettings& _rStyle )
384 _rDevice.Push( PUSH_LINECOLOR | PUSH_TEXTCOLOR );
386 ::boost::optional< ::Color > const aLineColor( m_pImpl->rModel.getLineColor() );
387 ::Color const lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : *aLineColor;
388 _rDevice.SetLineColor( lineColor );
389 _rDevice.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() );
391 Any const rowHeading( m_pImpl->rModel.getRowHeading( m_pImpl->nCurrentRow ) );
392 OUString const rowTitle( m_pImpl->aStringConverter.convertToString( rowHeading ) );
393 if ( !rowTitle.isEmpty() )
395 ::Color const textColor = lcl_getEffectiveColor( m_pImpl->rModel.getHeaderTextColor(), _rStyle, &StyleSettings::GetFieldTextColor );
396 _rDevice.SetTextColor( textColor );
398 Rectangle const aTextRect( lcl_getTextRenderingArea( lcl_getContentArea( *m_pImpl, _rArea ) ) );
399 sal_uLong const nDrawTextFlags = lcl_getAlignmentTextDrawFlags( *m_pImpl, 0 ) | TEXT_DRAW_CLIP;
400 // TODO: is using the horizontal alignment of the 0'th column a good idea here? This is pretty ... arbitray ..
401 _rDevice.DrawText( aTextRect, rowTitle, nDrawTextFlags );
404 (void)i_hasControlFocus;
405 (void)_bSelected;
406 _rDevice.Pop();
409 //------------------------------------------------------------------------------------------------------------------
410 struct GridTableRenderer::CellRenderContext
412 OutputDevice& rDevice;
413 Rectangle const aContentArea;
414 StyleSettings const & rStyle;
415 ColPos const nColumn;
416 bool const bSelected;
417 bool const bHasControlFocus;
419 CellRenderContext( OutputDevice& i_device, Rectangle const & i_contentArea,
420 StyleSettings const & i_style, ColPos const i_column, bool const i_selected, bool const i_hasControlFocus )
421 :rDevice( i_device )
422 ,aContentArea( i_contentArea )
423 ,rStyle( i_style )
424 ,nColumn( i_column )
425 ,bSelected( i_selected )
426 ,bHasControlFocus( i_hasControlFocus )
431 //------------------------------------------------------------------------------------------------------------------
432 void GridTableRenderer::PaintCell( ColPos const i_column, bool _bSelected, bool i_hasControlFocus,
433 OutputDevice& _rDevice, const Rectangle& _rArea, const StyleSettings& _rStyle )
435 _rDevice.Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
437 Rectangle const aContentArea( lcl_getContentArea( *m_pImpl, _rArea ) );
438 CellRenderContext const aRenderContext( _rDevice, aContentArea, _rStyle, i_column, _bSelected, i_hasControlFocus );
439 impl_paintCellContent( aRenderContext );
441 if ( m_pImpl->bUseGridLines )
443 ::boost::optional< ::Color > aLineColor( m_pImpl->rModel.getLineColor() );
444 ::Color lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : *aLineColor;
446 if ( _bSelected && !aLineColor )
448 // if no line color is specified by the model, use the usual selection color for lines in selected cells
449 lineColor = i_hasControlFocus
450 ? lcl_getEffectiveColor( m_pImpl->rModel.getActiveSelectionBackColor(), _rStyle, &StyleSettings::GetHighlightColor )
451 : lcl_getEffectiveColor( m_pImpl->rModel.getInactiveSelectionBackColor(), _rStyle, &StyleSettings::GetDeactiveColor );
454 _rDevice.SetLineColor( lineColor );
455 _rDevice.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() );
456 _rDevice.DrawLine( _rArea.BottomRight(), _rArea.TopRight() );
459 _rDevice.Pop();
462 //------------------------------------------------------------------------------------------------------------------
463 void GridTableRenderer::impl_paintCellImage( CellRenderContext const & i_context, Image const & i_image )
465 Point imagePos( Point( i_context.aContentArea.Left(), i_context.aContentArea.Top() ) );
466 Size imageSize = i_image.GetSizePixel();
467 if ( i_context.aContentArea.GetWidth() > imageSize.Width() )
469 const HorizontalAlignment eHorzAlign = m_pImpl->rModel.getColumnModel( i_context.nColumn )->getHorizontalAlign();
470 switch ( eHorzAlign )
472 case HorizontalAlignment_CENTER:
473 imagePos.X() += ( i_context.aContentArea.GetWidth() - imageSize.Width() ) / 2;
474 break;
475 case HorizontalAlignment_RIGHT:
476 imagePos.X() = i_context.aContentArea.Right() - imageSize.Width();
477 break;
478 default:
479 break;
483 else
484 imageSize.Width() = i_context.aContentArea.GetWidth();
486 if ( i_context.aContentArea.GetHeight() > imageSize.Height() )
488 const VerticalAlignment eVertAlign = m_pImpl->rModel.getVerticalAlign();
489 switch ( eVertAlign )
491 case VerticalAlignment_MIDDLE:
492 imagePos.Y() += ( i_context.aContentArea.GetHeight() - imageSize.Height() ) / 2;
493 break;
494 case VerticalAlignment_BOTTOM:
495 imagePos.Y() = i_context.aContentArea.Bottom() - imageSize.Height();
496 break;
497 default:
498 break;
501 else
502 imageSize.Height() = i_context.aContentArea.GetHeight() - 1;
504 i_context.rDevice.DrawImage( imagePos, imageSize, i_image, 0 );
507 //------------------------------------------------------------------------------------------------------------------
508 void GridTableRenderer::impl_paintCellContent( CellRenderContext const & i_context )
510 Any aCellContent;
511 m_pImpl->rModel.getCellContent( i_context.nColumn, m_pImpl->nCurrentRow, aCellContent );
513 if ( aCellContent.getValueTypeClass() == TypeClass_INTERFACE )
515 Reference< XInterface > const xContentInterface( aCellContent, UNO_QUERY );
516 if ( !xContentInterface.is() )
517 // allowed. kind of.
518 return;
520 Reference< XGraphic > const xGraphic( aCellContent, UNO_QUERY );
521 ENSURE_OR_RETURN_VOID( xGraphic.is(), "GridTableRenderer::impl_paintCellContent: only XGraphic interfaces (or NULL) are supported for painting." );
523 const Image aImage( xGraphic );
524 impl_paintCellImage( i_context, aImage );
525 return;
528 const OUString sText( m_pImpl->aStringConverter.convertToString( aCellContent ) );
529 impl_paintCellText( i_context, sText );
532 //------------------------------------------------------------------------------------------------------------------
533 void GridTableRenderer::impl_paintCellText( CellRenderContext const & i_context, OUString const & i_text )
535 if ( i_context.bSelected )
537 ::Color const textColor = i_context.bHasControlFocus
538 ? lcl_getEffectiveColor( m_pImpl->rModel.getActiveSelectionTextColor(), i_context.rStyle, &StyleSettings::GetHighlightTextColor )
539 : lcl_getEffectiveColor( m_pImpl->rModel.getInactiveSelectionTextColor(), i_context.rStyle, &StyleSettings::GetDeactiveTextColor );
540 i_context.rDevice.SetTextColor( textColor );
542 else
544 ::Color const textColor = lcl_getEffectiveColor( m_pImpl->rModel.getTextColor(), i_context.rStyle, &StyleSettings::GetFieldTextColor );
545 i_context.rDevice.SetTextColor( textColor );
548 Rectangle const textRect( lcl_getTextRenderingArea( i_context.aContentArea ) );
549 sal_uLong const nDrawTextFlags = lcl_getAlignmentTextDrawFlags( *m_pImpl, i_context.nColumn ) | TEXT_DRAW_CLIP;
550 i_context.rDevice.DrawText( textRect, i_text, nDrawTextFlags );
553 //------------------------------------------------------------------------------------------------------------------
554 void GridTableRenderer::ShowCellCursor( Window& _rView, const Rectangle& _rCursorRect)
556 _rView.ShowFocus( _rCursorRect );
559 //------------------------------------------------------------------------------------------------------------------
560 void GridTableRenderer::HideCellCursor( Window& _rView, const Rectangle& _rCursorRect)
562 (void)_rCursorRect;
563 _rView.HideFocus();
566 //------------------------------------------------------------------------------------------------------------------
567 bool GridTableRenderer::FitsIntoCell( Any const & i_cellContent, ColPos const i_colPos, RowPos const i_rowPos,
568 bool const i_active, bool const i_selected, OutputDevice& i_targetDevice, Rectangle const & i_targetArea ) const
570 if ( !i_cellContent.hasValue() )
571 return true;
573 if ( i_cellContent.getValueTypeClass() == TypeClass_INTERFACE )
575 Reference< XInterface > const xContentInterface( i_cellContent, UNO_QUERY );
576 if ( !xContentInterface.is() )
577 return true;
579 Reference< XGraphic > const xGraphic( i_cellContent, UNO_QUERY );
580 if ( xGraphic.is() )
581 // for the moment, assume it fits. We can always scale it down during painting ...
582 return true;
584 OSL_ENSURE( false, "GridTableRenderer::FitsIntoCell: only XGraphic interfaces (or NULL) are supported for painting." );
585 return true;
588 OUString const sText( m_pImpl->aStringConverter.convertToString( i_cellContent ) );
589 if ( sText.isEmpty() )
590 return true;
592 Rectangle const aTargetArea( lcl_getTextRenderingArea( lcl_getContentArea( *m_pImpl, i_targetArea ) ) );
594 long const nTextHeight = i_targetDevice.GetTextHeight();
595 if ( nTextHeight > aTargetArea.GetHeight() )
596 return false;
598 long const nTextWidth = i_targetDevice.GetTextWidth( sText );
599 if ( nTextWidth > aTargetArea.GetWidth() )
600 return false;
602 OSL_UNUSED( i_active );
603 OSL_UNUSED( i_selected );
604 OSL_UNUSED( i_rowPos );
605 OSL_UNUSED( i_colPos );
606 return true;
609 //------------------------------------------------------------------------------------------------------------------
610 bool GridTableRenderer::GetFormattedCellString( Any const & i_cellValue, ColPos const i_colPos, RowPos const i_rowPos, OUString & o_cellString ) const
612 o_cellString = m_pImpl->aStringConverter.convertToString( i_cellValue );
614 OSL_UNUSED( i_colPos );
615 OSL_UNUSED( i_rowPos );
616 return true;
619 //......................................................................................................................
620 } } // namespace svt::table
621 //......................................................................................................................
623 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */