Revert "FX Bool considered harmful, part 3"
[pdfium.git] / fpdfsdk / include / pdfwindow / PWL_Wnd.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 FPDFSDK_INCLUDE_PDFWINDOW_PWL_WND_H_
8 #define FPDFSDK_INCLUDE_PDFWINDOW_PWL_WND_H_
9
10 #include "../../../core/include/fxcrt/fx_basic.h"
11 #include "../../../core/include/fpdfdoc/fpdf_doc.h"
12 #include "../fx_systemhandler.h"
13
14 class CPWL_MsgControl;
15 class CPWL_ScrollBar;
16 class CPWL_Timer;
17 class CPWL_TimerHandler;
18 class CPWL_Wnd;
19 class IFX_Edit_FontMap;
20 class IFX_SystemHandler;
21 class IPWL_Provider;
22 class IPWL_SpellCheck;
23
24 #ifdef FX_READER_DLL
25         #ifdef PWL_EXPORT
26                         #define PWL_CLASS               __declspec(dllexport)
27                         #define PWL_FUNCTION    PWL_CLASS
28                 #else
29                         #define PWL_CLASS
30                         #define PWL_FUNCTION
31         #endif
32 #else
33         #define PWL_CLASS
34         #define PWL_FUNCTION
35 #endif
36
37 //window styles
38 #define PWS_CHILD                                                       0x80000000L
39 #define PWS_BORDER                                                      0x40000000L
40 #define PWS_BACKGROUND                                          0x20000000L
41 #define PWS_HSCROLL                                                     0x10000000L
42 #define PWS_VSCROLL                                                     0x08000000L
43 #define PWS_VISIBLE                                                     0x04000000L
44 #define PWS_DISABLE                                                     0x02000000L
45 #define PWS_READONLY                                            0x01000000L
46 #define PWS_AUTOFONTSIZE                                        0x00800000L
47 #define PWS_AUTOTRANSPARENT                                     0x00400000L
48 #define PWS_NOREFRESHCLIP                                       0x00200000L
49
50 //edit and label styles
51 #define PES_MULTILINE                                           0x0001L
52 #define PES_PASSWORD                                            0x0002L
53 #define PES_LEFT                                                        0x0004L
54 #define PES_RIGHT                                                       0x0008L
55 #define PES_MIDDLE                                                      0x0010L
56 #define PES_TOP                                                         0x0020L
57 #define PES_BOTTOM                                                      0x0040L
58 #define PES_CENTER                                                      0x0080L
59 #define PES_CHARARRAY                                           0x0100L
60 #define PES_AUTOSCROLL                                          0x0200L
61 #define PES_AUTORETURN                                          0x0400L
62 #define PES_UNDO                                                        0x0800L
63 #define PES_RICH                                                        0x1000L
64 #define PES_SPELLCHECK                                          0x2000L
65 #define PES_TEXTOVERFLOW                                        0x4000L
66 #define PES_NOREAD                                                      0x8000L
67
68 //listbox styles
69 #define PLBS_MULTIPLESEL                                        0x0001L
70 #define PLBS_HOVERSEL                                           0x0008L
71
72 //combobox styles
73 #define PCBS_ALLOWCUSTOMTEXT                            0x0001L
74
75 //richedit styles
76 #define PRES_MULTILINE                                          0x0001L
77 #define PRES_AUTORETURN                                         0x0002L
78 #define PRES_AUTOSCROLL                                         0x0004L
79 #define PRES_SPELLCHECK                                         0x0008L
80 #define PRES_UNDO                                                       0x0100L
81 #define PRES_MULTIPAGES                                         0x0200L
82 #define PRES_TEXTOVERFLOW                                       0x0400L
83
84 //border style
85 #define PBS_SOLID                                                       0
86 #define PBS_DASH                                                        1
87 #define PBS_BEVELED                                                     2
88 #define PBS_INSET                                                       3
89 #define PBS_UNDERLINED                                          4
90 #define PBS_SHADOW                                                      5
91
92 //notification messages
93 #define PNM_ADDCHILD                                            0x00000000L
94 #define PNM_REMOVECHILD                                         0x00000001L
95 #define PNM_SETSCROLLINFO                                       0x00000002L
96 #define PNM_SETSCROLLPOS                                        0x00000003L
97 #define PNM_SCROLLWINDOW                                        0x00000004L
98 #define PNM_LBUTTONDOWN                                         0x00000005L
99 #define PNM_LBUTTONUP                                           0x00000006L
100 #define PNM_MOUSEMOVE                                           0x00000007L
101 #define PNM_NOTERESET                                           0x00000008L
102 #define PNM_SETCARETINFO                                        0x00000009L
103 #define PNM_SELCHANGED                                          0x0000000AL
104 #define PNM_NOTEEDITCHANGED                                     0x0000000BL
105
106 #define PWL_CLASSNAME_EDIT                                      "CPWL_Edit"
107
108 struct CPWL_Dash
109 {
110         CPWL_Dash(int32_t dash, int32_t gap, int32_t phase) : nDash(dash), nGap(gap), nPhase(phase)
111         {}
112
113         int32_t                 nDash;
114         int32_t                 nGap;
115         int32_t                 nPhase;
116 };
117
118 struct PWL_CLASS CPWL_Color
119 {
120         CPWL_Color(int32_t type = COLORTYPE_TRANSPARENT, FX_FLOAT color1 = 0.0f, FX_FLOAT color2 = 0.0f, FX_FLOAT color3 = 0.0f, FX_FLOAT color4 = 0.0f)
121                 : nColorType(type), fColor1(color1), fColor2(color2), fColor3(color3), fColor4(color4)
122         {}
123
124         CPWL_Color(int32_t r, int32_t g, int32_t b) :
125                 nColorType(COLORTYPE_RGB), fColor1(r/255.0f), fColor2(g/255.0f), fColor3(b/255.0f), fColor4(0)
126         {}
127
128         void ConvertColorType(int32_t other_nColorType);
129
130         /*
131         COLORTYPE_TRANSPARENT
132         COLORTYPE_RGB
133         COLORTYPE_CMYK
134         COLORTYPE_GRAY
135         */
136         int32_t                                 nColorType;
137         FX_FLOAT                                        fColor1,fColor2,fColor3,fColor4;
138 };
139
140 inline FX_BOOL operator == (const CPWL_Color &c1, const CPWL_Color &c2)
141 {
142         return c1.nColorType == c2.nColorType &&
143                 c1.fColor1 - c2.fColor1 < 0.0001 && c1.fColor1 - c2.fColor1 > -0.0001 &&
144                 c1.fColor2 - c2.fColor2 < 0.0001 && c1.fColor2 - c2.fColor2 > -0.0001 &&
145                 c1.fColor3 - c2.fColor3 < 0.0001 && c1.fColor3 - c2.fColor3 > -0.0001 &&
146                 c1.fColor4 - c2.fColor4 < 0.0001 && c1.fColor4 - c2.fColor4 > -0.0001;
147 }
148
149 inline FX_BOOL operator != (const CPWL_Color &c1, const CPWL_Color &c2)
150 {
151         return !operator == (c1, c2);
152 }
153
154 #define PWL_SCROLLBAR_WIDTH                                     12.0f
155 #define PWL_SCROLLBAR_BUTTON_WIDTH                      9.0f
156 #define PWL_SCROLLBAR_POSBUTTON_MINWIDTH        2.0f
157 #define PWL_SCROLLBAR_TRANSPARANCY                      150
158 #define PWL_SCROLLBAR_BKCOLOR                           CPWL_Color(COLORTYPE_RGB,220.0f/255.0f,220.0f/255.0f,220.0f/255.0f)
159 #define PWL_DEFAULT_SELTEXTCOLOR                        CPWL_Color(COLORTYPE_RGB,1,1,1)
160 #define PWL_DEFAULT_SELBACKCOLOR                        CPWL_Color(COLORTYPE_RGB,0,51.0f/255.0f,113.0f/255.0f)
161 #define PWL_DEFAULT_BACKCOLOR                           PWL_DEFAULT_SELTEXTCOLOR
162 #define PWL_DEFAULT_TEXTCOLOR                           CPWL_Color(COLORTYPE_RGB,0,0,0)
163 #define PWL_DEFAULT_FONTSIZE                            9.0f
164 #define PWL_DEFAULT_BLACKCOLOR                          CPWL_Color(COLORTYPE_GRAY,0)
165 #define PWL_DEFAULT_WHITECOLOR                          CPWL_Color(COLORTYPE_GRAY,1)
166 #define PWL_DEFAULT_HEAVYGRAYCOLOR                      CPWL_Color(COLORTYPE_GRAY,0.50)
167 #define PWL_DEFAULT_LIGHTGRAYCOLOR                      CPWL_Color(COLORTYPE_GRAY,0.75)
168 #define PWL_TRIANGLE_HALFLEN                            2.0f
169 #define PWL_CBBUTTON_TRIANGLE_HALFLEN           3.0f
170 #define PWL_INVALIDATE_INFLATE                          2
171
172 class IPWL_SpellCheck
173 {
174 public:
175         virtual ~IPWL_SpellCheck() { }
176         virtual FX_BOOL                                                 CheckWord(const FX_CHAR* sWord) = 0;
177         virtual void                                                    SuggestWords(const FX_CHAR* sWord, CFX_ByteStringArray & sSuggest) = 0;
178 };
179
180 class IPWL_Provider
181 {
182 public:
183         virtual ~IPWL_Provider() { }
184
185         //get a matrix which map user space to CWnd client space
186         virtual CPDF_Matrix                                             GetWindowMatrix(void* pAttachedData) = 0;
187
188         /*
189         0 L"&Undo\tCtrl+Z"
190         1 L"&Redo\tCtrl+Shift+Z"
191         2 L"Cu&t\tCtrl+X"
192         3 L"&Copy\tCtrl+C"
193         4 L"&Paste\tCtrl+V"
194         5 L"&Delete"
195         6  L"&Select All\tCtrl+A"
196         */
197         virtual CFX_WideString                                  LoadPopupMenuString(int32_t nIndex) = 0;
198 };
199
200 class IPWL_FocusHandler
201 {
202 public:
203         virtual ~IPWL_FocusHandler() { }
204         virtual void                                                    OnSetFocus(CPWL_Wnd* pWnd) = 0;
205         virtual void                                                    OnKillFocus(CPWL_Wnd* pWnd) = 0;
206 };
207
208 struct PWL_CREATEPARAM
209 {
210 public:
211         PWL_CREATEPARAM() : rcRectWnd(0,0,0,0),
212                 pSystemHandler(NULL),
213                 pFontMap(NULL),
214                 pProvider(NULL),
215                 pFocusHandler(NULL),
216                 dwFlags(0),
217                 sBackgroundColor(),
218                 hAttachedWnd(NULL),
219                 pSpellCheck(NULL),
220                 nBorderStyle(PBS_SOLID),
221                 dwBorderWidth(1),
222                 sBorderColor(),
223                 sTextColor(),
224                 sTextStrokeColor(),
225                 nTransparency(255),
226                 fFontSize(PWL_DEFAULT_FONTSIZE),
227                 sDash(3,0,0),
228                 pAttachedData(NULL),
229                 pParentWnd(NULL),
230                 pMsgControl(NULL),
231                 eCursorType(FXCT_ARROW),
232                 mtChild(1,0,0,1,0,0)
233         {
234         }
235
236         CPDF_Rect                               rcRectWnd;                              //required
237         IFX_SystemHandler*              pSystemHandler;                 //required
238         IFX_Edit_FontMap*               pFontMap;                               //required for text window
239         IPWL_Provider*                  pProvider;                              //required for self coordinate
240         IPWL_FocusHandler*              pFocusHandler;                  //optional
241         FX_DWORD                                dwFlags;                                //optional
242         CPWL_Color                              sBackgroundColor;               //optional
243         FX_HWND                                 hAttachedWnd;                   //required for no-reader framework
244         IPWL_SpellCheck*                pSpellCheck;                    //required for spellchecking
245         int32_t                         nBorderStyle;                   //optional
246         int32_t                         dwBorderWidth;                  //optional
247         CPWL_Color                              sBorderColor;                   //optional
248         CPWL_Color                              sTextColor;                             //optional
249         CPWL_Color                              sTextStrokeColor;               //optional
250         int32_t                         nTransparency;                  //optional
251         FX_FLOAT                                fFontSize;                              //optional
252         CPWL_Dash                               sDash;                                  //optional
253         void*                                   pAttachedData;                  //optional
254         CPWL_Wnd*                               pParentWnd;                             //ignore
255         CPWL_MsgControl*                pMsgControl;                    //ignore
256         int32_t                         eCursorType;                    //ignore
257         CPDF_Matrix                             mtChild;                                //ignore
258 };
259
260 class CPWL_Timer
261 {
262 public:
263         CPWL_Timer(CPWL_TimerHandler* pAttached, IFX_SystemHandler* pSystemHandler);
264         virtual ~CPWL_Timer();
265
266         int32_t                                                 SetPWLTimer(int32_t nElapse);
267         void                                                            KillPWLTimer();
268         static void                                             TimerProc(int32_t idEvent);
269
270 private:
271         int32_t                                                 m_nTimerID;
272         CPWL_TimerHandler*                                      m_pAttached;
273         IFX_SystemHandler*                                      m_pSystemHandler;
274 };
275
276 class PWL_CLASS CPWL_TimerHandler
277 {
278 public:
279         CPWL_TimerHandler();
280         virtual ~CPWL_TimerHandler();
281
282         void                                                            BeginTimer(int32_t nElapse);
283         void                                                            EndTimer();
284         virtual void                                            TimerProc();
285         virtual IFX_SystemHandler*                      GetSystemHandler() const = 0;
286
287 private:
288         CPWL_Timer*                                                     m_pTimer;
289 };
290
291 class PWL_CLASS CPWL_Wnd : public CPWL_TimerHandler
292 {
293         friend class CPWL_MsgControl;
294 public:
295         CPWL_Wnd();
296         virtual ~CPWL_Wnd();
297
298         void                                                    Create(const PWL_CREATEPARAM & cp);
299         virtual CFX_ByteString                  GetClassName() const;
300         void                                                    Destroy();
301         void                                                    Move(const CPDF_Rect & rcNew,FX_BOOL bReset,FX_BOOL bRefresh);
302         virtual void                                    InvalidateRect(CPDF_Rect* pRect = NULL);
303
304         void                                                    GetAppearanceStream(CFX_ByteString & sAppStream);
305         void                                                    DrawAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device);
306
307         virtual FX_BOOL                                 OnKeyDown(FX_WORD nChar, FX_DWORD nFlag);
308         virtual FX_BOOL                                 OnKeyUp(FX_WORD nChar, FX_DWORD nFlag);
309         virtual FX_BOOL                                 OnChar(FX_WORD nChar, FX_DWORD nFlag);
310         virtual FX_BOOL                                 OnLButtonDblClk(const CPDF_Point & point, FX_DWORD nFlag);
311         virtual FX_BOOL                                 OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag);
312         virtual FX_BOOL                                 OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag);
313         virtual FX_BOOL                                 OnMButtonDblClk(const CPDF_Point & point, FX_DWORD nFlag);
314         virtual FX_BOOL                                 OnMButtonDown(const CPDF_Point & point, FX_DWORD nFlag);
315         virtual FX_BOOL                                 OnMButtonUp(const CPDF_Point & point, FX_DWORD nFlag);
316         virtual FX_BOOL                                 OnRButtonDown(const CPDF_Point & point, FX_DWORD nFlag);
317         virtual FX_BOOL                                 OnRButtonUp(const CPDF_Point & point, FX_DWORD nFlag);
318         virtual FX_BOOL                                 OnMouseMove(const CPDF_Point & point, FX_DWORD nFlag);
319         virtual FX_BOOL                                 OnMouseWheel(short zDelta, const CPDF_Point & point, FX_DWORD nFlag);
320
321         virtual void                                    SetFocus();
322         virtual void                                    KillFocus();
323         void                                                    SetCapture();
324         void                                                    ReleaseCapture();
325
326         virtual void                                    OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, intptr_t wParam = 0, intptr_t lParam = 0);
327         virtual void                                    SetTextColor(const CPWL_Color & color);
328         virtual void                                    SetTextStrokeColor(const CPWL_Color & color);
329         virtual void                                    SetVisible(FX_BOOL bVisible);
330
331         virtual CPDF_Rect                               GetFocusRect() const;
332         virtual CPWL_Color                              GetBackgroundColor() const;
333         virtual CPWL_Color                              GetBorderColor() const;
334         virtual CPWL_Color                              GetTextColor() const;
335         virtual CPWL_Color                              GetTextStrokeColor() const;
336         virtual FX_FLOAT                                GetFontSize() const;
337         virtual int32_t                         GetInnerBorderWidth() const;
338         virtual CPWL_Color                              GetBorderLeftTopColor(int32_t nBorderStyle) const;
339         virtual CPWL_Color                              GetBorderRightBottomColor(int32_t nBorderStyle) const;
340
341         virtual FX_BOOL                                 IsModified() const {return FALSE;}
342
343         virtual void                                    SetFontSize(FX_FLOAT fFontSize);
344
345         void                                                    SetBackgroundColor(const CPWL_Color & color);
346         void                                                    SetBorderColor(const CPWL_Color & color);
347         void                                                    SetBorderWidth(int32_t nBorderWidth);
348         void                                                    SetClipRect(const CPDF_Rect & rect);
349         void                                                    SetBorderStyle(int32_t eBorderStyle);
350         void                                                    SetBorderDash(const CPWL_Dash & sDash);
351
352         CPDF_Rect                                               GetOriginWindowRect() const;
353         virtual CPDF_Rect                               GetWindowRect() const;
354         virtual CPDF_Rect                               GetClientRect() const;
355         CPDF_Point                                              GetCenterPoint() const;
356         CPDF_Rect                                               GetClientCenterSquare() const;
357         CPDF_Rect                                               GetWindowCenterSquare() const;
358         int32_t                                         GetBorderWidth() const;
359         FX_BOOL                                                 IsVisible() const {return m_bVisible;}
360         FX_BOOL                                                 HasFlag(FX_DWORD dwFlags) const;
361         void                                                    AddFlag(FX_DWORD dwFlags);
362         void                                                    RemoveFlag(FX_DWORD dwFlags);
363         CPDF_Rect                                               GetClipRect() const;
364         CPWL_Wnd*                                               GetParentWindow() const;
365         int32_t                                         GetBorderStyle() const;
366         CPWL_Dash                                               GetBorderDash() const;
367         void*                                                   GetAttachedData() const;
368
369         FX_BOOL                                                 WndHitTest(const CPDF_Point & point) const;
370         FX_BOOL                                                 ClientHitTest(const CPDF_Point & point) const;
371         FX_BOOL                                                 IsCaptureMouse() const;
372
373         const CPWL_Wnd*                                 GetFocused() const;
374         FX_BOOL                                                 IsFocused() const;
375         FX_BOOL                                                 IsReadOnly() const;
376         CPWL_ScrollBar*                                 GetVScrollBar() const;
377
378         IFX_Edit_FontMap*                               GetFontMap() const;
379         IPWL_Provider*                                  GetProvider() const;
380         virtual IFX_SystemHandler*              GetSystemHandler() const;
381         IPWL_FocusHandler*                              GetFocusHandler() const;
382
383         int32_t                                         GetTransparency();
384         void                                                    SetTransparency(int32_t nTransparency);
385
386         CPDF_Matrix                                             GetChildToRoot() const;
387         CPDF_Matrix                                             GetChildMatrix() const;
388         void                                                    SetChildMatrix(const CPDF_Matrix& mt);
389         CPDF_Matrix                                             GetWindowMatrix() const;
390
391         virtual CPDF_Point                              ChildToParent(const CPDF_Point& point) const;
392         virtual CPDF_Rect                               ChildToParent(const CPDF_Rect& rect) const;
393         virtual CPDF_Point                              ParentToChild(const CPDF_Point& point) const;
394         virtual CPDF_Rect                               ParentToChild(const CPDF_Rect& rect) const;
395
396         //those methods only implemented by listctrl item
397         virtual FX_FLOAT                                GetItemHeight(FX_FLOAT fLimitWidth) {return 0;}
398         virtual FX_FLOAT                                GetItemLeftMargin() {return 0;}
399         virtual FX_FLOAT                                GetItemRightMargin() {return 0;}
400
401         void                                                    EnableWindow(FX_BOOL bEnable);
402         FX_BOOL                                                 IsEnabled();
403         virtual void                                    SetCursor();
404
405 protected:
406         virtual void                                    CreateChildWnd(const PWL_CREATEPARAM & cp);
407         virtual void                                    RePosChildWnd();
408         void                                                    GetAppearanceStream(CFX_ByteTextBuf & sAppStream);
409         virtual void                                    GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream);
410         virtual void                                    GetChildAppearanceStream(CFX_ByteTextBuf & sAppStream);
411
412         virtual void                                    DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device);
413         virtual void                                    DrawChildAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device);
414
415         virtual void                                    OnCreate(PWL_CREATEPARAM & cp);
416         virtual void                                    OnCreated();
417         virtual void                                    OnDestroy();
418
419         virtual void                                    OnSetFocus();
420         virtual void                                    OnKillFocus();
421
422         virtual void                                    OnEnabled();
423         virtual void                                    OnDisabled();
424
425         void                                                    SetNotifyFlag(FX_BOOL bNotifying = TRUE){m_bNotifying = bNotifying;};
426
427         FX_BOOL                                                 IsValid() const;
428         PWL_CREATEPARAM                                 GetCreationParam() const;
429         FX_BOOL                                                 IsNotifying() const {return m_bNotifying;}
430
431         void                                                    InvalidateRectMove(const CPDF_Rect & rcOld, const CPDF_Rect & rcNew);
432
433         void                                                    PWLtoWnd(const CPDF_Point & point, int32_t& x, int32_t& y) const;
434         FX_RECT                                                 PWLtoWnd(const CPDF_Rect & rect) const;
435         FX_HWND                                                 GetAttachedHWnd() const;
436
437         FX_BOOL                                                 IsWndCaptureMouse(const CPWL_Wnd * pWnd) const;
438         FX_BOOL                                                 IsWndCaptureKeyboard(const CPWL_Wnd * pWnd) const;
439         const CPWL_Wnd*                                 GetRootWnd() const;
440
441         FX_BOOL                                                 IsCTRLpressed(FX_DWORD nFlag) const;
442         FX_BOOL                                                 IsSHIFTpressed(FX_DWORD nFlag) const;
443         FX_BOOL                                                 IsALTpressed(FX_DWORD nFlag) const;
444         FX_BOOL                                                 IsINSERTpressed(FX_DWORD nFlag) const;
445
446 private:
447         void                                                    AddChild(CPWL_Wnd * pWnd);
448         void                                                    RemoveChild(CPWL_Wnd * pWnd);
449
450         void                                                    CreateScrollBar(const PWL_CREATEPARAM & cp);
451         void                                                    CreateVScrollBar(const PWL_CREATEPARAM & cp);
452
453         void                                                    AjustStyle();
454         void                                                    CreateMsgControl();
455         void                                                    DestroyMsgControl();
456
457         CPWL_MsgControl*                                GetMsgControl() const;
458
459 protected:
460         CFX_ArrayTemplate<CPWL_Wnd*>    m_aChildren;
461
462 private:
463         PWL_CREATEPARAM                                 m_sPrivateParam;
464
465         CPWL_ScrollBar*                                 m_pVScrollBar;
466
467         CPDF_Rect                                               m_rcWindow;
468         CPDF_Rect                                               m_rcClip;
469
470         FX_BOOL                                                 m_bCreated;
471         FX_BOOL                                                 m_bVisible;
472         FX_BOOL                                                 m_bNotifying;
473         FX_BOOL                                                 m_bEnabled;
474 };
475
476 #endif  // FPDFSDK_INCLUDE_PDFWINDOW_PWL_WND_H_