| 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/cpdfsdk_interform.h" | 7 #include "fpdfsdk/cpdfsdk_interform.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 #include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" | 40 #include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" |
| 41 #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" | 41 #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" |
| 42 #include "xfa/fxfa/cxfa_eventparam.h" | 42 #include "xfa/fxfa/cxfa_eventparam.h" |
| 43 #include "xfa/fxfa/xfa_ffdocview.h" | 43 #include "xfa/fxfa/xfa_ffdocview.h" |
| 44 #include "xfa/fxfa/xfa_ffwidget.h" | 44 #include "xfa/fxfa/xfa_ffwidget.h" |
| 45 #include "xfa/fxfa/xfa_ffwidgethandler.h" | 45 #include "xfa/fxfa/xfa_ffwidgethandler.h" |
| 46 #endif // PDF_ENABLE_XFA | 46 #endif // PDF_ENABLE_XFA |
| 47 | 47 |
| 48 CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_FormFillEnvironment* pFormFillEnv) | 48 CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_FormFillEnvironment* pFormFillEnv) |
| 49 : m_pFormFillEnv(pFormFillEnv), | 49 : m_pFormFillEnv(pFormFillEnv), |
| 50 m_pInterForm(new CPDF_InterForm( | 50 m_pInterForm(new CPDF_InterForm(m_pFormFillEnv->GetPDFDocument())), |
| 51 m_pFormFillEnv->GetSDKDocument()->GetPDFDocument())), | |
| 52 #ifdef PDF_ENABLE_XFA | 51 #ifdef PDF_ENABLE_XFA |
| 53 m_bXfaCalculate(TRUE), | 52 m_bXfaCalculate(TRUE), |
| 54 m_bXfaValidationsEnabled(TRUE), | 53 m_bXfaValidationsEnabled(TRUE), |
| 55 #endif // PDF_ENABLE_XFA | 54 #endif // PDF_ENABLE_XFA |
| 56 m_bCalculate(TRUE), | 55 m_bCalculate(TRUE), |
| 57 m_bBusy(FALSE), | 56 m_bBusy(FALSE), |
| 58 m_iHighlightAlpha(0) { | 57 m_iHighlightAlpha(0) { |
| 59 m_pInterForm->SetFormNotify(this); | 58 m_pInterForm->SetFormNotify(this); |
| 60 for (int i = 0; i < kNumFieldTypes; ++i) | 59 for (int i = 0; i < kNumFieldTypes; ++i) |
| 61 m_bNeedHightlight[i] = FALSE; | 60 m_bNeedHightlight[i] = FALSE; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 91 CPDFSDK_Widget* pWidget = nullptr; | 90 CPDFSDK_Widget* pWidget = nullptr; |
| 92 const auto it = m_Map.find(pControl); | 91 const auto it = m_Map.find(pControl); |
| 93 if (it != m_Map.end()) | 92 if (it != m_Map.end()) |
| 94 pWidget = it->second; | 93 pWidget = it->second; |
| 95 if (pWidget) | 94 if (pWidget) |
| 96 return pWidget; | 95 return pWidget; |
| 97 if (!createIfNeeded) | 96 if (!createIfNeeded) |
| 98 return nullptr; | 97 return nullptr; |
| 99 | 98 |
| 100 CPDF_Dictionary* pControlDict = pControl->GetWidget(); | 99 CPDF_Dictionary* pControlDict = pControl->GetWidget(); |
| 101 CPDF_Document* pDocument = m_pFormFillEnv->GetSDKDocument()->GetPDFDocument(); | 100 CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); |
| 102 CPDFSDK_PageView* pPage = nullptr; | 101 CPDFSDK_PageView* pPage = nullptr; |
| 103 | 102 |
| 104 if (CPDF_Dictionary* pPageDict = pControlDict->GetDictFor("P")) { | 103 if (CPDF_Dictionary* pPageDict = pControlDict->GetDictFor("P")) { |
| 105 int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum()); | 104 int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum()); |
| 106 if (nPageIndex >= 0) | 105 if (nPageIndex >= 0) |
| 107 pPage = m_pFormFillEnv->GetSDKDocument()->GetPageView(nPageIndex); | 106 pPage = m_pFormFillEnv->GetPageView(nPageIndex); |
| 108 } | 107 } |
| 109 | 108 |
| 110 if (!pPage) { | 109 if (!pPage) { |
| 111 int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict); | 110 int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict); |
| 112 if (nPageIndex >= 0) | 111 if (nPageIndex >= 0) |
| 113 pPage = m_pFormFillEnv->GetSDKDocument()->GetPageView(nPageIndex); | 112 pPage = m_pFormFillEnv->GetPageView(nPageIndex); |
| 114 } | 113 } |
| 115 | 114 |
| 116 if (!pPage) | 115 if (!pPage) |
| 117 return nullptr; | 116 return nullptr; |
| 118 | 117 |
| 119 return static_cast<CPDFSDK_Widget*>(pPage->GetAnnotByDict(pControlDict)); | 118 return static_cast<CPDFSDK_Widget*>(pPage->GetAnnotByDict(pControlDict)); |
| 120 } | 119 } |
| 121 | 120 |
| 122 void CPDFSDK_InterForm::GetWidgets( | 121 void CPDFSDK_InterForm::GetWidgets( |
| 123 const CFX_WideString& sFieldName, | 122 const CFX_WideString& sFieldName, |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 } | 327 } |
| 329 } | 328 } |
| 330 | 329 |
| 331 void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) { | 330 void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) { |
| 332 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { | 331 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 333 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); | 332 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); |
| 334 ASSERT(pFormCtrl); | 333 ASSERT(pFormCtrl); |
| 335 | 334 |
| 336 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) { | 335 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) { |
| 337 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); | 336 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); |
| 338 CPDFSDK_PageView* pPageView = | 337 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(pPage, false); |
| 339 m_pFormFillEnv->GetSDKDocument()->GetPageView(pPage, false); | |
| 340 FX_RECT rcBBox = m_pFormFillEnv->GetInteractiveFormFiller()->GetViewBBox( | 338 FX_RECT rcBBox = m_pFormFillEnv->GetInteractiveFormFiller()->GetViewBBox( |
| 341 pPageView, pWidget); | 339 pPageView, pWidget); |
| 342 | 340 |
| 343 m_pFormFillEnv->Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right, | 341 m_pFormFillEnv->Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right, |
| 344 rcBBox.bottom); | 342 rcBBox.bottom); |
| 345 } | 343 } |
| 346 } | 344 } |
| 347 } | 345 } |
| 348 | 346 |
| 349 FX_BOOL CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, | 347 FX_BOOL CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 nBufSize = fdfEncodedData.GetLength(); | 503 nBufSize = fdfEncodedData.GetLength(); |
| 506 pBuf = FX_Alloc(uint8_t, nBufSize); | 504 pBuf = FX_Alloc(uint8_t, nBufSize); |
| 507 FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize); | 505 FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize); |
| 508 return TRUE; | 506 return TRUE; |
| 509 } | 507 } |
| 510 | 508 |
| 511 FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf( | 509 FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf( |
| 512 const std::vector<CPDF_FormField*>& fields, | 510 const std::vector<CPDF_FormField*>& fields, |
| 513 bool bIncludeOrExclude, | 511 bool bIncludeOrExclude, |
| 514 CFX_ByteTextBuf& textBuf) { | 512 CFX_ByteTextBuf& textBuf) { |
| 515 std::unique_ptr<CFDF_Document> pFDF(m_pInterForm->ExportToFDF( | 513 std::unique_ptr<CFDF_Document> pFDF( |
| 516 m_pFormFillEnv->GetSDKDocument()->JS_docGetFilePath().AsStringC(), fields, | 514 m_pInterForm->ExportToFDF(m_pFormFillEnv->JS_docGetFilePath().AsStringC(), |
| 517 bIncludeOrExclude, false)); | 515 fields, bIncludeOrExclude, false)); |
| 518 return pFDF ? pFDF->WriteBuf(textBuf) : FALSE; | 516 return pFDF ? pFDF->WriteBuf(textBuf) : FALSE; |
| 519 } | 517 } |
| 520 | 518 |
| 521 CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName( | 519 CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName( |
| 522 const CFX_WideString& sFileExt) { | 520 const CFX_WideString& sFileExt) { |
| 523 return L""; | 521 return L""; |
| 524 } | 522 } |
| 525 | 523 |
| 526 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, | 524 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, |
| 527 FX_BOOL bUrlEncoded) { | 525 FX_BOOL bUrlEncoded) { |
| 528 if (sDestination.IsEmpty()) | 526 if (sDestination.IsEmpty()) |
| 529 return FALSE; | 527 return FALSE; |
| 530 | 528 |
| 531 if (!m_pFormFillEnv || !m_pFormFillEnv->GetSDKDocument() || !m_pInterForm) | 529 if (!m_pFormFillEnv || !m_pInterForm) |
| 532 return FALSE; | 530 return FALSE; |
| 533 | 531 |
| 534 CFX_WideString wsPDFFilePath = | 532 CFX_WideString wsPDFFilePath = m_pFormFillEnv->JS_docGetFilePath(); |
| 535 m_pFormFillEnv->GetSDKDocument()->JS_docGetFilePath(); | |
| 536 CFDF_Document* pFDFDoc = | 533 CFDF_Document* pFDFDoc = |
| 537 m_pInterForm->ExportToFDF(wsPDFFilePath.AsStringC(), false); | 534 m_pInterForm->ExportToFDF(wsPDFFilePath.AsStringC(), false); |
| 538 if (!pFDFDoc) | 535 if (!pFDFDoc) |
| 539 return FALSE; | 536 return FALSE; |
| 540 | 537 |
| 541 CFX_ByteTextBuf FdfBuffer; | 538 CFX_ByteTextBuf FdfBuffer; |
| 542 FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer); | 539 FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer); |
| 543 delete pFDFDoc; | 540 delete pFDFDoc; |
| 544 if (!bRet) | 541 if (!bRet) |
| 545 return FALSE; | 542 return FALSE; |
| 546 | 543 |
| 547 uint8_t* pBuffer = FdfBuffer.GetBuffer(); | 544 uint8_t* pBuffer = FdfBuffer.GetBuffer(); |
| 548 FX_STRSIZE nBufSize = FdfBuffer.GetLength(); | 545 FX_STRSIZE nBufSize = FdfBuffer.GetLength(); |
| 549 | 546 |
| 550 if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) | 547 if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) |
| 551 return FALSE; | 548 return FALSE; |
| 552 | 549 |
| 553 m_pFormFillEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str()); | 550 m_pFormFillEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str()); |
| 554 | 551 |
| 555 if (bUrlEncoded) | 552 if (bUrlEncoded) |
| 556 FX_Free(pBuffer); | 553 FX_Free(pBuffer); |
| 557 | 554 |
| 558 return TRUE; | 555 return TRUE; |
| 559 } | 556 } |
| 560 | 557 |
| 561 FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) { | 558 FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) { |
| 562 CFDF_Document* pFDF = m_pInterForm->ExportToFDF( | 559 CFDF_Document* pFDF = m_pInterForm->ExportToFDF( |
| 563 m_pFormFillEnv->GetSDKDocument()->JS_docGetFilePath().AsStringC(), false); | 560 m_pFormFillEnv->JS_docGetFilePath().AsStringC(), false); |
| 564 if (!pFDF) | 561 if (!pFDF) |
| 565 return FALSE; | 562 return FALSE; |
| 566 | 563 |
| 567 FX_BOOL bRet = pFDF->WriteBuf(textBuf); | 564 FX_BOOL bRet = pFDF->WriteBuf(textBuf); |
| 568 delete pFDF; | 565 delete pFDF; |
| 569 | 566 |
| 570 return bRet; | 567 return bRet; |
| 571 } | 568 } |
| 572 | 569 |
| 573 FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) { | 570 FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 } | 707 } |
| 711 } | 708 } |
| 712 | 709 |
| 713 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) { | 710 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) { |
| 714 if (nFieldType < 0 || nFieldType > kNumFieldTypes) | 711 if (nFieldType < 0 || nFieldType > kNumFieldTypes) |
| 715 return FXSYS_RGB(255, 255, 255); | 712 return FXSYS_RGB(255, 255, 255); |
| 716 if (nFieldType == 0) | 713 if (nFieldType == 0) |
| 717 return m_aHighlightColor[0]; | 714 return m_aHighlightColor[0]; |
| 718 return m_aHighlightColor[nFieldType - 1]; | 715 return m_aHighlightColor[nFieldType - 1]; |
| 719 } | 716 } |
| OLD | NEW |