blob: e0c49411a9a0f2435b7c2b32a5caa6d308e478bb [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
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009#include "../include/fsdk_define.h"
Bo Xufdc00a72014-10-28 23:03:33 -070010#include "../include/fpdfxfa/fpdfxfa_doc.h"
11#include "../include/fpdfxfa/fpdfxfa_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070012#include "../include/fsdk_mgr.h"
13#include "../include/formfiller/FFL_FormFiller.h"
14#include "../include/fsdk_annothandler.h"
15
Nico Weber9d8ec5a2015-08-04 13:00:21 -070016CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) {
17 m_pApp = pApp;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070018
Nico Weber9d8ec5a2015-08-04 13:00:21 -070019 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp);
20 pHandler->SetFormFiller(m_pApp->GetIFormFiller());
21 RegisterAnnotHandler(pHandler);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070022
Nico Weber9d8ec5a2015-08-04 13:00:21 -070023 CPDFSDK_XFAAnnotHandler* pXFAAnnotHandler =
24 new CPDFSDK_XFAAnnotHandler(m_pApp);
25 RegisterAnnotHandler(pXFAAnnotHandler);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070026}
27
Nico Weber9d8ec5a2015-08-04 13:00:21 -070028CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {
29 for (int i = 0; i < m_Handlers.GetSize(); i++) {
30 IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i);
31 delete pHandler;
32 }
33 m_Handlers.RemoveAll();
Tom Sepez09d33bc2015-08-19 09:49:24 -070034 m_mapType2Handler.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070035}
36
37void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler(
38 IPDFSDK_AnnotHandler* pAnnotHandler) {
Tom Sepez09d33bc2015-08-19 09:49:24 -070039 ASSERT(!GetAnnotHandler(pAnnotHandler->GetType()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -070040
41 m_Handlers.Add(pAnnotHandler);
Tom Sepez09d33bc2015-08-19 09:49:24 -070042 m_mapType2Handler[pAnnotHandler->GetType()] = pAnnotHandler;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043}
44
45void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler(
46 IPDFSDK_AnnotHandler* pAnnotHandler) {
Tom Sepez09d33bc2015-08-19 09:49:24 -070047 m_mapType2Handler.erase(pAnnotHandler->GetType());
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048 for (int i = 0, sz = m_Handlers.GetSize(); i < sz; i++) {
49 if (m_Handlers.GetAt(i) == pAnnotHandler) {
50 m_Handlers.RemoveAt(i);
51 break;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070052 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070053 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070054}
55
Nico Weber9d8ec5a2015-08-04 13:00:21 -070056CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot,
57 CPDFSDK_PageView* pPageView) {
58 ASSERT(pAnnot != NULL);
59 ASSERT(pPageView != NULL);
Lei Zhang60f507b2015-06-13 00:41:00 -070060
Nico Weber9d8ec5a2015-08-04 13:00:21 -070061 if (IPDFSDK_AnnotHandler* pAnnotHandler =
62 GetAnnotHandler(pAnnot->GetSubType())) {
63 return pAnnotHandler->NewAnnot(pAnnot, pPageView);
64 }
Lei Zhang60f507b2015-06-13 00:41:00 -070065
Nico Weber9d8ec5a2015-08-04 13:00:21 -070066 return new CPDFSDK_BAAnnot(pAnnot, pPageView);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070067}
68
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(IXFA_Widget* pAnnot,
70 CPDFSDK_PageView* pPageView) {
71 ASSERT(pAnnot != NULL);
72 ASSERT(pPageView != NULL);
Lei Zhang60f507b2015-06-13 00:41:00 -070073
Nico Weber9d8ec5a2015-08-04 13:00:21 -070074 if (IPDFSDK_AnnotHandler* pAnnotHandler =
75 GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME)) {
76 return pAnnotHandler->NewAnnot(pAnnot, pPageView);
77 }
Lei Zhang60f507b2015-06-13 00:41:00 -070078
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070080}
81
Nico Weber9d8ec5a2015-08-04 13:00:21 -070082void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
83 ASSERT(pAnnot != NULL);
Lei Zhang60f507b2015-06-13 00:41:00 -070084
Nico Weber9d8ec5a2015-08-04 13:00:21 -070085 pAnnot->GetPDFPage();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070086
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
88 pAnnotHandler->OnRelease(pAnnot);
89 pAnnotHandler->ReleaseAnnot(pAnnot);
90 } else {
91 delete (CPDFSDK_Annot*)pAnnot;
92 }
Bo Xufdc00a72014-10-28 23:03:33 -070093}
94
Nico Weber9d8ec5a2015-08-04 13:00:21 -070095void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot) {
96 ASSERT(pAnnot != NULL);
Bo Xufdc00a72014-10-28 23:03:33 -070097
Nico Weber9d8ec5a2015-08-04 13:00:21 -070098 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
Bo Xufdc00a72014-10-28 23:03:33 -070099
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700100 CPDFSDK_DateTime curTime;
101 pPDFAnnot->GetAnnotDict()->SetAtString("M", curTime.ToPDFDateTimeString());
102 pPDFAnnot->GetAnnotDict()->SetAtNumber("F", 0);
103
104 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
105 pAnnotHandler->OnCreate(pAnnot);
106 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700107}
108
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700109void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) {
110 ASSERT(pAnnot != NULL);
Lei Zhang60f507b2015-06-13 00:41:00 -0700111
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700112 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
113 pAnnotHandler->OnLoad(pAnnot);
114 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700115}
116
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700117IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
118 CPDFSDK_Annot* pAnnot) const {
119 ASSERT(pAnnot != NULL);
Lei Zhang60f507b2015-06-13 00:41:00 -0700120
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700121 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
122 if (pPDFAnnot)
123 return GetAnnotHandler(pPDFAnnot->GetSubType());
124 else if (pAnnot->GetXFAWidget())
125 return GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME);
126 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700127}
128
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700129IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
130 const CFX_ByteString& sType) const {
Tom Sepez09d33bc2015-08-19 09:49:24 -0700131 auto it = m_mapType2Handler.find(sType);
132 return it != m_mapType2Handler.end() ? it->second : nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700133}
134
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView,
136 CPDFSDK_Annot* pAnnot,
137 CFX_RenderDevice* pDevice,
138 CPDF_Matrix* pUser2Device,
139 FX_DWORD dwFlags) {
140 ASSERT(pAnnot != NULL);
Lei Zhang60f507b2015-06-13 00:41:00 -0700141
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700142 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
143 pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
144 } else {
145 if (!pAnnot->IsXFAField())
146 ((CPDFSDK_BAAnnot*)pAnnot)
147 ->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
148 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700149}
150
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700151FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(
152 CPDFSDK_PageView* pPageView,
153 CPDFSDK_Annot* pAnnot,
154 FX_DWORD nFlags,
155 const CPDF_Point& point) {
156 ASSERT(pAnnot != NULL);
157
158 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
159 return pAnnotHandler->OnLButtonDown(pPageView, pAnnot, nFlags, point);
160 }
161 return FALSE;
162}
163FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(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->OnLButtonUp(pPageView, pAnnot, nFlags, point);
171 }
172 return FALSE;
173}
174FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(
175 CPDFSDK_PageView* pPageView,
176 CPDFSDK_Annot* pAnnot,
177 FX_DWORD nFlags,
178 const CPDF_Point& point) {
179 ASSERT(pAnnot != NULL);
180
181 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
182 return pAnnotHandler->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
183 }
184 return FALSE;
185}
186FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(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->OnMouseMove(pPageView, pAnnot, nFlags, point);
194 }
195 return FALSE;
196}
197FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(CPDFSDK_PageView* pPageView,
198 CPDFSDK_Annot* pAnnot,
199 FX_DWORD nFlags,
200 short zDelta,
201 const CPDF_Point& point) {
202 ASSERT(pAnnot != NULL);
203
204 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
205 return pAnnotHandler->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,
206 point);
207 }
208 return FALSE;
209}
210FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(
211 CPDFSDK_PageView* pPageView,
212 CPDFSDK_Annot* pAnnot,
213 FX_DWORD nFlags,
214 const CPDF_Point& point) {
215 ASSERT(pAnnot != NULL);
216
217 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
218 return pAnnotHandler->OnRButtonDown(pPageView, pAnnot, nFlags, point);
219 }
220 return FALSE;
221}
222FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(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->OnRButtonUp(pPageView, pAnnot, nFlags, point);
230 }
231 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700232}
233
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700234void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(CPDFSDK_PageView* pPageView,
235 CPDFSDK_Annot* pAnnot,
236 FX_DWORD nFlag) {
237 ASSERT(pAnnot != NULL);
Lei Zhang60f507b2015-06-13 00:41:00 -0700238
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700239 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
240 pAnnotHandler->OnMouseEnter(pPageView, pAnnot, nFlag);
241 }
242 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700243}
244
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700245void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(CPDFSDK_PageView* pPageView,
246 CPDFSDK_Annot* pAnnot,
247 FX_DWORD nFlag) {
248 ASSERT(pAnnot != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700249
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700250 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
251 pAnnotHandler->OnMouseExit(pPageView, pAnnot, nFlag);
252 }
253 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700254}
255
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700256FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot,
257 FX_DWORD nChar,
258 FX_DWORD nFlags) {
259 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
260 return pAnnotHandler->OnChar(pAnnot, nChar, nFlags);
261 }
262 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700263}
264
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700265FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot,
266 int nKeyCode,
267 int nFlag) {
268 if (!m_pApp->FFI_IsCTRLKeyDown(nFlag) && !m_pApp->FFI_IsALTKeyDown(nFlag)) {
269 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
270 CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();
271 if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) {
272 CPDFSDK_Annot* pNext =
273 GetNextAnnot(pFocusAnnot, !m_pApp->FFI_IsSHIFTKeyDown(nFlag));
Lei Zhang60f507b2015-06-13 00:41:00 -0700274
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700275 if (pNext && pNext != pFocusAnnot) {
276 CPDFSDK_Document* pDocument = pPage->GetSDKDocument();
277 pDocument->SetFocusAnnot(pNext);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700278 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700279 }
280 }
281 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700282
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700283 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
284 return pAnnotHandler->OnKeyDown(pAnnot, nKeyCode, nFlag);
285 }
286 return FALSE;
287}
288FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot,
289 int nKeyCode,
290 int nFlag) {
291 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700292}
293
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(CPDFSDK_Annot* pAnnot,
295 FX_DWORD nFlag) {
296 ASSERT(pAnnot != NULL);
Lei Zhang60f507b2015-06-13 00:41:00 -0700297
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700298 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
299 if (pAnnotHandler->OnSetFocus(pAnnot, nFlag)) {
300 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
301 pPage->GetSDKDocument();
302 return TRUE;
303 }
304 }
305 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700306}
307
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700308FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot,
309 FX_DWORD nFlag) {
310 ASSERT(pAnnot);
311 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
312 return pAnnotHandler->OnKillFocus(pAnnot, nFlag);
313
314 return FALSE;
315}
316
317FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus(
318 CPDFSDK_Annot* pSetAnnot,
319 CPDFSDK_Annot* pKillAnnot) {
320 FX_BOOL bXFA = (pSetAnnot && pSetAnnot->GetXFAWidget()) ||
321 (pKillAnnot && pKillAnnot->GetXFAWidget());
322
323 if (bXFA) {
324 if (IPDFSDK_AnnotHandler* pXFAAnnotHandler =
325 GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME))
326 return pXFAAnnotHandler->OnXFAChangedFocus(pKillAnnot, pSetAnnot);
327 }
328
329 return TRUE;
330}
331
332CPDF_Rect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(
333 CPDFSDK_PageView* pPageView,
334 CPDFSDK_Annot* pAnnot) {
335 ASSERT(pAnnot);
336 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
337 return pAnnotHandler->GetViewBBox(pPageView, pAnnot);
338
339 return pAnnot->GetRect();
340}
341
342FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView,
343 CPDFSDK_Annot* pAnnot,
344 const CPDF_Point& point) {
345 ASSERT(pAnnot);
346 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
347 if (pAnnotHandler->CanAnswer(pAnnot))
348 return pAnnotHandler->HitTest(pPageView, pAnnot, point);
349 }
350 return FALSE;
351}
352
353CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,
354 FX_BOOL bNext) {
355 CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView();
356 CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage();
357 if (pPage == NULL)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700358 return NULL;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359 if (pPage->GetPDFPage()) { // for pdf annots.
360 CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), pSDKAnnot->GetType(), "");
361 CPDFSDK_Annot* pNext =
362 bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot);
363 return pNext;
364 }
365 // for xfa annots
366 IXFA_WidgetIterator* pWidgetIterator =
367 pPage->GetXFAPageView()->CreateWidgetIterator(
368 XFA_TRAVERSEWAY_Tranvalse, XFA_WIDGETFILTER_Visible |
369 XFA_WIDGETFILTER_Viewable |
370 XFA_WIDGETFILTER_Field);
371 if (pWidgetIterator == NULL)
372 return NULL;
373 if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget())
374 pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget());
375 IXFA_Widget* hNextFocus = NULL;
376 hNextFocus =
377 bNext ? pWidgetIterator->MoveToNext() : pWidgetIterator->MoveToPrevious();
378 if (hNextFocus == NULL && pSDKAnnot != NULL)
379 hNextFocus = pWidgetIterator->MoveToFirst();
380
381 pWidgetIterator->Release();
382 return pPageView->GetAnnotByXFAWidget(hNextFocus);
Bo Xufdc00a72014-10-28 23:03:33 -0700383}
384
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700385FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
386 ASSERT(pAnnot->GetType() == "Widget");
387 if (pAnnot->GetSubType() == BFFT_SIGNATURE)
388 return FALSE;
389
390 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
391 if (!pWidget->IsVisible())
392 return FALSE;
393
394 int nFieldFlags = pWidget->GetFieldFlags();
395 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
396 return FALSE;
397
398 if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON)
399 return TRUE;
400
401 CPDF_Page* pPage = pWidget->GetPDFPage();
402 CPDF_Document* pDocument = pPage->m_pDocument;
403 FX_DWORD dwPermissions = pDocument->GetUserPermissions();
404 return (dwPermissions & FPDFPERM_FILL_FORM) ||
405 (dwPermissions & FPDFPERM_ANNOT_FORM);
406}
407
408CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot,
409 CPDFSDK_PageView* pPage) {
410 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument();
411 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm();
412 CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl(
413 pInterForm->GetInterForm(), pAnnot->GetAnnotDict());
414 if (!pCtrl)
415 return nullptr;
416
417 CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm);
418 pInterForm->AddMap(pCtrl, pWidget);
419 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
420 if (pPDFInterForm && pPDFInterForm->NeedConstructAP())
421 pWidget->ResetAppearance(nullptr, FALSE);
422
423 return pWidget;
424}
425
426CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(IXFA_Widget* hWidget,
427 CPDFSDK_PageView* pPage) {
428 return NULL;
429}
430
431void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
432 ASSERT(pAnnot != NULL);
433
434 if (m_pFormFiller)
435 m_pFormFiller->OnDelete(pAnnot);
436
437 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
438 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
439 ASSERT(pInterForm != NULL);
440
441 CPDF_FormControl* pCtrol = pWidget->GetFormControl();
442 pInterForm->RemoveMap(pCtrol);
443
444 delete pWidget;
445}
446
447void CPDFSDK_BFAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
448 CPDFSDK_Annot* pAnnot,
449 CFX_RenderDevice* pDevice,
450 CPDF_Matrix* pUser2Device,
451 FX_DWORD dwFlags) {
452 ASSERT(pAnnot != NULL);
453 CFX_ByteString sSubType = pAnnot->GetSubType();
454
455 if (sSubType == BFFT_SIGNATURE) {
456 ((CPDFSDK_BAAnnot*)pAnnot)
457 ->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
458 } else {
459 if (m_pFormFiller) {
460 m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
461 }
462 }
463}
464
465void CPDFSDK_BFAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
466 CPDFSDK_Annot* pAnnot,
467 FX_DWORD nFlag) {
468 ASSERT(pAnnot != NULL);
469 CFX_ByteString sSubType = pAnnot->GetSubType();
470
471 if (sSubType == BFFT_SIGNATURE) {
472 } else {
473 if (m_pFormFiller)
474 m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag);
475 }
476}
477void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
478 CPDFSDK_Annot* pAnnot,
479 FX_DWORD nFlag) {
480 ASSERT(pAnnot != NULL);
481 CFX_ByteString sSubType = pAnnot->GetSubType();
482
483 if (sSubType == BFFT_SIGNATURE) {
484 } else {
485 if (m_pFormFiller)
486 m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag);
487 }
488}
489FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
490 CPDFSDK_Annot* pAnnot,
491 FX_DWORD nFlags,
492 const CPDF_Point& point) {
493 ASSERT(pAnnot != NULL);
494 CFX_ByteString sSubType = pAnnot->GetSubType();
495
496 if (sSubType == BFFT_SIGNATURE) {
497 } else {
498 if (m_pFormFiller)
499 return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point);
500 }
501
502 return FALSE;
503}
504
505FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
506 CPDFSDK_Annot* pAnnot,
507 FX_DWORD nFlags,
508 const CPDF_Point& point) {
509 ASSERT(pAnnot != NULL);
510 CFX_ByteString sSubType = pAnnot->GetSubType();
511
512 if (sSubType == BFFT_SIGNATURE) {
513 } else {
514 if (m_pFormFiller)
515 return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point);
516 }
517
518 return FALSE;
519}
520
521FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
522 CPDFSDK_Annot* pAnnot,
523 FX_DWORD nFlags,
524 const CPDF_Point& point) {
525 ASSERT(pAnnot != NULL);
526 CFX_ByteString sSubType = pAnnot->GetSubType();
527
528 if (sSubType == BFFT_SIGNATURE) {
529 } else {
530 if (m_pFormFiller)
531 return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
532 }
533
534 return FALSE;
535}
536
537FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
538 CPDFSDK_Annot* pAnnot,
539 FX_DWORD nFlags,
540 const CPDF_Point& point) {
541 ASSERT(pAnnot != NULL);
542 CFX_ByteString sSubType = pAnnot->GetSubType();
543
544 if (sSubType == BFFT_SIGNATURE) {
545 } else {
546 if (m_pFormFiller)
547 return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point);
548 }
549
550 return FALSE;
551}
552
553FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
554 CPDFSDK_Annot* pAnnot,
555 FX_DWORD nFlags,
556 short zDelta,
557 const CPDF_Point& point) {
558 ASSERT(pAnnot != NULL);
559 CFX_ByteString sSubType = pAnnot->GetSubType();
560
561 if (sSubType == BFFT_SIGNATURE) {
562 } else {
563 if (m_pFormFiller)
564 return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,
565 point);
566 }
567
568 return FALSE;
569}
570
571FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
572 CPDFSDK_Annot* pAnnot,
573 FX_DWORD nFlags,
574 const CPDF_Point& point) {
575 ASSERT(pAnnot != NULL);
576 CFX_ByteString sSubType = pAnnot->GetSubType();
577
578 if (sSubType == BFFT_SIGNATURE) {
579 } else {
580 if (m_pFormFiller)
581 return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point);
582 }
583
584 return FALSE;
585}
586FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
587 CPDFSDK_Annot* pAnnot,
588 FX_DWORD nFlags,
589 const CPDF_Point& point) {
590 ASSERT(pAnnot != NULL);
591 CFX_ByteString sSubType = pAnnot->GetSubType();
592
593 if (sSubType == BFFT_SIGNATURE) {
594 } else {
595 if (m_pFormFiller)
596 return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point);
597 }
598
599 return FALSE;
600}
601
602FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
603 FX_DWORD nChar,
604 FX_DWORD nFlags) {
605 ASSERT(pAnnot != NULL);
606 CFX_ByteString sSubType = pAnnot->GetSubType();
607
608 if (sSubType == BFFT_SIGNATURE) {
609 } else {
610 if (m_pFormFiller)
611 return m_pFormFiller->OnChar(pAnnot, nChar, nFlags);
612 }
613
614 return FALSE;
615}
616
617FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
618 int nKeyCode,
619 int nFlag) {
620 ASSERT(pAnnot != NULL);
621 CFX_ByteString sSubType = pAnnot->GetSubType();
622
623 if (sSubType == BFFT_SIGNATURE) {
624 } else {
625 if (m_pFormFiller)
626 return m_pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlag);
627 }
628
629 return FALSE;
630}
631
632FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
633 int nKeyCode,
634 int nFlag) {
635 return FALSE;
636}
637void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) {
638 ASSERT(pAnnot != NULL);
639 CFX_ByteString sSubType = pAnnot->GetSubType();
640
641 if (sSubType == BFFT_SIGNATURE) {
642 } else {
643 if (m_pFormFiller)
644 m_pFormFiller->OnCreate(pAnnot);
645 }
646}
647
648void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {
649 ASSERT(pAnnot != NULL);
650
651 CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
652 ASSERT(pPageView != NULL);
653
654 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
655 ASSERT(pSDKDoc != NULL);
656
657 CPDFXFA_Document* pDoc = pSDKDoc->GetDocument();
658 ASSERT(pDoc != NULL);
659
660 CFX_ByteString sSubType = pAnnot->GetSubType();
661
662 if (sSubType == BFFT_SIGNATURE) {
663 } else {
664 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
665 if (!pWidget->IsAppearanceValid())
666 pWidget->ResetAppearance(NULL, FALSE);
667
668 int nFieldType = pWidget->GetFieldType();
669 if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) {
670 FX_BOOL bFormated = FALSE;
671 CFX_WideString sValue = pWidget->OnFormat(bFormated);
672 if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) {
673 pWidget->ResetAppearance(sValue.c_str(), FALSE);
674 }
675 }
676
677 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
678 if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty())
679 pWidget->ResetAppearance(FALSE);
680 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700681
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700682 if (m_pFormFiller)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700683 m_pFormFiller->OnLoad(pAnnot);
684 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700685}
686
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700687FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot,
688 FX_DWORD nFlag) {
689 ASSERT(pAnnot != NULL);
690 CFX_ByteString sSubType = pAnnot->GetSubType();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700691
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700692 if (sSubType == BFFT_SIGNATURE) {
693 } else {
694 if (m_pFormFiller)
695 return m_pFormFiller->OnSetFocus(pAnnot, nFlag);
696 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700697
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700698 return TRUE;
699}
700FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot,
701 FX_DWORD nFlag) {
702 ASSERT(pAnnot != NULL);
703 CFX_ByteString sSubType = pAnnot->GetSubType();
704
705 if (sSubType == BFFT_SIGNATURE) {
706 } else {
707 if (m_pFormFiller)
708 return m_pFormFiller->OnKillFocus(pAnnot, nFlag);
709 }
710
711 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700712}
713
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700714CPDF_Rect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
715 CPDFSDK_Annot* pAnnot) {
716 ASSERT(pAnnot != NULL);
717 CFX_ByteString sSubType = pAnnot->GetSubType();
Lei Zhang60f507b2015-06-13 00:41:00 -0700718
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700719 if (sSubType == BFFT_SIGNATURE) {
720 } else {
721 if (m_pFormFiller)
722 return m_pFormFiller->GetViewBBox(pPageView, pAnnot);
723 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700724
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700725 return CPDF_Rect(0, 0, 0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700726}
727
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700728FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
729 CPDFSDK_Annot* pAnnot,
730 const CPDF_Point& point) {
731 ASSERT(pPageView);
732 ASSERT(pAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700733
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700734 CPDF_Rect rect = GetViewBBox(pPageView, pAnnot);
735 return rect.Contains(point.x, point.y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700736}
737
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700738#define FWL_WGTHITTEST_Unknown 0
Nico Weber077f1a32015-08-06 15:08:57 -0700739#define FWL_WGTHITTEST_Client 1 // arrow
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700740#define FWL_WGTHITTEST_Titlebar 11 // caption
741#define FWL_WGTHITTEST_HScrollBar 15
742#define FWL_WGTHITTEST_VScrollBar 16
743#define FWL_WGTHITTEST_Border 17
744#define FWL_WGTHITTEST_Edit 19
745#define FWL_WGTHITTEST_HyperLink 20
Lei Zhang60f507b2015-06-13 00:41:00 -0700746
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747CPDFSDK_XFAAnnotHandler::CPDFSDK_XFAAnnotHandler(CPDFDoc_Environment* pApp)
748 : m_pApp(pApp) {}
749
750CPDFSDK_Annot* CPDFSDK_XFAAnnotHandler::NewAnnot(IXFA_Widget* pAnnot,
751 CPDFSDK_PageView* pPage) {
752 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument();
753 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm();
754 CPDFSDK_XFAWidget* pWidget = new CPDFSDK_XFAWidget(pAnnot, pPage, pInterForm);
755 pInterForm->AddXFAMap(pAnnot, pWidget);
756 return pWidget;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700757}
758
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700759FX_BOOL CPDFSDK_XFAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
760 return pAnnot->GetXFAWidget() != NULL;
761}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700762
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700763void CPDFSDK_XFAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
764 CPDFSDK_Annot* pAnnot,
765 CFX_RenderDevice* pDevice,
766 CPDF_Matrix* pUser2Device,
767 FX_DWORD dwFlags) {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700768#ifdef PDF_ENABLE_XFA
769
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700770 ASSERT(pPageView != NULL);
771 ASSERT(pAnnot != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700772
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700773 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
774 ASSERT(pSDKDoc != NULL);
775
776 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
777 ASSERT(pWidgetHandler != NULL);
778
779 CFX_Graphics gs;
780 gs.Create(pDevice);
781
782 CFX_Matrix mt;
783 mt = *(CFX_Matrix*)pUser2Device;
784
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700785 FX_BOOL bIsHighlight = FALSE;
786 if (pSDKDoc->GetFocusAnnot() != pAnnot)
787 bIsHighlight = TRUE;
788
789 pWidgetHandler->RenderWidget(pAnnot->GetXFAWidget(), &gs, &mt, bIsHighlight);
790
791 // to do highlight and shadow
Tom Sepeza8a39e22015-10-12 15:47:07 -0700792#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700793}
794
795void CPDFSDK_XFAAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
796 ASSERT(pAnnot != NULL);
797
798 CPDFSDK_XFAWidget* pWidget = (CPDFSDK_XFAWidget*)pAnnot;
799 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
800 ASSERT(pInterForm != NULL);
801
802 pInterForm->RemoveXFAMap(pWidget->GetXFAWidget());
803
804 delete pWidget;
805}
806
807CPDF_Rect CPDFSDK_XFAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
808 CPDFSDK_Annot* pAnnot) {
809 ASSERT(pAnnot != NULL);
810
811 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
812 ASSERT(pWidgetHandler != NULL);
813
Tom Sepeza8a39e22015-10-12 15:47:07 -0700814 CFX_RectF rcBBox;
815#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700816 XFA_ELEMENT eType =
817 pWidgetHandler->GetDataAcc(pAnnot->GetXFAWidget())->GetUIType();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700818 if (eType == XFA_ELEMENT_Signature)
819 pWidgetHandler->GetBBox(pAnnot->GetXFAWidget(), rcBBox,
820 XFA_WIDGETSTATUS_Visible, TRUE);
821 else
Tom Sepeza8a39e22015-10-12 15:47:07 -0700822#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700823 pWidgetHandler->GetBBox(pAnnot->GetXFAWidget(), rcBBox, 0);
824
825 CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
826 rcBBox.top + rcBBox.height);
827 rcWidget.left -= 1.0f;
828 rcWidget.right += 1.0f;
829 rcWidget.bottom -= 1.0f;
830 rcWidget.top += 1.0f;
831
832 return rcWidget;
833}
834
835FX_BOOL CPDFSDK_XFAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
836 CPDFSDK_Annot* pAnnot,
837 const CPDF_Point& point) {
838 if (!pPageView || !pAnnot)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700839 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700840
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700841 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
842 if (!pSDKDoc)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700843 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700844
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700845 CPDFXFA_Document* pDoc = pSDKDoc->GetDocument();
846 if (!pDoc)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700847 return FALSE;
Lei Zhang60f507b2015-06-13 00:41:00 -0700848
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700849 IXFA_DocView* pDocView = pDoc->GetXFADocView();
850 if (!pDocView)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700851 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700852
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700853 IXFA_WidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
854 if (!pWidgetHandler)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700855 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700856
857 FX_DWORD dwHitTest =
858 pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point.x, point.y);
859 return (dwHitTest != FWL_WGTHITTEST_Unknown);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700860}
861
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700862void CPDFSDK_XFAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
863 CPDFSDK_Annot* pAnnot,
864 FX_DWORD nFlag) {
865 if (!pPageView || !pAnnot)
866 return;
867 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
868 ASSERT(pWidgetHandler != NULL);
Lei Zhang60f507b2015-06-13 00:41:00 -0700869
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700870 pWidgetHandler->OnMouseEnter(pAnnot->GetXFAWidget());
871}
Lei Zhang60f507b2015-06-13 00:41:00 -0700872
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700873void CPDFSDK_XFAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
874 CPDFSDK_Annot* pAnnot,
875 FX_DWORD nFlag) {
876 if (!pPageView || !pAnnot)
877 return;
878
879 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
880 ASSERT(pWidgetHandler != NULL);
881
882 pWidgetHandler->OnMouseExit(pAnnot->GetXFAWidget());
883}
884
885FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
886 CPDFSDK_Annot* pAnnot,
887 FX_DWORD nFlags,
888 const CPDF_Point& point) {
889 if (!pPageView || !pAnnot)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700890 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700891
892 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
893 ASSERT(pWidgetHandler != NULL);
894
895 FX_BOOL bRet = FALSE;
896 bRet = pWidgetHandler->OnLButtonDown(pAnnot->GetXFAWidget(),
897 GetFWLFlags(nFlags), point.x, point.y);
898
899 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700900}
901
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700902FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
903 CPDFSDK_Annot* pAnnot,
904 FX_DWORD nFlags,
905 const CPDF_Point& point) {
906 if (!pPageView || !pAnnot)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700907 return FALSE;
Lei Zhang60f507b2015-06-13 00:41:00 -0700908
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700909 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
910 ASSERT(pWidgetHandler != NULL);
911
912 FX_BOOL bRet = FALSE;
913 bRet = pWidgetHandler->OnLButtonUp(pAnnot->GetXFAWidget(),
914 GetFWLFlags(nFlags), point.x, point.y);
915
916 return bRet;
917}
918
919FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
920 CPDFSDK_Annot* pAnnot,
921 FX_DWORD nFlags,
922 const CPDF_Point& point) {
923 if (!pPageView || !pAnnot)
924 return FALSE;
925
926 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
927 ASSERT(pWidgetHandler != NULL);
928
929 FX_BOOL bRet = FALSE;
930 bRet = pWidgetHandler->OnLButtonDblClk(pAnnot->GetXFAWidget(),
931 GetFWLFlags(nFlags), point.x, point.y);
932
933 return bRet;
934}
935
936FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
937 CPDFSDK_Annot* pAnnot,
938 FX_DWORD nFlags,
939 const CPDF_Point& point) {
940 if (!pPageView || !pAnnot)
941 return FALSE;
942
943 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
944 ASSERT(pWidgetHandler != NULL);
945
946 FX_BOOL bRet = FALSE;
947 bRet = pWidgetHandler->OnMouseMove(pAnnot->GetXFAWidget(),
948 GetFWLFlags(nFlags), point.x, point.y);
949
950 return bRet;
951}
952
953FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
954 CPDFSDK_Annot* pAnnot,
955 FX_DWORD nFlags,
956 short zDelta,
957 const CPDF_Point& point) {
958 if (!pPageView || !pAnnot)
959 return FALSE;
960
961 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
962 ASSERT(pWidgetHandler != NULL);
963
964 FX_BOOL bRet = FALSE;
965 bRet = pWidgetHandler->OnMouseWheel(
966 pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), zDelta, point.x, point.y);
967
968 return bRet;
969}
970
971FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
972 CPDFSDK_Annot* pAnnot,
973 FX_DWORD nFlags,
974 const CPDF_Point& point) {
975 if (!pPageView || !pAnnot)
976 return FALSE;
977
978 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
979 ASSERT(pWidgetHandler != NULL);
980
981 FX_BOOL bRet = FALSE;
982 bRet = pWidgetHandler->OnRButtonDown(pAnnot->GetXFAWidget(),
983 GetFWLFlags(nFlags), point.x, point.y);
984
985 return bRet;
986}
987
988FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
989 CPDFSDK_Annot* pAnnot,
990 FX_DWORD nFlags,
991 const CPDF_Point& point) {
992 if (!pPageView || !pAnnot)
993 return FALSE;
994
995 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
996 ASSERT(pWidgetHandler != NULL);
997
998 FX_BOOL bRet = FALSE;
999 bRet = pWidgetHandler->OnRButtonUp(pAnnot->GetXFAWidget(),
1000 GetFWLFlags(nFlags), point.x, point.y);
1001
1002 return bRet;
1003}
1004
1005FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView,
1006 CPDFSDK_Annot* pAnnot,
1007 FX_DWORD nFlags,
1008 const CPDF_Point& point) {
1009 if (!pPageView || !pAnnot)
1010 return FALSE;
1011
1012 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
1013 ASSERT(pWidgetHandler != NULL);
1014
1015 FX_BOOL bRet = FALSE;
1016 bRet = pWidgetHandler->OnRButtonDblClk(pAnnot->GetXFAWidget(),
1017 GetFWLFlags(nFlags), point.x, point.y);
1018
1019 return bRet;
1020}
1021
1022FX_BOOL CPDFSDK_XFAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
1023 FX_DWORD nChar,
1024 FX_DWORD nFlags) {
1025 if (!pAnnot)
1026 return FALSE;
1027
1028 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
1029 ASSERT(pWidgetHandler != NULL);
1030
1031 FX_BOOL bRet = FALSE;
1032 bRet = pWidgetHandler->OnChar(pAnnot->GetXFAWidget(), nChar,
1033 GetFWLFlags(nFlags));
1034
1035 return bRet;
1036}
1037
1038FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
1039 int nKeyCode,
1040 int nFlag) {
1041 if (!pAnnot)
1042 return FALSE;
1043
1044 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
1045 ASSERT(pWidgetHandler != NULL);
1046
1047 FX_BOOL bRet = FALSE;
1048 bRet = pWidgetHandler->OnKeyDown(pAnnot->GetXFAWidget(), nKeyCode,
1049 GetFWLFlags(nFlag));
1050
1051 return bRet;
1052}
1053
1054FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
1055 int nKeyCode,
1056 int nFlag) {
1057 if (!pAnnot)
1058 return FALSE;
1059
1060 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
1061 ASSERT(pWidgetHandler != NULL);
1062
1063 FX_BOOL bRet = FALSE;
1064 bRet = pWidgetHandler->OnKeyUp(pAnnot->GetXFAWidget(), nKeyCode,
1065 GetFWLFlags(nFlag));
1066
1067 return bRet;
1068}
1069
1070FX_BOOL CPDFSDK_XFAAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot,
1071 FX_DWORD nFlag) {
1072 return TRUE;
1073}
1074
1075FX_BOOL CPDFSDK_XFAAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot,
1076 FX_DWORD nFlag) {
1077 return TRUE;
1078}
1079
1080FX_BOOL CPDFSDK_XFAAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot,
1081 CPDFSDK_Annot* pNewAnnot) {
1082 IXFA_WidgetHandler* pWidgetHandler = NULL;
1083
1084 if (pOldAnnot)
1085 pWidgetHandler = GetXFAWidgetHandler(pOldAnnot);
1086 else if (pNewAnnot)
1087 pWidgetHandler = GetXFAWidgetHandler(pNewAnnot);
1088
1089 if (pWidgetHandler) {
1090 FX_BOOL bRet = TRUE;
1091 IXFA_Widget* hWidget = pNewAnnot ? pNewAnnot->GetXFAWidget() : NULL;
1092 if (hWidget) {
1093 IXFA_PageView* pXFAPageView = pWidgetHandler->GetPageView(hWidget);
1094 if (pXFAPageView) {
1095 bRet = pXFAPageView->GetDocView()->SetFocus(hWidget);
1096 if (pXFAPageView->GetDocView()->GetFocusWidget() == hWidget)
1097 bRet = TRUE;
1098 }
Tom Sepezdcbc02f2015-07-17 09:16:17 -07001099 }
Tom Sepezdcbc02f2015-07-17 09:16:17 -07001100 return bRet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001101 }
1102
1103 return TRUE;
Bo Xufdc00a72014-10-28 23:03:33 -07001104}
1105
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001106IXFA_WidgetHandler* CPDFSDK_XFAAnnotHandler::GetXFAWidgetHandler(
1107 CPDFSDK_Annot* pAnnot) {
1108 if (!pAnnot)
1109 return NULL;
Bo Xufdc00a72014-10-28 23:03:33 -07001110
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001111 CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
1112 if (!pPageView)
1113 return NULL;
Bo Xufdc00a72014-10-28 23:03:33 -07001114
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001115 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
1116 if (!pSDKDoc)
1117 return NULL;
Bo Xufdc00a72014-10-28 23:03:33 -07001118
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001119 CPDFXFA_Document* pDoc = pSDKDoc->GetDocument();
1120 if (!pDoc)
1121 return NULL;
1122
1123 IXFA_DocView* pDocView = pDoc->GetXFADocView();
1124 if (!pDocView)
1125 return NULL;
1126
1127 return pDocView->GetWidgetHandler();
Bo Xufdc00a72014-10-28 23:03:33 -07001128}
1129
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001130#define FWL_KEYFLAG_Ctrl (1 << 0)
1131#define FWL_KEYFLAG_Alt (1 << 1)
1132#define FWL_KEYFLAG_Shift (1 << 2)
1133#define FWL_KEYFLAG_LButton (1 << 3)
1134#define FWL_KEYFLAG_RButton (1 << 4)
1135#define FWL_KEYFLAG_MButton (1 << 5)
Bo Xufdc00a72014-10-28 23:03:33 -07001136
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001137FX_DWORD CPDFSDK_XFAAnnotHandler::GetFWLFlags(FX_DWORD dwFlag) {
1138 FX_DWORD dwFWLFlag = 0;
Bo Xufdc00a72014-10-28 23:03:33 -07001139
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001140 if (dwFlag & FWL_EVENTFLAG_ControlKey)
1141 dwFWLFlag |= FWL_KEYFLAG_Ctrl;
1142 if (dwFlag & FWL_EVENTFLAG_LeftButtonDown)
1143 dwFWLFlag |= FWL_KEYFLAG_LButton;
1144 if (dwFlag & FWL_EVENTFLAG_MiddleButtonDown)
1145 dwFWLFlag |= FWL_KEYFLAG_MButton;
1146 if (dwFlag & FWL_EVENTFLAG_RightButtonDown)
1147 dwFWLFlag |= FWL_KEYFLAG_RButton;
1148 if (dwFlag & FWL_EVENTFLAG_ShiftKey)
1149 dwFWLFlag |= FWL_KEYFLAG_Shift;
1150 if (dwFlag & FWL_EVENTFLAG_AltKey)
1151 dwFWLFlag |= FWL_KEYFLAG_Alt;
Bo Xufdc00a72014-10-28 23:03:33 -07001152
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001153 return dwFWLFlag;
Bo Xufdc00a72014-10-28 23:03:33 -07001154}
1155
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001156CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView,
Lei Zhangbf60b292015-10-26 12:14:35 -07001157 bool bReverse)
1158 : m_bReverse(bReverse), m_pos(0) {
1159 const std::vector<CPDFSDK_Annot*>& annots = pPageView->GetAnnotList();
1160 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), annots.rbegin(),
1161 annots.rend());
1162 std::stable_sort(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(),
1163 [](CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) {
1164 return p1->GetLayoutOrder() < p2->GetLayoutOrder();
1165 });
Bo Xufdc00a72014-10-28 23:03:33 -07001166
Lei Zhangbf60b292015-10-26 12:14:35 -07001167 CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot();
1168 if (!pTopMostAnnot)
1169 return;
Lei Zhang60f507b2015-06-13 00:41:00 -07001170
Lei Zhangbf60b292015-10-26 12:14:35 -07001171 auto it = std::find(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(),
1172 pTopMostAnnot);
1173 if (it != m_iteratorAnnotList.end()) {
1174 CPDFSDK_Annot* pReaderAnnot = *it;
1175 m_iteratorAnnotList.erase(it);
1176 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), pReaderAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001177 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001178}
1179
Lei Zhangbf60b292015-10-26 12:14:35 -07001180CPDFSDK_AnnotIterator::~CPDFSDK_AnnotIterator() {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001181}
1182
Lei Zhangbf60b292015-10-26 12:14:35 -07001183CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot() {
1184 if (m_pos < m_iteratorAnnotList.size())
1185 return m_iteratorAnnotList[m_pos++];
1186 return nullptr;
1187}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001188
Lei Zhangbf60b292015-10-26 12:14:35 -07001189CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot() {
1190 if (m_pos < m_iteratorAnnotList.size())
1191 return m_iteratorAnnotList[m_iteratorAnnotList.size() - ++m_pos];
1192 return nullptr;
1193}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001194
Lei Zhangbf60b292015-10-26 12:14:35 -07001195CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next() {
1196 return m_bReverse ? PrevAnnot() : NextAnnot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001197}