OLD | NEW |
| (Empty) |
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 #include "xfa/src/fxfa/parser/xfa_script_eventpseudomodel.h" | |
8 | |
9 #include "xfa/src/fxfa/fm2js/xfa_fm2jsapi.h" | |
10 #include "xfa/src/fxfa/parser/xfa_docdata.h" | |
11 #include "xfa/src/fxfa/parser/xfa_doclayout.h" | |
12 #include "xfa/src/fxfa/parser/xfa_document.h" | |
13 #include "xfa/src/fxfa/parser/xfa_localemgr.h" | |
14 #include "xfa/src/fxfa/parser/xfa_object.h" | |
15 #include "xfa/src/fxfa/parser/xfa_parser.h" | |
16 #include "xfa/src/fxfa/parser/xfa_script.h" | |
17 #include "xfa/src/fxfa/parser/xfa_utils.h" | |
18 | |
19 CScript_EventPseudoModel::CScript_EventPseudoModel(CXFA_Document* pDocument) | |
20 : CXFA_OrdinaryObject(pDocument, XFA_ELEMENT_EventPseudoModel) { | |
21 m_uScriptHash = XFA_HASHCODE_Event; | |
22 } | |
23 CScript_EventPseudoModel::~CScript_EventPseudoModel() {} | |
24 void Script_EventPseudoModel_StringProperty(FXJSE_HVALUE hValue, | |
25 CFX_WideString& wsValue, | |
26 FX_BOOL bSetting) { | |
27 if (bSetting) { | |
28 CFX_ByteString bsValue; | |
29 FXJSE_Value_ToUTF8String(hValue, bsValue); | |
30 wsValue = CFX_WideString::FromUTF8(bsValue, bsValue.GetLength()); | |
31 } else { | |
32 FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsValue)); | |
33 } | |
34 } | |
35 void Script_EventPseudoModel_InterProperty(FXJSE_HVALUE hValue, | |
36 int32_t& iValue, | |
37 FX_BOOL bSetting) { | |
38 if (bSetting) { | |
39 iValue = FXJSE_Value_ToInteger(hValue); | |
40 } else { | |
41 FXJSE_Value_SetInteger(hValue, iValue); | |
42 } | |
43 } | |
44 void Script_EventPseudoModel_BooleanProperty(FXJSE_HVALUE hValue, | |
45 FX_BOOL& bValue, | |
46 FX_BOOL bSetting) { | |
47 if (bSetting) { | |
48 bValue = FXJSE_Value_ToBoolean(hValue); | |
49 } else { | |
50 FXJSE_Value_SetBoolean(hValue, bValue); | |
51 } | |
52 } | |
53 void CScript_EventPseudoModel::Script_EventPseudoModel_Property( | |
54 FXJSE_HVALUE hValue, | |
55 FX_DWORD dwFlag, | |
56 FX_BOOL bSetting) { | |
57 IXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); | |
58 if (!pScriptContext) { | |
59 return; | |
60 } | |
61 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); | |
62 if (!pEventParam) { | |
63 return; | |
64 } | |
65 switch (dwFlag) { | |
66 case XFA_EVENT_CANCELACTION: | |
67 Script_EventPseudoModel_BooleanProperty( | |
68 hValue, pEventParam->m_bCancelAction, bSetting); | |
69 break; | |
70 case XFA_EVENT_CHANGE: | |
71 Script_EventPseudoModel_StringProperty(hValue, pEventParam->m_wsChange, | |
72 bSetting); | |
73 break; | |
74 case XFA_EVENT_COMMITKEY: | |
75 Script_EventPseudoModel_InterProperty(hValue, pEventParam->m_iCommitKey, | |
76 bSetting); | |
77 break; | |
78 case XFA_EVENT_FULLTEXT: | |
79 Script_EventPseudoModel_StringProperty(hValue, pEventParam->m_wsFullText, | |
80 bSetting); | |
81 break; | |
82 case XFA_EVENT_KEYDOWN: | |
83 Script_EventPseudoModel_BooleanProperty(hValue, pEventParam->m_bKeyDown, | |
84 bSetting); | |
85 break; | |
86 case XFA_EVENT_MODIFIER: | |
87 Script_EventPseudoModel_BooleanProperty(hValue, pEventParam->m_bModifier, | |
88 bSetting); | |
89 break; | |
90 case XFA_EVENT_NEWCONTENTTYPE: | |
91 Script_EventPseudoModel_StringProperty( | |
92 hValue, pEventParam->m_wsNewContentType, bSetting); | |
93 break; | |
94 case XFA_EVENT_NEWTEXT: | |
95 Script_EventPseudoModel_StringProperty(hValue, pEventParam->m_wsNewText, | |
96 bSetting); | |
97 break; | |
98 case XFA_EVENT_PREVCONTENTTYPE: | |
99 Script_EventPseudoModel_StringProperty( | |
100 hValue, pEventParam->m_wsPrevContentType, bSetting); | |
101 break; | |
102 case XFA_EVENT_PREVTEXT: | |
103 Script_EventPseudoModel_StringProperty(hValue, pEventParam->m_wsPrevText, | |
104 bSetting); | |
105 break; | |
106 case XFA_EVENT_REENTER: | |
107 Script_EventPseudoModel_BooleanProperty(hValue, pEventParam->m_bReenter, | |
108 bSetting); | |
109 break; | |
110 case XFA_EVENT_SELEND: | |
111 Script_EventPseudoModel_InterProperty(hValue, pEventParam->m_iSelEnd, | |
112 bSetting); | |
113 break; | |
114 case XFA_EVENT_SELSTART: | |
115 Script_EventPseudoModel_InterProperty(hValue, pEventParam->m_iSelStart, | |
116 bSetting); | |
117 break; | |
118 case XFA_EVENT_SHIFT: | |
119 Script_EventPseudoModel_BooleanProperty(hValue, pEventParam->m_bShift, | |
120 bSetting); | |
121 break; | |
122 case XFA_EVENT_SOAPFAULTCODE: | |
123 Script_EventPseudoModel_StringProperty( | |
124 hValue, pEventParam->m_wsSoapFaultCode, bSetting); | |
125 break; | |
126 case XFA_EVENT_SOAPFAULTSTRING: | |
127 Script_EventPseudoModel_StringProperty( | |
128 hValue, pEventParam->m_wsSoapFaultString, bSetting); | |
129 break; | |
130 case XFA_EVENT_TARGET: | |
131 break; | |
132 default: | |
133 break; | |
134 } | |
135 } | |
136 void CScript_EventPseudoModel::Script_EventPseudoModel_CancelAction( | |
137 FXJSE_HVALUE hValue, | |
138 FX_BOOL bSetting, | |
139 XFA_ATTRIBUTE eAttribute) { | |
140 Script_EventPseudoModel_Property(hValue, XFA_EVENT_CANCELACTION, bSetting); | |
141 } | |
142 void CScript_EventPseudoModel::Script_EventPseudoModel_Change( | |
143 FXJSE_HVALUE hValue, | |
144 FX_BOOL bSetting, | |
145 XFA_ATTRIBUTE eAttribute) { | |
146 Script_EventPseudoModel_Property(hValue, XFA_EVENT_CHANGE, bSetting); | |
147 } | |
148 void CScript_EventPseudoModel::Script_EventPseudoModel_CommitKey( | |
149 FXJSE_HVALUE hValue, | |
150 FX_BOOL bSetting, | |
151 XFA_ATTRIBUTE eAttribute) { | |
152 Script_EventPseudoModel_Property(hValue, XFA_EVENT_COMMITKEY, bSetting); | |
153 } | |
154 void CScript_EventPseudoModel::Script_EventPseudoModel_FullText( | |
155 FXJSE_HVALUE hValue, | |
156 FX_BOOL bSetting, | |
157 XFA_ATTRIBUTE eAttribute) { | |
158 Script_EventPseudoModel_Property(hValue, XFA_EVENT_FULLTEXT, bSetting); | |
159 } | |
160 void CScript_EventPseudoModel::Script_EventPseudoModel_KeyDown( | |
161 FXJSE_HVALUE hValue, | |
162 FX_BOOL bSetting, | |
163 XFA_ATTRIBUTE eAttribute) { | |
164 Script_EventPseudoModel_Property(hValue, XFA_EVENT_KEYDOWN, bSetting); | |
165 } | |
166 void CScript_EventPseudoModel::Script_EventPseudoModel_Modifier( | |
167 FXJSE_HVALUE hValue, | |
168 FX_BOOL bSetting, | |
169 XFA_ATTRIBUTE eAttribute) { | |
170 Script_EventPseudoModel_Property(hValue, XFA_EVENT_MODIFIER, bSetting); | |
171 } | |
172 void CScript_EventPseudoModel::Script_EventPseudoModel_NewContentType( | |
173 FXJSE_HVALUE hValue, | |
174 FX_BOOL bSetting, | |
175 XFA_ATTRIBUTE eAttribute) { | |
176 Script_EventPseudoModel_Property(hValue, XFA_EVENT_NEWCONTENTTYPE, bSetting); | |
177 } | |
178 void CScript_EventPseudoModel::Script_EventPseudoModel_NewText( | |
179 FXJSE_HVALUE hValue, | |
180 FX_BOOL bSetting, | |
181 XFA_ATTRIBUTE eAttribute) { | |
182 Script_EventPseudoModel_Property(hValue, XFA_EVENT_NEWTEXT, bSetting); | |
183 } | |
184 void CScript_EventPseudoModel::Script_EventPseudoModel_PrevContentType( | |
185 FXJSE_HVALUE hValue, | |
186 FX_BOOL bSetting, | |
187 XFA_ATTRIBUTE eAttribute) { | |
188 Script_EventPseudoModel_Property(hValue, XFA_EVENT_PREVCONTENTTYPE, bSetting); | |
189 } | |
190 void CScript_EventPseudoModel::Script_EventPseudoModel_PrevText( | |
191 FXJSE_HVALUE hValue, | |
192 FX_BOOL bSetting, | |
193 XFA_ATTRIBUTE eAttribute) { | |
194 Script_EventPseudoModel_Property(hValue, XFA_EVENT_PREVTEXT, bSetting); | |
195 } | |
196 void CScript_EventPseudoModel::Script_EventPseudoModel_Reenter( | |
197 FXJSE_HVALUE hValue, | |
198 FX_BOOL bSetting, | |
199 XFA_ATTRIBUTE eAttribute) { | |
200 Script_EventPseudoModel_Property(hValue, XFA_EVENT_REENTER, bSetting); | |
201 } | |
202 void CScript_EventPseudoModel::Script_EventPseudoModel_SelEnd( | |
203 FXJSE_HVALUE hValue, | |
204 FX_BOOL bSetting, | |
205 XFA_ATTRIBUTE eAttribute) { | |
206 Script_EventPseudoModel_Property(hValue, XFA_EVENT_SELEND, bSetting); | |
207 } | |
208 void CScript_EventPseudoModel::Script_EventPseudoModel_SelStart( | |
209 FXJSE_HVALUE hValue, | |
210 FX_BOOL bSetting, | |
211 XFA_ATTRIBUTE eAttribute) { | |
212 Script_EventPseudoModel_Property(hValue, XFA_EVENT_SELSTART, bSetting); | |
213 } | |
214 void CScript_EventPseudoModel::Script_EventPseudoModel_Shift( | |
215 FXJSE_HVALUE hValue, | |
216 FX_BOOL bSetting, | |
217 XFA_ATTRIBUTE eAttribute) { | |
218 Script_EventPseudoModel_Property(hValue, XFA_EVENT_SHIFT, bSetting); | |
219 } | |
220 void CScript_EventPseudoModel::Script_EventPseudoModel_SoapFaultCode( | |
221 FXJSE_HVALUE hValue, | |
222 FX_BOOL bSetting, | |
223 XFA_ATTRIBUTE eAttribute) { | |
224 Script_EventPseudoModel_Property(hValue, XFA_EVENT_SOAPFAULTCODE, bSetting); | |
225 } | |
226 void CScript_EventPseudoModel::Script_EventPseudoModel_SoapFaultString( | |
227 FXJSE_HVALUE hValue, | |
228 FX_BOOL bSetting, | |
229 XFA_ATTRIBUTE eAttribute) { | |
230 Script_EventPseudoModel_Property(hValue, XFA_EVENT_SOAPFAULTSTRING, bSetting); | |
231 } | |
232 void CScript_EventPseudoModel::Script_EventPseudoModel_Target( | |
233 FXJSE_HVALUE hValue, | |
234 FX_BOOL bSetting, | |
235 XFA_ATTRIBUTE eAttribute) { | |
236 Script_EventPseudoModel_Property(hValue, XFA_EVENT_TARGET, bSetting); | |
237 } | |
238 void CScript_EventPseudoModel::Script_EventPseudoModel_Emit( | |
239 CFXJSE_Arguments* pArguments) { | |
240 IXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); | |
241 if (!pScriptContext) { | |
242 return; | |
243 } | |
244 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); | |
245 if (!pEventParam) { | |
246 return; | |
247 } | |
248 IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify(); | |
249 if (!pNotify) { | |
250 return; | |
251 } | |
252 IXFA_WidgetHandler* pWidgetHandler = pNotify->GetWidgetHandler(); | |
253 if (!pWidgetHandler) { | |
254 return; | |
255 } | |
256 pWidgetHandler->ProcessEvent(pEventParam->m_pTarget, pEventParam); | |
257 } | |
258 void CScript_EventPseudoModel::Script_EventPseudoModel_Reset( | |
259 CFXJSE_Arguments* pArguments) { | |
260 IXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); | |
261 if (!pScriptContext) { | |
262 return; | |
263 } | |
264 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); | |
265 if (!pEventParam) { | |
266 return; | |
267 } | |
268 pEventParam->Reset(); | |
269 } | |
OLD | NEW |