Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: fpdfsdk/fsdk_annothandler.cpp

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

Powered by Google App Engine
This is Rietveld 408576698