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.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
17 CLST_Size() : x(0.0f), y(0.0f)
21 CLST_Size(FX_FLOAT x,FX_FLOAT y)
33 FX_BOOL operator != (const CLST_Size & size) const
35 return FXSYS_memcmp(this, &size, sizeof(CLST_Size)) != 0;
41 class CLST_Rect : public CPDF_Rect
46 left = top = right = bottom = 0.0f;
49 CLST_Rect(FX_FLOAT left,FX_FLOAT top,
50 FX_FLOAT right,FX_FLOAT bottom)
55 this->bottom = bottom;
58 CLST_Rect(const CPDF_Rect & rect)
60 this->left = rect.left;
62 this->right = rect.right;
63 this->bottom = rect.bottom;
68 left = top = right = bottom = 0.0f;
71 const CLST_Rect operator = (const CPDF_Rect & rect)
73 this->left = rect.left;
75 this->right = rect.right;
76 this->bottom = rect.bottom;
81 FX_BOOL operator == (const CLST_Rect & rect) const
83 return FXSYS_memcmp(this, &rect, sizeof(CLST_Rect)) == 0;
86 FX_BOOL operator != (const CLST_Rect & rect) const
88 return FXSYS_memcmp(this, &rect, sizeof(CLST_Rect)) != 0;
91 FX_FLOAT Width() const
93 return this->right - this->left;
96 FX_FLOAT Height() const
98 if (this->top > this->bottom)
99 return this->top - this->bottom;
101 return this->bottom - this->top;
104 CPDF_Point LeftTop() const
106 return CPDF_Point(left,top);
109 CPDF_Point RightBottom() const
111 return CPDF_Point(right,bottom);
114 const CLST_Rect operator += (const CPDF_Point & point)
116 this->left += point.x;
117 this->right += point.x;
118 this->top += point.y;
119 this->bottom += point.y;
124 const CLST_Rect operator -= (const CPDF_Point & point)
126 this->left -= point.x;
127 this->right -= point.x;
128 this->top -= point.y;
129 this->bottom -= point.y;
134 CLST_Rect operator + (const CPDF_Point & point) const
136 return CLST_Rect(left + point.x,
142 CLST_Rect operator - (const CPDF_Point & point) const
144 return CLST_Rect(left - point.x,
155 virtual ~CFX_ListItem();
157 void SetFontMap(IFX_Edit_FontMap * pFontMap);
158 IFX_Edit_Iterator* GetIterator() const;
159 IFX_Edit* GetEdit() const;
162 void SetRect(const CLST_Rect & rect);
163 void SetSelect(FX_BOOL bSelected);
164 void SetCaret(FX_BOOL bCaret);
165 void SetText(FX_LPCWSTR text);
166 void SetFontSize(FX_FLOAT fFontSize);
167 CFX_WideString GetText() const;
169 CLST_Rect GetRect() const;
170 FX_BOOL IsSelected() const;
171 FX_BOOL IsCaret() const;
172 FX_FLOAT GetItemHeight() const;
173 FX_WORD GetFirstChar() const;
179 CLST_Rect m_rcListItem;
182 class CFX_ListContainer
185 CFX_ListContainer() : m_rcPlate(0.0f,0.0f,0.0f,0.0f), m_rcContent(0.0f,0.0f,0.0f,0.0f){}
186 virtual ~CFX_ListContainer(){}
187 virtual void SetPlateRect(const CPDF_Rect & rect){m_rcPlate = rect;}
188 CPDF_Rect GetPlateRect() const{return m_rcPlate;}
189 void SetContentRect(const CLST_Rect & rect){m_rcContent = rect;}
190 CLST_Rect GetContentRect() const{return m_rcContent;}
191 CPDF_Point GetBTPoint() const{return CPDF_Point(m_rcPlate.left,m_rcPlate.top);}
192 CPDF_Point GetETPoint() const{return CPDF_Point(m_rcPlate.right,m_rcPlate.bottom);}
194 CPDF_Point InnerToOuter(const CPDF_Point & point) const{return CPDF_Point(point.x + GetBTPoint().x,GetBTPoint().y - point.y);}
195 CPDF_Point OuterToInner(const CPDF_Point & point) const{return CPDF_Point(point.x - GetBTPoint().x,GetBTPoint().y - point.y);}
196 CPDF_Rect InnerToOuter(const CLST_Rect & rect) const{CPDF_Point ptLeftTop = InnerToOuter(CPDF_Point(rect.left,rect.top));
197 CPDF_Point ptRightBottom = InnerToOuter(CPDF_Point(rect.right,rect.bottom));
198 return CPDF_Rect(ptLeftTop.x,ptRightBottom.y,ptRightBottom.x,ptLeftTop.y);}
199 CLST_Rect OuterToInner(const CPDF_Rect & rect) const{CPDF_Point ptLeftTop = OuterToInner(CPDF_Point(rect.left,rect.top));
200 CPDF_Point ptRightBottom = OuterToInner(CPDF_Point(rect.right,rect.bottom));
201 return CLST_Rect(ptLeftTop.x,ptLeftTop.y,ptRightBottom.x,ptRightBottom.y);}
204 CLST_Rect m_rcContent; //positive forever!
207 template<class TYPE> class CLST_ArrayTemplate : public CFX_ArrayTemplate<TYPE>
210 FX_BOOL IsEmpty() { return CFX_ArrayTemplate<TYPE>::GetSize() <= 0; }
211 TYPE GetAt(FX_INT32 nIndex) const { if (nIndex >= 0 && nIndex < CFX_ArrayTemplate<TYPE>::GetSize()) return CFX_ArrayTemplate<TYPE>::GetAt(nIndex); return NULL;}
212 void RemoveAt(FX_INT32 nIndex){if (nIndex >= 0 && nIndex < CFX_ArrayTemplate<TYPE>::GetSize()) CFX_ArrayTemplate<TYPE>::RemoveAt(nIndex);}
215 class CFX_List : protected CFX_ListContainer , public IFX_List
222 virtual void SetFontMap(IFX_Edit_FontMap * pFontMap);
223 virtual void SetFontSize(FX_FLOAT fFontSize);
225 virtual CPDF_Rect GetPlateRect() const;
226 virtual CPDF_Rect GetContentRect() const;
228 virtual FX_FLOAT GetFontSize() const;
229 virtual IFX_Edit* GetItemEdit(FX_INT32 nIndex) const;
230 virtual FX_INT32 GetCount() const;
231 virtual FX_BOOL IsItemSelected(FX_INT32 nIndex) const;
232 virtual FX_FLOAT GetFirstHeight() const;
234 virtual void SetMultipleSel(FX_BOOL bMultiple);
235 virtual FX_BOOL IsMultipleSel() const;
236 virtual FX_BOOL IsValid(FX_INT32 nItemIndex) const;
237 virtual FX_INT32 FindNext(FX_INT32 nIndex,FX_WCHAR nChar) const;
240 virtual void Empty();
242 void AddItem(FX_LPCWSTR str);
243 virtual void ReArrange(FX_INT32 nItemIndex);
245 virtual CPDF_Rect GetItemRect(FX_INT32 nIndex) const;
246 CFX_WideString GetItemText(FX_INT32 nIndex) const;
248 void SetItemSelect(FX_INT32 nItemIndex, FX_BOOL bSelected);
249 void SetItemCaret(FX_INT32 nItemIndex, FX_BOOL bCaret);
251 virtual FX_INT32 GetItemIndex(const CPDF_Point & point) const;
252 FX_INT32 GetFirstSelected() const;
253 FX_INT32 GetLastSelected() const;
254 FX_WCHAR Toupper(FX_WCHAR c) const;
257 CLST_ArrayTemplate<CFX_ListItem*> m_aListItems;
258 FX_FLOAT m_fFontSize;
259 IFX_Edit_FontMap* m_pFontMap;
263 struct CPLST_Select_Item
265 CPLST_Select_Item(FX_INT32 nItemIndex,FX_INT32 nState)
267 this->nItemIndex = nItemIndex;
268 this->nState = nState;
272 FX_INT32 nState; //0:normal select -1:to deselect 1: to select
279 virtual ~CPLST_Select();
282 void Add(FX_INT32 nItemIndex);
283 void Add(FX_INT32 nBeginIndex, FX_INT32 nEndIndex);
284 void Sub(FX_INT32 nItemIndex);
285 void Sub(FX_INT32 nBeginIndex, FX_INT32 nEndIndex);
286 FX_BOOL IsExist(FX_INT32 nItemIndex) const;
287 FX_INT32 Find(FX_INT32 nItemIndex) const;
288 FX_INT32 GetCount() const;
289 FX_INT32 GetItemIndex(FX_INT32 nIndex) const;
290 FX_INT32 GetState(FX_INT32 nIndex) const;
295 CFX_ArrayTemplate<CPLST_Select_Item*> m_aItems;
298 class CFX_ListCtrl : public CFX_List
302 virtual ~CFX_ListCtrl();
305 void SetNotify(IFX_List_Notify * pNotify);
307 void OnMouseDown(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl);
308 void OnMouseMove(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl);
309 void OnVK_UP(FX_BOOL bShift,FX_BOOL bCtrl);
310 void OnVK_DOWN(FX_BOOL bShift,FX_BOOL bCtrl);
311 void OnVK_LEFT(FX_BOOL bShift,FX_BOOL bCtrl);
312 void OnVK_RIGHT(FX_BOOL bShift,FX_BOOL bCtrl);
313 void OnVK_HOME(FX_BOOL bShift,FX_BOOL bCtrl);
314 void OnVK_END(FX_BOOL bShift,FX_BOOL bCtrl);
315 void OnVK(FX_INT32 nItemIndex,FX_BOOL bShift,FX_BOOL bCtrl);
316 FX_BOOL OnChar(FX_WORD nChar,FX_BOOL bShift,FX_BOOL bCtrl);
318 virtual CPDF_Point InToOut(const CPDF_Point & point) const;
319 virtual CPDF_Point OutToIn(const CPDF_Point & point) const;
320 virtual CPDF_Rect InToOut(const CPDF_Rect & rect) const;
321 virtual CPDF_Rect OutToIn(const CPDF_Rect & rect) const;
323 virtual void SetPlateRect(const CPDF_Rect & rect);
324 void SetScrollPos(const CPDF_Point & point);
325 void ScrollToListItem(FX_INT32 nItemIndex);
326 virtual CPDF_Rect GetItemRect(FX_INT32 nIndex) const;
327 FX_INT32 GetCaret() const {return m_nCaretIndex;}
328 FX_INT32 GetSelect() const {return m_nSelItem;}
329 FX_INT32 GetTopItem() const;
330 virtual CPDF_Rect GetContentRect() const;
331 virtual FX_INT32 GetItemIndex(const CPDF_Point & point) const;
333 void AddString(FX_LPCWSTR string);
334 void SetTopItem(FX_INT32 nIndex);
335 void Select(FX_INT32 nItemIndex);
336 virtual void SetCaret(FX_INT32 nItemIndex);
337 virtual void Empty();
338 virtual void Cancel();
339 CFX_WideString GetText() const;
342 void SetMultipleSelect(FX_INT32 nItemIndex, FX_BOOL bSelected);
343 void SetSingleSelect(FX_INT32 nItemIndex);
344 void InvalidateItem(FX_INT32 nItemIndex);
346 FX_BOOL IsItemVisible(FX_INT32 nItemIndex) const;
347 void SetScrollInfo();
348 void SetScrollPosY(FX_FLOAT fy);
349 virtual void ReArrange(FX_INT32 nItemIndex);
352 IFX_List_Notify* m_pNotify;
353 FX_BOOL m_bNotifyFlag;
354 CPDF_Point m_ptScrollPos;
355 CPLST_Select m_aSelItems; //for multiple
356 FX_INT32 m_nSelItem; //for single
357 FX_INT32 m_nFootIndex; //for multiple
358 FX_BOOL m_bCtrlSel; //for multiple
359 FX_INT32 m_nCaretIndex; //for multiple