1 // Copyright 2020 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "fpdfsdk/pwl/cpwl_cbbutton.h"
8
9 #include <utility>
10
11 #include "core/fxge/cfx_fillrenderoptions.h"
12 #include "core/fxge/cfx_path.h"
13 #include "core/fxge/cfx_renderdevice.h"
14
CPWL_CBButton(const CreateParams & cp,std::unique_ptr<IPWL_FillerNotify::PerWindowData> pAttachedData)15 CPWL_CBButton::CPWL_CBButton(
16 const CreateParams& cp,
17 std::unique_ptr<IPWL_FillerNotify::PerWindowData> pAttachedData)
18 : CPWL_Wnd(cp, std::move(pAttachedData)) {}
19
20 CPWL_CBButton::~CPWL_CBButton() = default;
21
DrawThisAppearance(CFX_RenderDevice * pDevice,const CFX_Matrix & mtUser2Device)22 void CPWL_CBButton::DrawThisAppearance(CFX_RenderDevice* pDevice,
23 const CFX_Matrix& mtUser2Device) {
24 CPWL_Wnd::DrawThisAppearance(pDevice, mtUser2Device);
25
26 if (!IsVisible())
27 return;
28
29 CFX_FloatRect window = CPWL_Wnd::GetWindowRect();
30 if (window.IsEmpty())
31 return;
32
33 constexpr float kComboBoxTriangleLength = 6.0f;
34 constexpr float kComboBoxTriangleHalfLength = kComboBoxTriangleLength / 2;
35 constexpr float kComboBoxTriangleQuarterLength = kComboBoxTriangleLength / 4;
36 if (!FXSYS_IsFloatBigger(window.right - window.left,
37 kComboBoxTriangleLength) ||
38 !FXSYS_IsFloatBigger(window.top - window.bottom,
39 kComboBoxTriangleHalfLength)) {
40 return;
41 }
42
43 CFX_PointF ptCenter = GetCenterPoint();
44 CFX_PointF pt1(ptCenter.x - kComboBoxTriangleHalfLength,
45 ptCenter.y + kComboBoxTriangleQuarterLength);
46 CFX_PointF pt2(ptCenter.x + kComboBoxTriangleHalfLength,
47 ptCenter.y + kComboBoxTriangleQuarterLength);
48 CFX_PointF pt3(ptCenter.x, ptCenter.y - kComboBoxTriangleQuarterLength);
49
50 CFX_Path path;
51 path.AppendPoint(pt1, CFX_Path::Point::Type::kMove);
52 path.AppendPoint(pt2, CFX_Path::Point::Type::kLine);
53 path.AppendPoint(pt3, CFX_Path::Point::Type::kLine);
54 path.AppendPoint(pt1, CFX_Path::Point::Type::kLine);
55
56 pDevice->DrawPath(path, &mtUser2Device, nullptr,
57 kDefaultBlackColor.ToFXColor(GetTransparency()), 0,
58 CFX_FillRenderOptions::EvenOddOptions());
59 }
60
OnLButtonDown(Mask<FWL_EVENTFLAG> nFlag,const CFX_PointF & point)61 bool CPWL_CBButton::OnLButtonDown(Mask<FWL_EVENTFLAG> nFlag,
62 const CFX_PointF& point) {
63 CPWL_Wnd::OnLButtonDown(nFlag, point);
64
65 SetCapture();
66 CPWL_Wnd* pParent = GetParentWindow();
67 if (pParent)
68 pParent->NotifyLButtonDown(this, point);
69
70 return true;
71 }
72
OnLButtonUp(Mask<FWL_EVENTFLAG> nFlag,const CFX_PointF & point)73 bool CPWL_CBButton::OnLButtonUp(Mask<FWL_EVENTFLAG> nFlag,
74 const CFX_PointF& point) {
75 CPWL_Wnd::OnLButtonUp(nFlag, point);
76
77 ReleaseCapture();
78 return true;
79 }
80