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 1893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1904 } | 1904 } |
1905 | 1905 |
1906 if (nRet == XFA_EVENTERROR_Sucess) | 1906 if (nRet == XFA_EVENTERROR_Sucess) |
1907 return TRUE; | 1907 return TRUE; |
1908 } | 1908 } |
1909 } | 1909 } |
1910 } | 1910 } |
1911 #endif // PDF_ENABLE_XFA | 1911 #endif // PDF_ENABLE_XFA |
1912 | 1912 |
1913 CPDF_Action action = GetAAction(type); | 1913 CPDF_Action action = GetAAction(type); |
1914 if (action && action.GetType() != CPDF_Action::Unknown) { | 1914 if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) { |
1915 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); | 1915 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
1916 return pActionHandler->DoAction_Field(action, type, pDocument, | 1916 return pActionHandler->DoAction_Field(action, type, pDocument, |
1917 GetFormField(), data); | 1917 GetFormField(), data); |
1918 } | 1918 } |
1919 return FALSE; | 1919 return FALSE; |
1920 } | 1920 } |
1921 | 1921 |
1922 CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) { | 1922 CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) { |
1923 switch (eAAT) { | 1923 switch (eAAT) { |
1924 case CPDF_AAction::CursorEnter: | 1924 case CPDF_AAction::CursorEnter: |
1925 case CPDF_AAction::CursorExit: | 1925 case CPDF_AAction::CursorExit: |
1926 case CPDF_AAction::ButtonDown: | 1926 case CPDF_AAction::ButtonDown: |
1927 case CPDF_AAction::ButtonUp: | 1927 case CPDF_AAction::ButtonUp: |
1928 case CPDF_AAction::GetFocus: | 1928 case CPDF_AAction::GetFocus: |
1929 case CPDF_AAction::LoseFocus: | 1929 case CPDF_AAction::LoseFocus: |
1930 case CPDF_AAction::PageOpen: | 1930 case CPDF_AAction::PageOpen: |
1931 case CPDF_AAction::PageClose: | 1931 case CPDF_AAction::PageClose: |
1932 case CPDF_AAction::PageVisible: | 1932 case CPDF_AAction::PageVisible: |
1933 case CPDF_AAction::PageInvisible: | 1933 case CPDF_AAction::PageInvisible: |
1934 return CPDFSDK_BAAnnot::GetAAction(eAAT); | 1934 return CPDFSDK_BAAnnot::GetAAction(eAAT); |
1935 | 1935 |
1936 case CPDF_AAction::KeyStroke: | 1936 case CPDF_AAction::KeyStroke: |
1937 case CPDF_AAction::Format: | 1937 case CPDF_AAction::Format: |
1938 case CPDF_AAction::Validate: | 1938 case CPDF_AAction::Validate: |
1939 case CPDF_AAction::Calculate: { | 1939 case CPDF_AAction::Calculate: { |
1940 CPDF_FormField* pField = GetFormField(); | 1940 CPDF_FormField* pField = GetFormField(); |
1941 if (CPDF_AAction aa = pField->GetAdditionalAction()) | 1941 if (pField->GetAdditionalAction().GetDict()) |
1942 return aa.GetAction(eAAT); | 1942 return pField->GetAdditionalAction().GetAction(eAAT); |
1943 return CPDFSDK_BAAnnot::GetAAction(eAAT); | 1943 return CPDFSDK_BAAnnot::GetAAction(eAAT); |
1944 } | 1944 } |
1945 default: | 1945 default: |
1946 break; | 1946 break; |
1947 } | 1947 } |
1948 | 1948 |
1949 return CPDF_Action(); | 1949 return CPDF_Action(); |
1950 } | 1950 } |
1951 | 1951 |
1952 CFX_WideString CPDFSDK_Widget::GetAlternateName() const { | 1952 CFX_WideString CPDFSDK_Widget::GetAlternateName() const { |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2192 IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); | 2192 IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); |
2193 pRuntime->SetReaderDocument(m_pDocument); | 2193 pRuntime->SetReaderDocument(m_pDocument); |
2194 | 2194 |
2195 int nSize = m_pInterForm->CountFieldsInCalculationOrder(); | 2195 int nSize = m_pInterForm->CountFieldsInCalculationOrder(); |
2196 for (int i = 0; i < nSize; i++) { | 2196 for (int i = 0; i < nSize; i++) { |
2197 if (CPDF_FormField* pField = | 2197 if (CPDF_FormField* pField = |
2198 m_pInterForm->GetFieldInCalculationOrder(i)) { | 2198 m_pInterForm->GetFieldInCalculationOrder(i)) { |
2199 int nType = pField->GetFieldType(); | 2199 int nType = pField->GetFieldType(); |
2200 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { | 2200 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { |
2201 CPDF_AAction aAction = pField->GetAdditionalAction(); | 2201 CPDF_AAction aAction = pField->GetAdditionalAction(); |
2202 if (aAction && aAction.ActionExist(CPDF_AAction::Calculate)) { | 2202 if (aAction.GetDict() && |
| 2203 aAction.ActionExist(CPDF_AAction::Calculate)) { |
2203 CPDF_Action action = aAction.GetAction(CPDF_AAction::Calculate); | 2204 CPDF_Action action = aAction.GetAction(CPDF_AAction::Calculate); |
2204 if (action) { | 2205 if (action.GetDict()) { |
2205 CFX_WideString csJS = action.GetJavaScript(); | 2206 CFX_WideString csJS = action.GetJavaScript(); |
2206 if (!csJS.IsEmpty()) { | 2207 if (!csJS.IsEmpty()) { |
2207 IJS_Context* pContext = pRuntime->NewContext(); | 2208 IJS_Context* pContext = pRuntime->NewContext(); |
2208 CFX_WideString sOldValue = pField->GetValue(); | 2209 CFX_WideString sOldValue = pField->GetValue(); |
2209 CFX_WideString sValue = sOldValue; | 2210 CFX_WideString sValue = sOldValue; |
2210 FX_BOOL bRC = TRUE; | 2211 FX_BOOL bRC = TRUE; |
2211 pContext->OnField_Calculate(pFormField, pField, sValue, bRC); | 2212 pContext->OnField_Calculate(pFormField, pField, sValue, bRC); |
2212 | 2213 |
2213 CFX_WideString sInfo; | 2214 CFX_WideString sInfo; |
2214 FX_BOOL bRet = pContext->RunScript(csJS, &sInfo); | 2215 FX_BOOL bRet = pContext->RunScript(csJS, &sInfo); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2248 if (pFormField->CountSelectedItems() > 0) { | 2249 if (pFormField->CountSelectedItems() > 0) { |
2249 int index = pFormField->GetSelectedIndex(0); | 2250 int index = pFormField->GetSelectedIndex(0); |
2250 if (index >= 0) | 2251 if (index >= 0) |
2251 sValue = pFormField->GetOptionLabel(index); | 2252 sValue = pFormField->GetOptionLabel(index); |
2252 } | 2253 } |
2253 } | 2254 } |
2254 | 2255 |
2255 bFormated = FALSE; | 2256 bFormated = FALSE; |
2256 | 2257 |
2257 CPDF_AAction aAction = pFormField->GetAdditionalAction(); | 2258 CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
2258 if (aAction && aAction.ActionExist(CPDF_AAction::Format)) { | 2259 if (aAction.GetDict() && aAction.ActionExist(CPDF_AAction::Format)) { |
2259 CPDF_Action action = aAction.GetAction(CPDF_AAction::Format); | 2260 CPDF_Action action = aAction.GetAction(CPDF_AAction::Format); |
2260 if (action) { | 2261 if (action.GetDict()) { |
2261 CFX_WideString script = action.GetJavaScript(); | 2262 CFX_WideString script = action.GetJavaScript(); |
2262 if (!script.IsEmpty()) { | 2263 if (!script.IsEmpty()) { |
2263 CFX_WideString Value = sValue; | 2264 CFX_WideString Value = sValue; |
2264 | 2265 |
2265 IJS_Context* pContext = pRuntime->NewContext(); | 2266 IJS_Context* pContext = pRuntime->NewContext(); |
2266 pContext->OnField_Format(pFormField, Value, TRUE); | 2267 pContext->OnField_Format(pFormField, Value, TRUE); |
2267 | 2268 |
2268 CFX_WideString sInfo; | 2269 CFX_WideString sInfo; |
2269 FX_BOOL bRet = pContext->RunScript(script, &sInfo); | 2270 FX_BOOL bRet = pContext->RunScript(script, &sInfo); |
2270 pRuntime->ReleaseContext(pContext); | 2271 pRuntime->ReleaseContext(pContext); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2305 | 2306 |
2306 pEnv->FFI_Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right, | 2307 pEnv->FFI_Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right, |
2307 rcBBox.bottom); | 2308 rcBBox.bottom); |
2308 } | 2309 } |
2309 } | 2310 } |
2310 } | 2311 } |
2311 | 2312 |
2312 FX_BOOL CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, | 2313 FX_BOOL CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, |
2313 const CFX_WideString& csValue) { | 2314 const CFX_WideString& csValue) { |
2314 CPDF_AAction aAction = pFormField->GetAdditionalAction(); | 2315 CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
2315 if (!aAction || !aAction.ActionExist(CPDF_AAction::KeyStroke)) | 2316 if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::KeyStroke)) |
2316 return TRUE; | 2317 return TRUE; |
2317 | 2318 |
2318 CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke); | 2319 CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke); |
2319 if (!action) | 2320 if (!action.GetDict()) |
2320 return TRUE; | 2321 return TRUE; |
2321 | 2322 |
2322 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); | 2323 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
2323 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); | 2324 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
2324 PDFSDK_FieldAction fa; | 2325 PDFSDK_FieldAction fa; |
2325 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); | 2326 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); |
2326 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); | 2327 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); |
2327 fa.sValue = csValue; | 2328 fa.sValue = csValue; |
2328 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke, | 2329 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke, |
2329 m_pDocument, pFormField, fa); | 2330 m_pDocument, pFormField, fa); |
2330 return fa.bRC; | 2331 return fa.bRC; |
2331 } | 2332 } |
2332 | 2333 |
2333 FX_BOOL CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, | 2334 FX_BOOL CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, |
2334 const CFX_WideString& csValue) { | 2335 const CFX_WideString& csValue) { |
2335 CPDF_AAction aAction = pFormField->GetAdditionalAction(); | 2336 CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
2336 if (!aAction || !aAction.ActionExist(CPDF_AAction::Validate)) | 2337 if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::Validate)) |
2337 return TRUE; | 2338 return TRUE; |
2338 | 2339 |
2339 CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate); | 2340 CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate); |
2340 if (!action) | 2341 if (!action.GetDict()) |
2341 return TRUE; | 2342 return TRUE; |
2342 | 2343 |
2343 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); | 2344 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
2344 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); | 2345 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
2345 PDFSDK_FieldAction fa; | 2346 PDFSDK_FieldAction fa; |
2346 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); | 2347 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); |
2347 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); | 2348 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); |
2348 fa.sValue = csValue; | 2349 fa.sValue = csValue; |
2349 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate, | 2350 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate, |
2350 m_pDocument, pFormField, fa); | 2351 m_pDocument, pFormField, fa); |
2351 return fa.bRC; | 2352 return fa.bRC; |
2352 } | 2353 } |
2353 | 2354 |
2354 FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action) { | 2355 FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action) { |
2355 ASSERT(action); | 2356 ASSERT(action.GetDict()); |
2356 | 2357 |
2357 CPDF_ActionFields af = action.GetWidgets(); | 2358 CPDF_ActionFields af(&action); |
2358 std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); | 2359 std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); |
2359 std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); | 2360 std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); |
2360 | 2361 |
2361 FX_BOOL bHide = action.GetHideStatus(); | 2362 FX_BOOL bHide = action.GetHideStatus(); |
2362 FX_BOOL bChanged = FALSE; | 2363 FX_BOOL bChanged = FALSE; |
2363 | 2364 |
2364 for (CPDF_FormField* pField : fields) { | 2365 for (CPDF_FormField* pField : fields) { |
2365 for (int i = 0, sz = pField->CountControls(); i < sz; ++i) { | 2366 for (int i = 0, sz = pField->CountControls(); i < sz; ++i) { |
2366 CPDF_FormControl* pControl = pField->GetControl(i); | 2367 CPDF_FormControl* pControl = pField->GetControl(i); |
2367 ASSERT(pControl); | 2368 ASSERT(pControl); |
(...skipping 16 matching lines...) Expand all Loading... |
2384 return bChanged; | 2385 return bChanged; |
2385 } | 2386 } |
2386 | 2387 |
2387 FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action) { | 2388 FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action) { |
2388 CFX_WideString sDestination = action.GetFilePath(); | 2389 CFX_WideString sDestination = action.GetFilePath(); |
2389 if (sDestination.IsEmpty()) | 2390 if (sDestination.IsEmpty()) |
2390 return FALSE; | 2391 return FALSE; |
2391 | 2392 |
2392 CPDF_Dictionary* pActionDict = action.GetDict(); | 2393 CPDF_Dictionary* pActionDict = action.GetDict(); |
2393 if (pActionDict->KeyExist("Fields")) { | 2394 if (pActionDict->KeyExist("Fields")) { |
2394 CPDF_ActionFields af = action.GetWidgets(); | 2395 CPDF_ActionFields af(&action); |
2395 FX_DWORD dwFlags = action.GetFlags(); | 2396 FX_DWORD dwFlags = action.GetFlags(); |
2396 std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); | 2397 std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); |
2397 std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); | 2398 std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); |
2398 if (!fields.empty()) { | 2399 if (!fields.empty()) { |
2399 bool bIncludeOrExclude = !(dwFlags & 0x01); | 2400 bool bIncludeOrExclude = !(dwFlags & 0x01); |
2400 if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude)) | 2401 if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude)) |
2401 return FALSE; | 2402 return FALSE; |
2402 | 2403 |
2403 return SubmitFields(sDestination, fields, bIncludeOrExclude, FALSE); | 2404 return SubmitFields(sDestination, fields, bIncludeOrExclude, FALSE); |
2404 } | 2405 } |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2551 if (!pFDF) | 2552 if (!pFDF) |
2552 return FALSE; | 2553 return FALSE; |
2553 | 2554 |
2554 FX_BOOL bRet = pFDF->WriteBuf(textBuf); | 2555 FX_BOOL bRet = pFDF->WriteBuf(textBuf); |
2555 delete pFDF; | 2556 delete pFDF; |
2556 | 2557 |
2557 return bRet; | 2558 return bRet; |
2558 } | 2559 } |
2559 | 2560 |
2560 FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) { | 2561 FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) { |
2561 ASSERT(action); | 2562 ASSERT(action.GetDict()); |
2562 | 2563 |
2563 CPDF_Dictionary* pActionDict = action.GetDict(); | 2564 CPDF_Dictionary* pActionDict = action.GetDict(); |
2564 if (!pActionDict->KeyExist("Fields")) | 2565 if (!pActionDict->KeyExist("Fields")) |
2565 return m_pInterForm->ResetForm(true); | 2566 return m_pInterForm->ResetForm(true); |
2566 | 2567 |
2567 CPDF_ActionFields af = action.GetWidgets(); | 2568 CPDF_ActionFields af(&action); |
2568 FX_DWORD dwFlags = action.GetFlags(); | 2569 FX_DWORD dwFlags = action.GetFlags(); |
2569 | 2570 |
2570 std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); | 2571 std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); |
2571 std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); | 2572 std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); |
2572 return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), true); | 2573 return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), true); |
2573 } | 2574 } |
2574 | 2575 |
2575 FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action) { | 2576 FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action) { |
2576 return FALSE; | 2577 return FALSE; |
2577 } | 2578 } |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2857 break; | 2858 break; |
2858 } | 2859 } |
2859 } | 2860 } |
2860 } | 2861 } |
2861 | 2862 |
2862 CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) { | 2863 CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) { |
2863 CFX_FloatRect rcAnnot; | 2864 CFX_FloatRect rcAnnot; |
2864 pAnnot->GetPDFAnnot()->GetRect(rcAnnot); | 2865 pAnnot->GetPDFAnnot()->GetRect(rcAnnot); |
2865 return rcAnnot; | 2866 return rcAnnot; |
2866 } | 2867 } |
OLD | NEW |