summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-01-29 22:21:36 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-01-29 22:21:36 +0000
commit95b232f791231a0db0de780b568a0825a2e6e989 (patch)
tree951a11b9c846f4108c28ed8361a35f59f2b1829f
parent8308b8c3dfad425942d4aba19a6b85049beff6f4 (diff)
downloadpdfium-95b232f791231a0db0de780b568a0825a2e6e989.tar.xz
Cleanup some ChoiceList code
This CL combines some ComboBox with ListBox code to remove duplication when dealing with choice lists. Change-Id: I735b6596c67aaf80ab96573af5c8d81e7875c27c Reviewed-on: https://pdfium-review.googlesource.com/24551 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r--fpdfsdk/cpdfsdk_widget.cpp55
-rw-r--r--xfa/fxfa/parser/cxfa_node.h2
2 files changed, 17 insertions, 40 deletions
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp
index 8243d31383..429391cf38 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -304,25 +304,17 @@ void CPDFSDK_Widget::Synchronize(bool bSynchronizeElse) {
case FormFieldType::kTextField:
node->SetValue(XFA_VALUEPICTURE_Edit, pFormField->GetValue());
break;
+ case FormFieldType::kComboBox:
case FormFieldType::kListBox: {
node->ClearAllSelections();
- for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
- int nIndex = pFormField->GetSelectedIndex(i);
- if (nIndex > -1 && nIndex < node->CountChoiceListItems(false))
- node->SetItemState(nIndex, true, false, false, true);
- }
- break;
- }
- case FormFieldType::kComboBox: {
- node->ClearAllSelections();
-
- for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
+ for (int i = 0; i < pFormField->CountSelectedItems(); ++i) {
int nIndex = pFormField->GetSelectedIndex(i);
if (nIndex > -1 && nIndex < node->CountChoiceListItems(false))
node->SetItemState(nIndex, true, false, false, true);
}
- node->SetValue(XFA_VALUEPICTURE_Edit, pFormField->GetValue());
+ if (GetFieldType() == FormFieldType::kComboBox)
+ node->SetValue(XFA_VALUEPICTURE_Edit, pFormField->GetValue());
break;
}
default:
@@ -431,37 +423,22 @@ void CPDFSDK_Widget::SynchronizeXFAItems(CXFA_FFDocView* pXFADocView,
CPDF_FormControl* pFormControl) {
ASSERT(hWidget);
- CXFA_Node* node = hWidget->GetNode();
- switch (pFormField->GetFieldType()) {
- case FormFieldType::kListBox: {
- pFormField->ClearSelection(false);
- pFormField->ClearOptions(true);
-
- if (node->IsWidgetReady()) {
- for (int i = 0, sz = node->CountChoiceListItems(false); i < sz; i++) {
- pFormField->InsertOption(
- node->GetChoiceListItem(i, false).value_or(L""), i, true);
- }
- }
- break;
- }
- case FormFieldType::kComboBox: {
- pFormField->ClearSelection(false);
- pFormField->ClearOptions(false);
+ FormFieldType type = pFormField->GetFieldType();
+ if (type != FormFieldType::kComboBox && type != FormFieldType::kListBox)
+ return;
- if (node->IsWidgetReady()) {
- for (int i = 0, sz = node->CountChoiceListItems(false); i < sz; i++) {
- pFormField->InsertOption(
- node->GetChoiceListItem(i, false).value_or(L""), i, false);
- }
- }
+ CXFA_Node* node = hWidget->GetNode();
+ pFormField->ClearSelection(false);
+ pFormField->ClearOptions(type == FormFieldType::kListBox);
- pFormField->SetValue(L"", true);
- break;
+ if (node->IsWidgetReady()) {
+ for (int i = 0; i < node->CountChoiceListItems(false); ++i) {
+ pFormField->InsertOption(node->GetChoiceListItem(i, false).value_or(L""),
+ i, type == FormFieldType::kListBox);
}
- default:
- break;
}
+ if (pFormField->GetFieldType() == FormFieldType::kComboBox)
+ pFormField->SetValue(L"", true);
}
#endif // PDF_ENABLE_XFA
diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h
index 130422e59c..87f5a475bd 100644
--- a/xfa/fxfa/parser/cxfa_node.h
+++ b/xfa/fxfa/parser/cxfa_node.h
@@ -312,7 +312,6 @@ class CXFA_Node : public CXFA_Object {
bool IsListBox();
bool IsAllowNeutral();
bool IsRadioButton();
- bool IsChoiceListAllowTextEntry();
bool IsMultiLine();
XFA_AttributeEnum GetButtonHighlight();
@@ -336,6 +335,7 @@ class CXFA_Node : public CXFA_Object {
CXFA_Node* GetExclGroupFirstMember();
CXFA_Node* GetExclGroupNextMember(CXFA_Node* pNode);
+ bool IsChoiceListAllowTextEntry();
int32_t CountChoiceListItems(bool bSaveValue);
Optional<WideString> GetChoiceListItem(int32_t nIndex, bool bSaveValue);
bool IsChoiceListMultiSelect();