2009-08-26 13:11:27 +00:00
|
|
|
/*************************************************************************
|
2010-02-12 15:01:35 +01:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
|
|
|
*
|
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
|
|
|
*
|
|
|
|
* This file is part of OpenOffice.org.
|
|
|
|
*
|
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
|
|
|
*
|
2009-08-26 13:11:27 +00:00
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_svtools.hxx"
|
|
|
|
|
2011-01-04 10:26:14 +01:00
|
|
|
#include "cellvalueconversion.hxx"
|
2009-08-26 13:11:27 +00:00
|
|
|
#include "svtools/table/gridtablerenderer.hxx"
|
2011-01-12 12:34:24 +01:00
|
|
|
#include "svtools/colorcfg.hxx"
|
2009-08-26 13:11:27 +00:00
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
/** === begin UNO includes === **/
|
2011-01-04 10:26:14 +01:00
|
|
|
#include <com/sun/star/graphic/XGraphic.hpp>
|
2011-01-12 12:34:24 +01:00
|
|
|
/** === end UNO includes === **/
|
2011-01-04 10:26:14 +01:00
|
|
|
|
2009-08-26 13:11:27 +00:00
|
|
|
#include <tools/debug.hxx>
|
2011-01-11 21:45:47 +01:00
|
|
|
#include <tools/diagnose_ex.h>
|
2009-08-26 13:11:27 +00:00
|
|
|
#include <vcl/window.hxx>
|
2010-02-12 17:08:15 +01:00
|
|
|
#include <vcl/image.hxx>
|
2011-01-19 11:11:29 +01:00
|
|
|
#include <vcl/virdev.hxx>
|
|
|
|
#include <vcl/decoview.hxx>
|
2009-08-26 13:11:27 +00:00
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
//......................................................................................................................
|
2009-08-26 13:11:27 +00:00
|
|
|
namespace svt { namespace table
|
|
|
|
{
|
2011-01-12 12:34:24 +01:00
|
|
|
//......................................................................................................................
|
2009-08-26 13:11:27 +00:00
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
/** === begin UNO using === **/
|
2011-01-04 10:26:14 +01:00
|
|
|
using ::com::sun::star::uno::Any;
|
|
|
|
using ::com::sun::star::uno::Reference;
|
|
|
|
using ::com::sun::star::uno::UNO_QUERY;
|
2011-01-20 13:52:50 +01:00
|
|
|
using ::com::sun::star::uno::XInterface;
|
|
|
|
using ::com::sun::star::uno::TypeClass_INTERFACE;
|
2011-01-04 10:26:14 +01:00
|
|
|
using ::com::sun::star::graphic::XGraphic;
|
|
|
|
using ::com::sun::star::style::HorizontalAlignment;
|
|
|
|
using ::com::sun::star::style::HorizontalAlignment_LEFT;
|
|
|
|
using ::com::sun::star::style::HorizontalAlignment_CENTER;
|
|
|
|
using ::com::sun::star::style::HorizontalAlignment_RIGHT;
|
|
|
|
using ::com::sun::star::style::VerticalAlignment;
|
|
|
|
using ::com::sun::star::style::VerticalAlignment_TOP;
|
|
|
|
using ::com::sun::star::style::VerticalAlignment_MIDDLE;
|
|
|
|
using ::com::sun::star::style::VerticalAlignment_BOTTOM;
|
2011-01-12 12:34:24 +01:00
|
|
|
/** === end UNO using === **/
|
2011-01-04 10:26:14 +01:00
|
|
|
|
2011-01-19 11:11:29 +01:00
|
|
|
//==================================================================================================================
|
|
|
|
//= CachedSortIndicator
|
|
|
|
//==================================================================================================================
|
|
|
|
class CachedSortIndicator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CachedSortIndicator()
|
|
|
|
:m_lastHeaderHeight( 0 )
|
|
|
|
,m_lastArrowColor( COL_TRANSPARENT )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
BitmapEx const & getBitmapFor( OutputDevice const & i_device, long const i_headerHeight, StyleSettings const & i_style, bool const i_sortAscending );
|
|
|
|
|
|
|
|
private:
|
|
|
|
long m_lastHeaderHeight;
|
|
|
|
Color m_lastArrowColor;
|
|
|
|
BitmapEx m_sortAscending;
|
|
|
|
BitmapEx m_sortDescending;
|
|
|
|
};
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
|
|
|
BitmapEx const & CachedSortIndicator::getBitmapFor( OutputDevice const & i_device, long const i_headerHeight,
|
|
|
|
StyleSettings const & i_style, bool const i_sortAscending )
|
|
|
|
{
|
|
|
|
BitmapEx & rBitmap( i_sortAscending ? m_sortAscending : m_sortDescending );
|
|
|
|
if ( !rBitmap || ( i_headerHeight != m_lastHeaderHeight ) || ( i_style.GetActiveColor() != m_lastArrowColor ) )
|
|
|
|
{
|
|
|
|
long const nSortIndicatorWidth = 2 * i_headerHeight / 3;
|
|
|
|
long const nSortIndicatorHeight = 2 * nSortIndicatorWidth / 3;
|
|
|
|
|
|
|
|
Point const aBitmapPos( 0, 0 );
|
|
|
|
Size const aBitmapSize( nSortIndicatorWidth, nSortIndicatorHeight );
|
|
|
|
VirtualDevice aDevice( i_device, 0, 0 );
|
|
|
|
aDevice.SetOutputSizePixel( aBitmapSize );
|
|
|
|
|
|
|
|
DecorationView aDecoView( &aDevice );
|
|
|
|
aDecoView.DrawSymbol(
|
|
|
|
Rectangle( aBitmapPos, aBitmapSize ),
|
2011-01-26 20:43:12 +01:00
|
|
|
i_sortAscending ? SYMBOL_SPIN_UP : SYMBOL_SPIN_DOWN,
|
2011-01-19 11:11:29 +01:00
|
|
|
i_style.GetActiveColor()
|
|
|
|
);
|
|
|
|
|
|
|
|
rBitmap = aDevice.GetBitmapEx( aBitmapPos, aBitmapSize );
|
|
|
|
m_lastHeaderHeight = i_headerHeight;
|
|
|
|
m_lastArrowColor = i_style.GetActiveColor();
|
|
|
|
}
|
|
|
|
return rBitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==================================================================================================================
|
|
|
|
//= GridTableRenderer_Impl
|
|
|
|
//==================================================================================================================
|
2009-08-26 13:11:27 +00:00
|
|
|
struct GridTableRenderer_Impl
|
|
|
|
{
|
2011-01-19 11:11:29 +01:00
|
|
|
ITableModel& rModel;
|
|
|
|
RowPos nCurrentRow;
|
|
|
|
bool bUseGridLines;
|
|
|
|
CachedSortIndicator aSortIndicator;
|
2009-08-26 13:11:27 +00:00
|
|
|
|
|
|
|
GridTableRenderer_Impl( ITableModel& _rModel )
|
|
|
|
:rModel( _rModel )
|
|
|
|
,nCurrentRow( ROW_INVALID )
|
2011-01-12 12:34:24 +01:00
|
|
|
,bUseGridLines( true )
|
2009-08-26 13:11:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
2011-01-19 11:11:29 +01:00
|
|
|
|
|
|
|
//==================================================================================================================
|
|
|
|
//= helper
|
|
|
|
//==================================================================================================================
|
2011-01-12 14:00:45 +01:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
static Rectangle lcl_getContentArea( GridTableRenderer_Impl const & i_impl, Rectangle const & i_cellArea )
|
|
|
|
{
|
|
|
|
Rectangle aContentArea( i_cellArea );
|
|
|
|
if ( i_impl.bUseGridLines )
|
|
|
|
{
|
|
|
|
--aContentArea.Right();
|
|
|
|
--aContentArea.Bottom();
|
|
|
|
}
|
|
|
|
return aContentArea;
|
|
|
|
}
|
|
|
|
static Rectangle lcl_getTextRenderingArea( Rectangle const & i_contentArea )
|
|
|
|
{
|
|
|
|
Rectangle aTextArea( i_contentArea );
|
|
|
|
aTextArea.Left() += 2; aTextArea.Right() -= 2;
|
|
|
|
++aTextArea.Top(); --aTextArea.Bottom();
|
|
|
|
return aTextArea;
|
|
|
|
}
|
2011-01-12 14:09:38 +01:00
|
|
|
|
|
|
|
static ULONG lcl_getAlignmentTextDrawFlags( GridTableRenderer_Impl const & i_impl, ColPos const i_columnPos )
|
|
|
|
{
|
|
|
|
ULONG nVertFlag = TEXT_DRAW_TOP;
|
|
|
|
VerticalAlignment const eVertAlign = i_impl.rModel.getVerticalAlign();
|
|
|
|
switch ( eVertAlign )
|
|
|
|
{
|
|
|
|
case VerticalAlignment_MIDDLE: nVertFlag = TEXT_DRAW_VCENTER; break;
|
|
|
|
case VerticalAlignment_BOTTOM: nVertFlag = TEXT_DRAW_BOTTOM; break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG nHorzFlag = TEXT_DRAW_LEFT;
|
|
|
|
HorizontalAlignment const eHorzAlign = i_impl.rModel.getColumnModel( i_columnPos )->getHorizontalAlign();
|
|
|
|
switch ( eHorzAlign )
|
|
|
|
{
|
|
|
|
case HorizontalAlignment_CENTER: nHorzFlag = TEXT_DRAW_CENTER; break;
|
|
|
|
case HorizontalAlignment_RIGHT: nHorzFlag = TEXT_DRAW_RIGHT; break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nVertFlag | nHorzFlag;
|
|
|
|
}
|
|
|
|
|
2011-01-12 14:00:45 +01:00
|
|
|
}
|
2009-08-26 13:11:27 +00:00
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
//==================================================================================================================
|
2009-08-26 13:11:27 +00:00
|
|
|
//= GridTableRenderer
|
2011-01-12 12:34:24 +01:00
|
|
|
//==================================================================================================================
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
2009-08-26 13:11:27 +00:00
|
|
|
GridTableRenderer::GridTableRenderer( ITableModel& _rModel )
|
|
|
|
:m_pImpl( new GridTableRenderer_Impl( _rModel ) )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
2009-08-26 13:11:27 +00:00
|
|
|
GridTableRenderer::~GridTableRenderer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
|
|
|
RowPos GridTableRenderer::getCurrentRow() const
|
2009-08-26 13:11:27 +00:00
|
|
|
{
|
|
|
|
return m_pImpl->nCurrentRow;
|
|
|
|
}
|
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool GridTableRenderer::useGridLines() const
|
|
|
|
{
|
|
|
|
return m_pImpl->bUseGridLines;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
|
|
|
void GridTableRenderer::useGridLines( bool const i_use )
|
|
|
|
{
|
|
|
|
m_pImpl->bUseGridLines = i_use;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
Color lcl_getEffectiveColor(
|
|
|
|
::boost::optional< ::Color > const & i_modelColor,
|
|
|
|
StyleSettings const & i_styleSettings,
|
|
|
|
::Color const & ( StyleSettings::*i_getDefaultColor ) () const
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if ( !!i_modelColor )
|
|
|
|
return *i_modelColor;
|
|
|
|
return ( i_styleSettings.*i_getDefaultColor )();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
2009-08-26 13:11:27 +00:00
|
|
|
void GridTableRenderer::PaintHeaderArea(
|
|
|
|
OutputDevice& _rDevice, const Rectangle& _rArea, bool _bIsColHeaderArea, bool _bIsRowHeaderArea,
|
|
|
|
const StyleSettings& _rStyle )
|
|
|
|
{
|
|
|
|
OSL_PRECOND( _bIsColHeaderArea || _bIsRowHeaderArea,
|
|
|
|
"GridTableRenderer::PaintHeaderArea: invalid area flags!" );
|
|
|
|
|
2011-01-12 14:00:45 +01:00
|
|
|
_rDevice.Push( PUSH_FILLCOLOR | PUSH_LINECOLOR );
|
2011-01-12 12:34:24 +01:00
|
|
|
|
|
|
|
Color const background = lcl_getEffectiveColor( m_pImpl->rModel.getHeaderBackgroundColor(), _rStyle, &StyleSettings::GetDialogColor );
|
|
|
|
_rDevice.SetFillColor( background );
|
|
|
|
|
2011-01-12 14:00:45 +01:00
|
|
|
_rDevice.SetLineColor();
|
2009-08-26 13:11:27 +00:00
|
|
|
_rDevice.DrawRect( _rArea );
|
2011-01-12 14:00:45 +01:00
|
|
|
|
2009-08-26 13:11:27 +00:00
|
|
|
// delimiter lines at bottom/right
|
2011-01-12 14:00:45 +01:00
|
|
|
::boost::optional< ::Color > aLineColor( m_pImpl->rModel.getLineColor() );
|
|
|
|
::Color const lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : *aLineColor;
|
|
|
|
_rDevice.SetLineColor( lineColor );
|
2009-08-26 13:11:27 +00:00
|
|
|
_rDevice.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() );
|
|
|
|
_rDevice.DrawLine( _rArea.BottomRight(), _rArea.TopRight() );
|
|
|
|
|
|
|
|
_rDevice.Pop();
|
2010-04-16 16:55:27 +02:00
|
|
|
(void)_bIsColHeaderArea;
|
|
|
|
(void)_bIsRowHeaderArea;
|
2009-08-26 13:11:27 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
2009-08-26 13:11:27 +00:00
|
|
|
void GridTableRenderer::PaintColumnHeader( ColPos _nCol, bool _bActive, bool _bSelected,
|
|
|
|
OutputDevice& _rDevice, const Rectangle& _rArea, const StyleSettings& _rStyle )
|
|
|
|
{
|
2010-02-12 17:08:15 +01:00
|
|
|
_rDevice.Push( PUSH_LINECOLOR);
|
2009-08-26 13:11:27 +00:00
|
|
|
|
|
|
|
String sHeaderText;
|
2011-01-17 12:19:05 +01:00
|
|
|
PColumnModel const pColumn = m_pImpl->rModel.getColumnModel( _nCol );
|
2009-08-26 13:11:27 +00:00
|
|
|
DBG_ASSERT( !!pColumn, "GridTableRenderer::PaintColumnHeader: invalid column model object!" );
|
|
|
|
if ( !!pColumn )
|
|
|
|
sHeaderText = pColumn->getName();
|
2011-01-12 12:34:24 +01:00
|
|
|
|
|
|
|
::Color const textColor = lcl_getEffectiveColor( m_pImpl->rModel.getTextColor(), _rStyle, &StyleSettings::GetFieldTextColor );
|
|
|
|
_rDevice.SetTextColor( textColor );
|
|
|
|
|
2011-01-12 14:00:45 +01:00
|
|
|
Rectangle const aTextRect( lcl_getTextRenderingArea( lcl_getContentArea( *m_pImpl, _rArea ) ) );
|
2011-01-12 14:09:38 +01:00
|
|
|
ULONG const nDrawTextFlags = lcl_getAlignmentTextDrawFlags( *m_pImpl, _nCol ) | TEXT_DRAW_CLIP;
|
|
|
|
_rDevice.DrawText( aTextRect, sHeaderText, nDrawTextFlags );
|
2011-01-12 12:34:24 +01:00
|
|
|
|
2011-01-17 12:19:05 +01:00
|
|
|
::boost::optional< ::Color > const aLineColor( m_pImpl->rModel.getLineColor() );
|
2011-01-12 14:00:45 +01:00
|
|
|
::Color const lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : *aLineColor;
|
|
|
|
_rDevice.SetLineColor( lineColor );
|
|
|
|
_rDevice.DrawLine( _rArea.BottomRight(), _rArea.TopRight());
|
2010-04-16 16:55:27 +02:00
|
|
|
_rDevice.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() );
|
2011-01-12 14:00:45 +01:00
|
|
|
|
2011-01-19 11:11:29 +01:00
|
|
|
// draw sort indicator if the model data is sorted by the given column
|
|
|
|
ITableDataSort const * pSortAdapter = m_pImpl->rModel.getSortAdapter();
|
|
|
|
ColumnSort aCurrentSortOrder;
|
|
|
|
if ( pSortAdapter != NULL )
|
|
|
|
aCurrentSortOrder = pSortAdapter->getCurrentSortOrder();
|
|
|
|
if ( aCurrentSortOrder.nColumnPos == _nCol )
|
|
|
|
{
|
|
|
|
long const nHeaderHeight( _rArea.GetHeight() );
|
|
|
|
BitmapEx const aIndicatorBitmap = m_pImpl->aSortIndicator.getBitmapFor( _rDevice, nHeaderHeight, _rStyle,
|
|
|
|
aCurrentSortOrder.eSortDirection == ColumnSortAscending );
|
|
|
|
Size const aBitmapSize( aIndicatorBitmap.GetSizePixel() );
|
|
|
|
long const nSortIndicatorPaddingX = 2;
|
|
|
|
long const nSortIndicatorPaddingY = ( nHeaderHeight - aBitmapSize.Height() ) / 2;
|
|
|
|
|
|
|
|
if ( ( nDrawTextFlags & TEXT_DRAW_RIGHT ) != 0 )
|
|
|
|
{
|
|
|
|
// text is right aligned => draw the sort indicator at the left hand side
|
|
|
|
_rDevice.DrawBitmapEx(
|
|
|
|
Point( nSortIndicatorPaddingX, nSortIndicatorPaddingY ),
|
|
|
|
aIndicatorBitmap
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// text is left-aligned or centered => draw the sort indicator at the right hand side
|
|
|
|
_rDevice.DrawBitmapEx(
|
|
|
|
Point( _rArea.Right() - nSortIndicatorPaddingX - aBitmapSize.Width(), nSortIndicatorPaddingY ),
|
|
|
|
aIndicatorBitmap
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-26 13:11:27 +00:00
|
|
|
_rDevice.Pop();
|
|
|
|
|
|
|
|
(void)_bActive;
|
|
|
|
// no special painting for the active column at the moment
|
|
|
|
|
2010-02-12 17:08:15 +01:00
|
|
|
(void)_bSelected;
|
2011-01-12 12:34:24 +01:00
|
|
|
// selection for column header not yet implemented
|
2009-08-26 13:11:27 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
2009-08-26 13:11:27 +00:00
|
|
|
void GridTableRenderer::PrepareRow( RowPos _nRow, bool _bActive, bool _bSelected,
|
|
|
|
OutputDevice& _rDevice, const Rectangle& _rRowArea, const StyleSettings& _rStyle )
|
|
|
|
{
|
|
|
|
// remember the row for subsequent calls to the other ->ITableRenderer methods
|
|
|
|
m_pImpl->nCurrentRow = _nRow;
|
|
|
|
|
2010-02-12 17:08:15 +01:00
|
|
|
_rDevice.Push( PUSH_FILLCOLOR | PUSH_LINECOLOR);
|
2009-08-26 13:11:27 +00:00
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
::Color backgroundColor = _rStyle.GetFieldColor();
|
|
|
|
|
|
|
|
::boost::optional< ::Color > aLineColor( m_pImpl->rModel.getLineColor() );
|
|
|
|
::Color lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : *aLineColor;
|
|
|
|
|
2011-01-04 10:26:14 +01:00
|
|
|
if ( _bSelected )
|
2010-02-12 17:08:15 +01:00
|
|
|
{
|
2011-01-12 12:34:24 +01:00
|
|
|
// selected rows use the background color from the style
|
|
|
|
backgroundColor = _rStyle.GetHighlightColor();
|
|
|
|
if ( !aLineColor )
|
|
|
|
lineColor = backgroundColor;
|
2010-02-12 17:08:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-12 12:34:24 +01:00
|
|
|
::boost::optional< ::std::vector< ::Color > > aRowColors = m_pImpl->rModel.getRowBackgroundColors();
|
|
|
|
if ( !aRowColors )
|
2010-04-16 16:55:27 +02:00
|
|
|
{
|
2011-01-12 12:34:24 +01:00
|
|
|
// use alternating default colors
|
2011-01-14 11:31:43 +01:00
|
|
|
Color const fieldColor = _rStyle.GetFieldColor();
|
|
|
|
if ( _rStyle.GetHighContrastMode() || ( ( m_pImpl->nCurrentRow % 2 ) == 0 ) )
|
2011-01-12 12:34:24 +01:00
|
|
|
{
|
2011-01-14 11:31:43 +01:00
|
|
|
backgroundColor = fieldColor;
|
2011-01-12 12:34:24 +01:00
|
|
|
}
|
2010-04-16 16:55:27 +02:00
|
|
|
else
|
2011-01-12 12:34:24 +01:00
|
|
|
{
|
|
|
|
Color hilightColor = _rStyle.GetHighlightColor();
|
2011-01-14 11:31:43 +01:00
|
|
|
hilightColor.SetRed( 9 * ( fieldColor.GetRed() - hilightColor.GetRed() ) / 10 + hilightColor.GetRed() );
|
|
|
|
hilightColor.SetGreen( 9 * ( fieldColor.GetGreen() - hilightColor.GetGreen() ) / 10 + hilightColor.GetGreen() );
|
|
|
|
hilightColor.SetBlue( 9 * ( fieldColor.GetBlue() - hilightColor.GetBlue() ) / 10 + hilightColor.GetBlue() );
|
2011-01-12 12:34:24 +01:00
|
|
|
backgroundColor = hilightColor;
|
|
|
|
}
|
2010-04-16 16:55:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-12 12:34:24 +01:00
|
|
|
if ( aRowColors->empty() )
|
|
|
|
{
|
|
|
|
// all colors have the same background color
|
|
|
|
backgroundColor = _rStyle.GetFieldColor();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
backgroundColor = aRowColors->at( m_pImpl->nCurrentRow % aRowColors->size() );
|
|
|
|
}
|
2010-04-16 16:55:27 +02:00
|
|
|
}
|
2010-02-12 17:08:15 +01:00
|
|
|
}
|
2009-08-26 13:11:27 +00:00
|
|
|
|
2011-01-12 14:00:45 +01:00
|
|
|
//m_pImpl->bUseGridLines ? _rDevice.SetLineColor( lineColor ) : _rDevice.SetLineColor();
|
|
|
|
_rDevice.SetLineColor();
|
2011-01-12 12:34:24 +01:00
|
|
|
_rDevice.SetFillColor( backgroundColor );
|
|
|
|
_rDevice.DrawRect( _rRowArea );
|
2009-08-26 13:11:27 +00:00
|
|
|
|
|
|
|
_rDevice.Pop();
|
2011-01-12 12:34:24 +01:00
|
|
|
|
2010-04-16 16:55:27 +02:00
|
|
|
(void)_bActive;
|
2011-01-12 12:34:24 +01:00
|
|
|
// row containing the active cell not rendered any special at the moment
|
2009-08-26 13:11:27 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
2011-01-11 17:21:55 +01:00
|
|
|
void GridTableRenderer::PaintRowHeader( bool _bActive, bool _bSelected, OutputDevice& _rDevice, const Rectangle& _rArea,
|
2011-01-03 16:01:14 +01:00
|
|
|
const StyleSettings& _rStyle )
|
2009-08-26 13:11:27 +00:00
|
|
|
{
|
2011-01-04 10:26:14 +01:00
|
|
|
_rDevice.Push( PUSH_LINECOLOR | PUSH_TEXTCOLOR );
|
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
::boost::optional< ::Color > const aLineColor( m_pImpl->rModel.getLineColor() );
|
|
|
|
::Color const lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : *aLineColor;
|
2011-01-12 14:00:45 +01:00
|
|
|
_rDevice.SetLineColor( lineColor );
|
2009-08-26 13:11:27 +00:00
|
|
|
_rDevice.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() );
|
2011-01-04 10:26:14 +01:00
|
|
|
|
2011-01-16 22:18:58 +01:00
|
|
|
Any const rowHeading( m_pImpl->rModel.getRowHeading( m_pImpl->nCurrentRow ) );
|
|
|
|
::rtl::OUString const rowTitle( CellValueConversion::convertToString( rowHeading ) );
|
|
|
|
if ( rowTitle.getLength() )
|
|
|
|
{
|
|
|
|
::Color const textColor = lcl_getEffectiveColor( m_pImpl->rModel.getHeaderTextColor(), _rStyle, &StyleSettings::GetFieldTextColor );
|
|
|
|
_rDevice.SetTextColor( textColor );
|
2011-01-04 10:26:14 +01:00
|
|
|
|
2011-01-16 22:18:58 +01:00
|
|
|
Rectangle const aTextRect( lcl_getTextRenderingArea( lcl_getContentArea( *m_pImpl, _rArea ) ) );
|
|
|
|
ULONG const nDrawTextFlags = lcl_getAlignmentTextDrawFlags( *m_pImpl, 0 ) | TEXT_DRAW_CLIP;
|
|
|
|
// TODO: is using the horizontal alignment of the 0'th column a good idea here? This is pretty ... arbitray ..
|
|
|
|
_rDevice.DrawText( aTextRect, rowTitle, nDrawTextFlags );
|
|
|
|
}
|
2011-01-04 10:26:14 +01:00
|
|
|
|
2009-08-26 13:11:27 +00:00
|
|
|
// TODO: active? selected?
|
|
|
|
(void)_bActive;
|
|
|
|
(void)_bSelected;
|
|
|
|
_rDevice.Pop();
|
|
|
|
}
|
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
2011-01-04 10:26:14 +01:00
|
|
|
struct GridTableRenderer::CellRenderContext
|
|
|
|
{
|
|
|
|
OutputDevice& rDevice;
|
|
|
|
Rectangle const aContentArea;
|
|
|
|
StyleSettings const & rStyle;
|
|
|
|
ColPos const nColumn;
|
|
|
|
bool const bSelected;
|
|
|
|
|
|
|
|
CellRenderContext( OutputDevice& i_device, Rectangle const & i_contentArea,
|
|
|
|
StyleSettings const & i_style, ColPos const i_column, bool const i_selected )
|
|
|
|
:rDevice( i_device )
|
|
|
|
,aContentArea( i_contentArea )
|
|
|
|
,rStyle( i_style )
|
|
|
|
,nColumn( i_column )
|
|
|
|
,bSelected( i_selected )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
2011-01-04 10:26:14 +01:00
|
|
|
void GridTableRenderer::PaintCell( ColPos const i_column, bool _bSelected, bool _bActive,
|
|
|
|
OutputDevice& _rDevice, const Rectangle& _rArea, const StyleSettings& _rStyle )
|
2011-01-11 21:45:47 +01:00
|
|
|
{
|
2011-01-04 10:26:14 +01:00
|
|
|
_rDevice.Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
|
|
|
|
|
2011-01-12 14:00:45 +01:00
|
|
|
Rectangle const aContentArea( lcl_getContentArea( *m_pImpl, _rArea ) );
|
|
|
|
CellRenderContext const aRenderContext( _rDevice, aContentArea, _rStyle, i_column, _bSelected );
|
|
|
|
impl_paintCellContent( aRenderContext );
|
2011-01-12 12:34:24 +01:00
|
|
|
|
2011-01-12 14:00:45 +01:00
|
|
|
if ( m_pImpl->bUseGridLines )
|
2010-02-12 17:08:15 +01:00
|
|
|
{
|
2011-01-12 14:00:45 +01:00
|
|
|
::boost::optional< ::Color > aLineColor( m_pImpl->rModel.getLineColor() );
|
|
|
|
::Color lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : *aLineColor;
|
2011-01-12 12:34:24 +01:00
|
|
|
|
2011-01-12 14:00:45 +01:00
|
|
|
if ( _bSelected && !aLineColor )
|
|
|
|
{
|
|
|
|
// if no line color is specified by the model, use the usual selection color for lines in selected cells
|
|
|
|
lineColor = _rStyle.GetHighlightColor();
|
|
|
|
}
|
2011-01-04 10:26:14 +01:00
|
|
|
|
2011-01-12 14:00:45 +01:00
|
|
|
_rDevice.SetLineColor( lineColor );
|
|
|
|
_rDevice.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() );
|
|
|
|
_rDevice.DrawLine( _rArea.BottomRight(), _rArea.TopRight() );
|
|
|
|
}
|
2011-01-04 10:26:14 +01:00
|
|
|
|
2010-06-04 15:02:11 +02:00
|
|
|
_rDevice.Pop();
|
2010-02-12 17:08:15 +01:00
|
|
|
|
|
|
|
(void)_bActive;
|
2010-03-23 15:28:55 +01:00
|
|
|
// no special painting for the active cell at the moment
|
2010-02-12 17:08:15 +01:00
|
|
|
}
|
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
2011-01-04 10:26:14 +01:00
|
|
|
void GridTableRenderer::impl_paintCellImage( CellRenderContext const & i_context, Image const & i_image )
|
|
|
|
{
|
|
|
|
Point imagePos( Point( i_context.aContentArea.Left(), i_context.aContentArea.Top() ) );
|
|
|
|
Size imageSize = i_image.GetSizePixel();
|
|
|
|
if ( i_context.aContentArea.GetWidth() > imageSize.Width() )
|
2009-08-26 13:11:27 +00:00
|
|
|
{
|
2011-01-04 10:26:14 +01:00
|
|
|
const HorizontalAlignment eHorzAlign = m_pImpl->rModel.getColumnModel( i_context.nColumn )->getHorizontalAlign();
|
|
|
|
switch ( eHorzAlign )
|
|
|
|
{
|
|
|
|
case HorizontalAlignment_CENTER:
|
|
|
|
imagePos.X() += ( i_context.aContentArea.GetWidth() - imageSize.Width() ) / 2;
|
|
|
|
break;
|
|
|
|
case HorizontalAlignment_RIGHT:
|
|
|
|
imagePos.X() = i_context.aContentArea.Right() - imageSize.Width();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-02-12 17:08:15 +01:00
|
|
|
}
|
|
|
|
else
|
2011-01-04 10:26:14 +01:00
|
|
|
imageSize.Width() = i_context.aContentArea.GetWidth();
|
|
|
|
|
|
|
|
if ( i_context.aContentArea.GetHeight() > imageSize.Height() )
|
2010-02-12 17:08:15 +01:00
|
|
|
{
|
2011-01-04 10:26:14 +01:00
|
|
|
const VerticalAlignment eVertAlign = m_pImpl->rModel.getVerticalAlign();
|
|
|
|
switch ( eVertAlign )
|
2010-06-04 15:02:11 +02:00
|
|
|
{
|
2011-01-04 10:26:14 +01:00
|
|
|
case VerticalAlignment_MIDDLE:
|
|
|
|
imagePos.Y() += ( i_context.aContentArea.GetHeight() - imageSize.Height() ) / 2;
|
|
|
|
break;
|
|
|
|
case VerticalAlignment_BOTTOM:
|
|
|
|
imagePos.Y() = i_context.aContentArea.Bottom() - imageSize.Height();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2010-06-04 15:02:11 +02:00
|
|
|
}
|
2009-08-26 13:11:27 +00:00
|
|
|
}
|
2011-01-04 10:26:14 +01:00
|
|
|
else
|
|
|
|
imageSize.Height() = i_context.aContentArea.GetHeight() - 1;
|
2010-06-04 15:02:11 +02:00
|
|
|
|
2011-01-04 10:26:14 +01:00
|
|
|
i_context.rDevice.DrawImage( imagePos, imageSize, i_image, 0 );
|
|
|
|
}
|
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
2011-01-04 10:26:14 +01:00
|
|
|
void GridTableRenderer::impl_paintCellContent( CellRenderContext const & i_context )
|
|
|
|
{
|
|
|
|
Any aCellContent;
|
2011-01-04 10:37:54 +01:00
|
|
|
m_pImpl->rModel.getCellContent( i_context.nColumn, m_pImpl->nCurrentRow, aCellContent );
|
2011-01-04 10:26:14 +01:00
|
|
|
|
2011-01-20 13:52:50 +01:00
|
|
|
if ( aCellContent.getValueTypeClass() == TypeClass_INTERFACE )
|
2011-01-04 10:26:14 +01:00
|
|
|
{
|
2011-01-20 13:52:50 +01:00
|
|
|
Reference< XInterface > const xContentInterface( aCellContent, UNO_QUERY );
|
|
|
|
if ( !xContentInterface.is() )
|
|
|
|
// allowed. kind of.
|
|
|
|
return;
|
|
|
|
|
|
|
|
Reference< XGraphic > const xGraphic( aCellContent, UNO_QUERY );
|
|
|
|
ENSURE_OR_RETURN_VOID( xGraphic.is(), "GridTableRenderer::impl_paintCellContent: only XGraphic interfaces (or NULL) are supported for painting." );
|
|
|
|
|
2011-01-04 10:26:14 +01:00
|
|
|
const Image aImage( xGraphic );
|
|
|
|
impl_paintCellImage( i_context, aImage );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ::rtl::OUString sText( CellValueConversion::convertToString( aCellContent ) );
|
|
|
|
impl_paintCellText( i_context, sText );
|
|
|
|
}
|
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
2011-01-04 10:26:14 +01:00
|
|
|
void GridTableRenderer::impl_paintCellText( CellRenderContext const & i_context, ::rtl::OUString const & i_text )
|
|
|
|
{
|
|
|
|
if ( i_context.bSelected )
|
|
|
|
i_context.rDevice.SetTextColor( i_context.rStyle.GetHighlightTextColor() );
|
2010-06-09 14:39:18 +02:00
|
|
|
else
|
2011-01-12 12:34:24 +01:00
|
|
|
{
|
|
|
|
::Color const textColor = lcl_getEffectiveColor( m_pImpl->rModel.getTextColor(), i_context.rStyle, &StyleSettings::GetFieldTextColor );
|
|
|
|
i_context.rDevice.SetTextColor( textColor );
|
|
|
|
}
|
2011-01-04 10:26:14 +01:00
|
|
|
|
2011-01-12 14:00:45 +01:00
|
|
|
Rectangle const textRect( lcl_getTextRenderingArea( i_context.aContentArea ) );
|
2011-01-12 14:09:38 +01:00
|
|
|
ULONG const nDrawTextFlags = lcl_getAlignmentTextDrawFlags( *m_pImpl, i_context.nColumn ) | TEXT_DRAW_CLIP;
|
|
|
|
i_context.rDevice.DrawText( textRect, i_text, nDrawTextFlags );
|
2009-08-26 13:11:27 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
2009-08-26 13:11:27 +00:00
|
|
|
void GridTableRenderer::ShowCellCursor( Window& _rView, const Rectangle& _rCursorRect)
|
|
|
|
{
|
|
|
|
_rView.ShowFocus( _rCursorRect );
|
|
|
|
}
|
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
2009-08-26 13:11:27 +00:00
|
|
|
void GridTableRenderer::HideCellCursor( Window& _rView, const Rectangle& _rCursorRect)
|
|
|
|
{
|
2011-01-11 21:45:47 +01:00
|
|
|
(void)_rCursorRect;
|
2009-08-26 13:11:27 +00:00
|
|
|
_rView.HideFocus();
|
2011-01-11 21:45:47 +01:00
|
|
|
}
|
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
2011-01-11 21:45:47 +01:00
|
|
|
bool GridTableRenderer::FitsIntoCell( Any const & i_cellContent, ColPos const i_colPos, RowPos const i_rowPos,
|
|
|
|
bool const i_active, bool const i_selected, OutputDevice& i_targetDevice, Rectangle const & i_targetArea )
|
|
|
|
{
|
|
|
|
if ( !i_cellContent.hasValue() )
|
|
|
|
return true;
|
|
|
|
|
2011-01-20 13:52:50 +01:00
|
|
|
if ( i_cellContent.getValueTypeClass() == TypeClass_INTERFACE )
|
|
|
|
{
|
|
|
|
Reference< XInterface > const xContentInterface( i_cellContent, UNO_QUERY );
|
|
|
|
if ( !xContentInterface.is() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Reference< XGraphic > const xGraphic( i_cellContent, UNO_QUERY );
|
|
|
|
if ( xGraphic.is() )
|
|
|
|
// for the moment, assume it fits. We can always scale it down during painting ...
|
|
|
|
return true;
|
|
|
|
|
|
|
|
OSL_ENSURE( false, "GridTableRenderer::FitsIntoCell: only XGraphic interfaces (or NULL) are supported for painting." );
|
2011-01-11 21:45:47 +01:00
|
|
|
return true;
|
2011-01-20 13:52:50 +01:00
|
|
|
}
|
2011-01-11 21:45:47 +01:00
|
|
|
|
|
|
|
::rtl::OUString const sText( CellValueConversion::convertToString( i_cellContent ) );
|
|
|
|
if ( sText.getLength() == 0 )
|
|
|
|
return true;
|
|
|
|
|
2011-01-12 14:00:45 +01:00
|
|
|
Rectangle const aTargetArea( lcl_getTextRenderingArea( lcl_getContentArea( *m_pImpl, i_targetArea ) ) );
|
2011-01-11 21:45:47 +01:00
|
|
|
|
|
|
|
long const nTextHeight = i_targetDevice.GetTextHeight();
|
|
|
|
if ( nTextHeight > aTargetArea.GetHeight() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
long const nTextWidth = i_targetDevice.GetTextWidth( sText );
|
|
|
|
if ( nTextWidth > aTargetArea.GetWidth() )
|
|
|
|
return false;
|
2009-08-26 13:11:27 +00:00
|
|
|
|
2011-01-11 21:45:47 +01:00
|
|
|
OSL_UNUSED( i_active );
|
|
|
|
OSL_UNUSED( i_selected );
|
2011-01-16 21:18:35 +01:00
|
|
|
OSL_UNUSED( i_rowPos );
|
|
|
|
OSL_UNUSED( i_colPos );
|
2011-01-11 21:45:47 +01:00
|
|
|
return true;
|
2009-08-26 13:11:27 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 12:34:24 +01:00
|
|
|
//......................................................................................................................
|
2009-08-26 13:11:27 +00:00
|
|
|
} } // namespace svt::table
|
2011-01-12 12:34:24 +01:00
|
|
|
//......................................................................................................................
|
2009-08-26 13:11:27 +00:00
|
|
|
|