blob: 2185562668b6f42b404e01f7d95a7fdb8aafa687 [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"
Dan Sinclairedbb3192016-03-21 09:08:24 -040014#include "fpdfsdk/formfiller/cffl_formfiller.h"
Lei Zhangbde53d22015-11-12 22:21:30 -080015#include "fpdfsdk/include/fsdk_define.h"
16#include "fpdfsdk/include/fsdk_mgr.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070017
Tom Sepez40e9ff32015-11-30 12:39:54 -080018#ifdef PDF_ENABLE_XFA
dsinclair89bdd082016-04-06 10:47:54 -070019#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
20#include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h"
21#include "fpdfsdk/fpdfxfa/include/fpdfxfa_util.h"
dsinclair89fcde82016-05-03 13:00:25 -070022#include "xfa/fwl/core/include/fwl_widgethit.h"
dsinclair7222ea62016-04-06 14:33:07 -070023#include "xfa/fxfa/include/xfa_ffwidget.h"
weili625ad662016-06-15 11:21:33 -070024#include "xfa/fxfa/include/xfa_ffdocview.h"
25#include "xfa/fxfa/include/xfa_ffpageview.h"
26#include "xfa/fxfa/include/xfa_ffwidgethandler.h"
Dan Sinclair811b8a42016-03-17 08:59:42 -040027#include "xfa/fxgraphics/include/cfx_graphics.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080028#endif // PDF_ENABLE_XFA
29
Nico Weber9d8ec5a2015-08-04 13:00:21 -070030CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) {
31 m_pApp = pApp;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070032
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp);
34 pHandler->SetFormFiller(m_pApp->GetIFormFiller());
35 RegisterAnnotHandler(pHandler);
Tom Sepez51da0932015-11-25 16:05:49 -080036#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037 CPDFSDK_XFAAnnotHandler* pXFAAnnotHandler =
38 new CPDFSDK_XFAAnnotHandler(m_pApp);
39 RegisterAnnotHandler(pXFAAnnotHandler);
Tom Sepez40e9ff32015-11-30 12:39:54 -080040#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070041}
42
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {
44 for (int i = 0; i < m_Handlers.GetSize(); i++) {
45 IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i);
46 delete pHandler;
47 }
48 m_Handlers.RemoveAll();
Tom Sepez09d33bc2015-08-19 09:49:24 -070049 m_mapType2Handler.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070050}
51
52void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler(
53 IPDFSDK_AnnotHandler* pAnnotHandler) {
Tom Sepez09d33bc2015-08-19 09:49:24 -070054 ASSERT(!GetAnnotHandler(pAnnotHandler->GetType()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055
56 m_Handlers.Add(pAnnotHandler);
Tom Sepez09d33bc2015-08-19 09:49:24 -070057 m_mapType2Handler[pAnnotHandler->GetType()] = pAnnotHandler;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070058}
59
60void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler(
61 IPDFSDK_AnnotHandler* pAnnotHandler) {
Tom Sepez09d33bc2015-08-19 09:49:24 -070062 m_mapType2Handler.erase(pAnnotHandler->GetType());
Nico Weber9d8ec5a2015-08-04 13:00:21 -070063 for (int i = 0, sz = m_Handlers.GetSize(); i < sz; i++) {
64 if (m_Handlers.GetAt(i) == pAnnotHandler) {
65 m_Handlers.RemoveAt(i);
66 break;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070067 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070068 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070069}
70
Nico Weber9d8ec5a2015-08-04 13:00:21 -070071CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot,
72 CPDFSDK_PageView* pPageView) {
Lei Zhang96660d62015-12-14 18:27:25 -080073 ASSERT(pPageView);
Lei Zhang60f507b2015-06-13 00:41:00 -070074
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075 if (IPDFSDK_AnnotHandler* pAnnotHandler =
76 GetAnnotHandler(pAnnot->GetSubType())) {
77 return pAnnotHandler->NewAnnot(pAnnot, pPageView);
78 }
Lei Zhang60f507b2015-06-13 00:41:00 -070079
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080 return new CPDFSDK_BAAnnot(pAnnot, pPageView);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070081}
82
Tom Sepez51da0932015-11-25 16:05:49 -080083#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -070084CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CXFA_FFWidget* pAnnot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070085 CPDFSDK_PageView* pPageView) {
Lei Zhang5eca3052016-02-22 20:32:21 -080086 ASSERT(pAnnot);
87 ASSERT(pPageView);
Lei Zhang60f507b2015-06-13 00:41:00 -070088
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089 if (IPDFSDK_AnnotHandler* pAnnotHandler =
90 GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME)) {
91 return pAnnotHandler->NewAnnot(pAnnot, pPageView);
92 }
Lei Zhang60f507b2015-06-13 00:41:00 -070093
thestig1cd352e2016-06-07 17:53:06 -070094 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070095}
Tom Sepez40e9ff32015-11-30 12:39:54 -080096#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070097
Nico Weber9d8ec5a2015-08-04 13:00:21 -070098void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070099 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
100 pAnnotHandler->OnRelease(pAnnot);
101 pAnnotHandler->ReleaseAnnot(pAnnot);
102 } else {
tsepez77b909e2016-06-09 14:08:11 -0700103 delete pAnnot;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700104 }
Bo Xufdc00a72014-10-28 23:03:33 -0700105}
106
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
Bo Xufdc00a72014-10-28 23:03:33 -0700109
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700110 CPDFSDK_DateTime curTime;
111 pPDFAnnot->GetAnnotDict()->SetAtString("M", curTime.ToPDFDateTimeString());
112 pPDFAnnot->GetAnnotDict()->SetAtNumber("F", 0);
113
114 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
115 pAnnotHandler->OnCreate(pAnnot);
116 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700117}
118
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700119void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) {
Lei Zhang96660d62015-12-14 18:27:25 -0800120 ASSERT(pAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700121
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700122 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
123 pAnnotHandler->OnLoad(pAnnot);
124 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700125}
126
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
128 CPDFSDK_Annot* pAnnot) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700129 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
130 if (pPDFAnnot)
131 return GetAnnotHandler(pPDFAnnot->GetSubType());
Tom Sepez51da0932015-11-25 16:05:49 -0800132#ifdef PDF_ENABLE_XFA
Tom Sepezc7e4c4f2015-11-20 09:45:24 -0800133 if (pAnnot->GetXFAWidget())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700134 return GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800135#endif // PDF_ENABLE_XFA
Tom Sepezc7e4c4f2015-11-20 09:45:24 -0800136 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700137}
138
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700139IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
140 const CFX_ByteString& sType) const {
Tom Sepez09d33bc2015-08-19 09:49:24 -0700141 auto it = m_mapType2Handler.find(sType);
142 return it != m_mapType2Handler.end() ? it->second : nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700143}
144
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView,
146 CPDFSDK_Annot* pAnnot,
147 CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800148 CFX_Matrix* pUser2Device,
tsepezc3255f52016-03-25 14:52:27 -0700149 uint32_t dwFlags) {
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500150 ASSERT(pAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700151
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700152 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
153 pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
154 } else {
Tom Sepez51da0932015-11-25 16:05:49 -0800155#ifdef PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800156 if (pAnnot->IsXFAField())
157 return;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800158#endif // PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800159 static_cast<CPDFSDK_BAAnnot*>(pAnnot)
160 ->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700161 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700162}
163
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700164FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(
165 CPDFSDK_PageView* pPageView,
166 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700167 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800168 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800169 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700170
171 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
172 return pAnnotHandler->OnLButtonDown(pPageView, pAnnot, nFlags, point);
173 }
174 return FALSE;
175}
Tom Sepez281a9ea2016-02-26 14:24:28 -0800176FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(
177 CPDFSDK_PageView* pPageView,
178 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700179 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800180 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800181 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700182
183 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
184 return pAnnotHandler->OnLButtonUp(pPageView, pAnnot, nFlags, point);
185 }
186 return FALSE;
187}
188FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(
189 CPDFSDK_PageView* pPageView,
190 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700191 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800192 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800193 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700194
195 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
196 return pAnnotHandler->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
197 }
198 return FALSE;
199}
Tom Sepez281a9ea2016-02-26 14:24:28 -0800200FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(
201 CPDFSDK_PageView* pPageView,
202 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700203 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800204 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800205 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206
207 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
208 return pAnnotHandler->OnMouseMove(pPageView, pAnnot, nFlags, point);
209 }
210 return FALSE;
211}
Tom Sepez281a9ea2016-02-26 14:24:28 -0800212FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(
213 CPDFSDK_PageView* pPageView,
214 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700215 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800216 short zDelta,
217 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800218 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219
220 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
221 return pAnnotHandler->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,
222 point);
223 }
224 return FALSE;
225}
226FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(
227 CPDFSDK_PageView* pPageView,
228 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700229 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800230 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800231 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232
233 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
234 return pAnnotHandler->OnRButtonDown(pPageView, pAnnot, nFlags, point);
235 }
236 return FALSE;
237}
Tom Sepez281a9ea2016-02-26 14:24:28 -0800238FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(
239 CPDFSDK_PageView* pPageView,
240 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700241 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800242 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800243 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700244
245 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
246 return pAnnotHandler->OnRButtonUp(pPageView, pAnnot, nFlags, point);
247 }
248 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700249}
250
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700251void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(CPDFSDK_PageView* pPageView,
252 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700253 uint32_t nFlag) {
Lei Zhang96660d62015-12-14 18:27:25 -0800254 ASSERT(pAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700255
Lei Zhang05e67412016-01-25 16:35:42 -0800256 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700257 pAnnotHandler->OnMouseEnter(pPageView, pAnnot, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700258}
259
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700260void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(CPDFSDK_PageView* pPageView,
261 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700262 uint32_t nFlag) {
Lei Zhang96660d62015-12-14 18:27:25 -0800263 ASSERT(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700264
Lei Zhang05e67412016-01-25 16:35:42 -0800265 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700266 pAnnotHandler->OnMouseExit(pPageView, pAnnot, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700267}
268
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700269FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700270 uint32_t nChar,
271 uint32_t nFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700272 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
273 return pAnnotHandler->OnChar(pAnnot, nChar, nFlags);
274 }
275 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700276}
277
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700278FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot,
279 int nKeyCode,
280 int nFlag) {
281 if (!m_pApp->FFI_IsCTRLKeyDown(nFlag) && !m_pApp->FFI_IsALTKeyDown(nFlag)) {
282 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
283 CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();
284 if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) {
285 CPDFSDK_Annot* pNext =
286 GetNextAnnot(pFocusAnnot, !m_pApp->FFI_IsSHIFTKeyDown(nFlag));
Lei Zhang60f507b2015-06-13 00:41:00 -0700287
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288 if (pNext && pNext != pFocusAnnot) {
289 CPDFSDK_Document* pDocument = pPage->GetSDKDocument();
290 pDocument->SetFocusAnnot(pNext);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700291 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292 }
293 }
294 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700295
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
297 return pAnnotHandler->OnKeyDown(pAnnot, nKeyCode, nFlag);
298 }
299 return FALSE;
300}
301FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot,
302 int nKeyCode,
303 int nFlag) {
304 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700305}
306
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700308 uint32_t nFlag) {
Lei Zhang96660d62015-12-14 18:27:25 -0800309 ASSERT(pAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700310
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700311 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
312 if (pAnnotHandler->OnSetFocus(pAnnot, nFlag)) {
313 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
314 pPage->GetSDKDocument();
315 return TRUE;
316 }
317 }
318 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700319}
320
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700321FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700322 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323 ASSERT(pAnnot);
324 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
325 return pAnnotHandler->OnKillFocus(pAnnot, nFlag);
326
327 return FALSE;
328}
329
Tom Sepez51da0932015-11-25 16:05:49 -0800330#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700331FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus(
332 CPDFSDK_Annot* pSetAnnot,
333 CPDFSDK_Annot* pKillAnnot) {
334 FX_BOOL bXFA = (pSetAnnot && pSetAnnot->GetXFAWidget()) ||
335 (pKillAnnot && pKillAnnot->GetXFAWidget());
336
337 if (bXFA) {
338 if (IPDFSDK_AnnotHandler* pXFAAnnotHandler =
339 GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME))
340 return pXFAAnnotHandler->OnXFAChangedFocus(pKillAnnot, pSetAnnot);
341 }
342
343 return TRUE;
344}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800345#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700346
Tom Sepez281a9ea2016-02-26 14:24:28 -0800347CFX_FloatRect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700348 CPDFSDK_PageView* pPageView,
349 CPDFSDK_Annot* pAnnot) {
350 ASSERT(pAnnot);
351 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
352 return pAnnotHandler->GetViewBBox(pPageView, pAnnot);
353
354 return pAnnot->GetRect();
355}
356
357FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView,
358 CPDFSDK_Annot* pAnnot,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800359 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360 ASSERT(pAnnot);
361 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
362 if (pAnnotHandler->CanAnswer(pAnnot))
363 return pAnnotHandler->HitTest(pPageView, pAnnot, point);
364 }
365 return FALSE;
366}
367
368CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,
369 FX_BOOL bNext) {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800370#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700371 CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView();
372 CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage();
thestig1cd352e2016-06-07 17:53:06 -0700373 if (!pPage)
374 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700375 if (pPage->GetPDFPage()) { // for pdf annots.
376 CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), pSDKAnnot->GetType(), "");
377 CPDFSDK_Annot* pNext =
378 bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot);
379 return pNext;
380 }
381 // for xfa annots
tsepezcc4d6d82016-05-16 13:21:03 -0700382 std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700383 pPage->GetXFAPageView()->CreateWidgetIterator(
dsinclair935d8d52016-05-17 10:32:18 -0700384 XFA_TRAVERSEWAY_Tranvalse, XFA_WidgetStatus_Visible |
385 XFA_WidgetStatus_Viewable |
386 XFA_WidgetStatus_Focused));
tsepezcc4d6d82016-05-16 13:21:03 -0700387 if (!pWidgetIterator)
388 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700389 if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget())
390 pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget());
tsepezcc4d6d82016-05-16 13:21:03 -0700391 CXFA_FFWidget* hNextFocus =
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700392 bNext ? pWidgetIterator->MoveToNext() : pWidgetIterator->MoveToPrevious();
Lei Zhang5eca3052016-02-22 20:32:21 -0800393 if (!hNextFocus && pSDKAnnot)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700394 hNextFocus = pWidgetIterator->MoveToFirst();
395
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700396 return pPageView->GetAnnotByXFAWidget(hNextFocus);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800397#else // PDF_ENABLE_XFA
398 CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), "Widget", "");
399 return bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot);
400#endif // PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -0700401}
402
weili625ad662016-06-15 11:21:33 -0700403CPDFSDK_BFAnnotHandler::CPDFSDK_BFAnnotHandler(CPDFDoc_Environment* pApp)
404 : m_pApp(pApp), m_pFormFiller(nullptr) {}
405
406CPDFSDK_BFAnnotHandler::~CPDFSDK_BFAnnotHandler() {}
407
408CFX_ByteString CPDFSDK_BFAnnotHandler::GetType() {
409 return CFX_ByteString("Widget");
410}
411
412CFX_ByteString CPDFSDK_BFAnnotHandler::GetName() {
413 return CFX_ByteString("WidgetHandler");
414}
415
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700416FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
417 ASSERT(pAnnot->GetType() == "Widget");
418 if (pAnnot->GetSubType() == BFFT_SIGNATURE)
419 return FALSE;
420
tsepez77b909e2016-06-09 14:08:11 -0700421 CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700422 if (!pWidget->IsVisible())
423 return FALSE;
424
425 int nFieldFlags = pWidget->GetFieldFlags();
426 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
427 return FALSE;
428
429 if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON)
430 return TRUE;
431
432 CPDF_Page* pPage = pWidget->GetPDFPage();
433 CPDF_Document* pDocument = pPage->m_pDocument;
tsepezc3255f52016-03-25 14:52:27 -0700434 uint32_t dwPermissions = pDocument->GetUserPermissions();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700435 return (dwPermissions & FPDFPERM_FILL_FORM) ||
436 (dwPermissions & FPDFPERM_ANNOT_FORM);
437}
438
439CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot,
440 CPDFSDK_PageView* pPage) {
441 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument();
tsepez23ae4a52016-06-08 20:44:54 -0700442 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700443 CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl(
444 pInterForm->GetInterForm(), pAnnot->GetAnnotDict());
445 if (!pCtrl)
446 return nullptr;
447
448 CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm);
449 pInterForm->AddMap(pCtrl, pWidget);
450 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
451 if (pPDFInterForm && pPDFInterForm->NeedConstructAP())
452 pWidget->ResetAppearance(nullptr, FALSE);
453
454 return pWidget;
455}
456
Tom Sepez51da0932015-11-25 16:05:49 -0800457#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -0700458CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CXFA_FFWidget* hWidget,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700459 CPDFSDK_PageView* pPage) {
thestig1cd352e2016-06-07 17:53:06 -0700460 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800462#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463
464void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
Lei Zhang96660d62015-12-14 18:27:25 -0800465 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466
467 if (m_pFormFiller)
468 m_pFormFiller->OnDelete(pAnnot);
469
tsepez77b909e2016-06-09 14:08:11 -0700470 std::unique_ptr<CPDFSDK_Widget> pWidget(static_cast<CPDFSDK_Widget*>(pAnnot));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
tsepez77b909e2016-06-09 14:08:11 -0700472 CPDF_FormControl* pControl = pWidget->GetFormControl();
473 pInterForm->RemoveMap(pControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700474}
475
weili625ad662016-06-15 11:21:33 -0700476void CPDFSDK_BFAnnotHandler::DeleteAnnot(CPDFSDK_Annot* pAnnot) {}
477
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478void CPDFSDK_BFAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
479 CPDFSDK_Annot* pAnnot,
480 CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800481 CFX_Matrix* pUser2Device,
tsepezc3255f52016-03-25 14:52:27 -0700482 uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700483 CFX_ByteString sSubType = pAnnot->GetSubType();
484
485 if (sSubType == BFFT_SIGNATURE) {
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500486 static_cast<CPDFSDK_BAAnnot*>(pAnnot)
487 ->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700488 } else {
489 if (m_pFormFiller) {
490 m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
491 }
492 }
493}
494
weili625ad662016-06-15 11:21:33 -0700495void CPDFSDK_BFAnnotHandler::OnDrawSleep(CPDFSDK_PageView* pPageView,
496 CPDFSDK_Annot* pAnnot,
497 CFX_RenderDevice* pDevice,
498 CFX_Matrix* pUser2Device,
499 const CFX_FloatRect& rcWindow,
500 uint32_t dwFlags) {}
501
502void CPDFSDK_BFAnnotHandler::OnDelete(CPDFSDK_Annot* pAnnot) {}
503
504void CPDFSDK_BFAnnotHandler::OnRelease(CPDFSDK_Annot* pAnnot) {}
505
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700506void CPDFSDK_BFAnnotHandler::OnMouseEnter(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->OnMouseEnter(pPageView, pAnnot, nFlag);
515 }
516}
517void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
518 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700519 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520 CFX_ByteString sSubType = pAnnot->GetSubType();
521
522 if (sSubType == BFFT_SIGNATURE) {
523 } else {
524 if (m_pFormFiller)
525 m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag);
526 }
527}
528FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
529 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700530 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800531 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532 CFX_ByteString sSubType = pAnnot->GetSubType();
533
534 if (sSubType == BFFT_SIGNATURE) {
535 } else {
536 if (m_pFormFiller)
537 return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point);
538 }
539
540 return FALSE;
541}
542
543FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
544 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700545 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800546 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547 CFX_ByteString sSubType = pAnnot->GetSubType();
548
549 if (sSubType == BFFT_SIGNATURE) {
550 } else {
551 if (m_pFormFiller)
552 return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point);
553 }
554
555 return FALSE;
556}
557
558FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
559 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700560 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800561 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700562 CFX_ByteString sSubType = pAnnot->GetSubType();
563
564 if (sSubType == BFFT_SIGNATURE) {
565 } else {
566 if (m_pFormFiller)
567 return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
568 }
569
570 return FALSE;
571}
572
573FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
574 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700575 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800576 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700577 CFX_ByteString sSubType = pAnnot->GetSubType();
578
579 if (sSubType == BFFT_SIGNATURE) {
580 } else {
581 if (m_pFormFiller)
582 return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point);
583 }
584
585 return FALSE;
586}
587
588FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
589 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700590 uint32_t nFlags,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700591 short zDelta,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800592 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700593 CFX_ByteString sSubType = pAnnot->GetSubType();
594
595 if (sSubType == BFFT_SIGNATURE) {
596 } else {
597 if (m_pFormFiller)
598 return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,
599 point);
600 }
601
602 return FALSE;
603}
604
605FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
606 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700607 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800608 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700609 CFX_ByteString sSubType = pAnnot->GetSubType();
610
611 if (sSubType == BFFT_SIGNATURE) {
612 } else {
613 if (m_pFormFiller)
614 return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point);
615 }
616
617 return FALSE;
618}
619FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
620 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700621 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800622 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623 CFX_ByteString sSubType = pAnnot->GetSubType();
624
625 if (sSubType == BFFT_SIGNATURE) {
626 } else {
627 if (m_pFormFiller)
628 return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point);
629 }
630
631 return FALSE;
632}
633
weili625ad662016-06-15 11:21:33 -0700634FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView,
635 CPDFSDK_Annot* pAnnot,
636 uint32_t nFlags,
637 const CFX_FloatPoint& point) {
638 return FALSE;
639}
640
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700641FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700642 uint32_t nChar,
643 uint32_t nFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700644 CFX_ByteString sSubType = pAnnot->GetSubType();
645
646 if (sSubType == BFFT_SIGNATURE) {
647 } else {
648 if (m_pFormFiller)
649 return m_pFormFiller->OnChar(pAnnot, nChar, nFlags);
650 }
651
652 return FALSE;
653}
654
655FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
656 int nKeyCode,
657 int nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700658 CFX_ByteString sSubType = pAnnot->GetSubType();
659
660 if (sSubType == BFFT_SIGNATURE) {
661 } else {
662 if (m_pFormFiller)
663 return m_pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlag);
664 }
665
666 return FALSE;
667}
668
669FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
670 int nKeyCode,
671 int nFlag) {
672 return FALSE;
673}
674void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700675 CFX_ByteString sSubType = pAnnot->GetSubType();
676
677 if (sSubType == BFFT_SIGNATURE) {
678 } else {
679 if (m_pFormFiller)
680 m_pFormFiller->OnCreate(pAnnot);
681 }
682}
683
684void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {
Tom Sepez50d12ad2015-11-24 09:50:51 -0800685 if (pAnnot->GetSubType() == BFFT_SIGNATURE)
686 return;
687
tsepez77b909e2016-06-09 14:08:11 -0700688 CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot);
Tom Sepez50d12ad2015-11-24 09:50:51 -0800689 if (!pWidget->IsAppearanceValid())
thestig1cd352e2016-06-07 17:53:06 -0700690 pWidget->ResetAppearance(nullptr, FALSE);
Tom Sepez50d12ad2015-11-24 09:50:51 -0800691
692 int nFieldType = pWidget->GetFieldType();
693 if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) {
694 FX_BOOL bFormated = FALSE;
695 CFX_WideString sValue = pWidget->OnFormat(bFormated);
696 if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) {
697 pWidget->ResetAppearance(sValue.c_str(), FALSE);
698 }
699 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700700
Tom Sepez51da0932015-11-25 16:05:49 -0800701#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700702 CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700703 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800704 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
705 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
706 if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty())
707 pWidget->ResetAppearance(FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700708 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800709#endif // PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800710 if (m_pFormFiller)
711 m_pFormFiller->OnLoad(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700712}
713
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700714FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700715 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700716 CFX_ByteString sSubType = pAnnot->GetSubType();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700717
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700718 if (sSubType == BFFT_SIGNATURE) {
719 } else {
720 if (m_pFormFiller)
721 return m_pFormFiller->OnSetFocus(pAnnot, nFlag);
722 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700723
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700724 return TRUE;
725}
726FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700727 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700728 CFX_ByteString sSubType = pAnnot->GetSubType();
729
730 if (sSubType == BFFT_SIGNATURE) {
731 } else {
732 if (m_pFormFiller)
733 return m_pFormFiller->OnKillFocus(pAnnot, nFlag);
734 }
735
736 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700737}
738
weili625ad662016-06-15 11:21:33 -0700739#ifdef PDF_ENABLE_XFA
740
741FX_BOOL CPDFSDK_BFAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot,
742 CPDFSDK_Annot* pNewAnnot) {
743 return TRUE;
744}
745
746#endif // PDF_ENABLE_XFA
747
Tom Sepez281a9ea2016-02-26 14:24:28 -0800748CFX_FloatRect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
749 CPDFSDK_Annot* pAnnot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700750 CFX_ByteString sSubType = pAnnot->GetSubType();
Tom Sepezd5e7b352016-02-29 11:24:29 -0800751 if (sSubType != BFFT_SIGNATURE && m_pFormFiller)
752 return CFX_FloatRect(m_pFormFiller->GetViewBBox(pPageView, pAnnot));
Lei Zhang60f507b2015-06-13 00:41:00 -0700753
Tom Sepez281a9ea2016-02-26 14:24:28 -0800754 return CFX_FloatRect(0, 0, 0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700755}
756
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700757FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
758 CPDFSDK_Annot* pAnnot,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800759 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700760 ASSERT(pPageView);
761 ASSERT(pAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700762
Tom Sepez281a9ea2016-02-26 14:24:28 -0800763 CFX_FloatRect rect = GetViewBBox(pPageView, pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700764 return rect.Contains(point.x, point.y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700765}
766
Tom Sepez51da0932015-11-25 16:05:49 -0800767#ifdef PDF_ENABLE_XFA
Lei Zhang60f507b2015-06-13 00:41:00 -0700768
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700769CPDFSDK_XFAAnnotHandler::CPDFSDK_XFAAnnotHandler(CPDFDoc_Environment* pApp)
770 : m_pApp(pApp) {}
771
weili625ad662016-06-15 11:21:33 -0700772CPDFSDK_XFAAnnotHandler::~CPDFSDK_XFAAnnotHandler() {}
773
774CFX_ByteString CPDFSDK_XFAAnnotHandler::GetType() {
775 return FSDK_XFAWIDGET_TYPENAME;
776}
777
778CFX_ByteString CPDFSDK_XFAAnnotHandler::GetName() {
779 return "XFAWidgetHandler";
780}
781
782FX_BOOL CPDFSDK_XFAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
783 return !!pAnnot->GetXFAWidget();
784}
785
786CPDFSDK_Annot* CPDFSDK_XFAAnnotHandler::NewAnnot(CPDF_Annot* pAnnot,
787 CPDFSDK_PageView* pPage) {
788 return nullptr;
789}
790
dsinclairdf4bc592016-03-31 20:34:43 -0700791CPDFSDK_Annot* CPDFSDK_XFAAnnotHandler::NewAnnot(CXFA_FFWidget* pAnnot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700792 CPDFSDK_PageView* pPage) {
793 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument();
tsepez23ae4a52016-06-08 20:44:54 -0700794 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700795 CPDFSDK_XFAWidget* pWidget = new CPDFSDK_XFAWidget(pAnnot, pPage, pInterForm);
796 pInterForm->AddXFAMap(pAnnot, pWidget);
797 return pWidget;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700798}
799
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700800void CPDFSDK_XFAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
801 CPDFSDK_Annot* pAnnot,
802 CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800803 CFX_Matrix* pUser2Device,
tsepezc3255f52016-03-25 14:52:27 -0700804 uint32_t dwFlags) {
thestig1cd352e2016-06-07 17:53:06 -0700805 ASSERT(pPageView);
806 ASSERT(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700807
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700808 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
dsinclairdf4bc592016-03-31 20:34:43 -0700809 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700810
811 CFX_Graphics gs;
812 gs.Create(pDevice);
813
814 CFX_Matrix mt;
815 mt = *(CFX_Matrix*)pUser2Device;
816
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700817 FX_BOOL bIsHighlight = FALSE;
818 if (pSDKDoc->GetFocusAnnot() != pAnnot)
819 bIsHighlight = TRUE;
820
821 pWidgetHandler->RenderWidget(pAnnot->GetXFAWidget(), &gs, &mt, bIsHighlight);
822
823 // to do highlight and shadow
824}
825
weili625ad662016-06-15 11:21:33 -0700826void CPDFSDK_XFAAnnotHandler::OnDrawSleep(CPDFSDK_PageView* pPageView,
827 CPDFSDK_Annot* pAnnot,
828 CFX_RenderDevice* pDevice,
829 CFX_Matrix* pUser2Device,
830 const CFX_FloatRect& rcWindow,
831 uint32_t dwFlags) {}
832
833void CPDFSDK_XFAAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) {}
834
835void CPDFSDK_XFAAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {}
836
837void CPDFSDK_XFAAnnotHandler::OnDelete(CPDFSDK_Annot* pAnnot) {}
838
839void CPDFSDK_XFAAnnotHandler::OnRelease(CPDFSDK_Annot* pAnnot) {}
840
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700841void CPDFSDK_XFAAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700842 CPDFSDK_XFAWidget* pWidget = (CPDFSDK_XFAWidget*)pAnnot;
843 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700844 pInterForm->RemoveXFAMap(pWidget->GetXFAWidget());
845
846 delete pWidget;
847}
848
weili625ad662016-06-15 11:21:33 -0700849void CPDFSDK_XFAAnnotHandler::DeleteAnnot(CPDFSDK_Annot* pAnnot) {}
850
Tom Sepez281a9ea2016-02-26 14:24:28 -0800851CFX_FloatRect CPDFSDK_XFAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
852 CPDFSDK_Annot* pAnnot) {
Lei Zhang5eca3052016-02-22 20:32:21 -0800853 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700854
Tom Sepeza8a39e22015-10-12 15:47:07 -0700855 CFX_RectF rcBBox;
dsinclair56a8b192016-06-21 14:15:25 -0700856 XFA_Element eType = pAnnot->GetXFAWidget()->GetDataAcc()->GetUIType();
857 if (eType == XFA_Element::Signature)
dsinclair935d8d52016-05-17 10:32:18 -0700858 pAnnot->GetXFAWidget()->GetBBox(rcBBox, XFA_WidgetStatus_Visible, TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700859 else
dsinclair935d8d52016-05-17 10:32:18 -0700860 pAnnot->GetXFAWidget()->GetBBox(rcBBox, XFA_WidgetStatus_None);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700861
862 CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
863 rcBBox.top + rcBBox.height);
864 rcWidget.left -= 1.0f;
865 rcWidget.right += 1.0f;
866 rcWidget.bottom -= 1.0f;
867 rcWidget.top += 1.0f;
868
869 return rcWidget;
870}
871
872FX_BOOL CPDFSDK_XFAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
873 CPDFSDK_Annot* pAnnot,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800874 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700875 if (!pPageView || !pAnnot)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700876 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700877
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700878 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
879 if (!pSDKDoc)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700880 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700881
Tom Sepez50d12ad2015-11-24 09:50:51 -0800882 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700883 if (!pDoc)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700884 return FALSE;
Lei Zhang60f507b2015-06-13 00:41:00 -0700885
dsinclairdf4bc592016-03-31 20:34:43 -0700886 CXFA_FFDocView* pDocView = pDoc->GetXFADocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700887 if (!pDocView)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700888 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700889
dsinclairdf4bc592016-03-31 20:34:43 -0700890 CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700891 if (!pWidgetHandler)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700892 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700893
dsinclair89fcde82016-05-03 13:00:25 -0700894 FWL_WidgetHit dwHitTest =
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700895 pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point.x, point.y);
dsinclair89fcde82016-05-03 13:00:25 -0700896 return dwHitTest != FWL_WidgetHit::Unknown;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700897}
898
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700899void CPDFSDK_XFAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
900 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700901 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700902 if (!pPageView || !pAnnot)
903 return;
dsinclairdf4bc592016-03-31 20:34:43 -0700904 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700905 pWidgetHandler->OnMouseEnter(pAnnot->GetXFAWidget());
906}
Lei Zhang60f507b2015-06-13 00:41:00 -0700907
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700908void CPDFSDK_XFAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
909 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700910 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700911 if (!pPageView || !pAnnot)
912 return;
913
dsinclairdf4bc592016-03-31 20:34:43 -0700914 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700915 pWidgetHandler->OnMouseExit(pAnnot->GetXFAWidget());
916}
917
918FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
919 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700920 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800921 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700922 if (!pPageView || !pAnnot)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700923 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700924
dsinclairdf4bc592016-03-31 20:34:43 -0700925 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800926 return pWidgetHandler->OnLButtonDown(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700927 GetFWLFlags(nFlags), point.x, point.y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700928}
929
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700930FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
931 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700932 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800933 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700934 if (!pPageView || !pAnnot)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700935 return FALSE;
Lei Zhang60f507b2015-06-13 00:41:00 -0700936
dsinclairdf4bc592016-03-31 20:34:43 -0700937 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800938 return pWidgetHandler->OnLButtonUp(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700939 GetFWLFlags(nFlags), point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700940}
941
942FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
943 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700944 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800945 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700946 if (!pPageView || !pAnnot)
947 return FALSE;
948
dsinclairdf4bc592016-03-31 20:34:43 -0700949 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800950 return pWidgetHandler->OnLButtonDblClk(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700951 GetFWLFlags(nFlags), point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700952}
953
954FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
955 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700956 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800957 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700958 if (!pPageView || !pAnnot)
959 return FALSE;
960
dsinclairdf4bc592016-03-31 20:34:43 -0700961 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800962 return pWidgetHandler->OnMouseMove(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700963 GetFWLFlags(nFlags), point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700964}
965
966FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
967 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700968 uint32_t nFlags,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700969 short zDelta,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800970 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700971 if (!pPageView || !pAnnot)
972 return FALSE;
973
dsinclairdf4bc592016-03-31 20:34:43 -0700974 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800975 return pWidgetHandler->OnMouseWheel(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700976 pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), zDelta, point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700977}
978
979FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
980 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700981 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800982 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700983 if (!pPageView || !pAnnot)
984 return FALSE;
985
dsinclairdf4bc592016-03-31 20:34:43 -0700986 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800987 return pWidgetHandler->OnRButtonDown(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700988 GetFWLFlags(nFlags), point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700989}
990
991FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
992 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700993 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800994 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700995 if (!pPageView || !pAnnot)
996 return FALSE;
997
dsinclairdf4bc592016-03-31 20:34:43 -0700998 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800999 return pWidgetHandler->OnRButtonUp(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001000 GetFWLFlags(nFlags), point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001001}
1002
1003FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView,
1004 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -07001005 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -08001006 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001007 if (!pPageView || !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->OnRButtonDblClk(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001012 GetFWLFlags(nFlags), point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001013}
1014
1015FX_BOOL CPDFSDK_XFAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -07001016 uint32_t nChar,
1017 uint32_t nFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001018 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->OnChar(pAnnot->GetXFAWidget(), nChar,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001023 GetFWLFlags(nFlags));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001024}
1025
1026FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyDown(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->OnKeyDown(pAnnot->GetXFAWidget(), nKeyCode,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001034 GetFWLFlags(nFlag));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001035}
1036
1037FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
1038 int nKeyCode,
1039 int nFlag) {
1040 if (!pAnnot)
1041 return FALSE;
1042
dsinclairdf4bc592016-03-31 20:34:43 -07001043 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -08001044 return pWidgetHandler->OnKeyUp(pAnnot->GetXFAWidget(), nKeyCode,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001045 GetFWLFlags(nFlag));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001046}
1047
weili625ad662016-06-15 11:21:33 -07001048void CPDFSDK_XFAAnnotHandler::OnDeSelected(CPDFSDK_Annot* pAnnot) {}
1049
1050void CPDFSDK_XFAAnnotHandler::OnSelected(CPDFSDK_Annot* pAnnot) {}
1051
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001052FX_BOOL CPDFSDK_XFAAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -07001053 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001054 return TRUE;
1055}
1056
1057FX_BOOL CPDFSDK_XFAAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -07001058 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001059 return TRUE;
1060}
1061
1062FX_BOOL CPDFSDK_XFAAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot,
1063 CPDFSDK_Annot* pNewAnnot) {
thestig1cd352e2016-06-07 17:53:06 -07001064 CXFA_FFWidgetHandler* pWidgetHandler = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001065
1066 if (pOldAnnot)
1067 pWidgetHandler = GetXFAWidgetHandler(pOldAnnot);
1068 else if (pNewAnnot)
1069 pWidgetHandler = GetXFAWidgetHandler(pNewAnnot);
1070
1071 if (pWidgetHandler) {
1072 FX_BOOL bRet = TRUE;
thestig1cd352e2016-06-07 17:53:06 -07001073 CXFA_FFWidget* hWidget = pNewAnnot ? pNewAnnot->GetXFAWidget() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001074 if (hWidget) {
dsinclair221caf62016-04-04 12:08:40 -07001075 CXFA_FFPageView* pXFAPageView = hWidget->GetPageView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001076 if (pXFAPageView) {
1077 bRet = pXFAPageView->GetDocView()->SetFocus(hWidget);
1078 if (pXFAPageView->GetDocView()->GetFocusWidget() == hWidget)
1079 bRet = TRUE;
1080 }
Tom Sepezdcbc02f2015-07-17 09:16:17 -07001081 }
Tom Sepezdcbc02f2015-07-17 09:16:17 -07001082 return bRet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001083 }
1084
1085 return TRUE;
Bo Xufdc00a72014-10-28 23:03:33 -07001086}
1087
dsinclairdf4bc592016-03-31 20:34:43 -07001088CXFA_FFWidgetHandler* CPDFSDK_XFAAnnotHandler::GetXFAWidgetHandler(
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001089 CPDFSDK_Annot* pAnnot) {
1090 if (!pAnnot)
thestig1cd352e2016-06-07 17:53:06 -07001091 return nullptr;
Bo Xufdc00a72014-10-28 23:03:33 -07001092
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001093 CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
1094 if (!pPageView)
thestig1cd352e2016-06-07 17:53:06 -07001095 return nullptr;
Bo Xufdc00a72014-10-28 23:03:33 -07001096
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001097 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
1098 if (!pSDKDoc)
thestig1cd352e2016-06-07 17:53:06 -07001099 return nullptr;
Bo Xufdc00a72014-10-28 23:03:33 -07001100
Tom Sepez50d12ad2015-11-24 09:50:51 -08001101 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001102 if (!pDoc)
thestig1cd352e2016-06-07 17:53:06 -07001103 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001104
dsinclairdf4bc592016-03-31 20:34:43 -07001105 CXFA_FFDocView* pDocView = pDoc->GetXFADocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001106 if (!pDocView)
thestig1cd352e2016-06-07 17:53:06 -07001107 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001108
1109 return pDocView->GetWidgetHandler();
Bo Xufdc00a72014-10-28 23:03:33 -07001110}
1111
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001112#define FWL_KEYFLAG_Ctrl (1 << 0)
1113#define FWL_KEYFLAG_Alt (1 << 1)
1114#define FWL_KEYFLAG_Shift (1 << 2)
1115#define FWL_KEYFLAG_LButton (1 << 3)
1116#define FWL_KEYFLAG_RButton (1 << 4)
1117#define FWL_KEYFLAG_MButton (1 << 5)
Bo Xufdc00a72014-10-28 23:03:33 -07001118
tsepezc3255f52016-03-25 14:52:27 -07001119uint32_t CPDFSDK_XFAAnnotHandler::GetFWLFlags(uint32_t dwFlag) {
1120 uint32_t dwFWLFlag = 0;
Bo Xufdc00a72014-10-28 23:03:33 -07001121
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001122 if (dwFlag & FWL_EVENTFLAG_ControlKey)
1123 dwFWLFlag |= FWL_KEYFLAG_Ctrl;
1124 if (dwFlag & FWL_EVENTFLAG_LeftButtonDown)
1125 dwFWLFlag |= FWL_KEYFLAG_LButton;
1126 if (dwFlag & FWL_EVENTFLAG_MiddleButtonDown)
1127 dwFWLFlag |= FWL_KEYFLAG_MButton;
1128 if (dwFlag & FWL_EVENTFLAG_RightButtonDown)
1129 dwFWLFlag |= FWL_KEYFLAG_RButton;
1130 if (dwFlag & FWL_EVENTFLAG_ShiftKey)
1131 dwFWLFlag |= FWL_KEYFLAG_Shift;
1132 if (dwFlag & FWL_EVENTFLAG_AltKey)
1133 dwFWLFlag |= FWL_KEYFLAG_Alt;
Bo Xufdc00a72014-10-28 23:03:33 -07001134
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001135 return dwFWLFlag;
Bo Xufdc00a72014-10-28 23:03:33 -07001136}
Tom Sepez40e9ff32015-11-30 12:39:54 -08001137#endif // PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -07001138
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001139CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView,
Lei Zhangbf60b292015-10-26 12:14:35 -07001140 bool bReverse)
1141 : m_bReverse(bReverse), m_pos(0) {
1142 const std::vector<CPDFSDK_Annot*>& annots = pPageView->GetAnnotList();
1143 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), annots.rbegin(),
1144 annots.rend());
1145 std::stable_sort(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(),
1146 [](CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) {
1147 return p1->GetLayoutOrder() < p2->GetLayoutOrder();
1148 });
Bo Xufdc00a72014-10-28 23:03:33 -07001149
Lei Zhangbf60b292015-10-26 12:14:35 -07001150 CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot();
1151 if (!pTopMostAnnot)
1152 return;
Lei Zhang60f507b2015-06-13 00:41:00 -07001153
Lei Zhangbf60b292015-10-26 12:14:35 -07001154 auto it = std::find(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(),
1155 pTopMostAnnot);
1156 if (it != m_iteratorAnnotList.end()) {
1157 CPDFSDK_Annot* pReaderAnnot = *it;
1158 m_iteratorAnnotList.erase(it);
1159 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), pReaderAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001160 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001161}
1162
Dan Sinclairf766ad22016-03-14 13:51:24 -04001163CPDFSDK_AnnotIterator::~CPDFSDK_AnnotIterator() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001164
Lei Zhangbf60b292015-10-26 12:14:35 -07001165CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot() {
1166 if (m_pos < m_iteratorAnnotList.size())
1167 return m_iteratorAnnotList[m_pos++];
1168 return nullptr;
1169}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001170
Lei Zhangbf60b292015-10-26 12:14:35 -07001171CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot() {
1172 if (m_pos < m_iteratorAnnotList.size())
1173 return m_iteratorAnnotList[m_iteratorAnnotList.size() - ++m_pos];
1174 return nullptr;
1175}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001176
Lei Zhangbf60b292015-10-26 12:14:35 -07001177CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next() {
1178 return m_bReverse ? PrevAnnot() : NextAnnot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001179}