1 // Copyright 2014 PDFium Authors. All rights reserved.
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_edit.h"
14 #include "fpdfsdk/pwl/cpwl_list_box.h"
15 #include "fpdfsdk/pwl/cpwl_wnd.h"
16 
17 class CPWL_CBListBox : public CPWL_ListBox {
18  public:
CPWL_CBListBox()19   CPWL_CBListBox() {}
~CPWL_CBListBox()20   ~CPWL_CBListBox() override {}
21 
22   // CPWL_ListBox
23   bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override;
24 
25   bool IsMovementKey(uint16_t nChar) const;
26   bool OnMovementKeyDown(uint16_t nChar, uint32_t nFlag);
27   bool IsChar(uint16_t nChar, uint32_t nFlag) const;
28   bool OnCharNotify(uint16_t nChar, uint32_t nFlag);
29 };
30 
31 class CPWL_CBButton : public CPWL_Wnd {
32  public:
CPWL_CBButton()33   CPWL_CBButton() {}
~CPWL_CBButton()34   ~CPWL_CBButton() override {}
35 
36   // CPWL_Wnd
37   void DrawThisAppearance(CFX_RenderDevice* pDevice,
38                           const CFX_Matrix& mtUser2Device) override;
39   bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override;
40   bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override;
41 };
42 
43 class CPWL_ComboBox : public CPWL_Wnd {
44  public:
45   CPWL_ComboBox();
46   ~CPWL_ComboBox() override;
47 
GetEdit()48   CPWL_Edit* GetEdit() const { return m_pEdit.Get(); }
49 
50   // CPWL_Wnd:
51   ByteString GetClassName() const override;
52   void OnCreate(CreateParams* pParamsToAdjust) override;
53   void OnDestroy() override;
54   bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override;
55   bool OnChar(uint16_t nChar, uint32_t nFlag) override;
56   void NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) override;
57   void NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) override;
58   void CreateChildWnd(const CreateParams& cp) override;
59   bool RePosChildWnd() override;
60   CFX_FloatRect GetFocusRect() const override;
61   void SetFocus() override;
62   void KillFocus() override;
63   WideString GetSelectedText() override;
64   void ReplaceSelection(const WideString& text) override;
65 
66   void SetFillerNotify(IPWL_Filler_Notify* pNotify);
67 
68   WideString GetText() const;
69   void SetText(const WideString& text);
70   void AddString(const WideString& str);
71   int32_t GetSelect() const;
72   void SetSelect(int32_t nItemIndex);
73 
74   void SetEditSelection(int32_t nStartChar, int32_t nEndChar);
75   void GetEditSelection(int32_t& nStartChar, int32_t& nEndChar) const;
76   void ClearSelection();
77   void SelectAll();
78   bool IsPopup() const;
79 
80   void SetSelectText();
81 
AttachFFLData(CFFL_FormFiller * pData)82   void AttachFFLData(CFFL_FormFiller* pData) { m_pFormFiller = pData; }
83 
84  private:
85   void CreateEdit(const CreateParams& cp);
86   void CreateButton(const CreateParams& cp);
87   void CreateListBox(const CreateParams& cp);
88 
89   // Returns |true| iff this instance is still allocated.
90   bool SetPopup(bool bPopup);
91 
92   UnownedPtr<CPWL_Edit> m_pEdit;
93   UnownedPtr<CPWL_CBButton> m_pButton;
94   UnownedPtr<CPWL_CBListBox> m_pList;
95   CFX_FloatRect m_rcOldWindow;
96   bool m_bPopup = false;
97   bool m_bBottom = true;
98   int32_t m_nSelectItem = -1;
99   UnownedPtr<IPWL_Filler_Notify> m_pFillerNotify;
100   UnownedPtr<CFFL_FormFiller> m_pFormFiller;
101 };
102 
103 #endif  // FPDFSDK_PWL_CPWL_COMBO_BOX_H_
104