blob: 5e65a1f9475415793ea56b2d82002f43076153ba [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 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.
Lei Zhang60f507b2015-06-13 00:41:00 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclair3ebd1212016-03-09 09:59:23 -05007#include "fpdfsdk/include/fsdk_annothandler.h"
8
Lei Zhangbf60b292015-10-26 12:14:35 -07009#include <algorithm>
Dan Sinclair3ebd1212016-03-09 09:59:23 -050010#include <vector>
Lei Zhangbf60b292015-10-26 12:14:35 -070011
Dan Sinclair455a4192016-03-16 09:48:56 -040012#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
Dan Sinclairaa403d32016-03-15 14:57:22 -040013#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
dsinclaircac704d2016-07-28 12:59:09 -070014#include "core/fpdfdoc/include/cpdf_interform.h"
npm9ada2d82016-08-10 07:51:38 -070015#include "core/fxge/include/cfx_renderdevice.h"
Dan Sinclairedbb3192016-03-21 09:08:24 -040016#include "fpdfsdk/formfiller/cffl_formfiller.h"
jaepark27362762016-08-11 13:10:39 -070017#include "fpdfsdk/include/cpdfsdk_datetime.h"
Lei Zhangbde53d22015-11-12 22:21:30 -080018#include "fpdfsdk/include/fsdk_define.h"
19#include "fpdfsdk/include/fsdk_mgr.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070020
Tom Sepez40e9ff32015-11-30 12:39:54 -080021#ifdef PDF_ENABLE_XFA
dsinclair89bdd082016-04-06 10:47:54 -070022#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
23#include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h"
24#include "fpdfsdk/fpdfxfa/include/fpdfxfa_util.h"
dsinclair89fcde82016-05-03 13:00:25 -070025#include "xfa/fwl/core/include/fwl_widgethit.h"
dsinclair7222ea62016-04-06 14:33:07 -070026#include "xfa/fxfa/include/xfa_ffwidget.h"
weili625ad662016-06-15 11:21:33 -070027#include "xfa/fxfa/include/xfa_ffdocview.h"
28#include "xfa/fxfa/include/xfa_ffpageview.h"
29#include "xfa/fxfa/include/xfa_ffwidgethandler.h"
Dan Sinclair811b8a42016-03-17 08:59:42 -040030#include "xfa/fxgraphics/include/cfx_graphics.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080031#endif // PDF_ENABLE_XFA
32
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) {
34 m_pApp = pApp;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070035
Nico Weber9d8ec5a2015-08-04 13:00:21 -070036 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp);
37 pHandler->SetFormFiller(m_pApp->GetIFormFiller());
38 RegisterAnnotHandler(pHandler);
Tom Sepez51da0932015-11-25 16:05:49 -080039#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -070040 CPDFSDK_XFAAnnotHandler* pXFAAnnotHandler =
41 new CPDFSDK_XFAAnnotHandler(m_pApp);
42 RegisterAnnotHandler(pXFAAnnotHandler);
Tom Sepez40e9ff32015-11-30 12:39:54 -080043#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070044}
45
weili9ca2b092016-07-21 12:26:18 -070046CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047
48void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler(
49 IPDFSDK_AnnotHandler* pAnnotHandler) {
Tom Sepez09d33bc2015-08-19 09:49:24 -070050 ASSERT(!GetAnnotHandler(pAnnotHandler->GetType()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -070051
weili9ca2b092016-07-21 12:26:18 -070052 m_mapType2Handler[pAnnotHandler->GetType()].reset(pAnnotHandler);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070053}
54
55void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler(
56 IPDFSDK_AnnotHandler* pAnnotHandler) {
Tom Sepez09d33bc2015-08-19 09:49:24 -070057 m_mapType2Handler.erase(pAnnotHandler->GetType());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070058}
59
Nico Weber9d8ec5a2015-08-04 13:00:21 -070060CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot,
61 CPDFSDK_PageView* pPageView) {
Lei Zhang96660d62015-12-14 18:27:25 -080062 ASSERT(pPageView);
Lei Zhang60f507b2015-06-13 00:41:00 -070063
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064 if (IPDFSDK_AnnotHandler* pAnnotHandler =
65 GetAnnotHandler(pAnnot->GetSubType())) {
66 return pAnnotHandler->NewAnnot(pAnnot, pPageView);
67 }
Lei Zhang60f507b2015-06-13 00:41:00 -070068
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069 return new CPDFSDK_BAAnnot(pAnnot, pPageView);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070070}
71
Tom Sepez51da0932015-11-25 16:05:49 -080072#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -070073CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CXFA_FFWidget* pAnnot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070074 CPDFSDK_PageView* pPageView) {
Lei Zhang5eca3052016-02-22 20:32:21 -080075 ASSERT(pAnnot);
76 ASSERT(pPageView);
Lei Zhang60f507b2015-06-13 00:41:00 -070077
Nico Weber9d8ec5a2015-08-04 13:00:21 -070078 if (IPDFSDK_AnnotHandler* pAnnotHandler =
79 GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME)) {
80 return pAnnotHandler->NewAnnot(pAnnot, pPageView);
81 }
Lei Zhang60f507b2015-06-13 00:41:00 -070082
thestig1cd352e2016-06-07 17:53:06 -070083 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070084}
Tom Sepez40e9ff32015-11-30 12:39:54 -080085#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070086
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
89 pAnnotHandler->OnRelease(pAnnot);
90 pAnnotHandler->ReleaseAnnot(pAnnot);
91 } else {
tsepez77b909e2016-06-09 14:08:11 -070092 delete pAnnot;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070093 }
Bo Xufdc00a72014-10-28 23:03:33 -070094}
95
Nico Weber9d8ec5a2015-08-04 13:00:21 -070096void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
Bo Xufdc00a72014-10-28 23:03:33 -070098
Nico Weber9d8ec5a2015-08-04 13:00:21 -070099 CPDFSDK_DateTime curTime;
100 pPDFAnnot->GetAnnotDict()->SetAtString("M", curTime.ToPDFDateTimeString());
101 pPDFAnnot->GetAnnotDict()->SetAtNumber("F", 0);
102
103 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
104 pAnnotHandler->OnCreate(pAnnot);
105 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700106}
107
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) {
Lei Zhang96660d62015-12-14 18:27:25 -0800109 ASSERT(pAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700110
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700111 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
112 pAnnotHandler->OnLoad(pAnnot);
113 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700114}
115
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
117 CPDFSDK_Annot* pAnnot) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700118 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
119 if (pPDFAnnot)
120 return GetAnnotHandler(pPDFAnnot->GetSubType());
Tom Sepez51da0932015-11-25 16:05:49 -0800121#ifdef PDF_ENABLE_XFA
Tom Sepezc7e4c4f2015-11-20 09:45:24 -0800122 if (pAnnot->GetXFAWidget())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700123 return GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800124#endif // PDF_ENABLE_XFA
Tom Sepezc7e4c4f2015-11-20 09:45:24 -0800125 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700126}
127
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700128IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
129 const CFX_ByteString& sType) const {
Tom Sepez09d33bc2015-08-19 09:49:24 -0700130 auto it = m_mapType2Handler.find(sType);
weili9ca2b092016-07-21 12:26:18 -0700131 return it != m_mapType2Handler.end() ? it->second.get() : nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132}
133
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700134void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView,
135 CPDFSDK_Annot* pAnnot,
136 CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800137 CFX_Matrix* pUser2Device,
tsepezc3255f52016-03-25 14:52:27 -0700138 uint32_t dwFlags) {
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500139 ASSERT(pAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700140
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700141 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
142 pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
143 } else {
Tom Sepez51da0932015-11-25 16:05:49 -0800144#ifdef PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800145 if (pAnnot->IsXFAField())
146 return;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800147#endif // PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800148 static_cast<CPDFSDK_BAAnnot*>(pAnnot)
149 ->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700150 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700151}
152
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700153FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(
154 CPDFSDK_PageView* pPageView,
155 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700156 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800157 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800158 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700159
160 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
161 return pAnnotHandler->OnLButtonDown(pPageView, pAnnot, nFlags, point);
162 }
163 return FALSE;
164}
Tom Sepez281a9ea2016-02-26 14:24:28 -0800165FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(
166 CPDFSDK_PageView* pPageView,
167 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700168 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800169 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800170 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171
172 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
173 return pAnnotHandler->OnLButtonUp(pPageView, pAnnot, nFlags, point);
174 }
175 return FALSE;
176}
177FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(
178 CPDFSDK_PageView* pPageView,
179 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700180 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800181 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800182 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183
184 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
185 return pAnnotHandler->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
186 }
187 return FALSE;
188}
Tom Sepez281a9ea2016-02-26 14:24:28 -0800189FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(
190 CPDFSDK_PageView* pPageView,
191 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700192 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800193 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800194 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700195
196 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
197 return pAnnotHandler->OnMouseMove(pPageView, pAnnot, nFlags, point);
198 }
199 return FALSE;
200}
Tom Sepez281a9ea2016-02-26 14:24:28 -0800201FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(
202 CPDFSDK_PageView* pPageView,
203 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700204 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800205 short zDelta,
206 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800207 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700208
209 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
210 return pAnnotHandler->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,
211 point);
212 }
213 return FALSE;
214}
215FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(
216 CPDFSDK_PageView* pPageView,
217 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700218 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800219 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800220 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700221
222 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
223 return pAnnotHandler->OnRButtonDown(pPageView, pAnnot, nFlags, point);
224 }
225 return FALSE;
226}
Tom Sepez281a9ea2016-02-26 14:24:28 -0800227FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(
228 CPDFSDK_PageView* pPageView,
229 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700230 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800231 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800232 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700233
234 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
235 return pAnnotHandler->OnRButtonUp(pPageView, pAnnot, nFlags, point);
236 }
237 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700238}
239
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(CPDFSDK_PageView* pPageView,
241 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700242 uint32_t nFlag) {
Lei Zhang96660d62015-12-14 18:27:25 -0800243 ASSERT(pAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700244
Lei Zhang05e67412016-01-25 16:35:42 -0800245 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700246 pAnnotHandler->OnMouseEnter(pPageView, pAnnot, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700247}
248
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700249void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(CPDFSDK_PageView* pPageView,
250 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700251 uint32_t nFlag) {
Lei Zhang96660d62015-12-14 18:27:25 -0800252 ASSERT(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700253
Lei Zhang05e67412016-01-25 16:35:42 -0800254 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255 pAnnotHandler->OnMouseExit(pPageView, pAnnot, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700256}
257
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700258FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700259 uint32_t nChar,
260 uint32_t nFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
262 return pAnnotHandler->OnChar(pAnnot, nChar, nFlags);
263 }
264 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700265}
266
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700267FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot,
268 int nKeyCode,
269 int nFlag) {
270 if (!m_pApp->FFI_IsCTRLKeyDown(nFlag) && !m_pApp->FFI_IsALTKeyDown(nFlag)) {
271 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
272 CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();
273 if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) {
274 CPDFSDK_Annot* pNext =
275 GetNextAnnot(pFocusAnnot, !m_pApp->FFI_IsSHIFTKeyDown(nFlag));
Lei Zhang60f507b2015-06-13 00:41:00 -0700276
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700277 if (pNext && pNext != pFocusAnnot) {
278 CPDFSDK_Document* pDocument = pPage->GetSDKDocument();
279 pDocument->SetFocusAnnot(pNext);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700280 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700281 }
282 }
283 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700284
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700285 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
286 return pAnnotHandler->OnKeyDown(pAnnot, nKeyCode, nFlag);
287 }
288 return FALSE;
289}
290FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot,
291 int nKeyCode,
292 int nFlag) {
293 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700294}
295
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700297 uint32_t nFlag) {
Lei Zhang96660d62015-12-14 18:27:25 -0800298 ASSERT(pAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700299
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
301 if (pAnnotHandler->OnSetFocus(pAnnot, nFlag)) {
302 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
303 pPage->GetSDKDocument();
304 return TRUE;
305 }
306 }
307 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700308}
309
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700311 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312 ASSERT(pAnnot);
313 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
314 return pAnnotHandler->OnKillFocus(pAnnot, nFlag);
315
316 return FALSE;
317}
318
Tom Sepez51da0932015-11-25 16:05:49 -0800319#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700320FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus(
321 CPDFSDK_Annot* pSetAnnot,
322 CPDFSDK_Annot* pKillAnnot) {
323 FX_BOOL bXFA = (pSetAnnot && pSetAnnot->GetXFAWidget()) ||
324 (pKillAnnot && pKillAnnot->GetXFAWidget());
325
326 if (bXFA) {
327 if (IPDFSDK_AnnotHandler* pXFAAnnotHandler =
328 GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME))
329 return pXFAAnnotHandler->OnXFAChangedFocus(pKillAnnot, pSetAnnot);
330 }
331
332 return TRUE;
333}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800334#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700335
Tom Sepez281a9ea2016-02-26 14:24:28 -0800336CFX_FloatRect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700337 CPDFSDK_PageView* pPageView,
338 CPDFSDK_Annot* pAnnot) {
339 ASSERT(pAnnot);
340 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
341 return pAnnotHandler->GetViewBBox(pPageView, pAnnot);
342
343 return pAnnot->GetRect();
344}
345
346FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView,
347 CPDFSDK_Annot* pAnnot,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800348 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700349 ASSERT(pAnnot);
350 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
351 if (pAnnotHandler->CanAnswer(pAnnot))
352 return pAnnotHandler->HitTest(pPageView, pAnnot, point);
353 }
354 return FALSE;
355}
356
357CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,
358 FX_BOOL bNext) {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800359#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360 CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView();
361 CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage();
thestig1cd352e2016-06-07 17:53:06 -0700362 if (!pPage)
363 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700364 if (pPage->GetPDFPage()) { // for pdf annots.
365 CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), pSDKAnnot->GetType(), "");
366 CPDFSDK_Annot* pNext =
367 bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot);
368 return pNext;
369 }
370 // for xfa annots
tsepezcc4d6d82016-05-16 13:21:03 -0700371 std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700372 pPage->GetXFAPageView()->CreateWidgetIterator(
dsinclair935d8d52016-05-17 10:32:18 -0700373 XFA_TRAVERSEWAY_Tranvalse, XFA_WidgetStatus_Visible |
374 XFA_WidgetStatus_Viewable |
375 XFA_WidgetStatus_Focused));
tsepezcc4d6d82016-05-16 13:21:03 -0700376 if (!pWidgetIterator)
377 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700378 if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget())
379 pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget());
tsepezcc4d6d82016-05-16 13:21:03 -0700380 CXFA_FFWidget* hNextFocus =
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700381 bNext ? pWidgetIterator->MoveToNext() : pWidgetIterator->MoveToPrevious();
Lei Zhang5eca3052016-02-22 20:32:21 -0800382 if (!hNextFocus && pSDKAnnot)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700383 hNextFocus = pWidgetIterator->MoveToFirst();
384
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700385 return pPageView->GetAnnotByXFAWidget(hNextFocus);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800386#else // PDF_ENABLE_XFA
387 CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), "Widget", "");
388 return bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot);
389#endif // PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -0700390}
391
weili625ad662016-06-15 11:21:33 -0700392CPDFSDK_BFAnnotHandler::CPDFSDK_BFAnnotHandler(CPDFDoc_Environment* pApp)
393 : m_pApp(pApp), m_pFormFiller(nullptr) {}
394
395CPDFSDK_BFAnnotHandler::~CPDFSDK_BFAnnotHandler() {}
396
397CFX_ByteString CPDFSDK_BFAnnotHandler::GetType() {
398 return CFX_ByteString("Widget");
399}
400
401CFX_ByteString CPDFSDK_BFAnnotHandler::GetName() {
402 return CFX_ByteString("WidgetHandler");
403}
404
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700405FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
406 ASSERT(pAnnot->GetType() == "Widget");
407 if (pAnnot->GetSubType() == BFFT_SIGNATURE)
408 return FALSE;
409
tsepez77b909e2016-06-09 14:08:11 -0700410 CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700411 if (!pWidget->IsVisible())
412 return FALSE;
413
414 int nFieldFlags = pWidget->GetFieldFlags();
415 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
416 return FALSE;
417
418 if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON)
419 return TRUE;
420
421 CPDF_Page* pPage = pWidget->GetPDFPage();
422 CPDF_Document* pDocument = pPage->m_pDocument;
tsepezc3255f52016-03-25 14:52:27 -0700423 uint32_t dwPermissions = pDocument->GetUserPermissions();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700424 return (dwPermissions & FPDFPERM_FILL_FORM) ||
425 (dwPermissions & FPDFPERM_ANNOT_FORM);
426}
427
428CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot,
429 CPDFSDK_PageView* pPage) {
430 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument();
tsepez23ae4a52016-06-08 20:44:54 -0700431 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700432 CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl(
433 pInterForm->GetInterForm(), pAnnot->GetAnnotDict());
434 if (!pCtrl)
435 return nullptr;
436
437 CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm);
438 pInterForm->AddMap(pCtrl, pWidget);
439 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
440 if (pPDFInterForm && pPDFInterForm->NeedConstructAP())
441 pWidget->ResetAppearance(nullptr, FALSE);
442
443 return pWidget;
444}
445
Tom Sepez51da0932015-11-25 16:05:49 -0800446#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -0700447CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CXFA_FFWidget* hWidget,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700448 CPDFSDK_PageView* pPage) {
thestig1cd352e2016-06-07 17:53:06 -0700449 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700450}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800451#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452
453void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
Lei Zhang96660d62015-12-14 18:27:25 -0800454 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700455
456 if (m_pFormFiller)
457 m_pFormFiller->OnDelete(pAnnot);
458
tsepez77b909e2016-06-09 14:08:11 -0700459 std::unique_ptr<CPDFSDK_Widget> pWidget(static_cast<CPDFSDK_Widget*>(pAnnot));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700460 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
tsepez77b909e2016-06-09 14:08:11 -0700461 CPDF_FormControl* pControl = pWidget->GetFormControl();
462 pInterForm->RemoveMap(pControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463}
464
weili625ad662016-06-15 11:21:33 -0700465void CPDFSDK_BFAnnotHandler::DeleteAnnot(CPDFSDK_Annot* pAnnot) {}
466
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467void CPDFSDK_BFAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
468 CPDFSDK_Annot* pAnnot,
469 CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800470 CFX_Matrix* pUser2Device,
tsepezc3255f52016-03-25 14:52:27 -0700471 uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700472 CFX_ByteString sSubType = pAnnot->GetSubType();
473
474 if (sSubType == BFFT_SIGNATURE) {
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500475 static_cast<CPDFSDK_BAAnnot*>(pAnnot)
476 ->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700477 } else {
478 if (m_pFormFiller) {
479 m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
480 }
481 }
482}
483
weili625ad662016-06-15 11:21:33 -0700484void CPDFSDK_BFAnnotHandler::OnDrawSleep(CPDFSDK_PageView* pPageView,
485 CPDFSDK_Annot* pAnnot,
486 CFX_RenderDevice* pDevice,
487 CFX_Matrix* pUser2Device,
488 const CFX_FloatRect& rcWindow,
489 uint32_t dwFlags) {}
490
491void CPDFSDK_BFAnnotHandler::OnDelete(CPDFSDK_Annot* pAnnot) {}
492
493void CPDFSDK_BFAnnotHandler::OnRelease(CPDFSDK_Annot* pAnnot) {}
494
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495void CPDFSDK_BFAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
496 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700497 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498 CFX_ByteString sSubType = pAnnot->GetSubType();
499
500 if (sSubType == BFFT_SIGNATURE) {
501 } else {
502 if (m_pFormFiller)
503 m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag);
504 }
505}
506void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
507 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700508 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509 CFX_ByteString sSubType = pAnnot->GetSubType();
510
511 if (sSubType == BFFT_SIGNATURE) {
512 } else {
513 if (m_pFormFiller)
514 m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag);
515 }
516}
517FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
518 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700519 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800520 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700521 CFX_ByteString sSubType = pAnnot->GetSubType();
522
523 if (sSubType == BFFT_SIGNATURE) {
524 } else {
525 if (m_pFormFiller)
526 return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point);
527 }
528
529 return FALSE;
530}
531
532FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
533 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700534 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800535 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700536 CFX_ByteString sSubType = pAnnot->GetSubType();
537
538 if (sSubType == BFFT_SIGNATURE) {
539 } else {
540 if (m_pFormFiller)
541 return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point);
542 }
543
544 return FALSE;
545}
546
547FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
548 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700549 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800550 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700551 CFX_ByteString sSubType = pAnnot->GetSubType();
552
553 if (sSubType == BFFT_SIGNATURE) {
554 } else {
555 if (m_pFormFiller)
556 return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
557 }
558
559 return FALSE;
560}
561
562FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
563 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700564 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800565 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700566 CFX_ByteString sSubType = pAnnot->GetSubType();
567
568 if (sSubType == BFFT_SIGNATURE) {
569 } else {
570 if (m_pFormFiller)
571 return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point);
572 }
573
574 return FALSE;
575}
576
577FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
578 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700579 uint32_t nFlags,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580 short zDelta,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800581 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700582 CFX_ByteString sSubType = pAnnot->GetSubType();
583
584 if (sSubType == BFFT_SIGNATURE) {
585 } else {
586 if (m_pFormFiller)
587 return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,
588 point);
589 }
590
591 return FALSE;
592}
593
594FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
595 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700596 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800597 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700598 CFX_ByteString sSubType = pAnnot->GetSubType();
599
600 if (sSubType == BFFT_SIGNATURE) {
601 } else {
602 if (m_pFormFiller)
603 return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point);
604 }
605
606 return FALSE;
607}
608FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
609 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700610 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800611 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700612 CFX_ByteString sSubType = pAnnot->GetSubType();
613
614 if (sSubType == BFFT_SIGNATURE) {
615 } else {
616 if (m_pFormFiller)
617 return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point);
618 }
619
620 return FALSE;
621}
622
weili625ad662016-06-15 11:21:33 -0700623FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView,
624 CPDFSDK_Annot* pAnnot,
625 uint32_t nFlags,
626 const CFX_FloatPoint& point) {
627 return FALSE;
628}
629
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700630FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700631 uint32_t nChar,
632 uint32_t nFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700633 CFX_ByteString sSubType = pAnnot->GetSubType();
634
635 if (sSubType == BFFT_SIGNATURE) {
636 } else {
637 if (m_pFormFiller)
638 return m_pFormFiller->OnChar(pAnnot, nChar, nFlags);
639 }
640
641 return FALSE;
642}
643
644FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
645 int nKeyCode,
646 int nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700647 CFX_ByteString sSubType = pAnnot->GetSubType();
648
649 if (sSubType == BFFT_SIGNATURE) {
650 } else {
651 if (m_pFormFiller)
652 return m_pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlag);
653 }
654
655 return FALSE;
656}
657
658FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
659 int nKeyCode,
660 int nFlag) {
661 return FALSE;
662}
663void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700664 CFX_ByteString sSubType = pAnnot->GetSubType();
665
666 if (sSubType == BFFT_SIGNATURE) {
667 } else {
668 if (m_pFormFiller)
669 m_pFormFiller->OnCreate(pAnnot);
670 }
671}
672
673void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {
Tom Sepez50d12ad2015-11-24 09:50:51 -0800674 if (pAnnot->GetSubType() == BFFT_SIGNATURE)
675 return;
676
tsepez77b909e2016-06-09 14:08:11 -0700677 CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot);
Tom Sepez50d12ad2015-11-24 09:50:51 -0800678 if (!pWidget->IsAppearanceValid())
thestig1cd352e2016-06-07 17:53:06 -0700679 pWidget->ResetAppearance(nullptr, FALSE);
Tom Sepez50d12ad2015-11-24 09:50:51 -0800680
681 int nFieldType = pWidget->GetFieldType();
682 if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) {
683 FX_BOOL bFormated = FALSE;
684 CFX_WideString sValue = pWidget->OnFormat(bFormated);
685 if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) {
686 pWidget->ResetAppearance(sValue.c_str(), FALSE);
687 }
688 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700689
Tom Sepez51da0932015-11-25 16:05:49 -0800690#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691 CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700692 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800693 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
694 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
695 if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty())
696 pWidget->ResetAppearance(FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700697 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800698#endif // PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800699 if (m_pFormFiller)
700 m_pFormFiller->OnLoad(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700701}
702
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700703FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700704 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700705 CFX_ByteString sSubType = pAnnot->GetSubType();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700706
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700707 if (sSubType == BFFT_SIGNATURE) {
708 } else {
709 if (m_pFormFiller)
710 return m_pFormFiller->OnSetFocus(pAnnot, nFlag);
711 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700712
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700713 return TRUE;
714}
715FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700716 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700717 CFX_ByteString sSubType = pAnnot->GetSubType();
718
719 if (sSubType == BFFT_SIGNATURE) {
720 } else {
721 if (m_pFormFiller)
722 return m_pFormFiller->OnKillFocus(pAnnot, nFlag);
723 }
724
725 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700726}
727
weili625ad662016-06-15 11:21:33 -0700728#ifdef PDF_ENABLE_XFA
729
730FX_BOOL CPDFSDK_BFAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot,
731 CPDFSDK_Annot* pNewAnnot) {
732 return TRUE;
733}
734
735#endif // PDF_ENABLE_XFA
736
Tom Sepez281a9ea2016-02-26 14:24:28 -0800737CFX_FloatRect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
738 CPDFSDK_Annot* pAnnot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700739 CFX_ByteString sSubType = pAnnot->GetSubType();
Tom Sepezd5e7b352016-02-29 11:24:29 -0800740 if (sSubType != BFFT_SIGNATURE && m_pFormFiller)
741 return CFX_FloatRect(m_pFormFiller->GetViewBBox(pPageView, pAnnot));
Lei Zhang60f507b2015-06-13 00:41:00 -0700742
Tom Sepez281a9ea2016-02-26 14:24:28 -0800743 return CFX_FloatRect(0, 0, 0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700744}
745
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700746FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
747 CPDFSDK_Annot* pAnnot,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800748 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700749 ASSERT(pPageView);
750 ASSERT(pAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700751
Tom Sepez281a9ea2016-02-26 14:24:28 -0800752 CFX_FloatRect rect = GetViewBBox(pPageView, pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700753 return rect.Contains(point.x, point.y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700754}
755
Tom Sepez51da0932015-11-25 16:05:49 -0800756#ifdef PDF_ENABLE_XFA
Lei Zhang60f507b2015-06-13 00:41:00 -0700757
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700758CPDFSDK_XFAAnnotHandler::CPDFSDK_XFAAnnotHandler(CPDFDoc_Environment* pApp)
759 : m_pApp(pApp) {}
760
weili625ad662016-06-15 11:21:33 -0700761CPDFSDK_XFAAnnotHandler::~CPDFSDK_XFAAnnotHandler() {}
762
763CFX_ByteString CPDFSDK_XFAAnnotHandler::GetType() {
764 return FSDK_XFAWIDGET_TYPENAME;
765}
766
767CFX_ByteString CPDFSDK_XFAAnnotHandler::GetName() {
768 return "XFAWidgetHandler";
769}
770
771FX_BOOL CPDFSDK_XFAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
772 return !!pAnnot->GetXFAWidget();
773}
774
775CPDFSDK_Annot* CPDFSDK_XFAAnnotHandler::NewAnnot(CPDF_Annot* pAnnot,
776 CPDFSDK_PageView* pPage) {
777 return nullptr;
778}
779
dsinclairdf4bc592016-03-31 20:34:43 -0700780CPDFSDK_Annot* CPDFSDK_XFAAnnotHandler::NewAnnot(CXFA_FFWidget* pAnnot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700781 CPDFSDK_PageView* pPage) {
782 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument();
tsepez23ae4a52016-06-08 20:44:54 -0700783 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700784 CPDFSDK_XFAWidget* pWidget = new CPDFSDK_XFAWidget(pAnnot, pPage, pInterForm);
785 pInterForm->AddXFAMap(pAnnot, pWidget);
786 return pWidget;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700787}
788
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700789void CPDFSDK_XFAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
790 CPDFSDK_Annot* pAnnot,
791 CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800792 CFX_Matrix* pUser2Device,
tsepezc3255f52016-03-25 14:52:27 -0700793 uint32_t dwFlags) {
thestig1cd352e2016-06-07 17:53:06 -0700794 ASSERT(pPageView);
795 ASSERT(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700796
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700797 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
dsinclairdf4bc592016-03-31 20:34:43 -0700798 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700799
800 CFX_Graphics gs;
801 gs.Create(pDevice);
802
803 CFX_Matrix mt;
804 mt = *(CFX_Matrix*)pUser2Device;
805
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700806 FX_BOOL bIsHighlight = FALSE;
807 if (pSDKDoc->GetFocusAnnot() != pAnnot)
808 bIsHighlight = TRUE;
809
810 pWidgetHandler->RenderWidget(pAnnot->GetXFAWidget(), &gs, &mt, bIsHighlight);
811
812 // to do highlight and shadow
813}
814
weili625ad662016-06-15 11:21:33 -0700815void CPDFSDK_XFAAnnotHandler::OnDrawSleep(CPDFSDK_PageView* pPageView,
816 CPDFSDK_Annot* pAnnot,
817 CFX_RenderDevice* pDevice,
818 CFX_Matrix* pUser2Device,
819 const CFX_FloatRect& rcWindow,
820 uint32_t dwFlags) {}
821
822void CPDFSDK_XFAAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) {}
823
824void CPDFSDK_XFAAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {}
825
826void CPDFSDK_XFAAnnotHandler::OnDelete(CPDFSDK_Annot* pAnnot) {}
827
828void CPDFSDK_XFAAnnotHandler::OnRelease(CPDFSDK_Annot* pAnnot) {}
829
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700830void CPDFSDK_XFAAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700831 CPDFSDK_XFAWidget* pWidget = (CPDFSDK_XFAWidget*)pAnnot;
832 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700833 pInterForm->RemoveXFAMap(pWidget->GetXFAWidget());
834
835 delete pWidget;
836}
837
weili625ad662016-06-15 11:21:33 -0700838void CPDFSDK_XFAAnnotHandler::DeleteAnnot(CPDFSDK_Annot* pAnnot) {}
839
Tom Sepez281a9ea2016-02-26 14:24:28 -0800840CFX_FloatRect CPDFSDK_XFAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
841 CPDFSDK_Annot* pAnnot) {
Lei Zhang5eca3052016-02-22 20:32:21 -0800842 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700843
Tom Sepeza8a39e22015-10-12 15:47:07 -0700844 CFX_RectF rcBBox;
dsinclair56a8b192016-06-21 14:15:25 -0700845 XFA_Element eType = pAnnot->GetXFAWidget()->GetDataAcc()->GetUIType();
846 if (eType == XFA_Element::Signature)
dsinclair935d8d52016-05-17 10:32:18 -0700847 pAnnot->GetXFAWidget()->GetBBox(rcBBox, XFA_WidgetStatus_Visible, TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700848 else
dsinclair935d8d52016-05-17 10:32:18 -0700849 pAnnot->GetXFAWidget()->GetBBox(rcBBox, XFA_WidgetStatus_None);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700850
851 CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
852 rcBBox.top + rcBBox.height);
853 rcWidget.left -= 1.0f;
854 rcWidget.right += 1.0f;
855 rcWidget.bottom -= 1.0f;
856 rcWidget.top += 1.0f;
857
858 return rcWidget;
859}
860
861FX_BOOL CPDFSDK_XFAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
862 CPDFSDK_Annot* pAnnot,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800863 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700864 if (!pPageView || !pAnnot)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700865 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700866
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700867 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
868 if (!pSDKDoc)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700869 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700870
Tom Sepez50d12ad2015-11-24 09:50:51 -0800871 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700872 if (!pDoc)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700873 return FALSE;
Lei Zhang60f507b2015-06-13 00:41:00 -0700874
dsinclairdf4bc592016-03-31 20:34:43 -0700875 CXFA_FFDocView* pDocView = pDoc->GetXFADocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700876 if (!pDocView)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700877 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700878
dsinclairdf4bc592016-03-31 20:34:43 -0700879 CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700880 if (!pWidgetHandler)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700881 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700882
dsinclair89fcde82016-05-03 13:00:25 -0700883 FWL_WidgetHit dwHitTest =
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700884 pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point.x, point.y);
dsinclair89fcde82016-05-03 13:00:25 -0700885 return dwHitTest != FWL_WidgetHit::Unknown;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700886}
887
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700888void CPDFSDK_XFAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
889 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700890 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700891 if (!pPageView || !pAnnot)
892 return;
dsinclairdf4bc592016-03-31 20:34:43 -0700893 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700894 pWidgetHandler->OnMouseEnter(pAnnot->GetXFAWidget());
895}
Lei Zhang60f507b2015-06-13 00:41:00 -0700896
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700897void CPDFSDK_XFAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
898 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700899 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700900 if (!pPageView || !pAnnot)
901 return;
902
dsinclairdf4bc592016-03-31 20:34:43 -0700903 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700904 pWidgetHandler->OnMouseExit(pAnnot->GetXFAWidget());
905}
906
907FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
908 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700909 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800910 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700911 if (!pPageView || !pAnnot)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700912 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700913
dsinclairdf4bc592016-03-31 20:34:43 -0700914 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800915 return pWidgetHandler->OnLButtonDown(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700916 GetFWLFlags(nFlags), point.x, point.y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700917}
918
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700919FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
920 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700921 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800922 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700923 if (!pPageView || !pAnnot)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700924 return FALSE;
Lei Zhang60f507b2015-06-13 00:41:00 -0700925
dsinclairdf4bc592016-03-31 20:34:43 -0700926 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800927 return pWidgetHandler->OnLButtonUp(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700928 GetFWLFlags(nFlags), point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700929}
930
931FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
932 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700933 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800934 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700935 if (!pPageView || !pAnnot)
936 return FALSE;
937
dsinclairdf4bc592016-03-31 20:34:43 -0700938 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800939 return pWidgetHandler->OnLButtonDblClk(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700940 GetFWLFlags(nFlags), point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700941}
942
943FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
944 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700945 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800946 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700947 if (!pPageView || !pAnnot)
948 return FALSE;
949
dsinclairdf4bc592016-03-31 20:34:43 -0700950 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800951 return pWidgetHandler->OnMouseMove(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700952 GetFWLFlags(nFlags), point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700953}
954
955FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
956 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700957 uint32_t nFlags,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700958 short zDelta,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800959 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700960 if (!pPageView || !pAnnot)
961 return FALSE;
962
dsinclairdf4bc592016-03-31 20:34:43 -0700963 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800964 return pWidgetHandler->OnMouseWheel(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700965 pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), zDelta, point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700966}
967
968FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
969 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700970 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800971 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700972 if (!pPageView || !pAnnot)
973 return FALSE;
974
dsinclairdf4bc592016-03-31 20:34:43 -0700975 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800976 return pWidgetHandler->OnRButtonDown(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700977 GetFWLFlags(nFlags), point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700978}
979
980FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
981 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700982 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800983 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700984 if (!pPageView || !pAnnot)
985 return FALSE;
986
dsinclairdf4bc592016-03-31 20:34:43 -0700987 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800988 return pWidgetHandler->OnRButtonUp(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700989 GetFWLFlags(nFlags), point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700990}
991
992FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView,
993 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700994 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800995 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700996 if (!pPageView || !pAnnot)
997 return FALSE;
998
dsinclairdf4bc592016-03-31 20:34:43 -0700999 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -08001000 return pWidgetHandler->OnRButtonDblClk(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001001 GetFWLFlags(nFlags), point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001002}
1003
1004FX_BOOL CPDFSDK_XFAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -07001005 uint32_t nChar,
1006 uint32_t nFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001007 if (!pAnnot)
1008 return FALSE;
1009
dsinclairdf4bc592016-03-31 20:34:43 -07001010 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -08001011 return pWidgetHandler->OnChar(pAnnot->GetXFAWidget(), nChar,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001012 GetFWLFlags(nFlags));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001013}
1014
1015FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
1016 int nKeyCode,
1017 int nFlag) {
1018 if (!pAnnot)
1019 return FALSE;
1020
dsinclairdf4bc592016-03-31 20:34:43 -07001021 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -08001022 return pWidgetHandler->OnKeyDown(pAnnot->GetXFAWidget(), nKeyCode,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001023 GetFWLFlags(nFlag));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001024}
1025
1026FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
1027 int nKeyCode,
1028 int nFlag) {
1029 if (!pAnnot)
1030 return FALSE;
1031
dsinclairdf4bc592016-03-31 20:34:43 -07001032 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -08001033 return pWidgetHandler->OnKeyUp(pAnnot->GetXFAWidget(), nKeyCode,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001034 GetFWLFlags(nFlag));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001035}
1036
weili625ad662016-06-15 11:21:33 -07001037void CPDFSDK_XFAAnnotHandler::OnDeSelected(CPDFSDK_Annot* pAnnot) {}
1038
1039void CPDFSDK_XFAAnnotHandler::OnSelected(CPDFSDK_Annot* pAnnot) {}
1040
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001041FX_BOOL CPDFSDK_XFAAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -07001042 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001043 return TRUE;
1044}
1045
1046FX_BOOL CPDFSDK_XFAAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -07001047 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001048 return TRUE;
1049}
1050
1051FX_BOOL CPDFSDK_XFAAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot,
1052 CPDFSDK_Annot* pNewAnnot) {
thestig1cd352e2016-06-07 17:53:06 -07001053 CXFA_FFWidgetHandler* pWidgetHandler = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001054
1055 if (pOldAnnot)
1056 pWidgetHandler = GetXFAWidgetHandler(pOldAnnot);
1057 else if (pNewAnnot)
1058 pWidgetHandler = GetXFAWidgetHandler(pNewAnnot);
1059
1060 if (pWidgetHandler) {
1061 FX_BOOL bRet = TRUE;
thestig1cd352e2016-06-07 17:53:06 -07001062 CXFA_FFWidget* hWidget = pNewAnnot ? pNewAnnot->GetXFAWidget() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001063 if (hWidget) {
dsinclair221caf62016-04-04 12:08:40 -07001064 CXFA_FFPageView* pXFAPageView = hWidget->GetPageView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001065 if (pXFAPageView) {
1066 bRet = pXFAPageView->GetDocView()->SetFocus(hWidget);
1067 if (pXFAPageView->GetDocView()->GetFocusWidget() == hWidget)
1068 bRet = TRUE;
1069 }
Tom Sepezdcbc02f2015-07-17 09:16:17 -07001070 }
Tom Sepezdcbc02f2015-07-17 09:16:17 -07001071 return bRet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001072 }
1073
1074 return TRUE;
Bo Xufdc00a72014-10-28 23:03:33 -07001075}
1076
dsinclairdf4bc592016-03-31 20:34:43 -07001077CXFA_FFWidgetHandler* CPDFSDK_XFAAnnotHandler::GetXFAWidgetHandler(
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001078 CPDFSDK_Annot* pAnnot) {
1079 if (!pAnnot)
thestig1cd352e2016-06-07 17:53:06 -07001080 return nullptr;
Bo Xufdc00a72014-10-28 23:03:33 -07001081
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001082 CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
1083 if (!pPageView)
thestig1cd352e2016-06-07 17:53:06 -07001084 return nullptr;
Bo Xufdc00a72014-10-28 23:03:33 -07001085
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001086 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
1087 if (!pSDKDoc)
thestig1cd352e2016-06-07 17:53:06 -07001088 return nullptr;
Bo Xufdc00a72014-10-28 23:03:33 -07001089
Tom Sepez50d12ad2015-11-24 09:50:51 -08001090 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001091 if (!pDoc)
thestig1cd352e2016-06-07 17:53:06 -07001092 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001093
dsinclairdf4bc592016-03-31 20:34:43 -07001094 CXFA_FFDocView* pDocView = pDoc->GetXFADocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001095 if (!pDocView)
thestig1cd352e2016-06-07 17:53:06 -07001096 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001097
1098 return pDocView->GetWidgetHandler();
Bo Xufdc00a72014-10-28 23:03:33 -07001099}
1100
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001101#define FWL_KEYFLAG_Ctrl (1 << 0)
1102#define FWL_KEYFLAG_Alt (1 << 1)
1103#define FWL_KEYFLAG_Shift (1 << 2)
1104#define FWL_KEYFLAG_LButton (1 << 3)
1105#define FWL_KEYFLAG_RButton (1 << 4)
1106#define FWL_KEYFLAG_MButton (1 << 5)
Bo Xufdc00a72014-10-28 23:03:33 -07001107
tsepezc3255f52016-03-25 14:52:27 -07001108uint32_t CPDFSDK_XFAAnnotHandler::GetFWLFlags(uint32_t dwFlag) {
1109 uint32_t dwFWLFlag = 0;
Bo Xufdc00a72014-10-28 23:03:33 -07001110
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001111 if (dwFlag & FWL_EVENTFLAG_ControlKey)
1112 dwFWLFlag |= FWL_KEYFLAG_Ctrl;
1113 if (dwFlag & FWL_EVENTFLAG_LeftButtonDown)
1114 dwFWLFlag |= FWL_KEYFLAG_LButton;
1115 if (dwFlag & FWL_EVENTFLAG_MiddleButtonDown)
1116 dwFWLFlag |= FWL_KEYFLAG_MButton;
1117 if (dwFlag & FWL_EVENTFLAG_RightButtonDown)
1118 dwFWLFlag |= FWL_KEYFLAG_RButton;
1119 if (dwFlag & FWL_EVENTFLAG_ShiftKey)
1120 dwFWLFlag |= FWL_KEYFLAG_Shift;
1121 if (dwFlag & FWL_EVENTFLAG_AltKey)
1122 dwFWLFlag |= FWL_KEYFLAG_Alt;
Bo Xufdc00a72014-10-28 23:03:33 -07001123
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001124 return dwFWLFlag;
Bo Xufdc00a72014-10-28 23:03:33 -07001125}
Tom Sepez40e9ff32015-11-30 12:39:54 -08001126#endif // PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -07001127
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001128CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView,
Lei Zhangbf60b292015-10-26 12:14:35 -07001129 bool bReverse)
1130 : m_bReverse(bReverse), m_pos(0) {
1131 const std::vector<CPDFSDK_Annot*>& annots = pPageView->GetAnnotList();
1132 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), annots.rbegin(),
1133 annots.rend());
1134 std::stable_sort(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(),
1135 [](CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) {
1136 return p1->GetLayoutOrder() < p2->GetLayoutOrder();
1137 });
Bo Xufdc00a72014-10-28 23:03:33 -07001138
Lei Zhangbf60b292015-10-26 12:14:35 -07001139 CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot();
1140 if (!pTopMostAnnot)
1141 return;
Lei Zhang60f507b2015-06-13 00:41:00 -07001142
Lei Zhangbf60b292015-10-26 12:14:35 -07001143 auto it = std::find(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(),
1144 pTopMostAnnot);
1145 if (it != m_iteratorAnnotList.end()) {
1146 CPDFSDK_Annot* pReaderAnnot = *it;
1147 m_iteratorAnnotList.erase(it);
1148 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), pReaderAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001149 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001150}
1151
Dan Sinclairf766ad22016-03-14 13:51:24 -04001152CPDFSDK_AnnotIterator::~CPDFSDK_AnnotIterator() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001153
Lei Zhangbf60b292015-10-26 12:14:35 -07001154CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot() {
1155 if (m_pos < m_iteratorAnnotList.size())
1156 return m_iteratorAnnotList[m_pos++];
1157 return nullptr;
1158}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001159
Lei Zhangbf60b292015-10-26 12:14:35 -07001160CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot() {
1161 if (m_pos < m_iteratorAnnotList.size())
1162 return m_iteratorAnnotList[m_iteratorAnnotList.size() - ++m_pos];
1163 return nullptr;
1164}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001165
Lei Zhangbf60b292015-10-26 12:14:35 -07001166CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next() {
1167 return m_bReverse ? PrevAnnot() : NextAnnot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001168}