7#include "fpdfsdk/formfiller/cffl_combobox.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_combo_box.h"
17#include "fpdfsdk/pwl/cpwl_edit.h"
20 CPDFSDK_Widget* pWidget)
32 if (m_pWidget->GetFieldFlags() & pdfium::form_flags::kChoiceEdit)
41 std::unique_ptr<IPWL_FillerNotify::PerWindowData> pAttachedData) {
42 static_cast<CFFL_PerWindowData*>(pAttachedData.get())
->SetFormField(
this);
43 auto pWnd =
std::make_unique<CPWL_ComboBox>(cp,
std::move(pAttachedData));
46 int32_t nCurSel = m_pWidget->GetSelectedIndex(0);
49 swText = m_pWidget->GetValue();
51 swText = m_pWidget->GetOptionLabel(nCurSel);
53 for (int32_t i = 0, sz = m_pWidget->CountOptions(); i < sz; i++)
54 pWnd->AddString(m_pWidget->GetOptionLabel(i));
56 pWnd->SetSelect(nCurSel);
57 pWnd->SetText(swText);
58 return std::move(pWnd);
61bool CFFL_ComboBox::
OnChar(CPDFSDK_Widget* pWidget,
63 Mask<FWL_EVENTFLAG> nFlags) {
68 auto* pWnd = GetPWLComboBox(pPageView);
73 if (!(m_pWidget->GetFieldFlags() & pdfium::form_flags::kChoiceEdit))
74 return nCurSel != m_pWidget->GetSelectedIndex(0);
77 return nCurSel != m_pWidget->GetSelectedIndex(0);
79 return pWnd->GetText() != m_pWidget->GetValue();
82void CFFL_ComboBox::
SaveData(
const CPDFSDK_PageView* pPageView) {
83 CPWL_ComboBox* pWnd = GetPWLComboBox(pPageView);
89 bool bSetValue =
false;
90 if (m_pWidget->GetFieldFlags() & pdfium::form_flags::kChoiceEdit)
91 bSetValue = (nCurSel < 0) || (swText != m_pWidget->GetOptionLabel(nCurSel));
94 m_pWidget->SetValue(swText);
96 m_pWidget->GetSelectedIndex(0);
97 m_pWidget->SetOptionSelection(nCurSel);
99 ObservedPtr<CPDFSDK_Widget> observed_widget(m_pWidget);
100 ObservedPtr<CFFL_ComboBox> observed_this(
this);
101 m_pWidget->ResetFieldAppearance();
102 if (!observed_widget)
105 m_pWidget->UpdateField();
106 if (!observed_widget || !observed_this)
117 if (CPWL_ComboBox* pComboBox = GetPWLComboBox(pPageView)) {
122 fa.sChangeEx = GetSelectExportText();
126 fa.sChangeEx.clear();
132 if (CPWL_ComboBox* pComboBox = GetPWLComboBox(pPageView)) {
138 case CPDF_AAction::kLoseFocus:
139 case CPDF_AAction::kGetFocus:
140 fa.sValue = m_pWidget->GetValue();
152 if (CPWL_ComboBox* pComboBox = GetPWLComboBox(pPageView)) {
165 CPWL_ComboBox* pComboBox = GetPWLComboBox(pPageView);
169 m_State.nIndex = pComboBox->GetSelect();
175 std::tie(m_State.nStart, m_State.nEnd) = pEdit->GetSelection();
176 m_State.sValue = pEdit->GetText();
180 const CPDFSDK_PageView* pPageView) {
181 CPWL_ComboBox* pComboBox = CreateOrUpdatePWLComboBox(pPageView);
185 if (m_State.nIndex >= 0) {
186 pComboBox->SetSelect(m_State.nIndex);
194 pEdit->SetText(m_State.sValue);
195 pEdit->SetSelection(m_State.nStart, m_State.nEnd);
202 if (index < 0 || index >= m_pWidget->CountOptions())
217 if (index < 0 || index >= m_pWidget->CountOptions())
225bool CFFL_ComboBox::IsFieldFull(
const CPDFSDK_PageView* pPageView) {
226 CPWL_ComboBox* pComboBox = GetPWLComboBox(pPageView);
230 CPWL_Edit* pEdit = pComboBox->GetEdit();
231 return pEdit && pEdit->IsTextFull();
238 m_pFormFiller->OnSetFieldInputFocus(pEdit->GetText());
241WideString CFFL_ComboBox::GetSelectExportText() {
244 return m_pWidget->GetSelectExportText(nExport);
247CPWL_ComboBox* CFFL_ComboBox::GetPWLComboBox(
248 const CPDFSDK_PageView* pPageView)
const {
249 return static_cast<CPWL_ComboBox*>(
GetPWLWindow(pPageView));
252CPWL_ComboBox* CFFL_ComboBox::CreateOrUpdatePWLComboBox(
253 const CPDFSDK_PageView* pPageView) {
bool OnChar(CPDFSDK_Widget *pWidget, uint32_t nChar, Mask< FWL_EVENTFLAG > nFlags) override
void SavePWLWindowState(const CPDFSDK_PageView *pPageView) override
void SaveData(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 RecreatePWLWindowFromSavedState(const CPDFSDK_PageView *pPageView) override
void GetActionData(const CPDFSDK_PageView *pPageView, CPDF_AAction::AActionType type, CFFL_FieldAction &fa) override
bool IsDataChanged(const CPDFSDK_PageView *pPageView) override
~CFFL_ComboBox() override
CPWL_Wnd::CreateParams GetCreateParam() override
CFFL_ComboBox(CFFL_InteractiveFormFiller *pFormFiller, CPDFSDK_Widget *pWidget)
void SetActionData(const CPDFSDK_PageView *pPageView, CPDF_AAction::AActionType type, const CFFL_FieldAction &fa) override
bool IsIndexSelected(int index) override
bool SetIndexSelected(int index, bool selected) override
void OnSetFocusForEdit(CPWL_Edit *pEdit) override
void SetFormField(CFFL_FormField *pFormField)
CPDF_BAFontMap * GetOrCreateFontMap()
CFFL_TextObject(CFFL_InteractiveFormFiller *pFormFiller, CPDFSDK_Widget *pWidget)
void SetSelect(int32_t nItemIndex)
int32_t GetSelect() const
WideString GetText() override
CPWL_Edit * GetEdit() const
WideString GetText() override
void SetCharSet(FX_Charset nCharSet)
void SetSelection(int32_t nStartChar, int32_t nEndChar)
std::pair< int32_t, int32_t > GetSelection() const
void ReplaceSelection(const WideString &text) override
#define PCBS_ALLOWCUSTOMTEXT