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