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 #include <sal/log.hxx>
35 
36 #define HINT_LINESPACE 2
37 #define HINT_INDENT 3
38 #define HINT_MARGIN 4
39 
40 ScOverlayHint::ScOverlayHint(const OUString& rTit, const OUString& rMsg, const Color& rColor, const vcl::Font& rFont)
41  : OverlayObject(rColor)
42  , m_aTitle(rTit)
43  , m_aMessage(convertLineEnd(rMsg, LINEEND_CR))
44  , m_aTextFont(rFont)
45  , m_aMapMode(MapUnit::MapPixel)
46  , m_nLeft(0)
47  , m_nTop(0)
48 {
49 }
50 
52  const MapMode &rMapMode,
53  basegfx::B2DRange &rRange) const
54 {
56  MapMode aOld = pDefaultDev->GetMapMode();
57  pDefaultDev->SetMapMode(rMapMode);
58 
59  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
60  const Color& rColor = rStyleSettings.GetLabelTextColor();
61  vcl::Font aTextFont = m_aTextFont;
62  aTextFont.SetFontSize(pDefaultDev->PixelToLogic(aTextFont.GetFontSize(), rMapMode));
63  vcl::Font aHeadFont = aTextFont;
64  aHeadFont.SetWeight(WEIGHT_BOLD);
65 
66  // Create the text primitive for the title
67  basegfx::B2DVector aFontSize;
69  drawinglayer::primitive2d::getFontAttributeFromVclFont(aFontSize, aHeadFont, false, false);
70 
71  FontMetric aFontMetric = pDefaultDev->GetFontMetric(aHeadFont);
72  Size aHintMargin = pDefaultDev->PixelToLogic(Size(HINT_MARGIN, HINT_MARGIN), rMapMode);
73  Size aIndent = pDefaultDev->PixelToLogic(Size(HINT_INDENT, HINT_LINESPACE), rMapMode);
74  double nTextOffsetY = nTop + aHintMargin.Height() + aFontMetric.GetAscent();
75  Point aTextPos(nLeft + aHintMargin.Width() , nTextOffsetY);
76  rRange = basegfx::B2DRange(nLeft, nTop, nLeft + aHintMargin.Width(), nTop + aHintMargin.Height());
77 
79  aFontSize.getX(), aFontSize.getY(),
80  aTextPos.X(), aTextPos.Y()));
81 
84  aTextMatrix, m_aTitle, 0, m_aTitle.getLength(),
85  std::vector<double>(), aFontAttr, css::lang::Locale(),
86  rColor.getBColor());
87 
88  Point aTextStart(nLeft + aHintMargin.Width() + aIndent.Width(),
89  nTop + aHintMargin.Height() + aFontMetric.GetLineHeight() + aIndent.Height());
90 
92  rRange.expand(pTitle->getB2DRange(aDummy));
93 
95 
96  aFontMetric = pDefaultDev->GetFontMetric(aTextFont);
97  pDefaultDev->SetMapMode(aOld);
98 
99  nTextOffsetY = aFontMetric.GetAscent();
100  sal_Int32 nLineHeight = aFontMetric.GetLineHeight();
101 
102  aFontAttr = drawinglayer::primitive2d::getFontAttributeFromVclFont(aFontSize, aTextFont, false, false);
103 
104  sal_Int32 nIndex = 0;
105  Point aLineStart = aTextStart;
106  sal_Int32 nLineCount = 0;
107  while (nIndex != -1)
108  {
109  OUString aLine = m_aMessage.getToken( 0, '\r', nIndex );
110  if (aLine.getLength() > 255)
111  {
112  // prevent silliness higher up from hanging up the program
113  SAL_WARN("sc", "ridiculously long line, truncating, len=" << aLine.getLength());
114  aLine = aLine.copy(0,255);
115  }
116 
118  aFontSize.getX(), aFontSize.getY(),
119  aLineStart.X(), aLineStart.Y() + nTextOffsetY);
120 
121  // Create the text primitive for each line of text
124  aTextMatrix, aLine, 0, aLine.getLength(),
125  std::vector<double>(), aFontAttr, css::lang::Locale(),
126  rColor.getBColor());
127 
128  rRange.expand(pMessage->getB2DRange(aDummy));
129 
130  aSeq.push_back(pMessage);
131 
132  aLineStart.AdjustY(nLineHeight );
133  nLineCount++;
134  if (nLineCount > 50)
135  {
136  // prevent silliness higher up from hanging up the program
137  SAL_WARN("sc", "ridiculously long message, bailing out");
138  break;
139  }
140  }
141 
142  rRange.expand(basegfx::B2DTuple(rRange.getMaxX() + aHintMargin.Width(),
143  rRange.getMaxY() + aHintMargin.Height()));
144 
146 
149 
150  basegfx::BColor aBorderColor(0.5, 0.5, 0.5);
153  aPoly, aBorderColor));
154 
155  aSeq.insert(aSeq.begin(), aBorder);
156  aSeq.insert(aSeq.begin(), aBg);
157 
158  return aSeq;
159 }
160 
162 {
163  basegfx::B2DRange aRange;
165 }
166 
168 {
169  basegfx::B2DRange aRange;
170  createOverlaySequence(0, 0, MapMode(MapUnit::MapPixel), aRange);
171  return Size(aRange.getWidth(), aRange.getHeight());
172 }
173 
174 void ScOverlayHint::SetPos(const Point& rPos, const MapMode& rMode)
175 {
176  m_nLeft = rPos.X();
177  m_nTop = rPos.Y();
178  m_aMapMode = rMode;
179 }
180 
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double getY() 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
#define HINT_MARGIN
Definition: hintwin.cxx:38
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
void SetWeight(FontWeight)
const MapMode & GetMapMode() 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
constexpr tools::Long Width() const
double getWidth() const
tools::Long GetAscent() 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:174
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:51
#define HINT_INDENT
Definition: hintwin.cxx:37
#define HINT_LINESPACE
Definition: hintwin.cxx:36
Point PixelToLogic(const Point &rDevicePt) const
const Color & getBaseColor() const
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
sal_Int32 m_nTop
constexpr tools::Long Height() const
const OUString m_aTitle
Sequence< sal_Int8 > aSeq
basegfx::BColor getBColor() const
Size GetSizePixel() const
Definition: hintwin.cxx:167
MapUnit
#define SAL_WARN(area, stream)
double getX() const
const OUString m_aMessage
virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override
Definition: hintwin.cxx:161
ScOverlayHint(const OUString &rTit, const OUString &rMsg, const Color &rColor, const vcl::Font &rFont)
Definition: hintwin.cxx:40
sal_Int32 m_nLeft
tools::Long GetLineHeight() const
MapMode m_aMapMode