FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) { ASSERT(action.GetDict()); CPDF_Dictionary* pActionDict = action.GetDict(); if (!pActionDict->KeyExist("Fields")) return m_pInterForm->ResetForm(true); CPDF_ActionFields af(&action); uint32_t dwFlags = action.GetFlags(); std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), true); }
bool CPDFSDK_ActionHandler::ExecuteDocumentPageAction( const CPDF_Action& action, CPDF_AAction::AActionType type, CPDFSDK_FormFillEnvironment* pFormFillEnv, std::set<CPDF_Dictionary*>* visited) { CPDF_Dictionary* pDict = action.GetDict(); if (pdfium::ContainsKey(*visited, pDict)) return false; visited->insert(pDict); ASSERT(pFormFillEnv); if (action.GetType() == CPDF_Action::JavaScript) { if (pFormFillEnv->IsJSInitiated()) { CFX_WideString swJS = action.GetJavaScript(); if (!swJS.IsEmpty()) { RunDocumentPageJavaScript(pFormFillEnv, type, swJS); } } } else { DoAction_NoJs(action, pFormFillEnv); } if (!IsValidDocView(pFormFillEnv)) return false; for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { CPDF_Action subaction = action.GetSubAction(i); if (!ExecuteDocumentPageAction(subaction, type, pFormFillEnv, visited)) return false; } return true; }
FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentOpenAction( const CPDF_Action& action, CPDFSDK_Document* pDocument, std::set<CPDF_Dictionary*>* visited) { CPDF_Dictionary* pDict = action.GetDict(); if (pdfium::ContainsKey(*visited, pDict)) return FALSE; visited->insert(pDict); CPDFDoc_Environment* pEnv = pDocument->GetEnv(); ASSERT(pEnv); if (action.GetType() == CPDF_Action::JavaScript) { if (pEnv->IsJSInitiated()) { CFX_WideString swJS = action.GetJavaScript(); if (!swJS.IsEmpty()) { RunDocumentOpenJavaScript(pDocument, L"", swJS); } } } else { DoAction_NoJs(action, pDocument); } for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { CPDF_Action subaction = action.GetSubAction(i); if (!ExecuteDocumentOpenAction(subaction, pDocument, visited)) return FALSE; } return TRUE; }
FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action) { ASSERT(action.GetDict()); CPDF_ActionFields af(&action); std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); bool bHide = action.GetHideStatus(); FX_BOOL bChanged = FALSE; for (CPDF_FormField* pField : fields) { for (int i = 0, sz = pField->CountControls(); i < sz; ++i) { CPDF_FormControl* pControl = pField->GetControl(i); ASSERT(pControl); if (CPDFSDK_Widget* pWidget = GetWidget(pControl, false)) { uint32_t nFlags = pWidget->GetFlags(); nFlags &= ~ANNOTFLAG_INVISIBLE; nFlags &= ~ANNOTFLAG_NOVIEW; if (bHide) nFlags |= ANNOTFLAG_HIDDEN; else nFlags &= ~ANNOTFLAG_HIDDEN; pWidget->SetFlags(nFlags); pWidget->GetPageView()->UpdateView(pWidget); bChanged = TRUE; } } } return bChanged; }
FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentOpenAction( const CPDF_Action& action, CPDFSDK_Document* pDocument, CFX_PtrList& list) { CPDF_Dictionary* pDict = action.GetDict(); if (list.Find(pDict)) return FALSE; list.AddTail(pDict); CPDFDoc_Environment* pEnv = pDocument->GetEnv(); ASSERT(pEnv); if (action.GetType() == CPDF_Action::JavaScript) { if (pEnv->IsJSInitiated()) { CFX_WideString swJS = action.GetJavaScript(); if (!swJS.IsEmpty()) { RunDocumentOpenJavaScript(pDocument, L"", swJS); } } } else { DoAction_NoJs(action, pDocument); } for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { CPDF_Action subaction = action.GetSubAction(i); if (!ExecuteDocumentOpenAction(subaction, pDocument, list)) return FALSE; } return TRUE; }
void CPDFSDK_ActionHandler::DoAction_GoTo( CPDFSDK_FormFillEnvironment* pFormFillEnv, const CPDF_Action& action) { ASSERT(action.GetDict()); CPDF_Document* pPDFDocument = pFormFillEnv->GetPDFDocument(); ASSERT(pPDFDocument); CPDF_Dest MyDest = action.GetDest(pPDFDocument); int nPageIndex = MyDest.GetPageIndex(pPDFDocument); int nFitType = MyDest.GetZoomMode(); const CPDF_Array* pMyArray = ToArray(MyDest.GetObject()); float* pPosAry = nullptr; int sizeOfAry = 0; if (pMyArray) { pPosAry = new float[pMyArray->GetCount()]; int j = 0; for (size_t i = 2; i < pMyArray->GetCount(); i++) { pPosAry[j++] = pMyArray->GetFloatAt(i); } sizeOfAry = j; } pFormFillEnv->DoGoToAction(nPageIndex, nFitType, pPosAry, sizeOfAry); delete[] pPosAry; }
void CPDFSDK_ActionHandler::DoAction_URI( CPDFSDK_FormFillEnvironment* pFormFillEnv, const CPDF_Action& action) { ASSERT(action.GetDict()); CFX_ByteString sURI = action.GetURI(pFormFillEnv->GetPDFDocument()); pFormFillEnv->DoURIAction(sURI.c_str()); }
void CPDFSDK_ActionHandler::DoAction_Named( CPDFSDK_FormFillEnvironment* pFormFillEnv, const CPDF_Action& action) { ASSERT(action.GetDict()); CFX_ByteString csName = action.GetNamedAction(); pFormFillEnv->ExecuteNamedAction(csName.c_str()); }
void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) { CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); ASSERT(pEnv); if (!pEnv->IsJSInitiated()) return; if (m_bBusy) return; m_bBusy = TRUE; if (!IsCalculateEnabled()) { m_bBusy = FALSE; return; } IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); pRuntime->SetReaderDocument(m_pDocument); int nSize = m_pInterForm->CountFieldsInCalculationOrder(); for (int i = 0; i < nSize; i++) { CPDF_FormField* pField = m_pInterForm->GetFieldInCalculationOrder(i); if (!pField) continue; int nType = pField->GetFieldType(); if (nType != FIELDTYPE_COMBOBOX && nType != FIELDTYPE_TEXTFIELD) continue; CPDF_AAction aAction = pField->GetAdditionalAction(); if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::Calculate)) continue; CPDF_Action action = aAction.GetAction(CPDF_AAction::Calculate); if (!action.GetDict()) continue; CFX_WideString csJS = action.GetJavaScript(); if (csJS.IsEmpty()) continue; IJS_Context* pContext = pRuntime->NewContext(); CFX_WideString sOldValue = pField->GetValue(); CFX_WideString sValue = sOldValue; FX_BOOL bRC = TRUE; pContext->OnField_Calculate(pFormField, pField, sValue, bRC); CFX_WideString sInfo; FX_BOOL bRet = pContext->RunScript(csJS, &sInfo); pRuntime->ReleaseContext(pContext); if (bRet && bRC && sValue.Compare(sOldValue) != 0) pField->SetValue(sValue, TRUE); } m_bBusy = FALSE; }
void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) { ASSERT(action); if ((CPDF_Action&)action != CPDF_Action(m_pAnnot->GetAnnotDict()->GetDictBy("A"))) { CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); CPDF_Dictionary* pDict = action.GetDict(); if (pDict && pDict->GetObjNum() == 0) { pDoc->AddIndirectObject(pDict); } m_pAnnot->GetAnnotDict()->SetAtReference("A", pDoc, pDict->GetObjNum()); } }
DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, FPDF_LINK pDict) { if (!pDict) return nullptr; CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); if (!pDoc) return nullptr; CPDF_Link link(ToDictionary(static_cast<CPDF_Object*>(pDict))); FPDF_DEST dest = link.GetDest(pDoc).GetObject(); if (dest) return dest; // If this link is not directly associated with a dest, we try to get action CPDF_Action action = link.GetAction(); if (!action.GetDict()) return nullptr; return action.GetDest(pDoc).GetObject(); }
FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFLink_GetDest(FPDF_DOCUMENT document, FPDF_LINK pDict) { if (!pDict) return nullptr; CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); if (!pDoc) return nullptr; CPDF_Link link(CPDFDictionaryFromFPDFLink(pDict)); FPDF_DEST dest = FPDFDestFromCPDFArray(link.GetDest(pDoc).GetArray()); if (dest) return dest; // If this link is not directly associated with a dest, we try to get action CPDF_Action action = link.GetAction(); if (!action.GetDict()) return nullptr; return FPDFDestFromCPDFArray(action.GetDest(pDoc).GetArray()); }
CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField, FX_BOOL& bFormatted) { CFX_WideString sValue = pFormField->GetValue(); CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); ASSERT(pEnv); if (!pEnv->IsJSInitiated()) { bFormatted = FALSE; return sValue; } IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); pRuntime->SetReaderDocument(m_pDocument); if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX && pFormField->CountSelectedItems() > 0) { int index = pFormField->GetSelectedIndex(0); if (index >= 0) sValue = pFormField->GetOptionLabel(index); } bFormatted = FALSE; CPDF_AAction aAction = pFormField->GetAdditionalAction(); if (aAction.GetDict() && aAction.ActionExist(CPDF_AAction::Format)) { CPDF_Action action = aAction.GetAction(CPDF_AAction::Format); if (action.GetDict()) { CFX_WideString script = action.GetJavaScript(); if (!script.IsEmpty()) { CFX_WideString Value = sValue; IJS_Context* pContext = pRuntime->NewContext(); pContext->OnField_Format(pFormField, Value, TRUE); CFX_WideString sInfo; FX_BOOL bRet = pContext->RunScript(script, &sInfo); pRuntime->ReleaseContext(pContext); if (bRet) { sValue = Value; bFormatted = TRUE; } } } } return sValue; }
FX_BOOL CPDFSDK_ActionHandler::ExecuteBookMark(const CPDF_Action& action, CPDFSDK_Document* pDocument, CPDF_Bookmark* pBookmark, CFX_PtrList& list) { ASSERT(pDocument != NULL); CPDF_Dictionary* pDict = action.GetDict(); if (list.Find(pDict)) return FALSE; list.AddTail(pDict); CPDFDoc_Environment* pEnv = pDocument->GetEnv(); ASSERT(pEnv); if (action.GetType() == CPDF_Action::JavaScript) { if (pEnv->IsJSInitiated()) { CFX_WideString swJS = action.GetJavaScript(); if (!swJS.IsEmpty()) { IJS_Runtime* pRuntime = pDocument->GetJsRuntime(); pRuntime->SetReaderDocument(pDocument); IJS_Context* pContext = pRuntime->NewContext(); pContext->OnBookmark_MouseUp(pBookmark); CFX_WideString csInfo; FX_BOOL bRet = pContext->RunScript(swJS, &csInfo); if (!bRet) { // FIXME: return error. } pRuntime->ReleaseContext(pContext); } } } else { DoAction_NoJs(action, pDocument); } for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { CPDF_Action subaction = action.GetSubAction(i); if (!ExecuteBookMark(subaction, pDocument, pBookmark, list)) return FALSE; } return TRUE; }
DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { if (!pDict) return nullptr; CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); if (!pDoc) return nullptr; CPDF_Bookmark bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict))); CPDF_Dest dest = bookmark.GetDest(pDoc); if (dest.GetObject()) return dest.GetObject(); // If this bookmark is not directly associated with a dest, we try to get // action CPDF_Action action = bookmark.GetAction(); if (!action.GetDict()) return nullptr; return action.GetDest(pDoc).GetObject(); }
FX_BOOL CPDFSDK_ActionHandler::ExecuteScreenAction( const CPDF_Action& action, CPDF_AAction::AActionType type, CPDFSDK_Document* pDocument, CPDFSDK_Annot* pScreen, std::set<CPDF_Dictionary*>* visited) { CPDF_Dictionary* pDict = action.GetDict(); if (pdfium::ContainsKey(*visited, pDict)) return FALSE; visited->insert(pDict); CPDFDoc_Environment* pEnv = pDocument->GetEnv(); ASSERT(pEnv); if (action.GetType() == CPDF_Action::JavaScript) { if (pEnv->IsJSInitiated()) { CFX_WideString swJS = action.GetJavaScript(); if (!swJS.IsEmpty()) { IJS_Runtime* pRuntime = pDocument->GetJsRuntime(); pRuntime->SetReaderDocument(pDocument); IJS_Context* pContext = pRuntime->NewContext(); CFX_WideString csInfo; FX_BOOL bRet = pContext->RunScript(swJS, &csInfo); if (!bRet) { // FIXME: return error. } pRuntime->ReleaseContext(pContext); } } } else { DoAction_NoJs(action, pDocument); } for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { CPDF_Action subaction = action.GetSubAction(i); if (!ExecuteScreenAction(subaction, type, pDocument, pScreen, visited)) return FALSE; } return TRUE; }
FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFBookmark_GetDest(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); if (!pDoc) return nullptr; if (!pDict) return nullptr; CPDF_Bookmark bookmark(CPDFDictionaryFromFPDFBookmark(pDict)); CPDF_Dest dest = bookmark.GetDest(pDoc); if (dest.GetArray()) return FPDFDestFromCPDFArray(dest.GetArray()); // If this bookmark is not directly associated with a dest, we try to get // action CPDF_Action action = bookmark.GetAction(); if (!action.GetDict()) return nullptr; return FPDFDestFromCPDFArray(action.GetDest(pDoc).GetArray()); }
FX_BOOL CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, const CFX_WideString& csValue) { CPDF_AAction aAction = pFormField->GetAdditionalAction(); if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::Validate)) return TRUE; CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate); if (!action.GetDict()) return TRUE; CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); PDFSDK_FieldAction fa; fa.bModifier = pEnv->IsCTRLKeyDown(0); fa.bShift = pEnv->IsSHIFTKeyDown(0); fa.sValue = csValue; pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate, m_pDocument, pFormField, fa); return fa.bRC; }
bool CPDFSDK_ActionHandler::ExecuteBookMark( const CPDF_Action& action, CPDFSDK_FormFillEnvironment* pFormFillEnv, CPDF_Bookmark* pBookmark, std::set<CPDF_Dictionary*>* visited) { CPDF_Dictionary* pDict = action.GetDict(); if (pdfium::ContainsKey(*visited, pDict)) return false; visited->insert(pDict); ASSERT(pFormFillEnv); if (action.GetType() == CPDF_Action::JavaScript) { if (pFormFillEnv->IsJSInitiated()) { CFX_WideString swJS = action.GetJavaScript(); if (!swJS.IsEmpty()) { IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime(); IJS_Context* pContext = pRuntime->NewContext(); pContext->OnBookmark_MouseUp(pBookmark); CFX_WideString csInfo; bool bRet = pContext->RunScript(swJS, &csInfo); if (!bRet) { // FIXME: return error. } pRuntime->ReleaseContext(pContext); } } } else { DoAction_NoJs(action, pFormFillEnv); } for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { CPDF_Action subaction = action.GetSubAction(i); if (!ExecuteBookMark(subaction, pFormFillEnv, pBookmark, visited)) return false; } return true; }
FX_BOOL CPDFSDK_ActionHandler::ExecuteFieldAction( const CPDF_Action& action, CPDF_AAction::AActionType type, CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, PDFSDK_FieldAction& data, CFX_PtrList& list) { ASSERT(pDocument != NULL); CPDF_Dictionary* pDict = action.GetDict(); if (list.Find(pDict)) return FALSE; list.AddTail(pDict); CPDFDoc_Environment* pEnv = pDocument->GetEnv(); ASSERT(pEnv); if (action.GetType() == CPDF_Action::JavaScript) { if (pEnv->IsJSInitiated()) { CFX_WideString swJS = action.GetJavaScript(); if (!swJS.IsEmpty()) { RunFieldJavaScript(pDocument, pFormField, type, data, swJS); if (!IsValidField(pDocument, pFormField->GetFieldDict())) return FALSE; } } } else { DoAction_NoJs(action, pDocument); } for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) { CPDF_Action subaction = action.GetSubAction(i); if (!ExecuteFieldAction(subaction, type, pDocument, pFormField, data, list)) return FALSE; } return TRUE; }
FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action) { CFX_WideString sDestination = action.GetFilePath(); if (sDestination.IsEmpty()) return FALSE; CPDF_Dictionary* pActionDict = action.GetDict(); if (pActionDict->KeyExist("Fields")) { CPDF_ActionFields af(&action); uint32_t dwFlags = action.GetFlags(); std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); if (!fields.empty()) { bool bIncludeOrExclude = !(dwFlags & 0x01); if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude)) return FALSE; return SubmitFields(sDestination, fields, bIncludeOrExclude, false); } } if (m_pInterForm->CheckRequiredFields(nullptr, true)) return FALSE; return SubmitForm(sDestination, FALSE); }