1 // Copyright 2017 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 "fxjs/xfa/cjx_boolean.h" 8 9 #include "fxjs/cfxjse_value.h" 10 #include "xfa/fxfa/cxfa_widgetacc.h" 11 #include "xfa/fxfa/parser/cxfa_boolean.h" 12 13 CJX_Boolean::CJX_Boolean(CXFA_Boolean* node) : CJX_Content(node) {} 14 15 CJX_Boolean::~CJX_Boolean() = default; 16 17 void CJX_Boolean::use(CFXJSE_Value* pValue, 18 bool bSetting, 19 XFA_Attribute eAttribute) { 20 Script_Attribute_String(pValue, bSetting, eAttribute); 21 } 22 23 void CJX_Boolean::defaultValue(CFXJSE_Value* pValue, 24 bool bSetting, 25 XFA_Attribute eAttribute) { 26 if (!bSetting) { 27 WideString wsValue = GetContent(true); 28 pValue->SetBoolean(wsValue == L"1"); 29 return; 30 } 31 32 ByteString newValue; 33 if (pValue && !(pValue->IsNull() || pValue->IsUndefined())) 34 newValue = pValue->ToString(); 35 36 int32_t iValue = FXSYS_atoi(newValue.c_str()); 37 WideString wsNewValue(iValue == 0 ? L"0" : L"1"); 38 WideString wsFormatValue(wsNewValue); 39 CXFA_WidgetAcc* pContainerWidgetAcc = 40 ToNode(GetXFAObject())->GetContainerWidgetAcc(); 41 if (pContainerWidgetAcc) 42 wsFormatValue = pContainerWidgetAcc->GetFormatDataValue(wsNewValue); 43 44 SetContent(wsNewValue, wsFormatValue, true, true, true); 45 } 46 47 void CJX_Boolean::usehref(CFXJSE_Value* pValue, 48 bool bSetting, 49 XFA_Attribute eAttribute) { 50 Script_Attribute_String(pValue, bSetting, eAttribute); 51 } 52 53 void CJX_Boolean::value(CFXJSE_Value* pValue, 54 bool bSetting, 55 XFA_Attribute eAttribute) { 56 defaultValue(pValue, bSetting, eAttribute); 57 } 58