| 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 "fpdfsdk/include/fsdk_baseform.h" | 7 #include "fpdfsdk/include/fsdk_baseform.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | 14 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
| 15 #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" | 15 #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" |
| 16 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 16 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 17 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 17 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| 18 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" | 18 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" |
| 19 #include "core/fxge/include/fx_ge.h" | 19 #include "core/fxge/include/fx_ge.h" |
| 20 #include "fpdfsdk/formfiller/cffl_formfiller.h" | 20 #include "fpdfsdk/formfiller/cffl_formfiller.h" |
| 21 #include "fpdfsdk/fxedit/include/fxet_edit.h" |
| 21 #include "fpdfsdk/include/fsdk_actionhandler.h" | 22 #include "fpdfsdk/include/fsdk_actionhandler.h" |
| 22 #include "fpdfsdk/include/fsdk_baseannot.h" | 23 #include "fpdfsdk/include/fsdk_baseannot.h" |
| 23 #include "fpdfsdk/include/fsdk_define.h" | 24 #include "fpdfsdk/include/fsdk_define.h" |
| 24 #include "fpdfsdk/include/fsdk_mgr.h" | 25 #include "fpdfsdk/include/fsdk_mgr.h" |
| 25 #include "fpdfsdk/javascript/ijs_context.h" | 26 #include "fpdfsdk/javascript/ijs_context.h" |
| 26 #include "fpdfsdk/javascript/ijs_runtime.h" | 27 #include "fpdfsdk/javascript/ijs_runtime.h" |
| 27 #include "fpdfsdk/pdfwindow/PWL_Utils.h" | 28 #include "fpdfsdk/pdfwindow/PWL_Utils.h" |
| 28 | 29 |
| 29 #ifdef PDF_ENABLE_XFA | 30 #ifdef PDF_ENABLE_XFA |
| 30 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" | 31 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" |
| (...skipping 1324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1355 void CPDFSDK_Widget::ResetAppearance_ComboBox(const FX_WCHAR* sValue) { | 1356 void CPDFSDK_Widget::ResetAppearance_ComboBox(const FX_WCHAR* sValue) { |
| 1356 CPDF_FormControl* pControl = GetFormControl(); | 1357 CPDF_FormControl* pControl = GetFormControl(); |
| 1357 CPDF_FormField* pField = pControl->GetField(); | 1358 CPDF_FormField* pField = pControl->GetField(); |
| 1358 CFX_ByteTextBuf sBody, sLines; | 1359 CFX_ByteTextBuf sBody, sLines; |
| 1359 | 1360 |
| 1360 CFX_FloatRect rcClient = GetClientRect(); | 1361 CFX_FloatRect rcClient = GetClientRect(); |
| 1361 CFX_FloatRect rcButton = rcClient; | 1362 CFX_FloatRect rcButton = rcClient; |
| 1362 rcButton.left = rcButton.right - 13; | 1363 rcButton.left = rcButton.right - 13; |
| 1363 rcButton.Normalize(); | 1364 rcButton.Normalize(); |
| 1364 | 1365 |
| 1365 IFX_Edit* pEdit = IFX_Edit::NewEdit(); | 1366 std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit); |
| 1366 pEdit->EnableRefresh(FALSE); | 1367 pEdit->EnableRefresh(FALSE); |
| 1367 | 1368 |
| 1368 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); | 1369 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
| 1369 CPDFDoc_Environment* pEnv = pDoc->GetEnv(); | 1370 CPDFDoc_Environment* pEnv = pDoc->GetEnv(); |
| 1370 CBA_FontMap font_map(this, pEnv->GetSysHandler()); | 1371 CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
| 1371 pEdit->SetFontMap(&font_map); | 1372 pEdit->SetFontMap(&font_map); |
| 1372 | 1373 |
| 1373 CFX_FloatRect rcEdit = rcClient; | 1374 CFX_FloatRect rcEdit = rcClient; |
| 1374 rcEdit.right = rcButton.left; | 1375 rcEdit.right = rcButton.left; |
| 1375 rcEdit.Normalize(); | 1376 rcEdit.Normalize(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1392 | 1393 |
| 1393 if (nCurSel < 0) | 1394 if (nCurSel < 0) |
| 1394 pEdit->SetText(pField->GetValue().c_str()); | 1395 pEdit->SetText(pField->GetValue().c_str()); |
| 1395 else | 1396 else |
| 1396 pEdit->SetText(pField->GetOptionLabel(nCurSel).c_str()); | 1397 pEdit->SetText(pField->GetOptionLabel(nCurSel).c_str()); |
| 1397 } | 1398 } |
| 1398 | 1399 |
| 1399 CFX_FloatRect rcContent = pEdit->GetContentRect(); | 1400 CFX_FloatRect rcContent = pEdit->GetContentRect(); |
| 1400 | 1401 |
| 1401 CFX_ByteString sEdit = | 1402 CFX_ByteString sEdit = |
| 1402 CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, 0.0f)); | 1403 CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_FloatPoint(0.0f, 0.0f)); |
| 1403 if (sEdit.GetLength() > 0) { | 1404 if (sEdit.GetLength() > 0) { |
| 1404 sBody << "/Tx BMC\n" | 1405 sBody << "/Tx BMC\n" |
| 1405 << "q\n"; | 1406 << "q\n"; |
| 1406 if (rcContent.Width() > rcEdit.Width() || | 1407 if (rcContent.Width() > rcEdit.Width() || |
| 1407 rcContent.Height() > rcEdit.Height()) { | 1408 rcContent.Height() > rcEdit.Height()) { |
| 1408 sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width() | 1409 sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width() |
| 1409 << " " << rcEdit.Height() << " re\nW\nn\n"; | 1410 << " " << rcEdit.Height() << " re\nW\nn\n"; |
| 1410 } | 1411 } |
| 1411 | 1412 |
| 1412 CPWL_Color crText = GetTextPWLColor(); | 1413 CPWL_Color crText = GetTextPWLColor(); |
| 1413 sBody << "BT\n" | 1414 sBody << "BT\n" |
| 1414 << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" | 1415 << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" |
| 1415 << "Q\nEMC\n"; | 1416 << "Q\nEMC\n"; |
| 1416 } | 1417 } |
| 1417 | 1418 |
| 1418 IFX_Edit::DelEdit(pEdit); | |
| 1419 | |
| 1420 sBody << CPWL_Utils::GetDropButtonAppStream(rcButton); | 1419 sBody << CPWL_Utils::GetDropButtonAppStream(rcButton); |
| 1421 | 1420 |
| 1422 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + | 1421 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
| 1423 sLines.AsStringC() + sBody.AsStringC(); | 1422 sLines.AsStringC() + sBody.AsStringC(); |
| 1424 | 1423 |
| 1425 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); | 1424 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
| 1426 } | 1425 } |
| 1427 | 1426 |
| 1428 void CPDFSDK_Widget::ResetAppearance_ListBox() { | 1427 void CPDFSDK_Widget::ResetAppearance_ListBox() { |
| 1429 CPDF_FormControl* pControl = GetFormControl(); | 1428 CPDF_FormControl* pControl = GetFormControl(); |
| 1430 CPDF_FormField* pField = pControl->GetField(); | 1429 CPDF_FormField* pField = pControl->GetField(); |
| 1431 CFX_FloatRect rcClient = GetClientRect(); | 1430 CFX_FloatRect rcClient = GetClientRect(); |
| 1432 CFX_ByteTextBuf sBody, sLines; | 1431 CFX_ByteTextBuf sBody, sLines; |
| 1433 | 1432 |
| 1434 IFX_Edit* pEdit = IFX_Edit::NewEdit(); | 1433 std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit); |
| 1435 pEdit->EnableRefresh(FALSE); | 1434 pEdit->EnableRefresh(FALSE); |
| 1436 | 1435 |
| 1437 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); | 1436 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
| 1438 CPDFDoc_Environment* pEnv = pDoc->GetEnv(); | 1437 CPDFDoc_Environment* pEnv = pDoc->GetEnv(); |
| 1439 | 1438 |
| 1440 CBA_FontMap font_map(this, pEnv->GetSysHandler()); | 1439 CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
| 1441 pEdit->SetFontMap(&font_map); | 1440 pEdit->SetFontMap(&font_map); |
| 1442 | 1441 |
| 1443 pEdit->SetPlateRect(CFX_FloatRect(rcClient.left, 0.0f, rcClient.right, 0.0f)); | 1442 pEdit->SetPlateRect(CFX_FloatRect(rcClient.left, 0.0f, rcClient.right, 0.0f)); |
| 1444 | 1443 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1477 CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, | 1476 CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, |
| 1478 113.0f / 255.0f), | 1477 113.0f / 255.0f), |
| 1479 TRUE) | 1478 TRUE) |
| 1480 << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() | 1479 << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() |
| 1481 << " " << rcItem.Height() << " re f\n" | 1480 << " " << rcItem.Height() << " re f\n" |
| 1482 << "Q\n"; | 1481 << "Q\n"; |
| 1483 | 1482 |
| 1484 sList << "BT\n" | 1483 sList << "BT\n" |
| 1485 << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1), | 1484 << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1), |
| 1486 TRUE) | 1485 TRUE) |
| 1487 << CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, fy)) | 1486 << CPWL_Utils::GetEditAppStream(pEdit.get(), |
| 1487 CFX_FloatPoint(0.0f, fy)) |
| 1488 << "ET\n"; | 1488 << "ET\n"; |
| 1489 } else { | 1489 } else { |
| 1490 CPWL_Color crText = GetTextPWLColor(); | 1490 CPWL_Color crText = GetTextPWLColor(); |
| 1491 sList << "BT\n" | 1491 sList << "BT\n" |
| 1492 << CPWL_Utils::GetColorAppStream(crText, TRUE) | 1492 << CPWL_Utils::GetColorAppStream(crText, TRUE) |
| 1493 << CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, fy)) | 1493 << CPWL_Utils::GetEditAppStream(pEdit.get(), |
| 1494 CFX_FloatPoint(0.0f, fy)) |
| 1494 << "ET\n"; | 1495 << "ET\n"; |
| 1495 } | 1496 } |
| 1496 | 1497 |
| 1497 fy -= fItemHeight; | 1498 fy -= fItemHeight; |
| 1498 } | 1499 } |
| 1499 | 1500 |
| 1500 if (sList.GetSize() > 0) { | 1501 if (sList.GetSize() > 0) { |
| 1501 sBody << "/Tx BMC\n" | 1502 sBody << "/Tx BMC\n" |
| 1502 << "q\n" | 1503 << "q\n" |
| 1503 << rcClient.left << " " << rcClient.bottom << " " << rcClient.Width() | 1504 << rcClient.left << " " << rcClient.bottom << " " << rcClient.Width() |
| 1504 << " " << rcClient.Height() << " re\nW\nn\n"; | 1505 << " " << rcClient.Height() << " re\nW\nn\n"; |
| 1505 sBody << sList << "Q\nEMC\n"; | 1506 sBody << sList << "Q\nEMC\n"; |
| 1506 } | 1507 } |
| 1507 | 1508 |
| 1508 IFX_Edit::DelEdit(pEdit); | |
| 1509 | |
| 1510 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + | 1509 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
| 1511 sLines.AsStringC() + sBody.AsStringC(); | 1510 sLines.AsStringC() + sBody.AsStringC(); |
| 1512 | 1511 |
| 1513 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); | 1512 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
| 1514 } | 1513 } |
| 1515 | 1514 |
| 1516 void CPDFSDK_Widget::ResetAppearance_TextField(const FX_WCHAR* sValue) { | 1515 void CPDFSDK_Widget::ResetAppearance_TextField(const FX_WCHAR* sValue) { |
| 1517 CPDF_FormControl* pControl = GetFormControl(); | 1516 CPDF_FormControl* pControl = GetFormControl(); |
| 1518 CPDF_FormField* pField = pControl->GetField(); | 1517 CPDF_FormField* pField = pControl->GetField(); |
| 1519 CFX_ByteTextBuf sBody, sLines; | 1518 CFX_ByteTextBuf sBody, sLines; |
| 1520 | 1519 |
| 1521 IFX_Edit* pEdit = IFX_Edit::NewEdit(); | 1520 std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit); |
| 1522 pEdit->EnableRefresh(FALSE); | 1521 pEdit->EnableRefresh(FALSE); |
| 1523 | 1522 |
| 1524 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); | 1523 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
| 1525 CPDFDoc_Environment* pEnv = pDoc->GetEnv(); | 1524 CPDFDoc_Environment* pEnv = pDoc->GetEnv(); |
| 1526 | 1525 |
| 1527 CBA_FontMap font_map(this, pEnv->GetSysHandler()); | 1526 CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
| 1528 pEdit->SetFontMap(&font_map); | 1527 pEdit->SetFontMap(&font_map); |
| 1529 | 1528 |
| 1530 CFX_FloatRect rcClient = GetClientRect(); | 1529 CFX_FloatRect rcClient = GetClientRect(); |
| 1531 pEdit->SetPlateRect(rcClient); | 1530 pEdit->SetPlateRect(rcClient); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1582 pEdit->Initialize(); | 1581 pEdit->Initialize(); |
| 1583 | 1582 |
| 1584 if (sValue) | 1583 if (sValue) |
| 1585 pEdit->SetText(sValue); | 1584 pEdit->SetText(sValue); |
| 1586 else | 1585 else |
| 1587 pEdit->SetText(pField->GetValue().c_str()); | 1586 pEdit->SetText(pField->GetValue().c_str()); |
| 1588 | 1587 |
| 1589 CFX_FloatRect rcContent = pEdit->GetContentRect(); | 1588 CFX_FloatRect rcContent = pEdit->GetContentRect(); |
| 1590 | 1589 |
| 1591 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream( | 1590 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream( |
| 1592 pEdit, CFX_FloatPoint(0.0f, 0.0f), nullptr, !bCharArray, subWord); | 1591 pEdit.get(), CFX_FloatPoint(0.0f, 0.0f), nullptr, !bCharArray, subWord); |
| 1593 | 1592 |
| 1594 if (sEdit.GetLength() > 0) { | 1593 if (sEdit.GetLength() > 0) { |
| 1595 sBody << "/Tx BMC\n" | 1594 sBody << "/Tx BMC\n" |
| 1596 << "q\n"; | 1595 << "q\n"; |
| 1597 if (rcContent.Width() > rcClient.Width() || | 1596 if (rcContent.Width() > rcClient.Width() || |
| 1598 rcContent.Height() > rcClient.Height()) { | 1597 rcContent.Height() > rcClient.Height()) { |
| 1599 sBody << rcClient.left << " " << rcClient.bottom << " " | 1598 sBody << rcClient.left << " " << rcClient.bottom << " " |
| 1600 << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n"; | 1599 << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n"; |
| 1601 } | 1600 } |
| 1602 CPWL_Color crText = GetTextPWLColor(); | 1601 CPWL_Color crText = GetTextPWLColor(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1652 | 1651 |
| 1653 sLines << "Q\n"; | 1652 sLines << "Q\n"; |
| 1654 } | 1653 } |
| 1655 break; | 1654 break; |
| 1656 } | 1655 } |
| 1657 default: | 1656 default: |
| 1658 break; | 1657 break; |
| 1659 } | 1658 } |
| 1660 } | 1659 } |
| 1661 | 1660 |
| 1662 IFX_Edit::DelEdit(pEdit); | |
| 1663 | |
| 1664 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + | 1661 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
| 1665 sLines.AsStringC() + sBody.AsStringC(); | 1662 sLines.AsStringC() + sBody.AsStringC(); |
| 1666 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); | 1663 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
| 1667 } | 1664 } |
| 1668 | 1665 |
| 1669 CFX_FloatRect CPDFSDK_Widget::GetClientRect() const { | 1666 CFX_FloatRect CPDFSDK_Widget::GetClientRect() const { |
| 1670 CFX_FloatRect rcWindow = GetRotatedRect(); | 1667 CFX_FloatRect rcWindow = GetRotatedRect(); |
| 1671 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); | 1668 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
| 1672 switch (GetBorderStyle()) { | 1669 switch (GetBorderStyle()) { |
| 1673 case BorderStyle::BEVELED: | 1670 case BorderStyle::BEVELED: |
| (...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2830 break; | 2827 break; |
| 2831 } | 2828 } |
| 2832 } | 2829 } |
| 2833 } | 2830 } |
| 2834 | 2831 |
| 2835 CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) { | 2832 CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) { |
| 2836 CFX_FloatRect rcAnnot; | 2833 CFX_FloatRect rcAnnot; |
| 2837 pAnnot->GetPDFAnnot()->GetRect(rcAnnot); | 2834 pAnnot->GetPDFAnnot()->GetRect(rcAnnot); |
| 2838 return rcAnnot; | 2835 return rcAnnot; |
| 2839 } | 2836 } |
| OLD | NEW |