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