• 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 {
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   virtual ~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 SetCaret(int32_t nItemIndex);
75   void Empty();
76   void Cancel();
77   WideString GetText() const;
78 
SetFontMap(IPVT_FontMap * pFontMap)79   void SetFontMap(IPVT_FontMap* pFontMap) { m_pFontMap = pFontMap; }
SetFontSize(float fFontSize)80   void SetFontSize(float fFontSize) { m_fFontSize = fFontSize; }
GetPlateRect()81   CFX_FloatRect GetPlateRect() const { return m_rcPlate; }
82   void SetPlateRect(const CFX_FloatRect& rect);
83 
GetFontSize()84   float GetFontSize() const { return m_fFontSize; }
85   CPWL_EditImpl* GetItemEdit(int32_t nIndex) const;
86   int32_t GetCount() const;
87   bool IsItemSelected(int32_t nIndex) const;
88   float GetFirstHeight() const;
SetMultipleSel(bool bMultiple)89   void SetMultipleSel(bool bMultiple) { m_bMultiple = bMultiple; }
IsMultipleSel()90   bool IsMultipleSel() const { return m_bMultiple; }
91   int32_t FindNext(int32_t nIndex, wchar_t nChar) const;
92   int32_t GetFirstSelected() const;
93 
94  private:
95   class Item {
96    public:
97     Item();
98     ~Item();
99 
100     void SetFontMap(IPVT_FontMap* pFontMap);
GetEdit()101     CPWL_EditImpl* GetEdit() const { return m_pEdit.get(); }
102 
SetRect(const CFX_FloatRect & rect)103     void SetRect(const CFX_FloatRect& rect) { m_rcListItem = rect; }
SetSelect(bool bSelected)104     void SetSelect(bool bSelected) { m_bSelected = bSelected; }
105     void SetText(const WideString& text);
106     void SetFontSize(float fFontSize);
107     WideString GetText() const;
108 
GetRect()109     CFX_FloatRect GetRect() const { return m_rcListItem; }
IsSelected()110     bool IsSelected() const { return m_bSelected; }
111     float GetItemHeight() const;
112     uint16_t GetFirstChar() const;
113 
114    private:
115     CPWL_EditImpl_Iterator* GetIterator() const;
116 
117     std::unique_ptr<CPWL_EditImpl> m_pEdit;
118     bool m_bSelected;
119     CFX_FloatRect m_rcListItem;
120   };
121 
122   CFX_PointF InToOut(const CFX_PointF& point) const;
123   CFX_PointF OutToIn(const CFX_PointF& point) const;
124   CFX_FloatRect InToOut(const CFX_FloatRect& rect) const;
125   CFX_FloatRect OutToIn(const CFX_FloatRect& rect) const;
126 
127   CFX_PointF InnerToOuter(const CFX_PointF& point) const;
128   CFX_PointF OuterToInner(const CFX_PointF& point) const;
129   CFX_FloatRect InnerToOuter(const CFX_FloatRect& rect) const;
130   CFX_FloatRect OuterToInner(const CFX_FloatRect& rect) const;
131 
132   void OnVK(int32_t nItemIndex, bool bShift, bool bCtrl);
133   bool IsValid(int32_t nItemIndex) const;
134 
135   void ReArrange(int32_t nItemIndex);
136   CFX_FloatRect GetItemRectInternal(int32_t nIndex) const;
137   CFX_FloatRect GetContentRectInternal() const;
138   void SetMultipleSelect(int32_t nItemIndex, bool bSelected);
139   void SetSingleSelect(int32_t nItemIndex);
140   void InvalidateItem(int32_t nItemIndex);
141   void SelectItems();
142   bool IsItemVisible(int32_t nItemIndex) const;
143   void SetScrollInfo();
144   void SetScrollPosY(float fy);
145   void AddItem(const WideString& str);
146   WideString GetItemText(int32_t nIndex) const;
147   void SetItemSelect(int32_t nItemIndex, bool bSelected);
148   int32_t GetLastSelected() const;
GetBTPoint()149   CFX_PointF GetBTPoint() const {
150     return CFX_PointF(m_rcPlate.left, m_rcPlate.top);
151   }
152 
153   CFX_FloatRect m_rcPlate;
154   CFX_FloatRect m_rcContent;
155   UnownedPtr<CPWL_List_Notify> m_pNotify;
156   bool m_bNotifyFlag;
157   CFX_PointF m_ptScrollPos;
158   CPLST_Select m_aSelItems;  // for multiple
159   int32_t m_nSelItem;        // for single
160   int32_t m_nFootIndex;      // for multiple
161   bool m_bCtrlSel;           // for multiple
162   int32_t m_nCaretIndex;     // for multiple
163   std::vector<std::unique_ptr<Item>> m_ListItems;
164   float m_fFontSize;
165   UnownedPtr<IPVT_FontMap> m_pFontMap;
166   bool m_bMultiple;
167 };
168 
169 #endif  // FPDFSDK_PWL_CPWL_LIST_IMPL_H_
170