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" |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 if (pText->TryContent(wsContent) && (wsContent == wsValue)) | 373 if (pText->TryContent(wsContent) && (wsContent == wsValue)) |
374 return (XFA_CHECKSTATE)i; | 374 return (XFA_CHECKSTATE)i; |
375 | 375 |
376 i++; | 376 i++; |
377 pText = pText->GetNodeItem(XFA_NODEITEM_NextSibling); | 377 pText = pText->GetNodeItem(XFA_NODEITEM_NextSibling); |
378 } | 378 } |
379 } | 379 } |
380 return XFA_CHECKSTATE_Off; | 380 return XFA_CHECKSTATE_Off; |
381 } | 381 } |
382 | 382 |
383 void CXFA_WidgetData::SetCheckState(XFA_CHECKSTATE eCheckState, | 383 void CXFA_WidgetData::SetCheckState(XFA_CHECKSTATE eCheckState, bool bNotify) { |
384 FX_BOOL bNotify) { | |
385 CXFA_WidgetData exclGroup(GetExclGroupNode()); | 384 CXFA_WidgetData exclGroup(GetExclGroupNode()); |
386 if (exclGroup) { | 385 if (exclGroup) { |
387 CFX_WideString wsValue; | 386 CFX_WideString wsValue; |
388 if (eCheckState != XFA_CHECKSTATE_Off) { | 387 if (eCheckState != XFA_CHECKSTATE_Off) { |
389 if (CXFA_Node* pItems = m_pNode->GetChild(0, XFA_ELEMENT_Items)) { | 388 if (CXFA_Node* pItems = m_pNode->GetChild(0, XFA_ELEMENT_Items)) { |
390 CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); | 389 CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); |
391 if (pText) | 390 if (pText) |
392 pText->TryContent(wsValue); | 391 pText->TryContent(wsValue); |
393 } | 392 } |
394 } | 393 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 CXFA_WidgetData widgetData(pNode); | 456 CXFA_WidgetData widgetData(pNode); |
458 if (widgetData.GetCheckState() == XFA_CHECKSTATE_On) { | 457 if (widgetData.GetCheckState() == XFA_CHECKSTATE_On) { |
459 pSelectedMember = pNode; | 458 pSelectedMember = pNode; |
460 break; | 459 break; |
461 } | 460 } |
462 } | 461 } |
463 return pSelectedMember; | 462 return pSelectedMember; |
464 } | 463 } |
465 | 464 |
466 CXFA_Node* CXFA_WidgetData::SetSelectedMember(const CFX_WideStringC& wsName, | 465 CXFA_Node* CXFA_WidgetData::SetSelectedMember(const CFX_WideStringC& wsName, |
467 FX_BOOL bNotify) { | 466 bool bNotify) { |
468 CXFA_Node* pSelectedMember = NULL; | |
469 uint32_t nameHash = FX_HashCode_GetW(wsName, false); | 467 uint32_t nameHash = FX_HashCode_GetW(wsName, false); |
470 for (CXFA_Node* pNode = ToNode(m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild)); | 468 for (CXFA_Node* pNode = ToNode(m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild)); |
471 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { | 469 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
472 if (pNode->GetNameHash() == nameHash) { | 470 if (pNode->GetNameHash() == nameHash) { |
473 CXFA_WidgetData widgetData(pNode); | 471 CXFA_WidgetData widgetData(pNode); |
474 widgetData.SetCheckState(XFA_CHECKSTATE_On, bNotify); | 472 widgetData.SetCheckState(XFA_CHECKSTATE_On, bNotify); |
475 pSelectedMember = pNode; | 473 return pNode; |
476 break; | |
477 } | 474 } |
478 } | 475 } |
479 return pSelectedMember; | 476 return nullptr; |
480 } | 477 } |
481 | 478 |
482 void CXFA_WidgetData::SetSelectedMemberByValue(const CFX_WideStringC& wsValue, | 479 void CXFA_WidgetData::SetSelectedMemberByValue(const CFX_WideStringC& wsValue, |
483 FX_BOOL bNotify, | 480 bool bNotify, |
484 FX_BOOL bScriptModify, | 481 FX_BOOL bScriptModify, |
485 FX_BOOL bSyncData) { | 482 FX_BOOL bSyncData) { |
486 CFX_WideString wsExclGroup; | 483 CFX_WideString wsExclGroup; |
487 for (CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); pNode; | 484 for (CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); pNode; |
488 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { | 485 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
489 if (pNode->GetClassID() != XFA_ELEMENT_Field) | 486 if (pNode->GetClassID() != XFA_ELEMENT_Field) |
490 continue; | 487 continue; |
491 | 488 |
492 CXFA_Node* pItem = pNode->GetChild(0, XFA_ELEMENT_Items); | 489 CXFA_Node* pItem = pNode->GetChild(0, XFA_ELEMENT_Items); |
493 if (!pItem) | 490 if (!pItem) |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 int32_t iValues = wsValueArray.GetSize(); | 761 int32_t iValues = wsValueArray.GetSize(); |
765 for (int32_t j = 0; j < iValues; j++) { | 762 for (int32_t j = 0; j < iValues; j++) { |
766 if (wsValueArray[j] == wsSaveTextArray[nIndex]) | 763 if (wsValueArray[j] == wsSaveTextArray[nIndex]) |
767 return TRUE; | 764 return TRUE; |
768 } | 765 } |
769 return FALSE; | 766 return FALSE; |
770 } | 767 } |
771 | 768 |
772 void CXFA_WidgetData::SetItemState(int32_t nIndex, | 769 void CXFA_WidgetData::SetItemState(int32_t nIndex, |
773 FX_BOOL bSelected, | 770 FX_BOOL bSelected, |
774 FX_BOOL bNotify, | 771 bool bNotify, |
775 FX_BOOL bScriptModify, | 772 FX_BOOL bScriptModify, |
776 FX_BOOL bSyncData) { | 773 FX_BOOL bSyncData) { |
777 if (nIndex < 0) | 774 if (nIndex < 0) |
778 return; | 775 return; |
779 | 776 |
780 CFX_WideStringArray wsSaveTextArray; | 777 CFX_WideStringArray wsSaveTextArray; |
781 GetChoiceListItems(wsSaveTextArray, TRUE); | 778 GetChoiceListItems(wsSaveTextArray, TRUE); |
782 if (wsSaveTextArray.GetSize() <= nIndex) | 779 if (wsSaveTextArray.GetSize() <= nIndex) |
783 return; | 780 return; |
784 | 781 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 bSyncData); | 821 bSyncData); |
825 } | 822 } |
826 } else if (iSel >= 0) { | 823 } else if (iSel >= 0) { |
827 m_pNode->SetContent(CFX_WideString(), CFX_WideString(), bNotify, | 824 m_pNode->SetContent(CFX_WideString(), CFX_WideString(), bNotify, |
828 bScriptModify, bSyncData); | 825 bScriptModify, bSyncData); |
829 } | 826 } |
830 } | 827 } |
831 } | 828 } |
832 | 829 |
833 void CXFA_WidgetData::SetSelectedItems(CFX_Int32Array& iSelArray, | 830 void CXFA_WidgetData::SetSelectedItems(CFX_Int32Array& iSelArray, |
834 FX_BOOL bNotify, | 831 bool bNotify, |
835 FX_BOOL bScriptModify, | 832 FX_BOOL bScriptModify, |
836 FX_BOOL bSyncData) { | 833 FX_BOOL bSyncData) { |
837 CFX_WideString wsValue; | 834 CFX_WideString wsValue; |
838 int32_t iSize = iSelArray.GetSize(); | 835 int32_t iSize = iSelArray.GetSize(); |
839 if (iSize >= 1) { | 836 if (iSize >= 1) { |
840 CFX_WideStringArray wsSaveTextArray; | 837 CFX_WideStringArray wsSaveTextArray; |
841 GetChoiceListItems(wsSaveTextArray, TRUE); | 838 GetChoiceListItems(wsSaveTextArray, TRUE); |
842 CFX_WideString wsItemValue; | 839 CFX_WideString wsItemValue; |
843 for (int32_t i = 0; i < iSize; i++) { | 840 for (int32_t i = 0; i < iSize; i++) { |
844 wsItemValue = (iSize == 1) | 841 wsItemValue = (iSize == 1) |
845 ? wsSaveTextArray[iSelArray[i]] | 842 ? wsSaveTextArray[iSelArray[i]] |
846 : wsSaveTextArray[iSelArray[i]] + FX_WSTRC(L"\n"); | 843 : wsSaveTextArray[iSelArray[i]] + FX_WSTRC(L"\n"); |
847 wsValue += wsItemValue; | 844 wsValue += wsItemValue; |
848 } | 845 } |
849 } | 846 } |
850 CFX_WideString wsFormat(wsValue); | 847 CFX_WideString wsFormat(wsValue); |
851 if (GetChoiceListOpen() != XFA_ATTRIBUTEENUM_MultiSelect) | 848 if (GetChoiceListOpen() != XFA_ATTRIBUTEENUM_MultiSelect) |
852 GetFormatDataValue(wsValue, wsFormat); | 849 GetFormatDataValue(wsValue, wsFormat); |
853 | 850 |
854 m_pNode->SetContent(wsValue, wsFormat, bNotify, bScriptModify, bSyncData); | 851 m_pNode->SetContent(wsValue, wsFormat, bNotify, bScriptModify, bSyncData); |
855 } | 852 } |
856 | 853 |
857 void CXFA_WidgetData::ClearAllSelections() { | 854 void CXFA_WidgetData::ClearAllSelections() { |
858 CXFA_Node* pBind = m_pNode->GetBindData(); | 855 CXFA_Node* pBind = m_pNode->GetBindData(); |
859 if (pBind && GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { | 856 if (!pBind || GetChoiceListOpen() != XFA_ATTRIBUTEENUM_MultiSelect) { |
860 while (CXFA_Node* pChildNode = | 857 SyncValue(CFX_WideString(), false); |
861 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) { | 858 return; |
862 pBind->RemoveChild(pChildNode); | |
863 } | |
864 } else { | |
865 SyncValue(CFX_WideString(), FALSE); | |
866 } | 859 } |
| 860 |
| 861 while (CXFA_Node* pChildNode = pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) |
| 862 pBind->RemoveChild(pChildNode); |
867 } | 863 } |
868 | 864 |
869 void CXFA_WidgetData::InsertItem(const CFX_WideString& wsLabel, | 865 void CXFA_WidgetData::InsertItem(const CFX_WideString& wsLabel, |
870 const CFX_WideString& wsValue, | 866 const CFX_WideString& wsValue, |
871 int32_t nIndex, | 867 int32_t nIndex, |
872 FX_BOOL bNotify) { | 868 FX_BOOL bNotify) { |
873 CFX_WideString wsNewValue(wsValue); | 869 CFX_WideString wsNewValue(wsValue); |
874 if (wsNewValue.IsEmpty()) | 870 if (wsNewValue.IsEmpty()) |
875 wsNewValue = wsLabel; | 871 wsNewValue = wsLabel; |
876 | 872 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 for (; pItems; pItems = pItems->GetNodeItem(XFA_NODEITEM_NextSibling)) { | 1025 for (; pItems; pItems = pItems->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
1030 if (pItems->GetClassID() != XFA_ELEMENT_Items) | 1026 if (pItems->GetClassID() != XFA_ELEMENT_Items) |
1031 continue; | 1027 continue; |
1032 | 1028 |
1033 if (nIndex < 0) { | 1029 if (nIndex < 0) { |
1034 while (CXFA_Node* pNode = pItems->GetNodeItem(XFA_NODEITEM_FirstChild)) { | 1030 while (CXFA_Node* pNode = pItems->GetNodeItem(XFA_NODEITEM_FirstChild)) { |
1035 pItems->RemoveChild(pNode); | 1031 pItems->RemoveChild(pNode); |
1036 } | 1032 } |
1037 } else { | 1033 } else { |
1038 if (!bSetValue && pItems->GetBoolean(XFA_ATTRIBUTE_Save)) { | 1034 if (!bSetValue && pItems->GetBoolean(XFA_ATTRIBUTE_Save)) { |
1039 SetItemState(nIndex, FALSE, TRUE, bScriptModify, bSyncData); | 1035 SetItemState(nIndex, FALSE, true, bScriptModify, bSyncData); |
1040 bSetValue = TRUE; | 1036 bSetValue = TRUE; |
1041 } | 1037 } |
1042 int32_t i = 0; | 1038 int32_t i = 0; |
1043 CXFA_Node* pNode = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); | 1039 CXFA_Node* pNode = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); |
1044 while (pNode) { | 1040 while (pNode) { |
1045 if (i == nIndex) { | 1041 if (i == nIndex) { |
1046 pItems->RemoveChild(pNode); | 1042 pItems->RemoveChild(pNode); |
1047 break; | 1043 break; |
1048 } | 1044 } |
1049 i++; | 1045 i++; |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1311 if (CXFA_Node* pChild = pNode->GetChild(0, XFA_ELEMENT_Decimal)) | 1307 if (CXFA_Node* pChild = pNode->GetChild(0, XFA_ELEMENT_Decimal)) |
1312 return pChild->TryInteger(XFA_ATTRIBUTE_LeadDigits, iLeadDigits); | 1308 return pChild->TryInteger(XFA_ATTRIBUTE_LeadDigits, iLeadDigits); |
1313 } | 1309 } |
1314 iLeadDigits = -1; | 1310 iLeadDigits = -1; |
1315 return FALSE; | 1311 return FALSE; |
1316 } | 1312 } |
1317 | 1313 |
1318 FX_BOOL CXFA_WidgetData::SetValue(const CFX_WideString& wsValue, | 1314 FX_BOOL CXFA_WidgetData::SetValue(const CFX_WideString& wsValue, |
1319 XFA_VALUEPICTURE eValueType) { | 1315 XFA_VALUEPICTURE eValueType) { |
1320 if (wsValue.IsEmpty()) { | 1316 if (wsValue.IsEmpty()) { |
1321 SyncValue(wsValue, TRUE); | 1317 SyncValue(wsValue, true); |
1322 return TRUE; | 1318 return TRUE; |
1323 } | 1319 } |
1324 m_bPreNull = m_bIsNull; | 1320 m_bPreNull = m_bIsNull; |
1325 m_bIsNull = FALSE; | 1321 m_bIsNull = FALSE; |
1326 CFX_WideString wsNewText(wsValue); | 1322 CFX_WideString wsNewText(wsValue); |
1327 CFX_WideString wsPicture; | 1323 CFX_WideString wsPicture; |
1328 GetPictureContent(wsPicture, eValueType); | 1324 GetPictureContent(wsPicture, eValueType); |
1329 FX_BOOL bValidate = TRUE; | 1325 FX_BOOL bValidate = TRUE; |
1330 FX_BOOL bSyncData = FALSE; | 1326 FX_BOOL bSyncData = FALSE; |
1331 CXFA_Node* pNode = GetUIChild(); | 1327 CXFA_Node* pNode = GetUIChild(); |
(...skipping 26 matching lines...) Expand all Loading... |
1358 int32_t iLeadDigits = 0; | 1354 int32_t iLeadDigits = 0; |
1359 int32_t iFracDigits = 0; | 1355 int32_t iFracDigits = 0; |
1360 GetLeadDigits(iLeadDigits); | 1356 GetLeadDigits(iLeadDigits); |
1361 GetFracDigits(iFracDigits); | 1357 GetFracDigits(iFracDigits); |
1362 wsNewText = NumericLimit(wsNewText, iLeadDigits, iFracDigits); | 1358 wsNewText = NumericLimit(wsNewText, iLeadDigits, iFracDigits); |
1363 } | 1359 } |
1364 bSyncData = TRUE; | 1360 bSyncData = TRUE; |
1365 } | 1361 } |
1366 } | 1362 } |
1367 if (uiType != XFA_ELEMENT_NumericEdit || bSyncData) | 1363 if (uiType != XFA_ELEMENT_NumericEdit || bSyncData) |
1368 SyncValue(wsNewText, TRUE); | 1364 SyncValue(wsNewText, true); |
1369 | 1365 |
1370 return bValidate; | 1366 return bValidate; |
1371 } | 1367 } |
1372 | 1368 |
1373 FX_BOOL CXFA_WidgetData::GetPictureContent(CFX_WideString& wsPicture, | 1369 FX_BOOL CXFA_WidgetData::GetPictureContent(CFX_WideString& wsPicture, |
1374 XFA_VALUEPICTURE ePicture) { | 1370 XFA_VALUEPICTURE ePicture) { |
1375 if (ePicture == XFA_VALUEPICTURE_Raw) | 1371 if (ePicture == XFA_VALUEPICTURE_Raw) |
1376 return FALSE; | 1372 return FALSE; |
1377 | 1373 |
1378 CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(this); | 1374 CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(this); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1720 wsOutput += wsSrcNum.Right(len - dot_index - 1); | 1716 wsOutput += wsSrcNum.Right(len - dot_index - 1); |
1721 } | 1717 } |
1722 if (bNeg) { | 1718 if (bNeg) { |
1723 CFX_WideString wsMinusymbol; | 1719 CFX_WideString wsMinusymbol; |
1724 pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus, wsMinusymbol); | 1720 pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus, wsMinusymbol); |
1725 wsOutput = wsMinusymbol + wsOutput; | 1721 wsOutput = wsMinusymbol + wsOutput; |
1726 } | 1722 } |
1727 } | 1723 } |
1728 } | 1724 } |
1729 | 1725 |
1730 void CXFA_WidgetData::SyncValue(const CFX_WideString& wsValue, | 1726 void CXFA_WidgetData::SyncValue(const CFX_WideString& wsValue, bool bNotify) { |
1731 FX_BOOL bNotify) { | |
1732 if (!m_pNode) | 1727 if (!m_pNode) |
1733 return; | 1728 return; |
1734 | 1729 |
1735 CFX_WideString wsFormatValue(wsValue); | 1730 CFX_WideString wsFormatValue(wsValue); |
1736 CXFA_WidgetData* pContainerWidgetData = m_pNode->GetContainerWidgetData(); | 1731 CXFA_WidgetData* pContainerWidgetData = m_pNode->GetContainerWidgetData(); |
1737 if (pContainerWidgetData) | 1732 if (pContainerWidgetData) |
1738 pContainerWidgetData->GetFormatDataValue(wsValue, wsFormatValue); | 1733 pContainerWidgetData->GetFormatDataValue(wsValue, wsFormatValue); |
1739 | 1734 |
1740 m_pNode->SetContent(wsValue, wsFormatValue, bNotify); | 1735 m_pNode->SetContent(wsValue, wsFormatValue, bNotify); |
1741 } | 1736 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1784 } | 1779 } |
1785 } | 1780 } |
1786 } else if (wc == L'.') { | 1781 } else if (wc == L'.') { |
1787 iTread_ = 0; | 1782 iTread_ = 0; |
1788 iLead = -1; | 1783 iLead = -1; |
1789 } | 1784 } |
1790 wsRet += wc; | 1785 wsRet += wc; |
1791 } | 1786 } |
1792 return wsRet; | 1787 return wsRet; |
1793 } | 1788 } |
OLD | NEW |