xref: /aosp_15_r20/external/pdfium/fpdfsdk/pwl/cpwl_combo_box.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2014 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef FPDFSDK_PWL_CPWL_COMBO_BOX_H_
8 #define FPDFSDK_PWL_CPWL_COMBO_BOX_H_
9 
10 #include <memory>
11 
12 #include "core/fxcrt/unowned_ptr.h"
13 #include "fpdfsdk/pwl/cpwl_wnd.h"
14 #include "fpdfsdk/pwl/ipwl_fillernotify.h"
15 
16 class CPWL_Edit;
17 class CPWL_CBButton;
18 class CPWL_CBListBox;
19 class IPWL_FillerNotify;
20 
21 class CPWL_ComboBox final : public CPWL_Wnd {
22  public:
23   CPWL_ComboBox(
24       const CreateParams& cp,
25       std::unique_ptr<IPWL_FillerNotify::PerWindowData> pAttachedData);
26   ~CPWL_ComboBox() override;
27 
GetEdit()28   CPWL_Edit* GetEdit() const { return m_pEdit; }
29 
30   // CPWL_Wnd:
31   void OnDestroy() override;
32   bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask<FWL_EVENTFLAG> nFlag) override;
33   bool OnChar(uint16_t nChar, Mask<FWL_EVENTFLAG> nFlag) override;
34   void NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) override;
35   void NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) override;
36   void CreateChildWnd(const CreateParams& cp) override;
37   bool RepositionChildWnd() override;
38   CFX_FloatRect GetFocusRect() const override;
39   void SetFocus() override;
40   void KillFocus() override;
41   WideString GetText() override;
42   WideString GetSelectedText() override;
43   void ReplaceAndKeepSelection(const WideString& text) override;
44   void ReplaceSelection(const WideString& text) override;
45   bool SelectAllText() override;
46   bool CanUndo() override;
47   bool CanRedo() override;
48   bool Undo() override;
49   bool Redo() override;
50 
51   void SetText(const WideString& text);
52   void AddString(const WideString& str);
53   int32_t GetSelect() const;
54   void SetSelect(int32_t nItemIndex);
55 
56   void SetEditSelection(int32_t nStartChar, int32_t nEndChar);
57   void ClearSelection();
58   void SelectAll();
59   bool IsPopup() const;
60   void SetSelectText();
61 
62  private:
63   void CreateEdit(const CreateParams& cp);
64   void CreateButton(const CreateParams& cp);
65   void CreateListBox(const CreateParams& cp);
66 
67   // Returns |true| iff this instance is still allocated.
68   [[nodiscard]] bool SetPopup(bool bPopup);
69 
70   UnownedPtr<CPWL_Edit> m_pEdit;
71   UnownedPtr<CPWL_CBButton> m_pButton;
72   UnownedPtr<CPWL_CBListBox> m_pList;
73   CFX_FloatRect m_rcOldWindow;
74   bool m_bPopup = false;
75   bool m_bBottom = true;
76   int32_t m_nSelectItem = -1;
77 };
78 
79 #endif  // FPDFSDK_PWL_CPWL_COMBO_BOX_H_
80