| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fxfa/parser/xfa_utils.h" | 7 #include "xfa/fxfa/parser/xfa_utils.h" |
| 8 | 8 |
| 9 #include "core/fxcrt/include/fx_ext.h" | 9 #include "core/fxcrt/include/fx_ext.h" |
| 10 #include "xfa/fde/xml/fde_xml_imp.h" | 10 #include "xfa/fde/xml/fde_xml_imp.h" |
| 11 #include "xfa/fxfa/parser/xfa_doclayout.h" | 11 #include "xfa/fxfa/parser/xfa_doclayout.h" |
| 12 #include "xfa/fxfa/parser/xfa_document.h" | 12 #include "xfa/fxfa/parser/xfa_document.h" |
| 13 #include "xfa/fxfa/parser/xfa_localemgr.h" | 13 #include "xfa/fxfa/parser/xfa_localemgr.h" |
| 14 #include "xfa/fxfa/parser/xfa_localevalue.h" | 14 #include "xfa/fxfa/parser/xfa_localevalue.h" |
| 15 #include "xfa/fxfa/parser/xfa_object.h" | 15 #include "xfa/fxfa/parser/xfa_object.h" |
| 16 #include "xfa/fxfa/parser/xfa_parser.h" | 16 #include "xfa/fxfa/parser/xfa_parser.h" |
| 17 #include "xfa/fxfa/parser/xfa_script.h" | 17 #include "xfa/fxfa/parser/xfa_script.h" |
| 18 | 18 |
| 19 CXFA_Node* XFA_CreateUIChild(CXFA_Node* pNode, XFA_ELEMENT& eWidgetType) { | 19 CXFA_Node* XFA_CreateUIChild(CXFA_Node* pNode, XFA_Element& eWidgetType) { |
| 20 XFA_ELEMENT eType = pNode->GetClassID(); | 20 XFA_Element eType = pNode->GetClassID(); |
| 21 eWidgetType = eType; | 21 eWidgetType = eType; |
| 22 if (eType != XFA_ELEMENT_Field && eType != XFA_ELEMENT_Draw) { | 22 if (eType != XFA_Element::Field && eType != XFA_Element::Draw) { |
| 23 return NULL; | 23 return NULL; |
| 24 } | 24 } |
| 25 eWidgetType = XFA_ELEMENT_UNKNOWN; | 25 eWidgetType = XFA_Element::Unknown; |
| 26 XFA_ELEMENT eUIType = XFA_ELEMENT_UNKNOWN; | 26 XFA_Element eUIType = XFA_Element::Unknown; |
| 27 CXFA_Value defValue(pNode->GetProperty(0, XFA_ELEMENT_Value, TRUE)); | 27 CXFA_Value defValue(pNode->GetProperty(0, XFA_Element::Value, TRUE)); |
| 28 XFA_ELEMENT eValueType = (XFA_ELEMENT)defValue.GetChildValueClassID(); | 28 XFA_Element eValueType = defValue.GetChildValueClassID(); |
| 29 switch (eValueType) { | 29 switch (eValueType) { |
| 30 case XFA_ELEMENT_Boolean: | 30 case XFA_Element::Boolean: |
| 31 eUIType = XFA_ELEMENT_CheckButton; | 31 eUIType = XFA_Element::CheckButton; |
| 32 break; | 32 break; |
| 33 case XFA_ELEMENT_Integer: | 33 case XFA_Element::Integer: |
| 34 case XFA_ELEMENT_Decimal: | 34 case XFA_Element::Decimal: |
| 35 case XFA_ELEMENT_Float: | 35 case XFA_Element::Float: |
| 36 eUIType = XFA_ELEMENT_NumericEdit; | 36 eUIType = XFA_Element::NumericEdit; |
| 37 break; | 37 break; |
| 38 case XFA_ELEMENT_ExData: | 38 case XFA_Element::ExData: |
| 39 case XFA_ELEMENT_Text: | 39 case XFA_Element::Text: |
| 40 eUIType = XFA_ELEMENT_TextEdit; | 40 eUIType = XFA_Element::TextEdit; |
| 41 eWidgetType = XFA_ELEMENT_Text; | 41 eWidgetType = XFA_Element::Text; |
| 42 break; | 42 break; |
| 43 case XFA_ELEMENT_Date: | 43 case XFA_Element::Date: |
| 44 case XFA_ELEMENT_Time: | 44 case XFA_Element::Time: |
| 45 case XFA_ELEMENT_DateTime: | 45 case XFA_Element::DateTime: |
| 46 eUIType = XFA_ELEMENT_DateTimeEdit; | 46 eUIType = XFA_Element::DateTimeEdit; |
| 47 break; | 47 break; |
| 48 case XFA_ELEMENT_Image: | 48 case XFA_Element::Image: |
| 49 eUIType = XFA_ELEMENT_ImageEdit; | 49 eUIType = XFA_Element::ImageEdit; |
| 50 eWidgetType = XFA_ELEMENT_Image; | 50 eWidgetType = XFA_Element::Image; |
| 51 break; | 51 break; |
| 52 case XFA_ELEMENT_Arc: | 52 case XFA_Element::Arc: |
| 53 case XFA_ELEMENT_Line: | 53 case XFA_Element::Line: |
| 54 case XFA_ELEMENT_Rectangle: | 54 case XFA_Element::Rectangle: |
| 55 eUIType = XFA_ELEMENT_DefaultUi; | 55 eUIType = XFA_Element::DefaultUi; |
| 56 eWidgetType = eValueType; | 56 eWidgetType = eValueType; |
| 57 break; | 57 break; |
| 58 default: | 58 default: |
| 59 break; | 59 break; |
| 60 } | 60 } |
| 61 CXFA_Node* pUIChild = NULL; | 61 CXFA_Node* pUIChild = NULL; |
| 62 CXFA_Node* pUI = pNode->GetProperty(0, XFA_ELEMENT_Ui, TRUE); | 62 CXFA_Node* pUI = pNode->GetProperty(0, XFA_Element::Ui, TRUE); |
| 63 CXFA_Node* pChild = pUI->GetNodeItem(XFA_NODEITEM_FirstChild); | 63 CXFA_Node* pChild = pUI->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 64 for (; pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { | 64 for (; pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 65 XFA_ELEMENT eChild = pChild->GetClassID(); | 65 XFA_Element eChild = pChild->GetClassID(); |
| 66 if (eChild == XFA_ELEMENT_Extras || eChild == XFA_ELEMENT_Picture) { | 66 if (eChild == XFA_Element::Extras || eChild == XFA_Element::Picture) { |
| 67 continue; | 67 continue; |
| 68 } | 68 } |
| 69 const XFA_PROPERTY* pProperty = | 69 const XFA_PROPERTY* pProperty = |
| 70 XFA_GetPropertyOfElement(XFA_ELEMENT_Ui, eChild, XFA_XDPPACKET_Form); | 70 XFA_GetPropertyOfElement(XFA_Element::Ui, eChild, XFA_XDPPACKET_Form); |
| 71 if (pProperty && (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) { | 71 if (pProperty && (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) { |
| 72 pUIChild = pChild; | 72 pUIChild = pChild; |
| 73 break; | 73 break; |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 if (eType == XFA_ELEMENT_Draw) { | 76 if (eType == XFA_Element::Draw) { |
| 77 XFA_ELEMENT eDraw = pUIChild ? pUIChild->GetClassID() : XFA_ELEMENT_UNKNOWN; | 77 XFA_Element eDraw = |
| 78 pUIChild ? pUIChild->GetClassID() : XFA_Element::Unknown; |
| 78 switch (eDraw) { | 79 switch (eDraw) { |
| 79 case XFA_ELEMENT_TextEdit: | 80 case XFA_Element::TextEdit: |
| 80 eWidgetType = XFA_ELEMENT_Text; | 81 eWidgetType = XFA_Element::Text; |
| 81 break; | 82 break; |
| 82 case XFA_ELEMENT_ImageEdit: | 83 case XFA_Element::ImageEdit: |
| 83 eWidgetType = XFA_ELEMENT_Image; | 84 eWidgetType = XFA_Element::Image; |
| 84 break; | 85 break; |
| 85 default: | 86 default: |
| 86 eWidgetType = | 87 eWidgetType = eWidgetType == XFA_Element::Unknown ? XFA_Element::Text |
| 87 eWidgetType == XFA_ELEMENT_UNKNOWN ? XFA_ELEMENT_Text : eWidgetType; | 88 : eWidgetType; |
| 88 break; | 89 break; |
| 89 } | 90 } |
| 90 } else { | 91 } else { |
| 91 if (pUIChild && pUIChild->GetClassID() == XFA_ELEMENT_DefaultUi) { | 92 if (pUIChild && pUIChild->GetClassID() == XFA_Element::DefaultUi) { |
| 92 eWidgetType = XFA_ELEMENT_TextEdit; | 93 eWidgetType = XFA_Element::TextEdit; |
| 93 } else { | 94 } else { |
| 94 eWidgetType = pUIChild | 95 eWidgetType = |
| 95 ? pUIChild->GetClassID() | 96 pUIChild ? pUIChild->GetClassID() |
| 96 : (eUIType == XFA_ELEMENT_UNKNOWN ? XFA_ELEMENT_TextEdit | 97 : (eUIType == XFA_Element::Unknown ? XFA_Element::TextEdit |
| 97 : eUIType); | 98 : eUIType); |
| 98 } | 99 } |
| 99 } | 100 } |
| 100 if (!pUIChild) { | 101 if (!pUIChild) { |
| 101 if (eUIType == XFA_ELEMENT_UNKNOWN) { | 102 if (eUIType == XFA_Element::Unknown) { |
| 102 eUIType = XFA_ELEMENT_TextEdit; | 103 eUIType = XFA_Element::TextEdit; |
| 103 defValue.GetNode()->GetProperty(0, XFA_ELEMENT_Text, TRUE); | 104 defValue.GetNode()->GetProperty(0, XFA_Element::Text, TRUE); |
| 104 } | 105 } |
| 105 pUIChild = pUI->GetProperty(0, eUIType, TRUE); | 106 pUIChild = pUI->GetProperty(0, eUIType, TRUE); |
| 106 } else if (eUIType == XFA_ELEMENT_UNKNOWN) { | 107 } else if (eUIType == XFA_Element::Unknown) { |
| 107 switch (pUIChild->GetClassID()) { | 108 switch (pUIChild->GetClassID()) { |
| 108 case XFA_ELEMENT_CheckButton: { | 109 case XFA_Element::CheckButton: { |
| 109 eValueType = XFA_ELEMENT_Text; | 110 eValueType = XFA_Element::Text; |
| 110 if (CXFA_Node* pItems = pNode->GetChild(0, XFA_ELEMENT_Items)) { | 111 if (CXFA_Node* pItems = pNode->GetChild(0, XFA_Element::Items)) { |
| 111 if (CXFA_Node* pItem = pItems->GetChild(0, XFA_ELEMENT_UNKNOWN)) { | 112 if (CXFA_Node* pItem = pItems->GetChild(0, XFA_Element::Unknown)) { |
| 112 eValueType = pItem->GetClassID(); | 113 eValueType = pItem->GetClassID(); |
| 113 } | 114 } |
| 114 } | 115 } |
| 115 } break; | 116 } break; |
| 116 case XFA_ELEMENT_DateTimeEdit: | 117 case XFA_Element::DateTimeEdit: |
| 117 eValueType = XFA_ELEMENT_DateTime; | 118 eValueType = XFA_Element::DateTime; |
| 118 break; | 119 break; |
| 119 case XFA_ELEMENT_ImageEdit: | 120 case XFA_Element::ImageEdit: |
| 120 eValueType = XFA_ELEMENT_Image; | 121 eValueType = XFA_Element::Image; |
| 121 break; | 122 break; |
| 122 case XFA_ELEMENT_NumericEdit: | 123 case XFA_Element::NumericEdit: |
| 123 eValueType = XFA_ELEMENT_Float; | 124 eValueType = XFA_Element::Float; |
| 124 break; | 125 break; |
| 125 case XFA_ELEMENT_ChoiceList: { | 126 case XFA_Element::ChoiceList: { |
| 126 eValueType = (pUIChild->GetEnum(XFA_ATTRIBUTE_Open) == | 127 eValueType = (pUIChild->GetEnum(XFA_ATTRIBUTE_Open) == |
| 127 XFA_ATTRIBUTEENUM_MultiSelect) | 128 XFA_ATTRIBUTEENUM_MultiSelect) |
| 128 ? XFA_ELEMENT_ExData | 129 ? XFA_Element::ExData |
| 129 : XFA_ELEMENT_Text; | 130 : XFA_Element::Text; |
| 130 } break; | 131 } break; |
| 131 case XFA_ELEMENT_Barcode: | 132 case XFA_Element::Barcode: |
| 132 case XFA_ELEMENT_Button: | 133 case XFA_Element::Button: |
| 133 case XFA_ELEMENT_PasswordEdit: | 134 case XFA_Element::PasswordEdit: |
| 134 case XFA_ELEMENT_Signature: | 135 case XFA_Element::Signature: |
| 135 case XFA_ELEMENT_TextEdit: | 136 case XFA_Element::TextEdit: |
| 136 default: | 137 default: |
| 137 eValueType = XFA_ELEMENT_Text; | 138 eValueType = XFA_Element::Text; |
| 138 break; | 139 break; |
| 139 } | 140 } |
| 140 defValue.GetNode()->GetProperty(0, eValueType, TRUE); | 141 defValue.GetNode()->GetProperty(0, eValueType, TRUE); |
| 141 } | 142 } |
| 142 return pUIChild; | 143 return pUIChild; |
| 143 } | 144 } |
| 144 CXFA_LocaleValue XFA_GetLocaleValue(CXFA_WidgetData* pWidgetData) { | 145 CXFA_LocaleValue XFA_GetLocaleValue(CXFA_WidgetData* pWidgetData) { |
| 145 CXFA_Node* pNodeValue = | 146 CXFA_Node* pNodeValue = |
| 146 pWidgetData->GetNode()->GetChild(0, XFA_ELEMENT_Value); | 147 pWidgetData->GetNode()->GetChild(0, XFA_Element::Value); |
| 147 if (!pNodeValue) { | 148 if (!pNodeValue) { |
| 148 return CXFA_LocaleValue(); | 149 return CXFA_LocaleValue(); |
| 149 } | 150 } |
| 150 CXFA_Node* pValueChild = pNodeValue->GetNodeItem(XFA_NODEITEM_FirstChild); | 151 CXFA_Node* pValueChild = pNodeValue->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 151 if (!pValueChild) { | 152 if (!pValueChild) { |
| 152 return CXFA_LocaleValue(); | 153 return CXFA_LocaleValue(); |
| 153 } | 154 } |
| 154 int32_t iVTType = XFA_VT_NULL; | 155 int32_t iVTType = XFA_VT_NULL; |
| 155 XFA_ELEMENT eType = pValueChild->GetClassID(); | 156 XFA_Element eType = pValueChild->GetClassID(); |
| 156 switch (eType) { | 157 switch (eType) { |
| 157 case XFA_ELEMENT_Decimal: | 158 case XFA_Element::Decimal: |
| 158 iVTType = XFA_VT_DECIMAL; | 159 iVTType = XFA_VT_DECIMAL; |
| 159 break; | 160 break; |
| 160 case XFA_ELEMENT_Float: | 161 case XFA_Element::Float: |
| 161 iVTType = XFA_VT_FLOAT; | 162 iVTType = XFA_VT_FLOAT; |
| 162 break; | 163 break; |
| 163 case XFA_ELEMENT_Date: | 164 case XFA_Element::Date: |
| 164 iVTType = XFA_VT_DATE; | 165 iVTType = XFA_VT_DATE; |
| 165 break; | 166 break; |
| 166 case XFA_ELEMENT_Time: | 167 case XFA_Element::Time: |
| 167 iVTType = XFA_VT_TIME; | 168 iVTType = XFA_VT_TIME; |
| 168 break; | 169 break; |
| 169 case XFA_ELEMENT_DateTime: | 170 case XFA_Element::DateTime: |
| 170 iVTType = XFA_VT_DATETIME; | 171 iVTType = XFA_VT_DATETIME; |
| 171 break; | 172 break; |
| 172 case XFA_ELEMENT_Boolean: | 173 case XFA_Element::Boolean: |
| 173 iVTType = XFA_VT_BOOLEAN; | 174 iVTType = XFA_VT_BOOLEAN; |
| 174 break; | 175 break; |
| 175 case XFA_ELEMENT_Integer: | 176 case XFA_Element::Integer: |
| 176 iVTType = XFA_VT_INTEGER; | 177 iVTType = XFA_VT_INTEGER; |
| 177 break; | 178 break; |
| 178 case XFA_ELEMENT_Text: | 179 case XFA_Element::Text: |
| 179 iVTType = XFA_VT_TEXT; | 180 iVTType = XFA_VT_TEXT; |
| 180 break; | 181 break; |
| 181 default: | 182 default: |
| 182 iVTType = XFA_VT_NULL; | 183 iVTType = XFA_VT_NULL; |
| 183 break; | 184 break; |
| 184 } | 185 } |
| 185 return CXFA_LocaleValue(iVTType, pWidgetData->GetRawValue(), | 186 return CXFA_LocaleValue(iVTType, pWidgetData->GetRawValue(), |
| 186 pWidgetData->GetNode()->GetDocument()->GetLocalMgr()); | 187 pWidgetData->GetNode()->GetDocument()->GetLocalMgr()); |
| 187 } | 188 } |
| 188 void XFA_GetPlainTextFromRichText(CFDE_XMLNode* pXMLNode, | 189 void XFA_GetPlainTextFromRichText(CFDE_XMLNode* pXMLNode, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 pChildXML; | 228 pChildXML; |
| 228 pChildXML = pChildXML->GetNodeItem(CFDE_XMLNode::NextSibling)) { | 229 pChildXML = pChildXML->GetNodeItem(CFDE_XMLNode::NextSibling)) { |
| 229 XFA_GetPlainTextFromRichText(pChildXML, wsPlainText); | 230 XFA_GetPlainTextFromRichText(pChildXML, wsPlainText); |
| 230 } | 231 } |
| 231 } | 232 } |
| 232 FX_BOOL XFA_FieldIsMultiListBox(CXFA_Node* pFieldNode) { | 233 FX_BOOL XFA_FieldIsMultiListBox(CXFA_Node* pFieldNode) { |
| 233 FX_BOOL bRet = FALSE; | 234 FX_BOOL bRet = FALSE; |
| 234 if (!pFieldNode) { | 235 if (!pFieldNode) { |
| 235 return bRet; | 236 return bRet; |
| 236 } | 237 } |
| 237 CXFA_Node* pUIChild = pFieldNode->GetChild(0, XFA_ELEMENT_Ui); | 238 CXFA_Node* pUIChild = pFieldNode->GetChild(0, XFA_Element::Ui); |
| 238 if (pUIChild) { | 239 if (pUIChild) { |
| 239 CXFA_Node* pFirstChild = pUIChild->GetNodeItem(XFA_NODEITEM_FirstChild); | 240 CXFA_Node* pFirstChild = pUIChild->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 240 if (pFirstChild && pFirstChild->GetClassID() == XFA_ELEMENT_ChoiceList) { | 241 if (pFirstChild && pFirstChild->GetClassID() == XFA_Element::ChoiceList) { |
| 241 bRet = pFirstChild->GetEnum(XFA_ATTRIBUTE_Open) == | 242 bRet = pFirstChild->GetEnum(XFA_ATTRIBUTE_Open) == |
| 242 XFA_ATTRIBUTEENUM_MultiSelect; | 243 XFA_ATTRIBUTEENUM_MultiSelect; |
| 243 } | 244 } |
| 244 } | 245 } |
| 245 return bRet; | 246 return bRet; |
| 246 } | 247 } |
| 247 FX_BOOL XFA_IsLayoutElement(XFA_ELEMENT eElement, FX_BOOL bLayoutContainer) { | 248 FX_BOOL XFA_IsLayoutElement(XFA_Element eElement, FX_BOOL bLayoutContainer) { |
| 248 switch (eElement) { | 249 switch (eElement) { |
| 249 case XFA_ELEMENT_Draw: | 250 case XFA_Element::Draw: |
| 250 case XFA_ELEMENT_Field: | 251 case XFA_Element::Field: |
| 251 case XFA_ELEMENT_InstanceManager: | 252 case XFA_Element::InstanceManager: |
| 252 return !bLayoutContainer; | 253 return !bLayoutContainer; |
| 253 case XFA_ELEMENT_Area: | 254 case XFA_Element::Area: |
| 254 case XFA_ELEMENT_Subform: | 255 case XFA_Element::Subform: |
| 255 case XFA_ELEMENT_ExclGroup: | 256 case XFA_Element::ExclGroup: |
| 256 case XFA_ELEMENT_SubformSet: | 257 case XFA_Element::SubformSet: |
| 257 case XFA_ELEMENT_PageArea: | 258 case XFA_Element::PageArea: |
| 258 case XFA_ELEMENT_Form: | 259 case XFA_Element::Form: |
| 259 return TRUE; | 260 return TRUE; |
| 260 default: | 261 default: |
| 261 return FALSE; | 262 return FALSE; |
| 262 } | 263 } |
| 263 } | 264 } |
| 264 | 265 |
| 265 static const FX_DOUBLE fraction_scales[] = {0.1, | 266 static const FX_DOUBLE fraction_scales[] = {0.1, |
| 266 0.01, | 267 0.01, |
| 267 0.001, | 268 0.001, |
| 268 0.0001, | 269 0.0001, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 FX_DOUBLE XFA_ByteStringToDouble(const CFX_ByteStringC& szStringVal) { | 361 FX_DOUBLE XFA_ByteStringToDouble(const CFX_ByteStringC& szStringVal) { |
| 361 CFX_WideString wsValue = CFX_WideString::FromUTF8(szStringVal); | 362 CFX_WideString wsValue = CFX_WideString::FromUTF8(szStringVal); |
| 362 return XFA_WideStringToDouble(wsValue); | 363 return XFA_WideStringToDouble(wsValue); |
| 363 } | 364 } |
| 364 | 365 |
| 365 int32_t XFA_MapRotation(int32_t nRotation) { | 366 int32_t XFA_MapRotation(int32_t nRotation) { |
| 366 nRotation = nRotation % 360; | 367 nRotation = nRotation % 360; |
| 367 nRotation = nRotation < 0 ? nRotation + 360 : nRotation; | 368 nRotation = nRotation < 0 ? nRotation + 360 : nRotation; |
| 368 return nRotation; | 369 return nRotation; |
| 369 } | 370 } |
| OLD | NEW |