| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/cxfa_widgetdata.h" | 7 #include "xfa/fxfa/parser/cxfa_widgetdata.h" |
| 8 | 8 |
| 9 #include "core/fxcrt/include/fx_ext.h" | 9 #include "core/fxcrt/include/fx_ext.h" |
| 10 #include "xfa/fxbarcode/include/BC_Library.h" | 10 #include "xfa/fxbarcode/include/BC_Library.h" |
| 11 #include "xfa/fxfa/app/xfa_ffnotify.h" | 11 #include "xfa/fxfa/app/xfa_ffnotify.h" |
| 12 #include "xfa/fxfa/parser/cxfa_event.h" | 12 #include "xfa/fxfa/parser/cxfa_event.h" |
| 13 #include "xfa/fxfa/parser/cxfa_measurement.h" |
| 13 #include "xfa/fxfa/parser/xfa_document.h" | 14 #include "xfa/fxfa/parser/xfa_document.h" |
| 14 #include "xfa/fxfa/parser/xfa_localevalue.h" | 15 #include "xfa/fxfa/parser/xfa_localevalue.h" |
| 15 #include "xfa/fxfa/parser/xfa_object.h" | 16 #include "xfa/fxfa/parser/xfa_object.h" |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 FX_FLOAT GetEdgeThickness(const CXFA_StrokeArray& strokes, | 20 FX_FLOAT GetEdgeThickness(const CXFA_StrokeArray& strokes, |
| 20 FX_BOOL b3DStyle, | 21 FX_BOOL b3DStyle, |
| 21 int32_t nIndex) { | 22 int32_t nIndex) { |
| 22 FX_FLOAT fThickness = 0; | 23 FX_FLOAT fThickness = 0; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 case XFA_Element::TextEdit: | 200 case XFA_Element::TextEdit: |
| 200 default: | 201 default: |
| 201 eValueType = XFA_Element::Text; | 202 eValueType = XFA_Element::Text; |
| 202 break; | 203 break; |
| 203 } | 204 } |
| 204 defValue.GetNode()->GetProperty(0, eValueType, TRUE); | 205 defValue.GetNode()->GetProperty(0, eValueType, TRUE); |
| 205 | 206 |
| 206 return pUIChild; | 207 return pUIChild; |
| 207 } | 208 } |
| 208 | 209 |
| 210 XFA_ATTRIBUTEENUM GetAttributeDefaultValue_Enum(XFA_Element eElement, |
| 211 XFA_ATTRIBUTE eAttribute, |
| 212 uint32_t dwPacket) { |
| 213 void* pValue; |
| 214 if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, |
| 215 XFA_ATTRIBUTETYPE_Enum, dwPacket)) { |
| 216 return (XFA_ATTRIBUTEENUM)(uintptr_t)pValue; |
| 217 } |
| 218 return XFA_ATTRIBUTEENUM_Unknown; |
| 219 } |
| 220 |
| 221 CFX_WideStringC GetAttributeDefaultValue_Cdata(XFA_Element eElement, |
| 222 XFA_ATTRIBUTE eAttribute, |
| 223 uint32_t dwPacket) { |
| 224 void* pValue; |
| 225 if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, |
| 226 XFA_ATTRIBUTETYPE_Cdata, dwPacket)) { |
| 227 return (const FX_WCHAR*)pValue; |
| 228 } |
| 229 return nullptr; |
| 230 } |
| 231 |
| 232 FX_BOOL GetAttributeDefaultValue_Boolean(XFA_Element eElement, |
| 233 XFA_ATTRIBUTE eAttribute, |
| 234 uint32_t dwPacket) { |
| 235 void* pValue; |
| 236 if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, |
| 237 XFA_ATTRIBUTETYPE_Boolean, dwPacket)) { |
| 238 return (FX_BOOL)(uintptr_t)pValue; |
| 239 } |
| 240 return FALSE; |
| 241 } |
| 242 |
| 209 } // namespace | 243 } // namespace |
| 210 | 244 |
| 211 CXFA_WidgetData::CXFA_WidgetData(CXFA_Node* pNode) | 245 CXFA_WidgetData::CXFA_WidgetData(CXFA_Node* pNode) |
| 212 : CXFA_Data(pNode), | 246 : CXFA_Data(pNode), |
| 213 m_bIsNull(TRUE), | 247 m_bIsNull(TRUE), |
| 214 m_bPreNull(TRUE), | 248 m_bPreNull(TRUE), |
| 215 m_pUiChildNode(nullptr), | 249 m_pUiChildNode(nullptr), |
| 216 m_eUIType(XFA_Element::Unknown) {} | 250 m_eUIType(XFA_Element::Unknown) {} |
| 217 | 251 |
| 218 CXFA_Node* CXFA_WidgetData::GetUIChild() { | 252 CXFA_Node* CXFA_WidgetData::GetUIChild() { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 fLeftInset = GetEdgeThickness(strokes, bVisible, 3); | 444 fLeftInset = GetEdgeThickness(strokes, bVisible, 3); |
| 411 } | 445 } |
| 412 } | 446 } |
| 413 rtUIMargin.Set(fLeftInset, fTopInset, fRightInset, fBottomInset); | 447 rtUIMargin.Set(fLeftInset, fTopInset, fRightInset, fBottomInset); |
| 414 } | 448 } |
| 415 | 449 |
| 416 int32_t CXFA_WidgetData::GetButtonHighlight() { | 450 int32_t CXFA_WidgetData::GetButtonHighlight() { |
| 417 CXFA_Node* pUIChild = GetUIChild(); | 451 CXFA_Node* pUIChild = GetUIChild(); |
| 418 if (pUIChild) | 452 if (pUIChild) |
| 419 return pUIChild->GetEnum(XFA_ATTRIBUTE_Highlight); | 453 return pUIChild->GetEnum(XFA_ATTRIBUTE_Highlight); |
| 420 return XFA_GetAttributeDefaultValue_Enum( | 454 return GetAttributeDefaultValue_Enum( |
| 421 XFA_Element::Button, XFA_ATTRIBUTE_Highlight, XFA_XDPPACKET_Form); | 455 XFA_Element::Button, XFA_ATTRIBUTE_Highlight, XFA_XDPPACKET_Form); |
| 422 } | 456 } |
| 423 | 457 |
| 424 FX_BOOL CXFA_WidgetData::GetButtonRollover(CFX_WideString& wsRollover, | 458 FX_BOOL CXFA_WidgetData::GetButtonRollover(CFX_WideString& wsRollover, |
| 425 FX_BOOL& bRichText) { | 459 FX_BOOL& bRichText) { |
| 426 if (CXFA_Node* pItems = m_pNode->GetChild(0, XFA_Element::Items)) { | 460 if (CXFA_Node* pItems = m_pNode->GetChild(0, XFA_Element::Items)) { |
| 427 CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); | 461 CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 428 while (pText) { | 462 while (pText) { |
| 429 CFX_WideStringC wsName; | 463 CFX_WideStringC wsName; |
| 430 pText->TryCData(XFA_ATTRIBUTE_Name, wsName); | 464 pText->TryCData(XFA_ATTRIBUTE_Name, wsName); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 454 pText = pText->GetNodeItem(XFA_NODEITEM_NextSibling); | 488 pText = pText->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 455 } | 489 } |
| 456 } | 490 } |
| 457 return FALSE; | 491 return FALSE; |
| 458 } | 492 } |
| 459 | 493 |
| 460 int32_t CXFA_WidgetData::GetCheckButtonShape() { | 494 int32_t CXFA_WidgetData::GetCheckButtonShape() { |
| 461 CXFA_Node* pUIChild = GetUIChild(); | 495 CXFA_Node* pUIChild = GetUIChild(); |
| 462 if (pUIChild) | 496 if (pUIChild) |
| 463 return pUIChild->GetEnum(XFA_ATTRIBUTE_Shape); | 497 return pUIChild->GetEnum(XFA_ATTRIBUTE_Shape); |
| 464 return XFA_GetAttributeDefaultValue_Enum( | 498 return GetAttributeDefaultValue_Enum(XFA_Element::CheckButton, |
| 465 XFA_Element::CheckButton, XFA_ATTRIBUTE_Shape, XFA_XDPPACKET_Form); | 499 XFA_ATTRIBUTE_Shape, XFA_XDPPACKET_Form); |
| 466 } | 500 } |
| 467 | 501 |
| 468 int32_t CXFA_WidgetData::GetCheckButtonMark() { | 502 int32_t CXFA_WidgetData::GetCheckButtonMark() { |
| 469 CXFA_Node* pUIChild = GetUIChild(); | 503 CXFA_Node* pUIChild = GetUIChild(); |
| 470 if (pUIChild) | 504 if (pUIChild) |
| 471 return pUIChild->GetEnum(XFA_ATTRIBUTE_Mark); | 505 return pUIChild->GetEnum(XFA_ATTRIBUTE_Mark); |
| 472 return XFA_GetAttributeDefaultValue_Enum( | 506 return GetAttributeDefaultValue_Enum(XFA_Element::CheckButton, |
| 473 XFA_Element::CheckButton, XFA_ATTRIBUTE_Mark, XFA_XDPPACKET_Form); | 507 XFA_ATTRIBUTE_Mark, XFA_XDPPACKET_Form); |
| 474 } | 508 } |
| 475 | 509 |
| 476 FX_BOOL CXFA_WidgetData::IsRadioButton() { | 510 FX_BOOL CXFA_WidgetData::IsRadioButton() { |
| 477 if (CXFA_Node* pParent = m_pNode->GetNodeItem(XFA_NODEITEM_Parent)) | 511 if (CXFA_Node* pParent = m_pNode->GetNodeItem(XFA_NODEITEM_Parent)) |
| 478 return pParent->GetElementType() == XFA_Element::ExclGroup; | 512 return pParent->GetElementType() == XFA_Element::ExclGroup; |
| 479 return FALSE; | 513 return FALSE; |
| 480 } | 514 } |
| 481 | 515 |
| 482 FX_FLOAT CXFA_WidgetData::GetCheckButtonSize() { | 516 FX_FLOAT CXFA_WidgetData::GetCheckButtonSize() { |
| 483 CXFA_Node* pUIChild = GetUIChild(); | 517 CXFA_Node* pUIChild = GetUIChild(); |
| 484 if (pUIChild) | 518 if (pUIChild) |
| 485 return pUIChild->GetMeasure(XFA_ATTRIBUTE_Size).ToUnit(XFA_UNIT_Pt); | 519 return pUIChild->GetMeasure(XFA_ATTRIBUTE_Size).ToUnit(XFA_UNIT_Pt); |
| 486 return XFA_GetAttributeDefaultValue_Measure( | 520 return XFA_GetAttributeDefaultValue_Measure( |
| 487 XFA_Element::CheckButton, XFA_ATTRIBUTE_Size, XFA_XDPPACKET_Form) | 521 XFA_Element::CheckButton, XFA_ATTRIBUTE_Size, XFA_XDPPACKET_Form) |
| 488 .ToUnit(XFA_UNIT_Pt); | 522 .ToUnit(XFA_UNIT_Pt); |
| 489 } | 523 } |
| 490 | 524 |
| 491 FX_BOOL CXFA_WidgetData::IsAllowNeutral() { | 525 FX_BOOL CXFA_WidgetData::IsAllowNeutral() { |
| 492 CXFA_Node* pUIChild = GetUIChild(); | 526 CXFA_Node* pUIChild = GetUIChild(); |
| 493 if (pUIChild) | 527 if (pUIChild) |
| 494 return pUIChild->GetBoolean(XFA_ATTRIBUTE_AllowNeutral); | 528 return pUIChild->GetBoolean(XFA_ATTRIBUTE_AllowNeutral); |
| 495 return XFA_GetAttributeDefaultValue_Boolean( | 529 return GetAttributeDefaultValue_Boolean( |
| 496 XFA_Element::CheckButton, XFA_ATTRIBUTE_AllowNeutral, XFA_XDPPACKET_Form); | 530 XFA_Element::CheckButton, XFA_ATTRIBUTE_AllowNeutral, XFA_XDPPACKET_Form); |
| 497 } | 531 } |
| 498 | 532 |
| 499 XFA_CHECKSTATE CXFA_WidgetData::GetCheckState() { | 533 XFA_CHECKSTATE CXFA_WidgetData::GetCheckState() { |
| 500 CFX_WideString wsValue = GetRawValue(); | 534 CFX_WideString wsValue = GetRawValue(); |
| 501 if (wsValue.IsEmpty()) | 535 if (wsValue.IsEmpty()) |
| 502 return XFA_CHECKSTATE_Off; | 536 return XFA_CHECKSTATE_Off; |
| 503 | 537 |
| 504 if (CXFA_Node* pItems = m_pNode->GetChild(0, XFA_Element::Items)) { | 538 if (CXFA_Node* pItems = m_pNode->GetChild(0, XFA_Element::Items)) { |
| 505 CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); | 539 CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 | 708 |
| 675 pNodeField = pNodeField->GetNodeItem(XFA_NODEITEM_NextSibling); | 709 pNodeField = pNodeField->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 676 } | 710 } |
| 677 return nullptr; | 711 return nullptr; |
| 678 } | 712 } |
| 679 | 713 |
| 680 int32_t CXFA_WidgetData::GetChoiceListCommitOn() { | 714 int32_t CXFA_WidgetData::GetChoiceListCommitOn() { |
| 681 CXFA_Node* pUIChild = GetUIChild(); | 715 CXFA_Node* pUIChild = GetUIChild(); |
| 682 if (pUIChild) | 716 if (pUIChild) |
| 683 return pUIChild->GetEnum(XFA_ATTRIBUTE_CommitOn); | 717 return pUIChild->GetEnum(XFA_ATTRIBUTE_CommitOn); |
| 684 return XFA_GetAttributeDefaultValue_Enum( | 718 return GetAttributeDefaultValue_Enum( |
| 685 XFA_Element::ChoiceList, XFA_ATTRIBUTE_CommitOn, XFA_XDPPACKET_Form); | 719 XFA_Element::ChoiceList, XFA_ATTRIBUTE_CommitOn, XFA_XDPPACKET_Form); |
| 686 } | 720 } |
| 687 | 721 |
| 688 FX_BOOL CXFA_WidgetData::IsChoiceListAllowTextEntry() { | 722 FX_BOOL CXFA_WidgetData::IsChoiceListAllowTextEntry() { |
| 689 CXFA_Node* pUIChild = GetUIChild(); | 723 CXFA_Node* pUIChild = GetUIChild(); |
| 690 if (pUIChild) | 724 if (pUIChild) |
| 691 return pUIChild->GetBoolean(XFA_ATTRIBUTE_TextEntry); | 725 return pUIChild->GetBoolean(XFA_ATTRIBUTE_TextEntry); |
| 692 return XFA_GetAttributeDefaultValue_Boolean( | 726 return GetAttributeDefaultValue_Boolean( |
| 693 XFA_Element::ChoiceList, XFA_ATTRIBUTE_TextEntry, XFA_XDPPACKET_Form); | 727 XFA_Element::ChoiceList, XFA_ATTRIBUTE_TextEntry, XFA_XDPPACKET_Form); |
| 694 } | 728 } |
| 695 | 729 |
| 696 int32_t CXFA_WidgetData::GetChoiceListOpen() { | 730 int32_t CXFA_WidgetData::GetChoiceListOpen() { |
| 697 CXFA_Node* pUIChild = GetUIChild(); | 731 CXFA_Node* pUIChild = GetUIChild(); |
| 698 if (pUIChild) | 732 if (pUIChild) |
| 699 return pUIChild->GetEnum(XFA_ATTRIBUTE_Open); | 733 return pUIChild->GetEnum(XFA_ATTRIBUTE_Open); |
| 700 return XFA_GetAttributeDefaultValue_Enum( | 734 return GetAttributeDefaultValue_Enum(XFA_Element::ChoiceList, |
| 701 XFA_Element::ChoiceList, XFA_ATTRIBUTE_Open, XFA_XDPPACKET_Form); | 735 XFA_ATTRIBUTE_Open, XFA_XDPPACKET_Form); |
| 702 } | 736 } |
| 703 | 737 |
| 704 FX_BOOL CXFA_WidgetData::IsListBox() { | 738 FX_BOOL CXFA_WidgetData::IsListBox() { |
| 705 int32_t iOpenMode = GetChoiceListOpen(); | 739 int32_t iOpenMode = GetChoiceListOpen(); |
| 706 return (iOpenMode == XFA_ATTRIBUTEENUM_Always || | 740 return (iOpenMode == XFA_ATTRIBUTEENUM_Always || |
| 707 iOpenMode == XFA_ATTRIBUTEENUM_MultiSelect); | 741 iOpenMode == XFA_ATTRIBUTEENUM_MultiSelect); |
| 708 } | 742 } |
| 709 | 743 |
| 710 int32_t CXFA_WidgetData::CountChoiceListItems(FX_BOOL bSaveValue) { | 744 int32_t CXFA_WidgetData::CountChoiceListItems(FX_BOOL bSaveValue) { |
| 711 CXFA_NodeArray pItems; | 745 CXFA_NodeArray pItems; |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1380 return TRUE; | 1414 return TRUE; |
| 1381 } | 1415 } |
| 1382 return FALSE; | 1416 return FALSE; |
| 1383 } | 1417 } |
| 1384 | 1418 |
| 1385 void CXFA_WidgetData::GetPasswordChar(CFX_WideString& wsPassWord) { | 1419 void CXFA_WidgetData::GetPasswordChar(CFX_WideString& wsPassWord) { |
| 1386 CXFA_Node* pUIChild = GetUIChild(); | 1420 CXFA_Node* pUIChild = GetUIChild(); |
| 1387 if (pUIChild) { | 1421 if (pUIChild) { |
| 1388 pUIChild->TryCData(XFA_ATTRIBUTE_PasswordChar, wsPassWord); | 1422 pUIChild->TryCData(XFA_ATTRIBUTE_PasswordChar, wsPassWord); |
| 1389 } else { | 1423 } else { |
| 1390 wsPassWord = XFA_GetAttributeDefaultValue_Cdata(XFA_Element::PasswordEdit, | 1424 wsPassWord = GetAttributeDefaultValue_Cdata(XFA_Element::PasswordEdit, |
| 1391 XFA_ATTRIBUTE_PasswordChar, | 1425 XFA_ATTRIBUTE_PasswordChar, |
| 1392 XFA_XDPPACKET_Form); | 1426 XFA_XDPPACKET_Form); |
| 1393 } | 1427 } |
| 1394 } | 1428 } |
| 1395 | 1429 |
| 1396 FX_BOOL CXFA_WidgetData::IsMultiLine() { | 1430 FX_BOOL CXFA_WidgetData::IsMultiLine() { |
| 1397 CXFA_Node* pUIChild = GetUIChild(); | 1431 CXFA_Node* pUIChild = GetUIChild(); |
| 1398 if (pUIChild) | 1432 if (pUIChild) |
| 1399 return pUIChild->GetBoolean(XFA_ATTRIBUTE_MultiLine); | 1433 return pUIChild->GetBoolean(XFA_ATTRIBUTE_MultiLine); |
| 1400 return XFA_GetAttributeDefaultValue_Boolean( | 1434 return GetAttributeDefaultValue_Boolean( |
| 1401 XFA_Element::TextEdit, XFA_ATTRIBUTE_MultiLine, XFA_XDPPACKET_Form); | 1435 XFA_Element::TextEdit, XFA_ATTRIBUTE_MultiLine, XFA_XDPPACKET_Form); |
| 1402 } | 1436 } |
| 1403 | 1437 |
| 1404 int32_t CXFA_WidgetData::GetVerticalScrollPolicy() { | 1438 int32_t CXFA_WidgetData::GetVerticalScrollPolicy() { |
| 1405 CXFA_Node* pUIChild = GetUIChild(); | 1439 CXFA_Node* pUIChild = GetUIChild(); |
| 1406 if (pUIChild) | 1440 if (pUIChild) |
| 1407 return pUIChild->GetEnum(XFA_ATTRIBUTE_VScrollPolicy); | 1441 return pUIChild->GetEnum(XFA_ATTRIBUTE_VScrollPolicy); |
| 1408 return XFA_GetAttributeDefaultValue_Enum( | 1442 return GetAttributeDefaultValue_Enum( |
| 1409 XFA_Element::TextEdit, XFA_ATTRIBUTE_VScrollPolicy, XFA_XDPPACKET_Form); | 1443 XFA_Element::TextEdit, XFA_ATTRIBUTE_VScrollPolicy, XFA_XDPPACKET_Form); |
| 1410 } | 1444 } |
| 1411 | 1445 |
| 1412 int32_t CXFA_WidgetData::GetMaxChars(XFA_Element& eType) { | 1446 int32_t CXFA_WidgetData::GetMaxChars(XFA_Element& eType) { |
| 1413 if (CXFA_Node* pNode = m_pNode->GetChild(0, XFA_Element::Value)) { | 1447 if (CXFA_Node* pNode = m_pNode->GetChild(0, XFA_Element::Value)) { |
| 1414 if (CXFA_Node* pChild = pNode->GetNodeItem(XFA_NODEITEM_FirstChild)) { | 1448 if (CXFA_Node* pChild = pNode->GetNodeItem(XFA_NODEITEM_FirstChild)) { |
| 1415 switch (pChild->GetElementType()) { | 1449 switch (pChild->GetElementType()) { |
| 1416 case XFA_Element::Text: | 1450 case XFA_Element::Text: |
| 1417 eType = XFA_Element::Text; | 1451 eType = XFA_Element::Text; |
| 1418 return pChild->GetInteger(XFA_ATTRIBUTE_MaxChars); | 1452 return pChild->GetInteger(XFA_ATTRIBUTE_MaxChars); |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1906 } | 1940 } |
| 1907 } | 1941 } |
| 1908 } else if (wc == L'.') { | 1942 } else if (wc == L'.') { |
| 1909 iTread_ = 0; | 1943 iTread_ = 0; |
| 1910 iLead = -1; | 1944 iLead = -1; |
| 1911 } | 1945 } |
| 1912 wsRet += wc; | 1946 wsRet += wc; |
| 1913 } | 1947 } |
| 1914 return wsRet; | 1948 return wsRet; |
| 1915 } | 1949 } |
| OLD | NEW |