7#include "fpdfsdk/formfiller/cffl_listbox.h"
11#include "constants/form_flags.h"
12#include "core/fpdfdoc/cpdf_bafontmap.h"
13#include "fpdfsdk/cpdfsdk_widget.h"
14#include "fpdfsdk/formfiller/cffl_interactiveformfiller.h"
15#include "fpdfsdk/formfiller/cffl_perwindowdata.h"
16#include "fpdfsdk/pwl/cpwl_list_box.h"
17#include "third_party/base/containers/contains.h"
20 CPDFSDK_Widget* pWidget)
27 uint32_t dwFieldFlag = m_pWidget->GetFieldFlags();
34 constexpr float kDefaultListBoxFontSize = 12.0f;
44 std::unique_ptr<IPWL_FillerNotify::PerWindowData> pAttachedData) {
45 static_cast<CFFL_PerWindowData*>(pAttachedData.get())
->SetFormField(
this);
49 for (int32_t i = 0, sz = m_pWidget->CountOptions(); i < sz; i++)
50 pWnd->AddString(m_pWidget->GetOptionLabel(i));
53 m_OriginSelections.clear();
55 bool bSetCaret =
false;
56 for (int32_t i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) {
57 if (m_pWidget->IsOptionSelected(i)) {
63 m_OriginSelections.insert(i);
67 for (
int i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) {
68 if (m_pWidget->IsOptionSelected(i)) {
75 pWnd->SetTopVisibleIndex(m_pWidget->GetTopVisibleIndex());
76 return std::move(pWnd);
79bool CFFL_ListBox::
OnChar(CPDFSDK_Widget* pWidget,
81 Mask<FWL_EVENTFLAG> nFlags) {
90 if (m_pWidget->GetFieldFlags() & pdfium::form_flags::kChoiceMultiSelect) {
92 for (int32_t i = 0, sz = pListBox
->GetCount(); i < sz; ++i) {
94 if (!pdfium::Contains(m_OriginSelections, i))
101 return nSelCount != m_OriginSelections.size();
103 return pListBox->GetCurSel() != m_pWidget->GetSelectedIndex(0);
106void CFFL_ListBox::
SaveData(
const CPDFSDK_PageView* pPageView) {
113 m_pWidget->ClearSelection();
117 if (m_pWidget->GetFieldFlags() & pdfium::form_flags::kChoiceMultiSelect) {
118 for (int32_t i = 0, sz = pListBox
->GetCount(); i < sz; i++) {
120 m_pWidget->SetOptionSelection(i);
127 m_pWidget->SetOptionSelection(pListBox->GetCurSel());
132 ObservedPtr<CPDFSDK_Widget> observed_widget(m_pWidget);
133 ObservedPtr<CFFL_ListBox> observed_this(
this);
134 m_pWidget->SetTopVisibleIndex(nNewTopIndex);
135 if (!observed_widget) {
138 m_pWidget->ResetFieldAppearance();
139 if (!observed_widget) {
142 m_pWidget->UpdateField();
143 if (!observed_widget || !observed_this) {
154 if (m_pWidget->GetFieldFlags() & pdfium::form_flags::kChoiceMultiSelect) {
161 fa.sValue = m_pWidget->GetOptionLabel(nCurSel);
167 if (m_pWidget->GetFieldFlags() & pdfium::form_flags::kChoiceMultiSelect) {
170 int32_t nCurSel = m_pWidget->GetSelectedIndex(0);
172 fa.sValue = m_pWidget->GetOptionLabel(nCurSel);
185 for (int32_t i = 0, sz = pListBox
->GetCount(); i < sz; i++) {
186 if (pListBox->IsItemSelected(i))
187 m_State.push_back(i);
192 const CPDFSDK_PageView* pPageView) {
193 CPWL_ListBox* pListBox = CreateOrUpdatePWLListBox(pPageView);
197 for (
const auto& item : m_State)
198 pListBox->Select(item);
205 if (index < 0 || index >= m_pWidget->CountOptions())
227 if (index < 0 || index >= m_pWidget->CountOptions())
235 const CPDFSDK_PageView* pPageView)
const {
240 const CPDFSDK_PageView* pPageView) {
bool IsDataChanged(const CPDFSDK_PageView *pPageView) override
CFFL_ListBox(CFFL_InteractiveFormFiller *pFormFiller, CPDFSDK_Widget *pWidget)
void GetActionData(const CPDFSDK_PageView *pPageView, CPDF_AAction::AActionType type, CFFL_FieldAction &fa) override
bool SetIndexSelected(int index, bool selected) override
void SavePWLWindowState(const CPDFSDK_PageView *pPageView) override
std::unique_ptr< CPWL_Wnd > NewPWLWindow(const CPWL_Wnd::CreateParams &cp, std::unique_ptr< IPWL_FillerNotify::PerWindowData > pAttachedData) override
void SaveData(const CPDFSDK_PageView *pPageView) override
bool IsIndexSelected(int index) override
bool OnChar(CPDFSDK_Widget *pWidget, uint32_t nChar, Mask< FWL_EVENTFLAG > nFlags) override
void RecreatePWLWindowFromSavedState(const CPDFSDK_PageView *pPageView) override
CPWL_Wnd::CreateParams GetCreateParam() override
void SetFormField(CFFL_FormField *pFormField)
CPDF_BAFontMap * GetOrCreateFontMap()
CFFL_TextObject(CFFL_InteractiveFormFiller *pFormFiller, CPDFSDK_Widget *pWidget)
int32_t GetCurSel() const
void Deselect(int32_t nItemIndex)
void Select(int32_t nItemIndex)
int32_t GetTopVisibleIndex() const
void SetCaret(int32_t nItemIndex)
bool IsItemSelected(int32_t nItemIndex) const