LibreOffice Module sc (master) 1
dpcontrol.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 <dpcontrol.hxx>
21
22#include <vcl/outdev.hxx>
23#include <vcl/settings.hxx>
24#include <comphelper/lok.hxx>
25#include <scitems.hxx>
26#include <document.hxx>
27#include <docpool.hxx>
28#include <patattr.hxx>
29#include <svtools/colorcfg.hxx>
30
31ScDPFieldButton::ScDPFieldButton(OutputDevice* pOutDev, const StyleSettings* pStyle, const Fraction* pZoomY, ScDocument* pDoc) :
32 mpDoc(pDoc),
33 mpOutDev(pOutDev),
34 mpStyle(pStyle),
35 mbBaseButton(true),
36 mbPopupButton(false),
37 mbHasHiddenMember(false),
38 mbPopupPressed(false),
39 mbPopupLeft(false)
40{
41 if (pZoomY)
42 maZoomY = *pZoomY;
43 else
44 maZoomY = Fraction(1, 1);
45}
46
48{
49}
50
51void ScDPFieldButton::setText(const OUString& rText)
52{
53 maText = rText;
54}
55
56void ScDPFieldButton::setBoundingBox(const Point& rPos, const Size& rSize, bool bLayoutRTL)
57{
58 maPos = rPos;
59 maSize = rSize;
60 if (bLayoutRTL)
61 {
62 // rPos is the logical-left position, adjust maPos to visual-left (inside the cell border)
63 maPos.AdjustX( -(maSize.Width() - 1) );
64 }
65}
66
68{
69 mbBaseButton = b;
70}
71
73{
74 mbPopupButton = b;
75}
76
78{
80}
81
83{
85}
86
88{
89 mbPopupLeft = b;
90}
91
93{
94 bool bOldMapEnabled = mpOutDev->IsMapModeEnabled();
95
96 if (mpOutDev->GetMapMode().GetMapUnit() != MapUnit::MapPixel)
97 mpOutDev->EnableMapMode(false);
98
99 if (mbBaseButton)
100 {
101 // Background
103 mpOutDev->SetLineColor(mpStyle->GetFaceColor());
104 mpOutDev->SetFillColor(mpStyle->GetFaceColor());
105 mpOutDev->DrawRect(aRect);
106
107 // Border lines
108 mpOutDev->SetLineColor(mpStyle->GetLightColor());
109 mpOutDev->DrawLine(maPos, Point(maPos.X(), maPos.Y()+maSize.Height()-1));
110 mpOutDev->DrawLine(maPos, Point(maPos.X()+maSize.Width()-1, maPos.Y()));
111
112 mpOutDev->SetLineColor(mpStyle->GetShadowColor());
113 mpOutDev->DrawLine(Point(maPos.X(), maPos.Y()+maSize.Height()-1),
114 Point(maPos.X()+maSize.Width()-1, maPos.Y()+maSize.Height()-1));
115 mpOutDev->DrawLine(Point(maPos.X()+maSize.Width()-1, maPos.Y()),
116 Point(maPos.X()+maSize.Width()-1, maPos.Y()+maSize.Height()-1));
117
118 // Field name.
119 // Get the font and size the same way as in scenario selection (lcl_DrawOneFrame in gridwin4.cxx)
120 vcl::Font aTextFont( mpStyle->GetAppFont() );
121 if ( mpDoc )
122 {
123 // use ScPatternAttr::GetFont only for font size
124 vcl::Font aAttrFont;
126 GetFont( aAttrFont, SC_AUTOCOL_BLACK, mpOutDev, &maZoomY );
127 aTextFont.SetFontSize( aAttrFont.GetFontSize() );
128 }
129 mpOutDev->SetFont(aTextFont);
130 mpOutDev->SetTextColor(mpStyle->GetButtonTextColor());
131
132 Point aTextPos = maPos;
133 tools::Long nTHeight = mpOutDev->GetTextHeight();
134 aTextPos.setX(maPos.getX() + 2); // 2 = Margin
135 aTextPos.setY(maPos.getY() + (maSize.Height()-nTHeight)/2);
136
138 mpOutDev->IntersectClipRegion(aRect);
139 mpOutDev->DrawText(aTextPos, maText);
140 mpOutDev->Pop();
141 }
142
143 if (mbPopupButton)
145
146 mpOutDev->EnableMapMode(bOldMapEnabled);
147}
148
149void ScDPFieldButton::getPopupBoundingBox(Point& rPos, Size& rSize) const
150{
151 float fScaleFactor = mpOutDev->GetDPIScaleFactor();
152
153 tools::Long nMaxSize = 18 * fScaleFactor; // Button max size in either dimension
154
155 tools::Long nW = std::min(maSize.getWidth() / 2, nMaxSize);
156 tools::Long nH = std::min(maSize.getHeight(), nMaxSize);
157
158 double fZoom = static_cast<double>(maZoomY) > 1.0 ? static_cast<double>(maZoomY) : 1.0;
159 if (fZoom > 1.0)
160 {
161 nW = fZoom * (nW - 1);
162 nH = fZoom * (nH - 1);
163 }
164
165 // #i114944# AutoFilter button is left-aligned in RTL.
166 // DataPilot button is always right-aligned for now, so text output isn't affected.
167 if (mbPopupLeft)
168 rPos.setX(maPos.getX());
169 else
170 rPos.setX(maPos.getX() + maSize.getWidth() - nW);
171
172 rPos.setY(maPos.getY() + maSize.getHeight() - nH);
173 rSize.setWidth(nW);
174 rSize.setHeight(nH);
175}
176
178{
179 Point aPos;
180 Size aSize;
181 getPopupBoundingBox(aPos, aSize);
182
183 float fScaleFactor = mpOutDev->GetDPIScaleFactor();
184
185 // Button background color
186 Color aFaceColor = mpStyle->GetFaceColor();
187 Color aBackgroundColor
189 : mbPopupPressed ? mpStyle->GetShadowColor() : aFaceColor;
190
191 // Button line color
192 mpOutDev->SetLineColor(mpStyle->GetLabelTextColor());
193 // If the document background is light and face color is dark, use ShadowColor instead
195 if (aDocColor.IsBright() && aFaceColor.IsDark())
196 mpOutDev->SetLineColor(mpStyle->GetShadowColor());
197
198 mpOutDev->SetFillColor(aBackgroundColor);
199 mpOutDev->DrawRect(tools::Rectangle(aPos, aSize));
200
201 // the arrowhead
203 // FIXME: HACK: The following DrawPolygon draws twice in lok rtl mode for some reason.
204 // => one at the correct location with fill (possibly no outline)
205 // => and the other at an x offset with outline and without fill
206 // eg. Replacing this with a DrawRect() does not have any such problems.
207 comphelper::LibreOfficeKit::isActive() ? mpOutDev->SetLineColor() : mpOutDev->SetLineColor(aArrowColor);
208 mpOutDev->SetFillColor(aArrowColor);
209
210 Point aCenter(aPos.X() + (aSize.Width() / 2), aPos.Y() + (aSize.Height() / 2));
211
212 Size aArrowSize(4 * fScaleFactor, 2 * fScaleFactor);
213
214 tools::Polygon aPoly(3);
215 aPoly.SetPoint(Point(aCenter.X() - aArrowSize.Width(), aCenter.Y() - aArrowSize.Height()), 0);
216 aPoly.SetPoint(Point(aCenter.X() + aArrowSize.Width(), aCenter.Y() - aArrowSize.Height()), 1);
217 aPoly.SetPoint(Point(aCenter.X(), aCenter.Y() + aArrowSize.Height()), 2);
218 mpOutDev->DrawPolygon(aPoly);
219
221 {
222 // tiny little box to display in presence of hidden member(s).
223 Point aBoxPos(aPos.X() + aSize.Width() - 5 * fScaleFactor, aPos.Y() + aSize.Height() - 5 * fScaleFactor);
224 Size aBoxSize(3 * fScaleFactor, 3 * fScaleFactor);
225 mpOutDev->DrawRect(tools::Rectangle(aBoxPos, aBoxSize));
226 }
227}
228
229/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsBright() const
bool IsDark() const
void setHasHiddenMember(bool b)
Definition: dpcontrol.cxx:77
VclPtr< OutputDevice > mpOutDev
Definition: dpcontrol.hxx:62
void setDrawPopupButton(bool b)
Definition: dpcontrol.cxx:72
const StyleSettings * mpStyle
Definition: dpcontrol.hxx:63
void setPopupPressed(bool b)
Definition: dpcontrol.cxx:82
void drawPopupButton()
Definition: dpcontrol.cxx:177
void setPopupLeft(bool b)
Definition: dpcontrol.cxx:87
bool mbHasHiddenMember
Definition: dpcontrol.hxx:66
Fraction maZoomY
Definition: dpcontrol.hxx:60
void setBoundingBox(const Point &rPos, const Size &rSize, bool bLayoutRTL)
Definition: dpcontrol.cxx:56
void setText(const OUString &rText)
Definition: dpcontrol.cxx:51
ScDPFieldButton(OutputDevice *pOutDev, const StyleSettings *pStyle, const Fraction *pZoomY=nullptr, ScDocument *pDoc=nullptr)
Definition: dpcontrol.cxx:31
void setDrawBaseButton(bool b)
Definition: dpcontrol.cxx:67
OUString maText
Definition: dpcontrol.hxx:59
ScDocument * mpDoc
Definition: dpcontrol.hxx:61
void getPopupBoundingBox(Point &rPos, Size &rSize) const
Definition: dpcontrol.cxx:149
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6181
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
constexpr tools::Long getHeight() const
constexpr tools::Long Height() const
constexpr tools::Long getWidth() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
const Color & GetShadowColor() const
const Color & GetLabelTextColor() const
const Color & GetLightColor() const
const Color & GetHighlightColor() const
const Color & GetFaceColor() const
const vcl::Font & GetAppFont() const
const Color & GetHighlightTextColor() const
const Color & GetButtonTextColor() const
ColorConfigValue GetColorValue(ColorConfigEntry eEntry, bool bSmart=true) const
void SetPoint(const Point &rPt, sal_uInt16 nPos)
void SetFontSize(const Size &)
const Size & GetFontSize() const
long Long
vcl::Font GetFont(vcl::Font const &rFont, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
@ SC_AUTOCOL_BLACK
always use black
Definition: patattr.hxx:45
constexpr TypedWhichId< ScPatternAttr > ATTR_PATTERN(156)