blob: 24f3d60d4737ab14c15c2e776c7ce7bed0abb403 [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"
dsinclair7222ea62016-04-06 14:33:07 -070022#include "xfa/fxfa/include/xfa_ffwidget.h"
Dan Sinclair811b8a42016-03-17 08:59:42 -040023#include "xfa/fxgraphics/include/cfx_graphics.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080024#endif // PDF_ENABLE_XFA
25
Nico Weber9d8ec5a2015-08-04 13:00:21 -070026CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) {
27 m_pApp = pApp;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070028
Nico Weber9d8ec5a2015-08-04 13:00:21 -070029 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp);
30 pHandler->SetFormFiller(m_pApp->GetIFormFiller());
31 RegisterAnnotHandler(pHandler);
Tom Sepez51da0932015-11-25 16:05:49 -080032#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033 CPDFSDK_XFAAnnotHandler* pXFAAnnotHandler =
34 new CPDFSDK_XFAAnnotHandler(m_pApp);
35 RegisterAnnotHandler(pXFAAnnotHandler);
Tom Sepez40e9ff32015-11-30 12:39:54 -080036#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070037}
38
Nico Weber9d8ec5a2015-08-04 13:00:21 -070039CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {
40 for (int i = 0; i < m_Handlers.GetSize(); i++) {
41 IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i);
42 delete pHandler;
43 }
44 m_Handlers.RemoveAll();
Tom Sepez09d33bc2015-08-19 09:49:24 -070045 m_mapType2Handler.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070046}
47
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
52 m_Handlers.Add(pAnnotHandler);
Tom Sepez09d33bc2015-08-19 09:49:24 -070053 m_mapType2Handler[pAnnotHandler->GetType()] = pAnnotHandler;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070054}
55
56void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler(
57 IPDFSDK_AnnotHandler* pAnnotHandler) {
Tom Sepez09d33bc2015-08-19 09:49:24 -070058 m_mapType2Handler.erase(pAnnotHandler->GetType());
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059 for (int i = 0, sz = m_Handlers.GetSize(); i < sz; i++) {
60 if (m_Handlers.GetAt(i) == pAnnotHandler) {
61 m_Handlers.RemoveAt(i);
62 break;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070063 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070065}
66
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot,
68 CPDFSDK_PageView* pPageView) {
Lei Zhang96660d62015-12-14 18:27:25 -080069 ASSERT(pPageView);
Lei Zhang60f507b2015-06-13 00:41:00 -070070
Nico Weber9d8ec5a2015-08-04 13:00:21 -070071 if (IPDFSDK_AnnotHandler* pAnnotHandler =
72 GetAnnotHandler(pAnnot->GetSubType())) {
73 return pAnnotHandler->NewAnnot(pAnnot, pPageView);
74 }
Lei Zhang60f507b2015-06-13 00:41:00 -070075
Nico Weber9d8ec5a2015-08-04 13:00:21 -070076 return new CPDFSDK_BAAnnot(pAnnot, pPageView);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070077}
78
Tom Sepez51da0932015-11-25 16:05:49 -080079#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -070080CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CXFA_FFWidget* pAnnot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070081 CPDFSDK_PageView* pPageView) {
Lei Zhang5eca3052016-02-22 20:32:21 -080082 ASSERT(pAnnot);
83 ASSERT(pPageView);
Lei Zhang60f507b2015-06-13 00:41:00 -070084
Nico Weber9d8ec5a2015-08-04 13:00:21 -070085 if (IPDFSDK_AnnotHandler* pAnnotHandler =
86 GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME)) {
87 return pAnnotHandler->NewAnnot(pAnnot, pPageView);
88 }
Lei Zhang60f507b2015-06-13 00:41:00 -070089
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070091}
Tom Sepez40e9ff32015-11-30 12:39:54 -080092#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070093
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070095 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
96 pAnnotHandler->OnRelease(pAnnot);
97 pAnnotHandler->ReleaseAnnot(pAnnot);
98 } else {
99 delete (CPDFSDK_Annot*)pAnnot;
100 }
Bo Xufdc00a72014-10-28 23:03:33 -0700101}
102
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700103void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700104 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
Bo Xufdc00a72014-10-28 23:03:33 -0700105
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700106 CPDFSDK_DateTime curTime;
107 pPDFAnnot->GetAnnotDict()->SetAtString("M", curTime.ToPDFDateTimeString());
108 pPDFAnnot->GetAnnotDict()->SetAtNumber("F", 0);
109
110 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
111 pAnnotHandler->OnCreate(pAnnot);
112 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700113}
114
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700115void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) {
Lei Zhang96660d62015-12-14 18:27:25 -0800116 ASSERT(pAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700117
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700118 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
119 pAnnotHandler->OnLoad(pAnnot);
120 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700121}
122
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700123IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
124 CPDFSDK_Annot* pAnnot) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
126 if (pPDFAnnot)
127 return GetAnnotHandler(pPDFAnnot->GetSubType());
Tom Sepez51da0932015-11-25 16:05:49 -0800128#ifdef PDF_ENABLE_XFA
Tom Sepezc7e4c4f2015-11-20 09:45:24 -0800129 if (pAnnot->GetXFAWidget())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700130 return GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800131#endif // PDF_ENABLE_XFA
Tom Sepezc7e4c4f2015-11-20 09:45:24 -0800132 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700133}
134
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
136 const CFX_ByteString& sType) const {
Tom Sepez09d33bc2015-08-19 09:49:24 -0700137 auto it = m_mapType2Handler.find(sType);
138 return it != m_mapType2Handler.end() ? it->second : nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700139}
140
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700141void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView,
142 CPDFSDK_Annot* pAnnot,
143 CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800144 CFX_Matrix* pUser2Device,
tsepezc3255f52016-03-25 14:52:27 -0700145 uint32_t dwFlags) {
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500146 ASSERT(pAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700147
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700148 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
149 pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
150 } else {
Tom Sepez51da0932015-11-25 16:05:49 -0800151#ifdef PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800152 if (pAnnot->IsXFAField())
153 return;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800154#endif // PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800155 static_cast<CPDFSDK_BAAnnot*>(pAnnot)
156 ->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700157 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700158}
159
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(
161 CPDFSDK_PageView* pPageView,
162 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700163 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800164 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800165 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166
167 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
168 return pAnnotHandler->OnLButtonDown(pPageView, pAnnot, nFlags, point);
169 }
170 return FALSE;
171}
Tom Sepez281a9ea2016-02-26 14:24:28 -0800172FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(
173 CPDFSDK_PageView* pPageView,
174 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700175 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800176 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800177 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178
179 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
180 return pAnnotHandler->OnLButtonUp(pPageView, pAnnot, nFlags, point);
181 }
182 return FALSE;
183}
184FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(
185 CPDFSDK_PageView* pPageView,
186 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700187 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800188 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800189 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700190
191 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
192 return pAnnotHandler->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
193 }
194 return FALSE;
195}
Tom Sepez281a9ea2016-02-26 14:24:28 -0800196FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(
197 CPDFSDK_PageView* pPageView,
198 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700199 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800200 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800201 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202
203 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
204 return pAnnotHandler->OnMouseMove(pPageView, pAnnot, nFlags, point);
205 }
206 return FALSE;
207}
Tom Sepez281a9ea2016-02-26 14:24:28 -0800208FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(
209 CPDFSDK_PageView* pPageView,
210 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700211 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800212 short zDelta,
213 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800214 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700215
216 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
217 return pAnnotHandler->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,
218 point);
219 }
220 return FALSE;
221}
222FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(
223 CPDFSDK_PageView* pPageView,
224 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700225 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800226 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800227 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700228
229 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
230 return pAnnotHandler->OnRButtonDown(pPageView, pAnnot, nFlags, point);
231 }
232 return FALSE;
233}
Tom Sepez281a9ea2016-02-26 14:24:28 -0800234FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(
235 CPDFSDK_PageView* pPageView,
236 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700237 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800238 const CFX_FloatPoint& point) {
Lei Zhang96660d62015-12-14 18:27:25 -0800239 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240
241 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
242 return pAnnotHandler->OnRButtonUp(pPageView, pAnnot, nFlags, point);
243 }
244 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700245}
246
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700247void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(CPDFSDK_PageView* pPageView,
248 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700249 uint32_t nFlag) {
Lei Zhang96660d62015-12-14 18:27:25 -0800250 ASSERT(pAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700251
Lei Zhang05e67412016-01-25 16:35:42 -0800252 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700253 pAnnotHandler->OnMouseEnter(pPageView, pAnnot, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700254}
255
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700256void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(CPDFSDK_PageView* pPageView,
257 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700258 uint32_t nFlag) {
Lei Zhang96660d62015-12-14 18:27:25 -0800259 ASSERT(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700260
Lei Zhang05e67412016-01-25 16:35:42 -0800261 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700262 pAnnotHandler->OnMouseExit(pPageView, pAnnot, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700263}
264
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700265FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700266 uint32_t nChar,
267 uint32_t nFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700268 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
269 return pAnnotHandler->OnChar(pAnnot, nChar, nFlags);
270 }
271 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700272}
273
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700274FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot,
275 int nKeyCode,
276 int nFlag) {
277 if (!m_pApp->FFI_IsCTRLKeyDown(nFlag) && !m_pApp->FFI_IsALTKeyDown(nFlag)) {
278 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
279 CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();
280 if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) {
281 CPDFSDK_Annot* pNext =
282 GetNextAnnot(pFocusAnnot, !m_pApp->FFI_IsSHIFTKeyDown(nFlag));
Lei Zhang60f507b2015-06-13 00:41:00 -0700283
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700284 if (pNext && pNext != pFocusAnnot) {
285 CPDFSDK_Document* pDocument = pPage->GetSDKDocument();
286 pDocument->SetFocusAnnot(pNext);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700287 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288 }
289 }
290 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700291
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
293 return pAnnotHandler->OnKeyDown(pAnnot, nKeyCode, nFlag);
294 }
295 return FALSE;
296}
297FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot,
298 int nKeyCode,
299 int nFlag) {
300 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700301}
302
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700304 uint32_t nFlag) {
Lei Zhang96660d62015-12-14 18:27:25 -0800305 ASSERT(pAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700306
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
308 if (pAnnotHandler->OnSetFocus(pAnnot, nFlag)) {
309 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
310 pPage->GetSDKDocument();
311 return TRUE;
312 }
313 }
314 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700315}
316
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700317FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700318 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700319 ASSERT(pAnnot);
320 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
321 return pAnnotHandler->OnKillFocus(pAnnot, nFlag);
322
323 return FALSE;
324}
325
Tom Sepez51da0932015-11-25 16:05:49 -0800326#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700327FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus(
328 CPDFSDK_Annot* pSetAnnot,
329 CPDFSDK_Annot* pKillAnnot) {
330 FX_BOOL bXFA = (pSetAnnot && pSetAnnot->GetXFAWidget()) ||
331 (pKillAnnot && pKillAnnot->GetXFAWidget());
332
333 if (bXFA) {
334 if (IPDFSDK_AnnotHandler* pXFAAnnotHandler =
335 GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME))
336 return pXFAAnnotHandler->OnXFAChangedFocus(pKillAnnot, pSetAnnot);
337 }
338
339 return TRUE;
340}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800341#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700342
Tom Sepez281a9ea2016-02-26 14:24:28 -0800343CFX_FloatRect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700344 CPDFSDK_PageView* pPageView,
345 CPDFSDK_Annot* pAnnot) {
346 ASSERT(pAnnot);
347 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
348 return pAnnotHandler->GetViewBBox(pPageView, pAnnot);
349
350 return pAnnot->GetRect();
351}
352
353FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView,
354 CPDFSDK_Annot* pAnnot,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800355 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700356 ASSERT(pAnnot);
357 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
358 if (pAnnotHandler->CanAnswer(pAnnot))
359 return pAnnotHandler->HitTest(pPageView, pAnnot, point);
360 }
361 return FALSE;
362}
363
364CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,
365 FX_BOOL bNext) {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800366#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700367 CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView();
368 CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage();
369 if (pPage == NULL)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700370 return NULL;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700371 if (pPage->GetPDFPage()) { // for pdf annots.
372 CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), pSDKAnnot->GetType(), "");
373 CPDFSDK_Annot* pNext =
374 bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot);
375 return pNext;
376 }
377 // for xfa annots
378 IXFA_WidgetIterator* pWidgetIterator =
379 pPage->GetXFAPageView()->CreateWidgetIterator(
380 XFA_TRAVERSEWAY_Tranvalse, XFA_WIDGETFILTER_Visible |
381 XFA_WIDGETFILTER_Viewable |
382 XFA_WIDGETFILTER_Field);
383 if (pWidgetIterator == NULL)
384 return NULL;
385 if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget())
386 pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget());
dsinclairdf4bc592016-03-31 20:34:43 -0700387 CXFA_FFWidget* hNextFocus = NULL;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700388 hNextFocus =
389 bNext ? pWidgetIterator->MoveToNext() : pWidgetIterator->MoveToPrevious();
Lei Zhang5eca3052016-02-22 20:32:21 -0800390 if (!hNextFocus && pSDKAnnot)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391 hNextFocus = pWidgetIterator->MoveToFirst();
392
393 pWidgetIterator->Release();
394 return pPageView->GetAnnotByXFAWidget(hNextFocus);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800395#else // PDF_ENABLE_XFA
396 CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), "Widget", "");
397 return bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot);
398#endif // PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -0700399}
400
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700401FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
402 ASSERT(pAnnot->GetType() == "Widget");
403 if (pAnnot->GetSubType() == BFFT_SIGNATURE)
404 return FALSE;
405
406 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
407 if (!pWidget->IsVisible())
408 return FALSE;
409
410 int nFieldFlags = pWidget->GetFieldFlags();
411 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
412 return FALSE;
413
414 if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON)
415 return TRUE;
416
417 CPDF_Page* pPage = pWidget->GetPDFPage();
418 CPDF_Document* pDocument = pPage->m_pDocument;
tsepezc3255f52016-03-25 14:52:27 -0700419 uint32_t dwPermissions = pDocument->GetUserPermissions();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700420 return (dwPermissions & FPDFPERM_FILL_FORM) ||
421 (dwPermissions & FPDFPERM_ANNOT_FORM);
422}
423
424CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot,
425 CPDFSDK_PageView* pPage) {
426 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument();
427 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm();
428 CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl(
429 pInterForm->GetInterForm(), pAnnot->GetAnnotDict());
430 if (!pCtrl)
431 return nullptr;
432
433 CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm);
434 pInterForm->AddMap(pCtrl, pWidget);
435 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
436 if (pPDFInterForm && pPDFInterForm->NeedConstructAP())
437 pWidget->ResetAppearance(nullptr, FALSE);
438
439 return pWidget;
440}
441
Tom Sepez51da0932015-11-25 16:05:49 -0800442#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -0700443CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CXFA_FFWidget* hWidget,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700444 CPDFSDK_PageView* pPage) {
445 return NULL;
446}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800447#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700448
449void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
Lei Zhang96660d62015-12-14 18:27:25 -0800450 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451
452 if (m_pFormFiller)
453 m_pFormFiller->OnDelete(pAnnot);
454
455 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
456 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700457 CPDF_FormControl* pCtrol = pWidget->GetFormControl();
458 pInterForm->RemoveMap(pCtrol);
459
460 delete pWidget;
461}
462
463void CPDFSDK_BFAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
464 CPDFSDK_Annot* pAnnot,
465 CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800466 CFX_Matrix* pUser2Device,
tsepezc3255f52016-03-25 14:52:27 -0700467 uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468 CFX_ByteString sSubType = pAnnot->GetSubType();
469
470 if (sSubType == BFFT_SIGNATURE) {
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500471 static_cast<CPDFSDK_BAAnnot*>(pAnnot)
472 ->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473 } else {
474 if (m_pFormFiller) {
475 m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
476 }
477 }
478}
479
480void CPDFSDK_BFAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
481 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700482 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700483 CFX_ByteString sSubType = pAnnot->GetSubType();
484
485 if (sSubType == BFFT_SIGNATURE) {
486 } else {
487 if (m_pFormFiller)
488 m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag);
489 }
490}
491void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
492 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700493 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494 CFX_ByteString sSubType = pAnnot->GetSubType();
495
496 if (sSubType == BFFT_SIGNATURE) {
497 } else {
498 if (m_pFormFiller)
499 m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag);
500 }
501}
502FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
503 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700504 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800505 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700506 CFX_ByteString sSubType = pAnnot->GetSubType();
507
508 if (sSubType == BFFT_SIGNATURE) {
509 } else {
510 if (m_pFormFiller)
511 return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point);
512 }
513
514 return FALSE;
515}
516
517FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(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->OnLButtonUp(pPageView, pAnnot, nFlags, point);
527 }
528
529 return FALSE;
530}
531
532FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(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->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
542 }
543
544 return FALSE;
545}
546
547FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(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->OnMouseMove(pPageView, pAnnot, nFlags, point);
557 }
558
559 return FALSE;
560}
561
562FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
563 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700564 uint32_t nFlags,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565 short zDelta,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800566 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567 CFX_ByteString sSubType = pAnnot->GetSubType();
568
569 if (sSubType == BFFT_SIGNATURE) {
570 } else {
571 if (m_pFormFiller)
572 return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,
573 point);
574 }
575
576 return FALSE;
577}
578
579FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
580 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700581 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800582 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700583 CFX_ByteString sSubType = pAnnot->GetSubType();
584
585 if (sSubType == BFFT_SIGNATURE) {
586 } else {
587 if (m_pFormFiller)
588 return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point);
589 }
590
591 return FALSE;
592}
593FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
594 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700595 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800596 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700597 CFX_ByteString sSubType = pAnnot->GetSubType();
598
599 if (sSubType == BFFT_SIGNATURE) {
600 } else {
601 if (m_pFormFiller)
602 return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point);
603 }
604
605 return FALSE;
606}
607
608FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700609 uint32_t nChar,
610 uint32_t nFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700611 CFX_ByteString sSubType = pAnnot->GetSubType();
612
613 if (sSubType == BFFT_SIGNATURE) {
614 } else {
615 if (m_pFormFiller)
616 return m_pFormFiller->OnChar(pAnnot, nChar, nFlags);
617 }
618
619 return FALSE;
620}
621
622FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
623 int nKeyCode,
624 int nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700625 CFX_ByteString sSubType = pAnnot->GetSubType();
626
627 if (sSubType == BFFT_SIGNATURE) {
628 } else {
629 if (m_pFormFiller)
630 return m_pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlag);
631 }
632
633 return FALSE;
634}
635
636FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
637 int nKeyCode,
638 int nFlag) {
639 return FALSE;
640}
641void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700642 CFX_ByteString sSubType = pAnnot->GetSubType();
643
644 if (sSubType == BFFT_SIGNATURE) {
645 } else {
646 if (m_pFormFiller)
647 m_pFormFiller->OnCreate(pAnnot);
648 }
649}
650
651void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {
Tom Sepez50d12ad2015-11-24 09:50:51 -0800652 if (pAnnot->GetSubType() == BFFT_SIGNATURE)
653 return;
654
655 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
656 if (!pWidget->IsAppearanceValid())
657 pWidget->ResetAppearance(NULL, FALSE);
658
659 int nFieldType = pWidget->GetFieldType();
660 if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) {
661 FX_BOOL bFormated = FALSE;
662 CFX_WideString sValue = pWidget->OnFormat(bFormated);
663 if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) {
664 pWidget->ResetAppearance(sValue.c_str(), FALSE);
665 }
666 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700667
Tom Sepez51da0932015-11-25 16:05:49 -0800668#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700669 CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700670 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800671 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
672 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
673 if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty())
674 pWidget->ResetAppearance(FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700675 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800676#endif // PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800677 if (m_pFormFiller)
678 m_pFormFiller->OnLoad(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700679}
680
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700681FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700682 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700683 CFX_ByteString sSubType = pAnnot->GetSubType();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700684
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685 if (sSubType == BFFT_SIGNATURE) {
686 } else {
687 if (m_pFormFiller)
688 return m_pFormFiller->OnSetFocus(pAnnot, nFlag);
689 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700690
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691 return TRUE;
692}
693FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700694 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700695 CFX_ByteString sSubType = pAnnot->GetSubType();
696
697 if (sSubType == BFFT_SIGNATURE) {
698 } else {
699 if (m_pFormFiller)
700 return m_pFormFiller->OnKillFocus(pAnnot, nFlag);
701 }
702
703 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700704}
705
Tom Sepez281a9ea2016-02-26 14:24:28 -0800706CFX_FloatRect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
707 CPDFSDK_Annot* pAnnot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700708 CFX_ByteString sSubType = pAnnot->GetSubType();
Tom Sepezd5e7b352016-02-29 11:24:29 -0800709 if (sSubType != BFFT_SIGNATURE && m_pFormFiller)
710 return CFX_FloatRect(m_pFormFiller->GetViewBBox(pPageView, pAnnot));
Lei Zhang60f507b2015-06-13 00:41:00 -0700711
Tom Sepez281a9ea2016-02-26 14:24:28 -0800712 return CFX_FloatRect(0, 0, 0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700713}
714
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700715FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
716 CPDFSDK_Annot* pAnnot,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800717 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700718 ASSERT(pPageView);
719 ASSERT(pAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700720
Tom Sepez281a9ea2016-02-26 14:24:28 -0800721 CFX_FloatRect rect = GetViewBBox(pPageView, pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700722 return rect.Contains(point.x, point.y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700723}
724
Tom Sepez51da0932015-11-25 16:05:49 -0800725#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700726#define FWL_WGTHITTEST_Unknown 0
Nico Weber077f1a32015-08-06 15:08:57 -0700727#define FWL_WGTHITTEST_Client 1 // arrow
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700728#define FWL_WGTHITTEST_Titlebar 11 // caption
729#define FWL_WGTHITTEST_HScrollBar 15
730#define FWL_WGTHITTEST_VScrollBar 16
731#define FWL_WGTHITTEST_Border 17
732#define FWL_WGTHITTEST_Edit 19
733#define FWL_WGTHITTEST_HyperLink 20
Lei Zhang60f507b2015-06-13 00:41:00 -0700734
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700735CPDFSDK_XFAAnnotHandler::CPDFSDK_XFAAnnotHandler(CPDFDoc_Environment* pApp)
736 : m_pApp(pApp) {}
737
dsinclairdf4bc592016-03-31 20:34:43 -0700738CPDFSDK_Annot* CPDFSDK_XFAAnnotHandler::NewAnnot(CXFA_FFWidget* pAnnot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700739 CPDFSDK_PageView* pPage) {
740 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument();
741 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm();
742 CPDFSDK_XFAWidget* pWidget = new CPDFSDK_XFAWidget(pAnnot, pPage, pInterForm);
743 pInterForm->AddXFAMap(pAnnot, pWidget);
744 return pWidget;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700745}
746
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747FX_BOOL CPDFSDK_XFAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
748 return pAnnot->GetXFAWidget() != NULL;
749}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700750
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700751void CPDFSDK_XFAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
752 CPDFSDK_Annot* pAnnot,
753 CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800754 CFX_Matrix* pUser2Device,
tsepezc3255f52016-03-25 14:52:27 -0700755 uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700756 ASSERT(pPageView != NULL);
757 ASSERT(pAnnot != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700758
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700759 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
dsinclairdf4bc592016-03-31 20:34:43 -0700760 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700761
762 CFX_Graphics gs;
763 gs.Create(pDevice);
764
765 CFX_Matrix mt;
766 mt = *(CFX_Matrix*)pUser2Device;
767
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700768 FX_BOOL bIsHighlight = FALSE;
769 if (pSDKDoc->GetFocusAnnot() != pAnnot)
770 bIsHighlight = TRUE;
771
772 pWidgetHandler->RenderWidget(pAnnot->GetXFAWidget(), &gs, &mt, bIsHighlight);
773
774 // to do highlight and shadow
775}
776
777void CPDFSDK_XFAAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700778 CPDFSDK_XFAWidget* pWidget = (CPDFSDK_XFAWidget*)pAnnot;
779 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700780 pInterForm->RemoveXFAMap(pWidget->GetXFAWidget());
781
782 delete pWidget;
783}
784
Tom Sepez281a9ea2016-02-26 14:24:28 -0800785CFX_FloatRect CPDFSDK_XFAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
786 CPDFSDK_Annot* pAnnot) {
Lei Zhang5eca3052016-02-22 20:32:21 -0800787 ASSERT(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700788
Tom Sepeza8a39e22015-10-12 15:47:07 -0700789 CFX_RectF rcBBox;
dsinclair221caf62016-04-04 12:08:40 -0700790 XFA_ELEMENT eType = pAnnot->GetXFAWidget()->GetDataAcc()->GetUIType();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700791 if (eType == XFA_ELEMENT_Signature)
dsinclair221caf62016-04-04 12:08:40 -0700792 pAnnot->GetXFAWidget()->GetBBox(rcBBox, XFA_WIDGETSTATUS_Visible, TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700793 else
dsinclair221caf62016-04-04 12:08:40 -0700794 pAnnot->GetXFAWidget()->GetBBox(rcBBox, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700795
796 CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
797 rcBBox.top + rcBBox.height);
798 rcWidget.left -= 1.0f;
799 rcWidget.right += 1.0f;
800 rcWidget.bottom -= 1.0f;
801 rcWidget.top += 1.0f;
802
803 return rcWidget;
804}
805
806FX_BOOL CPDFSDK_XFAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
807 CPDFSDK_Annot* pAnnot,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800808 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700809 if (!pPageView || !pAnnot)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700810 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700811
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700812 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
813 if (!pSDKDoc)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700814 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700815
Tom Sepez50d12ad2015-11-24 09:50:51 -0800816 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700817 if (!pDoc)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700818 return FALSE;
Lei Zhang60f507b2015-06-13 00:41:00 -0700819
dsinclairdf4bc592016-03-31 20:34:43 -0700820 CXFA_FFDocView* pDocView = pDoc->GetXFADocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700821 if (!pDocView)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700822 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700823
dsinclairdf4bc592016-03-31 20:34:43 -0700824 CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700825 if (!pWidgetHandler)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700826 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700827
tsepezc3255f52016-03-25 14:52:27 -0700828 uint32_t dwHitTest =
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700829 pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point.x, point.y);
830 return (dwHitTest != FWL_WGTHITTEST_Unknown);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700831}
832
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700833void CPDFSDK_XFAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
834 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700835 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700836 if (!pPageView || !pAnnot)
837 return;
dsinclairdf4bc592016-03-31 20:34:43 -0700838 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700839 pWidgetHandler->OnMouseEnter(pAnnot->GetXFAWidget());
840}
Lei Zhang60f507b2015-06-13 00:41:00 -0700841
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700842void CPDFSDK_XFAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
843 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700844 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700845 if (!pPageView || !pAnnot)
846 return;
847
dsinclairdf4bc592016-03-31 20:34:43 -0700848 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700849 pWidgetHandler->OnMouseExit(pAnnot->GetXFAWidget());
850}
851
852FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
853 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700854 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800855 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700856 if (!pPageView || !pAnnot)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700857 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700858
dsinclairdf4bc592016-03-31 20:34:43 -0700859 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800860 return pWidgetHandler->OnLButtonDown(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700861 GetFWLFlags(nFlags), point.x, point.y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700862}
863
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700864FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
865 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700866 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800867 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700868 if (!pPageView || !pAnnot)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700869 return FALSE;
Lei Zhang60f507b2015-06-13 00:41:00 -0700870
dsinclairdf4bc592016-03-31 20:34:43 -0700871 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800872 return pWidgetHandler->OnLButtonUp(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700873 GetFWLFlags(nFlags), point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700874}
875
876FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
877 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700878 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800879 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700880 if (!pPageView || !pAnnot)
881 return FALSE;
882
dsinclairdf4bc592016-03-31 20:34:43 -0700883 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800884 return pWidgetHandler->OnLButtonDblClk(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700885 GetFWLFlags(nFlags), point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700886}
887
888FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
889 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700890 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800891 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700892 if (!pPageView || !pAnnot)
893 return FALSE;
894
dsinclairdf4bc592016-03-31 20:34:43 -0700895 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800896 return pWidgetHandler->OnMouseMove(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700897 GetFWLFlags(nFlags), point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700898}
899
900FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
901 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700902 uint32_t nFlags,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700903 short zDelta,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800904 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700905 if (!pPageView || !pAnnot)
906 return FALSE;
907
dsinclairdf4bc592016-03-31 20:34:43 -0700908 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800909 return pWidgetHandler->OnMouseWheel(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700910 pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), zDelta, point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700911}
912
913FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
914 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700915 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800916 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700917 if (!pPageView || !pAnnot)
918 return FALSE;
919
dsinclairdf4bc592016-03-31 20:34:43 -0700920 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800921 return pWidgetHandler->OnRButtonDown(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700922 GetFWLFlags(nFlags), point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700923}
924
925FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
926 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700927 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800928 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700929 if (!pPageView || !pAnnot)
930 return FALSE;
931
dsinclairdf4bc592016-03-31 20:34:43 -0700932 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800933 return pWidgetHandler->OnRButtonUp(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700934 GetFWLFlags(nFlags), point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700935}
936
937FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView,
938 CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700939 uint32_t nFlags,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800940 const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700941 if (!pPageView || !pAnnot)
942 return FALSE;
943
dsinclairdf4bc592016-03-31 20:34:43 -0700944 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800945 return pWidgetHandler->OnRButtonDblClk(pAnnot->GetXFAWidget(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700946 GetFWLFlags(nFlags), point.x, point.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700947}
948
949FX_BOOL CPDFSDK_XFAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700950 uint32_t nChar,
951 uint32_t nFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700952 if (!pAnnot)
953 return FALSE;
954
dsinclairdf4bc592016-03-31 20:34:43 -0700955 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800956 return pWidgetHandler->OnChar(pAnnot->GetXFAWidget(), nChar,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700957 GetFWLFlags(nFlags));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700958}
959
960FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
961 int nKeyCode,
962 int nFlag) {
963 if (!pAnnot)
964 return FALSE;
965
dsinclairdf4bc592016-03-31 20:34:43 -0700966 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800967 return pWidgetHandler->OnKeyDown(pAnnot->GetXFAWidget(), nKeyCode,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700968 GetFWLFlags(nFlag));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700969}
970
971FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
972 int nKeyCode,
973 int nFlag) {
974 if (!pAnnot)
975 return FALSE;
976
dsinclairdf4bc592016-03-31 20:34:43 -0700977 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
Lei Zhang5eca3052016-02-22 20:32:21 -0800978 return pWidgetHandler->OnKeyUp(pAnnot->GetXFAWidget(), nKeyCode,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700979 GetFWLFlags(nFlag));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700980}
981
982FX_BOOL CPDFSDK_XFAAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700983 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700984 return TRUE;
985}
986
987FX_BOOL CPDFSDK_XFAAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot,
tsepezc3255f52016-03-25 14:52:27 -0700988 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700989 return TRUE;
990}
991
992FX_BOOL CPDFSDK_XFAAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot,
993 CPDFSDK_Annot* pNewAnnot) {
dsinclairdf4bc592016-03-31 20:34:43 -0700994 CXFA_FFWidgetHandler* pWidgetHandler = NULL;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700995
996 if (pOldAnnot)
997 pWidgetHandler = GetXFAWidgetHandler(pOldAnnot);
998 else if (pNewAnnot)
999 pWidgetHandler = GetXFAWidgetHandler(pNewAnnot);
1000
1001 if (pWidgetHandler) {
1002 FX_BOOL bRet = TRUE;
dsinclairdf4bc592016-03-31 20:34:43 -07001003 CXFA_FFWidget* hWidget = pNewAnnot ? pNewAnnot->GetXFAWidget() : NULL;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001004 if (hWidget) {
dsinclair221caf62016-04-04 12:08:40 -07001005 CXFA_FFPageView* pXFAPageView = hWidget->GetPageView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001006 if (pXFAPageView) {
1007 bRet = pXFAPageView->GetDocView()->SetFocus(hWidget);
1008 if (pXFAPageView->GetDocView()->GetFocusWidget() == hWidget)
1009 bRet = TRUE;
1010 }
Tom Sepezdcbc02f2015-07-17 09:16:17 -07001011 }
Tom Sepezdcbc02f2015-07-17 09:16:17 -07001012 return bRet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001013 }
1014
1015 return TRUE;
Bo Xufdc00a72014-10-28 23:03:33 -07001016}
1017
dsinclairdf4bc592016-03-31 20:34:43 -07001018CXFA_FFWidgetHandler* CPDFSDK_XFAAnnotHandler::GetXFAWidgetHandler(
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001019 CPDFSDK_Annot* pAnnot) {
1020 if (!pAnnot)
1021 return NULL;
Bo Xufdc00a72014-10-28 23:03:33 -07001022
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001023 CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
1024 if (!pPageView)
1025 return NULL;
Bo Xufdc00a72014-10-28 23:03:33 -07001026
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001027 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
1028 if (!pSDKDoc)
1029 return NULL;
Bo Xufdc00a72014-10-28 23:03:33 -07001030
Tom Sepez50d12ad2015-11-24 09:50:51 -08001031 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001032 if (!pDoc)
1033 return NULL;
1034
dsinclairdf4bc592016-03-31 20:34:43 -07001035 CXFA_FFDocView* pDocView = pDoc->GetXFADocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001036 if (!pDocView)
1037 return NULL;
1038
1039 return pDocView->GetWidgetHandler();
Bo Xufdc00a72014-10-28 23:03:33 -07001040}
1041
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001042#define FWL_KEYFLAG_Ctrl (1 << 0)
1043#define FWL_KEYFLAG_Alt (1 << 1)
1044#define FWL_KEYFLAG_Shift (1 << 2)
1045#define FWL_KEYFLAG_LButton (1 << 3)
1046#define FWL_KEYFLAG_RButton (1 << 4)
1047#define FWL_KEYFLAG_MButton (1 << 5)
Bo Xufdc00a72014-10-28 23:03:33 -07001048
tsepezc3255f52016-03-25 14:52:27 -07001049uint32_t CPDFSDK_XFAAnnotHandler::GetFWLFlags(uint32_t dwFlag) {
1050 uint32_t dwFWLFlag = 0;
Bo Xufdc00a72014-10-28 23:03:33 -07001051
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001052 if (dwFlag & FWL_EVENTFLAG_ControlKey)
1053 dwFWLFlag |= FWL_KEYFLAG_Ctrl;
1054 if (dwFlag & FWL_EVENTFLAG_LeftButtonDown)
1055 dwFWLFlag |= FWL_KEYFLAG_LButton;
1056 if (dwFlag & FWL_EVENTFLAG_MiddleButtonDown)
1057 dwFWLFlag |= FWL_KEYFLAG_MButton;
1058 if (dwFlag & FWL_EVENTFLAG_RightButtonDown)
1059 dwFWLFlag |= FWL_KEYFLAG_RButton;
1060 if (dwFlag & FWL_EVENTFLAG_ShiftKey)
1061 dwFWLFlag |= FWL_KEYFLAG_Shift;
1062 if (dwFlag & FWL_EVENTFLAG_AltKey)
1063 dwFWLFlag |= FWL_KEYFLAG_Alt;
Bo Xufdc00a72014-10-28 23:03:33 -07001064
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001065 return dwFWLFlag;
Bo Xufdc00a72014-10-28 23:03:33 -07001066}
Tom Sepez40e9ff32015-11-30 12:39:54 -08001067#endif // PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -07001068
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001069CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView,
Lei Zhangbf60b292015-10-26 12:14:35 -07001070 bool bReverse)
1071 : m_bReverse(bReverse), m_pos(0) {
1072 const std::vector<CPDFSDK_Annot*>& annots = pPageView->GetAnnotList();
1073 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), annots.rbegin(),
1074 annots.rend());
1075 std::stable_sort(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(),
1076 [](CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) {
1077 return p1->GetLayoutOrder() < p2->GetLayoutOrder();
1078 });
Bo Xufdc00a72014-10-28 23:03:33 -07001079
Lei Zhangbf60b292015-10-26 12:14:35 -07001080 CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot();
1081 if (!pTopMostAnnot)
1082 return;
Lei Zhang60f507b2015-06-13 00:41:00 -07001083
Lei Zhangbf60b292015-10-26 12:14:35 -07001084 auto it = std::find(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(),
1085 pTopMostAnnot);
1086 if (it != m_iteratorAnnotList.end()) {
1087 CPDFSDK_Annot* pReaderAnnot = *it;
1088 m_iteratorAnnotList.erase(it);
1089 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), pReaderAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001090 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001091}
1092
Dan Sinclairf766ad22016-03-14 13:51:24 -04001093CPDFSDK_AnnotIterator::~CPDFSDK_AnnotIterator() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001094
Lei Zhangbf60b292015-10-26 12:14:35 -07001095CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot() {
1096 if (m_pos < m_iteratorAnnotList.size())
1097 return m_iteratorAnnotList[m_pos++];
1098 return nullptr;
1099}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001100
Lei Zhangbf60b292015-10-26 12:14:35 -07001101CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot() {
1102 if (m_pos < m_iteratorAnnotList.size())
1103 return m_iteratorAnnotList[m_iteratorAnnotList.size() - ++m_pos];
1104 return nullptr;
1105}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001106
Lei Zhangbf60b292015-10-26 12:14:35 -07001107CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next() {
1108 return m_bReverse ? PrevAnnot() : NextAnnot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001109}