LibreOffice Module sc (master)  1
hintwin.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <overlayobject.hxx>
21 
30 #include <tools/lineend.hxx>
31 #include <vcl/outdev.hxx>
32 #include <vcl/settings.hxx>
33 #include <vcl/metric.hxx>
34 
35 #define HINT_LINESPACE 2
36 #define HINT_INDENT 3
37 #define HINT_MARGIN 4
38 
39 ScOverlayHint::ScOverlayHint(const OUString& rTit, const OUString& rMsg, const Color& rColor, const vcl::Font& rFont)
40  : OverlayObject(rColor)
41  , m_aTitle(rTit)
42  , m_aMessage(convertLineEnd(rMsg, LINEEND_CR))
43  , m_aTextFont(rFont)
44  , m_aMapMode(MapUnit::MapPixel)
45  , m_nLeft(0)
46  , m_nTop(0)
47 {
48 }
49 
51  const MapMode &rMapMode,
52  basegfx::B2DRange &rRange) const
53 {
55  MapMode aOld = pDefaultDev->GetMapMode();
56  pDefaultDev->SetMapMode(rMapMode);
57 
58  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
59  const Color& rColor = rStyleSettings.GetLabelTextColor();
60  vcl::Font aTextFont = m_aTextFont;
61  aTextFont.SetFontSize(pDefaultDev->PixelToLogic(aTextFont.GetFontSize(), rMapMode));
62  vcl::Font aHeadFont = aTextFont;
63  aHeadFont.SetWeight(WEIGHT_BOLD);
64 
65  // Create the text primitive for the title
66  basegfx::B2DVector aFontSize;
68  drawinglayer::primitive2d::getFontAttributeFromVclFont(aFontSize, aHeadFont, false, false);
69 
70  FontMetric aFontMetric = pDefaultDev->GetFontMetric(aHeadFont);
71  Size aHintMargin = pDefaultDev->PixelToLogic(Size(HINT_MARGIN, HINT_MARGIN), rMapMode);
72  Size aIndent = pDefaultDev->PixelToLogic(Size(HINT_INDENT, HINT_LINESPACE), rMapMode);
73  double nTextOffsetY = nTop + aHintMargin.Height() + aFontMetric.GetAscent();
74  Point aTextPos(nLeft + aHintMargin.Width() , nTextOffsetY);
75  rRange = basegfx::B2DRange(nLeft, nTop, nLeft + aHintMargin.Width(), nTop + aHintMargin.Height());
76 
78  aFontSize.getX(), aFontSize.getY(),
79  aTextPos.X(), aTextPos.Y()));
80 
83  aTextMatrix, m_aTitle, 0, m_aTitle.getLength(),
84  std::vector<double>(), aFontAttr, css::lang::Locale(),
85  rColor.getBColor());
86 
88 
89  Point aTextStart(nLeft + aHintMargin.Width() + aIndent.Width(),
90  nTop + aHintMargin.Height() + aFontMetric.GetLineHeight() + aIndent.Height());
91 
93  rRange.expand(pTitle->getB2DRange(aDummy));
94 
96 
97  aFontMetric = pDefaultDev->GetFontMetric(aTextFont);
98  pDefaultDev->SetMapMode(aOld);
99 
100  nTextOffsetY = aFontMetric.GetAscent();
101  sal_Int32 nLineHeight = aFontMetric.GetLineHeight();
102 
103  aFontAttr = drawinglayer::primitive2d::getFontAttributeFromVclFont(aFontSize, aTextFont, false, false);
104 
105  sal_Int32 nIndex = 0;
106  Point aLineStart = aTextStart;
107  while (nIndex != -1)
108  {
109  OUString aLine = m_aMessage.getToken( 0, '\r', nIndex );
110 
112  aFontSize.getX(), aFontSize.getY(),
113  aLineStart.X(), aLineStart.Y() + nTextOffsetY);
114 
115  // Create the text primitive for each line of text
118  aTextMatrix, aLine, 0, aLine.getLength(),
119  std::vector<double>(), aFontAttr, css::lang::Locale(),
120  rColor.getBColor());
121 
122  rRange.expand(pMessage->getB2DRange(aDummy));
123 
124  const drawinglayer::primitive2d::Primitive2DReference aMessage(pMessage);
125  aSeq.push_back(aMessage);
126 
127  aLineStart.AdjustY(nLineHeight );
128  }
129 
130  rRange.expand(basegfx::B2DTuple(rRange.getMaxX() + aHintMargin.Width(),
131  rRange.getMaxY() + aHintMargin.Height()));
132 
134 
137 
138  basegfx::BColor aBorderColor(0.5, 0.5, 0.5);
141  aPoly, aBorderColor));
142 
143  aSeq.insert(aSeq.begin(), aBorder);
144  aSeq.insert(aSeq.begin(), aBg);
145 
146  return aSeq;
147 }
148 
150 {
151  basegfx::B2DRange aRange;
153 }
154 
156 {
157  basegfx::B2DRange aRange;
158  createOverlaySequence(0, 0, MapMode(MapUnit::MapPixel), aRange);
159  return Size(aRange.getWidth(), aRange.getHeight());
160 }
161 
162 void ScOverlayHint::SetPos(const Point& rPos, const MapMode& rMode)
163 {
164  m_nLeft = rPos.X();
165  m_nTop = rPos.Y();
166  m_aMapMode = rMode;
167 }
168 
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
sal_Int32 nIndex
void SetFontSize(const Size &)
TOOLS_DLLPUBLIC OString convertLineEnd(const OString &rIn, LineEnd eLineEnd)
const vcl::Font m_aTextFont
double getHeight() const
long Height() const
#define HINT_MARGIN
Definition: hintwin.cxx:37
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
double getX() const
void SetWeight(FontWeight)
const MapMode & GetMapMode() const
double getY() const
const Color & GetLabelTextColor() const
LINEEND_CR
void SetMapMode()
attribute::FontAttribute getFontAttributeFromVclFont(basegfx::B2DVector &o_rSize, const vcl::Font &rFont, bool bRTL, bool bBiDiStrong)
static OutputDevice * GetDefaultDevice()
WEIGHT_BOLD
double getWidth() const
B2DHomMatrix createScaleTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fTranslateX, double fTranslateY)
FontMetric GetFontMetric() const
void SetPos(const Point &rPos, const MapMode &rMode)
Definition: hintwin.cxx:162
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
const Size & GetFontSize() const
drawinglayer::primitive2d::Primitive2DContainer createOverlaySequence(sal_Int32 nLeft, sal_Int32 nTop, const MapMode &rMapMode, basegfx::B2DRange &rRange) const
Definition: hintwin.cxx:50
long GetAscent() const
#define HINT_INDENT
Definition: hintwin.cxx:36
#define HINT_LINESPACE
Definition: hintwin.cxx:35
virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D &rViewInformation) const override
Point PixelToLogic(const Point &rDevicePt) const
const Color & getBaseColor() const
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
sal_Int32 m_nTop
const OUString m_aTitle
Sequence< sal_Int8 > aSeq
basegfx::BColor getBColor() const
Size GetSizePixel() const
Definition: hintwin.cxx:155
MapUnit
const OUString m_aMessage
virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override
Definition: hintwin.cxx:149
ScOverlayHint(const OUString &rTit, const OUString &rMsg, const Color &rColor, const vcl::Font &rFont)
Definition: hintwin.cxx:39
sal_Int32 m_nLeft
MapMode m_aMapMode
long GetLineHeight() const