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  SetPosSizePixel(aBoxPos, aBoxSize);
53 }
54 
56 {
57  assert(GetParent());
58 
59  Point aPixPos = GetPosPixel();
60  aPixPos.AdjustY(GetSizePixel().Height());
61 
62  // sets m_pFieldPopup
63  InitPopup();
64 
65  m_pFieldPopup->SetPopupModeEndHdl(LINK(this, DropDownFormFieldButton, FieldPopupModeEndHdl));
66 
67  tools::Rectangle aRect(GetParent()->OutputToScreenPixel(aPixPos), Size(0, 0));
68  m_pFieldPopup->StartPopupMode(aRect, FloatWinPopupFlags::Down | FloatWinPopupFlags::GrabFocus);
69  Invalidate();
70 }
71 
72 IMPL_LINK_NOARG(FormFieldButton, FieldPopupModeEndHdl, FloatingWindow*, void)
73 {
74  m_pFieldPopup.disposeAndClear();
75  m_rFieldmark.Invalidate();
76  // Hide the button here and make it visible later, to make transparent background work with SAL_USE_VCLPLUGIN=gen
77  Show(false);
78  Invalidate();
79 }
80 
81 static basegfx::BColor lcl_GetFillColor(const basegfx::BColor& rLineColor, double aLuminance)
82 {
83  basegfx::BColor aHslLine = basegfx::utils::rgb2hsl(rLineColor);
84  aHslLine.setZ(aLuminance);
85  return basegfx::utils::hsl2rgb(aHslLine);
86 }
87 
89 {
90  SetMapMode(MapMode(MapUnit::MapPixel));
91 
92  //const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
93  Color aLineColor = COL_BLACK;
94  Color aFillColor(lcl_GetFillColor(aLineColor.getBColor(), (m_pFieldPopup ? 0.5 : 0.75)));
95 
96  // Draw the frame around the field
97  // GTK3 backend cuts down the frame's top and left border, to avoid that add a padding around the frame
98  int nPadding = 1;
99  Point aPos(nPadding, nPadding);
100  Size aSize(m_aFieldFramePixel.GetSize().Width() - nPadding,
101  m_aFieldFramePixel.GetSize().Height() - nPadding);
102  const tools::Rectangle aFrameRect(tools::Rectangle(aPos, aSize));
103  rRenderContext.SetLineColor(aLineColor);
104  rRenderContext.SetFillColor(COL_TRANSPARENT);
105  rRenderContext.DrawRect(aFrameRect);
106 
107  // Draw the button next to the frame
108  Point aButtonPos(aFrameRect.TopLeft());
109  aButtonPos.AdjustX(aFrameRect.GetSize().getWidth() - 1);
110  Size aButtonSize(aFrameRect.GetSize());
111  aButtonSize.setWidth(GetSizePixel().getWidth() - aFrameRect.getWidth() - nPadding);
112  const tools::Rectangle aButtonRect(tools::Rectangle(aButtonPos, aButtonSize));
113 
114  // Background & border
115  rRenderContext.SetLineColor(aLineColor);
116  rRenderContext.SetFillColor(aFillColor);
117  rRenderContext.DrawRect(aButtonRect);
118 
119  // the arrowhead
120  rRenderContext.SetLineColor(aLineColor);
121  rRenderContext.SetFillColor(aLineColor);
122 
123  Point aCenter(aButtonPos.X() + (aButtonSize.Width() / 2),
124  aButtonPos.Y() + (aButtonSize.Height() / 2));
125  Size aArrowSize(aButtonSize.Width() / 4, aButtonSize.Height() / 10);
126 
127  tools::Polygon aPoly(3);
128  aPoly.SetPoint(Point(aCenter.X() - aArrowSize.Width(), aCenter.Y() - aArrowSize.Height()), 0);
129  aPoly.SetPoint(Point(aCenter.X() + aArrowSize.Width(), aCenter.Y() - aArrowSize.Height()), 1);
130  aPoly.SetPoint(Point(aCenter.X(), aCenter.Y() + aArrowSize.Height()), 2);
131  rRenderContext.DrawPolygon(aPoly);
132 }
133 
135 {
136  // We need to check whether the position hits the button (the frame should be mouse transparent)
137  WindowHitTest aResult = MenuButton::ImplHitTest(rFramePos);
138  if (aResult != WindowHitTest::Inside)
139  return aResult;
140  else
141  {
142  return rFramePos.X() >= m_aFieldFramePixel.Right() ? WindowHitTest::Inside
143  : WindowHitTest::Transparent;
144  }
145 }
146 
147 /* 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 AdjustX(long nHorzMove)
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:167
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
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
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()
long AdjustY(long nVertMove)
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:176
virtual void MouseButtonUp(const MouseEvent &rMEvt) override
vcl::Window * GetParent() const
long X() 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)
void setZ(double fZ)
long Y() const
IMPL_LINK_NOARG(FormFieldButton, FieldPopupModeEndHdl, FloatingWindow *, void)
This button is shown when the cursor is on a drop-down form field.