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();
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);
207 const CFX_FloatRect rcClient = this_observed->GetClientRect();
208 if (this_observed->m_bPopup) {
209 const float fOldWindowHeight = this_observed->m_rcOldWindow.Height();
210 const float fOldClientHeight = fOldWindowHeight -
GetBorderWidth() * 2;
217 if (this_observed->m_bBottom) {
220 rcList
.top -= fOldWindowHeight;
224 rcList
.bottom += fOldWindowHeight;
226 if (this_observed->m_pButton) {
227 this_observed->m_pButton->Move(rcButton,
true,
false);
228 if (!this_observed) {
232 if (this_observed->m_pEdit) {
233 this_observed->m_pEdit->Move(rcEdit,
true,
false);
234 if (!this_observed) {
238 if (this_observed->m_pList) {
239 if (!this_observed->m_pList->SetVisible(
true) || !this_observed) {
242 if (!this_observed->m_pList->Move(rcList,
true,
false) ||
246 this_observed->m_pList->ScrollToListItem(this_observed->m_nSelectItem);
247 if (!this_observed) {
256 if (this_observed->m_pButton) {
257 this_observed->m_pButton->Move(rcButton,
true,
false);
258 if (!this_observed) {
265 if (this_observed->m_pEdit) {
266 this_observed->m_pEdit->Move(rcEdit,
true,
false);
267 if (!this_observed) {
271 if (this_observed->m_pList) {
272 if (!this_observed->m_pList->SetVisible(
false)) {
273 this_observed->m_pList =
nullptr;
276 if (!this_observed) {
285 m_pEdit->SelectAllText();
292bool CPWL_ComboBox::SetPopup(
bool bPopup) {
293 ObservedPtr<CPWL_ComboBox> this_observed(
this);
294 if (!this_observed->m_pList) {
297 if (bPopup == this_observed->m_bPopup) {
300 float fListHeight = this_observed->m_pList->GetContentRect().Height();
305 this_observed->m_bPopup =
false;
306 return Move(this_observed->m_rcOldWindow
, true, true);
309 return !!this_observed;
311 if (!this_observed) {
314 float fBorderWidth = this_observed->m_pList->GetBorderWidth() * 2;
315 float fPopupMin = 0.0f;
316 if (this_observed->m_pList->GetCount() > 3) {
317 fPopupMin = this_observed->m_pList->GetFirstHeight() * 3 + fBorderWidth;
319 float fPopupMax = fListHeight + fBorderWidth;
322 this_observed->GetFillerNotify()->QueryWherePopup(
323 this_observed->GetAttachedData(), fPopupMin, fPopupMax, &bBottom,
328 this_observed->m_rcOldWindow = this_observed->CPWL_Wnd::GetWindowRect();
329 this_observed->m_bPopup = bPopup;
330 this_observed->m_bBottom = bBottom;
336 rcWindow
.top += fPopupRet;
338 if (!this_observed->Move(rcWindow,
true,
true)) {
341 this_observed->GetFillerNotify()->OnPopupPostOpen(
342 this_observed->GetAttachedData(), {});
343 return !!this_observed;
347 Mask<FWL_EVENTFLAG> nFlag) {
348 ObservedPtr<CPWL_ComboBox> this_observed(
this);
349 if (!this_observed->m_pList) {
352 if (!this_observed->m_pEdit) {
355 this_observed->m_nSelectItem = -1;
359 if (this_observed->m_pList->GetCurSel() > 0) {
360 if (this_observed->GetFillerNotify()->OnPopupPreOpen(
GetAttachedData(),
365 if (this_observed->GetFillerNotify()->OnPopupPostOpen(
GetAttachedData(),
370 if (this_observed->m_pList->IsMovementKey(nKeyCode)) {
371 if (this_observed->m_pList->OnMovementKeyDown(nKeyCode, nFlag) ||
375 this_observed->SetSelectText();
380 if (this_observed->m_pList->GetCurSel() <
381 this_observed->m_pList->GetCount() - 1) {
382 if (this_observed->GetFillerNotify()->OnPopupPreOpen(
GetAttachedData(),
387 if (this_observed->GetFillerNotify()->OnPopupPostOpen(
GetAttachedData(),
392 if (this_observed->m_pList->IsMovementKey(nKeyCode)) {
393 if (this_observed->m_pList->OnMovementKeyDown(nKeyCode, nFlag) ||
397 this_observed->SetSelectText();
405 return this_observed->m_pEdit->OnKeyDown(nKeyCode, nFlag);
410bool CPWL_ComboBox::
OnChar(uint16_t nChar,
Mask<FWL_EVENTFLAG> nFlag) {
411 ObservedPtr<CPWL_ComboBox> this_observed(
this);
412 if (!this_observed->m_pList) {
415 if (!this_observed->m_pEdit) {
422 if (!this_observed->SetPopup(!this_observed->IsPopup())) {
425 this_observed->SetSelectText();
431 if (!this_observed->IsPopup()) {
432 if (!this_observed->SetPopup(
true)) {
435 this_observed->SetSelectText();
444 this_observed->m_nSelectItem = -1;
446 return this_observed->m_pEdit->OnChar(nChar, nFlag);
448 if (this_observed->GetFillerNotify()->OnPopupPreOpen(
GetAttachedData(),
453 if (this_observed->GetFillerNotify()->OnPopupPostOpen(
GetAttachedData(),
458 if (!this_observed->m_pList->IsChar(nChar, nFlag)) {
461 return this_observed->m_pList->OnCharNotify(nChar, nFlag);
465 if (child == m_pButton) {
466 (
void)SetPopup(!m_bPopup);
473 if (!m_pEdit || !m_pList || child != m_pList)
479 (
void)SetPopup(
false);
489 m_pEdit->SelectAllText();
490 m_pEdit->ReplaceSelection(m_pList->GetText());
491 m_pEdit->SelectAllText();
492 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
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
CFX_PTemplate< float > CFX_PointF
#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)
fxcrt::WideString WideString