7#include "xfa/fxfa/cxfa_ffcombobox.h"
12#include "third_party/base/check.h"
13#include "v8/include/cppgc/visitor.h"
14#include "xfa/fwl/cfwl_combobox.h"
15#include "xfa/fwl/cfwl_eventselectchanged.h"
16#include "xfa/fwl/cfwl_notedriver.h"
17#include "xfa/fxfa/cxfa_eventparam.h"
18#include "xfa/fxfa/cxfa_ffdocview.h"
19#include "xfa/fxfa/parser/cxfa_para.h"
24 return static_cast<CFWL_ComboBox*>(widget);
27const CFWL_ComboBox* ToComboBox(
const CFWL_Widget* widget) {
28 return static_cast<
const CFWL_ComboBox*>(widget);
37void CXFA_FFComboBox::Trace(
cppgc::Visitor* visitor)
const {
38 CXFA_FFDropDown::Trace(visitor);
39 visitor->Trace(m_pOldDelegate);
53 auto* pComboBox = ToComboBox(GetNormalWidget());
54 return pComboBox && pComboBox->GetBBox().Contains(point);
60 CFWL_ComboBox* pComboBox = cppgc::MakeGarbageCollected<CFWL_ComboBox>(
61 GetFWLApp()->GetHeap()->GetAllocationHandle(), GetFWLApp());
65 CFWL_NoteDriver* pNoteDriver = pComboBox
->GetFWLApp()->GetNoteDriver();
67 m_pOldDelegate = pComboBox->GetDelegate();
72 for (
const auto& label : m_pNode->GetChoiceListItems(
false))
73 pComboBox->AddString(label);
75 std::vector<int32_t> iSelArray = m_pNode->GetSelectedItems();
76 if (iSelArray.empty())
77 pComboBox->SetEditText(m_pNode->GetValue(XFA_ValuePicture::kRaw));
88 auto* pComboBox = ToComboBox(GetNormalWidget());
92 uint32_t dwExtendedStyle = 0;
95 if (m_pNode->IsChoiceListAllowTextEntry()) {
99 if (!m_pNode->IsOpenAccess() || !GetDoc()->GetXFADoc()->IsInteractive()) {
103 dwExtendedStyle |= GetAlignment();
104 GetNormalWidget()->ModifyStyleExts(dwExtendedStyle, 0xFFFFFFFF);
106 if (!m_pNode->IsHorizontalScrollPolicyOff())
109 pComboBox->EditModifyStyleExts(dwEditStyles, 0xFFFFFFFF);
113 const CFX_PointF& point) {
117 GetDoc()->PopupMenu(
this, point);
129 ToComboBox(GetNormalWidget())->ShowDropDownList();
133 return m_pNode->SetValue(XFA_ValuePicture::kRaw, m_wsNewValue);
137 WideString wsText = GetCurrentText();
138 if (m_pNode->GetValue(XFA_ValuePicture::kRaw) == wsText)
141 m_wsNewValue = std::move(wsText);
147 pParam->m_wsPrevText = ToComboBox(GetNormalWidget())->GetEditText();
148 m_pNode->ProcessEvent(GetDocView(), XFA_AttributeValue::Change, pParam);
151WideString CXFA_FFComboBox::GetCurrentText()
const {
152 auto* pFWLcombobox = ToComboBox(GetNormalWidget());
153 WideString wsText = pFWLcombobox->GetEditText();
154 int32_t iCursel = pFWLcombobox->GetCurSel();
156 WideString wsSel = pFWLcombobox->GetTextByIndex(iCursel);
158 wsText = m_pNode->GetChoiceListItem(iCursel,
true).value_or(L"");
163uint32_t CXFA_FFComboBox::GetAlignment() {
164 CXFA_Para* para = m_pNode->GetParaIfExists();
168 uint32_t dwExtendedStyle = 0;
200 return dwExtendedStyle;
204 auto* pComboBox = ToComboBox(GetNormalWidget());
208 std::vector<int32_t> iSelArray = m_pNode->GetSelectedItems();
209 if (!iSelArray.empty()) {
210 pComboBox->SetCurSel(iSelArray.front());
212 pComboBox->SetCurSel(-1);
213 pComboBox->SetEditText(m_pNode->GetValue(XFA_ValuePicture::kRaw));
220 return m_pNode->IsChoiceListAllowTextEntry() &&
221 ToComboBox(GetNormalWidget())->EditCanUndo();
225 return m_pNode->IsChoiceListAllowTextEntry() &&
226 ToComboBox(GetNormalWidget())->EditCanRedo();
230 return ToComboBox(GetNormalWidget())->EditCanCopy();
234 return m_pNode->IsOpenAccess() && m_pNode->IsChoiceListAllowTextEntry() &&
235 ToComboBox(GetNormalWidget())->EditCanCut();
239 return m_pNode->IsChoiceListAllowTextEntry() && m_pNode->IsOpenAccess();
243 return ToComboBox(GetNormalWidget())->EditCanSelectAll();
247 return m_pNode->IsChoiceListAllowTextEntry() &&
248 ToComboBox(GetNormalWidget())->EditUndo();
252 return m_pNode->IsChoiceListAllowTextEntry() &&
253 ToComboBox(GetNormalWidget())->EditRedo();
257 return ToComboBox(GetNormalWidget())->EditCopy();
261 if (!m_pNode->IsChoiceListAllowTextEntry())
262 return absl::nullopt;
264 return ToComboBox(GetNormalWidget())->EditCut();
267bool CXFA_FFComboBox::
Paste(
const WideString& wsPaste) {
268 return m_pNode->IsChoiceListAllowTextEntry() &&
269 ToComboBox(GetNormalWidget())->EditPaste(wsPaste);
273 ToComboBox(GetNormalWidget())->EditSelectAll();
277 ToComboBox(GetNormalWidget())->EditDelete();
281 ToComboBox(GetNormalWidget())->EditDeSelect();
285 return GetCurrentText();
289 return FormFieldType::kXFA_ComboBox;
293 ToComboBox(GetNormalWidget())->SetCurSel(bSelected ? nIndex : -1);
294 GetNormalWidget()->Update();
298void CXFA_FFComboBox::
InsertItem(
const WideString& wsLabel, int32_t nIndex) {
299 ToComboBox(GetNormalWidget())->AddString(wsLabel);
300 GetNormalWidget()->Update();
306 ToComboBox(GetNormalWidget())->RemoveAll();
308 ToComboBox(GetNormalWidget())->RemoveAt(nIndex);
310 GetNormalWidget()->Update();
315 const WideString& wsChanged) {
317 eParam.m_wsPrevText = m_pNode->GetValue(XFA_ValuePicture::kRaw);
318 eParam.m_wsChange = wsChanged;
319 FWLEventSelChange(&eParam);
324 eParam.m_wsPrevText = m_pNode->GetValue(XFA_ValuePicture::kRaw);
325 FWLEventSelChange(&eParam);
326 if (m_pNode->IsChoiceListCommitOnSelect() && bLButtonUp)
327 m_pDocView->SetFocusNode(
nullptr);
332 m_pNode->ProcessEvent(GetDocView(), XFA_AttributeValue::PreOpen, &eParam);
337 m_pNode->ProcessEvent(GetDocView(), XFA_AttributeValue::PostOpen, &eParam);
341 m_pOldDelegate->OnProcessMessage(pMessage);
348 auto* postEvent =
static_cast<CFWL_EventSelectChanged*>(pEvent);
353 WideString wsChanged;
368 m_pOldDelegate->OnProcessEvent(pEvent);
373 m_pOldDelegate->OnDrawWidget(pGraphics, matrix);
#define FWL_STYLEEXT_CMB_ListItemLeftAlign
#define FWL_STYLEEXT_CMB_EditVCenter
#define FWL_STYLEEXT_CMB_EditVFar
#define FWL_STYLEEXT_CMB_DropDown
#define FWL_STYLEEXT_CMB_ListItemCenterAlign
#define FWL_STYLEEXT_CMB_EditVNear
#define FWL_STYLEEXT_CMB_EditHNear
#define FWL_STYLEEXT_CMB_EditHCenter
#define FWL_STYLEEXT_CMB_ReadOnly
#define FWL_STYLEEXT_CMB_EditJustified
#define FWL_STYLEEXT_EDT_AutoHScroll
#define FWL_STYLEEXT_EDT_ReadOnly
void SetCurSel(int32_t iSel)
bool GetLButtonUp() const
void RegisterEventTarget(CFWL_Widget *pListener, CFWL_Widget *pEventSource)
constexpr CFX_RectF()=default
CXFA_EventParam(XFA_EVENTTYPE type)
void OnPostOpen(CFWL_Widget *pWidget)
void DeleteItem(int32_t nIndex) override
bool PtInActiveRect(const CFX_PointF &point) override
bool LoadWidget() override
bool OnKillFocus(CXFA_FFWidget *pNewWidget) override
void OnPreOpen(CFWL_Widget *pWidget)
void UpdateWidgetProperty() override
void OnProcessEvent(CFWL_Event *pEvent) override
void OnSelectChanged(CFWL_Widget *pWidget, bool bLButtonUp)
bool Paste(const WideString &wsPaste) override
bool OnRButtonUp(Mask< XFA_FWL_KeyFlag > dwFlags, const CFX_PointF &point) override
bool UpdateFWLData() override
CFX_RectF GetBBox(FocusOption focus) override
void SetItemState(int32_t nIndex, bool bSelected)
bool CanSelectAll() override
void OnTextChanged(CFWL_Widget *pWidget, const WideString &wsChanged)
FormFieldType GetFormFieldType() override
void OnDrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
~CXFA_FFComboBox() override
void OnProcessMessage(CFWL_Message *pMessage) override
bool IsDataChanged() override
absl::optional< WideString > Cut() override
CXFA_FFComboBox * AsComboBox() override
absl::optional< WideString > Copy() override
bool CommitData() override
void InsertItem(const WideString &wsLabel, int32_t nIndex) override
WideString GetText() override
void SelectAll() override
CXFA_FFDropDown(CXFA_Node *pNode)
bool OnKillFocus(CXFA_FFWidget *pNewWidget) override
bool ProcessCommittedData()
bool LoadWidget() override
bool OnRButtonUp(Mask< XFA_FWL_KeyFlag > dwFlags, const CFX_PointF &point) override
void SetNormalWidget(CFWL_Widget *widget)
void OnProcessEvent(CFWL_Event *pEvent) override
uint32_t UpdateUIProperty()
XFA_AttributeValue GetHorizontalAlign()
XFA_AttributeValue GetVerticalAlign()