7#include "xfa/fwl/cfwl_combobox.h"
9#include "v8/include/cppgc/visitor.h"
10#include "xfa/fde/cfde_texteditengine.h"
11#include "xfa/fde/cfde_textout.h"
12#include "xfa/fwl/cfwl_app.h"
13#include "xfa/fwl/cfwl_event.h"
14#include "xfa/fwl/cfwl_eventselectchanged.h"
15#include "xfa/fwl/cfwl_listbox.h"
16#include "xfa/fwl/cfwl_messagekey.h"
17#include "xfa/fwl/cfwl_messagekillfocus.h"
18#include "xfa/fwl/cfwl_messagemouse.h"
19#include "xfa/fwl/cfwl_messagesetfocus.h"
20#include "xfa/fwl/cfwl_notedriver.h"
21#include "xfa/fwl/cfwl_themebackground.h"
22#include "xfa/fwl/cfwl_themepart.h"
23#include "xfa/fwl/cfwl_themetext.h"
24#include "xfa/fwl/cfwl_widgetmgr.h"
25#include "xfa/fwl/fwl_widgetdef.h"
26#include "xfa/fwl/ifwl_themeprovider.h"
28CFWL_ComboBox::CFWL_ComboBox(CFWL_App* app)
30 m_pEdit(cppgc::MakeGarbageCollected<CFWL_ComboEdit>(
31 app->GetHeap()->GetAllocationHandle(),
35 m_pListBox(cppgc::MakeGarbageCollected<CFWL_ComboList>(
36 app->GetHeap()->GetAllocationHandle(),
44void CFWL_ComboBox::
Trace(cppgc::Visitor* visitor)
const {
45 CFWL_Widget::Trace(visitor);
46 visitor->Trace(m_pEdit);
47 visitor->Trace(m_pListBox);
54void CFWL_ComboBox::
AddString(
const WideString& wsText) {
55 m_pListBox->AddString(wsText);
59 m_pListBox->RemoveAt(iIndex);
63 m_pListBox->DeleteAll();
67 uint32_t dwStyleExtsRemoved) {
74 else if (bDelDropDown)
96 if (IsDropListVisible()) {
97 rect = m_pListBox->GetWidgetRect();
111 param.m_dwStates = m_iBtnState;
116 CFX_RectF rtEdit = m_pEdit->GetWidgetRect();
119 m_pEdit->DrawWidget(pGraphics, mt);
121 if (m_pListBox && IsDropListVisible()) {
122 CFX_RectF rtList = m_pListBox->GetWidgetRect();
125 m_pListBox->DrawWidget(pGraphics, mt);
135 int32_t iCount = m_pListBox->CountItems(
nullptr);
136 bool bClearSel = iSel < 0 || iSel >= iCount;
137 if (IsDropDownStyle() && m_pEdit) {
139 m_pEdit->SetText(WideString());
142 m_pEdit->SetText(hItem ? hItem->GetText() : WideString());
146 m_iCurSel = bClearSel ? -1 : iSel;
150 if (IsDropDownStyle() && m_pEdit)
151 m_pEdit->SetStates(dwStates);
153 m_pListBox->SetStates(dwStates);
158 if (IsDropDownStyle() && m_pEdit)
159 m_pEdit->RemoveStates(dwStates);
161 m_pListBox->RemoveStates(dwStates);
169 m_pEdit->SetText(wsText);
175 return m_pEdit->GetText();
185 if (!m_pListBox || !IsDropListVisible())
188 CFX_RectF rtList = m_pListBox->GetWidgetRect();
195 uint32_t dwStyleExtsRemoved) {
197 m_pEdit->ModifyStyleExts(dwStyleExtsAdded, dwStyleExtsRemoved);
201 if (IsDropListVisible())
209 CFWL_ComboList* pComboList = m_pListBox;
214 ResetListItemAlignment();
219 float fPopupMin = 0.0f;
221 fPopupMin = fItemHeight * 3 + fBorder * 2;
223 float fPopupMax = fItemHeight * iItems + fBorder * 2;
225 GetPopupPos(fPopupMin, fPopupMax,
m_WidgetRect, &rtList);
226 m_pListBox->SetWidgetRect(rtList);
227 m_pListBox->Update();
232 RepaintInflatedListBoxRect();
236 if (!IsDropListVisible())
240 RepaintInflatedListBoxRect();
243void CFWL_ComboBox::RepaintInflatedListBoxRect() {
244 CFX_RectF rect = m_pListBox->GetWidgetRect();
249void CFWL_ComboBox::MatchEditText() {
250 WideString wsText = m_pEdit->GetText();
251 int32_t iMatch = m_pListBox->MatchItem(wsText.AsStringView());
252 if (iMatch != m_iCurSel) {
253 m_pListBox->ChangeSelected(iMatch);
255 SyncEditText(iMatch);
256 }
else if (iMatch >= 0) {
257 m_pEdit->SetSelected();
262void CFWL_ComboBox::SyncEditText(int32_t iListItem) {
264 m_pEdit->SetText(hItem ? hItem->GetText() : WideString());
266 m_pEdit->SetSelected();
269void CFWL_ComboBox::Layout() {
271 m_ContentRect
= m_ClientRect;
274 float borderWidth = 1;
279 fBtn - borderWidth
, m_ClientRect
.height - 2 * borderWidth
);
287 if (!IsDropDownStyle() || !m_pEdit)
292 m_pEdit->SetWidgetRect(rtEdit);
294 if (m_iCurSel >= 0) {
297 m_pEdit->SetText(hItem ? hItem->GetText() : WideString());
302void CFWL_ComboBox::ResetEditAlignment() {
339void CFWL_ComboBox::ResetListItemAlignment() {
358 m_iCurSel = m_pListBox->GetItemIndex(
this, m_pListBox->GetSelItem(0));
359 if (!IsDropDownStyle()) {
368 m_pEdit->SetText(hItem->GetText());
370 m_pEdit->SetSelected();
372 CFWL_EventSelectChanged ev(
this, bLButtonUp);
377 bool backDefault =
true;
391 CFWL_MessageMouse* pMsg =
static_cast<CFWL_MessageMouse*>(pMessage);
406 CFWL_MessageKey* pKey =
static_cast<CFWL_MessageKey*>(pMessage);
407 if (IsDropListVisible() &&
414 m_pListBox->GetDelegate()->OnProcessMessage(pMessage);
432 CFWL_EventScroll* pScrollEvent =
static_cast<CFWL_EventScroll*>(pEvent);
447void CFWL_ComboBox::OnLButtonUp(CFWL_MessageMouse* pMsg) {
448 if (m_BtnRect.Contains(pMsg->m_pos))
449 m_iBtnState = CFWL_PartState::kHovered;
451 m_iBtnState = CFWL_PartState::kNormal;
456void CFWL_ComboBox::OnLButtonDown(CFWL_MessageMouse* pMsg) {
457 if (IsDropListVisible()) {
458 if (m_BtnRect.Contains(pMsg->m_pos))
462 if (!m_ClientRect.Contains(pMsg->m_pos))
470void CFWL_ComboBox::OnFocusGained() {
473 CFWL_MessageSetFocus msg(m_pEdit);
474 m_pEdit->GetDelegate()->OnProcessMessage(&msg);
478void CFWL_ComboBox::OnFocusLost() {
481 CFWL_MessageKillFocus msg
(nullptr);
482 m_pEdit->GetDelegate()->OnProcessMessage(&msg);
485void CFWL_ComboBox::OnKey(CFWL_MessageKey* pMsg) {
490 CFWL_ComboList* pComboList = m_pListBox;
495 bool bMatchEqual =
false;
496 int32_t iCurSel = m_iCurSel;
498 WideString wsText = m_pEdit->GetText();
507 }
else if (bMatchEqual) {
508 if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1))
516 SyncEditText(m_iCurSel);
520 m_pEdit->GetDelegate()->OnProcessMessage(pMsg);
523void CFWL_ComboBox::GetPopupPos(
float fMinHeight,
527 GetWidgetMgr()->GetAdapterPopupPos(
this, fMinHeight, fMaxHeight, rtAnchor,
#define FWL_STYLEEXT_CMB_ListItemAlignMask
#define FWL_STYLEEXT_CMB_EditHAlignMask
#define FWL_STYLEEXT_CMB_EditVCenter
#define FWL_STYLEEXT_CMB_EditVFar
#define FWL_STYLEEXT_CMB_DropDown
#define FWL_STYLEEXT_CMB_ListItemCenterAlign
#define FWL_STYLEEXT_CMB_EditHCenter
#define FWL_STYLEEXT_CMB_EditVAlignMask
#define FWL_STYLEEXT_CMB_ReadOnly
#define FWL_STYLEEXT_CMB_EditJustified
#define FWL_STYLEEXT_EDT_VAlignMask
#define FWL_STYLEEXT_EDT_HAlignModeMask
#define FWL_STYLEEXT_EDT_HAlignMask
#define FWL_STYLEEXT_EDT_VNear
#define FWL_STYLEEXT_EDT_VCenter
#define FWL_STYLEEXT_EDT_ReadOnly
#define FWL_STYLEEXT_EDT_VFar
#define FWL_STYLEEXT_EDT_HNear
#define FWL_STYLEEXT_EDT_Justified
#define FWL_STYLEEXT_EDT_HCenter
#define FWL_STYLEEXT_LTB_CenterAlign
#define FWL_STYLEEXT_LTB_LeftAlign
StateRestorer(CFGAS_GEGraphics *graphics)
void ConcatMatrix(const CFX_Matrix &matrix)
void ProcessSelChanged(bool bLButtonUp)
void OnProcessMessage(CFWL_Message *pMessage) override
void DrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
WideString GetTextByIndex(int32_t iIndex) const
~CFWL_ComboBox() override
void EditModifyStyleExts(uint32_t dwStyleExtsAdded, uint32_t dwStyleExtsRemoved)
FWL_Type GetClassID() const override
void AddString(const WideString &wsText)
FWL_WidgetHit HitTest(const CFX_PointF &point) override
void SetStates(uint32_t dwStates) override
void SetCurSel(int32_t iSel)
void RemoveStates(uint32_t dwStates) override
void OnProcessEvent(CFWL_Event *pEvent) override
CFX_RectF GetBBox() const
WideString GetEditText() const
void RemoveAt(int32_t iIndex)
void Trace(cppgc::Visitor *visitor) const override
void SetEditText(const WideString &wsText)
void OnDrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
void ModifyStyleExts(uint32_t dwStyleExtsAdded, uint32_t dwStyleExtsRemoved) override
void ChangeSelected(int32_t iSel)
int32_t MatchItem(WideStringView wsMatch)
CFWL_Widget * GetSrcTarget() const
WideString GetText() const
int32_t CountItems(const CFWL_Widget *pWidget) const
const uint32_t m_dwKeyCodeOrChar
CFWL_MessageKillFocus(CFWL_Widget *pDstTarget)
const MouseCommand m_dwCmd
CFWL_Widget * GetDstTarget() const
CFX_Matrix(float a1, float b1, float c1, float d1, float e1, float f1)
void Concat(const CFX_Matrix &right)
void Offset(float dx, float dy)
bool IsEmpty(float fEpsilon) const
void Deflate(float off_left, float off_top, float off_right, float off_bottom)
void Inflate(float x, float y)
CFX_RectF & operator=(const CFX_RectF &other)=default
bool Contains(const PointType &p) const
constexpr CFX_RectF(float dst_left, float dst_top, float dst_width, float dst_height)
void Union(const CFX_RectF &rt)
virtual CFX_RectF GetUIMargin(const CFWL_ThemePart &pThemePart) const =0
virtual float GetScrollBarWidth() const =0
bool operator==(const WideString &other) const