OLD | NEW |
| (Empty) |
1 // 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. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #include "fpdfsdk/include/fsdk_annothandler.h" | |
8 | |
9 #include <algorithm> | |
10 #include <vector> | |
11 | |
12 #include "core/include/fpdfapi/cpdf_document.h" | |
13 #include "fpdfsdk/include/formfiller/FFL_FormFiller.h" | |
14 #include "fpdfsdk/include/fsdk_define.h" | |
15 #include "fpdfsdk/include/fsdk_mgr.h" | |
16 | |
17 #ifdef PDF_ENABLE_XFA | |
18 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" | |
19 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h" | |
20 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_util.h" | |
21 #include "xfa/include/fxgraphics/fx_graphics.h" | |
22 #endif // PDF_ENABLE_XFA | |
23 | |
24 CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) { | |
25 m_pApp = pApp; | |
26 | |
27 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp); | |
28 pHandler->SetFormFiller(m_pApp->GetIFormFiller()); | |
29 RegisterAnnotHandler(pHandler); | |
30 #ifdef PDF_ENABLE_XFA | |
31 CPDFSDK_XFAAnnotHandler* pXFAAnnotHandler = | |
32 new CPDFSDK_XFAAnnotHandler(m_pApp); | |
33 RegisterAnnotHandler(pXFAAnnotHandler); | |
34 #endif // PDF_ENABLE_XFA | |
35 } | |
36 | |
37 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() { | |
38 for (int i = 0; i < m_Handlers.GetSize(); i++) { | |
39 IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i); | |
40 delete pHandler; | |
41 } | |
42 m_Handlers.RemoveAll(); | |
43 m_mapType2Handler.clear(); | |
44 } | |
45 | |
46 void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler( | |
47 IPDFSDK_AnnotHandler* pAnnotHandler) { | |
48 ASSERT(!GetAnnotHandler(pAnnotHandler->GetType())); | |
49 | |
50 m_Handlers.Add(pAnnotHandler); | |
51 m_mapType2Handler[pAnnotHandler->GetType()] = pAnnotHandler; | |
52 } | |
53 | |
54 void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler( | |
55 IPDFSDK_AnnotHandler* pAnnotHandler) { | |
56 m_mapType2Handler.erase(pAnnotHandler->GetType()); | |
57 for (int i = 0, sz = m_Handlers.GetSize(); i < sz; i++) { | |
58 if (m_Handlers.GetAt(i) == pAnnotHandler) { | |
59 m_Handlers.RemoveAt(i); | |
60 break; | |
61 } | |
62 } | |
63 } | |
64 | |
65 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot, | |
66 CPDFSDK_PageView* pPageView) { | |
67 ASSERT(pPageView); | |
68 | |
69 if (IPDFSDK_AnnotHandler* pAnnotHandler = | |
70 GetAnnotHandler(pAnnot->GetSubType())) { | |
71 return pAnnotHandler->NewAnnot(pAnnot, pPageView); | |
72 } | |
73 | |
74 return new CPDFSDK_BAAnnot(pAnnot, pPageView); | |
75 } | |
76 | |
77 #ifdef PDF_ENABLE_XFA | |
78 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(IXFA_Widget* pAnnot, | |
79 CPDFSDK_PageView* pPageView) { | |
80 ASSERT(pAnnot); | |
81 ASSERT(pPageView); | |
82 | |
83 if (IPDFSDK_AnnotHandler* pAnnotHandler = | |
84 GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME)) { | |
85 return pAnnotHandler->NewAnnot(pAnnot, pPageView); | |
86 } | |
87 | |
88 return NULL; | |
89 } | |
90 #endif // PDF_ENABLE_XFA | |
91 | |
92 void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { | |
93 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { | |
94 pAnnotHandler->OnRelease(pAnnot); | |
95 pAnnotHandler->ReleaseAnnot(pAnnot); | |
96 } else { | |
97 delete (CPDFSDK_Annot*)pAnnot; | |
98 } | |
99 } | |
100 | |
101 void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot) { | |
102 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); | |
103 | |
104 CPDFSDK_DateTime curTime; | |
105 pPDFAnnot->GetAnnotDict()->SetAtString("M", curTime.ToPDFDateTimeString()); | |
106 pPDFAnnot->GetAnnotDict()->SetAtNumber("F", 0); | |
107 | |
108 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { | |
109 pAnnotHandler->OnCreate(pAnnot); | |
110 } | |
111 } | |
112 | |
113 void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) { | |
114 ASSERT(pAnnot); | |
115 | |
116 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { | |
117 pAnnotHandler->OnLoad(pAnnot); | |
118 } | |
119 } | |
120 | |
121 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( | |
122 CPDFSDK_Annot* pAnnot) const { | |
123 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); | |
124 if (pPDFAnnot) | |
125 return GetAnnotHandler(pPDFAnnot->GetSubType()); | |
126 #ifdef PDF_ENABLE_XFA | |
127 if (pAnnot->GetXFAWidget()) | |
128 return GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME); | |
129 #endif // PDF_ENABLE_XFA | |
130 return nullptr; | |
131 } | |
132 | |
133 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( | |
134 const CFX_ByteString& sType) const { | |
135 auto it = m_mapType2Handler.find(sType); | |
136 return it != m_mapType2Handler.end() ? it->second : nullptr; | |
137 } | |
138 | |
139 void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, | |
140 CPDFSDK_Annot* pAnnot, | |
141 CFX_RenderDevice* pDevice, | |
142 CFX_Matrix* pUser2Device, | |
143 FX_DWORD dwFlags) { | |
144 ASSERT(pAnnot); | |
145 | |
146 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { | |
147 pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); | |
148 } else { | |
149 #ifdef PDF_ENABLE_XFA | |
150 if (pAnnot->IsXFAField()) | |
151 return; | |
152 #endif // PDF_ENABLE_XFA | |
153 static_cast<CPDFSDK_BAAnnot*>(pAnnot) | |
154 ->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); | |
155 } | |
156 } | |
157 | |
158 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown( | |
159 CPDFSDK_PageView* pPageView, | |
160 CPDFSDK_Annot* pAnnot, | |
161 FX_DWORD nFlags, | |
162 const CFX_FloatPoint& point) { | |
163 ASSERT(pAnnot); | |
164 | |
165 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { | |
166 return pAnnotHandler->OnLButtonDown(pPageView, pAnnot, nFlags, point); | |
167 } | |
168 return FALSE; | |
169 } | |
170 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp( | |
171 CPDFSDK_PageView* pPageView, | |
172 CPDFSDK_Annot* pAnnot, | |
173 FX_DWORD nFlags, | |
174 const CFX_FloatPoint& point) { | |
175 ASSERT(pAnnot); | |
176 | |
177 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { | |
178 return pAnnotHandler->OnLButtonUp(pPageView, pAnnot, nFlags, point); | |
179 } | |
180 return FALSE; | |
181 } | |
182 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk( | |
183 CPDFSDK_PageView* pPageView, | |
184 CPDFSDK_Annot* pAnnot, | |
185 FX_DWORD nFlags, | |
186 const CFX_FloatPoint& point) { | |
187 ASSERT(pAnnot); | |
188 | |
189 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { | |
190 return pAnnotHandler->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); | |
191 } | |
192 return FALSE; | |
193 } | |
194 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove( | |
195 CPDFSDK_PageView* pPageView, | |
196 CPDFSDK_Annot* pAnnot, | |
197 FX_DWORD nFlags, | |
198 const CFX_FloatPoint& point) { | |
199 ASSERT(pAnnot); | |
200 | |
201 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { | |
202 return pAnnotHandler->OnMouseMove(pPageView, pAnnot, nFlags, point); | |
203 } | |
204 return FALSE; | |
205 } | |
206 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel( | |
207 CPDFSDK_PageView* pPageView, | |
208 CPDFSDK_Annot* pAnnot, | |
209 FX_DWORD nFlags, | |
210 short zDelta, | |
211 const CFX_FloatPoint& point) { | |
212 ASSERT(pAnnot); | |
213 | |
214 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { | |
215 return pAnnotHandler->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, | |
216 point); | |
217 } | |
218 return FALSE; | |
219 } | |
220 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown( | |
221 CPDFSDK_PageView* pPageView, | |
222 CPDFSDK_Annot* pAnnot, | |
223 FX_DWORD nFlags, | |
224 const CFX_FloatPoint& point) { | |
225 ASSERT(pAnnot); | |
226 | |
227 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { | |
228 return pAnnotHandler->OnRButtonDown(pPageView, pAnnot, nFlags, point); | |
229 } | |
230 return FALSE; | |
231 } | |
232 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp( | |
233 CPDFSDK_PageView* pPageView, | |
234 CPDFSDK_Annot* pAnnot, | |
235 FX_DWORD nFlags, | |
236 const CFX_FloatPoint& point) { | |
237 ASSERT(pAnnot); | |
238 | |
239 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { | |
240 return pAnnotHandler->OnRButtonUp(pPageView, pAnnot, nFlags, point); | |
241 } | |
242 return FALSE; | |
243 } | |
244 | |
245 void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(CPDFSDK_PageView* pPageView, | |
246 CPDFSDK_Annot* pAnnot, | |
247 FX_DWORD nFlag) { | |
248 ASSERT(pAnnot); | |
249 | |
250 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) | |
251 pAnnotHandler->OnMouseEnter(pPageView, pAnnot, nFlag); | |
252 } | |
253 | |
254 void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(CPDFSDK_PageView* pPageView, | |
255 CPDFSDK_Annot* pAnnot, | |
256 FX_DWORD nFlag) { | |
257 ASSERT(pAnnot); | |
258 | |
259 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) | |
260 pAnnotHandler->OnMouseExit(pPageView, pAnnot, nFlag); | |
261 } | |
262 | |
263 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot, | |
264 FX_DWORD nChar, | |
265 FX_DWORD nFlags) { | |
266 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { | |
267 return pAnnotHandler->OnChar(pAnnot, nChar, nFlags); | |
268 } | |
269 return FALSE; | |
270 } | |
271 | |
272 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot, | |
273 int nKeyCode, | |
274 int nFlag) { | |
275 if (!m_pApp->FFI_IsCTRLKeyDown(nFlag) && !m_pApp->FFI_IsALTKeyDown(nFlag)) { | |
276 CPDFSDK_PageView* pPage = pAnnot->GetPageView(); | |
277 CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot(); | |
278 if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) { | |
279 CPDFSDK_Annot* pNext = | |
280 GetNextAnnot(pFocusAnnot, !m_pApp->FFI_IsSHIFTKeyDown(nFlag)); | |
281 | |
282 if (pNext && pNext != pFocusAnnot) { | |
283 CPDFSDK_Document* pDocument = pPage->GetSDKDocument(); | |
284 pDocument->SetFocusAnnot(pNext); | |
285 return TRUE; | |
286 } | |
287 } | |
288 } | |
289 | |
290 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { | |
291 return pAnnotHandler->OnKeyDown(pAnnot, nKeyCode, nFlag); | |
292 } | |
293 return FALSE; | |
294 } | |
295 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot, | |
296 int nKeyCode, | |
297 int nFlag) { | |
298 return FALSE; | |
299 } | |
300 | |
301 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(CPDFSDK_Annot* pAnnot, | |
302 FX_DWORD nFlag) { | |
303 ASSERT(pAnnot); | |
304 | |
305 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { | |
306 if (pAnnotHandler->OnSetFocus(pAnnot, nFlag)) { | |
307 CPDFSDK_PageView* pPage = pAnnot->GetPageView(); | |
308 pPage->GetSDKDocument(); | |
309 return TRUE; | |
310 } | |
311 } | |
312 return FALSE; | |
313 } | |
314 | |
315 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot, | |
316 FX_DWORD nFlag) { | |
317 ASSERT(pAnnot); | |
318 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) | |
319 return pAnnotHandler->OnKillFocus(pAnnot, nFlag); | |
320 | |
321 return FALSE; | |
322 } | |
323 | |
324 #ifdef PDF_ENABLE_XFA | |
325 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus( | |
326 CPDFSDK_Annot* pSetAnnot, | |
327 CPDFSDK_Annot* pKillAnnot) { | |
328 FX_BOOL bXFA = (pSetAnnot && pSetAnnot->GetXFAWidget()) || | |
329 (pKillAnnot && pKillAnnot->GetXFAWidget()); | |
330 | |
331 if (bXFA) { | |
332 if (IPDFSDK_AnnotHandler* pXFAAnnotHandler = | |
333 GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME)) | |
334 return pXFAAnnotHandler->OnXFAChangedFocus(pKillAnnot, pSetAnnot); | |
335 } | |
336 | |
337 return TRUE; | |
338 } | |
339 #endif // PDF_ENABLE_XFA | |
340 | |
341 CFX_FloatRect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox( | |
342 CPDFSDK_PageView* pPageView, | |
343 CPDFSDK_Annot* pAnnot) { | |
344 ASSERT(pAnnot); | |
345 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) | |
346 return pAnnotHandler->GetViewBBox(pPageView, pAnnot); | |
347 | |
348 return pAnnot->GetRect(); | |
349 } | |
350 | |
351 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView, | |
352 CPDFSDK_Annot* pAnnot, | |
353 const CFX_FloatPoint& point) { | |
354 ASSERT(pAnnot); | |
355 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { | |
356 if (pAnnotHandler->CanAnswer(pAnnot)) | |
357 return pAnnotHandler->HitTest(pPageView, pAnnot, point); | |
358 } | |
359 return FALSE; | |
360 } | |
361 | |
362 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot, | |
363 FX_BOOL bNext) { | |
364 #ifdef PDF_ENABLE_XFA | |
365 CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView(); | |
366 CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage(); | |
367 if (pPage == NULL) | |
368 return NULL; | |
369 if (pPage->GetPDFPage()) { // for pdf annots. | |
370 CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), pSDKAnnot->GetType(), ""); | |
371 CPDFSDK_Annot* pNext = | |
372 bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot); | |
373 return pNext; | |
374 } | |
375 // for xfa annots | |
376 IXFA_WidgetIterator* pWidgetIterator = | |
377 pPage->GetXFAPageView()->CreateWidgetIterator( | |
378 XFA_TRAVERSEWAY_Tranvalse, XFA_WIDGETFILTER_Visible | | |
379 XFA_WIDGETFILTER_Viewable | | |
380 XFA_WIDGETFILTER_Field); | |
381 if (pWidgetIterator == NULL) | |
382 return NULL; | |
383 if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget()) | |
384 pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget()); | |
385 IXFA_Widget* hNextFocus = NULL; | |
386 hNextFocus = | |
387 bNext ? pWidgetIterator->MoveToNext() : pWidgetIterator->MoveToPrevious(); | |
388 if (!hNextFocus && pSDKAnnot) | |
389 hNextFocus = pWidgetIterator->MoveToFirst(); | |
390 | |
391 pWidgetIterator->Release(); | |
392 return pPageView->GetAnnotByXFAWidget(hNextFocus); | |
393 #else // PDF_ENABLE_XFA | |
394 CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), "Widget", ""); | |
395 return bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot); | |
396 #endif // PDF_ENABLE_XFA | |
397 } | |
398 | |
399 FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { | |
400 ASSERT(pAnnot->GetType() == "Widget"); | |
401 if (pAnnot->GetSubType() == BFFT_SIGNATURE) | |
402 return FALSE; | |
403 | |
404 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; | |
405 if (!pWidget->IsVisible()) | |
406 return FALSE; | |
407 | |
408 int nFieldFlags = pWidget->GetFieldFlags(); | |
409 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) | |
410 return FALSE; | |
411 | |
412 if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON) | |
413 return TRUE; | |
414 | |
415 CPDF_Page* pPage = pWidget->GetPDFPage(); | |
416 CPDF_Document* pDocument = pPage->m_pDocument; | |
417 FX_DWORD dwPermissions = pDocument->GetUserPermissions(); | |
418 return (dwPermissions & FPDFPERM_FILL_FORM) || | |
419 (dwPermissions & FPDFPERM_ANNOT_FORM); | |
420 } | |
421 | |
422 CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot, | |
423 CPDFSDK_PageView* pPage) { | |
424 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument(); | |
425 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm(); | |
426 CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl( | |
427 pInterForm->GetInterForm(), pAnnot->GetAnnotDict()); | |
428 if (!pCtrl) | |
429 return nullptr; | |
430 | |
431 CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm); | |
432 pInterForm->AddMap(pCtrl, pWidget); | |
433 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); | |
434 if (pPDFInterForm && pPDFInterForm->NeedConstructAP()) | |
435 pWidget->ResetAppearance(nullptr, FALSE); | |
436 | |
437 return pWidget; | |
438 } | |
439 | |
440 #ifdef PDF_ENABLE_XFA | |
441 CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(IXFA_Widget* hWidget, | |
442 CPDFSDK_PageView* pPage) { | |
443 return NULL; | |
444 } | |
445 #endif // PDF_ENABLE_XFA | |
446 | |
447 void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { | |
448 ASSERT(pAnnot); | |
449 | |
450 if (m_pFormFiller) | |
451 m_pFormFiller->OnDelete(pAnnot); | |
452 | |
453 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; | |
454 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); | |
455 CPDF_FormControl* pCtrol = pWidget->GetFormControl(); | |
456 pInterForm->RemoveMap(pCtrol); | |
457 | |
458 delete pWidget; | |
459 } | |
460 | |
461 void CPDFSDK_BFAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView, | |
462 CPDFSDK_Annot* pAnnot, | |
463 CFX_RenderDevice* pDevice, | |
464 CFX_Matrix* pUser2Device, | |
465 FX_DWORD dwFlags) { | |
466 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
467 | |
468 if (sSubType == BFFT_SIGNATURE) { | |
469 static_cast<CPDFSDK_BAAnnot*>(pAnnot) | |
470 ->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); | |
471 } else { | |
472 if (m_pFormFiller) { | |
473 m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); | |
474 } | |
475 } | |
476 } | |
477 | |
478 void CPDFSDK_BFAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView, | |
479 CPDFSDK_Annot* pAnnot, | |
480 FX_DWORD nFlag) { | |
481 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
482 | |
483 if (sSubType == BFFT_SIGNATURE) { | |
484 } else { | |
485 if (m_pFormFiller) | |
486 m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag); | |
487 } | |
488 } | |
489 void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView, | |
490 CPDFSDK_Annot* pAnnot, | |
491 FX_DWORD nFlag) { | |
492 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
493 | |
494 if (sSubType == BFFT_SIGNATURE) { | |
495 } else { | |
496 if (m_pFormFiller) | |
497 m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag); | |
498 } | |
499 } | |
500 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView, | |
501 CPDFSDK_Annot* pAnnot, | |
502 FX_DWORD nFlags, | |
503 const CFX_FloatPoint& point) { | |
504 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
505 | |
506 if (sSubType == BFFT_SIGNATURE) { | |
507 } else { | |
508 if (m_pFormFiller) | |
509 return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point); | |
510 } | |
511 | |
512 return FALSE; | |
513 } | |
514 | |
515 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView, | |
516 CPDFSDK_Annot* pAnnot, | |
517 FX_DWORD nFlags, | |
518 const CFX_FloatPoint& point) { | |
519 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
520 | |
521 if (sSubType == BFFT_SIGNATURE) { | |
522 } else { | |
523 if (m_pFormFiller) | |
524 return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point); | |
525 } | |
526 | |
527 return FALSE; | |
528 } | |
529 | |
530 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView, | |
531 CPDFSDK_Annot* pAnnot, | |
532 FX_DWORD nFlags, | |
533 const CFX_FloatPoint& point) { | |
534 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
535 | |
536 if (sSubType == BFFT_SIGNATURE) { | |
537 } else { | |
538 if (m_pFormFiller) | |
539 return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); | |
540 } | |
541 | |
542 return FALSE; | |
543 } | |
544 | |
545 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView, | |
546 CPDFSDK_Annot* pAnnot, | |
547 FX_DWORD nFlags, | |
548 const CFX_FloatPoint& point) { | |
549 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
550 | |
551 if (sSubType == BFFT_SIGNATURE) { | |
552 } else { | |
553 if (m_pFormFiller) | |
554 return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point); | |
555 } | |
556 | |
557 return FALSE; | |
558 } | |
559 | |
560 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView, | |
561 CPDFSDK_Annot* pAnnot, | |
562 FX_DWORD nFlags, | |
563 short zDelta, | |
564 const CFX_FloatPoint& point) { | |
565 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
566 | |
567 if (sSubType == BFFT_SIGNATURE) { | |
568 } else { | |
569 if (m_pFormFiller) | |
570 return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, | |
571 point); | |
572 } | |
573 | |
574 return FALSE; | |
575 } | |
576 | |
577 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView, | |
578 CPDFSDK_Annot* pAnnot, | |
579 FX_DWORD nFlags, | |
580 const CFX_FloatPoint& point) { | |
581 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
582 | |
583 if (sSubType == BFFT_SIGNATURE) { | |
584 } else { | |
585 if (m_pFormFiller) | |
586 return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point); | |
587 } | |
588 | |
589 return FALSE; | |
590 } | |
591 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView, | |
592 CPDFSDK_Annot* pAnnot, | |
593 FX_DWORD nFlags, | |
594 const CFX_FloatPoint& point) { | |
595 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
596 | |
597 if (sSubType == BFFT_SIGNATURE) { | |
598 } else { | |
599 if (m_pFormFiller) | |
600 return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point); | |
601 } | |
602 | |
603 return FALSE; | |
604 } | |
605 | |
606 FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot, | |
607 FX_DWORD nChar, | |
608 FX_DWORD nFlags) { | |
609 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
610 | |
611 if (sSubType == BFFT_SIGNATURE) { | |
612 } else { | |
613 if (m_pFormFiller) | |
614 return m_pFormFiller->OnChar(pAnnot, nChar, nFlags); | |
615 } | |
616 | |
617 return FALSE; | |
618 } | |
619 | |
620 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, | |
621 int nKeyCode, | |
622 int nFlag) { | |
623 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
624 | |
625 if (sSubType == BFFT_SIGNATURE) { | |
626 } else { | |
627 if (m_pFormFiller) | |
628 return m_pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlag); | |
629 } | |
630 | |
631 return FALSE; | |
632 } | |
633 | |
634 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, | |
635 int nKeyCode, | |
636 int nFlag) { | |
637 return FALSE; | |
638 } | |
639 void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) { | |
640 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
641 | |
642 if (sSubType == BFFT_SIGNATURE) { | |
643 } else { | |
644 if (m_pFormFiller) | |
645 m_pFormFiller->OnCreate(pAnnot); | |
646 } | |
647 } | |
648 | |
649 void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) { | |
650 if (pAnnot->GetSubType() == BFFT_SIGNATURE) | |
651 return; | |
652 | |
653 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; | |
654 if (!pWidget->IsAppearanceValid()) | |
655 pWidget->ResetAppearance(NULL, FALSE); | |
656 | |
657 int nFieldType = pWidget->GetFieldType(); | |
658 if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) { | |
659 FX_BOOL bFormated = FALSE; | |
660 CFX_WideString sValue = pWidget->OnFormat(bFormated); | |
661 if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) { | |
662 pWidget->ResetAppearance(sValue.c_str(), FALSE); | |
663 } | |
664 } | |
665 | |
666 #ifdef PDF_ENABLE_XFA | |
667 CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); | |
668 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); | |
669 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); | |
670 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { | |
671 if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty()) | |
672 pWidget->ResetAppearance(FALSE); | |
673 } | |
674 #endif // PDF_ENABLE_XFA | |
675 if (m_pFormFiller) | |
676 m_pFormFiller->OnLoad(pAnnot); | |
677 } | |
678 | |
679 FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, | |
680 FX_DWORD nFlag) { | |
681 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
682 | |
683 if (sSubType == BFFT_SIGNATURE) { | |
684 } else { | |
685 if (m_pFormFiller) | |
686 return m_pFormFiller->OnSetFocus(pAnnot, nFlag); | |
687 } | |
688 | |
689 return TRUE; | |
690 } | |
691 FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot, | |
692 FX_DWORD nFlag) { | |
693 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
694 | |
695 if (sSubType == BFFT_SIGNATURE) { | |
696 } else { | |
697 if (m_pFormFiller) | |
698 return m_pFormFiller->OnKillFocus(pAnnot, nFlag); | |
699 } | |
700 | |
701 return TRUE; | |
702 } | |
703 | |
704 CFX_FloatRect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView, | |
705 CPDFSDK_Annot* pAnnot) { | |
706 CFX_ByteString sSubType = pAnnot->GetSubType(); | |
707 if (sSubType != BFFT_SIGNATURE && m_pFormFiller) | |
708 return CFX_FloatRect(m_pFormFiller->GetViewBBox(pPageView, pAnnot)); | |
709 | |
710 return CFX_FloatRect(0, 0, 0, 0); | |
711 } | |
712 | |
713 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, | |
714 CPDFSDK_Annot* pAnnot, | |
715 const CFX_FloatPoint& point) { | |
716 ASSERT(pPageView); | |
717 ASSERT(pAnnot); | |
718 | |
719 CFX_FloatRect rect = GetViewBBox(pPageView, pAnnot); | |
720 return rect.Contains(point.x, point.y); | |
721 } | |
722 | |
723 #ifdef PDF_ENABLE_XFA | |
724 #define FWL_WGTHITTEST_Unknown 0 | |
725 #define FWL_WGTHITTEST_Client 1 // arrow | |
726 #define FWL_WGTHITTEST_Titlebar 11 // caption | |
727 #define FWL_WGTHITTEST_HScrollBar 15 | |
728 #define FWL_WGTHITTEST_VScrollBar 16 | |
729 #define FWL_WGTHITTEST_Border 17 | |
730 #define FWL_WGTHITTEST_Edit 19 | |
731 #define FWL_WGTHITTEST_HyperLink 20 | |
732 | |
733 CPDFSDK_XFAAnnotHandler::CPDFSDK_XFAAnnotHandler(CPDFDoc_Environment* pApp) | |
734 : m_pApp(pApp) {} | |
735 | |
736 CPDFSDK_Annot* CPDFSDK_XFAAnnotHandler::NewAnnot(IXFA_Widget* pAnnot, | |
737 CPDFSDK_PageView* pPage) { | |
738 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument(); | |
739 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm(); | |
740 CPDFSDK_XFAWidget* pWidget = new CPDFSDK_XFAWidget(pAnnot, pPage, pInterForm); | |
741 pInterForm->AddXFAMap(pAnnot, pWidget); | |
742 return pWidget; | |
743 } | |
744 | |
745 FX_BOOL CPDFSDK_XFAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { | |
746 return pAnnot->GetXFAWidget() != NULL; | |
747 } | |
748 | |
749 void CPDFSDK_XFAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView, | |
750 CPDFSDK_Annot* pAnnot, | |
751 CFX_RenderDevice* pDevice, | |
752 CFX_Matrix* pUser2Device, | |
753 FX_DWORD dwFlags) { | |
754 ASSERT(pPageView != NULL); | |
755 ASSERT(pAnnot != NULL); | |
756 | |
757 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); | |
758 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
759 | |
760 CFX_Graphics gs; | |
761 gs.Create(pDevice); | |
762 | |
763 CFX_Matrix mt; | |
764 mt = *(CFX_Matrix*)pUser2Device; | |
765 | |
766 FX_BOOL bIsHighlight = FALSE; | |
767 if (pSDKDoc->GetFocusAnnot() != pAnnot) | |
768 bIsHighlight = TRUE; | |
769 | |
770 pWidgetHandler->RenderWidget(pAnnot->GetXFAWidget(), &gs, &mt, bIsHighlight); | |
771 | |
772 // to do highlight and shadow | |
773 } | |
774 | |
775 void CPDFSDK_XFAAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { | |
776 CPDFSDK_XFAWidget* pWidget = (CPDFSDK_XFAWidget*)pAnnot; | |
777 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); | |
778 pInterForm->RemoveXFAMap(pWidget->GetXFAWidget()); | |
779 | |
780 delete pWidget; | |
781 } | |
782 | |
783 CFX_FloatRect CPDFSDK_XFAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView, | |
784 CPDFSDK_Annot* pAnnot) { | |
785 ASSERT(pAnnot); | |
786 | |
787 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
788 CFX_RectF rcBBox; | |
789 XFA_ELEMENT eType = | |
790 pWidgetHandler->GetDataAcc(pAnnot->GetXFAWidget())->GetUIType(); | |
791 if (eType == XFA_ELEMENT_Signature) | |
792 pWidgetHandler->GetBBox(pAnnot->GetXFAWidget(), rcBBox, | |
793 XFA_WIDGETSTATUS_Visible, TRUE); | |
794 else | |
795 pWidgetHandler->GetBBox(pAnnot->GetXFAWidget(), rcBBox, 0); | |
796 | |
797 CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, | |
798 rcBBox.top + rcBBox.height); | |
799 rcWidget.left -= 1.0f; | |
800 rcWidget.right += 1.0f; | |
801 rcWidget.bottom -= 1.0f; | |
802 rcWidget.top += 1.0f; | |
803 | |
804 return rcWidget; | |
805 } | |
806 | |
807 FX_BOOL CPDFSDK_XFAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, | |
808 CPDFSDK_Annot* pAnnot, | |
809 const CFX_FloatPoint& point) { | |
810 if (!pPageView || !pAnnot) | |
811 return FALSE; | |
812 | |
813 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); | |
814 if (!pSDKDoc) | |
815 return FALSE; | |
816 | |
817 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); | |
818 if (!pDoc) | |
819 return FALSE; | |
820 | |
821 IXFA_DocView* pDocView = pDoc->GetXFADocView(); | |
822 if (!pDocView) | |
823 return FALSE; | |
824 | |
825 IXFA_WidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler(); | |
826 if (!pWidgetHandler) | |
827 return FALSE; | |
828 | |
829 FX_DWORD dwHitTest = | |
830 pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point.x, point.y); | |
831 return (dwHitTest != FWL_WGTHITTEST_Unknown); | |
832 } | |
833 | |
834 void CPDFSDK_XFAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView, | |
835 CPDFSDK_Annot* pAnnot, | |
836 FX_DWORD nFlag) { | |
837 if (!pPageView || !pAnnot) | |
838 return; | |
839 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
840 pWidgetHandler->OnMouseEnter(pAnnot->GetXFAWidget()); | |
841 } | |
842 | |
843 void CPDFSDK_XFAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView, | |
844 CPDFSDK_Annot* pAnnot, | |
845 FX_DWORD nFlag) { | |
846 if (!pPageView || !pAnnot) | |
847 return; | |
848 | |
849 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
850 pWidgetHandler->OnMouseExit(pAnnot->GetXFAWidget()); | |
851 } | |
852 | |
853 FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView, | |
854 CPDFSDK_Annot* pAnnot, | |
855 FX_DWORD nFlags, | |
856 const CFX_FloatPoint& point) { | |
857 if (!pPageView || !pAnnot) | |
858 return FALSE; | |
859 | |
860 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
861 return pWidgetHandler->OnLButtonDown(pAnnot->GetXFAWidget(), | |
862 GetFWLFlags(nFlags), point.x, point.y); | |
863 } | |
864 | |
865 FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView, | |
866 CPDFSDK_Annot* pAnnot, | |
867 FX_DWORD nFlags, | |
868 const CFX_FloatPoint& point) { | |
869 if (!pPageView || !pAnnot) | |
870 return FALSE; | |
871 | |
872 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
873 return pWidgetHandler->OnLButtonUp(pAnnot->GetXFAWidget(), | |
874 GetFWLFlags(nFlags), point.x, point.y); | |
875 } | |
876 | |
877 FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView, | |
878 CPDFSDK_Annot* pAnnot, | |
879 FX_DWORD nFlags, | |
880 const CFX_FloatPoint& point) { | |
881 if (!pPageView || !pAnnot) | |
882 return FALSE; | |
883 | |
884 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
885 return pWidgetHandler->OnLButtonDblClk(pAnnot->GetXFAWidget(), | |
886 GetFWLFlags(nFlags), point.x, point.y); | |
887 } | |
888 | |
889 FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView, | |
890 CPDFSDK_Annot* pAnnot, | |
891 FX_DWORD nFlags, | |
892 const CFX_FloatPoint& point) { | |
893 if (!pPageView || !pAnnot) | |
894 return FALSE; | |
895 | |
896 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
897 return pWidgetHandler->OnMouseMove(pAnnot->GetXFAWidget(), | |
898 GetFWLFlags(nFlags), point.x, point.y); | |
899 } | |
900 | |
901 FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView, | |
902 CPDFSDK_Annot* pAnnot, | |
903 FX_DWORD nFlags, | |
904 short zDelta, | |
905 const CFX_FloatPoint& point) { | |
906 if (!pPageView || !pAnnot) | |
907 return FALSE; | |
908 | |
909 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
910 return pWidgetHandler->OnMouseWheel( | |
911 pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), zDelta, point.x, point.y); | |
912 } | |
913 | |
914 FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView, | |
915 CPDFSDK_Annot* pAnnot, | |
916 FX_DWORD nFlags, | |
917 const CFX_FloatPoint& point) { | |
918 if (!pPageView || !pAnnot) | |
919 return FALSE; | |
920 | |
921 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
922 return pWidgetHandler->OnRButtonDown(pAnnot->GetXFAWidget(), | |
923 GetFWLFlags(nFlags), point.x, point.y); | |
924 } | |
925 | |
926 FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView, | |
927 CPDFSDK_Annot* pAnnot, | |
928 FX_DWORD nFlags, | |
929 const CFX_FloatPoint& point) { | |
930 if (!pPageView || !pAnnot) | |
931 return FALSE; | |
932 | |
933 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
934 return pWidgetHandler->OnRButtonUp(pAnnot->GetXFAWidget(), | |
935 GetFWLFlags(nFlags), point.x, point.y); | |
936 } | |
937 | |
938 FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView, | |
939 CPDFSDK_Annot* pAnnot, | |
940 FX_DWORD nFlags, | |
941 const CFX_FloatPoint& point) { | |
942 if (!pPageView || !pAnnot) | |
943 return FALSE; | |
944 | |
945 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
946 return pWidgetHandler->OnRButtonDblClk(pAnnot->GetXFAWidget(), | |
947 GetFWLFlags(nFlags), point.x, point.y); | |
948 } | |
949 | |
950 FX_BOOL CPDFSDK_XFAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot, | |
951 FX_DWORD nChar, | |
952 FX_DWORD nFlags) { | |
953 if (!pAnnot) | |
954 return FALSE; | |
955 | |
956 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
957 return pWidgetHandler->OnChar(pAnnot->GetXFAWidget(), nChar, | |
958 GetFWLFlags(nFlags)); | |
959 } | |
960 | |
961 FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, | |
962 int nKeyCode, | |
963 int nFlag) { | |
964 if (!pAnnot) | |
965 return FALSE; | |
966 | |
967 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
968 return pWidgetHandler->OnKeyDown(pAnnot->GetXFAWidget(), nKeyCode, | |
969 GetFWLFlags(nFlag)); | |
970 } | |
971 | |
972 FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, | |
973 int nKeyCode, | |
974 int nFlag) { | |
975 if (!pAnnot) | |
976 return FALSE; | |
977 | |
978 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
979 return pWidgetHandler->OnKeyUp(pAnnot->GetXFAWidget(), nKeyCode, | |
980 GetFWLFlags(nFlag)); | |
981 } | |
982 | |
983 FX_BOOL CPDFSDK_XFAAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, | |
984 FX_DWORD nFlag) { | |
985 return TRUE; | |
986 } | |
987 | |
988 FX_BOOL CPDFSDK_XFAAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot, | |
989 FX_DWORD nFlag) { | |
990 return TRUE; | |
991 } | |
992 | |
993 FX_BOOL CPDFSDK_XFAAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot, | |
994 CPDFSDK_Annot* pNewAnnot) { | |
995 IXFA_WidgetHandler* pWidgetHandler = NULL; | |
996 | |
997 if (pOldAnnot) | |
998 pWidgetHandler = GetXFAWidgetHandler(pOldAnnot); | |
999 else if (pNewAnnot) | |
1000 pWidgetHandler = GetXFAWidgetHandler(pNewAnnot); | |
1001 | |
1002 if (pWidgetHandler) { | |
1003 FX_BOOL bRet = TRUE; | |
1004 IXFA_Widget* hWidget = pNewAnnot ? pNewAnnot->GetXFAWidget() : NULL; | |
1005 if (hWidget) { | |
1006 IXFA_PageView* pXFAPageView = pWidgetHandler->GetPageView(hWidget); | |
1007 if (pXFAPageView) { | |
1008 bRet = pXFAPageView->GetDocView()->SetFocus(hWidget); | |
1009 if (pXFAPageView->GetDocView()->GetFocusWidget() == hWidget) | |
1010 bRet = TRUE; | |
1011 } | |
1012 } | |
1013 return bRet; | |
1014 } | |
1015 | |
1016 return TRUE; | |
1017 } | |
1018 | |
1019 IXFA_WidgetHandler* CPDFSDK_XFAAnnotHandler::GetXFAWidgetHandler( | |
1020 CPDFSDK_Annot* pAnnot) { | |
1021 if (!pAnnot) | |
1022 return NULL; | |
1023 | |
1024 CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); | |
1025 if (!pPageView) | |
1026 return NULL; | |
1027 | |
1028 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); | |
1029 if (!pSDKDoc) | |
1030 return NULL; | |
1031 | |
1032 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); | |
1033 if (!pDoc) | |
1034 return NULL; | |
1035 | |
1036 IXFA_DocView* pDocView = pDoc->GetXFADocView(); | |
1037 if (!pDocView) | |
1038 return NULL; | |
1039 | |
1040 return pDocView->GetWidgetHandler(); | |
1041 } | |
1042 | |
1043 #define FWL_KEYFLAG_Ctrl (1 << 0) | |
1044 #define FWL_KEYFLAG_Alt (1 << 1) | |
1045 #define FWL_KEYFLAG_Shift (1 << 2) | |
1046 #define FWL_KEYFLAG_LButton (1 << 3) | |
1047 #define FWL_KEYFLAG_RButton (1 << 4) | |
1048 #define FWL_KEYFLAG_MButton (1 << 5) | |
1049 | |
1050 FX_DWORD CPDFSDK_XFAAnnotHandler::GetFWLFlags(FX_DWORD dwFlag) { | |
1051 FX_DWORD dwFWLFlag = 0; | |
1052 | |
1053 if (dwFlag & FWL_EVENTFLAG_ControlKey) | |
1054 dwFWLFlag |= FWL_KEYFLAG_Ctrl; | |
1055 if (dwFlag & FWL_EVENTFLAG_LeftButtonDown) | |
1056 dwFWLFlag |= FWL_KEYFLAG_LButton; | |
1057 if (dwFlag & FWL_EVENTFLAG_MiddleButtonDown) | |
1058 dwFWLFlag |= FWL_KEYFLAG_MButton; | |
1059 if (dwFlag & FWL_EVENTFLAG_RightButtonDown) | |
1060 dwFWLFlag |= FWL_KEYFLAG_RButton; | |
1061 if (dwFlag & FWL_EVENTFLAG_ShiftKey) | |
1062 dwFWLFlag |= FWL_KEYFLAG_Shift; | |
1063 if (dwFlag & FWL_EVENTFLAG_AltKey) | |
1064 dwFWLFlag |= FWL_KEYFLAG_Alt; | |
1065 | |
1066 return dwFWLFlag; | |
1067 } | |
1068 #endif // PDF_ENABLE_XFA | |
1069 | |
1070 CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView, | |
1071 bool bReverse) | |
1072 : m_bReverse(bReverse), m_pos(0) { | |
1073 const std::vector<CPDFSDK_Annot*>& annots = pPageView->GetAnnotList(); | |
1074 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), annots.rbegin(), | |
1075 annots.rend()); | |
1076 std::stable_sort(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(), | |
1077 [](CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) { | |
1078 return p1->GetLayoutOrder() < p2->GetLayoutOrder(); | |
1079 }); | |
1080 | |
1081 CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot(); | |
1082 if (!pTopMostAnnot) | |
1083 return; | |
1084 | |
1085 auto it = std::find(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(), | |
1086 pTopMostAnnot); | |
1087 if (it != m_iteratorAnnotList.end()) { | |
1088 CPDFSDK_Annot* pReaderAnnot = *it; | |
1089 m_iteratorAnnotList.erase(it); | |
1090 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), pReaderAnnot); | |
1091 } | |
1092 } | |
1093 | |
1094 CPDFSDK_AnnotIterator::~CPDFSDK_AnnotIterator() { | |
1095 } | |
1096 | |
1097 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot() { | |
1098 if (m_pos < m_iteratorAnnotList.size()) | |
1099 return m_iteratorAnnotList[m_pos++]; | |
1100 return nullptr; | |
1101 } | |
1102 | |
1103 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot() { | |
1104 if (m_pos < m_iteratorAnnotList.size()) | |
1105 return m_iteratorAnnotList[m_iteratorAnnotList.size() - ++m_pos]; | |
1106 return nullptr; | |
1107 } | |
1108 | |
1109 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next() { | |
1110 return m_bReverse ? PrevAnnot() : NextAnnot(); | |
1111 } | |
OLD | NEW |