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"
30CFWL_ComboBox::CFWL_ComboBox(CFWL_App* app)
32 m_pEdit(cppgc::MakeGarbageCollected<CFWL_ComboEdit>(
33 app->GetHeap()->GetAllocationHandle(),
37 m_pListBox(cppgc::MakeGarbageCollected<CFWL_ComboList>(
38 app->GetHeap()->GetAllocationHandle(),
46void CFWL_ComboBox::
Trace(cppgc::Visitor* visitor)
const {
47 CFWL_Widget::Trace(visitor);
48 visitor->Trace(m_pEdit);
49 visitor->Trace(m_pListBox);
57 m_pListBox->AddString(wsText);
61 m_pListBox->RemoveAt(iIndex);
65 m_pListBox->DeleteAll();
69 uint32_t dwStyleExtsRemoved) {
76 else if (bDelDropDown)
98 if (IsDropListVisible()) {
99 rect = m_pListBox->GetWidgetRect();
113 param.m_dwStates = m_iBtnState;
118 CFX_RectF rtEdit = m_pEdit->GetWidgetRect();
121 m_pEdit->DrawWidget(pGraphics, mt);
123 if (m_pListBox && IsDropListVisible()) {
124 CFX_RectF rtList = m_pListBox->GetWidgetRect();
127 m_pListBox->DrawWidget(pGraphics, mt);
137 int32_t iCount = m_pListBox->CountItems(
nullptr);
138 bool bClearSel = iSel < 0 || iSel >= iCount;
139 if (IsDropDownStyle() && m_pEdit) {
141 m_pEdit->SetText(WideString());
144 m_pEdit->SetText(hItem ? hItem->GetText() : WideString());
148 m_iCurSel = bClearSel ? -1 : iSel;
152 if (IsDropDownStyle() && m_pEdit)
153 m_pEdit->SetStates(dwStates);
155 m_pListBox->SetStates(dwStates);
160 if (IsDropDownStyle() && m_pEdit)
161 m_pEdit->RemoveStates(dwStates);
163 m_pListBox->RemoveStates(dwStates);
171 m_pEdit->SetText(wsText);
177 return m_pEdit->GetText();
187 if (!m_pListBox || !IsDropListVisible())
190 CFX_RectF rtList = m_pListBox->GetWidgetRect();
197 uint32_t dwStyleExtsRemoved) {
199 m_pEdit->ModifyStyleExts(dwStyleExtsAdded, dwStyleExtsRemoved);
203 if (IsDropListVisible())
211 CFWL_ComboList* pComboList = m_pListBox;
216 ResetListItemAlignment();
221 float fPopupMin = 0.0f;
223 fPopupMin = fItemHeight * 3 + fBorder * 2;
225 float fPopupMax = fItemHeight * iItems + fBorder * 2;
227 GetPopupPos(fPopupMin, fPopupMax,
m_WidgetRect, &rtList);
228 m_pListBox->SetWidgetRect(rtList);
229 m_pListBox->Update();
234 RepaintInflatedListBoxRect();
238 if (!IsDropListVisible())
242 RepaintInflatedListBoxRect();
245void CFWL_ComboBox::RepaintInflatedListBoxRect() {
246 CFX_RectF rect = m_pListBox->GetWidgetRect();
251void CFWL_ComboBox::MatchEditText() {
253 int32_t iMatch = m_pListBox->MatchItem(wsText.AsStringView());
254 if (iMatch != m_iCurSel) {
255 m_pListBox->ChangeSelected(iMatch);
257 SyncEditText(iMatch);
258 }
else if (iMatch >= 0) {
259 m_pEdit->SetSelected();
264void CFWL_ComboBox::SyncEditText(int32_t iListItem) {
266 m_pEdit->SetText(hItem ? hItem->GetText() : WideString());
268 m_pEdit->SetSelected();
271void CFWL_ComboBox::Layout() {
273 m_ContentRect
= m_ClientRect;
276 float borderWidth = 1;
281 fBtn - borderWidth
, m_ClientRect
.height - 2 * borderWidth
);
289 if (!IsDropDownStyle() || !m_pEdit)
294 m_pEdit->SetWidgetRect(rtEdit);
296 if (m_iCurSel >= 0) {
299 m_pEdit->SetText(hItem ? hItem->GetText() : WideString());
304void CFWL_ComboBox::ResetEditAlignment() {
341void CFWL_ComboBox::ResetListItemAlignment() {
360 m_iCurSel = m_pListBox->GetItemIndex(
this, m_pListBox->GetSelItem(0));
361 if (!IsDropDownStyle()) {
370 m_pEdit->SetText(hItem->GetText());
372 m_pEdit->SetSelected();
374 CFWL_EventSelectChanged ev(
this, bLButtonUp);
379 bool backDefault =
true;
393 CFWL_MessageMouse* pMsg =
static_cast<CFWL_MessageMouse*>(pMessage);
408 CFWL_MessageKey* pKey =
static_cast<CFWL_MessageKey*>(pMessage);
409 if (IsDropListVisible() &&
416 m_pListBox->GetDelegate()->OnProcessMessage(pMessage);
434 CFWL_EventScroll* pScrollEvent =
static_cast<CFWL_EventScroll*>(pEvent);
449void CFWL_ComboBox::OnLButtonUp(CFWL_MessageMouse* pMsg) {
450 if (m_BtnRect.Contains(pMsg->m_pos))
451 m_iBtnState = CFWL_PartState::kHovered;
453 m_iBtnState = CFWL_PartState::kNormal;
458void CFWL_ComboBox::OnLButtonDown(CFWL_MessageMouse* pMsg) {
459 if (IsDropListVisible()) {
460 if (m_BtnRect.Contains(pMsg->m_pos))
464 if (!m_ClientRect.Contains(pMsg->m_pos))
472void CFWL_ComboBox::OnFocusGained() {
475 CFWL_MessageSetFocus msg(m_pEdit);
476 m_pEdit->GetDelegate()->OnProcessMessage(&msg);
480void CFWL_ComboBox::OnFocusLost() {
483 CFWL_MessageKillFocus msg
(nullptr);
484 m_pEdit->GetDelegate()->OnProcessMessage(&msg);
487void CFWL_ComboBox::OnKey(CFWL_MessageKey* pMsg) {
492 CFWL_ComboList* pComboList = m_pListBox;
497 bool bMatchEqual =
false;
498 int32_t iCurSel = m_iCurSel;
509 }
else if (bMatchEqual) {
510 if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1))
518 SyncEditText(m_iCurSel);
522 m_pEdit->GetDelegate()->OnProcessMessage(pMsg);
525void CFWL_ComboBox::GetPopupPos(
float fMinHeight,
529 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)
constexpr 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)
bool operator==(const WideString &other) const
void ProcessSelChanged(bool bLButtonUp)
void Trace(cppgc::Visitor *visitor) const override
void SetCurSel(int32_t iSel)
void SetEditText(const WideString &wsText)
void SetStates(uint32_t dwStates) override
void OnProcessEvent(CFWL_Event *pEvent) override
void RemoveAt(int32_t iIndex)
void ModifyStyleExts(uint32_t dwStyleExtsAdded, uint32_t dwStyleExtsRemoved) override
WideString GetTextByIndex(int32_t iIndex) const
CFX_RectF GetBBox() const
~CFWL_ComboBox() override
FWL_Type GetClassID() const override
void AddString(const WideString &wsText)
WideString GetEditText() const
void RemoveStates(uint32_t dwStates) override
void EditModifyStyleExts(uint32_t dwStyleExtsAdded, uint32_t dwStyleExtsRemoved)
void DrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
void OnProcessMessage(CFWL_Message *pMessage) override
void OnDrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
FWL_WidgetHit HitTest(const CFX_PointF &point) override
int32_t MatchItem(WideStringView wsMatch)
void ChangeSelected(int32_t iSel)
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
virtual float GetScrollBarWidth() const =0
virtual CFX_RectF GetUIMargin(const CFWL_ThemePart &pThemePart) const =0
CFX_PTemplate< float > CFX_PointF
fxcrt::WideString WideString