Split CPWL_CBButton and CPWL_CBListBox into their own files
-- move one constant to anonymous namespace while at it
Change-Id: I8d34372d574f2ccc8e7989dd10d95889e0762101
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/75152
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp
index a759b53..db9a7ff 100644
--- a/fpdfsdk/formfiller/cffl_combobox.cpp
+++ b/fpdfsdk/formfiller/cffl_combobox.cpp
@@ -14,6 +14,7 @@
#include "fpdfsdk/cpdfsdk_widget.h"
#include "fpdfsdk/formfiller/cffl_interactiveformfiller.h"
#include "fpdfsdk/pwl/cpwl_combo_box.h"
+#include "fpdfsdk/pwl/cpwl_edit.h"
CFFL_ComboBox::CFFL_ComboBox(CPDFSDK_FormFillEnvironment* pApp,
CPDFSDK_Widget* pWidget)
diff --git a/fpdfsdk/pwl/BUILD.gn b/fpdfsdk/pwl/BUILD.gn
index fa8df3c..6921b27 100644
--- a/fpdfsdk/pwl/BUILD.gn
+++ b/fpdfsdk/pwl/BUILD.gn
@@ -11,6 +11,10 @@
"cpwl_button.h",
"cpwl_caret.cpp",
"cpwl_caret.h",
+ "cpwl_cbbutton.cpp",
+ "cpwl_cbbutton.h",
+ "cpwl_cblistbox.cpp",
+ "cpwl_cblistbox.h",
"cpwl_combo_box.cpp",
"cpwl_combo_box.h",
"cpwl_edit.cpp",
diff --git a/fpdfsdk/pwl/cpwl_cbbutton.cpp b/fpdfsdk/pwl/cpwl_cbbutton.cpp
new file mode 100644
index 0000000..e2848b2
--- /dev/null
+++ b/fpdfsdk/pwl/cpwl_cbbutton.cpp
@@ -0,0 +1,77 @@
+// Copyright 2020 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "fpdfsdk/pwl/cpwl_cbbutton.h"
+
+#include <utility>
+
+#include "core/fxge/cfx_fillrenderoptions.h"
+#include "core/fxge/cfx_pathdata.h"
+#include "core/fxge/cfx_renderdevice.h"
+
+namespace {
+
+constexpr float kComboBoxTriangleHalfLength = 3.0f;
+constexpr float kComboBoxTriangleQuarterLength =
+ kComboBoxTriangleHalfLength * 0.5;
+
+} // namespace
+
+CPWL_CBButton::CPWL_CBButton(
+ const CreateParams& cp,
+ std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData)
+ : CPWL_Wnd(cp, std::move(pAttachedData)) {}
+
+CPWL_CBButton::~CPWL_CBButton() = default;
+
+void CPWL_CBButton::DrawThisAppearance(CFX_RenderDevice* pDevice,
+ const CFX_Matrix& mtUser2Device) {
+ CPWL_Wnd::DrawThisAppearance(pDevice, mtUser2Device);
+
+ CFX_FloatRect rectWnd = CPWL_Wnd::GetWindowRect();
+ if (!IsVisible() || rectWnd.IsEmpty())
+ return;
+
+ CFX_PointF ptCenter = GetCenterPoint();
+
+ CFX_PointF pt1(ptCenter.x - kComboBoxTriangleHalfLength,
+ ptCenter.y + kComboBoxTriangleQuarterLength);
+ CFX_PointF pt2(ptCenter.x + kComboBoxTriangleHalfLength,
+ ptCenter.y + kComboBoxTriangleQuarterLength);
+ CFX_PointF pt3(ptCenter.x, ptCenter.y - kComboBoxTriangleQuarterLength);
+
+ if (IsFloatBigger(rectWnd.right - rectWnd.left,
+ kComboBoxTriangleHalfLength * 2) &&
+ IsFloatBigger(rectWnd.top - rectWnd.bottom,
+ kComboBoxTriangleHalfLength)) {
+ CFX_PathData path;
+ path.AppendPoint(pt1, FXPT_TYPE::MoveTo);
+ path.AppendPoint(pt2, FXPT_TYPE::LineTo);
+ path.AppendPoint(pt3, FXPT_TYPE::LineTo);
+ path.AppendPoint(pt1, FXPT_TYPE::LineTo);
+
+ pDevice->DrawPath(&path, &mtUser2Device, nullptr,
+ PWL_DEFAULT_BLACKCOLOR.ToFXColor(GetTransparency()), 0,
+ CFX_FillRenderOptions::EvenOddOptions());
+ }
+}
+
+bool CPWL_CBButton::OnLButtonDown(uint32_t nFlag, const CFX_PointF& point) {
+ CPWL_Wnd::OnLButtonDown(nFlag, point);
+
+ SetCapture();
+ if (CPWL_Wnd* pParent = GetParentWindow())
+ pParent->NotifyLButtonDown(this, point);
+
+ return true;
+}
+
+bool CPWL_CBButton::OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) {
+ CPWL_Wnd::OnLButtonUp(nFlag, point);
+
+ ReleaseCapture();
+ return true;
+}
diff --git a/fpdfsdk/pwl/cpwl_cbbutton.h b/fpdfsdk/pwl/cpwl_cbbutton.h
new file mode 100644
index 0000000..ce36d7d
--- /dev/null
+++ b/fpdfsdk/pwl/cpwl_cbbutton.h
@@ -0,0 +1,29 @@
+// Copyright 2020 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef FPDFSDK_PWL_CPWL_CBBUTTON_H_
+#define FPDFSDK_PWL_CPWL_CBBUTTON_H_
+
+#include <memory>
+
+#include "fpdfsdk/pwl/cpwl_wnd.h"
+#include "fpdfsdk/pwl/ipwl_systemhandler.h"
+
+class CPWL_CBButton final : public CPWL_Wnd {
+ public:
+ CPWL_CBButton(
+ const CreateParams& cp,
+ std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData);
+ ~CPWL_CBButton() override;
+
+ // CPWL_Wnd:
+ void DrawThisAppearance(CFX_RenderDevice* pDevice,
+ const CFX_Matrix& mtUser2Device) override;
+ bool OnLButtonDown(uint32_t nFlag, const CFX_PointF& point) override;
+ bool OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) override;
+};
+
+#endif // FPDFSDK_PWL_CPWL_CBBUTTON_H_
diff --git a/fpdfsdk/pwl/cpwl_cblistbox.cpp b/fpdfsdk/pwl/cpwl_cblistbox.cpp
new file mode 100644
index 0000000..04b6f60
--- /dev/null
+++ b/fpdfsdk/pwl/cpwl_cblistbox.cpp
@@ -0,0 +1,89 @@
+// Copyright 2020 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "fpdfsdk/pwl/cpwl_cblistbox.h"
+
+#include <utility>
+
+#include "fpdfsdk/pwl/cpwl_combo_box.h"
+#include "fpdfsdk/pwl/cpwl_list_ctrl.h"
+#include "public/fpdf_fwlevent.h"
+
+CPWL_CBListBox::CPWL_CBListBox(
+ const CreateParams& cp,
+ std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData)
+ : CPWL_ListBox(cp, std::move(pAttachedData)) {}
+
+CPWL_CBListBox::~CPWL_CBListBox() = default;
+
+bool CPWL_CBListBox::OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) {
+ CPWL_Wnd::OnLButtonUp(nFlag, point);
+
+ if (!m_bMouseDown)
+ return true;
+
+ ReleaseCapture();
+ m_bMouseDown = false;
+
+ if (!ClientHitTest(point))
+ return true;
+ if (CPWL_Wnd* pParent = GetParentWindow())
+ pParent->NotifyLButtonUp(this, point);
+
+ return !OnNotifySelectionChanged(false, nFlag);
+}
+
+bool CPWL_CBListBox::IsMovementKey(uint16_t nChar) const {
+ switch (nChar) {
+ case FWL_VKEY_Up:
+ case FWL_VKEY_Down:
+ case FWL_VKEY_Home:
+ case FWL_VKEY_Left:
+ case FWL_VKEY_End:
+ case FWL_VKEY_Right:
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool CPWL_CBListBox::OnMovementKeyDown(uint16_t nChar, uint32_t nFlag) {
+ ASSERT(IsMovementKey(nChar));
+
+ switch (nChar) {
+ case FWL_VKEY_Up:
+ m_pListCtrl->OnVK_UP(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
+ break;
+ case FWL_VKEY_Down:
+ m_pListCtrl->OnVK_DOWN(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
+ break;
+ case FWL_VKEY_Home:
+ m_pListCtrl->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
+ break;
+ case FWL_VKEY_Left:
+ m_pListCtrl->OnVK_LEFT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
+ break;
+ case FWL_VKEY_End:
+ m_pListCtrl->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
+ break;
+ case FWL_VKEY_Right:
+ m_pListCtrl->OnVK_RIGHT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
+ break;
+ }
+ return OnNotifySelectionChanged(true, nFlag);
+}
+
+bool CPWL_CBListBox::IsChar(uint16_t nChar, uint32_t nFlag) const {
+ return m_pListCtrl->OnChar(nChar, IsSHIFTpressed(nFlag),
+ IsCTRLpressed(nFlag));
+}
+
+bool CPWL_CBListBox::OnCharNotify(uint16_t nChar, uint32_t nFlag) {
+ if (auto* pComboBox = static_cast<CPWL_ComboBox*>(GetParentWindow()))
+ pComboBox->SetSelectText();
+
+ return OnNotifySelectionChanged(true, nFlag);
+}
diff --git a/fpdfsdk/pwl/cpwl_cblistbox.h b/fpdfsdk/pwl/cpwl_cblistbox.h
new file mode 100644
index 0000000..f0f6d37
--- /dev/null
+++ b/fpdfsdk/pwl/cpwl_cblistbox.h
@@ -0,0 +1,31 @@
+// Copyright 2020 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef FPDFSDK_PWL_CPWL_CBLISTBOX_H_
+#define FPDFSDK_PWL_CPWL_CBLISTBOX_H_
+
+#include <memory>
+
+#include "fpdfsdk/pwl/cpwl_list_box.h"
+#include "fpdfsdk/pwl/ipwl_systemhandler.h"
+
+class CPWL_CBListBox final : public CPWL_ListBox {
+ public:
+ CPWL_CBListBox(
+ const CreateParams& cp,
+ std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData);
+ ~CPWL_CBListBox() override;
+
+ // CPWL_ListBox
+ bool OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) override;
+
+ bool IsMovementKey(uint16_t nChar) const;
+ bool OnMovementKeyDown(uint16_t nChar, uint32_t nFlag);
+ bool IsChar(uint16_t nChar, uint32_t nFlag) const;
+ bool OnCharNotify(uint16_t nChar, uint32_t nFlag);
+};
+
+#endif // FPDFSDK_PWL_CPWL_CBLISTBOX_H_
diff --git a/fpdfsdk/pwl/cpwl_combo_box.cpp b/fpdfsdk/pwl/cpwl_combo_box.cpp
index af5dffc..d49849f 100644
--- a/fpdfsdk/pwl/cpwl_combo_box.cpp
+++ b/fpdfsdk/pwl/cpwl_combo_box.cpp
@@ -7,159 +7,21 @@
#include "fpdfsdk/pwl/cpwl_combo_box.h"
#include <algorithm>
-#include <sstream>
#include <utility>
-#include "core/fxge/cfx_fillrenderoptions.h"
-#include "core/fxge/cfx_pathdata.h"
-#include "core/fxge/cfx_renderdevice.h"
-#include "fpdfsdk/pwl/cpwl_edit_ctrl.h"
-#include "fpdfsdk/pwl/cpwl_list_ctrl.h"
+#include "fpdfsdk/pwl/cpwl_cbbutton.h"
+#include "fpdfsdk/pwl/cpwl_cblistbox.h"
+#include "fpdfsdk/pwl/cpwl_edit.h"
#include "fpdfsdk/pwl/ipwl_fillernotify.h"
#include "public/fpdf_fwlevent.h"
namespace {
constexpr float kComboBoxDefaultFontSize = 12.0f;
-constexpr float kComboBoxTriangleHalfLength = 3.0f;
constexpr int kDefaultButtonWidth = 13;
} // namespace
-CPWL_CBListBox::CPWL_CBListBox(
- const CreateParams& cp,
- std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData)
- : CPWL_ListBox(cp, std::move(pAttachedData)) {}
-
-CPWL_CBListBox::~CPWL_CBListBox() = default;
-
-bool CPWL_CBListBox::OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) {
- CPWL_Wnd::OnLButtonUp(nFlag, point);
-
- if (!m_bMouseDown)
- return true;
-
- ReleaseCapture();
- m_bMouseDown = false;
-
- if (!ClientHitTest(point))
- return true;
- if (CPWL_Wnd* pParent = GetParentWindow())
- pParent->NotifyLButtonUp(this, point);
-
- return !OnNotifySelectionChanged(false, nFlag);
-}
-
-bool CPWL_CBListBox::IsMovementKey(uint16_t nChar) const {
- switch (nChar) {
- case FWL_VKEY_Up:
- case FWL_VKEY_Down:
- case FWL_VKEY_Home:
- case FWL_VKEY_Left:
- case FWL_VKEY_End:
- case FWL_VKEY_Right:
- return true;
- default:
- return false;
- }
-}
-
-bool CPWL_CBListBox::OnMovementKeyDown(uint16_t nChar, uint32_t nFlag) {
- ASSERT(IsMovementKey(nChar));
-
- switch (nChar) {
- case FWL_VKEY_Up:
- m_pListCtrl->OnVK_UP(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
- break;
- case FWL_VKEY_Down:
- m_pListCtrl->OnVK_DOWN(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
- break;
- case FWL_VKEY_Home:
- m_pListCtrl->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
- break;
- case FWL_VKEY_Left:
- m_pListCtrl->OnVK_LEFT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
- break;
- case FWL_VKEY_End:
- m_pListCtrl->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
- break;
- case FWL_VKEY_Right:
- m_pListCtrl->OnVK_RIGHT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
- break;
- }
- return OnNotifySelectionChanged(true, nFlag);
-}
-
-bool CPWL_CBListBox::IsChar(uint16_t nChar, uint32_t nFlag) const {
- return m_pListCtrl->OnChar(nChar, IsSHIFTpressed(nFlag),
- IsCTRLpressed(nFlag));
-}
-
-bool CPWL_CBListBox::OnCharNotify(uint16_t nChar, uint32_t nFlag) {
- if (auto* pComboBox = static_cast<CPWL_ComboBox*>(GetParentWindow()))
- pComboBox->SetSelectText();
-
- return OnNotifySelectionChanged(true, nFlag);
-}
-
-CPWL_CBButton::CPWL_CBButton(
- const CreateParams& cp,
- std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData)
- : CPWL_Wnd(cp, std::move(pAttachedData)) {}
-
-CPWL_CBButton::~CPWL_CBButton() = default;
-
-void CPWL_CBButton::DrawThisAppearance(CFX_RenderDevice* pDevice,
- const CFX_Matrix& mtUser2Device) {
- CPWL_Wnd::DrawThisAppearance(pDevice, mtUser2Device);
-
- CFX_FloatRect rectWnd = CPWL_Wnd::GetWindowRect();
- if (!IsVisible() || rectWnd.IsEmpty())
- return;
-
- CFX_PointF ptCenter = GetCenterPoint();
-
- static constexpr float kComboBoxTriangleQuarterLength =
- kComboBoxTriangleHalfLength * 0.5;
- CFX_PointF pt1(ptCenter.x - kComboBoxTriangleHalfLength,
- ptCenter.y + kComboBoxTriangleQuarterLength);
- CFX_PointF pt2(ptCenter.x + kComboBoxTriangleHalfLength,
- ptCenter.y + kComboBoxTriangleQuarterLength);
- CFX_PointF pt3(ptCenter.x, ptCenter.y - kComboBoxTriangleQuarterLength);
-
- if (IsFloatBigger(rectWnd.right - rectWnd.left,
- kComboBoxTriangleHalfLength * 2) &&
- IsFloatBigger(rectWnd.top - rectWnd.bottom,
- kComboBoxTriangleHalfLength)) {
- CFX_PathData path;
- path.AppendPoint(pt1, FXPT_TYPE::MoveTo);
- path.AppendPoint(pt2, FXPT_TYPE::LineTo);
- path.AppendPoint(pt3, FXPT_TYPE::LineTo);
- path.AppendPoint(pt1, FXPT_TYPE::LineTo);
-
- pDevice->DrawPath(&path, &mtUser2Device, nullptr,
- PWL_DEFAULT_BLACKCOLOR.ToFXColor(GetTransparency()), 0,
- CFX_FillRenderOptions::EvenOddOptions());
- }
-}
-
-bool CPWL_CBButton::OnLButtonDown(uint32_t nFlag, const CFX_PointF& point) {
- CPWL_Wnd::OnLButtonDown(nFlag, point);
-
- SetCapture();
- if (CPWL_Wnd* pParent = GetParentWindow())
- pParent->NotifyLButtonDown(this, point);
-
- return true;
-}
-
-bool CPWL_CBButton::OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) {
- CPWL_Wnd::OnLButtonUp(nFlag, point);
-
- ReleaseCapture();
- return true;
-}
-
CPWL_ComboBox::CPWL_ComboBox(
const CreateParams& cp,
std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData)
diff --git a/fpdfsdk/pwl/cpwl_combo_box.h b/fpdfsdk/pwl/cpwl_combo_box.h
index 1624af2..fb5d124 100644
--- a/fpdfsdk/pwl/cpwl_combo_box.h
+++ b/fpdfsdk/pwl/cpwl_combo_box.h
@@ -11,42 +11,15 @@
#include <utility>
#include "core/fxcrt/unowned_ptr.h"
-#include "fpdfsdk/pwl/cpwl_edit.h"
-#include "fpdfsdk/pwl/cpwl_list_box.h"
#include "fpdfsdk/pwl/cpwl_wnd.h"
+#include "fpdfsdk/pwl/ipwl_systemhandler.h"
+class CFFL_FormFiller;
+class CPWL_Edit;
+class CPWL_CBButton;
+class CPWL_CBListBox;
class IPWL_FillerNotify;
-class CPWL_CBListBox final : public CPWL_ListBox {
- public:
- CPWL_CBListBox(
- const CreateParams& cp,
- std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData);
- ~CPWL_CBListBox() override;
-
- // CPWL_ListBox
- bool OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) override;
-
- bool IsMovementKey(uint16_t nChar) const;
- bool OnMovementKeyDown(uint16_t nChar, uint32_t nFlag);
- bool IsChar(uint16_t nChar, uint32_t nFlag) const;
- bool OnCharNotify(uint16_t nChar, uint32_t nFlag);
-};
-
-class CPWL_CBButton final : public CPWL_Wnd {
- public:
- CPWL_CBButton(
- const CreateParams& cp,
- std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData);
- ~CPWL_CBButton() override;
-
- // CPWL_Wnd
- void DrawThisAppearance(CFX_RenderDevice* pDevice,
- const CFX_Matrix& mtUser2Device) override;
- bool OnLButtonDown(uint32_t nFlag, const CFX_PointF& point) override;
- bool OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) override;
-};
-
class CPWL_ComboBox final : public CPWL_Wnd {
public:
CPWL_ComboBox(