Debian Codegraph @

toolkit/source/controls/table/gridtablerenderer.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21 #include "cellvalueconversion.hxx"
22 #include <controls/table/gridtablerenderer.hxx>
23 #include <controls/table/tablesort.hxx>
24
25 #include <com/sun/star/graphic/XGraphic.hpp>
26
27 #include <tools/debug.hxx>
28 #include <comphelper/diagnose_ex.hxx>
29 #include <vcl/window.hxx>
30 #include <vcl/image.hxx>
31 #include <vcl/virdev.hxx>
32 #include <vcl/decoview.hxx>
33 #include <vcl/settings.hxx>
34
35
36 namespace svt::table
37 {
38 using ::css::uno::Any;
39 using ::css::uno::Reference;
40 using ::css::uno::UNO_QUERY;
41 using ::css::uno::XInterface;
42 using ::css::uno::TypeClass_INTERFACE;
43 using ::css::graphic::XGraphic;
44 using ::css::style::HorizontalAlignment;
45 using ::css::style::HorizontalAlignment_CENTER;
46 using ::css::style::HorizontalAlignment_RIGHT;
47 using ::css::style::VerticalAlignment;
48 using ::css::style::VerticalAlignment_MIDDLE;
49 using ::css::style::VerticalAlignment_BOTTOM;
50
51
52 //= CachedSortIndicator
53
54 namespace {
55
56 class CachedSortIndicator
57 {
58 public:
59 CachedSortIndicator()
60 : m_lastHeaderHeight( 0 )
61 , m_lastArrowColor( COL_TRANSPARENT )
62 {
63 }
64
65 Bitmap const & getBitmapFor(vcl::RenderContext const & i_device, tools::Long const i_headerHeight,
66 StyleSettings const & i_style, bool const i_sortAscending);
67
68 private:
69 tools::Long m_lastHeaderHeight;
70 Color m_lastArrowColor;
71 Bitmap m_sortAscending;
72 Bitmap m_sortDescending;
73 };
74
75 }
76
77 Bitmap const & CachedSortIndicator::getBitmapFor(vcl::RenderContext const& i_device, tools::Long const i_headerHeight,
78 StyleSettings const & i_style, bool const i_sortAscending )
79 {
80 Bitmap& rBitmap(i_sortAscending ? m_sortAscending : m_sortDescending);
81 if (rBitmap.IsEmpty() || (i_headerHeight != m_lastHeaderHeight) || (i_style.GetActiveColor() != m_lastArrowColor))
82 {
83 tools::Long const nSortIndicatorWidth = 2 * i_headerHeight / 3;
84 tools::Long const nSortIndicatorHeight = 2 * nSortIndicatorWidth / 3;
85
86 Point const aBitmapPos( 0, 0 );
87 Size const aBitmapSize( nSortIndicatorWidth, nSortIndicatorHeight );
88 ScopedVclPtrInstance< VirtualDevice > aDevice(i_device, DeviceFormat::WITH_ALPHA);
89 aDevice->SetOutputSizePixel( aBitmapSize );
90
91 DecorationView aDecoView(aDevice.get());
92 aDecoView.DrawSymbol(tools::Rectangle(aBitmapPos, aBitmapSize),
93 i_sortAscending ? SymbolType::SPIN_UP : SymbolType::SPIN_DOWN,
94 i_style.GetActiveColor());
95
96 rBitmap = aDevice->GetBitmap(aBitmapPos, aBitmapSize);
97 m_lastHeaderHeight = i_headerHeight;
98 m_lastArrowColor = i_style.GetActiveColor();
99 }
100 return rBitmap;
101 }
102
103
104 //= GridTableRenderer_Impl
105
106 struct GridTableRenderer_Impl
107 {
108 ITableModel& rModel;
109 RowPos nCurrentRow;
110 bool bUseGridLines;
111 CachedSortIndicator aSortIndicator;
112 CellValueConversion aStringConverter;
113
114 explicit GridTableRenderer_Impl( ITableModel& _rModel )
115 : rModel( _rModel )
116 , nCurrentRow( ROW_INVALID )
117 , bUseGridLines( true )
118 , aSortIndicator( )
119 , aStringConverter()
120 {
121 }
122 };
123
124
125 //= helper
126
127 namespace
128 {
129 tools::Rectangle lcl_getContentArea( GridTableRenderer_Impl const & i_impl, tools::Rectangle const & i_cellArea )
130 {
131 tools::Rectangle aContentArea( i_cellArea );
132 if ( i_impl.bUseGridLines )
133 {
134 aContentArea.AdjustRight( -1 );
135 aContentArea.AdjustBottom( -1 );
136 }
137 return aContentArea;
138 }
139 tools::Rectangle lcl_getTextRenderingArea( tools::Rectangle const & i_contentArea )
140 {
141 tools::Rectangle aTextArea( i_contentArea );
142 aTextArea.AdjustLeft(2 ); aTextArea.AdjustRight( -2 );
143 aTextArea.AdjustTop( 1 ); aTextArea.AdjustBottom( -1 );
144 return aTextArea;
145 }
146
147 DrawTextFlags lcl_getAlignmentTextDrawFlags( GridTableRenderer_Impl const & i_impl, ColPos const i_columnPos )
148 {
149 DrawTextFlags nVertFlag = DrawTextFlags::Top;
150 VerticalAlignment const eVertAlign = i_impl.rModel.getVerticalAlign();
151 switch ( eVertAlign )
152 {
153 case VerticalAlignment_MIDDLE: nVertFlag = DrawTextFlags::VCenter; break;
154 case VerticalAlignment_BOTTOM: nVertFlag = DrawTextFlags::Bottom; break;
155 default:
156 break;
157 }
158
159 DrawTextFlags nHorzFlag = DrawTextFlags::Left;
160 HorizontalAlignment const eHorzAlign = i_impl.rModel.getColumnCount() > 0
161 ? i_impl.rModel.getColumnModel( i_columnPos )->getHorizontalAlign()
162 : HorizontalAlignment_CENTER;
163 switch ( eHorzAlign )
164 {
165 case HorizontalAlignment_CENTER: nHorzFlag = DrawTextFlags::Center; break;
166 case HorizontalAlignment_RIGHT: nHorzFlag = DrawTextFlags::Right; break;
167 default:
168 break;
169 }
170
171 return nVertFlag | nHorzFlag;
172 }
173
174 }
175
176
177 //= GridTableRenderer
178
179
180 GridTableRenderer::GridTableRenderer( ITableModel& _rModel )
181 :m_pImpl( new GridTableRenderer_Impl( _rModel ) )
182 {
183 }
184
185
186 GridTableRenderer::~GridTableRenderer()
187 {
188 }
189
190
191 bool GridTableRenderer::useGridLines() const
192 {
193 return m_pImpl->bUseGridLines;
194 }
195
196
197 void GridTableRenderer::useGridLines( bool const i_use )
198 {
199 m_pImpl->bUseGridLines = i_use;
200 }
201
202
203 namespace
204 {
205 Color lcl_getEffectiveColor(std::optional<Color> const& i_modelColor,
206 StyleSettings const& i_styleSettings,
207 Color const& (StyleSettings::*i_getDefaultColor) () const)
208 {
209 if (!!i_modelColor)
210 return *i_modelColor;
211 return (i_styleSettings.*i_getDefaultColor)();
212 }
213 }
214
215
216 void GridTableRenderer::PaintHeaderArea(vcl::RenderContext& rRenderContext, const tools::Rectangle& _rArea,
217 bool _bIsColHeaderArea, bool _bIsRowHeaderArea, const StyleSettings& _rStyle)
218 {
219 OSL_PRECOND(_bIsColHeaderArea || _bIsRowHeaderArea, "GridTableRenderer::PaintHeaderArea: invalid area flags!");
220
221 auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::FILLCOLOR | vcl::PushFlags::LINECOLOR);
222
223 Color const background = lcl_getEffectiveColor(m_pImpl->rModel.getHeaderBackgroundColor(),
224 _rStyle, &StyleSettings::GetDialogColor);
225 rRenderContext.SetFillColor(background);
226
227 rRenderContext.SetLineColor();
228 rRenderContext.DrawRect(_rArea);
229
230 // delimiter lines at bottom/right
231 std::optional<Color> aLineColor(m_pImpl->rModel.getLineColor());
232 Color const lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : *aLineColor;
233 rRenderContext.SetLineColor(lineColor);
234 rRenderContext.DrawLine(_rArea.BottomLeft(), _rArea.BottomRight());
235 rRenderContext.DrawLine(_rArea.BottomRight(), _rArea.TopRight());
236 }
237
238
239 void GridTableRenderer::PaintColumnHeader(
240 ColPos _nCol,
241 vcl::RenderContext& rRenderContext,
242 const tools::Rectangle& _rArea, const StyleSettings& _rStyle)
243 {
244 auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::LINECOLOR);
245
246 OUString sHeaderText;
247 PColumnModel const pColumn = m_pImpl->rModel.getColumnModel( _nCol );
248 DBG_ASSERT( pColumn, "GridTableRenderer::PaintColumnHeader: invalid column model object!" );
249 if ( pColumn )
250 sHeaderText = pColumn->getName();
251
252 Color const textColor = lcl_getEffectiveColor( m_pImpl->rModel.getTextColor(), _rStyle, &StyleSettings::GetFieldTextColor );
253 rRenderContext.SetTextColor(textColor);
254
255 tools::Rectangle const aTextRect( lcl_getTextRenderingArea( lcl_getContentArea( *m_pImpl, _rArea ) ) );
256 DrawTextFlags nDrawTextFlags = lcl_getAlignmentTextDrawFlags( *m_pImpl, _nCol ) | DrawTextFlags::Clip;
257 if (!m_pImpl->rModel.isEnabled())
258 nDrawTextFlags |= DrawTextFlags::Disable;
259 rRenderContext.DrawText( aTextRect, sHeaderText, nDrawTextFlags );
260
261 std::optional<Color> const aLineColor( m_pImpl->rModel.getLineColor() );
262 Color const lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : *aLineColor;
263 rRenderContext.SetLineColor( lineColor );
264 rRenderContext.DrawLine( _rArea.BottomRight(), _rArea.TopRight());
265 rRenderContext.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() );
266
267 // draw sort indicator if the model data is sorted by the given column
268 ITableDataSort const * pSortAdapter = m_pImpl->rModel.getSortAdapter();
269 ColumnSort aCurrentSortOrder;
270 if ( pSortAdapter != nullptr )
271 aCurrentSortOrder = pSortAdapter->getCurrentSortOrder();
272 if ( aCurrentSortOrder.nColumnPos == _nCol )
273 {
274 tools::Long const nHeaderHeight( _rArea.GetHeight() );
275 Bitmap const aIndicatorBitmap = m_pImpl->aSortIndicator.getBitmapFor(rRenderContext, nHeaderHeight, _rStyle,
276 aCurrentSortOrder.eSortDirection == ColumnSortAscending);
277 Size const aBitmapSize( aIndicatorBitmap.GetSizePixel() );
278 tools::Long const nSortIndicatorPaddingX = 2;
279 tools::Long const nSortIndicatorPaddingY = ( nHeaderHeight - aBitmapSize.Height() ) / 2;
280
281 if ( nDrawTextFlags & DrawTextFlags::Right )
282 {
283 // text is right aligned => draw the sort indicator at the left hand side
284 rRenderContext.DrawBitmap(Point(_rArea.Left() + nSortIndicatorPaddingX, _rArea.Top() + nSortIndicatorPaddingY),
285 aIndicatorBitmap);
286 }
287 else
288 {
289 // text is left-aligned or centered => draw the sort indicator at the right hand side
290 rRenderContext.DrawBitmap(Point(_rArea.Right() - nSortIndicatorPaddingX - aBitmapSize.Width(), nSortIndicatorPaddingY),
291 aIndicatorBitmap);
292 }
293 }
294 }
295
296
297 void GridTableRenderer::PrepareRow(RowPos _nRow, bool i_hasControlFocus, bool _bSelected, vcl::RenderContext& rRenderContext,
298 const tools::Rectangle& _rRowArea, const StyleSettings& _rStyle)
299 {
300 // remember the row for subsequent calls to the other ->ITableRenderer methods
301 m_pImpl->nCurrentRow = _nRow;
302
303 auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::FILLCOLOR | vcl::PushFlags::LINECOLOR);
304
305 Color backgroundColor = _rStyle.GetFieldColor();
306
307 Color const activeSelectionBackColor = lcl_getEffectiveColor(m_pImpl->rModel.getActiveSelectionBackColor(),
308 _rStyle, &StyleSettings::GetHighlightColor);
309 if (_bSelected)
310 {
311 // selected rows use the background color from the style
312 backgroundColor = i_hasControlFocus
313 ? activeSelectionBackColor
314 : lcl_getEffectiveColor(m_pImpl->rModel.getInactiveSelectionBackColor(), _rStyle, &StyleSettings::GetDeactiveColor);
315 }
316 else
317 {
318 std::optional< std::vector<Color> > aRowColors = m_pImpl->rModel.getRowBackgroundColors();
319 if (!aRowColors)
320 {
321 // use alternating default colors
322 Color const fieldColor = _rStyle.GetFieldColor();
323 if (_rStyle.GetHighContrastMode() || ((m_pImpl->nCurrentRow % 2) == 0))
324 {
325 backgroundColor = fieldColor;
326 }
327 else
328 {
329 Color hilightColor = activeSelectionBackColor;
330 hilightColor.SetRed( 9 * ( fieldColor.GetRed() - hilightColor.GetRed() ) / 10 + hilightColor.GetRed() );
331 hilightColor.SetGreen( 9 * ( fieldColor.GetGreen() - hilightColor.GetGreen() ) / 10 + hilightColor.GetGreen() );
332 hilightColor.SetBlue( 9 * ( fieldColor.GetBlue() - hilightColor.GetBlue() ) / 10 + hilightColor.GetBlue() );
333 backgroundColor = hilightColor;
334 }
335 }
336 else
337 {
338 if (aRowColors->empty())
339 {
340 // all colors have the same background color
341 backgroundColor = _rStyle.GetFieldColor();
342 }
343 else
344 {
345 backgroundColor = aRowColors->at(m_pImpl->nCurrentRow % aRowColors->size());
346 }
347 }
348 }
349
350 rRenderContext.SetLineColor();
351 rRenderContext.SetFillColor(backgroundColor);
352 rRenderContext.DrawRect(_rRowArea);
353 }
354
355
356 void GridTableRenderer::PaintRowHeader(vcl::RenderContext& rRenderContext,
357 const tools::Rectangle& _rArea, const StyleSettings& _rStyle)
358 {
359 auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::LINECOLOR | vcl::PushFlags::TEXTCOLOR);
360
361 std::optional<Color> const aLineColor( m_pImpl->rModel.getLineColor() );
362 Color const lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : *aLineColor;
363 rRenderContext.SetLineColor(lineColor);
364 rRenderContext.DrawLine(_rArea.BottomLeft(), _rArea.BottomRight());
365
366 Any const rowHeading( m_pImpl->rModel.getRowHeading( m_pImpl->nCurrentRow ) );
367 OUString const rowTitle( m_pImpl->aStringConverter.convertToString( rowHeading ) );
368 if (!rowTitle.isEmpty())
369 {
370 Color const textColor = lcl_getEffectiveColor(m_pImpl->rModel.getHeaderTextColor(),
371 _rStyle, &StyleSettings::GetFieldTextColor);
372 rRenderContext.SetTextColor(textColor);
373
374 tools::Rectangle const aTextRect(lcl_getTextRenderingArea(lcl_getContentArea(*m_pImpl, _rArea)));
375 DrawTextFlags nDrawTextFlags = lcl_getAlignmentTextDrawFlags(*m_pImpl, 0) | DrawTextFlags::Clip;
376 if (!m_pImpl->rModel.isEnabled())
377 nDrawTextFlags |= DrawTextFlags::Disable;
378 // TODO: is using the horizontal alignment of the 0'th column a good idea here? This is pretty ... arbitrary ..
379 rRenderContext.DrawText(aTextRect, rowTitle, nDrawTextFlags);
380 }
381 }
382
383
384 struct GridTableRenderer::CellRenderContext
385 {
386 OutputDevice& rDevice;
387 tools::Rectangle const aContentArea;
388 StyleSettings const & rStyle;
389 ColPos const nColumn;
390 bool const bSelected;
391 bool const bHasControlFocus;
392
393 CellRenderContext( OutputDevice& i_device, tools::Rectangle const & i_contentArea,
394 StyleSettings const & i_style, ColPos const i_column, bool const i_selected, bool const i_hasControlFocus )
395 :rDevice( i_device )
396 ,aContentArea( i_contentArea )
397 ,rStyle( i_style )
398 ,nColumn( i_column )
399 ,bSelected( i_selected )
400 ,bHasControlFocus( i_hasControlFocus )
401 {
402 }
403 };
404
405
406 void GridTableRenderer::PaintCell(ColPos const i_column, bool _bSelected, bool i_hasControlFocus,
407 vcl::RenderContext& rRenderContext, const tools::Rectangle& _rArea, const StyleSettings& _rStyle)
408 {
409 auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR);
410
411 tools::Rectangle const aContentArea(lcl_getContentArea(*m_pImpl, _rArea));
412 CellRenderContext const aCellRenderContext(rRenderContext, aContentArea, _rStyle, i_column, _bSelected, i_hasControlFocus);
413 impl_paintCellContent(aCellRenderContext);
414
415 if ( m_pImpl->bUseGridLines )
416 {
417 ::std::optional< ::Color > aLineColor( m_pImpl->rModel.getLineColor() );
418 ::Color lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : *aLineColor;
419
420 if ( _bSelected && !aLineColor )
421 {
422 // if no line color is specified by the model, use the usual selection color for lines in selected cells
423 lineColor = i_hasControlFocus
424 ? lcl_getEffectiveColor( m_pImpl->rModel.getActiveSelectionBackColor(), _rStyle, &StyleSettings::GetHighlightColor )
425 : lcl_getEffectiveColor( m_pImpl->rModel.getInactiveSelectionBackColor(), _rStyle, &StyleSettings::GetDeactiveColor );
426 }
427
428 rRenderContext.SetLineColor( lineColor );
429 rRenderContext.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() );
430 rRenderContext.DrawLine( _rArea.BottomRight(), _rArea.TopRight() );
431 }
432 }
433
434
435 void GridTableRenderer::impl_paintCellImage( CellRenderContext const & i_context, Image const & i_image )
436 {
437 Point imagePos( i_context.aContentArea.Left(), i_context.aContentArea.Top() );
438 Size imageSize = i_image.GetSizePixel();
439 if ( i_context.aContentArea.GetWidth() > imageSize.Width() )
440 {
441 const HorizontalAlignment eHorzAlign = m_pImpl->rModel.getColumnModel( i_context.nColumn )->getHorizontalAlign();
442 switch ( eHorzAlign )
443 {
444 case HorizontalAlignment_CENTER:
445 imagePos.AdjustX(( i_context.aContentArea.GetWidth() - imageSize.Width() ) / 2 );
446 break;
447 case HorizontalAlignment_RIGHT:
448 imagePos.setX( i_context.aContentArea.Right() - imageSize.Width() );
449 break;
450 default:
451 break;
452 }
453
454 }
455 else
456 imageSize.setWidth( i_context.aContentArea.GetWidth() );
457
458 if ( i_context.aContentArea.GetHeight() > imageSize.Height() )
459 {
460 const VerticalAlignment eVertAlign = m_pImpl->rModel.getVerticalAlign();
461 switch ( eVertAlign )
462 {
463 case VerticalAlignment_MIDDLE:
464 imagePos.AdjustY(( i_context.aContentArea.GetHeight() - imageSize.Height() ) / 2 );
465 break;
466 case VerticalAlignment_BOTTOM:
467 imagePos.setY( i_context.aContentArea.Bottom() - imageSize.Height() );
468 break;
469 default:
470 break;
471 }
472 }
473 else
474 imageSize.setHeight( i_context.aContentArea.GetHeight() - 1 );
475 DrawImageFlags const nStyle = m_pImpl->rModel.isEnabled() ? DrawImageFlags::NONE : DrawImageFlags::Disable;
476 i_context.rDevice.DrawImage( imagePos, imageSize, i_image, nStyle );
477 }
478
479
480 void GridTableRenderer::impl_paintCellContent( CellRenderContext const & i_context )
481 {
482 Any aCellContent;
483 m_pImpl->rModel.getCellContent( i_context.nColumn, m_pImpl->nCurrentRow, aCellContent );
484
485 if ( aCellContent.getValueTypeClass() == TypeClass_INTERFACE )
486 {
487 Reference< XInterface > const xContentInterface( aCellContent, UNO_QUERY );
488 if ( !xContentInterface.is() )
489 // allowed. kind of.
490 return;
491
492 Reference< XGraphic > const xGraphic( aCellContent, UNO_QUERY );
493 ENSURE_OR_RETURN_VOID( xGraphic.is(), "GridTableRenderer::impl_paintCellContent: only XGraphic interfaces (or NULL) are supported for painting." );
494
495 const Image aImage( xGraphic );
496 impl_paintCellImage( i_context, aImage );
497 return;
498 }
499
500 const OUString sText( m_pImpl->aStringConverter.convertToString( aCellContent ) );
501 impl_paintCellText( i_context, sText );
502 }
503
504
505 void GridTableRenderer::impl_paintCellText( CellRenderContext const & i_context, OUString const & i_text )
506 {
507 if ( i_context.bSelected )
508 {
509 ::Color const textColor = i_context.bHasControlFocus
510 ? lcl_getEffectiveColor( m_pImpl->rModel.getActiveSelectionTextColor(), i_context.rStyle, &StyleSettings::GetHighlightTextColor )
511 : lcl_getEffectiveColor( m_pImpl->rModel.getInactiveSelectionTextColor(), i_context.rStyle, &StyleSettings::GetDeactiveTextColor );
512 i_context.rDevice.SetTextColor( textColor );
513 }
514 else
515 {
516 ::Color const textColor = lcl_getEffectiveColor( m_pImpl->rModel.getTextColor(), i_context.rStyle, &StyleSettings::GetFieldTextColor );
517 i_context.rDevice.SetTextColor( textColor );
518 }
519
520 tools::Rectangle const textRect( lcl_getTextRenderingArea( i_context.aContentArea ) );
521 DrawTextFlags nDrawTextFlags = lcl_getAlignmentTextDrawFlags( *m_pImpl, i_context.nColumn ) | DrawTextFlags::Clip;
522 if ( !m_pImpl->rModel.isEnabled() )
523 nDrawTextFlags |= DrawTextFlags::Disable;
524 i_context.rDevice.DrawText( textRect, i_text, nDrawTextFlags );
525 }
526
527
528 void GridTableRenderer::ShowCellCursor( vcl::Window& _rView, const tools::Rectangle& _rCursorRect)
529 {
530 _rView.ShowFocus( _rCursorRect );
531 }
532
533
534 void GridTableRenderer::HideCellCursor( vcl::Window& _rView )
535 {
536 _rView.HideFocus();
537 }
538
539
540 bool GridTableRenderer::FitsIntoCell( Any const & i_cellContent,
541 OutputDevice& i_targetDevice, tools::Rectangle const & i_targetArea ) const
542 {
543 if ( !i_cellContent.hasValue() )
544 return true;
545
546 if ( i_cellContent.getValueTypeClass() == TypeClass_INTERFACE )
547 {
548 Reference< XInterface > const xContentInterface( i_cellContent, UNO_QUERY );
549 if ( !xContentInterface.is() )
550 return true;
551
552 Reference< XGraphic > const xGraphic( i_cellContent, UNO_QUERY );
553 if ( xGraphic.is() )
554 // for the moment, assume it fits. We can always scale it down during painting ...
555 return true;
556
557 OSL_ENSURE( false, "GridTableRenderer::FitsIntoCell: only XGraphic interfaces (or NULL) are supported for painting." );
558 return true;
559 }
560
561 OUString const sText( m_pImpl->aStringConverter.convertToString( i_cellContent ) );
562 if ( sText.isEmpty() )
563 return true;
564
565 tools::Rectangle const aTargetArea( lcl_getTextRenderingArea( lcl_getContentArea( *m_pImpl, i_targetArea ) ) );
566
567 tools::Long const nTextHeight = i_targetDevice.GetTextHeight();
568 if ( nTextHeight > aTargetArea.GetHeight() )
569 return false;
570
571 tools::Long const nTextWidth = i_targetDevice.GetTextWidth( sText );
572 return nTextWidth <= aTargetArea.GetWidth();
573 }
574
575
576 bool GridTableRenderer::GetFormattedCellString( Any const & i_cellValue, OUString & o_cellString ) const
577 {
578 o_cellString = m_pImpl->aStringConverter.convertToString( i_cellValue );
579
580 return true;
581 }
582
583
584 } // namespace svt::table
585
586
587 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */