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