PWL_ListBox.h revision 5ae9d0c6fd838a2967cca72aa5751b51dadc2769
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_PDFWINDOW_PWL_LISTBOX_H_
8#define FPDFSDK_PDFWINDOW_PWL_LISTBOX_H_
9
10#include <memory>
11
12#include "fpdfsdk/fxedit/fx_edit.h"
13#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
14
15class CFX_ListCtrl;
16class CPWL_List_Notify;
17class CPWL_ListBox;
18class IPWL_Filler_Notify;
19struct CPVT_SecProps;
20struct CPVT_WordPlace;
21struct CPVT_WordProps;
22
23class CPWL_List_Notify {
24 public:
25  explicit CPWL_List_Notify(CPWL_ListBox* pList);
26  ~CPWL_List_Notify();
27
28  void IOnSetScrollInfoY(FX_FLOAT fPlateMin,
29                         FX_FLOAT fPlateMax,
30                         FX_FLOAT fContentMin,
31                         FX_FLOAT fContentMax,
32                         FX_FLOAT fSmallStep,
33                         FX_FLOAT fBigStep);
34  void IOnSetScrollPosY(FX_FLOAT fy);
35  void IOnInvalidateRect(CFX_FloatRect* pRect);
36
37  void IOnSetCaret(bool bVisible,
38                   const CFX_PointF& ptHead,
39                   const CFX_PointF& ptFoot,
40                   const CPVT_WordPlace& place);
41
42 private:
43  CPWL_ListBox* m_pList;
44};
45
46class CPWL_ListBox : public CPWL_Wnd {
47 public:
48  CPWL_ListBox();
49  ~CPWL_ListBox() override;
50
51  // CPWL_Wnd
52  CFX_ByteString GetClassName() const override;
53  void OnCreated() override;
54  void OnDestroy() override;
55  void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override;
56  void DrawThisAppearance(CFX_RenderDevice* pDevice,
57                          CFX_Matrix* pUser2Device) override;
58  bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override;
59  bool OnChar(uint16_t nChar, uint32_t nFlag) override;
60  bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override;
61  bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override;
62  bool OnMouseMove(const CFX_PointF& point, uint32_t nFlag) override;
63  bool OnMouseWheel(short zDelta,
64                    const CFX_PointF& point,
65                    uint32_t nFlag) override;
66  void KillFocus() override;
67  void OnNotify(CPWL_Wnd* pWnd,
68                uint32_t msg,
69                intptr_t wParam = 0,
70                intptr_t lParam = 0) override;
71  void RePosChildWnd() override;
72  CFX_FloatRect GetFocusRect() const override;
73  void SetFontSize(FX_FLOAT fFontSize) override;
74  FX_FLOAT GetFontSize() const override;
75
76  virtual CFX_WideString GetText() const;
77
78  void OnNotifySelChanged(bool bKeyDown, bool& bExit, uint32_t nFlag);
79
80  void AddString(const CFX_WideString& str);
81  void SetTopVisibleIndex(int32_t nItemIndex);
82  void ScrollToListItem(int32_t nItemIndex);
83  void ResetContent();
84  void Reset();
85  void Select(int32_t nItemIndex);
86  void SetCaret(int32_t nItemIndex);
87  void SetHoverSel(bool bHoverSel);
88
89  int32_t GetCount() const;
90  bool IsMultipleSel() const;
91  int32_t GetCaretIndex() const;
92  int32_t GetCurSel() const;
93  bool IsItemSelected(int32_t nItemIndex) const;
94  int32_t GetTopVisibleIndex() const;
95  int32_t FindNext(int32_t nIndex, FX_WCHAR nChar) const;
96  CFX_FloatRect GetContentRect() const;
97  FX_FLOAT GetFirstHeight() const;
98  CFX_FloatRect GetListRect() const;
99
100  void SetFillerNotify(IPWL_Filler_Notify* pNotify) {
101    m_pFillerNotify = pNotify;
102  }
103
104  void AttachFFLData(CFFL_FormFiller* pData) { m_pFormFiller = pData; }
105
106 protected:
107  std::unique_ptr<CFX_ListCtrl> m_pList;
108  std::unique_ptr<CPWL_List_Notify> m_pListNotify;
109  bool m_bMouseDown;
110  bool m_bHoverSel;
111  IPWL_Filler_Notify* m_pFillerNotify;
112
113 private:
114  CFFL_FormFiller* m_pFormFiller;  // Not owned.
115};
116
117#endif  // FPDFSDK_PDFWINDOW_PWL_LISTBOX_H_
118