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 <scitems.hxx>
25 #include <document.hxx>
26 #include <docpool.hxx>
27 #include <patattr.hxx>
28 
29 ScDPFieldButton::ScDPFieldButton(OutputDevice* pOutDev, const StyleSettings* pStyle, const Fraction* pZoomY, ScDocument* pDoc) :
30  mpDoc(pDoc),
31  mpOutDev(pOutDev),
32  mpStyle(pStyle),
33  mbBaseButton(true),
34  mbPopupButton(false),
35  mbHasHiddenMember(false),
36  mbPopupPressed(false),
37  mbPopupLeft(false)
38 {
39  if (pZoomY)
40  maZoomY = *pZoomY;
41  else
42  maZoomY = Fraction(1, 1);
43 }
44 
46 {
47 }
48 
49 void ScDPFieldButton::setText(const OUString& rText)
50 {
51  maText = rText;
52 }
53 
54 void ScDPFieldButton::setBoundingBox(const Point& rPos, const Size& rSize, bool bLayoutRTL)
55 {
56  maPos = rPos;
57  maSize = rSize;
58  if (bLayoutRTL)
59  {
60  // rPos is the logical-left position, adjust maPos to visual-left (inside the cell border)
61  maPos.AdjustX( -(maSize.Width() - 1) );
62  }
63 }
64 
66 {
67  mbBaseButton = b;
68 }
69 
71 {
72  mbPopupButton = b;
73 }
74 
76 {
78 }
79 
81 {
82  mbPopupPressed = b;
83 }
84 
86 {
87  mbPopupLeft = b;
88 }
89 
91 {
92  if (mbBaseButton)
93  {
94  // Background
98  mpOutDev->DrawRect(aRect);
99 
100  // Border lines
102  mpOutDev->DrawLine(maPos, Point(maPos.X(), maPos.Y()+maSize.Height()-1));
103  mpOutDev->DrawLine(maPos, Point(maPos.X()+maSize.Width()-1, maPos.Y()));
104 
106  mpOutDev->DrawLine(Point(maPos.X(), maPos.Y()+maSize.Height()-1),
107  Point(maPos.X()+maSize.Width()-1, maPos.Y()+maSize.Height()-1));
108  mpOutDev->DrawLine(Point(maPos.X()+maSize.Width()-1, maPos.Y()),
109  Point(maPos.X()+maSize.Width()-1, maPos.Y()+maSize.Height()-1));
110 
111  // Field name.
112  // Get the font and size the same way as in scenario selection (lcl_DrawOneFrame in gridwin4.cxx)
113  vcl::Font aTextFont( mpStyle->GetAppFont() );
114  if ( mpDoc )
115  {
116  // use ScPatternAttr::GetFont only for font size
117  vcl::Font aAttrFont;
119  GetFont( aAttrFont, SC_AUTOCOL_BLACK, mpOutDev, &maZoomY );
120  aTextFont.SetFontSize( aAttrFont.GetFontSize() );
121  }
122  mpOutDev->SetFont(aTextFont);
124 
125  Point aTextPos = maPos;
126  tools::Long nTHeight = mpOutDev->GetTextHeight();
127  aTextPos.setX(maPos.getX() + 2); // 2 = Margin
128  aTextPos.setY(maPos.getY() + (maSize.Height()-nTHeight)/2);
129 
130  mpOutDev->Push(PushFlags::CLIPREGION);
132  mpOutDev->DrawText(aTextPos, maText);
133  mpOutDev->Pop();
134  }
135 
136  if (mbPopupButton)
137  drawPopupButton();
138 }
139 
140 void ScDPFieldButton::getPopupBoundingBox(Point& rPos, Size& rSize) const
141 {
142  float fScaleFactor = mpOutDev->GetDPIScaleFactor();
143 
144  tools::Long nMaxSize = 18 * fScaleFactor; // Button max size in either dimension
145 
146  tools::Long nW = std::min(maSize.getWidth() / 2, nMaxSize);
147  tools::Long nH = std::min(maSize.getHeight(), nMaxSize);
148 
149  // #i114944# AutoFilter button is left-aligned in RTL.
150  // DataPilot button is always right-aligned for now, so text output isn't affected.
151  if (mbPopupLeft)
152  rPos.setX(maPos.getX());
153  else
154  rPos.setX(maPos.getX() + maSize.getWidth() - nW);
155 
156  rPos.setY(maPos.getY() + maSize.getHeight() - nH);
157  rSize.setWidth(nW);
158  rSize.setHeight(nH);
159 }
160 
162 {
163  Point aPos;
164  Size aSize;
165  getPopupBoundingBox(aPos, aSize);
166 
167  float fScaleFactor = mpOutDev->GetDPIScaleFactor();
168 
169  // Background & outer black border
171  Color aBackgroundColor = mbPopupPressed ? mpStyle->GetShadowColor() : mpStyle->GetFaceColor();
172  mpOutDev->SetFillColor(aBackgroundColor);
173  mpOutDev->DrawRect(tools::Rectangle(aPos, aSize));
174 
175  // the arrowhead
177  mpOutDev->SetLineColor(aArrowColor);
178  mpOutDev->SetFillColor(aArrowColor);
179 
180  Point aCenter(aPos.X() + (aSize.Width() / 2), aPos.Y() + (aSize.Height() / 2));
181 
182  Size aArrowSize(4 * fScaleFactor, 2 * fScaleFactor);
183 
184  tools::Polygon aPoly(3);
185  aPoly.SetPoint(Point(aCenter.X() - aArrowSize.Width(), aCenter.Y() - aArrowSize.Height()), 0);
186  aPoly.SetPoint(Point(aCenter.X() + aArrowSize.Width(), aCenter.Y() - aArrowSize.Height()), 1);
187  aPoly.SetPoint(Point(aCenter.X(), aCenter.Y() + aArrowSize.Height()), 2);
188  mpOutDev->DrawPolygon(aPoly);
189 
190  if (mbHasHiddenMember)
191  {
192  // tiny little box to display in presence of hidden member(s).
193  Point aBoxPos(aPos.X() + aSize.Width() - 5 * fScaleFactor, aPos.Y() + aSize.Height() - 5 * fScaleFactor);
194  Size aBoxSize(3 * fScaleFactor, 3 * fScaleFactor);
195  mpOutDev->DrawRect(tools::Rectangle(aBoxPos, aBoxSize));
196  }
197 }
198 
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScDocument * mpDoc
Definition: dpcontrol.hxx:62
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, MetricVector *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
const Color & GetShadowColor() const
void setDrawBaseButton(bool b)
Definition: dpcontrol.cxx:65
constexpr TypedWhichId< ScPatternAttr > ATTR_PATTERN(156)
void setWidth(tools::Long nWidth)
tools::Long getWidth() const
long Long
const Color & GetFaceColor() const
bool mbHasHiddenMember
Definition: dpcontrol.hxx:67
void DrawPolygon(const tools::Polygon &rPoly)
void IntersectClipRegion(const tools::Rectangle &rRect)
void SetPoint(const Point &rPt, sal_uInt16 nPos)
Fraction maZoomY
Definition: dpcontrol.hxx:61
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6056
void setPopupPressed(bool b)
Definition: dpcontrol.cxx:80
const StyleSettings * mpStyle
Definition: dpcontrol.hxx:64
void getPopupBoundingBox(Point &rPos, Size &rSize) const
Definition: dpcontrol.cxx:140
void setText(const OUString &rText)
Definition: dpcontrol.cxx:49
const Color & GetLightColor() const
void DrawLine(const Point &rStartPt, const Point &rEndPt)
void DrawRect(const tools::Rectangle &rRect)
OUString maText
Definition: dpcontrol.hxx:60
tools::Long getHeight() const
void SetLineColor()
VclPtr< OutputDevice > mpOutDev
Definition: dpcontrol.hxx:63
void SetFillColor()
tools::Long Width() const
void SetTextColor(const Color &rColor)
const Size & GetFontSize() const
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
float GetDPIScaleFactor() const
ScDPFieldButton(OutputDevice *pOutDev, const StyleSettings *pStyle, const Fraction *pZoomY=nullptr, ScDocument *pDoc=nullptr)
Definition: dpcontrol.cxx:29
void drawPopupButton()
Definition: dpcontrol.cxx:161
void setDrawPopupButton(bool b)
Definition: dpcontrol.cxx:70
const Color & GetButtonTextColor() const
void SetFont(const vcl::Font &rNewFont)
tools::Long GetTextHeight() const
void setHasHiddenMember(bool b)
Definition: dpcontrol.cxx:75
tools::Long Height() const
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_BLACK
const vcl::Font & GetAppFont() const
void setHeight(tools::Long nHeight)
const Color & GetHighlightLinkColor() const
void Push(PushFlags nFlags=PushFlags::ALL)
void setPopupLeft(bool b)
Definition: dpcontrol.cxx:85
void setBoundingBox(const Point &rPos, const Size &rSize, bool bLayoutRTL)
Definition: dpcontrol.cxx:54