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 "fpdfsdk/include/cpdfsdk_widget.h" | 7 #include "fpdfsdk/include/cpdfsdk_widget.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 return m_bAppModified; | 732 return m_bAppModified; |
733 } | 733 } |
734 | 734 |
735 #ifdef PDF_ENABLE_XFA | 735 #ifdef PDF_ENABLE_XFA |
736 void CPDFSDK_Widget::ResetAppearance(FX_BOOL bValueChanged) { | 736 void CPDFSDK_Widget::ResetAppearance(FX_BOOL bValueChanged) { |
737 switch (GetFieldType()) { | 737 switch (GetFieldType()) { |
738 case FIELDTYPE_TEXTFIELD: | 738 case FIELDTYPE_TEXTFIELD: |
739 case FIELDTYPE_COMBOBOX: { | 739 case FIELDTYPE_COMBOBOX: { |
740 FX_BOOL bFormatted = FALSE; | 740 FX_BOOL bFormatted = FALSE; |
741 CFX_WideString sValue = OnFormat(bFormatted); | 741 CFX_WideString sValue = OnFormat(bFormatted); |
742 ResetAppearance(bFormatted ? sValue.c_str() : nullptr, TRUE); | 742 ResetAppearance(bFormatted ? &sValue : nullptr, TRUE); |
743 break; | 743 break; |
744 } | 744 } |
745 default: | 745 default: |
746 ResetAppearance(nullptr, FALSE); | 746 ResetAppearance(nullptr, FALSE); |
747 break; | 747 break; |
748 } | 748 } |
749 } | 749 } |
750 #endif // PDF_ENABLE_XFA | 750 #endif // PDF_ENABLE_XFA |
751 | 751 |
752 void CPDFSDK_Widget::ResetAppearance(const FX_WCHAR* sValue, | 752 void CPDFSDK_Widget::ResetAppearance(const CFX_WideString* sValue, |
753 FX_BOOL bValueChanged) { | 753 FX_BOOL bValueChanged) { |
754 SetAppModified(); | 754 SetAppModified(); |
755 | 755 |
756 m_nAppAge++; | 756 m_nAppAge++; |
757 if (m_nAppAge > 999999) | 757 if (m_nAppAge > 999999) |
758 m_nAppAge = 0; | 758 m_nAppAge = 0; |
759 if (bValueChanged) | 759 if (bValueChanged) |
760 m_nValueAge++; | 760 m_nValueAge++; |
761 | 761 |
762 int nFieldType = GetFieldType(); | 762 int nFieldType = GetFieldType(); |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 | 1346 |
1347 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, | 1347 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, |
1348 pControl->GetCheckedAPState()); | 1348 pControl->GetCheckedAPState()); |
1349 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off"); | 1349 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off"); |
1350 | 1350 |
1351 CFX_ByteString csAS = GetAppState(); | 1351 CFX_ByteString csAS = GetAppState(); |
1352 if (csAS.IsEmpty()) | 1352 if (csAS.IsEmpty()) |
1353 SetAppState("Off"); | 1353 SetAppState("Off"); |
1354 } | 1354 } |
1355 | 1355 |
1356 void CPDFSDK_Widget::ResetAppearance_ComboBox(const FX_WCHAR* sValue) { | 1356 void CPDFSDK_Widget::ResetAppearance_ComboBox(const CFX_WideString* sValue) { |
1357 CPDF_FormControl* pControl = GetFormControl(); | 1357 CPDF_FormControl* pControl = GetFormControl(); |
1358 CPDF_FormField* pField = pControl->GetField(); | 1358 CPDF_FormField* pField = pControl->GetField(); |
1359 CFX_ByteTextBuf sBody, sLines; | 1359 CFX_ByteTextBuf sBody, sLines; |
1360 | 1360 |
1361 CFX_FloatRect rcClient = GetClientRect(); | 1361 CFX_FloatRect rcClient = GetClientRect(); |
1362 CFX_FloatRect rcButton = rcClient; | 1362 CFX_FloatRect rcButton = rcClient; |
1363 rcButton.left = rcButton.right - 13; | 1363 rcButton.left = rcButton.right - 13; |
1364 rcButton.Normalize(); | 1364 rcButton.Normalize(); |
1365 | 1365 |
1366 std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit); | 1366 std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit); |
(...skipping 13 matching lines...) Expand all Loading... |
1380 | 1380 |
1381 FX_FLOAT fFontSize = GetFontSize(); | 1381 FX_FLOAT fFontSize = GetFontSize(); |
1382 if (IsFloatZero(fFontSize)) | 1382 if (IsFloatZero(fFontSize)) |
1383 pEdit->SetAutoFontSize(TRUE, TRUE); | 1383 pEdit->SetAutoFontSize(TRUE, TRUE); |
1384 else | 1384 else |
1385 pEdit->SetFontSize(fFontSize); | 1385 pEdit->SetFontSize(fFontSize); |
1386 | 1386 |
1387 pEdit->Initialize(); | 1387 pEdit->Initialize(); |
1388 | 1388 |
1389 if (sValue) { | 1389 if (sValue) { |
1390 pEdit->SetText(sValue); | 1390 pEdit->SetText(*sValue); |
1391 } else { | 1391 } else { |
1392 int32_t nCurSel = pField->GetSelectedIndex(0); | 1392 int32_t nCurSel = pField->GetSelectedIndex(0); |
1393 | |
1394 if (nCurSel < 0) | 1393 if (nCurSel < 0) |
1395 pEdit->SetText(pField->GetValue().c_str()); | 1394 pEdit->SetText(pField->GetValue().c_str()); |
1396 else | 1395 else |
1397 pEdit->SetText(pField->GetOptionLabel(nCurSel).c_str()); | 1396 pEdit->SetText(pField->GetOptionLabel(nCurSel).c_str()); |
1398 } | 1397 } |
1399 | 1398 |
1400 CFX_FloatRect rcContent = pEdit->GetContentRect(); | 1399 CFX_FloatRect rcContent = pEdit->GetContentRect(); |
1401 | 1400 |
1402 CFX_ByteString sEdit = | 1401 CFX_ByteString sEdit = |
1403 CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_FloatPoint(0.0f, 0.0f)); | 1402 CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_FloatPoint(0.0f, 0.0f)); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1505 << " " << rcClient.Height() << " re\nW\nn\n"; | 1504 << " " << rcClient.Height() << " re\nW\nn\n"; |
1506 sBody << sList << "Q\nEMC\n"; | 1505 sBody << sList << "Q\nEMC\n"; |
1507 } | 1506 } |
1508 | 1507 |
1509 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + | 1508 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
1510 sLines.AsStringC() + sBody.AsStringC(); | 1509 sLines.AsStringC() + sBody.AsStringC(); |
1511 | 1510 |
1512 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); | 1511 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
1513 } | 1512 } |
1514 | 1513 |
1515 void CPDFSDK_Widget::ResetAppearance_TextField(const FX_WCHAR* sValue) { | 1514 void CPDFSDK_Widget::ResetAppearance_TextField(const CFX_WideString* sValue) { |
1516 CPDF_FormControl* pControl = GetFormControl(); | 1515 CPDF_FormControl* pControl = GetFormControl(); |
1517 CPDF_FormField* pField = pControl->GetField(); | 1516 CPDF_FormField* pField = pControl->GetField(); |
1518 CFX_ByteTextBuf sBody, sLines; | 1517 CFX_ByteTextBuf sBody, sLines; |
1519 | 1518 |
1520 std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit); | 1519 std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit); |
1521 pEdit->EnableRefresh(FALSE); | 1520 pEdit->EnableRefresh(FALSE); |
1522 | 1521 |
1523 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); | 1522 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
1524 CPDFDoc_Environment* pEnv = pDoc->GetEnv(); | 1523 CPDFDoc_Environment* pEnv = pDoc->GetEnv(); |
1525 | 1524 |
(...skipping 21 matching lines...) Expand all Loading... |
1547 } | 1546 } |
1548 | 1547 |
1549 int nMaxLen = pField->GetMaxLen(); | 1548 int nMaxLen = pField->GetMaxLen(); |
1550 FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1; | 1549 FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1; |
1551 FX_FLOAT fFontSize = GetFontSize(); | 1550 FX_FLOAT fFontSize = GetFontSize(); |
1552 | 1551 |
1553 #ifdef PDF_ENABLE_XFA | 1552 #ifdef PDF_ENABLE_XFA |
1554 CFX_WideString sValueTmp; | 1553 CFX_WideString sValueTmp; |
1555 if (!sValue && GetMixXFAWidget()) { | 1554 if (!sValue && GetMixXFAWidget()) { |
1556 sValueTmp = GetValue(TRUE); | 1555 sValueTmp = GetValue(TRUE); |
1557 sValue = sValueTmp.c_str(); | 1556 sValue = &sValueTmp; |
1558 } | 1557 } |
1559 #endif // PDF_ENABLE_XFA | 1558 #endif // PDF_ENABLE_XFA |
1560 | 1559 |
1561 if (nMaxLen > 0) { | 1560 if (nMaxLen > 0) { |
1562 if (bCharArray) { | 1561 if (bCharArray) { |
1563 pEdit->SetCharArray(nMaxLen); | 1562 pEdit->SetCharArray(nMaxLen); |
1564 | 1563 |
1565 if (IsFloatZero(fFontSize)) { | 1564 if (IsFloatZero(fFontSize)) { |
1566 fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(font_map.GetPDFFont(0), | 1565 fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(font_map.GetPDFFont(0), |
1567 rcClient, nMaxLen); | 1566 rcClient, nMaxLen); |
1568 } | 1567 } |
1569 } else { | 1568 } else { |
1570 if (sValue) | 1569 if (sValue) |
1571 nMaxLen = wcslen((const wchar_t*)sValue); | 1570 nMaxLen = sValue->GetLength(); |
1572 pEdit->SetLimitChar(nMaxLen); | 1571 pEdit->SetLimitChar(nMaxLen); |
1573 } | 1572 } |
1574 } | 1573 } |
1575 | 1574 |
1576 if (IsFloatZero(fFontSize)) | 1575 if (IsFloatZero(fFontSize)) |
1577 pEdit->SetAutoFontSize(TRUE, TRUE); | 1576 pEdit->SetAutoFontSize(TRUE, TRUE); |
1578 else | 1577 else |
1579 pEdit->SetFontSize(fFontSize); | 1578 pEdit->SetFontSize(fFontSize); |
1580 | 1579 |
1581 pEdit->Initialize(); | 1580 pEdit->Initialize(); |
1582 | 1581 |
1583 if (sValue) | 1582 if (sValue) |
1584 pEdit->SetText(sValue); | 1583 pEdit->SetText(*sValue); |
1585 else | 1584 else |
1586 pEdit->SetText(pField->GetValue().c_str()); | 1585 pEdit->SetText(pField->GetValue().c_str()); |
1587 | 1586 |
1588 CFX_FloatRect rcContent = pEdit->GetContentRect(); | 1587 CFX_FloatRect rcContent = pEdit->GetContentRect(); |
1589 | 1588 |
1590 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream( | 1589 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream( |
1591 pEdit.get(), CFX_FloatPoint(0.0f, 0.0f), nullptr, !bCharArray, subWord); | 1590 pEdit.get(), CFX_FloatPoint(0.0f, 0.0f), nullptr, !bCharArray, subWord); |
1592 | 1591 |
1593 if (sEdit.GetLength() > 0) { | 1592 if (sEdit.GetLength() > 0) { |
1594 sBody << "/Tx BMC\n" | 1593 sBody << "/Tx BMC\n" |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1946 return FALSE; | 1945 return FALSE; |
1947 | 1946 |
1948 if (!IsVisible()) | 1947 if (!IsVisible()) |
1949 return FALSE; | 1948 return FALSE; |
1950 | 1949 |
1951 if ((GetFieldFlags() & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) | 1950 if ((GetFieldFlags() & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) |
1952 return FALSE; | 1951 return FALSE; |
1953 | 1952 |
1954 return TRUE; | 1953 return TRUE; |
1955 } | 1954 } |
OLD | NEW |