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 <utility>
32#include <vcl/outdev.hxx>
33#include <vcl/settings.hxx>
34#include <vcl/metric.hxx>
35#include <sal/log.hxx>
36
37#define HINT_LINESPACE 2
38#define HINT_INDENT 3
39#define HINT_MARGIN 4
40
41ScOverlayHint::ScOverlayHint(OUString aTit, const OUString& rMsg, const Color& rColor, vcl::Font aFont)
42 : OverlayObject(rColor)
43 , m_aTitle(std::move(aTit))
44 , m_aMessage(convertLineEnd(rMsg, LINEEND_CR))
45 , m_aTextFont(std::move(aFont))
46 , m_aMapMode(MapUnit::MapPixel)
47 , m_nLeft(0)
48 , m_nTop(0)
49{
50}
51
53 const MapMode &rMapMode,
54 basegfx::B2DRange &rRange) const
55{
57 MapMode aOld = pDefaultDev->GetMapMode();
58 pDefaultDev->SetMapMode(rMapMode);
59
61 const Color& rColor = rStyleSettings.GetLabelTextColor();
62 vcl::Font aTextFont = m_aTextFont;
63 aTextFont.SetFontSize(pDefaultDev->PixelToLogic(aTextFont.GetFontSize(), rMapMode));
64 vcl::Font aHeadFont = aTextFont;
65 aHeadFont.SetWeight(WEIGHT_BOLD);
66
67 // Create the text primitive for the title
68 basegfx::B2DVector aFontSize;
70 drawinglayer::primitive2d::getFontAttributeFromVclFont(aFontSize, aHeadFont, false, false);
71
72 FontMetric aFontMetric = pDefaultDev->GetFontMetric(aHeadFont);
73 Size aHintMargin = pDefaultDev->PixelToLogic(Size(HINT_MARGIN, HINT_MARGIN), rMapMode);
74 Size aIndent = pDefaultDev->PixelToLogic(Size(HINT_INDENT, HINT_LINESPACE), rMapMode);
75 double nTextOffsetY = nTop + aHintMargin.Height() + aFontMetric.GetAscent();
76 Point aTextPos(nLeft + aHintMargin.Width() , nTextOffsetY);
77 rRange = basegfx::B2DRange(nLeft, nTop, nLeft + aHintMargin.Width(), nTop + aHintMargin.Height());
78
80 aFontSize.getX(), aFontSize.getY(),
81 aTextPos.X(), aTextPos.Y()));
82
85 aTextMatrix, m_aTitle, 0, m_aTitle.getLength(),
86 std::vector<double>(), {}, std::move(aFontAttr), css::lang::Locale(),
87 rColor.getBColor());
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 sal_Int32 nLineCount = 0;
108 while (nIndex != -1)
109 {
110 OUString aLine = m_aMessage.getToken( 0, '\r', nIndex );
111 if (aLine.getLength() > 255)
112 {
113 // prevent silliness higher up from hanging up the program
114 SAL_WARN("sc", "ridiculously long line, truncating, len=" << aLine.getLength());
115 aLine = aLine.copy(0,255);
116 }
117
119 aFontSize.getX(), aFontSize.getY(),
120 aLineStart.X(), aLineStart.Y() + nTextOffsetY);
121
122 // Create the text primitive for each line of text
125 aTextMatrix, aLine, 0, aLine.getLength(),
126 std::vector<double>(), {}, aFontAttr, css::lang::Locale(),
127 rColor.getBColor());
128
129 rRange.expand(pMessage->getB2DRange(aDummy));
130
131 aSeq.push_back(pMessage);
132
133 aLineStart.AdjustY(nLineHeight );
134 nLineCount++;
135 if (nLineCount > 50)
136 {
137 // prevent silliness higher up from hanging up the program
138 SAL_WARN("sc", "ridiculously long message, bailing out");
139 break;
140 }
141 }
142
143 rRange.expand(basegfx::B2DTuple(rRange.getMaxX() + aHintMargin.Width(),
144 rRange.getMaxY() + aHintMargin.Height()));
145
147
150
151 basegfx::BColor aBorderColor(0.5, 0.5, 0.5);
154 std::move(aPoly), aBorderColor));
155
156 aSeq.insert(aSeq.begin(), aBorder);
157 aSeq.insert(aSeq.begin(), aBg);
158
159 return aSeq;
160}
161
163{
164 basegfx::B2DRange aRange;
166}
167
169{
170 basegfx::B2DRange aRange;
171 createOverlaySequence(0, 0, MapMode(MapUnit::MapPixel), aRange);
172 return Size(aRange.getWidth(), aRange.getHeight());
173}
174
175void ScOverlayHint::SetPos(const Point& rPos, const MapMode& rMode)
176{
177 m_nLeft = rPos.X();
178 m_nTop = rPos.Y();
179 m_aMapMode = rMode;
180}
181
182/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const StyleSettings & GetStyleSettings() const
static OutputDevice * GetDefaultDevice()
static const AllSettings & GetSettings()
basegfx::BColor getBColor() const
tools::Long GetLineHeight() const
tools::Long GetAscent() const
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
void SetMapMode()
FontMetric GetFontMetric() const
const MapMode & GetMapMode() const
constexpr tools::Long Y() const
tools::Long AdjustY(tools::Long nVertMove)
constexpr tools::Long X() const
void SetPos(const Point &rPos, const MapMode &rMode)
Definition: hintwin.cxx:175
Size GetSizePixel() const
Definition: hintwin.cxx:168
virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override
Definition: hintwin.cxx:162
const OUString m_aMessage
const OUString m_aTitle
ScOverlayHint(OUString aTit, const OUString &rMsg, const Color &rColor, vcl::Font aFont)
Definition: hintwin.cxx:41
sal_Int32 m_nTop
drawinglayer::primitive2d::Primitive2DContainer createOverlaySequence(sal_Int32 nLeft, sal_Int32 nTop, const MapMode &rMapMode, basegfx::B2DRange &rRange) const
Definition: hintwin.cxx:52
MapMode m_aMapMode
const vcl::Font m_aTextFont
sal_Int32 m_nLeft
constexpr tools::Long Height() const
constexpr tools::Long Width() const
const Color & GetLabelTextColor() const
TYPE getMaxX() const
TYPE getWidth() const
void expand(const Tuple2D< TYPE > &rTuple)
TYPE getMaxY() const
TYPE getHeight() const
TYPE getX() const
TYPE getY() const
const Color & getBaseColor() const
void SetFontSize(const Size &)
void SetWeight(FontWeight)
const Size & GetFontSize() const
WEIGHT_BOLD
#define HINT_INDENT
Definition: hintwin.cxx:38
#define HINT_LINESPACE
Definition: hintwin.cxx:37
#define HINT_MARGIN
Definition: hintwin.cxx:39
sal_Int32 nIndex
LINEEND_CR
TOOLS_DLLPUBLIC OString convertLineEnd(const OString &rIn, LineEnd eLineEnd)
Sequence< sal_Int8 > aSeq
#define SAL_WARN(area, stream)
MapUnit
B2DHomMatrix createScaleTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fTranslateX, double fTranslateY)
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
attribute::FontAttribute getFontAttributeFromVclFont(basegfx::B2DVector &o_rSize, const vcl::Font &rFont, bool bRTL, bool bBiDiStrong)