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