summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser/xfa_script_eventpseudomodel.cpp
blob: 4cfcf1cbc7114d5a276bd5c76e88309d966d822c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#include "xfa/fxfa/parser/xfa_script_eventpseudomodel.h"

#include "xfa/fxfa/app/xfa_ffnotify.h"
#include "xfa/fxfa/fm2js/xfa_fm2jsapi.h"
#include "xfa/fxfa/parser/xfa_docdata.h"
#include "xfa/fxfa/parser/xfa_doclayout.h"
#include "xfa/fxfa/parser/xfa_document.h"
#include "xfa/fxfa/parser/xfa_localemgr.h"
#include "xfa/fxfa/parser/xfa_object.h"
#include "xfa/fxfa/parser/xfa_parser.h"
#include "xfa/fxfa/parser/xfa_parser_imp.h"
#include "xfa/fxfa/parser/xfa_script.h"
#include "xfa/fxfa/parser/xfa_script_imp.h"
#include "xfa/fxfa/parser/xfa_utils.h"
#include "xfa/fxjse/cfxjse_arguments.h"
#include "xfa/include/fxfa/xfa_ffwidgethandler.h"

CScript_EventPseudoModel::CScript_EventPseudoModel(CXFA_Document* pDocument)
    : CXFA_OrdinaryObject(pDocument, XFA_ELEMENT_EventPseudoModel) {
  m_uScriptHash = XFA_HASHCODE_Event;
}
CScript_EventPseudoModel::~CScript_EventPseudoModel() {}
void Script_EventPseudoModel_StringProperty(FXJSE_HVALUE hValue,
                                            CFX_WideString& wsValue,
                                            FX_BOOL bSetting) {
  if (bSetting) {
    CFX_ByteString bsValue;
    FXJSE_Value_ToUTF8String(hValue, bsValue);
    wsValue = CFX_WideString::FromUTF8(bsValue, bsValue.GetLength());
  } else {
    FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsValue).AsByteStringC());
  }
}
void Script_EventPseudoModel_InterProperty(FXJSE_HVALUE hValue,
                                           int32_t& iValue,
                                           FX_BOOL bSetting) {
  if (bSetting) {
    iValue = FXJSE_Value_ToInteger(hValue);
  } else {
    FXJSE_Value_SetInteger(hValue, iValue);
  }
}
void Script_EventPseudoModel_BooleanProperty(FXJSE_HVALUE hValue,
                                             FX_BOOL& bValue,
                                             FX_BOOL bSetting) {
  if (bSetting) {
    bValue = FXJSE_Value_ToBoolean(hValue);
  } else {
    FXJSE_Value_SetBoolean(hValue, bValue);
  }
}
void CScript_EventPseudoModel::Script_EventPseudoModel_Property(
    FXJSE_HVALUE hValue,
    uint32_t dwFlag,
    FX_BOOL bSetting) {
  CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
  if (!pScriptContext) {
    return;
  }
  CXFA_EventParam* pEventParam = pScriptContext->GetEventParam();
  if (!pEventParam) {
    return;
  }
  switch (dwFlag) {
    case XFA_EVENT_CANCELACTION:
      Script_EventPseudoModel_BooleanProperty(
          hValue, pEventParam->m_bCancelAction, bSetting);
      break;
    case XFA_EVENT_CHANGE:
      Script_EventPseudoModel_StringProperty(hValue, pEventParam->m_wsChange,
                                             bSetting);
      break;
    case XFA_EVENT_COMMITKEY:
      Script_EventPseudoModel_InterProperty(hValue, pEventParam->m_iCommitKey,
                                            bSetting);
      break;
    case XFA_EVENT_FULLTEXT:
      Script_EventPseudoModel_StringProperty(hValue, pEventParam->m_wsFullText,
                                             bSetting);
      break;
    case XFA_EVENT_KEYDOWN:
      Script_EventPseudoModel_BooleanProperty(hValue, pEventParam->m_bKeyDown,
                                              bSetting);
      break;
    case XFA_EVENT_MODIFIER:
      Script_EventPseudoModel_BooleanProperty(hValue, pEventParam->m_bModifier,
                                              bSetting);
      break;
    case XFA_EVENT_NEWCONTENTTYPE:
      Script_EventPseudoModel_StringProperty(
          hValue, pEventParam->m_wsNewContentType, bSetting);
      break;
    case XFA_EVENT_NEWTEXT:
      Script_EventPseudoModel_StringProperty(hValue, pEventParam->m_wsNewText,
                                             bSetting);
      break;
    case XFA_EVENT_PREVCONTENTTYPE:
      Script_EventPseudoModel_StringProperty(
          hValue, pEventParam->m_wsPrevContentType, bSetting);
      break;
    case XFA_EVENT_PREVTEXT:
      Script_EventPseudoModel_StringProperty(hValue, pEventParam->m_wsPrevText,
                                             bSetting);
      break;
    case XFA_EVENT_REENTER:
      Script_EventPseudoModel_BooleanProperty(hValue, pEventParam->m_bReenter,
                                              bSetting);
      break;
    case XFA_EVENT_SELEND:
      Script_EventPseudoModel_InterProperty(hValue, pEventParam->m_iSelEnd,
                                            bSetting);
      break;
    case XFA_EVENT_SELSTART:
      Script_EventPseudoModel_InterProperty(hValue, pEventParam->m_iSelStart,
                                            bSetting);
      break;
    case XFA_EVENT_SHIFT:
      Script_EventPseudoModel_BooleanProperty(hValue, pEventParam->m_bShift,
                                              bSetting);
      break;
    case XFA_EVENT_SOAPFAULTCODE:
      Script_EventPseudoModel_StringProperty(
          hValue, pEventParam->m_wsSoapFaultCode, bSetting);
      break;
    case XFA_EVENT_SOAPFAULTSTRING:
      Script_EventPseudoModel_StringProperty(
          hValue, pEventParam->m_wsSoapFaultString, bSetting);
      break;
    case XFA_EVENT_TARGET:
      break;
    default:
      break;
  }
}
void CScript_EventPseudoModel::Script_EventPseudoModel_CancelAction(
    FXJSE_HVALUE hValue,
    FX_BOOL bSetting,
    XFA_ATTRIBUTE eAttribute) {
  Script_EventPseudoModel_Property(hValue, XFA_EVENT_CANCELACTION, bSetting);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_Change(
    FXJSE_HVALUE hValue,
    FX_BOOL bSetting,
    XFA_ATTRIBUTE eAttribute) {
  Script_EventPseudoModel_Property(hValue, XFA_EVENT_CHANGE, bSetting);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_CommitKey(
    FXJSE_HVALUE hValue,
    FX_BOOL bSetting,
    XFA_ATTRIBUTE eAttribute) {
  Script_EventPseudoModel_Property(hValue, XFA_EVENT_COMMITKEY, bSetting);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_FullText(
    FXJSE_HVALUE hValue,
    FX_BOOL bSetting,
    XFA_ATTRIBUTE eAttribute) {
  Script_EventPseudoModel_Property(hValue, XFA_EVENT_FULLTEXT, bSetting);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_KeyDown(
    FXJSE_HVALUE hValue,
    FX_BOOL bSetting,
    XFA_ATTRIBUTE eAttribute) {
  Script_EventPseudoModel_Property(hValue, XFA_EVENT_KEYDOWN, bSetting);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_Modifier(
    FXJSE_HVALUE hValue,
    FX_BOOL bSetting,
    XFA_ATTRIBUTE eAttribute) {
  Script_EventPseudoModel_Property(hValue, XFA_EVENT_MODIFIER, bSetting);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_NewContentType(
    FXJSE_HVALUE hValue,
    FX_BOOL bSetting,
    XFA_ATTRIBUTE eAttribute) {
  Script_EventPseudoModel_Property(hValue, XFA_EVENT_NEWCONTENTTYPE, bSetting);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_NewText(
    FXJSE_HVALUE hValue,
    FX_BOOL bSetting,
    XFA_ATTRIBUTE eAttribute) {
  Script_EventPseudoModel_Property(hValue, XFA_EVENT_NEWTEXT, bSetting);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_PrevContentType(
    FXJSE_HVALUE hValue,
    FX_BOOL bSetting,
    XFA_ATTRIBUTE eAttribute) {
  Script_EventPseudoModel_Property(hValue, XFA_EVENT_PREVCONTENTTYPE, bSetting);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_PrevText(
    FXJSE_HVALUE hValue,
    FX_BOOL bSetting,
    XFA_ATTRIBUTE eAttribute) {
  Script_EventPseudoModel_Property(hValue, XFA_EVENT_PREVTEXT, bSetting);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_Reenter(
    FXJSE_HVALUE hValue,
    FX_BOOL bSetting,
    XFA_ATTRIBUTE eAttribute) {
  Script_EventPseudoModel_Property(hValue, XFA_EVENT_REENTER, bSetting);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_SelEnd(
    FXJSE_HVALUE hValue,
    FX_BOOL bSetting,
    XFA_ATTRIBUTE eAttribute) {
  Script_EventPseudoModel_Property(hValue, XFA_EVENT_SELEND, bSetting);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_SelStart(
    FXJSE_HVALUE hValue,
    FX_BOOL bSetting,
    XFA_ATTRIBUTE eAttribute) {
  Script_EventPseudoModel_Property(hValue, XFA_EVENT_SELSTART, bSetting);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_Shift(
    FXJSE_HVALUE hValue,
    FX_BOOL bSetting,
    XFA_ATTRIBUTE eAttribute) {
  Script_EventPseudoModel_Property(hValue, XFA_EVENT_SHIFT, bSetting);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_SoapFaultCode(
    FXJSE_HVALUE hValue,
    FX_BOOL bSetting,
    XFA_ATTRIBUTE eAttribute) {
  Script_EventPseudoModel_Property(hValue, XFA_EVENT_SOAPFAULTCODE, bSetting);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_SoapFaultString(
    FXJSE_HVALUE hValue,
    FX_BOOL bSetting,
    XFA_ATTRIBUTE eAttribute) {
  Script_EventPseudoModel_Property(hValue, XFA_EVENT_SOAPFAULTSTRING, bSetting);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_Target(
    FXJSE_HVALUE hValue,
    FX_BOOL bSetting,
    XFA_ATTRIBUTE eAttribute) {
  Script_EventPseudoModel_Property(hValue, XFA_EVENT_TARGET, bSetting);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_Emit(
    CFXJSE_Arguments* pArguments) {
  CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
  if (!pScriptContext) {
    return;
  }
  CXFA_EventParam* pEventParam = pScriptContext->GetEventParam();
  if (!pEventParam) {
    return;
  }
  CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify();
  if (!pNotify) {
    return;
  }
  CXFA_FFWidgetHandler* pWidgetHandler = pNotify->GetWidgetHandler();
  if (!pWidgetHandler) {
    return;
  }
  pWidgetHandler->ProcessEvent(pEventParam->m_pTarget, pEventParam);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_Reset(
    CFXJSE_Arguments* pArguments) {
  CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
  if (!pScriptContext) {
    return;
  }
  CXFA_EventParam* pEventParam = pScriptContext->GetEventParam();
  if (!pEventParam) {
    return;
  }
  pEventParam->Reset();
}