25#include <com/sun/star/graphic/XGraphic.hpp>
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;
56 class CachedSortIndicator
83 tools::Long const nSortIndicatorWidth = 2 * i_headerHeight / 3;
84 tools::Long const nSortIndicatorHeight = 2 * nSortIndicatorWidth / 3;
86 Point const aBitmapPos( 0, 0 );
87 Size const aBitmapSize( nSortIndicatorWidth, nSortIndicatorHeight );
89 aDevice->SetOutputSizePixel( aBitmapSize );
93 i_sortAscending ? SymbolType::SPIN_UP : SymbolType::SPIN_DOWN,
96 rBitmap = aDevice->GetBitmapEx(aBitmapPos, aBitmapSize);
132 if ( i_impl.bUseGridLines )
134 aContentArea.AdjustRight( -1 );
135 aContentArea.AdjustBottom( -1 );
142 aTextArea.AdjustLeft(2 ); aTextArea.AdjustRight( -2 );
143 aTextArea.AdjustTop( 1 ); aTextArea.AdjustBottom( -1 );
147 DrawTextFlags lcl_getAlignmentTextDrawFlags( GridTableRenderer_Impl
const & i_impl,
ColPos const i_columnPos )
150 VerticalAlignment
const eVertAlign = i_impl.rModel.getVerticalAlign();
151 switch ( eVertAlign )
153 case VerticalAlignment_MIDDLE: nVertFlag = DrawTextFlags::VCenter;
break;
154 case VerticalAlignment_BOTTOM: nVertFlag = DrawTextFlags::Bottom;
break;
160 HorizontalAlignment
const eHorzAlign = i_impl.rModel.getColumnCount() > 0
161 ? i_impl.rModel.getColumnModel( i_columnPos )->getHorizontalAlign()
162 : HorizontalAlignment_CENTER;
163 switch ( eHorzAlign )
165 case HorizontalAlignment_CENTER: nHorzFlag = DrawTextFlags::Center;
break;
166 case HorizontalAlignment_RIGHT: nHorzFlag = DrawTextFlags::Right;
break;
171 return nVertFlag | nHorzFlag;
199 m_pImpl->bUseGridLines = i_use;
205 Color lcl_getEffectiveColor(std::optional<Color>
const& i_modelColor,
210 return *i_modelColor;
211 return (i_styleSettings.*i_getDefaultColor)();
217 bool _bIsColHeaderArea,
bool _bIsRowHeaderArea,
const StyleSettings& _rStyle)
219 OSL_PRECOND(_bIsColHeaderArea || _bIsRowHeaderArea,
"GridTableRenderer::PaintHeaderArea: invalid area flags!");
223 Color const background = lcl_getEffectiveColor(
m_pImpl->rModel.getHeaderBackgroundColor(),
231 std::optional<Color> aLineColor(
m_pImpl->rModel.getLineColor());
237 rRenderContext.
Pop();
248 OUString sHeaderText;
250 DBG_ASSERT( pColumn,
"GridTableRenderer::PaintColumnHeader: invalid column model object!" );
252 sHeaderText = pColumn->getName();
258 DrawTextFlags nDrawTextFlags = lcl_getAlignmentTextDrawFlags( *
m_pImpl, _nCol ) | DrawTextFlags::Clip;
259 if (!
m_pImpl->rModel.isEnabled())
260 nDrawTextFlags |= DrawTextFlags::Disable;
261 rRenderContext.
DrawText( aTextRect, sHeaderText, nDrawTextFlags );
263 std::optional<Color>
const aLineColor(
m_pImpl->rModel.getLineColor() );
272 if ( pSortAdapter !=
nullptr )
277 BitmapEx const aIndicatorBitmap =
m_pImpl->aSortIndicator.getBitmapFor(rRenderContext, nHeaderHeight, _rStyle,
281 tools::Long const nSortIndicatorPaddingY = ( nHeaderHeight - aBitmapSize.
Height() ) / 2;
283 if ( nDrawTextFlags & DrawTextFlags::Right )
297 rRenderContext.
Pop();
311 Color const activeSelectionBackColor = lcl_getEffectiveColor(
m_pImpl->rModel.getActiveSelectionBackColor(),
316 backgroundColor = i_hasControlFocus
317 ? activeSelectionBackColor
322 std::optional< std::vector<Color> > aRowColors =
m_pImpl->rModel.getRowBackgroundColors();
329 backgroundColor = fieldColor;
333 Color hilightColor = activeSelectionBackColor;
337 backgroundColor = hilightColor;
342 if (aRowColors->empty())
349 backgroundColor = aRowColors->at(
m_pImpl->nCurrentRow % aRowColors->size());
358 rRenderContext.
Pop();
367 std::optional<Color>
const aLineColor(
m_pImpl->rModel.getLineColor() );
373 OUString
const rowTitle(
m_pImpl->aStringConverter.convertToString( rowHeading ) );
374 if (!rowTitle.isEmpty())
376 Color const textColor = lcl_getEffectiveColor(
m_pImpl->rModel.getHeaderTextColor(),
381 DrawTextFlags nDrawTextFlags = lcl_getAlignmentTextDrawFlags(*
m_pImpl, 0) | DrawTextFlags::Clip;
382 if (!
m_pImpl->rModel.isEnabled())
383 nDrawTextFlags |= DrawTextFlags::Disable;
385 rRenderContext.
DrawText(aTextRect, rowTitle, nDrawTextFlags);
388 rRenderContext.
Pop();
402 StyleSettings const & i_style,
ColPos const i_column,
bool const i_selected,
bool const i_hasControlFocus )
420 CellRenderContext const aCellRenderContext(rRenderContext, aContentArea, _rStyle, i_column, _bSelected, i_hasControlFocus);
425 ::std::optional< ::Color > aLineColor(
m_pImpl->rModel.getLineColor() );
428 if ( _bSelected && !aLineColor )
431 lineColor = i_hasControlFocus
441 rRenderContext.
Pop();
451 const HorizontalAlignment eHorzAlign =
m_pImpl->rModel.getColumnModel( i_context.
nColumn )->getHorizontalAlign();
452 switch ( eHorzAlign )
454 case HorizontalAlignment_CENTER:
457 case HorizontalAlignment_RIGHT:
470 const VerticalAlignment eVertAlign =
m_pImpl->rModel.getVerticalAlign();
471 switch ( eVertAlign )
473 case VerticalAlignment_MIDDLE:
476 case VerticalAlignment_BOTTOM:
485 DrawImageFlags const nStyle =
m_pImpl->rModel.isEnabled() ? DrawImageFlags::NONE : DrawImageFlags::Disable;
495 if ( aCellContent.getValueTypeClass() == TypeClass_INTERFACE )
497 Reference< XInterface >
const xContentInterface( aCellContent, UNO_QUERY );
498 if ( !xContentInterface.is() )
502 Reference< XGraphic >
const xGraphic( aCellContent, UNO_QUERY );
503 ENSURE_OR_RETURN_VOID( xGraphic.is(),
"GridTableRenderer::impl_paintCellContent: only XGraphic interfaces (or NULL) are supported for painting." );
505 const Image aImage( xGraphic );
510 const OUString sText(
m_pImpl->aStringConverter.convertToString( aCellContent ) );
532 if ( !
m_pImpl->rModel.isEnabled() )
533 nDrawTextFlags |= DrawTextFlags::Disable;
553 if ( !i_cellContent.hasValue() )
556 if ( i_cellContent.getValueTypeClass() == TypeClass_INTERFACE )
558 Reference< XInterface >
const xContentInterface( i_cellContent, UNO_QUERY );
559 if ( !xContentInterface.is() )
562 Reference< XGraphic >
const xGraphic( i_cellContent, UNO_QUERY );
567 OSL_ENSURE(
false,
"GridTableRenderer::FitsIntoCell: only XGraphic interfaces (or NULL) are supported for painting." );
571 OUString
const sText(
m_pImpl->aStringConverter.convertToString( i_cellContent ) );
572 if ( sText.isEmpty() )
575 tools::Rectangle const aTargetArea( lcl_getTextRenderingArea( lcl_getContentArea( *
m_pImpl, i_targetArea ) ) );
578 if ( nTextHeight > aTargetArea.
GetHeight() )
582 return nTextWidth <= aTargetArea.
GetWidth();
588 o_cellString =
m_pImpl->aStringConverter.convertToString( i_cellValue );
const Size & GetSizePixel() const
sal_uInt8 GetBlue() const
void SetGreen(sal_uInt8 nGreen)
void SetRed(sal_uInt8 nRed)
sal_uInt8 GetGreen() const
void SetBlue(sal_uInt8 nBlue)
void DrawSymbol(const tools::Rectangle &rRect, SymbolType eType, const Color &rColor, DrawSymbolFlags nStyle=DrawSymbolFlags::NONE)
Size GetSizePixel() const
void DrawBitmapEx(const Point &rDestPt, const BitmapEx &rBitmapEx)
void DrawRect(const tools::Rectangle &rRect)
void DrawLine(const Point &rStartPt, const Point &rEndPt)
tools::Long GetTextWidth(const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, vcl::text::TextLayoutCache const *=nullptr, SalLayoutGlyphs const *const pLayoutCache=nullptr) const
void SetTextColor(const Color &rColor)
void DrawImage(const Point &rPos, const Image &rImage, DrawImageFlags nStyle=DrawImageFlags::NONE)
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
tools::Long GetTextHeight() const
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
void setX(tools::Long nX)
void setY(tools::Long nY)
tools::Long AdjustY(tools::Long nVertMove)
tools::Long AdjustX(tools::Long nHorzMove)
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
const Color & GetDeactiveTextColor() const
const Color & GetFieldTextColor() const
bool GetHighContrastMode() const
const Color & GetFieldColor() const
const Color & GetDeactiveColor() const
Color GetSeparatorColor() const
const Color & GetActiveColor() const
const Color & GetDialogColor() const
const Color & GetHighlightColor() const
const Color & GetHighlightTextColor() const
reference_type * get() const
virtual void PaintCell(ColPos const i_col, bool i_hasControlFocus, bool _bSelected, vcl::RenderContext &_rDevice, const tools::Rectangle &_rArea, const StyleSettings &_rStyle) override
paints a certain cell
::std::unique_ptr< GridTableRenderer_Impl > m_pImpl
virtual void PaintRowHeader(vcl::RenderContext &_rDevice, const tools::Rectangle &_rArea, const StyleSettings &_rStyle) override
paints the header of a row
virtual void HideCellCursor(vcl::Window &_rView) override
hides the cell cursor previously drawn into the given rectangle
virtual ~GridTableRenderer() override
bool useGridLines() const
determines whether or not to paint grid lines
virtual void PaintColumnHeader(ColPos _nCol, vcl::RenderContext &_rDevice, const tools::Rectangle &_rArea, const StyleSettings &_rStyle) override
paints the header for a given column
virtual void PrepareRow(RowPos _nRow, bool i_hasControlFocus, bool _bSelected, vcl::RenderContext &_rDevice, const tools::Rectangle &_rRowArea, const StyleSettings &_rStyle) override
prepares a row for painting
virtual void PaintHeaderArea(vcl::RenderContext &_rDevice, const tools::Rectangle &_rArea, bool _bIsColHeaderArea, bool _bIsRowHeaderArea, const StyleSettings &_rStyle) override
paints a (part of) header area
virtual void ShowCellCursor(vcl::Window &_rView, const tools::Rectangle &_rCursorRect) override
draws a cell cursor in the given rectangle
void impl_paintCellImage(CellRenderContext const &i_context, Image const &i_image)
virtual bool FitsIntoCell(css::uno::Any const &i_cellContent, OutputDevice &i_targetDevice, tools::Rectangle const &i_targetArea) const override
checks whether a given cell content fits into a given target area on a given device.
void impl_paintCellContent(CellRenderContext const &i_context)
GridTableRenderer(ITableModel &_rModel)
creates a table renderer associated with the given model
void impl_paintCellText(CellRenderContext const &i_context, OUString const &i_text)
virtual bool GetFormattedCellString(css::uno::Any const &i_cellValue, OUString &o_cellString) const override
attempts to format the content of the given cell as string
provides sorting functionality for the data underlying an ITableModel
virtual ColumnSort getCurrentSortOrder() const =0
retrieves the current sort order of the data
declares the interface to implement by an abstract table model
virtual void ShowFocus(const tools::Rectangle &rRect)
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
#define DBG_ASSERT(sCon, aError)
#define ENSURE_OR_RETURN_VOID(c, m)
tools::Long m_lastHeaderHeight
BitmapEx m_sortDescending
Size imageSize(const sk_sp< SkImage > &image)
sal_Int32 RowPos
a value denoting a row position within a table
sal_Int32 ColPos
a value denoting a column position within a table
std::shared_ptr< IColumnModel > PColumnModel
ColumnSortDirection eSortDirection
bool const bHasControlFocus
CellRenderContext(OutputDevice &i_device, tools::Rectangle const &i_contentArea, StyleSettings const &i_style, ColPos const i_column, bool const i_selected, bool const i_hasControlFocus)
StyleSettings const & rStyle
tools::Rectangle const aContentArea
GridTableRenderer_Impl(ITableModel &_rModel)
CachedSortIndicator aSortIndicator
CellValueConversion aStringConverter
#define ROW_INVALID
denotes an invalid row index