summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-05-14 16:36:33 +0900
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-05-15 08:56:25 +0900
commit888f08889fe954e6cb47b26853f5e86ecc7f9a82 (patch)
tree0bf89d87f2089524570a0bee82c2683d2885ad19 /sc
parent3047de0f92c9d18cb77d78e26542ca004d3e4958 (diff)
refactor AutoFmtPreview to use RenderContext
Change-Id: Icaed24f08cfa85f3f91c3f2351384a0b59242d03
Diffstat (limited to 'sc')
-rw-r--r--sc/source/ui/inc/autofmt.hxx56
-rw-r--r--sc/source/ui/miscdlgs/autofmt.cxx369
2 files changed, 207 insertions, 218 deletions
diff --git a/sc/source/ui/inc/autofmt.hxx b/sc/source/ui/inc/autofmt.hxx
index 6edfd3b6bf0c..6beebfd9b994 100644
--- a/sc/source/ui/inc/autofmt.hxx
+++ b/sc/source/ui/inc/autofmt.hxx
@@ -55,10 +55,9 @@ protected:
virtual void Resize() SAL_OVERRIDE;
private:
- ScAutoFormatData* pCurData;
+ ScAutoFormatData* pCurData;
ScopedVclPtrInstance<VirtualDevice> aVD;
- SvtScriptedTextHelper aScriptedText;
- ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > xBreakIter;
+ css::uno::Reference<css::i18n::XBreakIterator> xBreakIter;
bool bFitWidth;
svx::frame::Array maArray; /// Implementation to draw the frame borders.
bool mbRTL;
@@ -76,40 +75,33 @@ private:
const OUString aStrSum;
SvNumberFormatter* pNumFmt;
- SAL_DLLPRIVATE void Init ();
- SAL_DLLPRIVATE void DoPaint ( const Rectangle& rRect );
- SAL_DLLPRIVATE void CalcCellArray ( bool bFitWidth );
- SAL_DLLPRIVATE void CalcLineMap ();
- SAL_DLLPRIVATE void PaintCells ();
+ SAL_DLLPRIVATE void Init();
+ SAL_DLLPRIVATE void DoPaint(vcl::RenderContext& rRenderContext, const Rectangle& rRect);
+ SAL_DLLPRIVATE void CalcCellArray(bool bFitWidth);
+ SAL_DLLPRIVATE void CalcLineMap();
+ SAL_DLLPRIVATE void PaintCells(vcl::RenderContext& rRenderContext);
/* Usage of type size_t instead of SCCOL/SCROW is correct here - used in
conjunction with class svx::frame::Array (svx/framelinkarray.hxx), which
expects size_t coordinates. */
- SAL_DLLPRIVATE sal_uInt16 GetFormatIndex( size_t nCol, size_t nRow ) const;
- SAL_DLLPRIVATE const SvxBoxItem& GetBoxItem( size_t nCol, size_t nRow ) const;
- SAL_DLLPRIVATE const SvxLineItem& GetDiagItem( size_t nCol, size_t nRow, bool bTLBR ) const;
-
- SAL_DLLPRIVATE void DrawString( size_t nCol, size_t nRow );
- SAL_DLLPRIVATE void DrawStrings();
- SAL_DLLPRIVATE void DrawBackground();
-
- SAL_DLLPRIVATE void MakeFonts ( sal_uInt16 nIndex,
- vcl::Font& rFont,
- vcl::Font& rCJKFont,
- vcl::Font& rCTLFont );
-
- SAL_DLLPRIVATE void CheckPriority ( sal_uInt16 nCurLine,
- AutoFmtLine eLine,
- ::editeng::SvxBorderLine& rLine );
- SAL_DLLPRIVATE void GetLines ( sal_uInt16 nIndex, AutoFmtLine eLine,
- ::editeng::SvxBorderLine& rLineD,
- ::editeng::SvxBorderLine& rLineLT,
- ::editeng::SvxBorderLine& rLineL,
- ::editeng::SvxBorderLine& rLineLB,
- ::editeng::SvxBorderLine& rLineRT,
- ::editeng::SvxBorderLine& rLineR,
- ::editeng::SvxBorderLine& rLineRB );
+ SAL_DLLPRIVATE sal_uInt16 GetFormatIndex( size_t nCol, size_t nRow ) const;
+ SAL_DLLPRIVATE const SvxBoxItem& GetBoxItem( size_t nCol, size_t nRow ) const;
+ SAL_DLLPRIVATE const SvxLineItem& GetDiagItem( size_t nCol, size_t nRow, bool bTLBR ) const;
+
+ SAL_DLLPRIVATE void DrawString(vcl::RenderContext& rRenderContext, size_t nCol, size_t nRow);
+ SAL_DLLPRIVATE void DrawStrings(vcl::RenderContext& rRenderContext);
+ SAL_DLLPRIVATE void DrawBackground(vcl::RenderContext& rRenderContext);
+
+ SAL_DLLPRIVATE void MakeFonts(sal_uInt16 nIndex, vcl::Font& rFont,
+ vcl::Font& rCJKFont, vcl::Font& rCTLFont );
+
+ SAL_DLLPRIVATE void CheckPriority(sal_uInt16 nCurLine, AutoFmtLine eLine, editeng::SvxBorderLine& rLine);
+ SAL_DLLPRIVATE void GetLines(sal_uInt16 nIndex, AutoFmtLine eLine,
+ editeng::SvxBorderLine& rLineD, editeng::SvxBorderLine& rLineLT,
+ editeng::SvxBorderLine& rLineL, editeng::SvxBorderLine& rLineLB,
+ editeng::SvxBorderLine& rLineRT, editeng::SvxBorderLine& rLineR,
+ editeng::SvxBorderLine& rLineRB);
};
#endif // INCLUDED_SC_SOURCE_UI_INC_AUTOFMT_HXX
diff --git a/sc/source/ui/miscdlgs/autofmt.cxx b/sc/source/ui/miscdlgs/autofmt.cxx
index 45baa5b3c421..6a3d9d5ef785 100644
--- a/sc/source/ui/miscdlgs/autofmt.cxx
+++ b/sc/source/ui/miscdlgs/autofmt.cxx
@@ -59,7 +59,6 @@ ScAutoFmtPreview::ScAutoFmtPreview(vcl::Window* pParent)
: Window(pParent)
, pCurData(NULL)
, aVD(*this)
- , aScriptedText(*aVD.get())
, bFitWidth(false)
, mbRTL(false)
, aStrJan(ScResId(STR_JAN))
@@ -184,226 +183,224 @@ const SvxLineItem& ScAutoFmtPreview::GetDiagItem( size_t nCol, size_t nRow, bool
return *static_cast< const SvxLineItem* >( pCurData->GetItem( GetFormatIndex( nCol, nRow ), bTLBR ? ATTR_BORDER_TLBR : ATTR_BORDER_BLTR ) );
}
-void ScAutoFmtPreview::DrawString( size_t nCol, size_t nRow )
+void ScAutoFmtPreview::DrawString(vcl::RenderContext& rRenderContext, size_t nCol, size_t nRow)
{
- if ( pCurData )
+ if (!pCurData)
{
+ return;
+ }
- // Emit the cell text
+ // Emit the cell text
- OUString cellString;
- bool bNumFormat = pCurData->GetIncludeValueFormat();
- sal_uLong nNum;
- double nVal;
- Color* pDummy = NULL;
- sal_uInt16 nIndex = static_cast< sal_uInt16 >( maArray.GetCellIndex( nCol, nRow, mbRTL ) );
+ OUString cellString;
+ bool bNumFormat = pCurData->GetIncludeValueFormat();
+ sal_uLong nNum;
+ double nVal;
+ Color* pDummy = NULL;
+ sal_uInt16 nIndex = static_cast<sal_uInt16>(maArray.GetCellIndex(nCol, nRow, mbRTL));
- switch( nIndex )
- {
- case 1: cellString = aStrJan; break;
- case 2: cellString = aStrFeb; break;
- case 3: cellString = aStrMar; break;
- case 5: cellString = aStrNorth; break;
- case 10: cellString = aStrMid; break;
- case 15: cellString = aStrSouth; break;
- case 4:
- case 20: cellString = aStrSum; break;
-
- case 6:
- case 8:
- case 16:
- case 18: nVal = nIndex;
- nNum = 5;
- goto mknum;
- case 17:
- case 7: nVal = nIndex;
- nNum = 6;
- goto mknum;
- case 11:
- case 12:
- case 13: nVal = nIndex;
- nNum = 12 == nIndex ? 10 : 9;
- goto mknum;
-
- case 9: nVal = 21; nNum = 7; goto mknum;
- case 14: nVal = 36; nNum = 11; goto mknum;
- case 19: nVal = 51; nNum = 7; goto mknum;
- case 21: nVal = 33; nNum = 13; goto mknum;
- case 22: nVal = 36; nNum = 14; goto mknum;
- case 23: nVal = 39; nNum = 13; goto mknum;
- case 24: nVal = 108; nNum = 15;
- mknum:
- if( bNumFormat )
- {
- ScNumFormatAbbrev& rNumFormat = (ScNumFormatAbbrev&)pCurData->GetNumFormat( (sal_uInt16) nNum );
- nNum = rNumFormat.GetFormatIndex( *pNumFmt );
- }
- else
- nNum = 0;
- pNumFmt->GetOutputString( nVal, nNum, cellString, &pDummy );
- break;
- }
+ switch (nIndex)
+ {
+ case 1: cellString = aStrJan; break;
+ case 2: cellString = aStrFeb; break;
+ case 3: cellString = aStrMar; break;
+ case 5: cellString = aStrNorth; break;
+ case 10: cellString = aStrMid; break;
+ case 15: cellString = aStrSouth; break;
+ case 4:
+ case 20: cellString = aStrSum; break;
+
+ case 6:
+ case 8:
+ case 16:
+ case 18: nVal = nIndex;
+ nNum = 5;
+ goto mknum;
+ case 17:
+ case 7: nVal = nIndex;
+ nNum = 6;
+ goto mknum;
+ case 11:
+ case 12:
+ case 13: nVal = nIndex;
+ nNum = 12 == nIndex ? 10 : 9;
+ goto mknum;
+
+ case 9: nVal = 21; nNum = 7; goto mknum;
+ case 14: nVal = 36; nNum = 11; goto mknum;
+ case 19: nVal = 51; nNum = 7; goto mknum;
+ case 21: nVal = 33; nNum = 13; goto mknum;
+ case 22: nVal = 36; nNum = 14; goto mknum;
+ case 23: nVal = 39; nNum = 13; goto mknum;
+ case 24: nVal = 108; nNum = 15;
+ mknum:
+ if (bNumFormat)
+ {
+ ScNumFormatAbbrev& rNumFormat = (ScNumFormatAbbrev&) pCurData->GetNumFormat(sal_uInt16(nNum));
+ nNum = rNumFormat.GetFormatIndex(*pNumFmt);
+ }
+ else
+ nNum = 0;
+ pNumFmt->GetOutputString(nVal, nNum, cellString, &pDummy);
+ break;
+ }
+
+ if (!cellString.isEmpty())
+ {
+
+ Size aStrSize;
+ sal_uInt16 nFmtIndex = GetFormatIndex( nCol, nRow );
+ Rectangle cellRect = maArray.GetCellRect( nCol, nRow );
+ Point aPos = cellRect.TopLeft();
+ sal_uInt16 nRightX = 0;
+ bool bJustify = pCurData->GetIncludeJustify();
+ SvxHorJustifyItem aHorJustifyItem( SVX_HOR_JUSTIFY_STANDARD, ATTR_HOR_JUSTIFY );
+ SvxCellHorJustify eJustification;
- if ( !cellString.isEmpty())
+ SvtScriptedTextHelper aScriptedText(rRenderContext);
+
+ // Justification:
+
+ eJustification = mbRTL ? SVX_HOR_JUSTIFY_RIGHT : bJustify ?
+ (SvxCellHorJustify) (static_cast<const SvxHorJustifyItem*>(pCurData->GetItem(nFmtIndex, ATTR_HOR_JUSTIFY))->GetValue()) :
+ SVX_HOR_JUSTIFY_STANDARD;
+
+ if (pCurData->GetIncludeFont())
{
- Size aStrSize;
- sal_uInt16 nFmtIndex = GetFormatIndex( nCol, nRow );
- Rectangle cellRect = maArray.GetCellRect( nCol, nRow );
- Point aPos = cellRect.TopLeft();
- sal_uInt16 nRightX = 0;
- bool bJustify = pCurData->GetIncludeJustify();
- SvxHorJustifyItem aHorJustifyItem( SVX_HOR_JUSTIFY_STANDARD, ATTR_HOR_JUSTIFY );
- SvxCellHorJustify eJustification;
-
- // Justification:
-
- eJustification = mbRTL ? SVX_HOR_JUSTIFY_RIGHT : bJustify ?
- (SvxCellHorJustify)(static_cast<const SvxHorJustifyItem*>(pCurData->GetItem( nFmtIndex, ATTR_HOR_JUSTIFY ))->GetValue()) :
- SVX_HOR_JUSTIFY_STANDARD;
-
- if ( pCurData->GetIncludeFont() )
- {
- vcl::Font aFont, aCJKFont, aCTLFont;
- Size theMaxStrSize;
+ vcl::Font aFont, aCJKFont, aCTLFont;
+ Size theMaxStrSize;
- MakeFonts( nFmtIndex, aFont, aCJKFont, aCTLFont );
+ MakeFonts( nFmtIndex, aFont, aCJKFont, aCTLFont );
- theMaxStrSize = cellRect.GetSize();
- theMaxStrSize.Width() -= FRAME_OFFSET;
- theMaxStrSize.Height() -= FRAME_OFFSET;
+ theMaxStrSize = cellRect.GetSize();
+ theMaxStrSize.Width() -= FRAME_OFFSET;
+ theMaxStrSize.Height() -= FRAME_OFFSET;
- aScriptedText.SetFonts( &aFont, &aCJKFont, &aCTLFont );
- aScriptedText.SetText( cellString, xBreakIter );
- aStrSize = aScriptedText.GetTextSize();
+ aScriptedText.SetFonts( &aFont, &aCJKFont, &aCTLFont );
+ aScriptedText.SetText(cellString, xBreakIter);
+ aStrSize = aScriptedText.GetTextSize();
- if ( theMaxStrSize.Height() < aStrSize.Height() )
- {
- // if the string does not fit in the row using this font,
- // the default font is used
- aScriptedText.SetDefaultFont();
- aStrSize = aScriptedText.GetTextSize();
- }
- while ( ( theMaxStrSize.Width() <= aStrSize.Width() )
- && ( cellString.getLength() > 1 ) )
- {
- if( eJustification == SVX_HOR_JUSTIFY_RIGHT )
- cellString = cellString.copy(1);
- else
- cellString = cellString.copy(0, cellString.getLength() - 1 );
-
- aScriptedText.SetText( cellString, xBreakIter );
- aStrSize = aScriptedText.GetTextSize();
- }
- }
- else
+ if (theMaxStrSize.Height() < aStrSize.Height())
{
+ // if the string does not fit in the row using this font,
+ // the default font is used
aScriptedText.SetDefaultFont();
- aScriptedText.SetText( cellString, xBreakIter );
aStrSize = aScriptedText.GetTextSize();
}
+ while((theMaxStrSize.Width() <= aStrSize.Width()) && (cellString.getLength() > 1))
+ {
+ if( eJustification == SVX_HOR_JUSTIFY_RIGHT )
+ cellString = cellString.copy(1);
+ else
+ cellString = cellString.copy(0, cellString.getLength() - 1 );
- nRightX = (sal_uInt16)( cellRect.GetWidth()
- - aStrSize.Width()
- - FRAME_OFFSET );
+ aScriptedText.SetText( cellString, xBreakIter );
+ aStrSize = aScriptedText.GetTextSize();
+ }
+ }
+ else
+ {
+ aScriptedText.SetDefaultFont();
+ aScriptedText.SetText( cellString, xBreakIter );
+ aStrSize = aScriptedText.GetTextSize();
+ }
- // vertical (always center):
+ nRightX = sal_uInt16(cellRect.GetWidth() - aStrSize.Width() - FRAME_OFFSET);
- aPos.Y() += (mnRowHeight - (sal_uInt16)aStrSize.Height()) / 2;
+ // vertical (always center):
- // horizontal
+ aPos.Y() += (mnRowHeight - (sal_uInt16)aStrSize.Height()) / 2;
- if ( eJustification != SVX_HOR_JUSTIFY_STANDARD )
- {
- sal_uInt16 nHorPos = (sal_uInt16)
- ((cellRect.GetWidth()-aStrSize.Width())/2);
-
- switch ( eJustification )
- {
- case SVX_HOR_JUSTIFY_LEFT:
- aPos.X() += FRAME_OFFSET;
- break;
- case SVX_HOR_JUSTIFY_RIGHT:
- aPos.X() += nRightX;
- break;
- case SVX_HOR_JUSTIFY_BLOCK:
- case SVX_HOR_JUSTIFY_REPEAT:
- case SVX_HOR_JUSTIFY_CENTER:
- aPos.X() += nHorPos;
- break;
- // coverity[dead_error_begin] - following conditions exist to avoid compiler warning
- case SVX_HOR_JUSTIFY_STANDARD:
- default:
- // Standard is not handled here
- break;
- }
- }
- else
- {
+ // horizontal
- // Standard justification
+ if (eJustification != SVX_HOR_JUSTIFY_STANDARD)
+ {
+ sal_uInt16 nHorPos = sal_uInt16((cellRect.GetWidth()-aStrSize.Width()) / 2);
- if ( (nCol == 0) || (nRow == 0) )
- {
- // Text label to the left or sum left adjusted
+ switch (eJustification)
+ {
+ case SVX_HOR_JUSTIFY_LEFT:
aPos.X() += FRAME_OFFSET;
- }
- else
- {
- // Numbers/Dates right adjusted
+ break;
+ case SVX_HOR_JUSTIFY_RIGHT:
aPos.X() += nRightX;
- }
+ break;
+ case SVX_HOR_JUSTIFY_BLOCK:
+ case SVX_HOR_JUSTIFY_REPEAT:
+ case SVX_HOR_JUSTIFY_CENTER:
+ aPos.X() += nHorPos;
+ break;
+ // coverity[dead_error_begin] - following conditions exist to avoid compiler warning
+ case SVX_HOR_JUSTIFY_STANDARD:
+ default:
+ // Standard is not handled here
+ break;
}
+ }
+ else
+ {
- aScriptedText.DrawText( aPos );
+ // Standard justification
+ if (nCol == 0 || nRow == 0)
+ {
+ // Text label to the left or sum left adjusted
+ aPos.X() += FRAME_OFFSET;
+ }
+ else
+ {
+ // Numbers/Dates right adjusted
+ aPos.X() += nRightX;
+ }
}
+ aScriptedText.DrawText(aPos);
}
}
#undef FRAME_OFFSET
-void ScAutoFmtPreview::DrawStrings()
+void ScAutoFmtPreview::DrawStrings(vcl::RenderContext& rRenderContext)
{
- for( size_t nRow = 0; nRow < 5; ++nRow )
- for( size_t nCol = 0; nCol < 5; ++nCol )
- DrawString( nCol, nRow );
+ for(size_t nRow = 0; nRow < 5; ++nRow)
+ for(size_t nCol = 0; nCol < 5; ++nCol)
+ DrawString(rRenderContext, nCol, nRow);
}
-void ScAutoFmtPreview::DrawBackground()
+void ScAutoFmtPreview::DrawBackground(vcl::RenderContext& rRenderContext)
{
- if( pCurData )
+ if (pCurData)
{
- for( size_t nRow = 0; nRow < 5; ++nRow )
+ for(size_t nRow = 0; nRow < 5; ++nRow)
{
- for( size_t nCol = 0; nCol < 5; ++nCol )
+ for(size_t nCol = 0; nCol < 5; ++nCol)
{
const SvxBrushItem* pItem = static_cast< const SvxBrushItem* >(
pCurData->GetItem( GetFormatIndex( nCol, nRow ), ATTR_BACKGROUND ) );
- aVD->Push( PushFlags::LINECOLOR | PushFlags::FILLCOLOR );
- aVD->SetLineColor();
- aVD->SetFillColor( pItem->GetColor() );
- aVD->DrawRect( maArray.GetCellRect( nCol, nRow ) );
- aVD->Pop();
+ rRenderContext.Push( PushFlags::LINECOLOR | PushFlags::FILLCOLOR );
+ rRenderContext.SetLineColor();
+ rRenderContext.SetFillColor( pItem->GetColor() );
+ rRenderContext.DrawRect( maArray.GetCellRect( nCol, nRow ) );
+ rRenderContext.Pop();
}
}
}
}
-void ScAutoFmtPreview::PaintCells()
+void ScAutoFmtPreview::PaintCells(vcl::RenderContext& rRenderContext)
{
- if ( pCurData )
+ if (pCurData)
{
// 1) background
- if ( pCurData->GetIncludeBackground() )
- DrawBackground();
+ if (pCurData->GetIncludeBackground())
+ DrawBackground(rRenderContext);
// 2) values
- DrawStrings();
+ DrawStrings(rRenderContext);
// 3) border
- if ( pCurData->GetIncludeFrame() )
- maArray.DrawArray( *aVD.get() );
+ if (pCurData->GetIncludeFrame())
+ maArray.DrawArray(rRenderContext);
}
}
@@ -483,42 +480,42 @@ void ScAutoFmtPreview::NotifyChange( ScAutoFormatData* pNewData )
CalcCellArray( bFitWidth );
CalcLineMap();
- DoPaint( Rectangle( Point(0,0), GetSizePixel() ) );
+ Invalidate(Rectangle(Point(0,0), GetSizePixel()));
}
-void ScAutoFmtPreview::DoPaint( const Rectangle& /* rRect */ )
+void ScAutoFmtPreview::DoPaint(vcl::RenderContext& rRenderContext, const Rectangle& /*rRect*/)
{
sal_uInt32 nOldDrawMode = aVD->GetDrawMode();
- Size aWndSize( GetSizePixel() );
- vcl::Font aFont( aVD->GetFont() );
- Color aBackCol( GetSettings().GetStyleSettings().GetWindowColor() );
+ Size aWndSize(GetSizePixel());
+ vcl::Font aFont(aVD->GetFont());
+ Color aBackCol(rRenderContext.GetSettings().GetStyleSettings().GetWindowColor());
Point aTmpPoint;
- Rectangle aRect( aTmpPoint, aWndSize );
+ Rectangle aRect(aTmpPoint, aWndSize);
aFont.SetTransparent( true );
- aVD->SetFont( aFont );
+ aVD->SetFont(aFont);
aVD->SetLineColor();
- aVD->SetFillColor( aBackCol );
- aVD->SetOutputSize( aWndSize );
- aVD->DrawRect( aRect );
+ aVD->SetFillColor(aBackCol);
+ aVD->SetOutputSize(aWndSize);
+ aVD->DrawRect(aRect);
+
+ PaintCells(*aVD.get());
- PaintCells();
- SetLineColor();
- SetFillColor( aBackCol );
- DrawRect( aRect );
+ rRenderContext.SetLineColor();
+ rRenderContext.SetFillColor(aBackCol);
+ rRenderContext.DrawRect(aRect);
- Point aPos( (aWndSize.Width() - aPrvSize.Width()) / 2, (aWndSize.Height() - aPrvSize.Height()) / 2 );
+ Point aPos((aWndSize.Width() - aPrvSize.Width()) / 2, (aWndSize.Height() - aPrvSize.Height()) / 2);
if (AllSettings::GetLayoutRTL())
aPos.X() = -aPos.X();
- DrawOutDev( aPos, aWndSize, Point(), aWndSize, *aVD.get() );
-
- aVD->SetDrawMode( nOldDrawMode );
+ rRenderContext.DrawOutDev(aPos, aWndSize, Point(), aWndSize, *aVD.get());
+ aVD->SetDrawMode(nOldDrawMode);
}
-void ScAutoFmtPreview::Paint( vcl::RenderContext& /*rRenderContext*/, const Rectangle& rRect )
+void ScAutoFmtPreview::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect)
{
- DoPaint( rRect );
+ DoPaint(rRenderContext, rRect);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */