• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_IMPL_H_
8 #define FPDFSDK_PWL_CPWL_LIST_IMPL_H_
9 
10 #include <map>
11 #include <memory>
12 #include <vector>
13 
14 #include "core/fxcrt/fx_coordinates.h"
15 #include "core/fxcrt/fx_string.h"
16 #include "core/fxcrt/unowned_ptr.h"
17 
18 class CPWL_EditImpl;
19 class CPWL_EditImpl_Iterator;
20 class CPWL_List_Notify;
21 class IPVT_FontMap;
22 
23 class CPLST_Select final {
24  public:
25   enum State { DESELECTING = -1, NORMAL = 0, SELECTING = 1 };
26   using const_iterator = std::map<int32_t, State>::const_iterator;
27 
28   CPLST_Select();
29   ~CPLST_Select();
30 
31   void Add(int32_t nItemIndex);
32   void Add(int32_t nBeginIndex, int32_t nEndIndex);
33   void Sub(int32_t nItemIndex);
34   void Sub(int32_t nBeginIndex, int32_t nEndIndex);
35   void DeselectAll();
36   void Done();
37 
begin()38   const_iterator begin() const { return m_Items.begin(); }
end()39   const_iterator end() const { return m_Items.end(); }
40 
41  private:
42   std::map<int32_t, State> m_Items;
43 };
44 
45 class CPWL_ListCtrl {
46  public:
47   CPWL_ListCtrl();
48   ~CPWL_ListCtrl();
49 
SetNotify(CPWL_List_Notify * pNotify)50   void SetNotify(CPWL_List_Notify* pNotify) { m_pNotify = pNotify; }
51   void OnMouseDown(const CFX_PointF& point, bool bShift, bool bCtrl);
52   void OnMouseMove(const CFX_PointF& point, bool bShift, bool bCtrl);
53   void OnVK_UP(bool bShift, bool bCtrl);
54   void OnVK_DOWN(bool bShift, bool bCtrl);
55   void OnVK_LEFT(bool bShift, bool bCtrl);
56   void OnVK_RIGHT(bool bShift, bool bCtrl);
57   void OnVK_HOME(bool bShift, bool bCtrl);
58   void OnVK_END(bool bShift, bool bCtrl);
59   bool OnChar(uint16_t nChar, bool bShift, bool bCtrl);
60 
61   void SetScrollPos(const CFX_PointF& point);
62   void ScrollToListItem(int32_t nItemIndex);
63   CFX_FloatRect GetItemRect(int32_t nIndex) const;
GetCaret()64   int32_t GetCaret() const { return m_nCaretIndex; }
GetSelect()65   int32_t GetSelect() const { return m_nSelItem; }
66   int32_t GetTopItem() const;
SetContentRect(const CFX_FloatRect & rect)67   void SetContentRect(const CFX_FloatRect& rect) { m_rcContent = rect; }
68   CFX_FloatRect GetContentRect() const;
69 
70   int32_t GetItemIndex(const CFX_PointF& point) const;
71   void AddString(const WideString& str);
72   void SetTopItem(int32_t nIndex);
73   void Select(int32_t nItemIndex);
74   void Deselect(int32_t nItemIndex);
75   void SetCaret(int32_t nItemIndex);
76   void Clear();
77   void Cancel();
78   WideString GetText() const;
79 
SetFontMap(IPVT_FontMap * pFontMap)80   void SetFontMap(IPVT_FontMap* pFontMap) { m_pFontMap = pFontMap; }
SetFontSize(float fFontSize)81   void SetFontSize(float fFontSize) { m_fFontSize = fFontSize; }
GetPlateRect()82   CFX_FloatRect GetPlateRect() const { return m_rcPlate; }
83   void SetPlateRect(const CFX_FloatRect& rect);
84 
GetFontSize()85   float GetFontSize() const { return m_fFontSize; }
86   CPWL_EditImpl* GetItemEdit(int32_t nIndex) const;
87   int32_t GetCount() const;
88   bool IsItemSelected(int32_t nIndex) const;
89   float GetFirstHeight() const;
SetMultipleSel(bool bMultiple)90   void SetMultipleSel(bool bMultiple) { m_bMultiple = bMultiple; }
IsMultipleSel()91   bool IsMultipleSel() const { return m_bMultiple; }
92   int32_t FindNext(int32_t nIndex, wchar_t nChar) const;
93   int32_t GetFirstSelected() const;
94 
95  private:
96   class Item {
97    public:
98     Item();
99     ~Item();
100 
101     void SetFontMap(IPVT_FontMap* pFontMap);
GetEdit()102     CPWL_EditImpl* GetEdit() const { return m_pEdit.get(); }
103 
SetRect(const CFX_FloatRect & rect)104     void SetRect(const CFX_FloatRect& rect) { m_rcListItem = rect; }
SetSelect(bool bSelected)105     void SetSelect(bool bSelected) { m_bSelected = bSelected; }
106     void SetText(const WideString& text);
107     void SetFontSize(float fFontSize);
108     WideString GetText() const;
109 
GetRect()110     CFX_FloatRect GetRect() const { return m_rcListItem; }
IsSelected()111     bool IsSelected() const { return m_bSelected; }
112     float GetItemHeight() const;
113     uint16_t GetFirstChar() const;
114 
115    private:
116     CPWL_EditImpl_Iterator* GetIterator() const;
117 
118     bool m_bSelected = false;
119     CFX_FloatRect m_rcListItem;
120     std::unique_ptr<CPWL_EditImpl> const m_pEdit;
121   };
122 
123   CFX_PointF InToOut(const CFX_PointF& point) const;
124   CFX_PointF OutToIn(const CFX_PointF& point) const;
125   CFX_FloatRect InToOut(const CFX_FloatRect& rect) const;
126   CFX_FloatRect OutToIn(const CFX_FloatRect& rect) const;
127 
128   CFX_PointF InnerToOuter(const CFX_PointF& point) const;
129   CFX_PointF OuterToInner(const CFX_PointF& point) const;
130   CFX_FloatRect InnerToOuter(const CFX_FloatRect& rect) const;
131   CFX_FloatRect OuterToInner(const CFX_FloatRect& rect) const;
132 
133   void OnVK(int32_t nItemIndex, bool bShift, bool bCtrl);
134   bool IsValid(int32_t nItemIndex) const;
135 
136   void ReArrange(int32_t nItemIndex);
137   CFX_FloatRect GetItemRectInternal(int32_t nIndex) const;
138   CFX_FloatRect GetContentRectInternal() const;
139   void SetMultipleSelect(int32_t nItemIndex, bool bSelected);
140   void SetSingleSelect(int32_t nItemIndex);
141   void InvalidateItem(int32_t nItemIndex);
142   void SelectItems();
143   bool IsItemVisible(int32_t nItemIndex) const;
144   void SetScrollInfo();
145   void SetScrollPosY(float fy);
146   void AddItem(const WideString& str);
147   WideString GetItemText(int32_t nIndex) const;
148   void SetItemSelect(int32_t nIndex, bool bSelected);
149   int32_t GetLastSelected() const;
GetBTPoint()150   CFX_PointF GetBTPoint() const {
151     return CFX_PointF(m_rcPlate.left, m_rcPlate.top);
152   }
153 
154   CFX_FloatRect m_rcPlate;
155   CFX_FloatRect m_rcContent;
156   UnownedPtr<CPWL_List_Notify> m_pNotify;
157   bool m_bNotifyFlag;
158   CFX_PointF m_ptScrollPos;
159   CPLST_Select m_aSelItems;  // for multiple
160   int32_t m_nSelItem;        // for single
161   int32_t m_nFootIndex;      // for multiple
162   bool m_bCtrlSel;           // for multiple
163   int32_t m_nCaretIndex;     // for multiple
164   std::vector<std::unique_ptr<Item>> m_ListItems;
165   float m_fFontSize;
166   UnownedPtr<IPVT_FontMap> m_pFontMap;
167   bool m_bMultiple;
168 };
169 
170 #endif  // FPDFSDK_PWL_CPWL_LIST_IMPL_H_
171