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 :
31 1143 : ScDPFieldButton::ScDPFieldButton(OutputDevice* pOutDev, const StyleSettings* pStyle, const Fraction* pZoomX, 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 1143 : mbPopupLeft(false)
40 : {
41 1143 : if (pZoomX)
42 1143 : maZoomX = *pZoomX;
43 : else
44 0 : maZoomX = Fraction(1, 1);
45 :
46 1143 : if (pZoomY)
47 1143 : maZoomY = *pZoomY;
48 : else
49 0 : maZoomY = Fraction(1, 1);
50 1143 : }
51 :
52 1143 : ScDPFieldButton::~ScDPFieldButton()
53 : {
54 1143 : }
55 :
56 680 : void ScDPFieldButton::setText(const OUString& rText)
57 : {
58 680 : maText = rText;
59 680 : }
60 :
61 710 : void ScDPFieldButton::setBoundingBox(const Point& rPos, const Size& rSize, bool bLayoutRTL)
62 : {
63 710 : maPos = rPos;
64 710 : maSize = rSize;
65 710 : if (bLayoutRTL)
66 : {
67 : // rPos is the logical-left position, adjust maPos to visual-left (inside the cell border)
68 0 : maPos.X() -= maSize.Width() - 1;
69 : }
70 710 : }
71 :
72 710 : void ScDPFieldButton::setDrawBaseButton(bool b)
73 : {
74 710 : mbBaseButton = b;
75 710 : }
76 :
77 710 : void ScDPFieldButton::setDrawPopupButton(bool b)
78 : {
79 710 : mbPopupButton = b;
80 710 : }
81 :
82 710 : void ScDPFieldButton::setHasHiddenMember(bool b)
83 : {
84 710 : mbHasHiddenMember = b;
85 710 : }
86 :
87 0 : void ScDPFieldButton::setPopupPressed(bool b)
88 : {
89 0 : mbPopupPressed = b;
90 0 : }
91 :
92 710 : void ScDPFieldButton::setPopupLeft(bool b)
93 : {
94 710 : mbPopupLeft = b;
95 710 : }
96 :
97 710 : void ScDPFieldButton::draw()
98 : {
99 710 : bool bOldMapEnablaed = mpOutDev->IsMapModeEnabled();
100 710 : mpOutDev->EnableMapMode(false);
101 :
102 710 : if (mbBaseButton)
103 : {
104 : // Background
105 100 : Rectangle aRect(maPos, maSize);
106 100 : mpOutDev->SetLineColor(mpStyle->GetFaceColor());
107 100 : mpOutDev->SetFillColor(mpStyle->GetFaceColor());
108 100 : mpOutDev->DrawRect(aRect);
109 :
110 : // Border lines
111 100 : mpOutDev->SetLineColor(mpStyle->GetLightColor());
112 100 : mpOutDev->DrawLine(Point(maPos), Point(maPos.X(), maPos.Y()+maSize.Height()-1));
113 100 : mpOutDev->DrawLine(Point(maPos), Point(maPos.X()+maSize.Width()-1, maPos.Y()));
114 :
115 100 : mpOutDev->SetLineColor(mpStyle->GetShadowColor());
116 200 : mpOutDev->DrawLine(Point(maPos.X(), maPos.Y()+maSize.Height()-1),
117 300 : Point(maPos.X()+maSize.Width()-1, maPos.Y()+maSize.Height()-1));
118 200 : mpOutDev->DrawLine(Point(maPos.X()+maSize.Width()-1, maPos.Y()),
119 300 : Point(maPos.X()+maSize.Width()-1, maPos.Y()+maSize.Height()-1));
120 :
121 : // Field name.
122 : // Get the font and size the same way as in scenario selection (lcl_DrawOneFrame in gridwin4.cxx)
123 100 : Font aTextFont( mpStyle->GetAppFont() );
124 100 : if ( mpDoc )
125 : {
126 : // use ScPatternAttr::GetFont only for font size
127 100 : Font aAttrFont;
128 200 : static_cast<const ScPatternAttr&>(mpDoc->GetPool()->GetDefaultItem(ATTR_PATTERN)).
129 300 : GetFont( aAttrFont, SC_AUTOCOL_BLACK, mpOutDev, &maZoomY );
130 100 : aTextFont.SetSize( aAttrFont.GetSize() );
131 : }
132 100 : mpOutDev->SetFont(aTextFont);
133 100 : mpOutDev->SetTextColor(mpStyle->GetButtonTextColor());
134 :
135 100 : Point aTextPos = maPos;
136 100 : long nTHeight = mpOutDev->GetTextHeight();
137 100 : aTextPos.setX(maPos.getX() + 2); // 2 = Margin
138 100 : aTextPos.setY(maPos.getY() + (maSize.Height()-nTHeight)/2);
139 :
140 100 : mpOutDev->Push(PUSH_CLIPREGION);
141 100 : mpOutDev->IntersectClipRegion(aRect);
142 100 : mpOutDev->DrawText(aTextPos, maText);
143 100 : mpOutDev->Pop();
144 : }
145 :
146 710 : if (mbPopupButton)
147 94 : drawPopupButton();
148 :
149 710 : mpOutDev->EnableMapMode(bOldMapEnablaed);
150 710 : }
151 :
152 94 : void ScDPFieldButton::getPopupBoundingBox(Point& rPos, Size& rSize) const
153 : {
154 94 : long nW = maSize.getWidth() / 2;
155 94 : long nH = maSize.getHeight();
156 94 : if (nW > 18)
157 94 : nW = 18;
158 94 : if (nH > 18)
159 0 : nH = 18;
160 :
161 : // #i114944# AutoFilter button is left-aligned in RTL.
162 : // DataPilot button is always right-aligned for now, so text output isn't affected.
163 94 : if (mbPopupLeft)
164 0 : rPos.setX(maPos.getX());
165 : else
166 94 : rPos.setX(maPos.getX() + maSize.getWidth() - nW);
167 94 : rPos.setY(maPos.getY() + maSize.getHeight() - nH);
168 94 : rSize.setWidth(nW);
169 94 : rSize.setHeight(nH);
170 94 : }
171 :
172 94 : void ScDPFieldButton::drawPopupButton()
173 : {
174 94 : Point aPos;
175 94 : Size aSize;
176 94 : getPopupBoundingBox(aPos, aSize);
177 :
178 : // Background & outer black border
179 94 : mpOutDev->SetLineColor(COL_BLACK);
180 94 : mpOutDev->SetFillColor(mpStyle->GetFaceColor());
181 94 : mpOutDev->DrawRect(Rectangle(aPos, aSize));
182 :
183 94 : if (!mbPopupPressed)
184 : {
185 : // border lines
186 94 : mpOutDev->SetLineColor(mpStyle->GetLightColor());
187 94 : mpOutDev->DrawLine(Point(aPos.X()+1, aPos.Y()+1), Point(aPos.X()+1, aPos.Y()+aSize.Height()-2));
188 94 : mpOutDev->DrawLine(Point(aPos.X()+1, aPos.Y()+1), Point(aPos.X()+aSize.Width()-2, aPos.Y()+1));
189 :
190 94 : mpOutDev->SetLineColor(mpStyle->GetShadowColor());
191 188 : mpOutDev->DrawLine(Point(aPos.X()+1, aPos.Y()+aSize.Height()-2),
192 282 : Point(aPos.X()+aSize.Width()-2, aPos.Y()+aSize.Height()-2));
193 188 : mpOutDev->DrawLine(Point(aPos.X()+aSize.Width()-2, aPos.Y()+1),
194 282 : Point(aPos.X()+aSize.Width()-2, aPos.Y()+aSize.Height()-2));
195 : }
196 :
197 : // the arrowhead
198 94 : Color aArrowColor = mbHasHiddenMember ? mpStyle->GetHighlightLinkColor() : mpStyle->GetButtonTextColor();
199 94 : mpOutDev->SetLineColor(aArrowColor);
200 94 : mpOutDev->SetFillColor(aArrowColor);
201 94 : Point aCenter(aPos.X() + (aSize.Width() >> 1), aPos.Y() + (aSize.Height() >> 1));
202 94 : Point aPos1, aPos2;
203 94 : aPos1.X() = aCenter.X() - 4;
204 94 : aPos2.X() = aCenter.X() + 4;
205 94 : aPos1.Y() = aCenter.Y() - 3;
206 94 : aPos2.Y() = aCenter.Y() - 3;
207 :
208 94 : if (mbPopupPressed)
209 : {
210 0 : aPos1.X() += 1;
211 0 : aPos2.X() += 1;
212 0 : aPos1.Y() += 1;
213 0 : aPos2.Y() += 1;
214 : }
215 :
216 376 : do
217 : {
218 376 : ++aPos1.X();
219 376 : --aPos2.X();
220 376 : ++aPos1.Y();
221 376 : ++aPos2.Y();
222 376 : mpOutDev->DrawLine(aPos1, aPos2);
223 : }
224 : while (aPos1 != aPos2);
225 :
226 94 : if (mbHasHiddenMember)
227 : {
228 : // tiny little box to display in presence of hidden member(s).
229 4 : Point aBoxPos(aPos.X() + aSize.Width() - 5, aPos.Y() + aSize.Height() - 5);
230 4 : if (mbPopupPressed)
231 : {
232 0 : aBoxPos.X() += 1;
233 0 : aBoxPos.Y() += 1;
234 : }
235 4 : Size aBoxSize(3, 3);
236 4 : mpOutDev->DrawRect(Rectangle(aBoxPos, aBoxSize));
237 : }
238 187 : }
239 :
240 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|