LCOV - code coverage report
Current view: top level - libreoffice/svtools/source/table - gridtablerenderer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 258 0.0 %
Date: 2012-12-27 Functions: 0 27 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10