jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 1 | // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 7 | #include "fpdfsdk/cpdfsdk_widgethandler.h" |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 8 | |
| 9 | #include <memory> |
| 10 | #include <vector> |
| 11 | |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 12 | #include "core/fpdfapi/page/cpdf_page.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/parser/cpdf_document.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 14 | #include "core/fpdfdoc/cpdf_interform.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 15 | #include "fpdfsdk/cpdfsdk_annot.h" |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 16 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 17 | #include "fpdfsdk/cpdfsdk_interform.h" |
| 18 | #include "fpdfsdk/cpdfsdk_pageview.h" |
| 19 | #include "fpdfsdk/cpdfsdk_widget.h" |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 20 | #include "fpdfsdk/formfiller/cffl_formfiller.h" |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 21 | |
| 22 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 23 | #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 24 | #endif // PDF_ENABLE_XFA |
| 25 | |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 26 | CPDFSDK_WidgetHandler::CPDFSDK_WidgetHandler( |
| 27 | CPDFSDK_FormFillEnvironment* pFormFillEnv) |
Lei Zhang | 60fa2fc | 2017-07-21 17:42:19 -0700 | [diff] [blame] | 28 | : m_pFormFillEnv(pFormFillEnv), |
| 29 | m_pFormFiller(pFormFillEnv->GetInteractiveFormFiller()) {} |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 30 | |
| 31 | CPDFSDK_WidgetHandler::~CPDFSDK_WidgetHandler() {} |
| 32 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 33 | bool CPDFSDK_WidgetHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 34 | ASSERT(pAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 35 | if (pAnnot->IsSignatureWidget()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 36 | return false; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 37 | |
| 38 | CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot); |
| 39 | if (!pWidget->IsVisible()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 40 | return false; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 41 | |
| 42 | int nFieldFlags = pWidget->GetFieldFlags(); |
| 43 | if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 44 | return false; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 45 | |
| 46 | if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 47 | return true; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 48 | |
| 49 | CPDF_Page* pPage = pWidget->GetPDFPage(); |
Tom Sepez | 4cb82ee | 2017-05-22 15:15:30 -0700 | [diff] [blame] | 50 | uint32_t dwPermissions = pPage->m_pDocument->GetUserPermissions(); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 51 | return (dwPermissions & FPDFPERM_FILL_FORM) || |
| 52 | (dwPermissions & FPDFPERM_ANNOT_FORM); |
| 53 | } |
| 54 | |
| 55 | CPDFSDK_Annot* CPDFSDK_WidgetHandler::NewAnnot(CPDF_Annot* pAnnot, |
| 56 | CPDFSDK_PageView* pPage) { |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 57 | CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 58 | CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl( |
| 59 | pInterForm->GetInterForm(), pAnnot->GetAnnotDict()); |
| 60 | if (!pCtrl) |
| 61 | return nullptr; |
| 62 | |
| 63 | CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm); |
| 64 | pInterForm->AddMap(pCtrl, pWidget); |
| 65 | CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
| 66 | if (pPDFInterForm && pPDFInterForm->NeedConstructAP()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 67 | pWidget->ResetAppearance(nullptr, false); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 68 | |
| 69 | return pWidget; |
| 70 | } |
| 71 | |
| 72 | #ifdef PDF_ENABLE_XFA |
| 73 | CPDFSDK_Annot* CPDFSDK_WidgetHandler::NewAnnot(CXFA_FFWidget* hWidget, |
| 74 | CPDFSDK_PageView* pPage) { |
| 75 | return nullptr; |
| 76 | } |
| 77 | #endif // PDF_ENABLE_XFA |
| 78 | |
| 79 | void CPDFSDK_WidgetHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { |
| 80 | ASSERT(pAnnot); |
| 81 | |
| 82 | if (m_pFormFiller) |
| 83 | m_pFormFiller->OnDelete(pAnnot); |
| 84 | |
| 85 | std::unique_ptr<CPDFSDK_Widget> pWidget(static_cast<CPDFSDK_Widget*>(pAnnot)); |
| 86 | CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); |
| 87 | CPDF_FormControl* pControl = pWidget->GetFormControl(); |
| 88 | pInterForm->RemoveMap(pControl); |
| 89 | } |
| 90 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 91 | void CPDFSDK_WidgetHandler::OnDraw(CPDFSDK_PageView* pPageView, |
| 92 | CPDFSDK_Annot* pAnnot, |
| 93 | CFX_RenderDevice* pDevice, |
jaepark | 75f84a5 | 2016-09-09 15:39:09 -0700 | [diff] [blame] | 94 | CFX_Matrix* pUser2Device, |
| 95 | bool bDrawAnnots) { |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 96 | if (pAnnot->IsSignatureWidget()) { |
| 97 | static_cast<CPDFSDK_BAAnnot*>(pAnnot)->DrawAppearance( |
Lei Zhang | 8a44940 | 2017-08-17 15:07:47 -0700 | [diff] [blame] | 98 | pDevice, *pUser2Device, CPDF_Annot::Normal, nullptr); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 99 | } else { |
| 100 | if (m_pFormFiller) |
jaepark | 4bae296 | 2016-09-01 14:39:24 -0700 | [diff] [blame] | 101 | m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 105 | void CPDFSDK_WidgetHandler::OnMouseEnter(CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 106 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 107 | uint32_t nFlag) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 108 | if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 109 | m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag); |
| 110 | } |
| 111 | |
| 112 | void CPDFSDK_WidgetHandler::OnMouseExit(CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 113 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 114 | uint32_t nFlag) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 115 | if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 116 | m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag); |
| 117 | } |
| 118 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 119 | bool CPDFSDK_WidgetHandler::OnLButtonDown(CPDFSDK_PageView* pPageView, |
| 120 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 121 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 122 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 123 | if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 124 | return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point); |
| 125 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 126 | return false; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 127 | } |
| 128 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 129 | bool CPDFSDK_WidgetHandler::OnLButtonUp(CPDFSDK_PageView* pPageView, |
| 130 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 131 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 132 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 133 | if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 134 | return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point); |
| 135 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 136 | return false; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 137 | } |
| 138 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 139 | bool CPDFSDK_WidgetHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView, |
| 140 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 141 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 142 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 143 | if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 144 | return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); |
| 145 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 146 | return false; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 147 | } |
| 148 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 149 | bool CPDFSDK_WidgetHandler::OnMouseMove(CPDFSDK_PageView* pPageView, |
| 150 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 151 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 152 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 153 | if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 154 | return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point); |
| 155 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 156 | return false; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 157 | } |
| 158 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 159 | bool CPDFSDK_WidgetHandler::OnMouseWheel(CPDFSDK_PageView* pPageView, |
| 160 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 161 | uint32_t nFlags, |
| 162 | short zDelta, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 163 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 164 | if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 165 | return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, |
| 166 | point); |
| 167 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 168 | return false; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 169 | } |
| 170 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 171 | bool CPDFSDK_WidgetHandler::OnRButtonDown(CPDFSDK_PageView* pPageView, |
| 172 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 173 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 174 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 175 | if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 176 | return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point); |
| 177 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 178 | return false; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 179 | } |
| 180 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 181 | bool CPDFSDK_WidgetHandler::OnRButtonUp(CPDFSDK_PageView* pPageView, |
| 182 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 183 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 184 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 185 | if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 186 | return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point); |
| 187 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 188 | return false; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 189 | } |
| 190 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 191 | bool CPDFSDK_WidgetHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView, |
| 192 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 193 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 194 | const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 195 | return false; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 196 | } |
| 197 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 198 | bool CPDFSDK_WidgetHandler::OnChar(CPDFSDK_Annot* pAnnot, |
| 199 | uint32_t nChar, |
| 200 | uint32_t nFlags) { |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 201 | if (!pAnnot->IsSignatureWidget() && m_pFormFiller) |
| 202 | return m_pFormFiller->OnChar(pAnnot, nChar, nFlags); |
| 203 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 204 | return false; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 205 | } |
| 206 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 207 | bool CPDFSDK_WidgetHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, |
| 208 | int nKeyCode, |
| 209 | int nFlag) { |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 210 | if (!pAnnot->IsSignatureWidget() && m_pFormFiller) |
| 211 | return m_pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlag); |
| 212 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 213 | return false; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 214 | } |
| 215 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 216 | bool CPDFSDK_WidgetHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, |
| 217 | int nKeyCode, |
| 218 | int nFlag) { |
| 219 | return false; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 220 | } |
| 221 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 222 | void CPDFSDK_WidgetHandler::OnLoad(CPDFSDK_Annot* pAnnot) { |
| 223 | if (pAnnot->IsSignatureWidget()) |
| 224 | return; |
| 225 | |
| 226 | CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot); |
| 227 | if (!pWidget->IsAppearanceValid()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 228 | pWidget->ResetAppearance(nullptr, false); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 229 | |
| 230 | int nFieldType = pWidget->GetFieldType(); |
| 231 | if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 232 | bool bFormatted = false; |
Lei Zhang | cd8ff7e | 2017-06-13 14:09:46 -0700 | [diff] [blame] | 233 | CPDFSDK_Annot::ObservedPtr pObserved(pWidget); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 234 | WideString sValue = pWidget->OnFormat(bFormatted); |
Lei Zhang | cd8ff7e | 2017-06-13 14:09:46 -0700 | [diff] [blame] | 235 | if (!pObserved) |
| 236 | return; |
| 237 | |
tsepez | 8c2a8cd | 2016-09-07 15:29:11 -0700 | [diff] [blame] | 238 | if (bFormatted && nFieldType == FIELDTYPE_COMBOBOX) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 239 | pWidget->ResetAppearance(&sValue, false); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | #ifdef PDF_ENABLE_XFA |
| 243 | CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 244 | CPDFXFA_Context* pContext = pPageView->GetFormFillEnv()->GetXFAContext(); |
Ryan Harrison | 854d71c | 2017-10-18 12:28:14 -0400 | [diff] [blame] | 245 | if (pContext->GetFormType() == FormType::kXFAForeground) { |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 246 | if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 247 | pWidget->ResetAppearance(false); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 248 | } |
| 249 | #endif // PDF_ENABLE_XFA |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 250 | } |
| 251 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 252 | bool CPDFSDK_WidgetHandler::OnSetFocus(CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 253 | uint32_t nFlag) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 254 | if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 255 | return m_pFormFiller->OnSetFocus(pAnnot, nFlag); |
| 256 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 257 | return true; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 258 | } |
| 259 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 260 | bool CPDFSDK_WidgetHandler::OnKillFocus(CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 261 | uint32_t nFlag) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 262 | if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 263 | return m_pFormFiller->OnKillFocus(pAnnot, nFlag); |
| 264 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 265 | return true; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | #ifdef PDF_ENABLE_XFA |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 269 | bool CPDFSDK_WidgetHandler::OnXFAChangedFocus( |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 270 | CPDFSDK_Annot::ObservedPtr* pOldAnnot, |
| 271 | CPDFSDK_Annot::ObservedPtr* pNewAnnot) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 272 | return true; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 273 | } |
| 274 | #endif // PDF_ENABLE_XFA |
| 275 | |
| 276 | CFX_FloatRect CPDFSDK_WidgetHandler::GetViewBBox(CPDFSDK_PageView* pPageView, |
| 277 | CPDFSDK_Annot* pAnnot) { |
| 278 | if (!pAnnot->IsSignatureWidget() && m_pFormFiller) |
| 279 | return CFX_FloatRect(m_pFormFiller->GetViewBBox(pPageView, pAnnot)); |
Lei Zhang | d24236a | 2017-06-29 18:28:58 -0700 | [diff] [blame] | 280 | return CFX_FloatRect(); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 283 | WideString CPDFSDK_WidgetHandler::GetSelectedText(CPDFSDK_Annot* pAnnot) { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 284 | if (!pAnnot->IsSignatureWidget() && m_pFormFiller) |
| 285 | return m_pFormFiller->GetSelectedText(pAnnot); |
| 286 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 287 | return WideString(); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 290 | void CPDFSDK_WidgetHandler::ReplaceSelection(CPDFSDK_Annot* pAnnot, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 291 | const WideString& text) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 292 | if (!pAnnot->IsSignatureWidget() && m_pFormFiller) |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 293 | m_pFormFiller->ReplaceSelection(pAnnot, text); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 294 | } |
| 295 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 296 | bool CPDFSDK_WidgetHandler::HitTest(CPDFSDK_PageView* pPageView, |
| 297 | CPDFSDK_Annot* pAnnot, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 298 | const CFX_PointF& point) { |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 299 | ASSERT(pPageView); |
| 300 | ASSERT(pAnnot); |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 301 | return GetViewBBox(pPageView, pAnnot).Contains(point); |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 302 | } |