25290928db802fa36a6df31c8a0b152dc370708f
[pdfium.git] / fpdfsdk / include / pdfwindow / PWL_Note.h
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 _PWL_NOTE_H_
8 #define _PWL_NOTE_H_
9
10 #include "PWL_Button.h"
11 #include "PWL_Edit.h"
12 #include "PWL_ListCtrl.h"
13 #include "PWL_ScrollBar.h"
14 #include "PWL_Wnd.h"
15
16 class CPWL_Label;
17 class CPWL_Note;
18 class CPWL_NoteItem;
19 class CPWL_Note_CloseBox;
20 class CPWL_Note_Contents;
21 class CPWL_Note_Edit;
22 class CPWL_Note_Icon;
23 class CPWL_Note_LBBox;
24 class CPWL_Note_Options;
25 class CPWL_Note_RBBox;
26 class IPWL_NoteHandler;
27 class IPWL_NoteItem;
28 class IPWL_NoteNotify;
29 class IPopup_Note;
30
31 class IPWL_NoteNotify
32 {
33 public:
34         virtual ~IPWL_NoteNotify() { }
35         virtual void                                            OnNoteMove(const FX_RECT& rtWin) = 0;
36         virtual void                                            OnNoteShow(FX_BOOL bShow) = 0;
37         virtual void                                            OnNoteActivate(FX_BOOL bActive) = 0;
38         virtual void                                            OnNoteClose() = 0;
39         virtual void                                            OnItemCreate(IPWL_NoteItem* pItem) = 0;
40         virtual void                                            OnItemDelete(IPWL_NoteItem* pItem) = 0;
41         virtual void                                            OnSetAuthorName(IPWL_NoteItem* pItem) = 0;
42         virtual void                                            OnSetBkColor(IPWL_NoteItem* pItem) = 0;
43         virtual void                                            OnSetContents(IPWL_NoteItem* pItem) = 0;
44         virtual void                                            OnSetDateTime(IPWL_NoteItem* pItem) = 0;
45         virtual void                                            OnSetSubjectName(IPWL_NoteItem* pItem) = 0;
46         virtual void                                            OnPopupMenu(FX_INT32 x, FX_INT32 y) = 0;
47         virtual void                                            OnPopupMenu(IPWL_NoteItem* pItem, FX_INT32 x, FX_INT32 y) = 0;
48 };
49
50 class IPWL_NoteHandler
51 {
52 public:
53         virtual ~IPWL_NoteHandler() { }
54         virtual void                                            OnNoteColorChanged(const CPWL_Color& color) = 0;
55 };
56
57 class IPWL_NoteItem
58 {
59 public:
60         virtual ~IPWL_NoteItem() { }
61         virtual void                                            SetPrivateData(void* pData) = 0;
62         virtual void                                            SetBkColor(const CPWL_Color& color) = 0;
63         virtual void                                            SetSubjectName(const CFX_WideString& sName) = 0;
64         virtual void                                            SetAuthorName(const CFX_WideString& sName) = 0;
65         virtual void                                            SetDateTime(FX_SYSTEMTIME time) = 0;
66         virtual void                                            SetContents(const CFX_WideString& sContents) = 0;
67
68         virtual IPWL_NoteItem*                          CreateSubItem() = 0;
69         virtual FX_INT32                                        CountSubItems() const = 0;
70         virtual IPWL_NoteItem*                          GetSubItems(FX_INT32 index) const = 0;
71         virtual void                                            DeleteSubItem(IPWL_NoteItem* pNoteItem) = 0;
72         virtual void                                            SetFocus() = 0;
73         
74         virtual IPWL_NoteItem*                          GetParentItem() const = 0;
75         virtual void*                                           GetPrivateData() const = 0;
76         virtual CFX_WideString                          GetAuthorName() const = 0;
77         virtual CPWL_Color                                      GetBkColor() const = 0;
78         virtual CFX_WideString                          GetContents() const = 0;
79         virtual FX_SYSTEMTIME                           GetDateTime() const = 0;
80         virtual CFX_WideString                          GetSubjectName() const = 0;
81
82         virtual CPWL_Edit*                                      GetEdit() const = 0;
83 };
84
85 class PWL_CLASS CPWL_Note_Icon : public CPWL_Wnd
86 {
87 public:
88         CPWL_Note_Icon();
89         virtual ~CPWL_Note_Icon();
90
91         void                                                            SetIconType(FX_INT32 nType);
92
93 public:
94
95 protected:
96         virtual void                                            DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device);
97
98 private:
99         FX_INT32                                                        m_nType;
100 };
101
102 class CPWL_Note_CloseBox : public CPWL_Button
103 {
104 public:
105         CPWL_Note_CloseBox();
106         virtual ~CPWL_Note_CloseBox();
107
108 protected:
109         virtual void                                            DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device);
110         virtual FX_BOOL                                         OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag);
111         virtual FX_BOOL                                         OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag);
112
113 private:
114         FX_BOOL                                                         m_bMouseDown;
115 };
116
117 class CPWL_Note_LBBox : public CPWL_Wnd
118 {
119 public:
120         CPWL_Note_LBBox();
121         virtual ~CPWL_Note_LBBox();
122
123 protected:
124         virtual void                                            DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device);
125 };
126
127 class CPWL_Note_RBBox : public CPWL_Wnd
128 {
129 public:
130         CPWL_Note_RBBox();
131         virtual ~CPWL_Note_RBBox();
132
133 protected:
134         virtual void                                            DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device);
135 };
136
137 class CPWL_Note_Edit : public CPWL_Edit
138 {
139 public:
140         CPWL_Note_Edit();
141         virtual ~CPWL_Note_Edit();
142
143         void                                                            EnableNotify(FX_BOOL bEnable) {m_bEnableNotify = bEnable;}
144         virtual FX_FLOAT                                        GetItemHeight(FX_FLOAT fLimitWidth);
145         FX_FLOAT                                                        GetItemLeftMargin();
146         FX_FLOAT                                                        GetItemRightMargin();
147
148         virtual void                                            SetText(FX_LPCWSTR csText);
149
150 protected:
151         virtual void                                            OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam = 0, FX_INTPTR lParam = 0);
152         virtual void                                            RePosChildWnd();
153         virtual void                                            OnSetFocus();
154         virtual void                                            OnKillFocus();  
155
156 private:
157         FX_BOOL                                                         m_bEnableNotify;
158         FX_FLOAT                                                        m_fOldItemHeight;
159         FX_BOOL                                                         m_bSizeChanged;
160         FX_FLOAT                                                        m_fOldMin;
161         FX_FLOAT                                                        m_fOldMax;
162 };
163
164 class CPWL_Note_Options : public CPWL_Wnd
165 {
166 public:
167         CPWL_Note_Options();
168         virtual ~CPWL_Note_Options();
169
170         CPDF_Rect                                                       GetContentRect() const;
171         virtual void                                            SetTextColor(const CPWL_Color & color);
172         void                                                            SetText(const CFX_WideString& sText);
173
174 protected:
175         virtual void                                            RePosChildWnd();
176         virtual void                                            CreateChildWnd(const PWL_CREATEPARAM & cp);
177         virtual void                                            DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device);
178
179 private:
180         CPWL_Label*                                                     m_pText;
181 };
182
183 class CPWL_Note_Contents : public CPWL_ListCtrl
184 {
185 public:
186         CPWL_Note_Contents();
187         virtual ~CPWL_Note_Contents();
188
189         virtual CFX_ByteString                          GetClassName() const;
190         virtual void                                            OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam = 0, FX_INTPTR lParam = 0);
191         virtual FX_BOOL                                         OnLButtonDown(const CPDF_Point& point, FX_DWORD nFlag);
192
193         void                                                            SetEditFocus(FX_BOOL bLast);
194         CPWL_Edit*                                                      GetEdit() const;
195
196 public:
197         void                                                            SetText(const CFX_WideString& sText);
198         CFX_WideString                                          GetText() const;
199
200         CPWL_NoteItem*                                          CreateSubItem();
201         void                                                            DeleteSubItem(IPWL_NoteItem* pNoteItem);
202         FX_INT32                                                        CountSubItems() const;
203         IPWL_NoteItem*                                          GetSubItems(FX_INT32 index) const;
204
205         virtual IPWL_NoteItem*                          GetHitNoteItem(const CPDF_Point& point);
206         void                                                            EnableRead(FX_BOOL bEnabled);
207         void                                                            EnableModify(FX_BOOL bEnabled);
208
209 protected:
210         virtual void                                            CreateChildWnd(const PWL_CREATEPARAM & cp);
211
212 private:
213         CPWL_Note_Edit*                                         m_pEdit;
214 };
215
216 class PWL_CLASS CPWL_NoteItem : public CPWL_Wnd, public IPWL_NoteItem 
217 {
218 public:
219         CPWL_NoteItem();
220         virtual ~CPWL_NoteItem();
221
222 public:
223         virtual void                                            SetPrivateData(void* pData);
224         virtual void                                            SetBkColor(const CPWL_Color& color);
225         virtual void                                            SetSubjectName(const CFX_WideString& sName);
226         virtual void                                            SetAuthorName(const CFX_WideString& sName);
227         virtual void                                            SetDateTime(FX_SYSTEMTIME time);
228         virtual void                                            SetContents(const CFX_WideString& sContents);
229
230         virtual IPWL_NoteItem*                          CreateSubItem();
231         virtual FX_INT32                                        CountSubItems() const;
232         virtual IPWL_NoteItem*                          GetSubItems(FX_INT32 index) const;
233         virtual void                                            DeleteSubItem(IPWL_NoteItem* pNoteItem);
234         virtual void                                            SetFocus(){SetNoteFocus(FALSE);}
235
236         virtual IPWL_NoteItem*                          GetParentItem() const;
237         virtual void*                                           GetPrivateData() const;
238         virtual CFX_WideString                          GetAuthorName() const;
239         virtual CPWL_Color                                      GetBkColor() const;
240         virtual CFX_WideString                          GetContents() const;
241         virtual FX_SYSTEMTIME                           GetDateTime() const;
242         virtual CFX_WideString                          GetSubjectName() const;
243         virtual FX_BOOL                                         IsTopItem() const { return FALSE;}
244         virtual CPWL_Edit*                                      GetEdit() const;
245
246 public:
247         virtual FX_BOOL                                         OnLButtonDown(const CPDF_Point& point, FX_DWORD nFlag);
248         virtual FX_BOOL                                         OnRButtonUp(const CPDF_Point & point, FX_DWORD nFlag);
249         virtual CFX_ByteString                          GetClassName() const;
250         virtual IPWL_NoteItem*                          GetHitNoteItem(const CPDF_Point& point);
251         virtual IPWL_NoteItem*                          GetFocusedNoteItem() const;
252
253         virtual void                                            ResetSubjectName(FX_INT32 nItemIndex);
254         void                                                            EnableRead(FX_BOOL bEnabled);
255         void                                                            EnableModify(FX_BOOL bEnabled);
256
257 protected:
258         virtual void                                            RePosChildWnd();
259         virtual void                                            CreateChildWnd(const PWL_CREATEPARAM & cp);
260
261         virtual void                                            OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam = 0, FX_INTPTR lParam = 0);
262
263 public:
264         virtual FX_FLOAT                                        GetItemHeight(FX_FLOAT fLimitWidth);
265         virtual FX_FLOAT                                        GetItemLeftMargin();
266         virtual FX_FLOAT                                        GetItemRightMargin();
267         CPWL_NoteItem*                                          CreateNoteItem();
268         CPWL_NoteItem*                                          GetParentNoteItem() const;
269
270         void                                                            SetNoteFocus(FX_BOOL bLast);
271         void                                                            OnContentsValidate();
272         
273         void                                                            OnCreateNoteItem();
274
275 protected:
276         void                                                            PopupNoteItemMenu(const CPDF_Point& point);
277
278         virtual const CPWL_Note*                        GetNote() const;
279         virtual IPWL_NoteNotify*                        GetNoteNotify() const;
280
281 protected:
282         CPWL_Label*                                                     m_pSubject;
283         CPWL_Label*                                                     m_pDateTime;
284         CPWL_Note_Contents*                                     m_pContents;
285
286 private:
287         void*                                                           m_pPrivateData;
288         FX_SYSTEMTIME                                           m_dtNote;
289         CFX_WideString                                          m_sAuthor;
290
291         FX_FLOAT                                                        m_fOldItemHeight;
292         FX_BOOL                                                         m_bSizeChanged;
293         FX_BOOL                                                         m_bAllowModify;
294 };
295
296 class PWL_CLASS CPWL_Note : public CPWL_NoteItem
297 {
298 public:
299         CPWL_Note(IPopup_Note* pPopupNote, IPWL_NoteNotify* pNoteNotify, IPWL_NoteHandler* pNoteHandler);
300         virtual ~CPWL_Note();
301
302 public:
303         virtual void                                            SetSubjectName(const CFX_WideString& sName);
304         virtual void                                            SetAuthorName(const CFX_WideString& sName);
305         virtual CFX_WideString                          GetAuthorName() const;
306         virtual void                                            SetBkColor(const CPWL_Color& color);
307         virtual void                                            ResetSubjectName(FX_INT32 nItemIndex){}
308         virtual FX_BOOL                                         IsTopItem() const {return TRUE;}
309         virtual const CPWL_Note*                        GetNote() const;
310         virtual IPWL_NoteNotify*                        GetNoteNotify() const;
311
312 public:
313         IPWL_NoteItem*                                          Reply();
314         void                                                            EnableNotify(FX_BOOL bEnabled);
315         void                                                            SetIconType(FX_INT32 nType);
316         void                                                            SetOptionsText(const CFX_WideString& sText);
317         void                                                            EnableRead(FX_BOOL bEnabled);
318         void                                                            EnableModify(FX_BOOL bEnabled);
319
320         CFX_WideString                                          GetReplyString() const;
321         void                                                            SetReplyString(const CFX_WideString& string);
322
323         //0-normal / 1-caption / 2-leftbottom corner / 3-rightbottom corner / 4-close / 5-options 
324         FX_INT32                                                        NoteHitTest(const CPDF_Point& point) const;
325         CPDF_Rect                                                       GetCaptionRect() const {return m_rcCaption;}
326         IPopup_Note*                                            GetPopupNote() const {return m_pPopupNote;}
327
328 public:
329         virtual FX_BOOL                                         OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag);
330         virtual FX_BOOL                                         OnRButtonUp(const CPDF_Point & point, FX_DWORD nFlag);
331         virtual FX_BOOL                                         OnMouseWheel(short zDelta, const CPDF_Point & point, FX_DWORD nFlag);
332
333 protected:
334         virtual void                                            RePosChildWnd();
335         virtual void                                            CreateChildWnd(const PWL_CREATEPARAM & cp);
336
337         virtual void                                            OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam = 0, FX_INTPTR lParam = 0);
338
339         FX_BOOL                                                         ResetScrollBar();
340         void                                                            RePosNoteChildren();
341         FX_BOOL                                                         ScrollBarShouldVisible();
342
343 private:
344         CPWL_Label*                                                     m_pAuthor;
345         CPWL_Note_Icon*                                         m_pIcon;
346         CPWL_Note_CloseBox*                                     m_pCloseBox;
347         CPWL_Note_LBBox*                                        m_pLBBox;
348         CPWL_Note_RBBox*                                        m_pRBBox;
349         CPWL_ScrollBar*                                         m_pContentsBar; 
350         CPWL_Note_Options*                                      m_pOptions;
351         IPWL_NoteNotify*                                        m_pNoteNotify;
352         FX_BOOL                                                         m_bResizing;
353         PWL_SCROLL_INFO                                         m_OldScrollInfo;
354         CPDF_Rect                                                       m_rcCaption;
355         FX_BOOL                                                         m_bEnalbleNotify;
356         IPopup_Note*                                            m_pPopupNote;
357         CFX_WideString                                          m_sReplyString;
358 };
359
360 #endif
361