7#include "fpdfsdk/pwl/cpwl_combo_box.h"
12#include "constants/ascii.h"
13#include "fpdfsdk/pwl/cpwl_cbbutton.h"
14#include "fpdfsdk/pwl/cpwl_cblistbox.h"
15#include "fpdfsdk/pwl/cpwl_edit.h"
16#include "fpdfsdk/pwl/ipwl_fillernotify.h"
17#include "public/fpdf_fwlevent.h"
21constexpr float kComboBoxDefaultFontSize = 12.0f;
22constexpr int kDefaultButtonWidth = 13;
28 std::unique_ptr<IPWL_FillerNotify::PerWindowData> pAttachedData)
40 m_pList.ExtractAsDangling();
41 m_pButton.ExtractAsDangling();
42 m_pEdit.ExtractAsDangling();
60 return m_pEdit->GetSelectedText();
67 m_pEdit->ReplaceAndKeepSelection(text);
72 m_pEdit->ReplaceSelection(text);
76 return m_pEdit && m_pEdit->SelectAllText();
80 return m_pEdit && m_pEdit->CanUndo();
84 return m_pEdit && m_pEdit->CanRedo();
87bool CPWL_ComboBox::
Undo() {
88 return m_pEdit && m_pEdit->Undo();
91bool CPWL_ComboBox::
Redo() {
92 return m_pEdit && m_pEdit->Redo();
96 return m_pEdit ? m_pEdit->GetText() : WideString();
99void CPWL_ComboBox::
SetText(
const WideString& text) {
101 m_pEdit->SetText(text);
106 m_pList->AddString(str);
110 return m_nSelectItem;
115 m_pList->Select(nItemIndex);
117 m_pEdit->SetText(m_pList->GetText());
118 m_nSelectItem = nItemIndex;
123 m_pEdit->SetSelection(nStartChar, nEndChar);
128 m_pEdit->ClearSelection();
155 auto pEdit = std::make_unique<CPWL_Edit>(ecp, CloneAttachedData());
156 m_pEdit = pEdit.get();
157 AddChild(std::move(pEdit));
161void CPWL_ComboBox::CreateButton(
const CreateParams& cp) {
168 220.0f / 255.0f
, 220.0f / 255.0f
);
174 auto pButton = std::make_unique<CPWL_CBButton>(bcp, CloneAttachedData());
175 m_pButton = pButton.get();
176 AddChild(std::move(pButton));
177 m_pButton->Realize();
180void CPWL_ComboBox::CreateListBox(
const CreateParams& cp) {
199 auto pList = std::make_unique<CPWL_CBListBox>(lcp, CloneAttachedData());
200 m_pList = pList.get();
201 AddChild(std::move(pList));
206 ObservedPtr<CPWL_ComboBox> this_observed(
this);
209 const float fOldWindowHeight = m_rcOldWindow
.Height();
210 const float fOldClientHeight = fOldWindowHeight -
GetBorderWidth() * 2;
221 rcList
.top -= fOldWindowHeight;
225 rcList
.bottom += fOldWindowHeight;
229 m_pButton->Move(rcButton,
true,
false);
230 if (!this_observed) {
236 m_pEdit->Move(rcEdit,
true,
false);
237 if (!this_observed) {
243 if (!m_pList->SetVisible(
true) || !this_observed) {
247 if (!m_pList->Move(rcList,
true,
false) || !this_observed) {
251 m_pList->ScrollToListItem(m_nSelectItem);
252 if (!this_observed) {
263 m_pButton->Move(rcButton,
true,
false);
264 if (!this_observed) {
273 m_pEdit->Move(rcEdit,
true,
false);
274 if (!this_observed) {
280 if (!m_pList->SetVisible(
false)) {
284 if (!this_observed) {
294 m_pEdit->SelectAllText();
301bool CPWL_ComboBox::SetPopup(
bool bPopup) {
304 if (bPopup == m_bPopup)
306 float fListHeight = m_pList->GetContentRect().Height();
312 return Move(m_rcOldWindow,
true,
true);
315 ObservedPtr<CPWL_ComboBox> this_observed(
this);
317 return !!this_observed;
318 if (!this_observed) {
322 float fBorderWidth = m_pList->GetBorderWidth() * 2;
323 float fPopupMin = 0.0f;
324 if (m_pList->GetCount() > 3)
325 fPopupMin = m_pList->GetFirstHeight() * 3 + fBorderWidth;
326 float fPopupMax = fListHeight + fBorderWidth;
331 &bBottom, &fPopupRet);
343 rcWindow
.top += fPopupRet;
345 if (!
Move(rcWindow,
true,
true))
349 return !!this_observed;
353 Mask<FWL_EVENTFLAG> nFlag) {
359 ObservedPtr<
CPWL_Wnd> this_observed(
this);
364 if (m_pList->GetCurSel() > 0) {
373 if (m_pList->IsMovementKey(nKeyCode)) {
374 if (m_pList->OnMovementKeyDown(nKeyCode, nFlag) || !this_observed) {
382 if (m_pList->GetCurSel() < m_pList->GetCount() - 1) {
391 if (m_pList->IsMovementKey(nKeyCode)) {
392 if (m_pList->OnMovementKeyDown(nKeyCode, nFlag) || !this_observed) {
404 return m_pEdit->OnKeyDown(nKeyCode, nFlag);
409bool CPWL_ComboBox::
OnChar(uint16_t nChar,
Mask<FWL_EVENTFLAG> nFlag) {
430 if (!SetPopup(
true)) {
444 return m_pEdit->OnChar(nChar, nFlag);
446 ObservedPtr<
CPWL_Wnd> this_observed(
this);
455 if (!m_pList->IsChar(nChar, nFlag))
457 return m_pList->OnCharNotify(nChar, nFlag);
461 if (child == m_pButton) {
462 (
void)SetPopup(!m_bPopup);
469 if (!m_pEdit || !m_pList || child != m_pList)
475 (
void)SetPopup(
false);
485 m_pEdit->SelectAllText();
486 m_pEdit->ReplaceSelection(m_pList->GetText());
487 m_pEdit->SelectAllText();
488 m_nSelectItem = m_pList->GetCurSel();
constexpr CFX_FloatRect()=default
CFX_FloatRect & operator=(const CFX_FloatRect &that)=default
void KillFocus() override
void SetSelect(int32_t nItemIndex)
void SetText(const WideString &text)
CFX_FloatRect GetFocusRect() const override
CPWL_ComboBox(const CreateParams &cp, std::unique_ptr< IPWL_FillerNotify::PerWindowData > pAttachedData)
void AddString(const WideString &str)
WideString GetSelectedText() override
~CPWL_ComboBox() override
void ReplaceSelection(const WideString &text) override
void ReplaceAndKeepSelection(const WideString &text) override
bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask< FWL_EVENTFLAG > nFlag) override
int32_t GetSelect() const
WideString GetText() override
bool OnChar(uint16_t nChar, Mask< FWL_EVENTFLAG > nFlag) override
bool SelectAllText() override
void NotifyLButtonDown(CPWL_Wnd *child, const CFX_PointF &pos) override
void CreateChildWnd(const CreateParams &cp) override
void OnDestroy() override
void SetEditSelection(int32_t nStartChar, int32_t nEndChar)
void NotifyLButtonUp(CPWL_Wnd *child, const CFX_PointF &pos) override
bool RepositionChildWnd() override
IPWL_FillerNotify::CursorStyle eCursorType
CFX_Color sBackgroundColor
IPWL_FillerNotify * GetFillerNotify() const
bool HasFlag(uint32_t dwFlags) const
virtual CFX_FloatRect GetClientRect() const
CFX_FloatRect GetWindowRect() const
int32_t GetBorderWidth() const
CreateParams * GetCreationParams()
IPWL_FillerNotify::PerWindowData * GetAttachedData() const
bool Move(const CFX_FloatRect &rcNew, bool bReset, bool bRefresh)
static const CFX_Color kDefaultWhiteColor
static const CFX_Color kDefaultBlackColor
#define PCBS_ALLOWCUSTOMTEXT
#define FXSYS_IsFloatBigger(fa, fb)
constexpr uint8_t kReturn
CFX_Color & operator=(const CFX_Color &that)=default
constexpr CFX_Color(Type type=CFX_Color::Type::kTransparent, float color1=0.0f, float color2=0.0f, float color3=0.0f, float color4=0.0f)