7#include "fxjs/xfa/cjx_field.h"
9#include "core/fxcrt/numerics/safe_conversions.h"
10#include "core/fxcrt/span.h"
11#include "fxjs/cfx_v8.h"
13#include "fxjs/js_resources.h"
14#include "v8/include/v8-primitive.h"
15#include "xfa/fgas/crt/cfgas_decimal.h"
16#include "xfa/fxfa/cxfa_eventparam.h"
17#include "xfa/fxfa/cxfa_ffnotify.h"
18#include "xfa/fxfa/fxfa.h"
19#include "xfa/fxfa/parser/cxfa_document.h"
20#include "xfa/fxfa/parser/cxfa_field.h"
21#include "xfa/fxfa/parser/cxfa_value.h"
24 {
"addItem", addItem_static},
25 {
"boundItem", boundItem_static},
26 {
"clearItems", clearItems_static},
27 {
"deleteItem", deleteItem_static},
28 {
"execCalculate", execCalculate_static},
29 {
"execEvent", execEvent_static},
30 {
"execInitialize", execInitialize_static},
31 {
"execValidate", execValidate_static},
32 {
"getDisplayItem", getDisplayItem_static},
33 {
"getItemState", getItemState_static},
34 {
"getSaveItem", getSaveItem_static},
35 {
"setItemState", setItemState_static}};
37CJX_Field::CJX_Field(CXFA_Field* field) :
CJX_Container(field) {
38 DefineMethods(MethodSpecs);
48 pdfium::span<v8::Local<v8::Value>> params) {
56 pdfium::span<v8::Local<v8::Value>> params) {
57 if (params.size() != 1)
60 WideString eventString = runtime->ToWideString(params[0]);
72 pdfium::span<v8::Local<v8::Value>> params) {
85 pdfium::span<v8::Local<v8::Value>> params) {
86 if (params.size() != 1)
93 bool bValue = node->DeleteItem(runtime->ToInt32(params[0]),
true,
true);
98 pdfium::span<v8::Local<v8::Value>> params) {
99 if (params.size() != 1)
102 int32_t iIndex = runtime->ToInt32(params[0]);
110 std::optional<
WideString> value = node->GetChoiceListItem(iIndex,
true);
111 if (!value.has_value())
115 runtime->NewString(value->ToUTF8().AsStringView())
);
119 pdfium::span<v8::Local<v8::Value>> params) {
120 if (params.size() != 1)
127 WideString value = runtime->ToWideString(params[0]);
130 runtime->NewString(boundValue
.ToUTF8().AsStringView())
);
134 pdfium::span<v8::Local<v8::Value>> params) {
135 if (params.size() != 1)
142 int32_t state = node->GetItemState(runtime->ToInt32(params[0]));
147 pdfium::span<v8::Local<v8::Value>> params) {
161 pdfium::span<v8::Local<v8::Value>> params) {
162 if (params.size() != 1)
165 int32_t iIndex = runtime->ToInt32(params[0]);
173 std::optional<
WideString> value = node->GetChoiceListItem(iIndex,
false);
174 if (!value.has_value())
178 runtime->NewString(value->ToUTF8().AsStringView())
);
182 pdfium::span<v8::Local<v8::Value>> params) {
183 if (params.size() != 2)
190 int32_t iIndex = runtime->ToInt32(params[0]);
191 if (runtime->ToInt32(params[1]) != 0) {
202 pdfium::span<v8::Local<v8::Value>> params) {
203 if (params.size() != 1 && params.size() != 2)
211 if (params.size() >= 1)
212 label = runtime->ToWideString(params[0]);
215 if (params.size() >= 2)
216 value = runtime->ToWideString(params[1]);
223 pdfium::span<v8::Local<v8::Value>> params) {
237void CJX_Field::defaultValue(
v8::Isolate* pIsolate,
238 v8::Local<v8::Value>* pValue,
253 wsNewText = fxv8::ReentrantToWideStringHelper(pIsolate, *pValue);
262 SetContent(wsNewText, wsFormatText,
true,
true,
true);
267 if (content.IsEmpty()) {
268 *pValue = fxv8::NewNullHelper(pIsolate);
273 CXFA_Node* pNode = formValue ? formValue->GetFirstChild() :
nullptr;
277 (pNode->JSObject()->GetInteger(
XFA_Attribute::FracDigits) == -1)) {
279 fxv8::NewStringHelper(pIsolate, content
.ToUTF8().AsStringView());
282 *pValue = fxv8::NewNumberHelper(pIsolate, decimal
.ToFloat());
285 *pValue = fxv8::NewNumberHelper(pIsolate, FXSYS_wtoi(content.c_str()));
288 fxv8::NewBooleanHelper(pIsolate, FXSYS_wtoi(content.c_str()) != 0);
291 *pValue = fxv8::NewNumberHelper(pIsolate, decimal
.ToFloat());
293 *pValue = fxv8::NewStringHelper(pIsolate, content
.ToUTF8().AsStringView());
297void CJX_Field::editValue(
v8::Isolate* pIsolate,
298 v8::Local<v8::Value>* pValue,
307 fxv8::ReentrantToWideStringHelper(pIsolate, *pValue)
);
310 *pValue = fxv8::NewStringHelper(
315void CJX_Field::formatMessage(
v8::Isolate* pIsolate,
316 v8::Local<v8::Value>* pValue,
319 ScriptSomMessage(pIsolate, pValue, bSetting, SOMMessageType::kFormatMessage);
322void CJX_Field::formattedValue(
v8::Isolate* pIsolate,
323 v8::Local<v8::Value>* pValue,
332 fxv8::ReentrantToWideStringHelper(pIsolate, *pValue)
);
335 *pValue = fxv8::NewStringHelper(
340void CJX_Field::length(
v8::Isolate* pIsolate,
341 v8::Local<v8::Value>* pValue,
350 *pValue = fxv8::NewNumberHelper(
352 node->CountChoiceListItems(
true))
356void CJX_Field::parentSubform(
v8::Isolate* pIsolate,
357 v8::Local<v8::Value>* pValue,
364 *pValue = fxv8::NewNullHelper(pIsolate);
367void CJX_Field::selectedIndex(
v8::Isolate* pIsolate,
368 v8::Local<v8::Value>* pValue,
380 int32_t iIndex = fxv8::ReentrantToInt32Helper(pIsolate, *pValue);
389void CJX_Field::rawValue(
v8::Isolate* pIsolate,
390 v8::Local<v8::Value>* pValue,
393 defaultValue(pIsolate, pValue, bSetting, eAttribute);
friend class EventParamScope
static CJS_Result Success()
static CJS_Result Failure(JSMessage id)
bool DynamicTypeIs(TypeTag eType) const override
bool DynamicTypeIs(TypeTag eType) const override
XFA_EventError execSingleEventByName(WideStringView wsEventName, XFA_Element eType)
WideString GetContent(bool bScriptModify) const
void ThrowInvalidPropertyException(v8::Isolate *pIsolate) const
CXFA_Document * GetDocument() const
CXFA_Node * GetXFANode() const
void SetContent(const WideString &wsContent, const WideString &wsXMLValue, bool bNotify, bool bScriptModify, bool bSyncData)
XFA_EventError ExecEventByDeepFirst(CXFA_Node *pFormNode, XFA_EVENTTYPE eEventType, bool bIsFormReady, bool bRecursive)
CXFA_Value * GetFormValueIfExists() const
WideString GetValue(XFA_ValuePicture eValueType)
bool SetValue(XFA_ValuePicture eValueType, const WideString &wsValue)
int32_t GetSelectedItem(int32_t nIndex)
void SetItemState(int32_t nIndex, bool bSelected, bool bNotify, bool bScriptModify)
WideString NumericLimit(const WideString &wsValue)
void InsertItem(const WideString &wsLabel, const WideString &wsValue, bool bNotify)
WideString GetFormatDataValue(const WideString &wsValue)
bool DeleteItem(int32_t nIndex, bool bNotify, bool bScriptModify)
void SetPreNull(bool val)
bool GetItemState(int32_t nIndex)
void ClearAllSelections()
CXFA_Node * GetContainerNode()
bool IsWidgetReady() const
CXFA_Node * GetUIChildNode()
WideString GetItemValue(WideStringView wsLabel)
XFA_Element GetElementType() const
ByteString ToUTF8() const
WideString & operator=(WideString &&that) noexcept
WideString(const WideString &other)=default
bool EqualsASCII(ByteStringView that) const
bool IsUndefined(v8::Local< v8::Value > value)
bool IsNull(v8::Local< v8::Value > value)
fxcrt::WideString WideString