summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/cpdfsdk_widget.cpp55
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