DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, FPDF_PAGE page,double page_x, double page_y) { if(!page || !hHandle) return -1; CPDF_Page * pPage = (CPDF_Page*) page; CPDF_InterForm * pInterForm = NULL; pInterForm = new CPDF_InterForm(pPage->m_pDocument,FALSE); if (!pInterForm) return -1; CPDF_FormControl* pFormCtrl = pInterForm->GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y); if(!pFormCtrl) { delete pInterForm; return -1; } CPDF_FormField* pFormField = pFormCtrl->GetField(); if(!pFormField) { delete pInterForm; return -1; } int nType = pFormField->GetFieldType(); delete pInterForm; return nType; }
bool CPDF_InterForm::ValidateFieldName( CFX_WideString& csNewFieldName, int iType, const CPDF_FormField* pExcludedField, const CPDF_FormControl* pExcludedControl) const { if (csNewFieldName.IsEmpty()) return false; int iPos = 0; int iLength = csNewFieldName.GetLength(); CFX_WideString csSub; while (true) { while (iPos < iLength && (csNewFieldName[iPos] == L'.' || csNewFieldName[iPos] == L' ')) { iPos++; } if (iPos < iLength && !csSub.IsEmpty()) csSub += L'.'; while (iPos < iLength && csNewFieldName[iPos] != L'.') csSub += csNewFieldName[iPos++]; for (int i = csSub.GetLength() - 1; i > -1; i--) { if (csSub[i] != L' ' && csSub[i] != L'.') break; csSub.SetAt(i, L'\0'); } size_t dwCount = m_pFieldTree->m_Root.CountFields(); for (size_t m = 0; m < dwCount; ++m) { CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(m); if (!pField) continue; if (pField == pExcludedField) { if (!pExcludedControl || pField->CountControls() < 2) continue; } CFX_WideString csFullName = pField->GetFullName(); int iRet = CompareFieldName(csSub, csFullName); if (iRet == 1) { if (pField->GetFieldType() != iType) return false; } else if (iRet == 2 && csSub == csNewFieldName) { if (csFullName[iPos] == L'.') return false; } else if (iRet == 3 && csSub == csNewFieldName) { if (csNewFieldName[csFullName.GetLength()] == L'.') return false; } } if (iPos >= iLength) break; } if (csSub.IsEmpty()) return false; csNewFieldName = csSub; return true; }
void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict, const CFX_WideString& parent_name, FX_BOOL bNotify, int nLevel) { CFX_WideString name; if (!parent_name.IsEmpty()) name = parent_name + L"."; name += pFieldDict->GetUnicodeTextBy("T"); CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); if (pKids) { for (size_t i = 0; i < pKids->GetCount(); i++) { CPDF_Dictionary* pKid = pKids->GetDictAt(i); if (!pKid) continue; if (nLevel <= nMaxRecursion) FDF_ImportField(pKid, name, bNotify, nLevel + 1); } return; } if (!pFieldDict->KeyExist("V")) return; CPDF_FormField* pField = m_pFieldTree->GetField(name); if (!pField) return; CFX_WideString csWValue = GetFieldValue(*pFieldDict, m_bsEncoding); int iType = pField->GetFieldType(); if (bNotify && m_pFormNotify) { int iRet = 0; if (iType == FIELDTYPE_LISTBOX) iRet = m_pFormNotify->BeforeSelectionChange(pField, csWValue); else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) iRet = m_pFormNotify->BeforeValueChange(pField, csWValue); if (iRet < 0) return; } pField->SetValue(csWValue); CPDF_FormField::Type eType = pField->GetType(); if ((eType == CPDF_FormField::ListBox || eType == CPDF_FormField::ComboBox) && pFieldDict->KeyExist("Opt")) { pField->m_pDict->SetAt( "Opt", pFieldDict->GetDirectObjectBy("Opt")->CloneDirectObject()); } if (bNotify && m_pFormNotify) { if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) m_pFormNotify->AfterCheckedStatusChange(pField); else if (iType == FIELDTYPE_LISTBOX) m_pFormNotify->AfterSelectionChange(pField); else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) m_pFormNotify->AfterValueChange(pField); } }
FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormControl* pControl, CFX_WideString& csNewFieldName) { if (!pControl || csNewFieldName.IsEmpty()) return FALSE; CPDF_FormField* pField = pControl->GetField(); return ValidateFieldName(csNewFieldName, pField->GetFieldType(), pField, pControl); }
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; }
FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormControl* pControl, CFX_WideString& csNewFieldName) { if (pControl == NULL || csNewFieldName.IsEmpty()) { return FALSE; } CPDF_FormField* pField = ((CPDF_FormControl*)pControl)->GetField(); return ValidateFieldName(csNewFieldName, pField->GetFieldType(), pField, pControl); }
FX_BOOL CPDF_InterForm::ValidateFieldName( CFX_WideString& csNewFieldName, int iType, const CPDF_FormField* pExcludedField, const CPDF_FormControl* pExcludedControl) { if (csNewFieldName.IsEmpty()) { return FALSE; } int iPos = 0; int iLength = csNewFieldName.GetLength(); CFX_WideString csSub; while (TRUE) { while (iPos < iLength && (csNewFieldName[iPos] == L'.' || csNewFieldName[iPos] == L' ')) { iPos++; } if (iPos < iLength && !csSub.IsEmpty()) { csSub += L'.'; } while (iPos < iLength && csNewFieldName[iPos] != L'.') { csSub += csNewFieldName[iPos++]; } for (int i = csSub.GetLength() - 1; i > -1; i--) { if (csSub[i] == L' ' || csSub[i] == L'.') { csSub.SetAt(i, L'\0'); } else { break; } } FX_DWORD dwCount = m_pFieldTree->m_Root.CountFields(); for (FX_DWORD m = 0; m < dwCount; m++) { CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(m); if (pField == NULL) { continue; } if (pField == pExcludedField) { if (pExcludedControl != NULL) { if (pField->CountControls() < 2) { continue; } } else { continue; } } CFX_WideString csFullName = pField->GetFullName(); int iRet = CompareFieldName(csSub, csFullName); if (iRet == 1) { if (pField->GetFieldType() != iType) { return FALSE; } } else if (iRet == 2 && csSub == csNewFieldName) { if (csFullName[iPos] == L'.') { return FALSE; } } else if (iRet == 3 && csSub == csNewFieldName) { if (csNewFieldName[csFullName.GetLength()] == L'.') { return FALSE; } } } if (iPos >= iLength) { break; } } if (csSub.IsEmpty()) { return FALSE; } csNewFieldName = csSub; return TRUE; }
void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict, const CFX_WideString& parent_name, FX_BOOL bNotify, int nLevel) { CFX_WideString name; if (!parent_name.IsEmpty()) { name = parent_name + L"."; } name += pFieldDict->GetUnicodeText("T"); CPDF_Array* pKids = pFieldDict->GetArray("Kids"); if (pKids) { for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { CPDF_Dictionary* pKid = pKids->GetDict(i); if (pKid == NULL) { continue; } if (nLevel <= nMaxRecursion) { FDF_ImportField(pKid, name, bNotify, nLevel + 1); } } return; } if (!pFieldDict->KeyExist("V")) { return; } CPDF_FormField* pField = m_pFieldTree->GetField(name); if (pField == NULL) { return; } CFX_WideString csWValue; FPDFDOC_FDF_GetFieldValue(pFieldDict, csWValue, m_bsEncoding); int iType = pField->GetFieldType(); if (bNotify && m_pFormNotify != NULL) { int iRet = 0; if (iType == FIELDTYPE_LISTBOX) { iRet = m_pFormNotify->BeforeSelectionChange(pField, csWValue); } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) { iRet = m_pFormNotify->BeforeValueChange(pField, csWValue); } if (iRet < 0) { return; } } CFX_ByteArray statusArray; if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) { SaveCheckedFieldStatus(pField, statusArray); } pField->SetValue(csWValue); CPDF_FormField::Type eType = pField->GetType(); if ((eType == CPDF_FormField::ListBox || eType == CPDF_FormField::ComboBox) && pFieldDict->KeyExist("Opt")) { pField->m_pDict->SetAt("Opt", pFieldDict->GetElementValue("Opt")->Clone(TRUE)); } if (bNotify && m_pFormNotify != NULL) { if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) { m_pFormNotify->AfterCheckedStatusChange(pField, statusArray); } else if (iType == FIELDTYPE_LISTBOX) { m_pFormNotify->AfterSelectionChange(pField); } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) { m_pFormNotify->AfterValueChange(pField); } } if (CPDF_InterForm::m_bUpdateAP) { pField->UpdateAP(NULL); } }
DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, double page_x, double page_y) { if (!hHandle) return -1; CPDF_Page* pPage = CPDFPageFromFPDFPage(page); if (pPage) { CPDF_InterForm interform(pPage->m_pDocument, FALSE); CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint(pPage, static_cast<FX_FLOAT>(page_x), static_cast<FX_FLOAT>(page_y), nullptr); if (!pFormCtrl) return -1; CPDF_FormField* pFormField = pFormCtrl->GetField(); return pFormField ? pFormField->GetFieldType() : -1; } #ifdef PDF_ENABLE_XFA CPDFXFA_Page* pXFAPage = UnderlyingFromFPDFPage(page); if (!pXFAPage) return -1; IXFA_PageView* pPageView = pXFAPage->GetXFAPageView(); if (!pPageView) return -1; IXFA_DocView* pDocView = pPageView->GetDocView(); if (!pDocView) return -1; IXFA_WidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler(); if (!pWidgetHandler) return -1; std::unique_ptr<IXFA_WidgetIterator, ReleaseDeleter<IXFA_WidgetIterator>> pWidgetIterator(pPageView->CreateWidgetIterator( XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Viewable | XFA_WIDGETFILTER_AllType)); if (!pWidgetIterator) return -1; IXFA_Widget* pXFAAnnot = pWidgetIterator->MoveToNext(); while (pXFAAnnot) { CFX_RectF rcBBox; pWidgetHandler->GetBBox(pXFAAnnot, rcBBox, 0); CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, rcBBox.top + rcBBox.height); rcWidget.left -= 1.0f; rcWidget.right += 1.0f; rcWidget.bottom -= 1.0f; rcWidget.top += 1.0f; if (rcWidget.Contains(static_cast<FX_FLOAT>(page_x), static_cast<FX_FLOAT>(page_y))) { return FPDF_FORMFIELD_XFA; } pXFAAnnot = pWidgetIterator->MoveToNext(); } #endif // PDF_ENABLE_XFA return -1; }