void CFFL_Button::OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, const CFX_Matrix& mtUser2Device) { ASSERT(pPageView); CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot); CPDF_FormControl* pCtrl = pWidget->GetFormControl(); if (pCtrl->GetHighlightingMode() != CPDF_FormControl::Push) { pWidget->DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::Normal, nullptr); return; } if (m_bMouseDown) { if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Down)) { pWidget->DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::Down, nullptr); } else { pWidget->DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::Normal, nullptr); } return; } if (m_bMouseIn) { if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Rollover)) { pWidget->DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::Rollover, nullptr); } else { pWidget->DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::Normal, nullptr); } return; } pWidget->DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::Normal, nullptr); }
bool CFFL_CheckBox::OnChar(CPDFSDK_Annot* pAnnot, uint32_t nChar, uint32_t nFlags) { switch (nChar) { case FWL_VKEY_Return: case FWL_VKEY_Space: { CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); ASSERT(pPageView); CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget.Get()); if (m_pFormFillEnv->GetInteractiveFormFiller()->OnButtonUp( &pObserved, pPageView, nFlags)) { if (!pObserved) m_pWidget = nullptr; return true; } if (!pObserved) { m_pWidget = nullptr; return true; } CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); CPWL_CheckBox* pWnd = GetCheckBox(pPageView, true); if (pWnd) { CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot); pWnd->SetCheck(!pWidget->IsChecked()); } return CommitData(pPageView, nFlags); } default: return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); } }
bool CFFL_InteractiveFormFiller::OnValidate(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, uint32_t nFlag) { if (m_bNotifying) return true; CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get()); if (!pWidget->GetAAction(CPDF_AAction::kValidate).GetDict()) return true; ASSERT(pPageView); m_bNotifying = true; pWidget->ClearAppModified(); CPDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag); fa.bKeyDown = true; fa.bRC = true; CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false); pFormFiller->GetActionData(pPageView, CPDF_AAction::kValidate, fa); pFormFiller->SaveState(pPageView); pWidget->OnAAction(CPDF_AAction::kValidate, &fa, pPageView); if (!pAnnot->HasObservable()) return true; m_bNotifying = false; return fa.bRC; }
bool CFFL_InteractiveFormFiller::OnPostOpen(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, uint32_t nFlag) { if (m_bNotifying) return false; CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get()); if (!pWidget->HasXFAAAction(PDFSDK_XFA_PostOpen)) return false; m_bNotifying = true; uint32_t nAge = pWidget->GetAppearanceAge(); uint32_t nValueAge = pWidget->GetValueAge(); CPDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag); pWidget->OnXFAAAction(PDFSDK_XFA_PostOpen, &fa, pPageView); m_bNotifying = false; if (!pAnnot->HasObservable() || !IsValidAnnot(pPageView, pWidget)) return true; if (nAge == pWidget->GetAppearanceAge()) return false; if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge()); return true; }
bool CFFL_InteractiveFormFiller::OnKillFocus(CPDFSDK_Annot::ObservedPtr* pAnnot, uint32_t nFlag) { if (!pAnnot->HasObservable()) return false; ASSERT((*pAnnot)->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot->Get(), false); if (!pFormFiller) return true; pFormFiller->KillFocusForAnnot(pAnnot->Get(), nFlag); if (!pAnnot->HasObservable()) return false; if (m_bNotifying) return true; CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get()); if (!pWidget->GetAAction(CPDF_AAction::kLoseFocus).GetDict()) return true; m_bNotifying = true; pWidget->ClearAppModified(); CPDFSDK_PageView* pPageView = pWidget->GetPageView(); ASSERT(pPageView); CPDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag); pFormFiller->GetActionData(pPageView, CPDF_AAction::kLoseFocus, fa); pWidget->OnAAction(CPDF_AAction::kLoseFocus, &fa, pPageView); m_bNotifying = false; return pAnnot->HasObservable(); }
void CFFL_InteractiveFormFiller::OnMouseExit(CPDFSDK_PageView* pPageView, CPDFSDK_Annot::ObservedPtr* pAnnot, uint32_t nFlag) { ASSERT((*pAnnot)->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); if (!m_bNotifying) { CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get()); if (pWidget->GetAAction(CPDF_AAction::kCursorExit).GetDict()) { m_bNotifying = true; uint32_t nValueAge = pWidget->GetValueAge(); pWidget->ClearAppModified(); ASSERT(pPageView); CPDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag); fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag); pWidget->OnAAction(CPDF_AAction::kCursorExit, &fa, pPageView); m_bNotifying = false; if (!pAnnot->HasObservable()) return; if (pWidget->IsAppModified()) { if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) { pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge()); } } } } if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot->Get(), false)) pFormFiller->OnMouseExit(pPageView, pAnnot->Get()); }
CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot, bool bNext) { #ifdef PDF_ENABLE_XFA CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView(); CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage(); if (pPage && !pPage->AsPDFPage()) { // For xfa annots in XFA pages not backed by PDF pages. std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator( pPage->GetXFAPageView()->CreateWidgetIterator( XFA_TRAVERSEWAY_Tranvalse, XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable | XFA_WidgetStatus_Focused)); if (!pWidgetIterator) return nullptr; if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget()) pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget()); CXFA_FFWidget* hNextFocus = bNext ? pWidgetIterator->MoveToNext() : pWidgetIterator->MoveToPrevious(); if (!hNextFocus && pSDKAnnot) hNextFocus = pWidgetIterator->MoveToFirst(); return pPageView->GetAnnotByXFAWidget(hNextFocus); } #endif // PDF_ENABLE_XFA // For PDF annots. CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pSDKAnnot); CPDFSDK_AnnotIterator ai(pWidget->GetPageView(), pWidget->GetAnnotSubtype()); return bNext ? ai.GetNextAnnot(pWidget) : ai.GetPrevAnnot(pWidget); }
void CFFL_InteractiveFormFiller::OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, const CFX_Matrix& mtUser2Device) { ASSERT(pPageView); CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot); if (!IsVisible(pWidget)) return; CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, false); if (pFormFiller && pFormFiller->IsValid()) { pFormFiller->OnDraw(pPageView, pAnnot, pDevice, mtUser2Device); pAnnot->GetPDFPage(); if (m_pFormFillEnv->GetFocusAnnot() != pAnnot) return; CFX_FloatRect rcFocus = pFormFiller->GetFocusBox(pPageView); if (rcFocus.IsEmpty()) return; CFX_PathData path; path.AppendPoint(CFX_PointF(rcFocus.left, rcFocus.top), FXPT_TYPE::MoveTo, false); path.AppendPoint(CFX_PointF(rcFocus.left, rcFocus.bottom), FXPT_TYPE::LineTo, false); path.AppendPoint(CFX_PointF(rcFocus.right, rcFocus.bottom), FXPT_TYPE::LineTo, false); path.AppendPoint(CFX_PointF(rcFocus.right, rcFocus.top), FXPT_TYPE::LineTo, false); path.AppendPoint(CFX_PointF(rcFocus.left, rcFocus.top), FXPT_TYPE::LineTo, false); CFX_GraphStateData gsd; gsd.m_DashArray = {1.0f}; gsd.m_DashPhase = 0; gsd.m_LineWidth = 1.0f; pDevice->DrawPath(&path, &mtUser2Device, &gsd, 0, ArgbEncode(255, 0, 0, 0), FXFILL_ALTERNATE); return; } pFormFiller = GetFormFiller(pAnnot, false); if (pFormFiller) { pFormFiller->OnDrawDeactive(pPageView, pAnnot, pDevice, mtUser2Device); } else { pWidget->DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::Normal, nullptr); } if (!IsReadOnly(pWidget) && IsFillingAllowed(pWidget)) pWidget->DrawShadow(pDevice, pPageView); }
void CFFL_InteractiveFormFiller::OnCalculate(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, uint32_t nFlag) { if (m_bNotifying) return; CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get()); if (pWidget) { CPDFSDK_InteractiveForm* pForm = pPageView->GetFormFillEnv()->GetInteractiveForm(); pForm->OnCalculate(pWidget->GetFormField()); } m_bNotifying = false; }
CFFL_FormFiller* CFFL_InteractiveFormFiller::GetFormFiller( CPDFSDK_Annot* pAnnot, bool bRegister) { auto it = m_Maps.find(pAnnot); if (it != m_Maps.end()) return it->second.get(); if (!bRegister) return nullptr; CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot); FormFieldType fieldType = pWidget->GetFieldType(); std::unique_ptr<CFFL_FormFiller> pFormFiller; switch (fieldType) { case FormFieldType::kPushButton: pFormFiller = pdfium::MakeUnique<CFFL_PushButton>(m_pFormFillEnv.Get(), pWidget); break; case FormFieldType::kCheckBox: pFormFiller = pdfium::MakeUnique<CFFL_CheckBox>(m_pFormFillEnv.Get(), pWidget); break; case FormFieldType::kRadioButton: pFormFiller = pdfium::MakeUnique<CFFL_RadioButton>(m_pFormFillEnv.Get(), pWidget); break; case FormFieldType::kTextField: pFormFiller = pdfium::MakeUnique<CFFL_TextField>(m_pFormFillEnv.Get(), pWidget); break; case FormFieldType::kListBox: pFormFiller = pdfium::MakeUnique<CFFL_ListBox>(m_pFormFillEnv.Get(), pWidget); break; case FormFieldType::kComboBox: pFormFiller = pdfium::MakeUnique<CFFL_ComboBox>(m_pFormFillEnv.Get(), pWidget); break; case FormFieldType::kUnknown: default: break; } if (!pFormFiller) return nullptr; CFFL_FormFiller* result = pFormFiller.get(); m_Maps[pAnnot] = std::move(pFormFiller); return result; }
bool CFFL_CheckBox::OnLButtonUp(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, uint32_t nFlags, const CFX_PointF& point) { CFFL_Button::OnLButtonUp(pPageView, pAnnot, nFlags, point); if (!IsValid()) return true; CPWL_CheckBox* pWnd = GetCheckBox(pPageView, true); if (pWnd) { CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot); pWnd->SetCheck(!pWidget->IsChecked()); } return CommitData(pPageView, nFlags); }
void CFFL_InteractiveFormFiller::OnFormat(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, uint32_t nFlag) { if (m_bNotifying) return; CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get()); ASSERT(pWidget); CPDFSDK_InteractiveForm* pForm = pPageView->GetFormFillEnv()->GetInteractiveForm(); Optional<WideString> sValue = pForm->OnFormat(pWidget->GetFormField()); if (!pAnnot->HasObservable()) return; if (sValue.has_value()) { pForm->ResetFieldAppearance(pWidget->GetFormField(), sValue, true); pForm->UpdateField(pWidget->GetFormField()); } m_bNotifying = false; }
bool CFFL_InteractiveFormFiller::OnLButtonDown( CPDFSDK_PageView* pPageView, CPDFSDK_Annot::ObservedPtr* pAnnot, uint32_t nFlags, const CFX_PointF& point) { ASSERT((*pAnnot)->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); if (!m_bNotifying) { CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get()); if (Annot_HitTest(pPageView, pAnnot->Get(), point) && pWidget->GetAAction(CPDF_AAction::kButtonDown).GetDict()) { m_bNotifying = true; uint32_t nValueAge = pWidget->GetValueAge(); pWidget->ClearAppModified(); ASSERT(pPageView); CPDFSDK_FieldAction fa; fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlags); fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlags); pWidget->OnAAction(CPDF_AAction::kButtonDown, &fa, pPageView); m_bNotifying = false; if (!pAnnot->HasObservable()) return true; if (!IsValidAnnot(pPageView, pAnnot->Get())) return true; if (pWidget->IsAppModified()) { if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) { pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge()); } } } } CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot->Get(), false); return pFormFiller && pFormFiller->OnLButtonDown(pPageView, pAnnot->Get(), nFlags, point); }
bool CFFL_InteractiveFormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, CPDFSDK_Annot::ObservedPtr* pAnnot, uint32_t nFlags, const CFX_PointF& point) { ASSERT((*pAnnot)->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot->Get()); bool bSetFocus; switch (pWidget->GetFieldType()) { case FormFieldType::kPushButton: case FormFieldType::kCheckBox: case FormFieldType::kRadioButton: { FX_RECT bbox = GetViewBBox(pPageView, pAnnot->Get()); bSetFocus = bbox.Contains(static_cast<int>(point.x), static_cast<int>(point.y)); break; } default: bSetFocus = true; break; } if (bSetFocus) m_pFormFillEnv->SetFocusAnnot(pAnnot); CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot->Get(), false); bool bRet = pFormFiller && pFormFiller->OnLButtonUp(pPageView, pAnnot->Get(), nFlags, point); if (m_pFormFillEnv->GetFocusAnnot() != pAnnot->Get()) return bRet; if (OnButtonUp(pAnnot, pPageView, nFlags) || !pAnnot) return true; #ifdef PDF_ENABLE_XFA if (OnClick(pAnnot, pPageView, nFlags) || !pAnnot) return true; #endif // PDF_ENABLE_XFA return bRet; }