summaryrefslogtreecommitdiff
path: root/fxjs/xfa/cjx_field.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fxjs/xfa/cjx_field.cpp')
-rw-r--r--fxjs/xfa/cjx_field.cpp300
1 files changed, 300 insertions, 0 deletions
diff --git a/fxjs/xfa/cjx_field.cpp b/fxjs/xfa/cjx_field.cpp
index 857aa50d40..059aead0f9 100644
--- a/fxjs/xfa/cjx_field.cpp
+++ b/fxjs/xfa/cjx_field.cpp
@@ -8,6 +8,7 @@
#include <vector>
+#include "core/fxcrt/cfx_decimal.h"
#include "fxjs/cfxjse_value.h"
#include "fxjs/js_resources.h"
#include "xfa/fxfa/cxfa_eventparam.h"
@@ -233,3 +234,302 @@ CJS_Return CJX_Field::execValidate(
false, false);
return CJS_Return(runtime->NewBoolean(iRet != XFA_EVENTERROR_Error));
}
+
+void CJX_Field::defaultValue(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData();
+ if (!pWidgetData)
+ return;
+
+ if (bSetting) {
+ if (pValue) {
+ pWidgetData->SetPreNull(pWidgetData->IsNull());
+ pWidgetData->SetIsNull(pValue->IsNull());
+ }
+
+ WideString wsNewText;
+ if (pValue && !(pValue->IsNull() || pValue->IsUndefined()))
+ wsNewText = pValue->ToWideString();
+
+ CXFA_Node* pUIChild = pWidgetData->GetUIChild();
+ if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
+ wsNewText =
+ pWidgetData->NumericLimit(wsNewText, pWidgetData->GetLeadDigits(),
+ pWidgetData->GetFracDigits());
+ }
+
+ CXFA_WidgetData* pContainerWidgetData =
+ GetXFANode()->GetContainerWidgetData();
+ WideString wsFormatText(wsNewText);
+ if (pContainerWidgetData)
+ wsFormatText = pContainerWidgetData->GetFormatDataValue(wsNewText);
+
+ SetContent(wsNewText, wsFormatText, true, true, true);
+ return;
+ }
+
+ WideString content = GetContent(true);
+ if (content.IsEmpty()) {
+ pValue->SetNull();
+ return;
+ }
+
+ CXFA_Node* pUIChild = pWidgetData->GetUIChild();
+ CXFA_Node* pNode = pWidgetData->GetFormValueData().GetNode()->GetNodeItem(
+ XFA_NODEITEM_FirstChild);
+ if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
+ if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
+ (pNode->JSObject()->GetInteger(XFA_Attribute::FracDigits) == -1)) {
+ pValue->SetString(content.UTF8Encode().AsStringView());
+ } else {
+ CFX_Decimal decimal(content.AsStringView());
+ pValue->SetFloat((float)(double)decimal);
+ }
+ } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
+ pValue->SetInteger(FXSYS_wtoi(content.c_str()));
+ } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
+ pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
+ } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
+ CFX_Decimal decimal(content.AsStringView());
+ pValue->SetFloat((float)(double)decimal);
+ } else {
+ pValue->SetString(content.UTF8Encode().AsStringView());
+ }
+}
+
+void CJX_Field::editValue(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData();
+ if (!pWidgetData)
+ return;
+
+ if (bSetting) {
+ pWidgetData->SetValue(XFA_VALUEPICTURE_Edit, pValue->ToWideString());
+ return;
+ }
+ pValue->SetString(
+ pWidgetData->GetValue(XFA_VALUEPICTURE_Edit).UTF8Encode().AsStringView());
+}
+
+void CJX_Field::formatMessage(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
+}
+
+void CJX_Field::formattedValue(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData();
+ if (!pWidgetData)
+ return;
+
+ if (bSetting) {
+ pWidgetData->SetValue(XFA_VALUEPICTURE_Display, pValue->ToWideString());
+ return;
+ }
+ pValue->SetString(pWidgetData->GetValue(XFA_VALUEPICTURE_Display)
+ .UTF8Encode()
+ .AsStringView());
+}
+
+void CJX_Field::parentSubform(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ if (bSetting) {
+ ThrowInvalidPropertyException();
+ return;
+ }
+ pValue->SetNull();
+}
+
+void CJX_Field::selectedIndex(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData();
+ if (!pWidgetData)
+ return;
+
+ if (!bSetting) {
+ pValue->SetInteger(pWidgetData->GetSelectedItem(0));
+ return;
+ }
+
+ int32_t iIndex = pValue->ToInteger();
+ if (iIndex == -1) {
+ pWidgetData->ClearAllSelections();
+ return;
+ }
+
+ pWidgetData->SetItemState(iIndex, true, true, true, true);
+}
+
+void CJX_Field::access(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::accessKey(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::anchorType(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::borderColor(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Som_BorderColor(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::borderWidth(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Som_BorderWidth(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::colSpan(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::fillColor(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Som_FillColor(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::fontColor(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Som_FontColor(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::h(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::hAlign(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::locale(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::mandatory(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Som_Mandatory(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::mandatoryMessage(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Som_MandatoryMessage(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::maxH(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::maxW(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::minH(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::minW(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::presence(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::rawValue(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ defaultValue(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::relevant(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::rotate(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::use(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::usehref(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::validationMessage(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Som_ValidationMessage(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::vAlign(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::w(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::x(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}
+
+void CJX_Field::y(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ Script_Attribute_String(pValue, bSetting, eAttribute);
+}