LibreOffice Module sw (master)  1
FormFieldButton.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 
11 #include <edtwin.hxx>
13 #include <bookmrk.hxx>
14 #include <vcl/floatwin.hxx>
15 #include <vcl/event.hxx>
16 
18  : MenuButton(pEditWin, WB_DIALOGCONTROL)
19  , m_rFieldmark(rFieldmark)
20 {
21  assert(GetParent());
22  assert(dynamic_cast<SwEditWin*>(GetParent()));
23 }
24 
26 
28 {
31 }
32 
33 void FormFieldButton::CalcPosAndSize(const SwRect& rPortionPaintArea)
34 {
35  assert(GetParent());
36 
37  Point aBoxPos = GetParent()->LogicToPixel(rPortionPaintArea.Pos());
38  Size aBoxSize = GetParent()->LogicToPixel(rPortionPaintArea.SSize());
39 
40  // First calculate the size of the frame around the field
41  int nPadding = aBoxSize.Height() / 4;
42  aBoxPos.AdjustX(-nPadding);
43  aBoxPos.AdjustY(-nPadding);
44  aBoxSize.AdjustWidth(2 * nPadding);
45  aBoxSize.AdjustHeight(2 * nPadding);
46 
47  m_aFieldFramePixel = tools::Rectangle(aBoxPos, aBoxSize);
48 
49  // Then extend the size with the button area
50  aBoxSize.AdjustWidth(GetParent()->LogicToPixel(rPortionPaintArea.SSize()).Height());
51 
52  if (aBoxPos != GetPosPixel() || aBoxSize != GetSizePixel())
53  {
54  SetPosSizePixel(aBoxPos, aBoxSize);
55  Invalidate();
56  }
57 }
58 
60 {
61  assert(GetParent());
62 
63  Point aPixPos = GetPosPixel();
64  aPixPos.AdjustY(GetSizePixel().Height());
65 
66  // sets m_pFieldPopup
67  InitPopup();
68 
69  m_pFieldPopup->SetPopupModeEndHdl(LINK(this, DropDownFormFieldButton, FieldPopupModeEndHdl));
70 
71  tools::Rectangle aRect(GetParent()->OutputToScreenPixel(aPixPos), Size(0, 0));
72  m_pFieldPopup->StartPopupMode(aRect, FloatWinPopupFlags::Down | FloatWinPopupFlags::GrabFocus);
73  Invalidate();
74 }
75 
76 IMPL_LINK_NOARG(FormFieldButton, FieldPopupModeEndHdl, FloatingWindow*, void)
77 {
78  m_pFieldPopup.disposeAndClear();
79  m_rFieldmark.Invalidate();
80  // Hide the button here and make it visible later, to make transparent background work with SAL_USE_VCLPLUGIN=gen
81  Show(false);
82  Invalidate();
83 }
84 
85 static basegfx::BColor lcl_GetFillColor(const basegfx::BColor& rLineColor, double aLuminance)
86 {
87  basegfx::BColor aHslLine = basegfx::utils::rgb2hsl(rLineColor);
88  aHslLine.setZ(aLuminance);
89  return basegfx::utils::hsl2rgb(aHslLine);
90 }
91 
93 {
94  SetMapMode(MapMode(MapUnit::MapPixel));
95 
96  //const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
97  Color aLineColor = COL_BLACK;
98  Color aFillColor(lcl_GetFillColor(aLineColor.getBColor(), (m_pFieldPopup ? 0.5 : 0.75)));
99 
100  // Draw the frame around the field
101  // GTK3 backend cuts down the frame's top and left border, to avoid that add a padding around the frame
102  int nPadding = 1;
103  Point aPos(nPadding, nPadding);
104  Size aSize(m_aFieldFramePixel.GetSize().Width() - nPadding,
105  m_aFieldFramePixel.GetSize().Height() - nPadding);
106  const tools::Rectangle aFrameRect(tools::Rectangle(aPos, aSize));
107  rRenderContext.SetLineColor(aLineColor);
108  rRenderContext.SetFillColor(COL_TRANSPARENT);
109  rRenderContext.DrawRect(aFrameRect);
110 
111  // Draw the button next to the frame
112  Point aButtonPos(aFrameRect.TopLeft());
113  aButtonPos.AdjustX(aFrameRect.GetSize().getWidth() - 1);
114  Size aButtonSize(aFrameRect.GetSize());
115  aButtonSize.setWidth(GetSizePixel().getWidth() - aFrameRect.getWidth() - nPadding);
116  const tools::Rectangle aButtonRect(tools::Rectangle(aButtonPos, aButtonSize));
117 
118  // Background & border
119  rRenderContext.SetLineColor(aLineColor);
120  rRenderContext.SetFillColor(aFillColor);
121  rRenderContext.DrawRect(aButtonRect);
122 
123  // the arrowhead
124  rRenderContext.SetLineColor(aLineColor);
125  rRenderContext.SetFillColor(aLineColor);
126 
127  Point aCenter(aButtonPos.X() + (aButtonSize.Width() / 2),
128  aButtonPos.Y() + (aButtonSize.Height() / 2));
129  Size aArrowSize(aButtonSize.Width() / 4, aButtonSize.Height() / 10);
130 
131  tools::Polygon aPoly(3);
132  aPoly.SetPoint(Point(aCenter.X() - aArrowSize.Width(), aCenter.Y() - aArrowSize.Height()), 0);
133  aPoly.SetPoint(Point(aCenter.X() + aArrowSize.Width(), aCenter.Y() - aArrowSize.Height()), 1);
134  aPoly.SetPoint(Point(aCenter.X(), aCenter.Y() + aArrowSize.Height()), 2);
135  rRenderContext.DrawPolygon(aPoly);
136 }
137 
139 {
140  // We need to check whether the position hits the button (the frame should be mouse transparent)
141  WindowHitTest aResult = MenuButton::ImplHitTest(rFramePos);
142  if (aResult != WindowHitTest::Inside)
143  return aResult;
144  else
145  {
146  return rFramePos.X() >= m_aFieldFramePixel.Right() ? WindowHitTest::Inside
147  : WindowHitTest::Transparent;
148  }
149 }
150 
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
virtual Point GetPosPixel() const
long Width() const
void StartPopupMode(const tools::Rectangle &rRect, FloatWinPopupFlags nFlags)
BColor rgb2hsl(const BColor &rRGBColor)
void SetPopupModeEndHdl(const Link< FloatingWindow *, void > &rLink)
constexpr::Color COL_BLACK(0x00, 0x00, 0x00)
WindowHitTest
long AdjustWidth(long n)
long Height() const
virtual WindowHitTest ImplHitTest(const Point &rFramePos)
virtual void dispose() override
void DrawPolygon(const tools::Polygon &rPoly)
virtual Size GetSizePixel() const
virtual WindowHitTest ImplHitTest(const Point &rFramePos) override
void Pos(const Point &rNew)
Definition: swrect.hxx:169
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
long AdjustHeight(long n)
void SetMapMode()
static basegfx::BColor lcl_GetFillColor(const basegfx::BColor &rLineColor, double aLuminance)
constexpr::Color COL_TRANSPARENT(0xFF, 0xFF, 0xFF, 0xFF)
long Right() const
VclPtr< FloatingWindow > m_pFieldPopup
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
virtual void InitPopup()=0
void DrawRect(const tools::Rectangle &rRect)
This button is shown when the cursor is on a form field with drop-down capability.
BColor hsl2rgb(const BColor &rHSLColor)
WinBits const WB_DIALOGCONTROL
void SetLineColor()
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:58
void CalcPosAndSize(const SwRect &rPortionPaintArea)
tools::Rectangle m_aFieldFramePixel
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
void SetFillColor()
void SSize(const Size &rNew)
Definition: swrect.hxx:178
virtual void MouseButtonUp(const MouseEvent &rMEvt) override
vcl::Window * GetParent() const
virtual ~FormFieldButton() override
Size GetSize() const
virtual void SetPosSizePixel(const Point &rNewPos, const Size &rNewSize)
Point LogicToPixel(const Point &rLogicPt) const
virtual void dispose() override
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
FormFieldButton(SwEditWin *pEditWin, sw::mark::Fieldmark &rFieldMark)
basegfx::BColor getBColor() const
Point OutputToScreenPixel(const Point &rPos) const
long getWidth() const
void setWidth(long nWidth)
IMPL_LINK_NOARG(FormFieldButton, FieldPopupModeEndHdl, FloatingWindow *, void)
This button is shown when the cursor is on a drop-down form field.