Initial commit.
[pdfium.git] / fpdfsdk / include / fxedit / fxet_list.h
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4  \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #ifndef _FXET_LIST_H_\r
8 #define _FXET_LIST_H_\r
9 \r
10 #include "fx_edit.h"\r
11 \r
12 class IFX_Edit;\r
13 \r
14 class CLST_Size\r
15 {\r
16 public:\r
17         CLST_Size() : x(0.0f), y(0.0f)\r
18         {               \r
19         }\r
20 \r
21         CLST_Size(FX_FLOAT x,FX_FLOAT y)\r
22         { \r
23                 this->x = x;\r
24                 this->y = y;\r
25         }\r
26 \r
27         void Default()\r
28         {\r
29                 x = 0.0f;\r
30                 y = 0.0f;\r
31         }\r
32 \r
33         FX_BOOL operator != (const CLST_Size & size) const\r
34         {\r
35                 return FXSYS_memcmp(this, &size, sizeof(CLST_Size)) != 0;\r
36         }\r
37 \r
38         FX_FLOAT x,y;\r
39 };\r
40 \r
41 class CLST_Rect : public CPDF_Rect\r
42 {\r
43 public:\r
44         CLST_Rect()\r
45         {       \r
46                 left = top = right = bottom = 0.0f;\r
47         }\r
48 \r
49         CLST_Rect(FX_FLOAT left,FX_FLOAT top,\r
50                                                 FX_FLOAT right,FX_FLOAT bottom)\r
51         { \r
52                 this->left = left; \r
53                 this->top = top; \r
54                 this->right = right; \r
55                 this->bottom = bottom; \r
56         }\r
57 \r
58         CLST_Rect(const CPDF_Rect & rect)\r
59         { \r
60                 this->left = rect.left; \r
61                 this->top = rect.top; \r
62                 this->right = rect.right; \r
63                 this->bottom = rect.bottom; \r
64         }\r
65 \r
66         void Default()\r
67         {\r
68                 left = top = right = bottom = 0.0f;\r
69         }\r
70 \r
71         const CLST_Rect operator = (const CPDF_Rect & rect)\r
72         {\r
73                 this->left = rect.left;\r
74                 this->top = rect.top;\r
75                 this->right = rect.right;\r
76                 this->bottom = rect.bottom;\r
77 \r
78                 return *this;\r
79         }\r
80 \r
81         FX_BOOL operator == (const CLST_Rect & rect) const\r
82         {\r
83                 return FXSYS_memcmp(this, &rect, sizeof(CLST_Rect)) == 0;\r
84         }\r
85 \r
86         FX_BOOL operator != (const CLST_Rect & rect) const\r
87         {\r
88                 return FXSYS_memcmp(this, &rect, sizeof(CLST_Rect)) != 0;\r
89         }\r
90 \r
91         FX_FLOAT Width() const\r
92         {\r
93                 return this->right - this->left;\r
94         }\r
95 \r
96         FX_FLOAT Height() const\r
97         {\r
98                 if (this->top > this->bottom)\r
99                         return this->top - this->bottom;\r
100                 else\r
101                         return this->bottom - this->top;\r
102         }\r
103 \r
104         CPDF_Point LeftTop() const\r
105         {\r
106                 return CPDF_Point(left,top);\r
107         }\r
108 \r
109         CPDF_Point RightBottom() const\r
110         {\r
111                 return CPDF_Point(right,bottom);\r
112         }\r
113 \r
114         const CLST_Rect operator += (const CPDF_Point & point) \r
115         {\r
116                 this->left += point.x;\r
117                 this->right += point.x;\r
118                 this->top += point.y;\r
119                 this->bottom += point.y;\r
120 \r
121                 return *this;\r
122         }\r
123 \r
124         const CLST_Rect operator -= (const CPDF_Point & point) \r
125         {\r
126                 this->left -= point.x;\r
127                 this->right -= point.x;\r
128                 this->top -= point.y;\r
129                 this->bottom -= point.y;\r
130 \r
131                 return *this;\r
132         }\r
133 \r
134         CLST_Rect operator + (const CPDF_Point & point) const\r
135         {\r
136                 return CLST_Rect(left + point.x,\r
137                                         top + point.y,\r
138                                         right + point.x,\r
139                                         bottom + point.y);\r
140         }\r
141 \r
142         CLST_Rect operator - (const CPDF_Point & point) const\r
143         {\r
144                 return CLST_Rect(left - point.x,\r
145                                         top - point.y,\r
146                                         right - point.x,\r
147                                         bottom - point.y);\r
148         }\r
149 };\r
150 \r
151 class CFX_ListItem\r
152 {\r
153 public:\r
154         CFX_ListItem();\r
155         virtual ~CFX_ListItem();\r
156 \r
157         void                                                    SetFontMap(IFX_Edit_FontMap * pFontMap);\r
158         IFX_Edit_Iterator*                              GetIterator() const;\r
159         IFX_Edit*                                               GetEdit() const;\r
160 \r
161 public:\r
162         void                                                    SetRect(const CLST_Rect & rect);                \r
163         void                                                    SetSelect(FX_BOOL bSelected);   \r
164         void                                                    SetCaret(FX_BOOL bCaret);\r
165         void                                                    SetText(FX_LPCWSTR text);\r
166         void                                                    SetFontSize(FX_FLOAT fFontSize);\r
167         CFX_WideString                                  GetText() const;\r
168 \r
169         CLST_Rect                                               GetRect() const;\r
170         FX_BOOL                                                 IsSelected() const;\r
171         FX_BOOL                                                 IsCaret() const;\r
172         FX_FLOAT                                                GetItemHeight() const;  \r
173         FX_WORD                                                 GetFirstChar() const;\r
174 \r
175 private:\r
176         IFX_Edit*                                               m_pEdit;\r
177         FX_BOOL                                                 m_bSelected;            //ÊÇ·ñÑ¡ÖÐ\r
178         FX_BOOL                                                 m_bCaret;               //ÊÇ·ñΪ½¹µã£¬¶àѡʱÓÃ\r
179         CLST_Rect                                               m_rcListItem;   //ÄÚ²¿×ø±ê\r
180 };\r
181 \r
182 class CFX_ListContainer\r
183 {\r
184 public:\r
185         CFX_ListContainer() : m_rcPlate(0.0f,0.0f,0.0f,0.0f), m_rcContent(0.0f,0.0f,0.0f,0.0f){}\r
186         virtual ~CFX_ListContainer(){}\r
187         virtual void                                    SetPlateRect(const CPDF_Rect & rect){m_rcPlate = rect;}\r
188         CPDF_Rect                                               GetPlateRect() const{return m_rcPlate;}\r
189         void                                                    SetContentRect(const CLST_Rect & rect){m_rcContent = rect;}\r
190         CLST_Rect                                               GetContentRect() const{return m_rcContent;}\r
191         CPDF_Point                                              GetBTPoint() const{return CPDF_Point(m_rcPlate.left,m_rcPlate.top);}\r
192         CPDF_Point                                              GetETPoint() const{return CPDF_Point(m_rcPlate.right,m_rcPlate.bottom);}\r
193 public:\r
194         CPDF_Point                                              InnerToOuter(const CPDF_Point & point) const{return CPDF_Point(point.x + GetBTPoint().x,GetBTPoint().y - point.y);}\r
195         CPDF_Point                                              OuterToInner(const CPDF_Point & point) const{return CPDF_Point(point.x - GetBTPoint().x,GetBTPoint().y - point.y);}\r
196         CPDF_Rect                                               InnerToOuter(const CLST_Rect & rect) const{CPDF_Point ptLeftTop = InnerToOuter(CPDF_Point(rect.left,rect.top));\r
197                                                                                                                                                         CPDF_Point ptRightBottom = InnerToOuter(CPDF_Point(rect.right,rect.bottom));\r
198                                                                                                                                                         return CPDF_Rect(ptLeftTop.x,ptRightBottom.y,ptRightBottom.x,ptLeftTop.y);}\r
199         CLST_Rect                                               OuterToInner(const CPDF_Rect & rect) const{CPDF_Point ptLeftTop = OuterToInner(CPDF_Point(rect.left,rect.top));\r
200                                                                                                                                                         CPDF_Point ptRightBottom = OuterToInner(CPDF_Point(rect.right,rect.bottom));\r
201                                                                                                                                                         return CLST_Rect(ptLeftTop.x,ptLeftTop.y,ptRightBottom.x,ptRightBottom.y);}\r
202 private:\r
203         CPDF_Rect                                               m_rcPlate;      \r
204         CLST_Rect                                               m_rcContent;            //positive forever!\r
205 };\r
206 \r
207 template<class TYPE> class CLST_ArrayTemplate : public CFX_ArrayTemplate<TYPE>\r
208 {\r
209 public: \r
210         FX_BOOL IsEmpty() { return CFX_ArrayTemplate<TYPE>::GetSize() <= 0; }\r
211         TYPE GetAt(FX_INT32 nIndex) const { if (nIndex >= 0 && nIndex < CFX_ArrayTemplate<TYPE>::GetSize()) return CFX_ArrayTemplate<TYPE>::GetAt(nIndex); return NULL;}\r
212         void RemoveAt(FX_INT32 nIndex){if (nIndex >= 0 && nIndex < CFX_ArrayTemplate<TYPE>::GetSize()) CFX_ArrayTemplate<TYPE>::RemoveAt(nIndex);}\r
213 };\r
214 \r
215 class CFX_List : protected CFX_ListContainer , public IFX_List\r
216 {\r
217 public:\r
218         CFX_List();\r
219         virtual ~CFX_List();\r
220 \r
221 public:\r
222         virtual void                                    SetFontMap(IFX_Edit_FontMap * pFontMap);\r
223         virtual void                                    SetFontSize(FX_FLOAT fFontSize);\r
224 \r
225         virtual CPDF_Rect                               GetPlateRect() const;\r
226         virtual CPDF_Rect                               GetContentRect() const;\r
227 \r
228         virtual FX_FLOAT                                GetFontSize() const;\r
229         virtual IFX_Edit*                               GetItemEdit(FX_INT32 nIndex) const;\r
230         virtual FX_INT32                                GetCount() const;\r
231         virtual FX_BOOL                                 IsItemSelected(FX_INT32 nIndex) const;\r
232         virtual FX_FLOAT                                GetFirstHeight() const;\r
233         \r
234         virtual void                                    SetMultipleSel(FX_BOOL bMultiple);\r
235         virtual FX_BOOL                                 IsMultipleSel() const;  \r
236         virtual FX_BOOL                                 IsValid(FX_INT32 nItemIndex) const;\r
237         virtual FX_INT32                                FindNext(FX_INT32 nIndex,FX_WCHAR nChar) const; \r
238 \r
239 protected:\r
240         virtual void                                    Empty();\r
241 \r
242         void                                                    AddItem(FX_LPCWSTR str);\r
243         virtual void                                    ReArrange(FX_INT32 nItemIndex); \r
244 \r
245         virtual CPDF_Rect                               GetItemRect(FX_INT32 nIndex) const;     \r
246         CFX_WideString                                  GetItemText(FX_INT32 nIndex) const;\r
247 \r
248         void                                                    SetItemSelect(FX_INT32 nItemIndex, FX_BOOL bSelected);\r
249         void                                                    SetItemCaret(FX_INT32 nItemIndex, FX_BOOL bCaret);\r
250 \r
251         virtual FX_INT32                                GetItemIndex(const CPDF_Point & point) const;           \r
252         FX_INT32                                                GetFirstSelected() const;\r
253         FX_INT32                                                GetLastSelected() const;\r
254         FX_WCHAR                                                Toupper(FX_WCHAR c) const;\r
255                 \r
256 private:\r
257         CLST_ArrayTemplate<CFX_ListItem*>       m_aListItems;\r
258         FX_FLOAT                                                        m_fFontSize;\r
259         IFX_Edit_FontMap*                                       m_pFontMap;\r
260         FX_BOOL                                                         m_bMultiple;    \r
261 };\r
262 \r
263 struct CPLST_Select_Item\r
264 {\r
265         CPLST_Select_Item(FX_INT32 nItemIndex,FX_INT32 nState)\r
266         {\r
267                 this->nItemIndex = nItemIndex;\r
268                 this->nState = nState;\r
269         }\r
270 \r
271         FX_INT32                nItemIndex;\r
272         FX_INT32                nState; //0:normal select -1:to deselect 1: to select\r
273 };\r
274 \r
275 class CPLST_Select\r
276 {\r
277 public:\r
278         CPLST_Select();\r
279         virtual ~CPLST_Select();\r
280 \r
281 public:\r
282         void                                                    Add(FX_INT32 nItemIndex);\r
283         void                                                    Add(FX_INT32 nBeginIndex, FX_INT32 nEndIndex);\r
284         void                                                    Sub(FX_INT32 nItemIndex);\r
285         void                                                    Sub(FX_INT32 nBeginIndex, FX_INT32 nEndIndex);\r
286         FX_BOOL                                                 IsExist(FX_INT32 nItemIndex) const;\r
287         FX_INT32                                                Find(FX_INT32 nItemIndex) const;\r
288         FX_INT32                                                GetCount() const;\r
289         FX_INT32                                                GetItemIndex(FX_INT32 nIndex) const;\r
290         FX_INT32                                                GetState(FX_INT32 nIndex) const;\r
291         void                                                    Done();\r
292         void                                                    DeselectAll();\r
293 \r
294 private:\r
295         CFX_ArrayTemplate<CPLST_Select_Item*>   m_aItems;\r
296 };\r
297 \r
298 class CFX_ListCtrl : public CFX_List\r
299 {\r
300 public:\r
301         CFX_ListCtrl();\r
302         virtual ~CFX_ListCtrl();\r
303 \r
304 public:\r
305         void                                                    SetNotify(IFX_List_Notify * pNotify);\r
306 \r
307         void                                                    OnMouseDown(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl);\r
308         void                                                    OnMouseMove(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl);\r
309         void                                                    OnVK_UP(FX_BOOL bShift,FX_BOOL bCtrl);\r
310         void                                                    OnVK_DOWN(FX_BOOL bShift,FX_BOOL bCtrl);\r
311         void                                                    OnVK_LEFT(FX_BOOL bShift,FX_BOOL bCtrl);\r
312         void                                                    OnVK_RIGHT(FX_BOOL bShift,FX_BOOL bCtrl);\r
313         void                                                    OnVK_HOME(FX_BOOL bShift,FX_BOOL bCtrl);\r
314         void                                                    OnVK_END(FX_BOOL bShift,FX_BOOL bCtrl);\r
315         void                                                    OnVK(FX_INT32 nItemIndex,FX_BOOL bShift,FX_BOOL bCtrl);\r
316         FX_BOOL                                                 OnChar(FX_WORD nChar,FX_BOOL bShift,FX_BOOL bCtrl);\r
317 \r
318         virtual CPDF_Point                              InToOut(const CPDF_Point & point) const;\r
319         virtual CPDF_Point                              OutToIn(const CPDF_Point & point) const;\r
320         virtual CPDF_Rect                               InToOut(const CPDF_Rect & rect) const;\r
321         virtual CPDF_Rect                               OutToIn(const CPDF_Rect & rect) const;\r
322 \r
323         virtual void                                    SetPlateRect(const CPDF_Rect & rect);\r
324         void                                                    SetScrollPos(const CPDF_Point & point);\r
325         void                                                    ScrollToListItem(FX_INT32 nItemIndex);\r
326         virtual CPDF_Rect                               GetItemRect(FX_INT32 nIndex) const;\r
327         FX_INT32                                                GetCaret() const {return m_nCaretIndex;}\r
328         FX_INT32                                                GetSelect() const {return m_nSelItem;}  \r
329         FX_INT32                                                GetTopItem() const;\r
330         virtual CPDF_Rect                               GetContentRect() const;\r
331         virtual FX_INT32                                GetItemIndex(const CPDF_Point & point) const;\r
332 \r
333         void                                                    AddString(FX_LPCWSTR string);\r
334         void                                                    SetTopItem(FX_INT32 nIndex);    \r
335         void                                                    Select(FX_INT32 nItemIndex);\r
336         virtual void                                    SetCaret(FX_INT32 nItemIndex);\r
337         virtual void                                    Empty();\r
338         virtual void                                    Cancel();\r
339         CFX_WideString                                  GetText() const;\r
340 \r
341 private:\r
342         void                                                    SetMultipleSelect(FX_INT32 nItemIndex, FX_BOOL bSelected);\r
343         void                                                    SetSingleSelect(FX_INT32 nItemIndex);\r
344         void                                                    InvalidateItem(FX_INT32 nItemIndex);\r
345         void                                                    SelectItems();\r
346         FX_BOOL                                                 IsItemVisible(FX_INT32 nItemIndex) const;               \r
347         void                                                    SetScrollInfo();\r
348         void                                                    SetScrollPosY(FX_FLOAT fy);\r
349         virtual void                                    ReArrange(FX_INT32 nItemIndex); \r
350 \r
351 private:\r
352         IFX_List_Notify*                                m_pNotify;\r
353         FX_BOOL                                                 m_bNotifyFlag;\r
354         CPDF_Point                                              m_ptScrollPos;\r
355         CPLST_Select                                    m_aSelItems;    //for multiple\r
356         FX_INT32                                                m_nSelItem;             //for single\r
357         FX_INT32                                                m_nFootIndex;   //for multiple\r
358         FX_BOOL                                                 m_bCtrlSel;             //for multiple\r
359         FX_INT32                                                m_nCaretIndex;  //for multiple\r
360 };\r
361 \r
362 #endif\r
363 \r