fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svtools / source / table / gridtablerenderer.cxx
blob0d56ee5b88aea60a45485fb8d9df1ca25bbd5251
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/componentcontext.hxx>
28 #include <comphelper/processfactory.hxx>
29 #include <tools/debug.hxx>
30 #include <tools/diagnose_ex.h>
31 #include <vcl/window.hxx>
32 #include <vcl/image.hxx>
33 #include <vcl/virdev.hxx>
34 #include <vcl/decoview.hxx>
36 //......................................................................................................................
37 namespace svt { namespace table
39 //......................................................................................................................
41 using ::com::sun::star::uno::Any;
42 using ::com::sun::star::uno::Reference;
43 using ::com::sun::star::uno::UNO_QUERY;
44 using ::com::sun::star::uno::XInterface;
45 using ::com::sun::star::uno::TypeClass_INTERFACE;
46 using ::com::sun::star::graphic::XGraphic;
47 using ::com::sun::star::style::HorizontalAlignment;
48 using ::com::sun::star::style::HorizontalAlignment_LEFT;
49 using ::com::sun::star::style::HorizontalAlignment_CENTER;
50 using ::com::sun::star::style::HorizontalAlignment_RIGHT;
51 using ::com::sun::star::style::VerticalAlignment;
52 using ::com::sun::star::style::VerticalAlignment_TOP;
53 using ::com::sun::star::style::VerticalAlignment_MIDDLE;
54 using ::com::sun::star::style::VerticalAlignment_BOTTOM;
56 //==================================================================================================================
57 //= CachedSortIndicator
58 //==================================================================================================================
59 class CachedSortIndicator
61 public:
62 CachedSortIndicator()
63 :m_lastHeaderHeight( 0 )
64 ,m_lastArrowColor( COL_TRANSPARENT )
68 BitmapEx const & getBitmapFor( OutputDevice const & i_device, long const i_headerHeight, StyleSettings const & i_style, bool const i_sortAscending );
70 private:
71 long m_lastHeaderHeight;
72 Color m_lastArrowColor;
73 BitmapEx m_sortAscending;
74 BitmapEx m_sortDescending;
77 //------------------------------------------------------------------------------------------------------------------
78 BitmapEx const & CachedSortIndicator::getBitmapFor( OutputDevice const & i_device, long const i_headerHeight,
79 StyleSettings const & i_style, bool const i_sortAscending )
81 BitmapEx & rBitmap( i_sortAscending ? m_sortAscending : m_sortDescending );
82 if ( !rBitmap || ( i_headerHeight != m_lastHeaderHeight ) || ( i_style.GetActiveColor() != m_lastArrowColor ) )
84 long const nSortIndicatorWidth = 2 * i_headerHeight / 3;
85 long const nSortIndicatorHeight = 2 * nSortIndicatorWidth / 3;
87 Point const aBitmapPos( 0, 0 );
88 Size const aBitmapSize( nSortIndicatorWidth, nSortIndicatorHeight );
89 VirtualDevice aDevice( i_device, 0, 0 );
90 aDevice.SetOutputSizePixel( aBitmapSize );
92 DecorationView aDecoView( &aDevice );
93 aDecoView.DrawSymbol(
94 Rectangle( aBitmapPos, aBitmapSize ),
95 i_sortAscending ? SYMBOL_SPIN_UP : SYMBOL_SPIN_DOWN,
96 i_style.GetActiveColor()
99 rBitmap = aDevice.GetBitmapEx( aBitmapPos, aBitmapSize );
100 m_lastHeaderHeight = i_headerHeight;
101 m_lastArrowColor = i_style.GetActiveColor();
103 return rBitmap;
106 //==================================================================================================================
107 //= GridTableRenderer_Impl
108 //==================================================================================================================
109 struct GridTableRenderer_Impl
111 ITableModel& rModel;
112 RowPos nCurrentRow;
113 bool bUseGridLines;
114 CachedSortIndicator aSortIndicator;
115 CellValueConversion aStringConverter;
117 GridTableRenderer_Impl( ITableModel& _rModel )
118 :rModel( _rModel )
119 ,nCurrentRow( ROW_INVALID )
120 ,bUseGridLines( true )
121 ,aSortIndicator( )
122 ,aStringConverter()
127 //==================================================================================================================
128 //= helper
129 //==================================================================================================================
130 namespace
132 static Rectangle lcl_getContentArea( GridTableRenderer_Impl const & i_impl, Rectangle const & i_cellArea )
134 Rectangle aContentArea( i_cellArea );
135 if ( i_impl.bUseGridLines )
137 --aContentArea.Right();
138 --aContentArea.Bottom();
140 return aContentArea;
142 static Rectangle lcl_getTextRenderingArea( Rectangle const & i_contentArea )
144 Rectangle aTextArea( i_contentArea );
145 aTextArea.Left() += 2; aTextArea.Right() -= 2;
146 ++aTextArea.Top(); --aTextArea.Bottom();
147 return aTextArea;
150 static sal_uLong lcl_getAlignmentTextDrawFlags( GridTableRenderer_Impl const & i_impl, ColPos const i_columnPos )
152 sal_uLong nVertFlag = TEXT_DRAW_TOP;
153 VerticalAlignment const eVertAlign = i_impl.rModel.getVerticalAlign();
154 switch ( eVertAlign )
156 case VerticalAlignment_MIDDLE: nVertFlag = TEXT_DRAW_VCENTER; break;
157 case VerticalAlignment_BOTTOM: nVertFlag = TEXT_DRAW_BOTTOM; break;
158 default:
159 break;
162 sal_uLong nHorzFlag = TEXT_DRAW_LEFT;
163 HorizontalAlignment const eHorzAlign = i_impl.rModel.getColumnCount() > 0
164 ? i_impl.rModel.getColumnModel( i_columnPos )->getHorizontalAlign()
165 : HorizontalAlignment_CENTER;
166 switch ( eHorzAlign )
168 case HorizontalAlignment_CENTER: nHorzFlag = TEXT_DRAW_CENTER; break;
169 case HorizontalAlignment_RIGHT: nHorzFlag = TEXT_DRAW_RIGHT; break;
170 default:
171 break;
174 return nVertFlag | nHorzFlag;
179 //==================================================================================================================
180 //= GridTableRenderer
181 //==================================================================================================================
182 //------------------------------------------------------------------------------------------------------------------
183 GridTableRenderer::GridTableRenderer( ITableModel& _rModel )
184 :m_pImpl( new GridTableRenderer_Impl( _rModel ) )
188 //------------------------------------------------------------------------------------------------------------------
189 GridTableRenderer::~GridTableRenderer()
193 //------------------------------------------------------------------------------------------------------------------
194 bool GridTableRenderer::useGridLines() const
196 return m_pImpl->bUseGridLines;
199 //------------------------------------------------------------------------------------------------------------------
200 void GridTableRenderer::useGridLines( bool const i_use )
202 m_pImpl->bUseGridLines = i_use;
205 //------------------------------------------------------------------------------------------------------------------
206 namespace
208 Color lcl_getEffectiveColor(
209 ::boost::optional< ::Color > const & i_modelColor,
210 StyleSettings const & i_styleSettings,
211 ::Color const & ( StyleSettings::*i_getDefaultColor ) () const
214 if ( !!i_modelColor )
215 return *i_modelColor;
216 return ( i_styleSettings.*i_getDefaultColor )();
220 //------------------------------------------------------------------------------------------------------------------
221 void GridTableRenderer::PaintHeaderArea(
222 OutputDevice& _rDevice, const Rectangle& _rArea, bool _bIsColHeaderArea, bool _bIsRowHeaderArea,
223 const StyleSettings& _rStyle )
225 OSL_PRECOND( _bIsColHeaderArea || _bIsRowHeaderArea,
226 "GridTableRenderer::PaintHeaderArea: invalid area flags!" );
228 _rDevice.Push( PUSH_FILLCOLOR | PUSH_LINECOLOR );
230 Color const background = lcl_getEffectiveColor( m_pImpl->rModel.getHeaderBackgroundColor(), _rStyle, &StyleSettings::GetDialogColor );
231 _rDevice.SetFillColor( background );
233 _rDevice.SetLineColor();
234 _rDevice.DrawRect( _rArea );
236 // delimiter lines at bottom/right
237 ::boost::optional< ::Color > aLineColor( m_pImpl->rModel.getLineColor() );
238 ::Color const lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : *aLineColor;
239 _rDevice.SetLineColor( lineColor );
240 _rDevice.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() );
241 _rDevice.DrawLine( _rArea.BottomRight(), _rArea.TopRight() );
243 _rDevice.Pop();
244 (void)_bIsColHeaderArea;
245 (void)_bIsRowHeaderArea;
248 //------------------------------------------------------------------------------------------------------------------
249 void GridTableRenderer::PaintColumnHeader( ColPos _nCol, bool _bActive, bool _bSelected,
250 OutputDevice& _rDevice, const Rectangle& _rArea, const StyleSettings& _rStyle )
252 _rDevice.Push( PUSH_LINECOLOR);
254 String sHeaderText;
255 PColumnModel const pColumn = m_pImpl->rModel.getColumnModel( _nCol );
256 DBG_ASSERT( !!pColumn, "GridTableRenderer::PaintColumnHeader: invalid column model object!" );
257 if ( !!pColumn )
258 sHeaderText = pColumn->getName();
260 ::Color const textColor = lcl_getEffectiveColor( m_pImpl->rModel.getTextColor(), _rStyle, &StyleSettings::GetFieldTextColor );
261 _rDevice.SetTextColor( textColor );
263 Rectangle const aTextRect( lcl_getTextRenderingArea( lcl_getContentArea( *m_pImpl, _rArea ) ) );
264 sal_uLong const nDrawTextFlags = lcl_getAlignmentTextDrawFlags( *m_pImpl, _nCol ) | TEXT_DRAW_CLIP;
265 _rDevice.DrawText( aTextRect, sHeaderText, nDrawTextFlags );
267 ::boost::optional< ::Color > const aLineColor( m_pImpl->rModel.getLineColor() );
268 ::Color const lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : *aLineColor;
269 _rDevice.SetLineColor( lineColor );
270 _rDevice.DrawLine( _rArea.BottomRight(), _rArea.TopRight());
271 _rDevice.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() );
273 // draw sort indicator if the model data is sorted by the given column
274 ITableDataSort const * pSortAdapter = m_pImpl->rModel.getSortAdapter();
275 ColumnSort aCurrentSortOrder;
276 if ( pSortAdapter != NULL )
277 aCurrentSortOrder = pSortAdapter->getCurrentSortOrder();
278 if ( aCurrentSortOrder.nColumnPos == _nCol )
280 long const nHeaderHeight( _rArea.GetHeight() );
281 BitmapEx const aIndicatorBitmap = m_pImpl->aSortIndicator.getBitmapFor( _rDevice, nHeaderHeight, _rStyle,
282 aCurrentSortOrder.eSortDirection == ColumnSortAscending );
283 Size const aBitmapSize( aIndicatorBitmap.GetSizePixel() );
284 long const nSortIndicatorPaddingX = 2;
285 long const nSortIndicatorPaddingY = ( nHeaderHeight - aBitmapSize.Height() ) / 2;
287 if ( ( nDrawTextFlags & TEXT_DRAW_RIGHT ) != 0 )
289 // text is right aligned => draw the sort indicator at the left hand side
290 _rDevice.DrawBitmapEx(
291 Point( _rArea.Left() + nSortIndicatorPaddingX, _rArea.Top() + nSortIndicatorPaddingY ),
292 aIndicatorBitmap
295 else
297 // text is left-aligned or centered => draw the sort indicator at the right hand side
298 _rDevice.DrawBitmapEx(
299 Point( _rArea.Right() - nSortIndicatorPaddingX - aBitmapSize.Width(), nSortIndicatorPaddingY ),
300 aIndicatorBitmap
305 _rDevice.Pop();
307 (void)_bActive;
308 // no special painting for the active column at the moment
310 (void)_bSelected;
311 // selection for column header not yet implemented
314 //------------------------------------------------------------------------------------------------------------------
315 void GridTableRenderer::PrepareRow( RowPos _nRow, bool i_hasControlFocus, bool _bSelected,
316 OutputDevice& _rDevice, const Rectangle& _rRowArea, const StyleSettings& _rStyle )
318 // remember the row for subsequent calls to the other ->ITableRenderer methods
319 m_pImpl->nCurrentRow = _nRow;
321 _rDevice.Push( PUSH_FILLCOLOR | PUSH_LINECOLOR);
323 ::Color backgroundColor = _rStyle.GetFieldColor();
325 ::boost::optional< ::Color > const aLineColor( m_pImpl->rModel.getLineColor() );
326 ::Color lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : *aLineColor;
328 ::Color const activeSelectionBackColor =
329 lcl_getEffectiveColor( m_pImpl->rModel.getActiveSelectionBackColor(), _rStyle, &StyleSettings::GetHighlightColor );
330 if ( _bSelected )
332 // selected rows use the background color from the style
333 backgroundColor = i_hasControlFocus
334 ? activeSelectionBackColor
335 : lcl_getEffectiveColor( m_pImpl->rModel.getInactiveSelectionBackColor(), _rStyle, &StyleSettings::GetDeactiveColor );
336 if ( !aLineColor )
337 lineColor = backgroundColor;
339 else
341 ::boost::optional< ::std::vector< ::Color > > aRowColors = m_pImpl->rModel.getRowBackgroundColors();
342 if ( !aRowColors )
344 // use alternating default colors
345 Color const fieldColor = _rStyle.GetFieldColor();
346 if ( _rStyle.GetHighContrastMode() || ( ( m_pImpl->nCurrentRow % 2 ) == 0 ) )
348 backgroundColor = fieldColor;
350 else
352 Color hilightColor = activeSelectionBackColor;
353 hilightColor.SetRed( 9 * ( fieldColor.GetRed() - hilightColor.GetRed() ) / 10 + hilightColor.GetRed() );
354 hilightColor.SetGreen( 9 * ( fieldColor.GetGreen() - hilightColor.GetGreen() ) / 10 + hilightColor.GetGreen() );
355 hilightColor.SetBlue( 9 * ( fieldColor.GetBlue() - hilightColor.GetBlue() ) / 10 + hilightColor.GetBlue() );
356 backgroundColor = hilightColor;
359 else
361 if ( aRowColors->empty() )
363 // all colors have the same background color
364 backgroundColor = _rStyle.GetFieldColor();
366 else
368 backgroundColor = aRowColors->at( m_pImpl->nCurrentRow % aRowColors->size() );
373 //m_pImpl->bUseGridLines ? _rDevice.SetLineColor( lineColor ) : _rDevice.SetLineColor();
374 _rDevice.SetLineColor();
375 _rDevice.SetFillColor( backgroundColor );
376 _rDevice.DrawRect( _rRowArea );
378 _rDevice.Pop();
381 //------------------------------------------------------------------------------------------------------------------
382 void GridTableRenderer::PaintRowHeader( bool i_hasControlFocus, bool _bSelected, OutputDevice& _rDevice, const Rectangle& _rArea,
383 const StyleSettings& _rStyle )
385 _rDevice.Push( PUSH_LINECOLOR | PUSH_TEXTCOLOR );
387 ::boost::optional< ::Color > const aLineColor( m_pImpl->rModel.getLineColor() );
388 ::Color const lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : *aLineColor;
389 _rDevice.SetLineColor( lineColor );
390 _rDevice.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() );
392 Any const rowHeading( m_pImpl->rModel.getRowHeading( m_pImpl->nCurrentRow ) );
393 OUString const rowTitle( m_pImpl->aStringConverter.convertToString( rowHeading ) );
394 if ( !rowTitle.isEmpty() )
396 ::Color const textColor = lcl_getEffectiveColor( m_pImpl->rModel.getHeaderTextColor(), _rStyle, &StyleSettings::GetFieldTextColor );
397 _rDevice.SetTextColor( textColor );
399 Rectangle const aTextRect( lcl_getTextRenderingArea( lcl_getContentArea( *m_pImpl, _rArea ) ) );
400 sal_uLong const nDrawTextFlags = lcl_getAlignmentTextDrawFlags( *m_pImpl, 0 ) | TEXT_DRAW_CLIP;
401 // TODO: is using the horizontal alignment of the 0'th column a good idea here? This is pretty ... arbitray ..
402 _rDevice.DrawText( aTextRect, rowTitle, nDrawTextFlags );
405 (void)i_hasControlFocus;
406 (void)_bSelected;
407 _rDevice.Pop();
410 //------------------------------------------------------------------------------------------------------------------
411 struct GridTableRenderer::CellRenderContext
413 OutputDevice& rDevice;
414 Rectangle const aContentArea;
415 StyleSettings const & rStyle;
416 ColPos const nColumn;
417 bool const bSelected;
418 bool const bHasControlFocus;
420 CellRenderContext( OutputDevice& i_device, Rectangle const & i_contentArea,
421 StyleSettings const & i_style, ColPos const i_column, bool const i_selected, bool const i_hasControlFocus )
422 :rDevice( i_device )
423 ,aContentArea( i_contentArea )
424 ,rStyle( i_style )
425 ,nColumn( i_column )
426 ,bSelected( i_selected )
427 ,bHasControlFocus( i_hasControlFocus )
432 //------------------------------------------------------------------------------------------------------------------
433 void GridTableRenderer::PaintCell( ColPos const i_column, bool _bSelected, bool i_hasControlFocus,
434 OutputDevice& _rDevice, const Rectangle& _rArea, const StyleSettings& _rStyle )
436 _rDevice.Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
438 Rectangle const aContentArea( lcl_getContentArea( *m_pImpl, _rArea ) );
439 CellRenderContext const aRenderContext( _rDevice, aContentArea, _rStyle, i_column, _bSelected, i_hasControlFocus );
440 impl_paintCellContent( aRenderContext );
442 if ( m_pImpl->bUseGridLines )
444 ::boost::optional< ::Color > aLineColor( m_pImpl->rModel.getLineColor() );
445 ::Color lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : *aLineColor;
447 if ( _bSelected && !aLineColor )
449 // if no line color is specified by the model, use the usual selection color for lines in selected cells
450 lineColor = i_hasControlFocus
451 ? lcl_getEffectiveColor( m_pImpl->rModel.getActiveSelectionBackColor(), _rStyle, &StyleSettings::GetHighlightColor )
452 : lcl_getEffectiveColor( m_pImpl->rModel.getInactiveSelectionBackColor(), _rStyle, &StyleSettings::GetDeactiveColor );
455 _rDevice.SetLineColor( lineColor );
456 _rDevice.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() );
457 _rDevice.DrawLine( _rArea.BottomRight(), _rArea.TopRight() );
460 _rDevice.Pop();
463 //------------------------------------------------------------------------------------------------------------------
464 void GridTableRenderer::impl_paintCellImage( CellRenderContext const & i_context, Image const & i_image )
466 Point imagePos( Point( i_context.aContentArea.Left(), i_context.aContentArea.Top() ) );
467 Size imageSize = i_image.GetSizePixel();
468 if ( i_context.aContentArea.GetWidth() > imageSize.Width() )
470 const HorizontalAlignment eHorzAlign = m_pImpl->rModel.getColumnModel( i_context.nColumn )->getHorizontalAlign();
471 switch ( eHorzAlign )
473 case HorizontalAlignment_CENTER:
474 imagePos.X() += ( i_context.aContentArea.GetWidth() - imageSize.Width() ) / 2;
475 break;
476 case HorizontalAlignment_RIGHT:
477 imagePos.X() = i_context.aContentArea.Right() - imageSize.Width();
478 break;
479 default:
480 break;
484 else
485 imageSize.Width() = i_context.aContentArea.GetWidth();
487 if ( i_context.aContentArea.GetHeight() > imageSize.Height() )
489 const VerticalAlignment eVertAlign = m_pImpl->rModel.getVerticalAlign();
490 switch ( eVertAlign )
492 case VerticalAlignment_MIDDLE:
493 imagePos.Y() += ( i_context.aContentArea.GetHeight() - imageSize.Height() ) / 2;
494 break;
495 case VerticalAlignment_BOTTOM:
496 imagePos.Y() = i_context.aContentArea.Bottom() - imageSize.Height();
497 break;
498 default:
499 break;
502 else
503 imageSize.Height() = i_context.aContentArea.GetHeight() - 1;
505 i_context.rDevice.DrawImage( imagePos, imageSize, i_image, 0 );
508 //------------------------------------------------------------------------------------------------------------------
509 void GridTableRenderer::impl_paintCellContent( CellRenderContext const & i_context )
511 Any aCellContent;
512 m_pImpl->rModel.getCellContent( i_context.nColumn, m_pImpl->nCurrentRow, aCellContent );
514 if ( aCellContent.getValueTypeClass() == TypeClass_INTERFACE )
516 Reference< XInterface > const xContentInterface( aCellContent, UNO_QUERY );
517 if ( !xContentInterface.is() )
518 // allowed. kind of.
519 return;
521 Reference< XGraphic > const xGraphic( aCellContent, UNO_QUERY );
522 ENSURE_OR_RETURN_VOID( xGraphic.is(), "GridTableRenderer::impl_paintCellContent: only XGraphic interfaces (or NULL) are supported for painting." );
524 const Image aImage( xGraphic );
525 impl_paintCellImage( i_context, aImage );
526 return;
529 const OUString sText( m_pImpl->aStringConverter.convertToString( aCellContent ) );
530 impl_paintCellText( i_context, sText );
533 //------------------------------------------------------------------------------------------------------------------
534 void GridTableRenderer::impl_paintCellText( CellRenderContext const & i_context, OUString const & i_text )
536 if ( i_context.bSelected )
538 ::Color const textColor = i_context.bHasControlFocus
539 ? lcl_getEffectiveColor( m_pImpl->rModel.getActiveSelectionTextColor(), i_context.rStyle, &StyleSettings::GetHighlightTextColor )
540 : lcl_getEffectiveColor( m_pImpl->rModel.getInactiveSelectionTextColor(), i_context.rStyle, &StyleSettings::GetDeactiveTextColor );
541 i_context.rDevice.SetTextColor( textColor );
543 else
545 ::Color const textColor = lcl_getEffectiveColor( m_pImpl->rModel.getTextColor(), i_context.rStyle, &StyleSettings::GetFieldTextColor );
546 i_context.rDevice.SetTextColor( textColor );
549 Rectangle const textRect( lcl_getTextRenderingArea( i_context.aContentArea ) );
550 sal_uLong const nDrawTextFlags = lcl_getAlignmentTextDrawFlags( *m_pImpl, i_context.nColumn ) | TEXT_DRAW_CLIP;
551 i_context.rDevice.DrawText( textRect, i_text, nDrawTextFlags );
554 //------------------------------------------------------------------------------------------------------------------
555 void GridTableRenderer::ShowCellCursor( Window& _rView, const Rectangle& _rCursorRect)
557 _rView.ShowFocus( _rCursorRect );
560 //------------------------------------------------------------------------------------------------------------------
561 void GridTableRenderer::HideCellCursor( Window& _rView, const Rectangle& _rCursorRect)
563 (void)_rCursorRect;
564 _rView.HideFocus();
567 //------------------------------------------------------------------------------------------------------------------
568 bool GridTableRenderer::FitsIntoCell( Any const & i_cellContent, ColPos const i_colPos, RowPos const i_rowPos,
569 bool const i_active, bool const i_selected, OutputDevice& i_targetDevice, Rectangle const & i_targetArea ) const
571 if ( !i_cellContent.hasValue() )
572 return true;
574 if ( i_cellContent.getValueTypeClass() == TypeClass_INTERFACE )
576 Reference< XInterface > const xContentInterface( i_cellContent, UNO_QUERY );
577 if ( !xContentInterface.is() )
578 return true;
580 Reference< XGraphic > const xGraphic( i_cellContent, UNO_QUERY );
581 if ( xGraphic.is() )
582 // for the moment, assume it fits. We can always scale it down during painting ...
583 return true;
585 OSL_ENSURE( false, "GridTableRenderer::FitsIntoCell: only XGraphic interfaces (or NULL) are supported for painting." );
586 return true;
589 OUString const sText( m_pImpl->aStringConverter.convertToString( i_cellContent ) );
590 if ( sText.isEmpty() )
591 return true;
593 Rectangle const aTargetArea( lcl_getTextRenderingArea( lcl_getContentArea( *m_pImpl, i_targetArea ) ) );
595 long const nTextHeight = i_targetDevice.GetTextHeight();
596 if ( nTextHeight > aTargetArea.GetHeight() )
597 return false;
599 long const nTextWidth = i_targetDevice.GetTextWidth( sText );
600 if ( nTextWidth > aTargetArea.GetWidth() )
601 return false;
603 OSL_UNUSED( i_active );
604 OSL_UNUSED( i_selected );
605 OSL_UNUSED( i_rowPos );
606 OSL_UNUSED( i_colPos );
607 return true;
610 //------------------------------------------------------------------------------------------------------------------
611 bool GridTableRenderer::GetFormattedCellString( Any const & i_cellValue, ColPos const i_colPos, RowPos const i_rowPos, OUString & o_cellString ) const
613 o_cellString = m_pImpl->aStringConverter.convertToString( i_cellValue );
615 OSL_UNUSED( i_colPos );
616 OSL_UNUSED( i_rowPos );
617 return true;
620 //......................................................................................................................
621 } } // namespace svt::table
622 //......................................................................................................................
624 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */