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