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