From 77e3fc5cebfb19aed09f920536200e017cff9a0b Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 15 Jun 2017 12:37:33 -0700 Subject: Change some CFFL classes to use early returns. 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 Reviewed-by: dsinclair --- fpdfsdk/formfiller/cffl_radiobutton.cpp | 61 +++++++++++++++++---------------- 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'fpdfsdk/formfiller/cffl_radiobutton.cpp') diff --git a/fpdfsdk/formfiller/cffl_radiobutton.cpp b/fpdfsdk/formfiller/cffl_radiobutton.cpp index c6ce432d0c..9ffdf494ca 100644 --- a/fpdfsdk/formfiller/cffl_radiobutton.cpp +++ b/fpdfsdk/formfiller/cffl_radiobutton.cpp @@ -57,8 +57,8 @@ bool CFFL_RadioButton::OnChar(CPDFSDK_Annot* pAnnot, return true; CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); - if (CPWL_RadioButton* pWnd = - (CPWL_RadioButton*)GetPDFWindow(pPageView, true)) + CPWL_RadioButton* pWnd = GetRadioButton(pPageView, true); + if (pWnd) pWnd->SetCheck(true); return CommitData(pPageView, nFlags); } @@ -73,44 +73,45 @@ bool CFFL_RadioButton::OnLButtonUp(CPDFSDK_PageView* pPageView, const CFX_PointF& point) { CFFL_Button::OnLButtonUp(pPageView, pAnnot, nFlags, point); - if (IsValid()) { - if (CPWL_RadioButton* pWnd = - (CPWL_RadioButton*)GetPDFWindow(pPageView, true)) - pWnd->SetCheck(true); + if (!IsValid()) + return true; - return CommitData(pPageView, nFlags); - } + CPWL_RadioButton* pWnd = GetRadioButton(pPageView, true); + if (pWnd) + pWnd->SetCheck(true); - return true; + return CommitData(pPageView, nFlags); } bool CFFL_RadioButton::IsDataChanged(CPDFSDK_PageView* pPageView) { - if (CPWL_RadioButton* pWnd = - (CPWL_RadioButton*)GetPDFWindow(pPageView, false)) { - return pWnd->IsChecked() != m_pWidget->IsChecked(); - } - - return false; + CPWL_RadioButton* pWnd = GetRadioButton(pPageView, false); + return pWnd && pWnd->IsChecked() != m_pWidget->IsChecked(); } void CFFL_RadioButton::SaveData(CPDFSDK_PageView* pPageView) { - if (CPWL_RadioButton* pWnd = - (CPWL_RadioButton*)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_RadioButton* pWnd = GetRadioButton(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_RadioButton* CFFL_RadioButton::GetRadioButton(CPDFSDK_PageView* pPageView, + bool bNew) { + return static_cast(GetPDFWindow(pPageView, bNew)); } -- cgit v1.2.3