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_LIST_BOX_H_ 8 #define FPDFSDK_PWL_CPWL_LIST_BOX_H_ 9 10 #include <memory> 11 12 #include "core/fxcrt/unowned_ptr.h" 13 #include "fpdfsdk/pwl/cpwl_wnd.h" 14 15 class CPWL_ListCtrl; 16 class CPWL_List_Notify; 17 class CPWL_ListBox; 18 class IPWL_Filler_Notify; 19 struct CPVT_WordPlace; 20 21 class CPWL_List_Notify { 22 public: 23 explicit CPWL_List_Notify(CPWL_ListBox* pList); 24 ~CPWL_List_Notify(); 25 26 void IOnSetScrollInfoY(float fPlateMin, 27 float fPlateMax, 28 float fContentMin, 29 float fContentMax, 30 float fSmallStep, 31 float fBigStep); 32 void IOnSetScrollPosY(float fy); 33 void IOnInvalidateRect(CFX_FloatRect* pRect); 34 35 private: 36 UnownedPtr<CPWL_ListBox> m_pList; 37 }; 38 39 class CPWL_ListBox : public CPWL_Wnd { 40 public: 41 CPWL_ListBox( 42 const CreateParams& cp, 43 std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData); 44 ~CPWL_ListBox() override; 45 46 // CPWL_Wnd 47 void OnCreated() override; 48 void OnDestroy() override; 49 void DrawThisAppearance(CFX_RenderDevice* pDevice, 50 const CFX_Matrix& mtUser2Device) override; 51 bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override; 52 bool OnChar(uint16_t nChar, uint32_t nFlag) override; 53 bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; 54 bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; 55 bool OnMouseMove(const CFX_PointF& point, uint32_t nFlag) override; 56 bool OnMouseWheel(short zDelta, 57 const CFX_PointF& point, 58 uint32_t nFlag) override; 59 WideString GetText() override; 60 void SetScrollInfo(const PWL_SCROLL_INFO& info) override; 61 void SetScrollPosition(float pos) override; 62 void ScrollWindowVertically(float pos) override; 63 bool RePosChildWnd() override; 64 CFX_FloatRect GetFocusRect() const override; 65 void SetFontSize(float fFontSize) override; 66 float GetFontSize() const override; 67 68 bool OnNotifySelectionChanged(bool bKeyDown, uint32_t nFlag); 69 70 void AddString(const WideString& str); 71 void SetTopVisibleIndex(int32_t nItemIndex); 72 void ScrollToListItem(int32_t nItemIndex); 73 void ResetContent(); 74 void Reset(); 75 void Select(int32_t nItemIndex); 76 void Deselect(int32_t nItemIndex); 77 void SetCaret(int32_t nItemIndex); 78 void SetHoverSel(bool bHoverSel); 79 80 int32_t GetCount() const; 81 bool IsMultipleSel() const; 82 int32_t GetCaretIndex() const; 83 int32_t GetCurSel() const; 84 bool IsItemSelected(int32_t nItemIndex) const; 85 int32_t GetTopVisibleIndex() const; 86 int32_t FindNext(int32_t nIndex, wchar_t nChar) const; 87 CFX_FloatRect GetContentRect() const; 88 float GetFirstHeight() const; 89 CFX_FloatRect GetListRect() const; 90 SetFillerNotify(IPWL_Filler_Notify * pNotify)91 void SetFillerNotify(IPWL_Filler_Notify* pNotify) { 92 m_pFillerNotify = pNotify; 93 } 94 AttachFFLData(CFFL_FormFiller * pData)95 void AttachFFLData(CFFL_FormFiller* pData) { m_pFormFiller = pData; } 96 97 protected: 98 bool m_bMouseDown = false; 99 bool m_bHoverSel = false; 100 std::unique_ptr<CPWL_ListCtrl> m_pList; 101 std::unique_ptr<CPWL_List_Notify> m_pListNotify; 102 UnownedPtr<IPWL_Filler_Notify> m_pFillerNotify; 103 104 private: 105 UnownedPtr<CFFL_FormFiller> m_pFormFiller; 106 }; 107 108 #endif // FPDFSDK_PWL_CPWL_LIST_BOX_H_ 109