diff options
-rw-r--r-- | fpdfsdk/cpdfsdk_widget.cpp | 55 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.h | 2 |
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(); |