FX Bool considered harmful, part 3
[pdfium.git] / fpdfsdk / include / javascript / JS_EventHandler.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_JAVASCRIPT_JS_EVENTHANDLER_H_
8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_EVENTHANDLER_H_
9
10 #include "../../../core/include/fxcrt/fx_string.h"
11 #include "../../../core/include/fxcrt/fx_system.h"
12
13 class CJS_Context;
14 class CPDFSDK_Annot;
15 class CPDFSDK_Document;
16 class CPDF_Bookmark;
17 class CPDF_FormField;
18 class Field;
19
20 enum JS_EVENT_T
21 {
22         JET_UNKNOWN,
23         JET_APP_INIT,
24         JET_DOC_OPEN,
25         JET_DOC_WILLPRINT,
26         JET_DOC_DIDPRINT,
27         JET_DOC_WILLSAVE,
28         JET_DOC_DIDSAVE,
29         JET_DOC_WILLCLOSE,
30         JET_PAGE_OPEN,
31         JET_PAGE_CLOSE,
32         JET_PAGE_INVIEW,
33         JET_PAGE_OUTVIEW,
34         JET_FIELD_MOUSEDOWN,
35         JET_FIELD_MOUSEUP,
36         JET_FIELD_MOUSEENTER,
37         JET_FIELD_MOUSEEXIT,
38         JET_FIELD_FOCUS,
39         JET_FIELD_BLUR,
40         JET_FIELD_KEYSTROKE,
41         JET_FIELD_VALIDATE,
42         JET_FIELD_CALCULATE,
43         JET_FIELD_FORMAT,
44         JET_SCREEN_FOCUS,
45         JET_SCREEN_BLUR,
46         JET_SCREEN_OPEN,
47         JET_SCREEN_CLOSE,
48         JET_SCREEN_MOUSEDOWN,
49         JET_SCREEN_MOUSEUP,
50         JET_SCREEN_MOUSEENTER,
51         JET_SCREEN_MOUSEEXIT,
52         JET_SCREEN_INVIEW,
53         JET_SCREEN_OUTVIEW,
54         JET_BATCH_EXEC,
55         JET_MENU_EXEC,
56         JET_CONSOLE_EXEC,
57         JET_EXTERNAL_EXEC,
58         JET_BOOKMARK_MOUSEUP,
59         JET_LINK_MOUSEUP
60 };
61
62 class CJS_EventHandler
63 {
64 public:
65         CJS_EventHandler(CJS_Context * pContext);
66         virtual ~CJS_EventHandler();
67
68         void                                    OnApp_Init();
69
70         void                                    OnDoc_Open(CPDFSDK_Document* pDoc, const CFX_WideString& strTargetName);
71         void                                    OnDoc_WillPrint(CPDFSDK_Document* pDoc);
72         void                                    OnDoc_DidPrint(CPDFSDK_Document* pDoc);
73         void                                    OnDoc_WillSave(CPDFSDK_Document* pDoc);
74         void                                    OnDoc_DidSave(CPDFSDK_Document* pDoc);
75         void                                    OnDoc_WillClose(CPDFSDK_Document* pDoc);
76
77         void                                    OnPage_Open(CPDFSDK_Document* pDoc);
78         void                                    OnPage_Close(CPDFSDK_Document* pDoc);
79         void                                    OnPage_InView(CPDFSDK_Document* pTarget);
80         void                                    OnPage_OutView(CPDFSDK_Document* pTarget);
81
82         void                                    OnField_Calculate(CPDF_FormField* pSource, CPDF_FormField* pTarget, CFX_WideString& Value, bool& bRc);
83         void                                    OnField_Format(CPDF_FormField* pTarget, CFX_WideString& Value, bool bWillCommit);
84         void                                    OnField_Keystroke(CFX_WideString& strChange, const CFX_WideString& strChangeEx,
85                                                                 bool KeyDown, bool bModifier, int &nSelEnd,int &nSelStart, bool bShift,
86                                                                 CPDF_FormField* pTarget, CFX_WideString& Value, bool bWillCommit,
87                                                                 bool bFieldFull, bool &bRc);
88         void                                    OnField_Validate(CFX_WideString& strChange, const CFX_WideString& strChangeEx, bool bKeyDown,
89                                                                 bool bModifier, bool bShift, CPDF_FormField* pTarget, CFX_WideString& Value, bool& bRc);
90
91         void                                    OnField_MouseDown(bool bModifier, bool bShift, CPDF_FormField *pTarget);
92         void                                    OnField_MouseEnter(bool bModifier, bool bShift, CPDF_FormField *pTarget);
93         void                                    OnField_MouseExit(bool bModifier, bool bShift, CPDF_FormField *pTarget);
94         void                                    OnField_MouseUp(bool bModifier, bool bShift, CPDF_FormField *pTarget);
95         void                                    OnField_Blur(bool bModifier, bool bShift, CPDF_FormField* pTarget, const CFX_WideString& Value);
96         void                                    OnField_Focus(bool bModifier, bool bShift, CPDF_FormField* pTarget, const CFX_WideString& Value);
97
98         void                                    OnScreen_Focus(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
99         void                                    OnScreen_Blur(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
100         void                                    OnScreen_Open(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
101         void                                    OnScreen_Close(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
102         void                                    OnScreen_MouseDown(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
103         void                                    OnScreen_MouseUp(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
104         void                                    OnScreen_MouseEnter(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
105         void                                    OnScreen_MouseExit(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
106         void                                    OnScreen_InView(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
107         void                                    OnScreen_OutView(bool bModifier, bool bShift, CPDFSDK_Annot* pScreen);
108
109         void                                    OnBookmark_MouseUp(CPDF_Bookmark* pBookMark);
110         void                                    OnLink_MouseUp(CPDFSDK_Document* pTarget);
111
112         void                                    OnMenu_Exec(CPDFSDK_Document* pTarget, const CFX_WideString& strTargetName);
113         void                                    OnBatchExec(CPDFSDK_Document *pTarget);
114         void                                    OnConsole_Exec();
115         void                                    OnExternal_Exec();
116
117 public:
118     void                                        Initial(JS_EVENT_T type);
119         void                                    Destroy();
120         bool                                    IsValid();
121
122
123         CFX_WideString&                 Change();
124         CFX_WideString                  ChangeEx();
125         int                                             CommitKey();
126         bool                                    FieldFull();
127         bool                                    KeyDown();
128         bool                                    Modifier();
129         const FX_WCHAR*                         Name();
130         const FX_WCHAR*                         Type();
131         bool&                           Rc();
132         int&                                    SelEnd();
133         int&                                    SelStart();
134         bool                                    Shift();
135         Field*                                  Source();
136         Field*                                  Target_Field();
137         CFX_WideString&                 Value();
138         bool                                    WillCommit();
139         CFX_WideString                  TargetName();
140
141         JS_EVENT_T                              EventType() {return m_eEventType;};
142
143 public:
144         CJS_Context*                    m_pJSContext;
145         JS_EVENT_T                              m_eEventType;
146         bool                                    m_bValid;
147
148         CFX_WideString                  m_strTargetName;
149         CFX_WideString                  m_strSourceName;
150         CFX_WideString*                 m_pWideStrChange;
151         CFX_WideString                  m_WideStrChangeDu;
152         CFX_WideString                  m_WideStrChangeEx;
153         int                                             m_nCommitKey;
154         bool                                    m_bKeyDown;
155         bool                                    m_bModifier;
156         bool                                    m_bShift;
157         int*                                    m_pISelEnd;
158         int                                             m_nSelEndDu;
159         int*                                    m_pISelStart;
160         int                                             m_nSelStartDu;
161         bool                                    m_bWillCommit;
162         CFX_WideString*                 m_pValue;
163         bool                                    m_bFieldFull;
164         bool*                           m_pbRc;
165         bool                                    m_bRcDu;
166
167         CPDFSDK_Document*               m_pSourceDoc;
168         CPDF_Bookmark*                  m_pTargetBookMark;
169         CPDFSDK_Document*               m_pTargetDoc;
170         CPDFSDK_Annot*                  m_pTargetAnnot;
171 };
172
173 #endif  // FPDFSDK_INCLUDE_JAVASCRIPT_JS_EVENTHANDLER_H_