fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / cctrl / dpcontrol.cxx
blobf020024a99ac29f3df25a9ac601f864541f3d6b7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
24 #include "global.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) :
31 mpDoc(pDoc),
32 mpOutDev(pOutDev),
33 mpStyle(pStyle),
34 mbBaseButton(true),
35 mbPopupButton(false),
36 mbHasHiddenMember(false),
37 mbPopupPressed(false),
38 mbPopupLeft(false)
40 if (pZoomX)
41 maZoomX = *pZoomX;
42 else
43 maZoomX = Fraction(1, 1);
45 if (pZoomY)
46 maZoomY = *pZoomY;
47 else
48 maZoomY = Fraction(1, 1);
51 ScDPFieldButton::~ScDPFieldButton()
55 void ScDPFieldButton::setText(const OUString& rText)
57 maText = rText;
60 void ScDPFieldButton::setBoundingBox(const Point& rPos, const Size& rSize, bool bLayoutRTL)
62 maPos = rPos;
63 maSize = rSize;
64 if (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)
73 mbBaseButton = b;
76 void ScDPFieldButton::setDrawPopupButton(bool b)
78 mbPopupButton = b;
81 void ScDPFieldButton::setHasHiddenMember(bool b)
83 mbHasHiddenMember = b;
86 void ScDPFieldButton::setPopupPressed(bool b)
88 mbPopupPressed = b;
91 void ScDPFieldButton::setPopupLeft(bool b)
93 mbPopupLeft = b;
96 void ScDPFieldButton::draw()
98 if (mbBaseButton)
100 // Background
101 Rectangle aRect(maPos, maSize);
102 mpOutDev->SetLineColor(mpStyle->GetFaceColor());
103 mpOutDev->SetFillColor(mpStyle->GetFaceColor());
104 mpOutDev->DrawRect(aRect);
106 // Border lines
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));
117 // Field name.
118 // Get the font and size the same way as in scenario selection (lcl_DrawOneFrame in gridwin4.cxx)
119 vcl::Font aTextFont( mpStyle->GetAppFont() );
120 if ( mpDoc )
122 // use ScPatternAttr::GetFont only for font size
123 vcl::Font aAttrFont;
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);
139 mpOutDev->Pop();
142 if (mbPopupButton)
143 drawPopupButton();
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.
157 if (mbPopupLeft)
158 rPos.setX(maPos.getX());
159 else
160 rPos.setX(maPos.getX() + maSize.getWidth() - nW);
162 rPos.setY(maPos.getY() + maSize.getHeight() - nH);
163 rSize.setWidth(nW);
164 rSize.setHeight(nH);
167 void ScDPFieldButton::drawPopupButton()
169 Point aPos;
170 Size aSize;
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));
181 // the arrowhead
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);
190 Polygon aPoly(3);
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: */