diff options
author | Caolán McNamara <caolanm@redhat.com> | 2016-08-05 14:21:39 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2016-08-08 14:29:08 +0100 |
commit | f045b7610e7a014f17f848140f877f4819ab5c54 (patch) | |
tree | 004796ec6620e56495ad8647a3265a375bd7dac2 /sc | |
parent | 1015d35f2362953f415804476037d4f162eb49b5 (diff) |
Reimplement ScHintWindow::Paint using drawinglayer primitives
they are very verbose and very unpleasant to work with, surely
it doesn't need to be this horrific
Change-Id: I6ad43eb73c94881cca594863f6637302ddc7f1df
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/inc/hintwin.hxx | 17 | ||||
-rw-r--r-- | sc/source/ui/view/hintwin.cxx | 123 |
2 files changed, 101 insertions, 39 deletions
diff --git a/sc/source/ui/inc/hintwin.hxx b/sc/source/ui/inc/hintwin.hxx index 801a7b166e5a..386e340eb650 100644 --- a/sc/source/ui/inc/hintwin.hxx +++ b/sc/source/ui/inc/hintwin.hxx @@ -25,19 +25,18 @@ class ScHintWindow : public vcl::Window { private: - OUString aTitle; - OUString aMessage; - Point aTextStart; - long nTextHeight; - vcl::Font aTextFont; - vcl::Font aHeadFont; + OUString m_aTitle; + OUString m_aMessage; + Point m_aTextStart; + long m_nTextHeight; + vcl::Font m_aTextFont; + vcl::Font m_aHeadFont; protected: - virtual void Paint( vcl::RenderContext& rRenderContext, const Rectangle& rRect ) override; + virtual void Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) override; public: - ScHintWindow( vcl::Window* pParent, const OUString& rTit, const OUString& rMsg ); - virtual ~ScHintWindow(); + ScHintWindow(vcl::Window* pParent, const OUString& rTit, const OUString& rMsg); }; #endif diff --git a/sc/source/ui/view/hintwin.cxx b/sc/source/ui/view/hintwin.cxx index d2ebcae65b79..7e3fbe2641d8 100644 --- a/sc/source/ui/view/hintwin.cxx +++ b/sc/source/ui/view/hintwin.cxx @@ -19,44 +19,55 @@ #include "hintwin.hxx" #include "global.hxx" +#include "scmod.hxx" + +#include <drawinglayer/attribute/fillgradientattribute.hxx> +#include <drawinglayer/attribute/fontattribute.hxx> +#include <drawinglayer/primitive2d/fillgradientprimitive2d.hxx> +#include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx> +#include <drawinglayer/primitive2d/polygonprimitive2d.hxx> +#include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx> +#include <drawinglayer/primitive2d/textlayoutdevice.hxx> +#include <drawinglayer/primitive2d/textprimitive2d.hxx> +#include <drawinglayer/processor2d/processorfromoutputdevice.hxx> +#include <drawinglayer/processor2d/baseprocessor2d.hxx> +#include <basegfx/polygon/b2dpolygontools.hxx> +#include <basegfx/matrix/b2dhommatrixtools.hxx> +#include <svtools/colorcfg.hxx> #define HINT_LINESPACE 2 #define HINT_INDENT 3 #define HINT_MARGIN 4 ScHintWindow::ScHintWindow( vcl::Window* pParent, const OUString& rTit, const OUString& rMsg ) : - Window( pParent, WinBits( WB_BORDER ) ), - aTitle( rTit ), - aMessage( convertLineEnd(rMsg, LINEEND_CR) ) + Window( pParent, 0 ), + m_aTitle( rTit ), + m_aMessage( convertLineEnd(rMsg, LINEEND_CR) ) { - // pale yellow, the same as for notes in detfunc.cxx - Color aYellow( 255,255,192 ); // pale yellow - SetBackground( aYellow ); - - aTextFont = GetFont(); - aTextFont.SetTransparent( true ); - aTextFont.SetWeight( WEIGHT_NORMAL ); - aHeadFont = aTextFont; - aHeadFont.SetWeight( WEIGHT_BOLD ); + m_aTextFont = GetFont(); + m_aTextFont.SetTransparent( true ); + m_aTextFont.SetWeight( WEIGHT_NORMAL ); + m_aHeadFont = m_aTextFont; + m_aHeadFont.SetWeight( WEIGHT_BOLD ); - SetFont( aHeadFont ); - Size aHeadSize( GetTextWidth( aTitle ), GetTextHeight() ); - SetFont( aTextFont ); + SetFont( m_aHeadFont ); + Size aHeadSize( GetTextWidth( m_aTitle ), GetTextHeight() ); + SetFont( m_aTextFont ); Size aTextSize; sal_Int32 nIndex = 0; while ( nIndex != -1 ) { - OUString aLine = aMessage.getToken( 0, '\r', nIndex ); + OUString aLine = m_aMessage.getToken( 0, '\r', nIndex ); Size aLineSize( GetTextWidth( aLine ), GetTextHeight() ); - nTextHeight = aLineSize.Height(); - aTextSize.Height() += nTextHeight; + m_nTextHeight = aLineSize.Height(); + aTextSize.Height() += m_nTextHeight; if ( aLineSize.Width() > aTextSize.Width() ) aTextSize.Width() = aLineSize.Width(); } aTextSize.Width() += HINT_INDENT; - aTextStart = Point( HINT_MARGIN + HINT_INDENT, + m_aTextStart = Point( HINT_MARGIN + HINT_INDENT, aHeadSize.Height() + HINT_MARGIN + HINT_LINESPACE ); Size aWinSize( std::max( aHeadSize.Width(), aTextSize.Width() ) + 2 * HINT_MARGIN + 1, @@ -64,24 +75,76 @@ ScHintWindow::ScHintWindow( vcl::Window* pParent, const OUString& rTit, const OU SetOutputSizePixel( aWinSize ); } -ScHintWindow::~ScHintWindow() +void ScHintWindow::Paint(vcl::RenderContext& rRenderContext, const Rectangle& /* rRect */) { -} + // Create the processor and process the primitives + const drawinglayer::geometry::ViewInformation2D aNewViewInfos; + std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> xProcessor( + drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(rRenderContext, aNewViewInfos)); -void ScHintWindow::Paint( vcl::RenderContext& /*rRenderContext*/, const Rectangle& /* rRect */ ) -{ - SetFont( aHeadFont ); - DrawText( Point(HINT_MARGIN,HINT_MARGIN), aTitle ); + const Rectangle aRect(Rectangle(Point(0, 0), rRenderContext.PixelToLogic(GetSizePixel()))); + basegfx::B2DPolygon aPoly(basegfx::tools::createPolygonFromRect(basegfx::B2DRectangle(aRect.Left(), aRect.Top(), + aRect.Right(), aRect.Bottom()))); + + const svtools::ColorConfig& rColorCfg = SC_MOD()->GetColorConfig(); + Color aCommentColor = rColorCfg.GetColorValue(svtools::CALCNOTESBACKGROUND).nColor; + const drawinglayer::primitive2d::Primitive2DReference aBg( + new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aPoly), aCommentColor.getBColor())); + + basegfx::BColor aBorder(0.5, 0.5, 0.5); + const drawinglayer::primitive2d::Primitive2DReference aReference( + new drawinglayer::primitive2d::PolygonHairlinePrimitive2D( + aPoly, aBorder)); + + // Create the text primitive for the title + basegfx::B2DVector aFontSize; + drawinglayer::attribute::FontAttribute aFontAttr = + drawinglayer::primitive2d::getFontAttributeFromVclFont(aFontSize, m_aHeadFont, false, false); + + FontMetric aFontMetric = rRenderContext.GetFontMetric(m_aHeadFont); + double nTextOffsetY = aFontMetric.GetAscent() + HINT_MARGIN; + Point aTextPos(HINT_MARGIN, nTextOffsetY); + + basegfx::B2DHomMatrix aTextMatrix(basegfx::tools::createScaleTranslateB2DHomMatrix( + aFontSize.getX(), aFontSize.getY(), + double(aTextPos.X()), double(aTextPos.Y()))); + + const drawinglayer::primitive2d::Primitive2DReference aTitle( + new drawinglayer::primitive2d::TextSimplePortionPrimitive2D( + aTextMatrix, m_aTitle, 0, m_aTitle.getLength(), + std::vector<double>(), aFontAttr, css::lang::Locale(), + GetLineColor().getBColor())); + + drawinglayer::primitive2d::Primitive2DContainer aSeq { aBg, aReference, aTitle }; + + aFontMetric = rRenderContext.GetFontMetric(m_aTextFont); + nTextOffsetY = aFontMetric.GetAscent(); + + aFontAttr = drawinglayer::primitive2d::getFontAttributeFromVclFont(aFontSize, m_aTextFont, false, false); - SetFont( aTextFont ); sal_Int32 nIndex = 0; - Point aLineStart = aTextStart; + Point aLineStart = m_aTextStart; while ( nIndex != -1 ) { - OUString aLine = aMessage.getToken( 0, '\r', nIndex ); - DrawText( aLineStart, aLine ); - aLineStart.Y() += nTextHeight; + OUString aLine = m_aMessage.getToken( 0, '\r', nIndex ); + + aTextMatrix = basegfx::tools::createScaleTranslateB2DHomMatrix( + aFontSize.getX(), aFontSize.getY(), + aLineStart.X(), aLineStart.Y() + nTextOffsetY); + + // Create the text primitive for each line of text + const drawinglayer::primitive2d::Primitive2DReference aMessage( + new drawinglayer::primitive2d::TextSimplePortionPrimitive2D( + aTextMatrix, aLine, 0, aLine.getLength(), + std::vector<double>(), aFontAttr, css::lang::Locale(), + GetLineColor().getBColor())); + + aSeq.push_back(aMessage); + + aLineStart.Y() += m_nTextHeight; } + + xProcessor->process(aSeq); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |