diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2018-01-29 22:21:36 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-01-29 22:21:36 +0000 |
commit | 95b232f791231a0db0de780b568a0825a2e6e989 (patch) | |
tree | 951a11b9c846f4108c28ed8361a35f59f2b1829f /fpdfsdk | |
parent | 8308b8c3dfad425942d4aba19a6b85049beff6f4 (diff) | |
download | pdfium-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>
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/cpdfsdk_widget.cpp | 55 |
1 files changed, 16 insertions, 39 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 |