Add CFFL_ComboBox::GetComboBox().
Consolidate a bunch of identical calls plus casting.
Change-Id: I20ee5fe928eab51daf22cbb796bde34bb07f0f01
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/60170
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp
index cee4108..9448ab8 100644
--- a/fpdfsdk/formfiller/cffl_combobox.cpp
+++ b/fpdfsdk/formfiller/cffl_combobox.cpp
@@ -77,7 +77,7 @@
}
bool CFFL_ComboBox::IsDataChanged(CPDFSDK_PageView* pPageView) {
- auto* pWnd = static_cast<CPWL_ComboBox*>(GetPWLWindow(pPageView, false));
+ auto* pWnd = GetComboBox(pPageView, false);
if (!pWnd)
return false;
@@ -92,8 +92,7 @@
}
void CFFL_ComboBox::SaveData(CPDFSDK_PageView* pPageView) {
- CPWL_ComboBox* pWnd =
- static_cast<CPWL_ComboBox*>(GetPWLWindow(pPageView, false));
+ CPWL_ComboBox* pWnd = GetComboBox(pPageView, false);
if (!pWnd)
return;
@@ -129,8 +128,7 @@
CPDFSDK_FieldAction& fa) {
switch (type) {
case CPDF_AAction::kKeyStroke:
- if (CPWL_ComboBox* pComboBox =
- static_cast<CPWL_ComboBox*>(GetPWLWindow(pPageView, false))) {
+ if (CPWL_ComboBox* pComboBox = GetComboBox(pPageView, false)) {
if (CPWL_Edit* pEdit = pComboBox->GetEdit()) {
fa.bFieldFull = pEdit->IsTextFull();
int nSelStart = 0;
@@ -149,8 +147,7 @@
}
break;
case CPDF_AAction::kValidate:
- if (CPWL_ComboBox* pComboBox =
- static_cast<CPWL_ComboBox*>(GetPWLWindow(pPageView, false))) {
+ if (CPWL_ComboBox* pComboBox = GetComboBox(pPageView, false)) {
if (CPWL_Edit* pEdit = pComboBox->GetEdit()) {
fa.sValue = pEdit->GetText();
}
@@ -170,8 +167,7 @@
const CPDFSDK_FieldAction& fa) {
switch (type) {
case CPDF_AAction::kKeyStroke:
- if (CPWL_ComboBox* pComboBox =
- static_cast<CPWL_ComboBox*>(GetPWLWindow(pPageView, false))) {
+ if (CPWL_ComboBox* pComboBox = GetComboBox(pPageView, false)) {
if (CPWL_Edit* pEdit = pComboBox->GetEdit()) {
pEdit->SetSelection(fa.nSelStart, fa.nSelEnd);
pEdit->ReplaceSelection(fa.sChange);
@@ -201,8 +197,7 @@
void CFFL_ComboBox::SaveState(CPDFSDK_PageView* pPageView) {
ASSERT(pPageView);
- if (CPWL_ComboBox* pComboBox =
- static_cast<CPWL_ComboBox*>(GetPWLWindow(pPageView, false))) {
+ if (CPWL_ComboBox* pComboBox = GetComboBox(pPageView, false)) {
m_State.nIndex = pComboBox->GetSelect();
if (CPWL_Edit* pEdit = pComboBox->GetEdit()) {
@@ -215,8 +210,7 @@
void CFFL_ComboBox::RestoreState(CPDFSDK_PageView* pPageView) {
ASSERT(pPageView);
- if (CPWL_ComboBox* pComboBox =
- static_cast<CPWL_ComboBox*>(GetPWLWindow(pPageView, true))) {
+ if (CPWL_ComboBox* pComboBox = GetComboBox(pPageView, true)) {
if (m_State.nIndex >= 0) {
pComboBox->SetSelect(m_State.nIndex);
} else {
@@ -238,8 +232,7 @@
CPDFSDK_PageView* pPageView = GetCurPageView(true);
ASSERT(pPageView);
- CPWL_ComboBox* pWnd =
- static_cast<CPWL_ComboBox*>(GetPWLWindow(pPageView, false));
+ CPWL_ComboBox* pWnd = GetComboBox(pPageView, false);
if (!pWnd)
return false;
@@ -257,8 +250,7 @@
CPDFSDK_PageView* pPageView = GetCurPageView(true);
ASSERT(pPageView);
- CPWL_ComboBox* pWnd =
- static_cast<CPWL_ComboBox*>(GetPWLWindow(pPageView, false));
+ CPWL_ComboBox* pWnd = GetComboBox(pPageView, false);
if (!pWnd)
return false;
@@ -267,8 +259,7 @@
#ifdef PDF_ENABLE_XFA
bool CFFL_ComboBox::IsFieldFull(CPDFSDK_PageView* pPageView) {
- if (CPWL_ComboBox* pComboBox =
- static_cast<CPWL_ComboBox*>(GetPWLWindow(pPageView, false))) {
+ if (CPWL_ComboBox* pComboBox = GetComboBox(pPageView, false)) {
if (CPWL_Edit* pEdit = pComboBox->GetEdit())
return pEdit->IsTextFull();
}
@@ -291,7 +282,7 @@
WideString swRet;
CPDFSDK_PageView* pPageView = GetCurPageView(true);
- auto* pComboBox = static_cast<CPWL_ComboBox*>(GetPWLWindow(pPageView, false));
+ CPWL_ComboBox* pComboBox = GetComboBox(pPageView, false);
int nExport = pComboBox ? pComboBox->GetSelect() : -1;
if (nExport >= 0) {
@@ -304,3 +295,8 @@
return swRet;
}
+
+CPWL_ComboBox* CFFL_ComboBox::GetComboBox(CPDFSDK_PageView* pPageView,
+ bool bNew) {
+ return static_cast<CPWL_ComboBox*>(GetPWLWindow(pPageView, bNew));
+}
diff --git a/fpdfsdk/formfiller/cffl_combobox.h b/fpdfsdk/formfiller/cffl_combobox.h
index 2e8cd37..77fb754 100644
--- a/fpdfsdk/formfiller/cffl_combobox.h
+++ b/fpdfsdk/formfiller/cffl_combobox.h
@@ -13,6 +13,7 @@
#include "fpdfsdk/formfiller/cffl_textobject.h"
class CBA_FontMap;
+class CPWL_ComboBox;
struct FFL_ComboBoxState {
int nIndex;
@@ -58,6 +59,7 @@
private:
WideString GetSelectExportText();
+ CPWL_ComboBox* GetComboBox(CPDFSDK_PageView* pPageView, bool bNew);
FFL_ComboBoxState m_State;
};