| 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> |
| (...skipping 2042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2053 FX_BOOL bNext) const { | 2053 FX_BOOL bNext) const { |
| 2054 std::unique_ptr<CBA_AnnotIterator> pIterator( | 2054 std::unique_ptr<CBA_AnnotIterator> pIterator( |
| 2055 new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", "")); | 2055 new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", "")); |
| 2056 | 2056 |
| 2057 if (bNext) { | 2057 if (bNext) { |
| 2058 return (CPDFSDK_Widget*)pIterator->GetNextAnnot(pWidget); | 2058 return (CPDFSDK_Widget*)pIterator->GetNextAnnot(pWidget); |
| 2059 } | 2059 } |
| 2060 return (CPDFSDK_Widget*)pIterator->GetPrevAnnot(pWidget); | 2060 return (CPDFSDK_Widget*)pIterator->GetPrevAnnot(pWidget); |
| 2061 } | 2061 } |
| 2062 | 2062 |
| 2063 CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const { | 2063 CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl, |
| 2064 bool createIfNeeded) const { |
| 2064 if (!pControl || !m_pInterForm) | 2065 if (!pControl || !m_pInterForm) |
| 2065 return nullptr; | 2066 return nullptr; |
| 2066 | 2067 |
| 2067 CPDFSDK_Widget* pWidget = nullptr; | 2068 CPDFSDK_Widget* pWidget = nullptr; |
| 2068 const auto it = m_Map.find(pControl); | 2069 const auto it = m_Map.find(pControl); |
| 2069 if (it != m_Map.end()) | 2070 if (it != m_Map.end()) |
| 2070 pWidget = it->second; | 2071 pWidget = it->second; |
| 2071 | |
| 2072 if (pWidget) | 2072 if (pWidget) |
| 2073 return pWidget; | 2073 return pWidget; |
| 2074 if (!createIfNeeded) |
| 2075 return nullptr; |
| 2074 | 2076 |
| 2075 CPDF_Dictionary* pControlDict = pControl->GetWidget(); | 2077 CPDF_Dictionary* pControlDict = pControl->GetWidget(); |
| 2076 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); | 2078 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
| 2077 CPDFSDK_PageView* pPage = nullptr; | 2079 CPDFSDK_PageView* pPage = nullptr; |
| 2078 | 2080 |
| 2079 if (CPDF_Dictionary* pPageDict = pControlDict->GetDictBy("P")) { | 2081 if (CPDF_Dictionary* pPageDict = pControlDict->GetDictBy("P")) { |
| 2080 int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum()); | 2082 int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum()); |
| 2081 if (nPageIndex >= 0) { | 2083 if (nPageIndex >= 0) { |
| 2082 pPage = m_pDocument->GetPageView(nPageIndex); | 2084 pPage = m_pDocument->GetPageView(nPageIndex); |
| 2083 } | 2085 } |
| 2084 } | 2086 } |
| 2085 | 2087 |
| 2086 if (!pPage) { | 2088 if (!pPage) { |
| 2087 int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict); | 2089 int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict); |
| 2088 if (nPageIndex >= 0) { | 2090 if (nPageIndex >= 0) { |
| 2089 pPage = m_pDocument->GetPageView(nPageIndex); | 2091 pPage = m_pDocument->GetPageView(nPageIndex); |
| 2090 } | 2092 } |
| 2091 } | 2093 } |
| 2092 | 2094 |
| 2093 if (!pPage) | 2095 if (!pPage) |
| 2094 return nullptr; | 2096 return nullptr; |
| 2097 |
| 2095 return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict); | 2098 return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict); |
| 2096 } | 2099 } |
| 2097 | 2100 |
| 2098 void CPDFSDK_InterForm::GetWidgets( | 2101 void CPDFSDK_InterForm::GetWidgets( |
| 2099 const CFX_WideString& sFieldName, | 2102 const CFX_WideString& sFieldName, |
| 2100 std::vector<CPDFSDK_Widget*>* widgets) const { | 2103 std::vector<CPDFSDK_Widget*>* widgets) const { |
| 2101 for (int i = 0, sz = m_pInterForm->CountFields(sFieldName); i < sz; ++i) { | 2104 for (int i = 0, sz = m_pInterForm->CountFields(sFieldName); i < sz; ++i) { |
| 2102 CPDF_FormField* pFormField = m_pInterForm->GetField(i, sFieldName); | 2105 CPDF_FormField* pFormField = m_pInterForm->GetField(i, sFieldName); |
| 2103 ASSERT(pFormField); | 2106 ASSERT(pFormField); |
| 2104 GetWidgets(pFormField, widgets); | 2107 GetWidgets(pFormField, widgets); |
| 2105 } | 2108 } |
| 2106 } | 2109 } |
| 2107 | 2110 |
| 2108 void CPDFSDK_InterForm::GetWidgets( | 2111 void CPDFSDK_InterForm::GetWidgets( |
| 2109 CPDF_FormField* pField, | 2112 CPDF_FormField* pField, |
| 2110 std::vector<CPDFSDK_Widget*>* widgets) const { | 2113 std::vector<CPDFSDK_Widget*>* widgets) const { |
| 2111 for (int i = 0, sz = pField->CountControls(); i < sz; ++i) { | 2114 for (int i = 0, sz = pField->CountControls(); i < sz; ++i) { |
| 2112 CPDF_FormControl* pFormCtrl = pField->GetControl(i); | 2115 CPDF_FormControl* pFormCtrl = pField->GetControl(i); |
| 2113 ASSERT(pFormCtrl); | 2116 ASSERT(pFormCtrl); |
| 2114 CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl); | 2117 CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, true); |
| 2115 if (pWidget) | 2118 if (pWidget) |
| 2116 widgets->push_back(pWidget); | 2119 widgets->push_back(pWidget); |
| 2117 } | 2120 } |
| 2118 } | 2121 } |
| 2119 | 2122 |
| 2120 int CPDFSDK_InterForm::GetPageIndexByAnnotDict( | 2123 int CPDFSDK_InterForm::GetPageIndexByAnnotDict( |
| 2121 CPDF_Document* pDocument, | 2124 CPDF_Document* pDocument, |
| 2122 CPDF_Dictionary* pAnnotDict) const { | 2125 CPDF_Dictionary* pAnnotDict) const { |
| 2123 ASSERT(pAnnotDict); | 2126 ASSERT(pAnnotDict); |
| 2124 | 2127 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2269 CPDF_AAction aAction = pFormField->GetAdditionalAction(); | 2272 CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
| 2270 if (aAction.GetDict() && aAction.ActionExist(CPDF_AAction::Format)) { | 2273 if (aAction.GetDict() && aAction.ActionExist(CPDF_AAction::Format)) { |
| 2271 CPDF_Action action = aAction.GetAction(CPDF_AAction::Format); | 2274 CPDF_Action action = aAction.GetAction(CPDF_AAction::Format); |
| 2272 if (action.GetDict()) { | 2275 if (action.GetDict()) { |
| 2273 CFX_WideString script = action.GetJavaScript(); | 2276 CFX_WideString script = action.GetJavaScript(); |
| 2274 if (!script.IsEmpty()) { | 2277 if (!script.IsEmpty()) { |
| 2275 CFX_WideString Value = sValue; | 2278 CFX_WideString Value = sValue; |
| 2276 | 2279 |
| 2277 IJS_Context* pContext = pRuntime->NewContext(); | 2280 IJS_Context* pContext = pRuntime->NewContext(); |
| 2278 pContext->OnField_Format(pFormField, Value, TRUE); | 2281 pContext->OnField_Format(pFormField, Value, TRUE); |
| 2279 | |
| 2280 CFX_WideString sInfo; | 2282 CFX_WideString sInfo; |
| 2281 FX_BOOL bRet = pContext->RunScript(script, &sInfo); | 2283 FX_BOOL bRet = pContext->RunScript(script, &sInfo); |
| 2282 pRuntime->ReleaseContext(pContext); | 2284 pRuntime->ReleaseContext(pContext); |
| 2283 | 2285 |
| 2284 if (bRet) { | 2286 if (bRet) { |
| 2285 sValue = Value; | 2287 sValue = Value; |
| 2286 bFormated = TRUE; | 2288 bFormated = TRUE; |
| 2287 } | 2289 } |
| 2288 } | 2290 } |
| 2289 } | 2291 } |
| 2290 } | 2292 } |
| 2291 | 2293 |
| 2292 return sValue; | 2294 return sValue; |
| 2293 } | 2295 } |
| 2294 | 2296 |
| 2295 void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField, | 2297 void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField, |
| 2296 const FX_WCHAR* sValue, | 2298 const FX_WCHAR* sValue, |
| 2297 FX_BOOL bValueChanged) { | 2299 FX_BOOL bValueChanged) { |
| 2298 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { | 2300 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 2299 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); | 2301 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); |
| 2300 ASSERT(pFormCtrl); | 2302 ASSERT(pFormCtrl); |
| 2301 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) | 2303 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) |
| 2302 pWidget->ResetAppearance(sValue, bValueChanged); | 2304 pWidget->ResetAppearance(sValue, bValueChanged); |
| 2303 } | 2305 } |
| 2304 } | 2306 } |
| 2305 | 2307 |
| 2306 void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) { | 2308 void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) { |
| 2307 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { | 2309 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 2308 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); | 2310 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); |
| 2309 ASSERT(pFormCtrl); | 2311 ASSERT(pFormCtrl); |
| 2310 | 2312 |
| 2311 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) { | 2313 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) { |
| 2312 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); | 2314 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
| 2313 CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller(); | 2315 CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller(); |
| 2314 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); | 2316 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); |
| 2315 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage, false); | 2317 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage, false); |
| 2316 FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget); | 2318 FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget); |
| 2317 | 2319 |
| 2318 pEnv->FFI_Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right, | 2320 pEnv->FFI_Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right, |
| 2319 rcBBox.bottom); | 2321 rcBBox.bottom); |
| 2320 } | 2322 } |
| 2321 } | 2323 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2371 std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); | 2373 std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); |
| 2372 | 2374 |
| 2373 bool bHide = action.GetHideStatus(); | 2375 bool bHide = action.GetHideStatus(); |
| 2374 FX_BOOL bChanged = FALSE; | 2376 FX_BOOL bChanged = FALSE; |
| 2375 | 2377 |
| 2376 for (CPDF_FormField* pField : fields) { | 2378 for (CPDF_FormField* pField : fields) { |
| 2377 for (int i = 0, sz = pField->CountControls(); i < sz; ++i) { | 2379 for (int i = 0, sz = pField->CountControls(); i < sz; ++i) { |
| 2378 CPDF_FormControl* pControl = pField->GetControl(i); | 2380 CPDF_FormControl* pControl = pField->GetControl(i); |
| 2379 ASSERT(pControl); | 2381 ASSERT(pControl); |
| 2380 | 2382 |
| 2381 if (CPDFSDK_Widget* pWidget = GetWidget(pControl)) { | 2383 if (CPDFSDK_Widget* pWidget = GetWidget(pControl, false)) { |
| 2382 uint32_t nFlags = pWidget->GetFlags(); | 2384 uint32_t nFlags = pWidget->GetFlags(); |
| 2383 nFlags &= ~ANNOTFLAG_INVISIBLE; | 2385 nFlags &= ~ANNOTFLAG_INVISIBLE; |
| 2384 nFlags &= ~ANNOTFLAG_NOVIEW; | 2386 nFlags &= ~ANNOTFLAG_NOVIEW; |
| 2385 if (bHide) | 2387 if (bHide) |
| 2386 nFlags |= ANNOTFLAG_HIDDEN; | 2388 nFlags |= ANNOTFLAG_HIDDEN; |
| 2387 else | 2389 else |
| 2388 nFlags &= ~ANNOTFLAG_HIDDEN; | 2390 nFlags &= ~ANNOTFLAG_HIDDEN; |
| 2389 pWidget->SetFlags(nFlags); | 2391 pWidget->SetFlags(nFlags); |
| 2390 pWidget->GetPageView()->UpdateView(pWidget); | 2392 pWidget->GetPageView()->UpdateView(pWidget); |
| 2391 bChanged = TRUE; | 2393 bChanged = TRUE; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2494 std::unique_ptr<CFDF_Document> pFDF(m_pInterForm->ExportToFDF( | 2496 std::unique_ptr<CFDF_Document> pFDF(m_pInterForm->ExportToFDF( |
| 2495 m_pDocument->GetPath().AsStringC(), fields, bIncludeOrExclude)); | 2497 m_pDocument->GetPath().AsStringC(), fields, bIncludeOrExclude)); |
| 2496 return pFDF ? pFDF->WriteBuf(textBuf) : FALSE; | 2498 return pFDF ? pFDF->WriteBuf(textBuf) : FALSE; |
| 2497 } | 2499 } |
| 2498 | 2500 |
| 2499 #ifdef PDF_ENABLE_XFA | 2501 #ifdef PDF_ENABLE_XFA |
| 2500 void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField, | 2502 void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField, |
| 2501 FX_BOOL bSynchronizeElse) { | 2503 FX_BOOL bSynchronizeElse) { |
| 2502 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { | 2504 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 2503 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); | 2505 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); |
| 2504 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) { | 2506 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl, false)) { |
| 2505 pWidget->Synchronize(bSynchronizeElse); | 2507 pWidget->Synchronize(bSynchronizeElse); |
| 2506 } | 2508 } |
| 2507 } | 2509 } |
| 2508 } | 2510 } |
| 2509 #endif // PDF_ENABLE_XFA | 2511 #endif // PDF_ENABLE_XFA |
| 2510 | 2512 |
| 2511 CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName( | 2513 CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName( |
| 2512 const CFX_WideString& sFileExt) { | 2514 const CFX_WideString& sFileExt) { |
| 2513 CFX_WideString sFileName; | 2515 CFX_WideString sFileName; |
| 2514 return L""; | 2516 return L""; |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2861 break; | 2863 break; |
| 2862 } | 2864 } |
| 2863 } | 2865 } |
| 2864 } | 2866 } |
| 2865 | 2867 |
| 2866 CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) { | 2868 CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) { |
| 2867 CFX_FloatRect rcAnnot; | 2869 CFX_FloatRect rcAnnot; |
| 2868 pAnnot->GetPDFAnnot()->GetRect(rcAnnot); | 2870 pAnnot->GetPDFAnnot()->GetRect(rcAnnot); |
| 2869 return rcAnnot; | 2871 return rcAnnot; |
| 2870 } | 2872 } |
| OLD | NEW |