summaryrefslogtreecommitdiff
path: root/xfa/fxfa/app/xfa_ffchoicelist.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxfa/app/xfa_ffchoicelist.cpp')
-rw-r--r--xfa/fxfa/app/xfa_ffchoicelist.cpp105
1 files changed, 45 insertions, 60 deletions
diff --git a/xfa/fxfa/app/xfa_ffchoicelist.cpp b/xfa/fxfa/app/xfa_ffchoicelist.cpp
index 460964532e..c628d2e47f 100644
--- a/xfa/fxfa/app/xfa_ffchoicelist.cpp
+++ b/xfa/fxfa/app/xfa_ffchoicelist.cpp
@@ -6,6 +6,7 @@
#include "xfa/fxfa/app/xfa_ffchoicelist.h"
+#include <algorithm>
#include <vector>
#include "third_party/base/ptr_util.h"
@@ -52,25 +53,18 @@ bool CXFA_FFListBox::LoadWidget() {
m_pNormalWidget->SetDelegate(this);
m_pNormalWidget->LockUpdate();
- std::vector<CFX_WideString> wsLabelArray;
- m_pDataAcc->GetChoiceListItems(wsLabelArray, false);
- int32_t iItems = pdfium::CollectionSize<int32_t>(wsLabelArray);
- for (int32_t i = 0; i < iItems; i++) {
- pListBox->AddString(wsLabelArray[i].AsStringC());
- }
+ for (const auto& label : m_pDataAcc->GetChoiceListItems(false))
+ pListBox->AddString(label.AsStringC());
+
uint32_t dwExtendedStyle = FWL_STYLEEXT_LTB_ShowScrollBarFocus;
- if (m_pDataAcc->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) {
+ if (m_pDataAcc->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect)
dwExtendedStyle |= FWL_STYLEEXT_LTB_MultiSelection;
- }
+
dwExtendedStyle |= GetAlignment();
m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF);
- CFX_ArrayTemplate<int32_t> iSelArray;
- m_pDataAcc->GetSelectedItems(iSelArray);
- int32_t iSelCount = iSelArray.GetSize();
- for (int32_t j = 0; j < iSelCount; j++) {
- CFWL_ListItem* item = pListBox->GetItem(nullptr, iSelArray[j]);
- pListBox->SetSelItem(item, true);
- }
+ for (int32_t selected : m_pDataAcc->GetSelectedItems())
+ pListBox->SetSelItem(pListBox->GetItem(nullptr, selected), true);
+
m_pNormalWidget->UnlockUpdate();
return CXFA_FFField::LoadWidget();
}
@@ -84,19 +78,18 @@ bool CXFA_FFListBox::OnKillFocus(CXFA_FFWidget* pNewFocus) {
bool CXFA_FFListBox::CommitData() {
CFWL_ListBox* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget);
+ std::vector<int32_t> iSelArray;
int32_t iSels = pListBox->CountSelItems();
- CFX_ArrayTemplate<int32_t> iSelArray;
for (int32_t i = 0; i < iSels; ++i)
- iSelArray.Add(pListBox->GetSelIndex(i));
+ iSelArray.push_back(pListBox->GetSelIndex(i));
m_pDataAcc->SetSelectedItems(iSelArray, true, false, true);
return true;
}
bool CXFA_FFListBox::IsDataChanged() {
- CFX_ArrayTemplate<int32_t> iSelArray;
- m_pDataAcc->GetSelectedItems(iSelArray);
- int32_t iOldSels = iSelArray.GetSize();
- CFWL_ListBox* pListBox = (CFWL_ListBox*)m_pNormalWidget;
+ std::vector<int32_t> iSelArray = m_pDataAcc->GetSelectedItems();
+ int32_t iOldSels = pdfium::CollectionSize<int32_t>(iSelArray);
+ auto* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget);
int32_t iSels = pListBox->CountSelItems();
if (iOldSels != iSels)
return true;
@@ -134,28 +127,24 @@ uint32_t CXFA_FFListBox::GetAlignment() {
return dwExtendedStyle;
}
bool CXFA_FFListBox::UpdateFWLData() {
- if (!m_pNormalWidget) {
+ if (!m_pNormalWidget)
return false;
- }
- CFWL_ListBox* pListBox = ((CFWL_ListBox*)m_pNormalWidget);
- CFX_ArrayTemplate<CFWL_ListItem*> selItemArray;
- CFX_ArrayTemplate<int32_t> iSelArray;
- m_pDataAcc->GetSelectedItems(iSelArray);
- int32_t iSelCount = iSelArray.GetSize();
- for (int32_t j = 0; j < iSelCount; j++) {
- CFWL_ListItem* lpItemSel = pListBox->GetSelItem(iSelArray[j]);
- selItemArray.Add(lpItemSel);
- }
+
+ auto* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget);
+ std::vector<int32_t> iSelArray = m_pDataAcc->GetSelectedItems();
+ std::vector<CFWL_ListItem*> selItemArray(iSelArray.size());
+ std::transform(iSelArray.begin(), iSelArray.end(), selItemArray.begin(),
+ [pListBox](int32_t val) { return pListBox->GetSelItem(val); });
+
pListBox->SetSelItem(pListBox->GetSelItem(-1), false);
- for (int32_t i = 0; i < iSelCount; i++) {
- ((CFWL_ListBox*)m_pNormalWidget)->SetSelItem(selItemArray[i], true);
- }
+ for (CFWL_ListItem* pItem : selItemArray)
+ pListBox->SetSelItem(pItem, true);
+
m_pNormalWidget->Update();
return true;
}
-void CXFA_FFListBox::OnSelectChanged(
- CFWL_Widget* pWidget,
- const CFX_ArrayTemplate<int32_t>& arrSels) {
+void CXFA_FFListBox::OnSelectChanged(CFWL_Widget* pWidget,
+ const std::vector<int32_t>& arrSels) {
CXFA_EventParam eParam;
eParam.m_eType = XFA_EVENT_Change;
eParam.m_pTarget = m_pDataAcc;
@@ -201,7 +190,7 @@ void CXFA_FFListBox::OnProcessEvent(CFWL_Event* pEvent) {
CXFA_FFField::OnProcessEvent(pEvent);
switch (pEvent->GetType()) {
case CFWL_Event::Type::SelectChanged: {
- CFX_ArrayTemplate<int32_t> arrSels;
+ std::vector<int32_t> arrSels;
OnSelectChanged(m_pNormalWidget, arrSels);
break;
}
@@ -244,17 +233,12 @@ bool CXFA_FFComboBox::LoadWidget() {
m_pNormalWidget->SetDelegate(this);
m_pNormalWidget->LockUpdate();
- std::vector<CFX_WideString> wsLabelArray;
- m_pDataAcc->GetChoiceListItems(wsLabelArray, false);
- int32_t iItems = pdfium::CollectionSize<int32_t>(wsLabelArray);
- for (int32_t i = 0; i < iItems; i++) {
- pComboBox->AddString(wsLabelArray[i].AsStringC());
- }
- CFX_ArrayTemplate<int32_t> iSelArray;
- m_pDataAcc->GetSelectedItems(iSelArray);
- int32_t iSelCount = iSelArray.GetSize();
- if (iSelCount > 0) {
- pComboBox->SetCurSel(iSelArray[0]);
+ for (const auto& label : m_pDataAcc->GetChoiceListItems(false))
+ pComboBox->AddString(label.AsStringC());
+
+ std::vector<int32_t> iSelArray = m_pDataAcc->GetSelectedItems();
+ if (!iSelArray.empty()) {
+ pComboBox->SetCurSel(iSelArray.front());
} else {
CFX_WideString wsText;
m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Raw);
@@ -375,24 +359,25 @@ uint32_t CXFA_FFComboBox::GetAlignment() {
}
return dwExtendedStyle;
}
+
bool CXFA_FFComboBox::UpdateFWLData() {
- if (!m_pNormalWidget) {
+ auto* pComboBox = static_cast<CFWL_ComboBox*>(m_pNormalWidget);
+ if (!pComboBox)
return false;
- }
- CFX_ArrayTemplate<int32_t> iSelArray;
- m_pDataAcc->GetSelectedItems(iSelArray);
- int32_t iSelCount = iSelArray.GetSize();
- if (iSelCount > 0) {
- ((CFWL_ComboBox*)m_pNormalWidget)->SetCurSel(iSelArray[0]);
+
+ std::vector<int32_t> iSelArray = m_pDataAcc->GetSelectedItems();
+ if (!iSelArray.empty()) {
+ pComboBox->SetCurSel(iSelArray.front());
} else {
CFX_WideString wsText;
- ((CFWL_ComboBox*)m_pNormalWidget)->SetCurSel(-1);
+ pComboBox->SetCurSel(-1);
m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Raw);
- ((CFWL_ComboBox*)m_pNormalWidget)->SetEditText(wsText);
+ pComboBox->SetEditText(wsText);
}
- m_pNormalWidget->Update();
+ pComboBox->Update();
return true;
}
+
bool CXFA_FFComboBox::CanUndo() {
return m_pDataAcc->IsChoiceListAllowTextEntry() &&
((CFWL_ComboBox*)m_pNormalWidget)->EditCanUndo();