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_INCLUDE_PDFWINDOW_PWL_ICONLIST_H_
8 #define FPDFSDK_INCLUDE_PDFWINDOW_PWL_ICONLIST_H_
9 
10 #include "../../../core/include/fxcrt/fx_string.h"
11 #include "PWL_ListCtrl.h"
12 #include "PWL_Wnd.h"
13 
14 class IPWL_IconList_Notify;
15 class CPWL_IconList_Item;
16 class CPWL_IconList_Content;
17 class CPWL_IconList;
18 class CPWL_Label;
19 
20 class IPWL_IconList_Notify
21 {
22 public:
~IPWL_IconList_Notify()23         virtual ~IPWL_IconList_Notify() { }
24 	virtual void						OnNoteListSelChanged(FX_INT32 nItemIndex) = 0;
25 };
26 
27 class CPWL_IconList_Item : public CPWL_Wnd
28 {
29 public:
30 	CPWL_IconList_Item();
31 	virtual ~CPWL_IconList_Item();
32 
33 	virtual CFX_ByteString				GetClassName() const;
34 	virtual void						CreateChildWnd(const PWL_CREATEPARAM & cp);
35 	virtual void						RePosChildWnd();
36 
37 	void								SetSelect(FX_BOOL bSelected);
38 	FX_BOOL								IsSelected() const;
39 	void								SetData(void* pData);
40 	void								SetIcon(FX_INT32 nIconIndex);
41 	void								SetText(const CFX_WideString& str);
42 	void								SetIconFillColor(const CPWL_Color& color);
43 	CFX_WideString						GetText() const;
44 
45 protected:
46 	virtual FX_FLOAT					GetItemHeight(FX_FLOAT fLimitWidth);
47 	virtual void						DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device);
48 
49 	virtual void						OnEnabled();
50 	virtual void						OnDisabled();
51 
52 private:
53 	FX_INT32							m_nIconIndex;
54 	void*								m_pData;
55 	FX_BOOL								m_bSelected;
56 	CPWL_Label*							m_pText;
57 	CPWL_Color							m_crIcon;
58 };
59 
60 class CPWL_IconList_Content : public CPWL_ListCtrl
61 {
62 public:
63 	CPWL_IconList_Content(FX_INT32 nListCount);
64 	virtual ~CPWL_IconList_Content();
65 
66 	void								SetSelect(FX_INT32 nIndex);
67 	FX_INT32							GetSelect() const;
68 	void								SetNotify(IPWL_IconList_Notify* pNotify);
69 	void								EnableNotify(FX_BOOL bNotify);
70 	void								SetListData(FX_INT32 nItemIndex, void* pData);
71 	void								SetListIcon(FX_INT32 nItemIndex, FX_INT32 nIconIndex);
72 	void								SetListString(FX_INT32 nItemIndex, const CFX_WideString& str);
73 	void								SetIconFillColor(const CPWL_Color& color);
74 	CFX_WideString						GetListString(FX_INT32 nItemIndex) const;
75 	IPWL_IconList_Notify*				GetNotify() const;
76 	void								ScrollToItem(FX_INT32 nItemIndex);
77 
78 protected:
79 	virtual void						CreateChildWnd(const PWL_CREATEPARAM & cp);
80 	virtual FX_BOOL						OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag);
81 	virtual FX_BOOL						OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag);
82 	virtual FX_BOOL						OnMouseMove(const CPDF_Point & point, FX_DWORD nFlag);
83 	virtual FX_BOOL						OnKeyDown(FX_WORD nChar, FX_DWORD nFlag);
84 
85 private:
86 	CPWL_IconList_Item*					GetListItem(FX_INT32 nItemIndex) const;
87 	void								SelectItem(FX_INT32 nItemIndex, FX_BOOL bSelect);
88 	FX_INT32							FindItemIndex(const CPDF_Point& point);
89 
90 	FX_BOOL								m_nSelectIndex;
91 	IPWL_IconList_Notify*				m_pNotify;
92 	FX_BOOL								m_bEnableNotify;
93 	FX_BOOL								m_bMouseDown;
94 	FX_INT32							m_nListCount;
95 };
96 
97 class PWL_CLASS CPWL_IconList : public CPWL_Wnd
98 {
99 public:
100 	CPWL_IconList(FX_INT32 nListCount);
101 	virtual ~CPWL_IconList();
102 
103 	virtual FX_BOOL						OnMouseWheel(short zDelta, const CPDF_Point & point, FX_DWORD nFlag);
104 
105 	void								SetSelect(FX_INT32 nIndex);
106 	void								SetTopItem(FX_INT32 nIndex);
107 	FX_INT32							GetSelect() const;
108 	void								SetNotify(IPWL_IconList_Notify* pNotify);
109 	void								EnableNotify(FX_BOOL bNotify);
110 	void								SetListData(FX_INT32 nItemIndex, void* pData);
111 	void								SetListIcon(FX_INT32 nItemIndex, FX_INT32 nIconIndex);
112 	void								SetListString(FX_INT32 nItemIndex, const CFX_WideString& str);
113 	void								SetIconFillColor(const CPWL_Color& color);
114 	CFX_WideString						GetListString(FX_INT32 nItemIndex) const;
115 
116 protected:
117 	virtual void						OnCreated();
118 	virtual void						RePosChildWnd();
119 	virtual void						CreateChildWnd(const PWL_CREATEPARAM & cp);
120 
121 	virtual void						OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam = 0, FX_INTPTR lParam = 0);
122 
123 private:
124 	CPWL_IconList_Content*				m_pListContent;
125 	FX_INT32							m_nListCount;
126 };
127 
128 #endif  // FPDFSDK_INCLUDE_PDFWINDOW_PWL_ICONLIST_H_
129