summaryrefslogtreecommitdiff
path: root/fpdfsdk/formfiller/cffl_checkbox.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-06-15 12:37:33 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-06-15 20:42:01 +0000
commit77e3fc5cebfb19aed09f920536200e017cff9a0b (patch)
tree64700810faf138812cdcf7573a9caff08fb0411b /fpdfsdk/formfiller/cffl_checkbox.cpp
parentb7384b5b997975c36bb37d25c63e2c900eca41f9 (diff)
downloadpdfium-77e3fc5cebfb19aed09f920536200e017cff9a0b.tar.xz
Change some CFFL classes to use early returns.chromium/3132
Also switch C-style casts to the appropriate C++ casts, and add helper functions in some cases. Change-Id: I73f1ab36c6c89ced9d2b7b98393805142661dcac Reviewed-on: https://pdfium-review.googlesource.com/6650 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/formfiller/cffl_checkbox.cpp')
-rw-r--r--fpdfsdk/formfiller/cffl_checkbox.cpp53
1 files changed, 30 insertions, 23 deletions
diff --git a/fpdfsdk/formfiller/cffl_checkbox.cpp b/fpdfsdk/formfiller/cffl_checkbox.cpp
index a81458e92d..a89e76ac0d 100644
--- a/fpdfsdk/formfiller/cffl_checkbox.cpp
+++ b/fpdfsdk/formfiller/cffl_checkbox.cpp
@@ -58,7 +58,8 @@ bool CFFL_CheckBox::OnChar(CPDFSDK_Annot* pAnnot,
return true;
CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
- if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, true))
+ CPWL_CheckBox* pWnd = GetCheckBox(pPageView, true);
+ if (pWnd)
pWnd->SetCheck(!pWnd->IsChecked());
return CommitData(pPageView, nFlags);
@@ -74,40 +75,46 @@ bool CFFL_CheckBox::OnLButtonUp(CPDFSDK_PageView* pPageView,
const CFX_PointF& point) {
CFFL_Button::OnLButtonUp(pPageView, pAnnot, nFlags, point);
- if (IsValid()) {
- if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, true)) {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
- pWnd->SetCheck(!pWidget->IsChecked());
- }
+ if (!IsValid())
+ return true;
- return CommitData(pPageView, nFlags);
+ CPWL_CheckBox* pWnd = GetCheckBox(pPageView, true);
+ if (pWnd) {
+ CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot);
+ pWnd->SetCheck(!pWidget->IsChecked());
}
- return true;
+ return CommitData(pPageView, nFlags);
}
bool CFFL_CheckBox::IsDataChanged(CPDFSDK_PageView* pPageView) {
- CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, false);
+ CPWL_CheckBox* pWnd = GetCheckBox(pPageView, false);
return pWnd && pWnd->IsChecked() != m_pWidget->IsChecked();
}
void CFFL_CheckBox::SaveData(CPDFSDK_PageView* pPageView) {
- if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, false)) {
- bool bNewChecked = pWnd->IsChecked();
-
- if (bNewChecked) {
- CPDF_FormField* pField = m_pWidget->GetFormField();
- for (int32_t i = 0, sz = pField->CountControls(); i < sz; i++) {
- if (CPDF_FormControl* pCtrl = pField->GetControl(i)) {
- if (pCtrl->IsChecked()) {
- break;
- }
+ CPWL_CheckBox* pWnd = GetCheckBox(pPageView, false);
+ if (!pWnd)
+ return;
+
+ bool bNewChecked = pWnd->IsChecked();
+ if (bNewChecked) {
+ CPDF_FormField* pField = m_pWidget->GetFormField();
+ for (int32_t i = 0, sz = pField->CountControls(); i < sz; i++) {
+ if (CPDF_FormControl* pCtrl = pField->GetControl(i)) {
+ if (pCtrl->IsChecked()) {
+ break;
}
}
}
-
- m_pWidget->SetCheck(bNewChecked, false);
- m_pWidget->UpdateField();
- SetChangeMark();
}
+
+ m_pWidget->SetCheck(bNewChecked, false);
+ m_pWidget->UpdateField();
+ SetChangeMark();
+}
+
+CPWL_CheckBox* CFFL_CheckBox::GetCheckBox(CPDFSDK_PageView* pPageView,
+ bool bNew) {
+ return static_cast<CPWL_CheckBox*>(GetPDFWindow(pPageView, bNew));
}