1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "dpcontrol.hxx"
22 #include <vcl/outdev.hxx>
23 #include <vcl/settings.hxx>
25 #include "scitems.hxx"
26 #include "document.hxx"
27 #include "docpool.hxx"
28 #include "patattr.hxx"
30 ScDPFieldButton::ScDPFieldButton(OutputDevice
* pOutDev
, const StyleSettings
* pStyle
, const Fraction
* pZoomX
, const Fraction
* pZoomY
, ScDocument
* pDoc
) :
36 mbHasHiddenMember(false),
37 mbPopupPressed(false),
43 maZoomX
= Fraction(1, 1);
48 maZoomY
= Fraction(1, 1);
51 ScDPFieldButton::~ScDPFieldButton()
55 void ScDPFieldButton::setText(const OUString
& rText
)
60 void ScDPFieldButton::setBoundingBox(const Point
& rPos
, const Size
& rSize
, bool bLayoutRTL
)
66 // rPos is the logical-left position, adjust maPos to visual-left (inside the cell border)
67 maPos
.X() -= maSize
.Width() - 1;
71 void ScDPFieldButton::setDrawBaseButton(bool b
)
76 void ScDPFieldButton::setDrawPopupButton(bool b
)
81 void ScDPFieldButton::setHasHiddenMember(bool b
)
83 mbHasHiddenMember
= b
;
86 void ScDPFieldButton::setPopupPressed(bool b
)
91 void ScDPFieldButton::setPopupLeft(bool b
)
96 void ScDPFieldButton::draw()
101 Rectangle
aRect(maPos
, maSize
);
102 mpOutDev
->SetLineColor(mpStyle
->GetFaceColor());
103 mpOutDev
->SetFillColor(mpStyle
->GetFaceColor());
104 mpOutDev
->DrawRect(aRect
);
107 mpOutDev
->SetLineColor(mpStyle
->GetLightColor());
108 mpOutDev
->DrawLine(Point(maPos
), Point(maPos
.X(), maPos
.Y()+maSize
.Height()-1));
109 mpOutDev
->DrawLine(Point(maPos
), Point(maPos
.X()+maSize
.Width()-1, maPos
.Y()));
111 mpOutDev
->SetLineColor(mpStyle
->GetShadowColor());
112 mpOutDev
->DrawLine(Point(maPos
.X(), maPos
.Y()+maSize
.Height()-1),
113 Point(maPos
.X()+maSize
.Width()-1, maPos
.Y()+maSize
.Height()-1));
114 mpOutDev
->DrawLine(Point(maPos
.X()+maSize
.Width()-1, maPos
.Y()),
115 Point(maPos
.X()+maSize
.Width()-1, maPos
.Y()+maSize
.Height()-1));
118 // Get the font and size the same way as in scenario selection (lcl_DrawOneFrame in gridwin4.cxx)
119 vcl::Font
aTextFont( mpStyle
->GetAppFont() );
122 // use ScPatternAttr::GetFont only for font size
124 static_cast<const ScPatternAttr
&>(mpDoc
->GetPool()->GetDefaultItem(ATTR_PATTERN
)).
125 GetFont( aAttrFont
, SC_AUTOCOL_BLACK
, mpOutDev
, &maZoomY
);
126 aTextFont
.SetSize( aAttrFont
.GetSize() );
128 mpOutDev
->SetFont(aTextFont
);
129 mpOutDev
->SetTextColor(mpStyle
->GetButtonTextColor());
131 Point aTextPos
= maPos
;
132 long nTHeight
= mpOutDev
->GetTextHeight();
133 aTextPos
.setX(maPos
.getX() + 2); // 2 = Margin
134 aTextPos
.setY(maPos
.getY() + (maSize
.Height()-nTHeight
)/2);
136 mpOutDev
->Push(PushFlags::CLIPREGION
);
137 mpOutDev
->IntersectClipRegion(aRect
);
138 mpOutDev
->DrawText(aTextPos
, maText
);
146 void ScDPFieldButton::getPopupBoundingBox(Point
& rPos
, Size
& rSize
) const
148 sal_Int32 nScaleFactor
= mpOutDev
->GetDPIScaleFactor();
150 long nMaxSize
= 18L * nScaleFactor
; // Button max size in either dimension
152 long nW
= std::min(maSize
.getWidth() / 2, nMaxSize
);
153 long nH
= std::min(maSize
.getHeight(), nMaxSize
);
155 // #i114944# AutoFilter button is left-aligned in RTL.
156 // DataPilot button is always right-aligned for now, so text output isn't affected.
158 rPos
.setX(maPos
.getX());
160 rPos
.setX(maPos
.getX() + maSize
.getWidth() - nW
);
162 rPos
.setY(maPos
.getY() + maSize
.getHeight() - nH
);
167 void ScDPFieldButton::drawPopupButton()
171 getPopupBoundingBox(aPos
, aSize
);
173 sal_Int32 nScaleFactor
= mpOutDev
->GetDPIScaleFactor();
175 // Background & outer black border
176 mpOutDev
->SetLineColor(COL_BLACK
);
177 Color aBackgroundColor
= mbPopupPressed
? mpStyle
->GetShadowColor() : mpStyle
->GetFaceColor();
178 mpOutDev
->SetFillColor(aBackgroundColor
);
179 mpOutDev
->DrawRect(Rectangle(aPos
, aSize
));
182 Color aArrowColor
= mbHasHiddenMember
? mpStyle
->GetHighlightLinkColor() : mpStyle
->GetButtonTextColor();
183 mpOutDev
->SetLineColor(aArrowColor
);
184 mpOutDev
->SetFillColor(aArrowColor
);
186 Point
aCenter(aPos
.X() + (aSize
.Width() / 2), aPos
.Y() + (aSize
.Height() / 2));
188 Size
aArrowSize(4 * nScaleFactor
, 2 * nScaleFactor
);
191 aPoly
.SetPoint(Point(aCenter
.X() - aArrowSize
.Width(), aCenter
.Y() - aArrowSize
.Height()), 0);
192 aPoly
.SetPoint(Point(aCenter
.X() + aArrowSize
.Width(), aCenter
.Y() - aArrowSize
.Height()), 1);
193 aPoly
.SetPoint(Point(aCenter
.X(), aCenter
.Y() + aArrowSize
.Height()), 2);
194 mpOutDev
->DrawPolygon(aPoly
);
196 if (mbHasHiddenMember
)
198 // tiny little box to display in presence of hidden member(s).
199 Point
aBoxPos(aPos
.X() + aSize
.Width() - 5 * nScaleFactor
, aPos
.Y() + aSize
.Height() - 5 * nScaleFactor
);
200 Size
aBoxSize(3 * nScaleFactor
, 3 * nScaleFactor
);
201 mpOutDev
->DrawRect(Rectangle(aBoxPos
, aBoxSize
));
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */