Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cffl_checkbox.cpp
Go to the documentation of this file.
1// Copyright 2014 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/formfiller/cffl_checkbox.h"
8
9#include <utility>
10
11#include "constants/ascii.h"
12#include "core/fpdfdoc/cpdf_formcontrol.h"
13#include "fpdfsdk/cpdfsdk_widget.h"
14#include "fpdfsdk/formfiller/cffl_formfield.h"
15#include "fpdfsdk/pwl/cpwl_special_button.h"
16#include "public/fpdf_fwlevent.h"
17#include "third_party/base/check.h"
18
19CFFL_CheckBox::CFFL_CheckBox(CFFL_InteractiveFormFiller* pFormFiller,
20 CPDFSDK_Widget* pWidget)
21 : CFFL_Button(pFormFiller, pWidget) {}
22
23CFFL_CheckBox::~CFFL_CheckBox() = default;
24
26 const CPWL_Wnd::CreateParams& cp,
27 std::unique_ptr<IPWL_FillerNotify::PerWindowData> pAttachedData) {
28 auto pWnd = std::make_unique<CPWL_CheckBox>(cp, std::move(pAttachedData));
29 pWnd->Realize();
30 pWnd->SetCheck(m_pWidget->IsChecked());
31 return std::move(pWnd);
32}
33
34bool CFFL_CheckBox::OnKeyDown(FWL_VKEYCODE nKeyCode,
35 Mask<FWL_EVENTFLAG> nFlags) {
36 switch (nKeyCode) {
37 case FWL_VKEY_Return:
38 case FWL_VKEY_Space:
39 return true;
40 default:
41 return CFFL_FormField::OnKeyDown(nKeyCode, nFlags);
42 }
43}
44
45bool CFFL_CheckBox::OnChar(CPDFSDK_Widget* pWidget,
46 uint32_t nChar,
47 Mask<FWL_EVENTFLAG> nFlags) {
48 switch (nChar) {
49 case pdfium::ascii::kReturn:
50 case pdfium::ascii::kSpace: {
51 CPDFSDK_PageView* pPageView = pWidget->GetPageView();
52 DCHECK(pPageView);
53
54 ObservedPtr<CPDFSDK_Widget> pObserved(m_pWidget);
55 if (m_pFormFiller->OnButtonUp(pObserved, pPageView, nFlags)) {
56 if (!pObserved)
57 m_pWidget = nullptr;
58 return true;
59 }
60 if (!pObserved) {
61 m_pWidget = nullptr;
62 return true;
63 }
64
65 CFFL_FormField::OnChar(pWidget, nChar, nFlags);
66
67 CPWL_CheckBox* pWnd = CreateOrUpdatePWLCheckBox(pPageView);
68 if (pWnd && !pWnd->IsReadOnly()) {
69 ObservedPtr<CPWL_CheckBox> pObservedBox(pWnd);
70 const bool is_checked = pWidget->IsChecked();
71 if (pObservedBox) {
72 pObservedBox->SetCheck(!is_checked);
73 }
74 }
75 return CommitData(pPageView, nFlags);
76 }
77 default:
78 return CFFL_FormField::OnChar(pWidget, nChar, nFlags);
79 }
80}
81
82bool CFFL_CheckBox::OnLButtonUp(CPDFSDK_PageView* pPageView,
83 CPDFSDK_Widget* pWidget,
84 Mask<FWL_EVENTFLAG> nFlags,
85 const CFX_PointF& point) {
86 CFFL_Button::OnLButtonUp(pPageView, pWidget, nFlags, point);
87 if (!IsValid()) {
88 return true;
89 }
90 CPWL_CheckBox* pWnd = CreateOrUpdatePWLCheckBox(pPageView);
91 if (pWnd) {
92 ObservedPtr<CPWL_CheckBox> pObservedBox(pWnd);
93 const bool is_checked = pWidget->IsChecked();
94 if (pObservedBox) {
95 pObservedBox->SetCheck(!is_checked);
96 }
97 }
98 return CommitData(pPageView, nFlags);
99}
100
101bool CFFL_CheckBox::IsDataChanged(const CPDFSDK_PageView* pPageView) {
102 CPWL_CheckBox* pWnd = GetPWLCheckBox(pPageView);
103 return pWnd && pWnd->IsChecked() != m_pWidget->IsChecked();
104}
105
106void CFFL_CheckBox::SaveData(const CPDFSDK_PageView* pPageView) {
107 CPWL_CheckBox* pWnd = GetPWLCheckBox(pPageView);
108 if (!pWnd)
109 return;
110
111 bool bNewChecked = pWnd->IsChecked();
112 ObservedPtr<CPDFSDK_Widget> observed_widget(m_pWidget);
113 ObservedPtr<CFFL_CheckBox> observed_this(this);
114 m_pWidget->SetCheck(bNewChecked);
115 if (!observed_widget)
116 return;
117
118 m_pWidget->UpdateField();
119 if (!observed_widget || !observed_this)
120 return;
121
123}
124
125CPWL_CheckBox* CFFL_CheckBox::GetPWLCheckBox(
126 const CPDFSDK_PageView* pPageView) const {
127 return static_cast<CPWL_CheckBox*>(GetPWLWindow(pPageView));
128}
129
130CPWL_CheckBox* CFFL_CheckBox::CreateOrUpdatePWLCheckBox(
131 const CPDFSDK_PageView* pPageView) {
132 return static_cast<CPWL_CheckBox*>(CreateOrUpdatePWLWindow(pPageView));
133}
CFFL_Button(CFFL_InteractiveFormFiller *pFormFiller, CPDFSDK_Widget *pWidget)
bool OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Widget *pWidget, Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point) override
~CFFL_CheckBox() override
bool IsDataChanged(const CPDFSDK_PageView *pPageView) override
bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask< FWL_EVENTFLAG > nFlags) override
std::unique_ptr< CPWL_Wnd > NewPWLWindow(const CPWL_Wnd::CreateParams &cp, std::unique_ptr< IPWL_FillerNotify::PerWindowData > pAttachedData) override
bool OnChar(CPDFSDK_Widget *pWidget, uint32_t nChar, Mask< FWL_EVENTFLAG > nFlags) override
bool OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Widget *pWidget, Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point) override
void SaveData(const CPDFSDK_PageView *pPageView) override
CFFL_CheckBox(CFFL_InteractiveFormFiller *pFormFiller, CPDFSDK_Widget *pWidget)
virtual bool OnChar(CPDFSDK_Widget *pAnnot, uint32_t nChar, Mask< FWL_EVENTFLAG > nFlags)
CPWL_Wnd * GetPWLWindow(const CPDFSDK_PageView *pPageView) const
CPWL_Wnd * CreateOrUpdatePWLWindow(const CPDFSDK_PageView *pPageView)
bool CommitData(const CPDFSDK_PageView *pPageView, Mask< FWL_EVENTFLAG > nFlag)
virtual bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask< FWL_EVENTFLAG > nFlags)
bool IsValid() const
CPDFSDK_PageView * GetPageView() const
bool IsChecked() const
bool IsChecked() const
bool IsReadOnly() const
Definition cpwl_wnd.cpp:610
@ FWL_VKEY_Space
@ FWL_VKEY_Return
constexpr uint8_t kReturn
Definition ascii.h:20
constexpr uint8_t kSpace
Definition ascii.h:25