blob: ae6b5f2fc807cfd5df31fb5323a3fc5079b272e6 [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
Lei Zhangbf60b292015-10-26 12:14:35 -07007#include <algorithm>
8
Lei Zhangbde53d22015-11-12 22:21:30 -08009#include "fpdfsdk/include/formfiller/FFL_FormFiller.h"
10#include "fpdfsdk/include/fsdk_annothandler.h"
11#include "fpdfsdk/include/fsdk_define.h"
12#include "fpdfsdk/include/fsdk_mgr.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070013
Tom Sepez40e9ff32015-11-30 12:39:54 -080014#ifdef PDF_ENABLE_XFA
15#include "../include/fpdfxfa/fpdfxfa_doc.h"
16#include "../include/fpdfxfa/fpdfxfa_util.h"
17#endif // PDF_ENABLE_XFA
18
Nico Weber9d8ec5a2015-08-04 13:00:21 -070019CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) {
20 m_pApp = pApp;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070021
Nico Weber9d8ec5a2015-08-04 13:00:21 -070022 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp);
23 pHandler->SetFormFiller(m_pApp->GetIFormFiller());
24 RegisterAnnotHandler(pHandler);
Tom Sepez51da0932015-11-25 16:05:49 -080025#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -070026 CPDFSDK_XFAAnnotHandler* pXFAAnnotHandler =
27 new CPDFSDK_XFAAnnotHandler(m_pApp);
28 RegisterAnnotHandler(pXFAAnnotHandler);
Tom Sepez40e9ff32015-11-30 12:39:54 -080029#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030}
31
Nico Weber9d8ec5a2015-08-04 13:00:21 -070032CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {
33 for (int i = 0; i < m_Handlers.GetSize(); i++) {
34 IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i);
35 delete pHandler;
36 }
37 m_Handlers.RemoveAll();
Tom Sepez09d33bc2015-08-19 09:49:24 -070038 m_mapType2Handler.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070039}
40
41void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler(
42 IPDFSDK_AnnotHandler* pAnnotHandler) {
Tom Sepez09d33bc2015-08-19 09:49:24 -070043 ASSERT(!GetAnnotHandler(pAnnotHandler->GetType()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -070044
45 m_Handlers.Add(pAnnotHandler);
Tom Sepez09d33bc2015-08-19 09:49:24 -070046 m_mapType2Handler[pAnnotHandler->GetType()] = pAnnotHandler;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047}
48
49void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler(
50 IPDFSDK_AnnotHandler* pAnnotHandler) {
Tom Sepez09d33bc2015-08-19 09:49:24 -070051 m_mapType2Handler.erase(pAnnotHandler->GetType());
Nico Weber9d8ec5a2015-08-04 13:00:21 -070052 for (int i = 0, sz = m_Handlers.GetSize(); i < sz; i++) {
53 if (m_Handlers.GetAt(i) == pAnnotHandler) {
54 m_Handlers.RemoveAt(i);
55 break;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070056 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070058}
59
Nico Weber9d8ec5a2015-08-04 13:00:21 -070060CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot,
61 CPDFSDK_PageView* pPageView) {
62 ASSERT(pAnnot != NULL);
63 ASSERT(pPageView != NULL);
Lei Zhang60f507b2015-06-13 00:41:00 -070064
Nico Weber9d8ec5a2015-08-04 13:00:21 -070065 if (IPDFSDK_AnnotHandler* pAnnotHandler =
66 GetAnnotHandler(pAnnot->GetSubType())) {
67 return pAnnotHandler->NewAnnot(pAnnot, pPageView);
68 }
Lei Zhang60f507b2015-06-13 00:41:00 -070069
Nico Weber9d8ec5a2015-08-04 13:00:21 -070070 return new CPDFSDK_BAAnnot(pAnnot, pPageView);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071}
72
Tom Sepez51da0932015-11-25 16:05:49 -080073#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -070074CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(IXFA_Widget* pAnnot,
75 CPDFSDK_PageView* pPageView) {
76 ASSERT(pAnnot != NULL);
77 ASSERT(pPageView != NULL);
Lei Zhang60f507b2015-06-13 00:41:00 -070078
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079 if (IPDFSDK_AnnotHandler* pAnnotHandler =
80 GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME)) {
81 return pAnnotHandler->NewAnnot(pAnnot, pPageView);
82 }
Lei Zhang60f507b2015-06-13 00:41:00 -070083
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070085}
Tom Sepez40e9ff32015-11-30 12:39:54 -080086#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070087
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
89 ASSERT(pAnnot != NULL);
Lei Zhang60f507b2015-06-13 00:41:00 -070090
Nico Weber9d8ec5a2015-08-04 13:00:21 -070091 pAnnot->GetPDFPage();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070092
Nico Weber9d8ec5a2015-08-04 13:00:21 -070093 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
94 pAnnotHandler->OnRelease(pAnnot);
95 pAnnotHandler->ReleaseAnnot(pAnnot);
96 } else {
97 delete (CPDFSDK_Annot*)pAnnot;
98 }
Bo Xufdc00a72014-10-28 23:03:33 -070099}
100
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot) {
102 ASSERT(pAnnot != NULL);
Bo Xufdc00a72014-10-28 23:03:33 -0700103
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) {
116 ASSERT(pAnnot != NULL);
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 {
125 ASSERT(pAnnot != NULL);
Lei Zhang60f507b2015-06-13 00:41:00 -0700126
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
128 if (pPDFAnnot)
129 return GetAnnotHandler(pPDFAnnot->GetSubType());
Tom Sepez51da0932015-11-25 16:05:49 -0800130#ifdef PDF_ENABLE_XFA
Tom Sepezc7e4c4f2015-11-20 09:45:24 -0800131 if (pAnnot->GetXFAWidget())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700132 return GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800133#endif // PDF_ENABLE_XFA
Tom Sepezc7e4c4f2015-11-20 09:45:24 -0800134 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700135}
136
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700137IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
138 const CFX_ByteString& sType) const {
Tom Sepez09d33bc2015-08-19 09:49:24 -0700139 auto it = m_mapType2Handler.find(sType);
140 return it != m_mapType2Handler.end() ? it->second : nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700141}
142
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700143void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView,
144 CPDFSDK_Annot* pAnnot,
145 CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800146 CFX_Matrix* pUser2Device,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700147 FX_DWORD dwFlags) {
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500148 ASSERT(pAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700149
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700150 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
151 pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
152 } else {
Tom Sepez51da0932015-11-25 16:05:49 -0800153#ifdef PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800154 if (pAnnot->IsXFAField())
155 return;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800156#endif // PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800157 static_cast<CPDFSDK_BAAnnot*>(pAnnot)
158 ->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700159 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700160}
161
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700162FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(
163 CPDFSDK_PageView* pPageView,
164 CPDFSDK_Annot* pAnnot,
165 FX_DWORD nFlags,
166 const CPDF_Point& point) {
167 ASSERT(pAnnot != NULL);
168
169 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
170 return pAnnotHandler->OnLButtonDown(pPageView, pAnnot, nFlags, point);
171 }
172 return FALSE;
173}
174FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(CPDFSDK_PageView* pPageView,
175 CPDFSDK_Annot* pAnnot,
176 FX_DWORD nFlags,
177 const CPDF_Point& point) {
178 ASSERT(pAnnot != NULL);
179
180 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
181 return pAnnotHandler->OnLButtonUp(pPageView, pAnnot, nFlags, point);
182 }
183 return FALSE;
184}
185FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(
186 CPDFSDK_PageView* pPageView,
187 CPDFSDK_Annot* pAnnot,
188 FX_DWORD nFlags,
189 const CPDF_Point& point) {
190 ASSERT(pAnnot != NULL);
191
192 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
193 return pAnnotHandler->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
194 }
195 return FALSE;
196}
197FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(CPDFSDK_PageView* pPageView,
198 CPDFSDK_Annot* pAnnot,
199 FX_DWORD nFlags,
200 const CPDF_Point& point) {
201 ASSERT(pAnnot != NULL);
202
203 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
204 return pAnnotHandler->OnMouseMove(pPageView, pAnnot, nFlags, point);
205 }
206 return FALSE;
207}
208FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(CPDFSDK_PageView* pPageView,
209 CPDFSDK_Annot* pAnnot,
210 FX_DWORD nFlags,
211 short zDelta,
212 const CPDF_Point& point) {
213 ASSERT(pAnnot != NULL);
214
215 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
216 return pAnnotHandler->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,
217 point);
218 }
219 return FALSE;
220}
221FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(
222 CPDFSDK_PageView* pPageView,
223 CPDFSDK_Annot* pAnnot,
224 FX_DWORD nFlags,
225 const CPDF_Point& point) {
226 ASSERT(pAnnot != NULL);
227
228 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
229 return pAnnotHandler->OnRButtonDown(pPageView, pAnnot, nFlags, point);
230 }
231 return FALSE;
232}
233FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(CPDFSDK_PageView* pPageView,
234 CPDFSDK_Annot* pAnnot,
235 FX_DWORD nFlags,
236 const CPDF_Point& point) {
237 ASSERT(pAnnot != NULL);
238
239 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
240 return pAnnotHandler->OnRButtonUp(pPageView, pAnnot, nFlags, point);
241 }
242 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700243}
244
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700245void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(CPDFSDK_PageView* pPageView,
246 CPDFSDK_Annot* pAnnot,
247 FX_DWORD nFlag) {
248 ASSERT(pAnnot != NULL);
Lei Zhang60f507b2015-06-13 00:41:00 -0700249
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700250 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
251 pAnnotHandler->OnMouseEnter(pPageView, pAnnot, nFlag);
252 }
253 return;
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,
258 FX_DWORD nFlag) {
259 ASSERT(pAnnot != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700260
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
262 pAnnotHandler->OnMouseExit(pPageView, pAnnot, nFlag);
263 }
264 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700265}
266
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700267FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot,
268 FX_DWORD nChar,
269 FX_DWORD nFlags) {
270 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
271 return pAnnotHandler->OnChar(pAnnot, nChar, nFlags);
272 }
273 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700274}
275
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700276FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot,
277 int nKeyCode,
278 int nFlag) {
279 if (!m_pApp->FFI_IsCTRLKeyDown(nFlag) && !m_pApp->FFI_IsALTKeyDown(nFlag)) {
280 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
281 CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();
282 if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) {
283 CPDFSDK_Annot* pNext =
284 GetNextAnnot(pFocusAnnot, !m_pApp->FFI_IsSHIFTKeyDown(nFlag));
Lei Zhang60f507b2015-06-13 00:41:00 -0700285
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700286 if (pNext && pNext != pFocusAnnot) {
287 CPDFSDK_Document* pDocument = pPage->GetSDKDocument();
288 pDocument->SetFocusAnnot(pNext);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700289 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290 }
291 }
292 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700293
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
295 return pAnnotHandler->OnKeyDown(pAnnot, nKeyCode, nFlag);
296 }
297 return FALSE;
298}
299FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot,
300 int nKeyCode,
301 int nFlag) {
302 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700303}
304
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700305FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(CPDFSDK_Annot* pAnnot,
306 FX_DWORD nFlag) {
307 ASSERT(pAnnot != NULL);
Lei Zhang60f507b2015-06-13 00:41:00 -0700308
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
310 if (pAnnotHandler->OnSetFocus(pAnnot, nFlag)) {
311 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
312 pPage->GetSDKDocument();
313 return TRUE;
314 }
315 }
316 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700317}
318
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700319FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot,
320 FX_DWORD nFlag) {
321 ASSERT(pAnnot);
322 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
323 return pAnnotHandler->OnKillFocus(pAnnot, nFlag);
324
325 return FALSE;
326}
327
Tom Sepez51da0932015-11-25 16:05:49 -0800328#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700329FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus(
330 CPDFSDK_Annot* pSetAnnot,
331 CPDFSDK_Annot* pKillAnnot) {
332 FX_BOOL bXFA = (pSetAnnot && pSetAnnot->GetXFAWidget()) ||
333 (pKillAnnot && pKillAnnot->GetXFAWidget());
334
335 if (bXFA) {
336 if (IPDFSDK_AnnotHandler* pXFAAnnotHandler =
337 GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME))
338 return pXFAAnnotHandler->OnXFAChangedFocus(pKillAnnot, pSetAnnot);
339 }
340
341 return TRUE;
342}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800343#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700344
345CPDF_Rect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(
346 CPDFSDK_PageView* pPageView,
347 CPDFSDK_Annot* pAnnot) {
348 ASSERT(pAnnot);
349 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
350 return pAnnotHandler->GetViewBBox(pPageView, pAnnot);
351
352 return pAnnot->GetRect();
353}
354
355FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView,
356 CPDFSDK_Annot* pAnnot,
357 const CPDF_Point& point) {
358 ASSERT(pAnnot);
359 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
360 if (pAnnotHandler->CanAnswer(pAnnot))
361 return pAnnotHandler->HitTest(pPageView, pAnnot, point);
362 }
363 return FALSE;
364}
365
366CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,
367 FX_BOOL bNext) {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800368#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700369 CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView();
370 CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage();
371 if (pPage == NULL)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700372 return NULL;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700373 if (pPage->GetPDFPage()) { // for pdf annots.
374 CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), pSDKAnnot->GetType(), "");
375 CPDFSDK_Annot* pNext =
376 bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot);
377 return pNext;
378 }
379 // for xfa annots
380 IXFA_WidgetIterator* pWidgetIterator =
381 pPage->GetXFAPageView()->CreateWidgetIterator(
382 XFA_TRAVERSEWAY_Tranvalse, XFA_WIDGETFILTER_Visible |
383 XFA_WIDGETFILTER_Viewable |
384 XFA_WIDGETFILTER_Field);
385 if (pWidgetIterator == NULL)
386 return NULL;
387 if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget())
388 pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget());
389 IXFA_Widget* hNextFocus = NULL;
390 hNextFocus =
391 bNext ? pWidgetIterator->MoveToNext() : pWidgetIterator->MoveToPrevious();
392 if (hNextFocus == NULL && pSDKAnnot != NULL)
393 hNextFocus = pWidgetIterator->MoveToFirst();
394
395 pWidgetIterator->Release();
396 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
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700403FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
404 ASSERT(pAnnot->GetType() == "Widget");
405 if (pAnnot->GetSubType() == BFFT_SIGNATURE)
406 return FALSE;
407
408 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
409 if (!pWidget->IsVisible())
410 return FALSE;
411
412 int nFieldFlags = pWidget->GetFieldFlags();
413 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
414 return FALSE;
415
416 if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON)
417 return TRUE;
418
419 CPDF_Page* pPage = pWidget->GetPDFPage();
420 CPDF_Document* pDocument = pPage->m_pDocument;
421 FX_DWORD dwPermissions = pDocument->GetUserPermissions();
422 return (dwPermissions & FPDFPERM_FILL_FORM) ||
423 (dwPermissions & FPDFPERM_ANNOT_FORM);
424}
425
426CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot,
427 CPDFSDK_PageView* pPage) {
428 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument();
429 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm();
430 CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl(
431 pInterForm->GetInterForm(), pAnnot->GetAnnotDict());
432 if (!pCtrl)
433 return nullptr;
434
435 CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm);
436 pInterForm->AddMap(pCtrl, pWidget);
437 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
438 if (pPDFInterForm && pPDFInterForm->NeedConstructAP())
439 pWidget->ResetAppearance(nullptr, FALSE);
440
441 return pWidget;
442}
443
Tom Sepez51da0932015-11-25 16:05:49 -0800444#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700445CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(IXFA_Widget* hWidget,
446 CPDFSDK_PageView* pPage) {
447 return NULL;
448}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800449#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700450
451void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
452 ASSERT(pAnnot != NULL);
453
454 if (m_pFormFiller)
455 m_pFormFiller->OnDelete(pAnnot);
456
457 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
458 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
459 ASSERT(pInterForm != NULL);
460
461 CPDF_FormControl* pCtrol = pWidget->GetFormControl();
462 pInterForm->RemoveMap(pCtrol);
463
464 delete pWidget;
465}
466
467void CPDFSDK_BFAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
468 CPDFSDK_Annot* pAnnot,
469 CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800470 CFX_Matrix* pUser2Device,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 FX_DWORD dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700472 CFX_ByteString sSubType = pAnnot->GetSubType();
473
474 if (sSubType == BFFT_SIGNATURE) {
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500475 static_cast<CPDFSDK_BAAnnot*>(pAnnot)
476 ->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700477 } else {
478 if (m_pFormFiller) {
479 m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
480 }
481 }
482}
483
484void CPDFSDK_BFAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
485 CPDFSDK_Annot* pAnnot,
486 FX_DWORD nFlag) {
487 ASSERT(pAnnot != NULL);
488 CFX_ByteString sSubType = pAnnot->GetSubType();
489
490 if (sSubType == BFFT_SIGNATURE) {
491 } else {
492 if (m_pFormFiller)
493 m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag);
494 }
495}
496void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
497 CPDFSDK_Annot* pAnnot,
498 FX_DWORD nFlag) {
499 ASSERT(pAnnot != NULL);
500 CFX_ByteString sSubType = pAnnot->GetSubType();
501
502 if (sSubType == BFFT_SIGNATURE) {
503 } else {
504 if (m_pFormFiller)
505 m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag);
506 }
507}
508FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
509 CPDFSDK_Annot* pAnnot,
510 FX_DWORD nFlags,
511 const CPDF_Point& point) {
512 ASSERT(pAnnot != NULL);
513 CFX_ByteString sSubType = pAnnot->GetSubType();
514
515 if (sSubType == BFFT_SIGNATURE) {
516 } else {
517 if (m_pFormFiller)
518 return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point);
519 }
520
521 return FALSE;
522}
523
524FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
525 CPDFSDK_Annot* pAnnot,
526 FX_DWORD nFlags,
527 const CPDF_Point& point) {
528 ASSERT(pAnnot != NULL);
529 CFX_ByteString sSubType = pAnnot->GetSubType();
530
531 if (sSubType == BFFT_SIGNATURE) {
532 } else {
533 if (m_pFormFiller)
534 return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point);
535 }
536
537 return FALSE;
538}
539
540FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
541 CPDFSDK_Annot* pAnnot,
542 FX_DWORD nFlags,
543 const CPDF_Point& point) {
544 ASSERT(pAnnot != NULL);
545 CFX_ByteString sSubType = pAnnot->GetSubType();
546
547 if (sSubType == BFFT_SIGNATURE) {
548 } else {
549 if (m_pFormFiller)
550 return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
551 }
552
553 return FALSE;
554}
555
556FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
557 CPDFSDK_Annot* pAnnot,
558 FX_DWORD nFlags,
559 const CPDF_Point& point) {
560 ASSERT(pAnnot != NULL);
561 CFX_ByteString sSubType = pAnnot->GetSubType();
562
563 if (sSubType == BFFT_SIGNATURE) {
564 } else {
565 if (m_pFormFiller)
566 return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point);
567 }
568
569 return FALSE;
570}
571
572FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
573 CPDFSDK_Annot* pAnnot,
574 FX_DWORD nFlags,
575 short zDelta,
576 const CPDF_Point& point) {
577 ASSERT(pAnnot != NULL);
578 CFX_ByteString sSubType = pAnnot->GetSubType();
579
580 if (sSubType == BFFT_SIGNATURE) {
581 } else {
582 if (m_pFormFiller)
583 return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,
584 point);
585 }
586
587 return FALSE;
588}
589
590FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
591 CPDFSDK_Annot* pAnnot,
592 FX_DWORD nFlags,
593 const CPDF_Point& point) {
594 ASSERT(pAnnot != NULL);
595 CFX_ByteString sSubType = pAnnot->GetSubType();
596
597 if (sSubType == BFFT_SIGNATURE) {
598 } else {
599 if (m_pFormFiller)
600 return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point);
601 }
602
603 return FALSE;
604}
605FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
606 CPDFSDK_Annot* pAnnot,
607 FX_DWORD nFlags,
608 const CPDF_Point& point) {
609 ASSERT(pAnnot != NULL);
610 CFX_ByteString sSubType = pAnnot->GetSubType();
611
612 if (sSubType == BFFT_SIGNATURE) {
613 } else {
614 if (m_pFormFiller)
615 return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point);
616 }
617
618 return FALSE;
619}
620
621FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
622 FX_DWORD nChar,
623 FX_DWORD nFlags) {
624 ASSERT(pAnnot != NULL);
625 CFX_ByteString sSubType = pAnnot->GetSubType();
626
627 if (sSubType == BFFT_SIGNATURE) {
628 } else {
629 if (m_pFormFiller)
630 return m_pFormFiller->OnChar(pAnnot, nChar, nFlags);
631 }
632
633 return FALSE;
634}
635
636FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
637 int nKeyCode,
638 int nFlag) {
639 ASSERT(pAnnot != NULL);
640 CFX_ByteString sSubType = pAnnot->GetSubType();
641
642 if (sSubType == BFFT_SIGNATURE) {
643 } else {
644 if (m_pFormFiller)
645 return m_pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlag);
646 }
647
648 return FALSE;
649}
650
651FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
652 int nKeyCode,
653 int nFlag) {
654 return FALSE;
655}
656void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) {
657 ASSERT(pAnnot != NULL);
658 CFX_ByteString sSubType = pAnnot->GetSubType();
659
660 if (sSubType == BFFT_SIGNATURE) {
661 } else {
662 if (m_pFormFiller)
663 m_pFormFiller->OnCreate(pAnnot);
664 }
665}
666
667void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {
Tom Sepez50d12ad2015-11-24 09:50:51 -0800668 if (pAnnot->GetSubType() == BFFT_SIGNATURE)
669 return;
670
671 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
672 if (!pWidget->IsAppearanceValid())
673 pWidget->ResetAppearance(NULL, FALSE);
674
675 int nFieldType = pWidget->GetFieldType();
676 if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) {
677 FX_BOOL bFormated = FALSE;
678 CFX_WideString sValue = pWidget->OnFormat(bFormated);
679 if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) {
680 pWidget->ResetAppearance(sValue.c_str(), FALSE);
681 }
682 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700683
Tom Sepez51da0932015-11-25 16:05:49 -0800684#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685 CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700686 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800687 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
688 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
689 if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty())
690 pWidget->ResetAppearance(FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800692#endif // PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800693 if (m_pFormFiller)
694 m_pFormFiller->OnLoad(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700695}
696
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700697FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot,
698 FX_DWORD nFlag) {
699 ASSERT(pAnnot != NULL);
700 CFX_ByteString sSubType = pAnnot->GetSubType();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700701
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700702 if (sSubType == BFFT_SIGNATURE) {
703 } else {
704 if (m_pFormFiller)
705 return m_pFormFiller->OnSetFocus(pAnnot, nFlag);
706 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700707
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700708 return TRUE;
709}
710FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot,
711 FX_DWORD nFlag) {
712 ASSERT(pAnnot != NULL);
713 CFX_ByteString sSubType = pAnnot->GetSubType();
714
715 if (sSubType == BFFT_SIGNATURE) {
716 } else {
717 if (m_pFormFiller)
718 return m_pFormFiller->OnKillFocus(pAnnot, nFlag);
719 }
720
721 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700722}
723
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700724CPDF_Rect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
725 CPDFSDK_Annot* pAnnot) {
726 ASSERT(pAnnot != NULL);
727 CFX_ByteString sSubType = pAnnot->GetSubType();
Lei Zhang60f507b2015-06-13 00:41:00 -0700728
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700729 if (sSubType == BFFT_SIGNATURE) {
730 } else {
731 if (m_pFormFiller)
732 return m_pFormFiller->GetViewBBox(pPageView, pAnnot);
733 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700734
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700735 return CPDF_Rect(0, 0, 0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700736}
737
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700738FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
739 CPDFSDK_Annot* pAnnot,
740 const CPDF_Point& point) {
741 ASSERT(pPageView);
742 ASSERT(pAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700743
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700744 CPDF_Rect rect = GetViewBBox(pPageView, pAnnot);
745 return rect.Contains(point.x, point.y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700746}
747
Tom Sepez51da0932015-11-25 16:05:49 -0800748#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700749#define FWL_WGTHITTEST_Unknown 0
Nico Weber077f1a32015-08-06 15:08:57 -0700750#define FWL_WGTHITTEST_Client 1 // arrow
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700751#define FWL_WGTHITTEST_Titlebar 11 // caption
752#define FWL_WGTHITTEST_HScrollBar 15
753#define FWL_WGTHITTEST_VScrollBar 16
754#define FWL_WGTHITTEST_Border 17
755#define FWL_WGTHITTEST_Edit 19
756#define FWL_WGTHITTEST_HyperLink 20
Lei Zhang60f507b2015-06-13 00:41:00 -0700757
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700758CPDFSDK_XFAAnnotHandler::CPDFSDK_XFAAnnotHandler(CPDFDoc_Environment* pApp)
759 : m_pApp(pApp) {}
760
761CPDFSDK_Annot* CPDFSDK_XFAAnnotHandler::NewAnnot(IXFA_Widget* pAnnot,
762 CPDFSDK_PageView* pPage) {
763 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument();
764 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm();
765 CPDFSDK_XFAWidget* pWidget = new CPDFSDK_XFAWidget(pAnnot, pPage, pInterForm);
766 pInterForm->AddXFAMap(pAnnot, pWidget);
767 return pWidget;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700768}
769
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700770FX_BOOL CPDFSDK_XFAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
771 return pAnnot->GetXFAWidget() != NULL;
772}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700773
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700774void CPDFSDK_XFAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
775 CPDFSDK_Annot* pAnnot,
776 CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800777 CFX_Matrix* pUser2Device,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700778 FX_DWORD dwFlags) {
779 ASSERT(pPageView != NULL);
780 ASSERT(pAnnot != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700781
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700782 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
783 ASSERT(pSDKDoc != NULL);
784
785 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
786 ASSERT(pWidgetHandler != NULL);
787
788 CFX_Graphics gs;
789 gs.Create(pDevice);
790
791 CFX_Matrix mt;
792 mt = *(CFX_Matrix*)pUser2Device;
793
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700794 FX_BOOL bIsHighlight = FALSE;
795 if (pSDKDoc->GetFocusAnnot() != pAnnot)
796 bIsHighlight = TRUE;
797
798 pWidgetHandler->RenderWidget(pAnnot->GetXFAWidget(), &gs, &mt, bIsHighlight);
799
800 // to do highlight and shadow
801}
802
803void CPDFSDK_XFAAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
804 ASSERT(pAnnot != NULL);
805
806 CPDFSDK_XFAWidget* pWidget = (CPDFSDK_XFAWidget*)pAnnot;
807 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
808 ASSERT(pInterForm != NULL);
809
810 pInterForm->RemoveXFAMap(pWidget->GetXFAWidget());
811
812 delete pWidget;
813}
814
815CPDF_Rect CPDFSDK_XFAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
816 CPDFSDK_Annot* pAnnot) {
817 ASSERT(pAnnot != NULL);
818
819 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
820 ASSERT(pWidgetHandler != NULL);
821
Tom Sepeza8a39e22015-10-12 15:47:07 -0700822 CFX_RectF rcBBox;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700823 XFA_ELEMENT eType =
824 pWidgetHandler->GetDataAcc(pAnnot->GetXFAWidget())->GetUIType();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700825 if (eType == XFA_ELEMENT_Signature)
826 pWidgetHandler->GetBBox(pAnnot->GetXFAWidget(), rcBBox,
827 XFA_WIDGETSTATUS_Visible, TRUE);
828 else
829 pWidgetHandler->GetBBox(pAnnot->GetXFAWidget(), rcBBox, 0);
830
831 CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
832 rcBBox.top + rcBBox.height);
833 rcWidget.left -= 1.0f;
834 rcWidget.right += 1.0f;
835 rcWidget.bottom -= 1.0f;
836 rcWidget.top += 1.0f;
837
838 return rcWidget;
839}
840
841FX_BOOL CPDFSDK_XFAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
842 CPDFSDK_Annot* pAnnot,
843 const CPDF_Point& point) {
844 if (!pPageView || !pAnnot)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700845 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700846
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700847 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
848 if (!pSDKDoc)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700849 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700850
Tom Sepez50d12ad2015-11-24 09:50:51 -0800851 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700852 if (!pDoc)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700853 return FALSE;
Lei Zhang60f507b2015-06-13 00:41:00 -0700854
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700855 IXFA_DocView* pDocView = pDoc->GetXFADocView();
856 if (!pDocView)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700857 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700858
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700859 IXFA_WidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
860 if (!pWidgetHandler)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700861 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700862
863 FX_DWORD dwHitTest =
864 pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point.x, point.y);
865 return (dwHitTest != FWL_WGTHITTEST_Unknown);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700866}
867
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700868void CPDFSDK_XFAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
869 CPDFSDK_Annot* pAnnot,
870 FX_DWORD nFlag) {
871 if (!pPageView || !pAnnot)
872 return;
873 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
874 ASSERT(pWidgetHandler != NULL);
Lei Zhang60f507b2015-06-13 00:41:00 -0700875
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700876 pWidgetHandler->OnMouseEnter(pAnnot->GetXFAWidget());
877}
Lei Zhang60f507b2015-06-13 00:41:00 -0700878
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700879void CPDFSDK_XFAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
880 CPDFSDK_Annot* pAnnot,
881 FX_DWORD nFlag) {
882 if (!pPageView || !pAnnot)
883 return;
884
885 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
886 ASSERT(pWidgetHandler != NULL);
887
888 pWidgetHandler->OnMouseExit(pAnnot->GetXFAWidget());
889}
890
891FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
892 CPDFSDK_Annot* pAnnot,
893 FX_DWORD nFlags,
894 const CPDF_Point& point) {
895 if (!pPageView || !pAnnot)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700896 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700897
898 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
899 ASSERT(pWidgetHandler != NULL);
900
901 FX_BOOL bRet = FALSE;
902 bRet = pWidgetHandler->OnLButtonDown(pAnnot->GetXFAWidget(),
903 GetFWLFlags(nFlags), point.x, point.y);
904
905 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700906}
907
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700908FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
909 CPDFSDK_Annot* pAnnot,
910 FX_DWORD nFlags,
911 const CPDF_Point& point) {
912 if (!pPageView || !pAnnot)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700913 return FALSE;
Lei Zhang60f507b2015-06-13 00:41:00 -0700914
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700915 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
916 ASSERT(pWidgetHandler != NULL);
917
918 FX_BOOL bRet = FALSE;
919 bRet = pWidgetHandler->OnLButtonUp(pAnnot->GetXFAWidget(),
920 GetFWLFlags(nFlags), point.x, point.y);
921
922 return bRet;
923}
924
925FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
926 CPDFSDK_Annot* pAnnot,
927 FX_DWORD nFlags,
928 const CPDF_Point& point) {
929 if (!pPageView || !pAnnot)
930 return FALSE;
931
932 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
933 ASSERT(pWidgetHandler != NULL);
934
935 FX_BOOL bRet = FALSE;
936 bRet = pWidgetHandler->OnLButtonDblClk(pAnnot->GetXFAWidget(),
937 GetFWLFlags(nFlags), point.x, point.y);
938
939 return bRet;
940}
941
942FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
943 CPDFSDK_Annot* pAnnot,
944 FX_DWORD nFlags,
945 const CPDF_Point& point) {
946 if (!pPageView || !pAnnot)
947 return FALSE;
948
949 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
950 ASSERT(pWidgetHandler != NULL);
951
952 FX_BOOL bRet = FALSE;
953 bRet = pWidgetHandler->OnMouseMove(pAnnot->GetXFAWidget(),
954 GetFWLFlags(nFlags), point.x, point.y);
955
956 return bRet;
957}
958
959FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
960 CPDFSDK_Annot* pAnnot,
961 FX_DWORD nFlags,
962 short zDelta,
963 const CPDF_Point& point) {
964 if (!pPageView || !pAnnot)
965 return FALSE;
966
967 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
968 ASSERT(pWidgetHandler != NULL);
969
970 FX_BOOL bRet = FALSE;
971 bRet = pWidgetHandler->OnMouseWheel(
972 pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), zDelta, point.x, point.y);
973
974 return bRet;
975}
976
977FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
978 CPDFSDK_Annot* pAnnot,
979 FX_DWORD nFlags,
980 const CPDF_Point& point) {
981 if (!pPageView || !pAnnot)
982 return FALSE;
983
984 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
985 ASSERT(pWidgetHandler != NULL);
986
987 FX_BOOL bRet = FALSE;
988 bRet = pWidgetHandler->OnRButtonDown(pAnnot->GetXFAWidget(),
989 GetFWLFlags(nFlags), point.x, point.y);
990
991 return bRet;
992}
993
994FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
995 CPDFSDK_Annot* pAnnot,
996 FX_DWORD nFlags,
997 const CPDF_Point& point) {
998 if (!pPageView || !pAnnot)
999 return FALSE;
1000
1001 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
1002 ASSERT(pWidgetHandler != NULL);
1003
1004 FX_BOOL bRet = FALSE;
1005 bRet = pWidgetHandler->OnRButtonUp(pAnnot->GetXFAWidget(),
1006 GetFWLFlags(nFlags), point.x, point.y);
1007
1008 return bRet;
1009}
1010
1011FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView,
1012 CPDFSDK_Annot* pAnnot,
1013 FX_DWORD nFlags,
1014 const CPDF_Point& point) {
1015 if (!pPageView || !pAnnot)
1016 return FALSE;
1017
1018 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
1019 ASSERT(pWidgetHandler != NULL);
1020
1021 FX_BOOL bRet = FALSE;
1022 bRet = pWidgetHandler->OnRButtonDblClk(pAnnot->GetXFAWidget(),
1023 GetFWLFlags(nFlags), point.x, point.y);
1024
1025 return bRet;
1026}
1027
1028FX_BOOL CPDFSDK_XFAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
1029 FX_DWORD nChar,
1030 FX_DWORD nFlags) {
1031 if (!pAnnot)
1032 return FALSE;
1033
1034 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
1035 ASSERT(pWidgetHandler != NULL);
1036
1037 FX_BOOL bRet = FALSE;
1038 bRet = pWidgetHandler->OnChar(pAnnot->GetXFAWidget(), nChar,
1039 GetFWLFlags(nFlags));
1040
1041 return bRet;
1042}
1043
1044FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
1045 int nKeyCode,
1046 int nFlag) {
1047 if (!pAnnot)
1048 return FALSE;
1049
1050 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
1051 ASSERT(pWidgetHandler != NULL);
1052
1053 FX_BOOL bRet = FALSE;
1054 bRet = pWidgetHandler->OnKeyDown(pAnnot->GetXFAWidget(), nKeyCode,
1055 GetFWLFlags(nFlag));
1056
1057 return bRet;
1058}
1059
1060FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
1061 int nKeyCode,
1062 int nFlag) {
1063 if (!pAnnot)
1064 return FALSE;
1065
1066 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
1067 ASSERT(pWidgetHandler != NULL);
1068
1069 FX_BOOL bRet = FALSE;
1070 bRet = pWidgetHandler->OnKeyUp(pAnnot->GetXFAWidget(), nKeyCode,
1071 GetFWLFlags(nFlag));
1072
1073 return bRet;
1074}
1075
1076FX_BOOL CPDFSDK_XFAAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot,
1077 FX_DWORD nFlag) {
1078 return TRUE;
1079}
1080
1081FX_BOOL CPDFSDK_XFAAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot,
1082 FX_DWORD nFlag) {
1083 return TRUE;
1084}
1085
1086FX_BOOL CPDFSDK_XFAAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot,
1087 CPDFSDK_Annot* pNewAnnot) {
1088 IXFA_WidgetHandler* pWidgetHandler = NULL;
1089
1090 if (pOldAnnot)
1091 pWidgetHandler = GetXFAWidgetHandler(pOldAnnot);
1092 else if (pNewAnnot)
1093 pWidgetHandler = GetXFAWidgetHandler(pNewAnnot);
1094
1095 if (pWidgetHandler) {
1096 FX_BOOL bRet = TRUE;
1097 IXFA_Widget* hWidget = pNewAnnot ? pNewAnnot->GetXFAWidget() : NULL;
1098 if (hWidget) {
1099 IXFA_PageView* pXFAPageView = pWidgetHandler->GetPageView(hWidget);
1100 if (pXFAPageView) {
1101 bRet = pXFAPageView->GetDocView()->SetFocus(hWidget);
1102 if (pXFAPageView->GetDocView()->GetFocusWidget() == hWidget)
1103 bRet = TRUE;
1104 }
Tom Sepezdcbc02f2015-07-17 09:16:17 -07001105 }
Tom Sepezdcbc02f2015-07-17 09:16:17 -07001106 return bRet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001107 }
1108
1109 return TRUE;
Bo Xufdc00a72014-10-28 23:03:33 -07001110}
1111
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001112IXFA_WidgetHandler* CPDFSDK_XFAAnnotHandler::GetXFAWidgetHandler(
1113 CPDFSDK_Annot* pAnnot) {
1114 if (!pAnnot)
1115 return NULL;
Bo Xufdc00a72014-10-28 23:03:33 -07001116
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001117 CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
1118 if (!pPageView)
1119 return NULL;
Bo Xufdc00a72014-10-28 23:03:33 -07001120
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001121 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
1122 if (!pSDKDoc)
1123 return NULL;
Bo Xufdc00a72014-10-28 23:03:33 -07001124
Tom Sepez50d12ad2015-11-24 09:50:51 -08001125 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001126 if (!pDoc)
1127 return NULL;
1128
1129 IXFA_DocView* pDocView = pDoc->GetXFADocView();
1130 if (!pDocView)
1131 return NULL;
1132
1133 return pDocView->GetWidgetHandler();
Bo Xufdc00a72014-10-28 23:03:33 -07001134}
1135
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001136#define FWL_KEYFLAG_Ctrl (1 << 0)
1137#define FWL_KEYFLAG_Alt (1 << 1)
1138#define FWL_KEYFLAG_Shift (1 << 2)
1139#define FWL_KEYFLAG_LButton (1 << 3)
1140#define FWL_KEYFLAG_RButton (1 << 4)
1141#define FWL_KEYFLAG_MButton (1 << 5)
Bo Xufdc00a72014-10-28 23:03:33 -07001142
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001143FX_DWORD CPDFSDK_XFAAnnotHandler::GetFWLFlags(FX_DWORD dwFlag) {
1144 FX_DWORD dwFWLFlag = 0;
Bo Xufdc00a72014-10-28 23:03:33 -07001145
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001146 if (dwFlag & FWL_EVENTFLAG_ControlKey)
1147 dwFWLFlag |= FWL_KEYFLAG_Ctrl;
1148 if (dwFlag & FWL_EVENTFLAG_LeftButtonDown)
1149 dwFWLFlag |= FWL_KEYFLAG_LButton;
1150 if (dwFlag & FWL_EVENTFLAG_MiddleButtonDown)
1151 dwFWLFlag |= FWL_KEYFLAG_MButton;
1152 if (dwFlag & FWL_EVENTFLAG_RightButtonDown)
1153 dwFWLFlag |= FWL_KEYFLAG_RButton;
1154 if (dwFlag & FWL_EVENTFLAG_ShiftKey)
1155 dwFWLFlag |= FWL_KEYFLAG_Shift;
1156 if (dwFlag & FWL_EVENTFLAG_AltKey)
1157 dwFWLFlag |= FWL_KEYFLAG_Alt;
Bo Xufdc00a72014-10-28 23:03:33 -07001158
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001159 return dwFWLFlag;
Bo Xufdc00a72014-10-28 23:03:33 -07001160}
Tom Sepez40e9ff32015-11-30 12:39:54 -08001161#endif // PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -07001162
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001163CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView,
Lei Zhangbf60b292015-10-26 12:14:35 -07001164 bool bReverse)
1165 : m_bReverse(bReverse), m_pos(0) {
1166 const std::vector<CPDFSDK_Annot*>& annots = pPageView->GetAnnotList();
1167 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), annots.rbegin(),
1168 annots.rend());
1169 std::stable_sort(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(),
1170 [](CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) {
1171 return p1->GetLayoutOrder() < p2->GetLayoutOrder();
1172 });
Bo Xufdc00a72014-10-28 23:03:33 -07001173
Lei Zhangbf60b292015-10-26 12:14:35 -07001174 CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot();
1175 if (!pTopMostAnnot)
1176 return;
Lei Zhang60f507b2015-06-13 00:41:00 -07001177
Lei Zhangbf60b292015-10-26 12:14:35 -07001178 auto it = std::find(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(),
1179 pTopMostAnnot);
1180 if (it != m_iteratorAnnotList.end()) {
1181 CPDFSDK_Annot* pReaderAnnot = *it;
1182 m_iteratorAnnotList.erase(it);
1183 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), pReaderAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001184 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001185}
1186
Lei Zhangbf60b292015-10-26 12:14:35 -07001187CPDFSDK_AnnotIterator::~CPDFSDK_AnnotIterator() {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001188}
1189
Lei Zhangbf60b292015-10-26 12:14:35 -07001190CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot() {
1191 if (m_pos < m_iteratorAnnotList.size())
1192 return m_iteratorAnnotList[m_pos++];
1193 return nullptr;
1194}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001195
Lei Zhangbf60b292015-10-26 12:14:35 -07001196CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot() {
1197 if (m_pos < m_iteratorAnnotList.size())
1198 return m_iteratorAnnotList[m_iteratorAnnotList.size() - ++m_pos];
1199 return nullptr;
1200}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001201
Lei Zhangbf60b292015-10-26 12:14:35 -07001202CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next() {
1203 return m_bReverse ? PrevAnnot() : NextAnnot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001204}