| 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 <memory> | 10 #include <memory> |
| (...skipping 2304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2315 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); | 2315 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); |
| 2316 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage, FALSE); | 2316 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage, FALSE); |
| 2317 FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget); | 2317 FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget); |
| 2318 | 2318 |
| 2319 pEnv->FFI_Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right, | 2319 pEnv->FFI_Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right, |
| 2320 rcBBox.bottom); | 2320 rcBBox.bottom); |
| 2321 } | 2321 } |
| 2322 } | 2322 } |
| 2323 } | 2323 } |
| 2324 | 2324 |
| 2325 void CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, | 2325 FX_BOOL CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, |
| 2326 CFX_WideString& csValue, | 2326 const CFX_WideString& csValue) { |
| 2327 FX_BOOL& bRC) { | |
| 2328 CPDF_AAction aAction = pFormField->GetAdditionalAction(); | 2327 CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
| 2329 if (aAction && aAction.ActionExist(CPDF_AAction::KeyStroke)) { | 2328 if (!aAction || !aAction.ActionExist(CPDF_AAction::KeyStroke)) |
| 2330 CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke); | 2329 return TRUE; |
| 2331 if (action) { | |
| 2332 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); | |
| 2333 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); | |
| 2334 PDFSDK_FieldAction fa; | |
| 2335 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); | |
| 2336 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); | |
| 2337 fa.sValue = csValue; | |
| 2338 | 2330 |
| 2339 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke, | 2331 CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke); |
| 2340 m_pDocument, pFormField, fa); | 2332 if (!action) |
| 2341 bRC = fa.bRC; | 2333 return TRUE; |
| 2342 } | 2334 |
| 2343 } | 2335 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
| 2336 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
| 2337 PDFSDK_FieldAction fa; |
| 2338 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); |
| 2339 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); |
| 2340 fa.sValue = csValue; |
| 2341 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke, |
| 2342 m_pDocument, pFormField, fa); |
| 2343 return fa.bRC; |
| 2344 } | 2344 } |
| 2345 | 2345 |
| 2346 void CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, | 2346 FX_BOOL CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, |
| 2347 CFX_WideString& csValue, | 2347 const CFX_WideString& csValue) { |
| 2348 FX_BOOL& bRC) { | |
| 2349 CPDF_AAction aAction = pFormField->GetAdditionalAction(); | 2348 CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
| 2350 if (aAction && aAction.ActionExist(CPDF_AAction::Validate)) { | 2349 if (!aAction || !aAction.ActionExist(CPDF_AAction::Validate)) |
| 2351 CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate); | 2350 return TRUE; |
| 2352 if (action) { | |
| 2353 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); | |
| 2354 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); | |
| 2355 PDFSDK_FieldAction fa; | |
| 2356 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); | |
| 2357 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); | |
| 2358 fa.sValue = csValue; | |
| 2359 | 2351 |
| 2360 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate, | 2352 CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate); |
| 2361 m_pDocument, pFormField, fa); | 2353 if (!action) |
| 2362 bRC = fa.bRC; | 2354 return TRUE; |
| 2363 } | 2355 |
| 2364 } | 2356 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
| 2357 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
| 2358 PDFSDK_FieldAction fa; |
| 2359 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); |
| 2360 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); |
| 2361 fa.sValue = csValue; |
| 2362 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate, |
| 2363 m_pDocument, pFormField, fa); |
| 2364 return fa.bRC; |
| 2365 } | 2365 } |
| 2366 | 2366 |
| 2367 FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action) { | 2367 FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action) { |
| 2368 ASSERT(action); | 2368 ASSERT(action); |
| 2369 | 2369 |
| 2370 CPDF_ActionFields af = action.GetWidgets(); | 2370 CPDF_ActionFields af = action.GetWidgets(); |
| 2371 std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); | 2371 std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); |
| 2372 std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); | 2372 std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); |
| 2373 | 2373 |
| 2374 FX_BOOL bHide = action.GetHideStatus(); | 2374 FX_BOOL bHide = action.GetHideStatus(); |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2601 if (pObject && pObject->IsString()) { | 2601 if (pObject && pObject->IsString()) { |
| 2602 CFX_WideString csName = pObject->GetUnicodeText(); | 2602 CFX_WideString csName = pObject->GetUnicodeText(); |
| 2603 CPDF_FormField* pField = m_pInterForm->GetField(0, csName); | 2603 CPDF_FormField* pField = m_pInterForm->GetField(0, csName); |
| 2604 if (pField) | 2604 if (pField) |
| 2605 fields.push_back(pField); | 2605 fields.push_back(pField); |
| 2606 } | 2606 } |
| 2607 } | 2607 } |
| 2608 return fields; | 2608 return fields; |
| 2609 } | 2609 } |
| 2610 | 2610 |
| 2611 int CPDFSDK_InterForm::BeforeValueChange(const CPDF_FormField* pField, | 2611 int CPDFSDK_InterForm::BeforeValueChange(CPDF_FormField* pField, |
| 2612 CFX_WideString& csValue) { | 2612 const CFX_WideString& csValue) { |
| 2613 CPDF_FormField* pFormField = (CPDF_FormField*)pField; | 2613 int nType = pField->GetFieldType(); |
| 2614 int nType = pFormField->GetFieldType(); | 2614 if (nType != FIELDTYPE_COMBOBOX && nType != FIELDTYPE_TEXTFIELD) |
| 2615 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { | |
| 2616 FX_BOOL bRC = TRUE; | |
| 2617 OnKeyStrokeCommit(pFormField, csValue, bRC); | |
| 2618 if (bRC) { | |
| 2619 OnValidate(pFormField, csValue, bRC); | |
| 2620 return bRC ? 1 : -1; | |
| 2621 } | |
| 2622 return -1; | |
| 2623 } | |
| 2624 return 0; | |
| 2625 } | |
| 2626 | |
| 2627 int CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField) { | |
| 2628 CPDF_FormField* pFormField = (CPDF_FormField*)pField; | |
| 2629 #ifdef PDF_ENABLE_XFA | |
| 2630 SynchronizeField(pFormField, FALSE); | |
| 2631 #endif // PDF_ENABLE_XFA | |
| 2632 int nType = pFormField->GetFieldType(); | |
| 2633 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { | |
| 2634 OnCalculate(pFormField); | |
| 2635 FX_BOOL bFormated = FALSE; | |
| 2636 CFX_WideString sValue = OnFormat(pFormField, bFormated); | |
| 2637 if (bFormated) | |
| 2638 ResetFieldAppearance(pFormField, sValue.c_str(), TRUE); | |
| 2639 else | |
| 2640 ResetFieldAppearance(pFormField, NULL, TRUE); | |
| 2641 UpdateField(pFormField); | |
| 2642 } | |
| 2643 return 0; | |
| 2644 } | |
| 2645 | |
| 2646 int CPDFSDK_InterForm::BeforeSelectionChange(const CPDF_FormField* pField, | |
| 2647 CFX_WideString& csValue) { | |
| 2648 CPDF_FormField* pFormField = (CPDF_FormField*)pField; | |
| 2649 if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX) | |
| 2650 return 0; | 2615 return 0; |
| 2651 | 2616 |
| 2652 FX_BOOL bRC = TRUE; | 2617 if (!OnKeyStrokeCommit(pField, csValue)) |
| 2653 OnKeyStrokeCommit(pFormField, csValue, bRC); | |
| 2654 if (!bRC) | |
| 2655 return -1; | 2618 return -1; |
| 2656 | 2619 |
| 2657 OnValidate(pFormField, csValue, bRC); | 2620 if (!OnValidate(pField, csValue)) |
| 2658 if (!bRC) | |
| 2659 return -1; | 2621 return -1; |
| 2660 | 2622 |
| 2661 return 1; | 2623 return 1; |
| 2662 } | 2624 } |
| 2663 | 2625 |
| 2664 int CPDFSDK_InterForm::AfterSelectionChange(const CPDF_FormField* pField) { | 2626 void CPDFSDK_InterForm::AfterValueChange(CPDF_FormField* pField) { |
| 2665 CPDF_FormField* pFormField = (CPDF_FormField*)pField; | 2627 #ifdef PDF_ENABLE_XFA |
| 2666 if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX) { | 2628 SynchronizeField(pField, FALSE); |
| 2667 OnCalculate(pFormField); | 2629 #endif // PDF_ENABLE_XFA |
| 2668 ResetFieldAppearance(pFormField, NULL, TRUE); | 2630 int nType = pField->GetFieldType(); |
| 2669 UpdateField(pFormField); | 2631 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { |
| 2632 OnCalculate(pField); |
| 2633 FX_BOOL bFormated = FALSE; |
| 2634 CFX_WideString sValue = OnFormat(pField, bFormated); |
| 2635 ResetFieldAppearance(pField, bFormated ? sValue.c_str() : nullptr, TRUE); |
| 2636 UpdateField(pField); |
| 2670 } | 2637 } |
| 2671 return 0; | 2638 } |
| 2639 |
| 2640 int CPDFSDK_InterForm::BeforeSelectionChange(CPDF_FormField* pField, |
| 2641 const CFX_WideString& csValue) { |
| 2642 if (pField->GetFieldType() != FIELDTYPE_LISTBOX) |
| 2643 return 0; |
| 2644 |
| 2645 if (!OnKeyStrokeCommit(pField, csValue)) |
| 2646 return -1; |
| 2647 |
| 2648 if (!OnValidate(pField, csValue)) |
| 2649 return -1; |
| 2650 |
| 2651 return 1; |
| 2652 } |
| 2653 |
| 2654 void CPDFSDK_InterForm::AfterSelectionChange(CPDF_FormField* pField) { |
| 2655 if (pField->GetFieldType() == FIELDTYPE_LISTBOX) { |
| 2656 OnCalculate(pField); |
| 2657 ResetFieldAppearance(pField, NULL, TRUE); |
| 2658 UpdateField(pField); |
| 2659 } |
| 2672 } | 2660 } |
| 2673 | 2661 |
| 2674 void CPDFSDK_InterForm::AfterCheckedStatusChange(CPDF_FormField* pField) { | 2662 void CPDFSDK_InterForm::AfterCheckedStatusChange(CPDF_FormField* pField) { |
| 2675 int nType = pField->GetFieldType(); | 2663 int nType = pField->GetFieldType(); |
| 2676 if (nType == FIELDTYPE_CHECKBOX || nType == FIELDTYPE_RADIOBUTTON) { | 2664 if (nType == FIELDTYPE_CHECKBOX || nType == FIELDTYPE_RADIOBUTTON) { |
| 2677 OnCalculate(pField); | 2665 OnCalculate(pField); |
| 2678 UpdateField(pField); | 2666 UpdateField(pField); |
| 2679 } | 2667 } |
| 2680 } | 2668 } |
| 2681 | 2669 |
| 2682 int CPDFSDK_InterForm::BeforeFormReset(const CPDF_InterForm* pForm) { | 2670 int CPDFSDK_InterForm::BeforeFormReset(CPDF_InterForm* pForm) { |
| 2683 return 0; | 2671 return 0; |
| 2684 } | 2672 } |
| 2685 | 2673 |
| 2686 int CPDFSDK_InterForm::AfterFormReset(const CPDF_InterForm* pForm) { | 2674 void CPDFSDK_InterForm::AfterFormReset(CPDF_InterForm* pForm) { |
| 2687 OnCalculate(nullptr); | 2675 OnCalculate(nullptr); |
| 2676 } |
| 2677 |
| 2678 int CPDFSDK_InterForm::BeforeFormImportData(CPDF_InterForm* pForm) { |
| 2688 return 0; | 2679 return 0; |
| 2689 } | 2680 } |
| 2690 | 2681 |
| 2691 int CPDFSDK_InterForm::BeforeFormImportData(const CPDF_InterForm* pForm) { | 2682 void CPDFSDK_InterForm::AfterFormImportData(CPDF_InterForm* pForm) { |
| 2692 return 0; | |
| 2693 } | |
| 2694 | |
| 2695 int CPDFSDK_InterForm::AfterFormImportData(const CPDF_InterForm* pForm) { | |
| 2696 OnCalculate(nullptr); | 2683 OnCalculate(nullptr); |
| 2697 return 0; | |
| 2698 } | 2684 } |
| 2699 | 2685 |
| 2700 FX_BOOL CPDFSDK_InterForm::IsNeedHighLight(int nFieldType) { | 2686 FX_BOOL CPDFSDK_InterForm::IsNeedHighLight(int nFieldType) { |
| 2701 if (nFieldType < 1 || nFieldType > kNumFieldTypes) | 2687 if (nFieldType < 1 || nFieldType > kNumFieldTypes) |
| 2702 return FALSE; | 2688 return FALSE; |
| 2703 return m_bNeedHightlight[nFieldType - 1]; | 2689 return m_bNeedHightlight[nFieldType - 1]; |
| 2704 } | 2690 } |
| 2705 | 2691 |
| 2706 void CPDFSDK_InterForm::RemoveAllHighLight() { | 2692 void CPDFSDK_InterForm::RemoveAllHighLight() { |
| 2707 for (int i = 0; i < kNumFieldTypes; ++i) | 2693 for (int i = 0; i < kNumFieldTypes; ++i) |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2889 break; | 2875 break; |
| 2890 } | 2876 } |
| 2891 } | 2877 } |
| 2892 } | 2878 } |
| 2893 | 2879 |
| 2894 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) { | 2880 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) { |
| 2895 CPDF_Rect rcAnnot; | 2881 CPDF_Rect rcAnnot; |
| 2896 pAnnot->GetPDFAnnot()->GetRect(rcAnnot); | 2882 pAnnot->GetPDFAnnot()->GetRect(rcAnnot); |
| 2897 return rcAnnot; | 2883 return rcAnnot; |
| 2898 } | 2884 } |
| OLD | NEW |