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

Side by Side Diff: fpdfsdk/src/fsdk_annothandler.cpp

Issue 1399273003: fpdfsdk/ differences with XFA (for didactic purposes only). (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Regenerate after taking juns patch Created 5 years 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/src/fsdk_actionhandler.cpp ('k') | fpdfsdk/src/fsdk_baseannot.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #ifdef PDF_ENABLE_XFA
10 #include "../include/fpdfxfa/fpdfxfa_doc.h"
11 #include "../include/fpdfxfa/fpdfxfa_util.h"
12 #endif
9 #include "fpdfsdk/include/formfiller/FFL_FormFiller.h" 13 #include "fpdfsdk/include/formfiller/FFL_FormFiller.h"
10 #include "fpdfsdk/include/fsdk_annothandler.h" 14 #include "fpdfsdk/include/fsdk_annothandler.h"
11 #include "fpdfsdk/include/fsdk_define.h" 15 #include "fpdfsdk/include/fsdk_define.h"
12 #include "fpdfsdk/include/fsdk_mgr.h" 16 #include "fpdfsdk/include/fsdk_mgr.h"
13 17
14 CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) { 18 CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) {
15 m_pApp = pApp; 19 m_pApp = pApp;
16 20
17 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp); 21 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp);
18 pHandler->SetFormFiller(m_pApp->GetIFormFiller()); 22 pHandler->SetFormFiller(m_pApp->GetIFormFiller());
19 RegisterAnnotHandler(pHandler); 23 RegisterAnnotHandler(pHandler);
24 #ifdef PDF_ENABLE_XFA
25
26 CPDFSDK_XFAAnnotHandler* pXFAAnnotHandler =
27 new CPDFSDK_XFAAnnotHandler(m_pApp);
28 RegisterAnnotHandler(pXFAAnnotHandler);
29 #endif
20 } 30 }
21 31
22 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() { 32 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {
23 for (int i = 0; i < m_Handlers.GetSize(); i++) { 33 for (int i = 0; i < m_Handlers.GetSize(); i++) {
24 IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i); 34 IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i);
25 delete pHandler; 35 delete pHandler;
26 } 36 }
27 m_Handlers.RemoveAll(); 37 m_Handlers.RemoveAll();
28 m_mapType2Handler.clear(); 38 m_mapType2Handler.clear();
29 } 39 }
(...skipping 23 matching lines...) Expand all
53 ASSERT(pPageView != NULL); 63 ASSERT(pPageView != NULL);
54 64
55 if (IPDFSDK_AnnotHandler* pAnnotHandler = 65 if (IPDFSDK_AnnotHandler* pAnnotHandler =
56 GetAnnotHandler(pAnnot->GetSubType())) { 66 GetAnnotHandler(pAnnot->GetSubType())) {
57 return pAnnotHandler->NewAnnot(pAnnot, pPageView); 67 return pAnnotHandler->NewAnnot(pAnnot, pPageView);
58 } 68 }
59 69
60 return new CPDFSDK_BAAnnot(pAnnot, pPageView); 70 return new CPDFSDK_BAAnnot(pAnnot, pPageView);
61 } 71 }
62 72
73 #ifdef PDF_ENABLE_XFA
74 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(IXFA_Widget* pAnnot,
75 CPDFSDK_PageView* pPageView) {
76 ASSERT(pAnnot != NULL);
77 ASSERT(pPageView != NULL);
78
79 if (IPDFSDK_AnnotHandler* pAnnotHandler =
80 GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME)) {
81 return pAnnotHandler->NewAnnot(pAnnot, pPageView);
82 }
83
84 return NULL;
85 }
86
87 #endif
63 void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { 88 void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
64 ASSERT(pAnnot != NULL); 89 ASSERT(pAnnot != NULL);
65 90
66 pAnnot->GetPDFPage(); 91 pAnnot->GetPDFPage();
67 92
68 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { 93 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
69 pAnnotHandler->OnRelease(pAnnot); 94 pAnnotHandler->OnRelease(pAnnot);
70 pAnnotHandler->ReleaseAnnot(pAnnot); 95 pAnnotHandler->ReleaseAnnot(pAnnot);
71 } else { 96 } else {
72 delete (CPDFSDK_Annot*)pAnnot; 97 delete (CPDFSDK_Annot*)pAnnot;
(...skipping 22 matching lines...) Expand all
95 } 120 }
96 } 121 }
97 122
98 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( 123 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
99 CPDFSDK_Annot* pAnnot) const { 124 CPDFSDK_Annot* pAnnot) const {
100 ASSERT(pAnnot != NULL); 125 ASSERT(pAnnot != NULL);
101 126
102 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); 127 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
103 if (pPDFAnnot) 128 if (pPDFAnnot)
104 return GetAnnotHandler(pPDFAnnot->GetSubType()); 129 return GetAnnotHandler(pPDFAnnot->GetSubType());
130 #ifdef PDF_ENABLE_XFA
131 if (pAnnot->GetXFAWidget())
132 return GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME);
133 #endif
105 return nullptr; 134 return nullptr;
106 } 135 }
107 136
108 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( 137 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
109 const CFX_ByteString& sType) const { 138 const CFX_ByteString& sType) const {
110 auto it = m_mapType2Handler.find(sType); 139 auto it = m_mapType2Handler.find(sType);
111 return it != m_mapType2Handler.end() ? it->second : nullptr; 140 return it != m_mapType2Handler.end() ? it->second : nullptr;
112 } 141 }
113 142
114 void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, 143 void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView,
115 CPDFSDK_Annot* pAnnot, 144 CPDFSDK_Annot* pAnnot,
116 CFX_RenderDevice* pDevice, 145 CFX_RenderDevice* pDevice,
117 CPDF_Matrix* pUser2Device, 146 CPDF_Matrix* pUser2Device,
118 FX_DWORD dwFlags) { 147 FX_DWORD dwFlags) {
119 ASSERT(pAnnot); 148 ASSERT(pAnnot);
120 149
121 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { 150 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
122 pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); 151 pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
123 } else { 152 } else {
153 #ifdef PDF_ENABLE_XFA
154 if (pAnnot->IsXFAField())
155 return;
156 #endif
124 static_cast<CPDFSDK_BAAnnot*>(pAnnot) 157 static_cast<CPDFSDK_BAAnnot*>(pAnnot)
125 ->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); 158 ->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
126 } 159 }
127 } 160 }
128 161
129 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown( 162 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(
130 CPDFSDK_PageView* pPageView, 163 CPDFSDK_PageView* pPageView,
131 CPDFSDK_Annot* pAnnot, 164 CPDFSDK_Annot* pAnnot,
132 FX_DWORD nFlags, 165 FX_DWORD nFlags,
133 const CPDF_Point& point) { 166 const CPDF_Point& point) {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 318
286 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot, 319 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot,
287 FX_DWORD nFlag) { 320 FX_DWORD nFlag) {
288 ASSERT(pAnnot); 321 ASSERT(pAnnot);
289 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) 322 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
290 return pAnnotHandler->OnKillFocus(pAnnot, nFlag); 323 return pAnnotHandler->OnKillFocus(pAnnot, nFlag);
291 324
292 return FALSE; 325 return FALSE;
293 } 326 }
294 327
328 #ifdef PDF_ENABLE_XFA
329 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus(
330 CPDFSDK_Annot* pSetAnnot,
331 CPDFSDK_Annot* pKillAnnot) {
332 FX_BOOL bXFA = (pSetAnnot && pSetAnnot->GetXFAWidget()) ||
333 (pKillAnnot && pKillAnnot->GetXFAWidget());
334
335 if (bXFA) {
336 if (IPDFSDK_AnnotHandler* pXFAAnnotHandler =
337 GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME))
338 return pXFAAnnotHandler->OnXFAChangedFocus(pKillAnnot, pSetAnnot);
339 }
340
341 return TRUE;
342 }
343
344 #endif
295 CPDF_Rect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox( 345 CPDF_Rect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(
296 CPDFSDK_PageView* pPageView, 346 CPDFSDK_PageView* pPageView,
297 CPDFSDK_Annot* pAnnot) { 347 CPDFSDK_Annot* pAnnot) {
298 ASSERT(pAnnot); 348 ASSERT(pAnnot);
299 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) 349 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
300 return pAnnotHandler->GetViewBBox(pPageView, pAnnot); 350 return pAnnotHandler->GetViewBBox(pPageView, pAnnot);
301 351
302 return pAnnot->GetRect(); 352 return pAnnot->GetRect();
303 } 353 }
304 354
305 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView, 355 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView,
306 CPDFSDK_Annot* pAnnot, 356 CPDFSDK_Annot* pAnnot,
307 const CPDF_Point& point) { 357 const CPDF_Point& point) {
308 ASSERT(pAnnot); 358 ASSERT(pAnnot);
309 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { 359 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
310 if (pAnnotHandler->CanAnswer(pAnnot)) 360 if (pAnnotHandler->CanAnswer(pAnnot))
311 return pAnnotHandler->HitTest(pPageView, pAnnot, point); 361 return pAnnotHandler->HitTest(pPageView, pAnnot, point);
312 } 362 }
313 return FALSE; 363 return FALSE;
314 } 364 }
315 365
316 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot, 366 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,
317 FX_BOOL bNext) { 367 FX_BOOL bNext) {
368 #ifndef PDF_ENABLE_XFA
318 CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), "Widget", ""); 369 CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), "Widget", "");
319 return bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot); 370 return bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot);
371 #else
372 CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView();
373 CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage();
374 if (pPage == NULL)
375 return NULL;
376 if (pPage->GetPDFPage()) { // for pdf annots.
377 CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), pSDKAnnot->GetType(), "");
378 CPDFSDK_Annot* pNext =
379 bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot);
380 return pNext;
381 }
382 // for xfa annots
383 IXFA_WidgetIterator* pWidgetIterator =
384 pPage->GetXFAPageView()->CreateWidgetIterator(
385 XFA_TRAVERSEWAY_Tranvalse, XFA_WIDGETFILTER_Visible |
386 XFA_WIDGETFILTER_Viewable |
387 XFA_WIDGETFILTER_Field);
388 if (pWidgetIterator == NULL)
389 return NULL;
390 if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget())
391 pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget());
392 IXFA_Widget* hNextFocus = NULL;
393 hNextFocus =
394 bNext ? pWidgetIterator->MoveToNext() : pWidgetIterator->MoveToPrevious();
395 if (hNextFocus == NULL && pSDKAnnot != NULL)
396 hNextFocus = pWidgetIterator->MoveToFirst();
397
398 pWidgetIterator->Release();
399 return pPageView->GetAnnotByXFAWidget(hNextFocus);
400 #endif
320 } 401 }
321 402
322 FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { 403 FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
323 ASSERT(pAnnot->GetType() == "Widget"); 404 ASSERT(pAnnot->GetType() == "Widget");
324 if (pAnnot->GetSubType() == BFFT_SIGNATURE) 405 if (pAnnot->GetSubType() == BFFT_SIGNATURE)
325 return FALSE; 406 return FALSE;
326 407
327 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; 408 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
328 if (!pWidget->IsVisible()) 409 if (!pWidget->IsVisible())
329 return FALSE; 410 return FALSE;
(...skipping 23 matching lines...) Expand all
353 434
354 CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm); 435 CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm);
355 pInterForm->AddMap(pCtrl, pWidget); 436 pInterForm->AddMap(pCtrl, pWidget);
356 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); 437 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
357 if (pPDFInterForm && pPDFInterForm->NeedConstructAP()) 438 if (pPDFInterForm && pPDFInterForm->NeedConstructAP())
358 pWidget->ResetAppearance(nullptr, FALSE); 439 pWidget->ResetAppearance(nullptr, FALSE);
359 440
360 return pWidget; 441 return pWidget;
361 } 442 }
362 443
444 #ifdef PDF_ENABLE_XFA
445 CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(IXFA_Widget* hWidget,
446 CPDFSDK_PageView* pPage) {
447 return NULL;
448 }
449
450 #endif
363 void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { 451 void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
364 ASSERT(pAnnot != NULL); 452 ASSERT(pAnnot != NULL);
365 453
366 if (m_pFormFiller) 454 if (m_pFormFiller)
367 m_pFormFiller->OnDelete(pAnnot); 455 m_pFormFiller->OnDelete(pAnnot);
368 456
369 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; 457 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
370 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); 458 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
371 ASSERT(pInterForm != NULL); 459 ASSERT(pInterForm != NULL);
372 460
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 674
587 int nFieldType = pWidget->GetFieldType(); 675 int nFieldType = pWidget->GetFieldType();
588 if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) { 676 if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) {
589 FX_BOOL bFormated = FALSE; 677 FX_BOOL bFormated = FALSE;
590 CFX_WideString sValue = pWidget->OnFormat(bFormated); 678 CFX_WideString sValue = pWidget->OnFormat(bFormated);
591 if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) { 679 if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) {
592 pWidget->ResetAppearance(sValue.c_str(), FALSE); 680 pWidget->ResetAppearance(sValue.c_str(), FALSE);
593 } 681 }
594 } 682 }
595 683
684 #ifdef PDF_ENABLE_XFA
685 CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
686 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
687 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
688 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
689 if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty())
690 pWidget->ResetAppearance(FALSE);
691 }
692
693 #endif
596 if (m_pFormFiller) 694 if (m_pFormFiller)
597 m_pFormFiller->OnLoad(pAnnot); 695 m_pFormFiller->OnLoad(pAnnot);
598 } 696 }
599 697
600 FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, 698 FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot,
601 FX_DWORD nFlag) { 699 FX_DWORD nFlag) {
602 ASSERT(pAnnot != NULL); 700 ASSERT(pAnnot != NULL);
603 CFX_ByteString sSubType = pAnnot->GetSubType(); 701 CFX_ByteString sSubType = pAnnot->GetSubType();
604 702
605 if (sSubType == BFFT_SIGNATURE) { 703 if (sSubType == BFFT_SIGNATURE) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, 739 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
642 CPDFSDK_Annot* pAnnot, 740 CPDFSDK_Annot* pAnnot,
643 const CPDF_Point& point) { 741 const CPDF_Point& point) {
644 ASSERT(pPageView); 742 ASSERT(pPageView);
645 ASSERT(pAnnot); 743 ASSERT(pAnnot);
646 744
647 CPDF_Rect rect = GetViewBBox(pPageView, pAnnot); 745 CPDF_Rect rect = GetViewBBox(pPageView, pAnnot);
648 return rect.Contains(point.x, point.y); 746 return rect.Contains(point.x, point.y);
649 } 747 }
650 748
749 #ifdef PDF_ENABLE_XFA
750 #define FWL_WGTHITTEST_Unknown 0
751 #define FWL_WGTHITTEST_Client 1 // arrow
752 #define FWL_WGTHITTEST_Titlebar 11 // caption
753 #define FWL_WGTHITTEST_HScrollBar 15
754 #define FWL_WGTHITTEST_VScrollBar 16
755 #define FWL_WGTHITTEST_Border 17
756 #define FWL_WGTHITTEST_Edit 19
757 #define FWL_WGTHITTEST_HyperLink 20
758
759 CPDFSDK_XFAAnnotHandler::CPDFSDK_XFAAnnotHandler(CPDFDoc_Environment* pApp)
760 : m_pApp(pApp) {}
761
762 CPDFSDK_Annot* CPDFSDK_XFAAnnotHandler::NewAnnot(IXFA_Widget* pAnnot,
763 CPDFSDK_PageView* pPage) {
764 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument();
765 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm();
766 CPDFSDK_XFAWidget* pWidget = new CPDFSDK_XFAWidget(pAnnot, pPage, pInterForm);
767 pInterForm->AddXFAMap(pAnnot, pWidget);
768 return pWidget;
769 }
770
771 FX_BOOL CPDFSDK_XFAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
772 return pAnnot->GetXFAWidget() != NULL;
773 }
774
775 void CPDFSDK_XFAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
776 CPDFSDK_Annot* pAnnot,
777 CFX_RenderDevice* pDevice,
778 CPDF_Matrix* pUser2Device,
779 FX_DWORD dwFlags) {
780 #ifdef PDF_ENABLE_XFA
781
782 ASSERT(pPageView != NULL);
783 ASSERT(pAnnot != NULL);
784
785 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
786 ASSERT(pSDKDoc != NULL);
787
788 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
789 ASSERT(pWidgetHandler != NULL);
790
791 CFX_Graphics gs;
792 gs.Create(pDevice);
793
794 CFX_Matrix mt;
795 mt = *(CFX_Matrix*)pUser2Device;
796
797 FX_BOOL bIsHighlight = FALSE;
798 if (pSDKDoc->GetFocusAnnot() != pAnnot)
799 bIsHighlight = TRUE;
800
801 pWidgetHandler->RenderWidget(pAnnot->GetXFAWidget(), &gs, &mt, bIsHighlight);
802
803 // to do highlight and shadow
804 #endif // PDF_ENABLE_XFA
805 }
806
807 void CPDFSDK_XFAAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
808 ASSERT(pAnnot != NULL);
809
810 CPDFSDK_XFAWidget* pWidget = (CPDFSDK_XFAWidget*)pAnnot;
811 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
812 ASSERT(pInterForm != NULL);
813
814 pInterForm->RemoveXFAMap(pWidget->GetXFAWidget());
815
816 delete pWidget;
817 }
818
819 CPDF_Rect CPDFSDK_XFAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
820 CPDFSDK_Annot* pAnnot) {
821 ASSERT(pAnnot != NULL);
822
823 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
824 ASSERT(pWidgetHandler != NULL);
825
826 CFX_RectF rcBBox;
827 #ifdef PDF_ENABLE_XFA
828 XFA_ELEMENT eType =
829 pWidgetHandler->GetDataAcc(pAnnot->GetXFAWidget())->GetUIType();
830 if (eType == XFA_ELEMENT_Signature)
831 pWidgetHandler->GetBBox(pAnnot->GetXFAWidget(), rcBBox,
832 XFA_WIDGETSTATUS_Visible, TRUE);
833 else
834 #endif
835 pWidgetHandler->GetBBox(pAnnot->GetXFAWidget(), rcBBox, 0);
836
837 CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
838 rcBBox.top + rcBBox.height);
839 rcWidget.left -= 1.0f;
840 rcWidget.right += 1.0f;
841 rcWidget.bottom -= 1.0f;
842 rcWidget.top += 1.0f;
843
844 return rcWidget;
845 }
846
847 FX_BOOL CPDFSDK_XFAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
848 CPDFSDK_Annot* pAnnot,
849 const CPDF_Point& point) {
850 if (!pPageView || !pAnnot)
851 return FALSE;
852
853 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
854 if (!pSDKDoc)
855 return FALSE;
856
857 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
858 if (!pDoc)
859 return FALSE;
860
861 IXFA_DocView* pDocView = pDoc->GetXFADocView();
862 if (!pDocView)
863 return FALSE;
864
865 IXFA_WidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
866 if (!pWidgetHandler)
867 return FALSE;
868
869 FX_DWORD dwHitTest =
870 pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point.x, point.y);
871 return (dwHitTest != FWL_WGTHITTEST_Unknown);
872 }
873
874 void CPDFSDK_XFAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
875 CPDFSDK_Annot* pAnnot,
876 FX_DWORD nFlag) {
877 if (!pPageView || !pAnnot)
878 return;
879 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
880 ASSERT(pWidgetHandler != NULL);
881
882 pWidgetHandler->OnMouseEnter(pAnnot->GetXFAWidget());
883 }
884
885 void CPDFSDK_XFAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
886 CPDFSDK_Annot* pAnnot,
887 FX_DWORD nFlag) {
888 if (!pPageView || !pAnnot)
889 return;
890
891 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
892 ASSERT(pWidgetHandler != NULL);
893
894 pWidgetHandler->OnMouseExit(pAnnot->GetXFAWidget());
895 }
896
897 FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
898 CPDFSDK_Annot* pAnnot,
899 FX_DWORD nFlags,
900 const CPDF_Point& point) {
901 if (!pPageView || !pAnnot)
902 return FALSE;
903
904 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
905 ASSERT(pWidgetHandler != NULL);
906
907 FX_BOOL bRet = FALSE;
908 bRet = pWidgetHandler->OnLButtonDown(pAnnot->GetXFAWidget(),
909 GetFWLFlags(nFlags), point.x, point.y);
910
911 return bRet;
912 }
913
914 FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
915 CPDFSDK_Annot* pAnnot,
916 FX_DWORD nFlags,
917 const CPDF_Point& point) {
918 if (!pPageView || !pAnnot)
919 return FALSE;
920
921 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
922 ASSERT(pWidgetHandler != NULL);
923
924 FX_BOOL bRet = FALSE;
925 bRet = pWidgetHandler->OnLButtonUp(pAnnot->GetXFAWidget(),
926 GetFWLFlags(nFlags), point.x, point.y);
927
928 return bRet;
929 }
930
931 FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
932 CPDFSDK_Annot* pAnnot,
933 FX_DWORD nFlags,
934 const CPDF_Point& point) {
935 if (!pPageView || !pAnnot)
936 return FALSE;
937
938 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
939 ASSERT(pWidgetHandler != NULL);
940
941 FX_BOOL bRet = FALSE;
942 bRet = pWidgetHandler->OnLButtonDblClk(pAnnot->GetXFAWidget(),
943 GetFWLFlags(nFlags), point.x, point.y);
944
945 return bRet;
946 }
947
948 FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
949 CPDFSDK_Annot* pAnnot,
950 FX_DWORD nFlags,
951 const CPDF_Point& point) {
952 if (!pPageView || !pAnnot)
953 return FALSE;
954
955 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
956 ASSERT(pWidgetHandler != NULL);
957
958 FX_BOOL bRet = FALSE;
959 bRet = pWidgetHandler->OnMouseMove(pAnnot->GetXFAWidget(),
960 GetFWLFlags(nFlags), point.x, point.y);
961
962 return bRet;
963 }
964
965 FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
966 CPDFSDK_Annot* pAnnot,
967 FX_DWORD nFlags,
968 short zDelta,
969 const CPDF_Point& point) {
970 if (!pPageView || !pAnnot)
971 return FALSE;
972
973 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
974 ASSERT(pWidgetHandler != NULL);
975
976 FX_BOOL bRet = FALSE;
977 bRet = pWidgetHandler->OnMouseWheel(
978 pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), zDelta, point.x, point.y);
979
980 return bRet;
981 }
982
983 FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
984 CPDFSDK_Annot* pAnnot,
985 FX_DWORD nFlags,
986 const CPDF_Point& point) {
987 if (!pPageView || !pAnnot)
988 return FALSE;
989
990 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
991 ASSERT(pWidgetHandler != NULL);
992
993 FX_BOOL bRet = FALSE;
994 bRet = pWidgetHandler->OnRButtonDown(pAnnot->GetXFAWidget(),
995 GetFWLFlags(nFlags), point.x, point.y);
996
997 return bRet;
998 }
999
1000 FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
1001 CPDFSDK_Annot* pAnnot,
1002 FX_DWORD nFlags,
1003 const CPDF_Point& point) {
1004 if (!pPageView || !pAnnot)
1005 return FALSE;
1006
1007 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
1008 ASSERT(pWidgetHandler != NULL);
1009
1010 FX_BOOL bRet = FALSE;
1011 bRet = pWidgetHandler->OnRButtonUp(pAnnot->GetXFAWidget(),
1012 GetFWLFlags(nFlags), point.x, point.y);
1013
1014 return bRet;
1015 }
1016
1017 FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView,
1018 CPDFSDK_Annot* pAnnot,
1019 FX_DWORD nFlags,
1020 const CPDF_Point& point) {
1021 if (!pPageView || !pAnnot)
1022 return FALSE;
1023
1024 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
1025 ASSERT(pWidgetHandler != NULL);
1026
1027 FX_BOOL bRet = FALSE;
1028 bRet = pWidgetHandler->OnRButtonDblClk(pAnnot->GetXFAWidget(),
1029 GetFWLFlags(nFlags), point.x, point.y);
1030
1031 return bRet;
1032 }
1033
1034 FX_BOOL CPDFSDK_XFAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
1035 FX_DWORD nChar,
1036 FX_DWORD nFlags) {
1037 if (!pAnnot)
1038 return FALSE;
1039
1040 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
1041 ASSERT(pWidgetHandler != NULL);
1042
1043 FX_BOOL bRet = FALSE;
1044 bRet = pWidgetHandler->OnChar(pAnnot->GetXFAWidget(), nChar,
1045 GetFWLFlags(nFlags));
1046
1047 return bRet;
1048 }
1049
1050 FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
1051 int nKeyCode,
1052 int nFlag) {
1053 if (!pAnnot)
1054 return FALSE;
1055
1056 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
1057 ASSERT(pWidgetHandler != NULL);
1058
1059 FX_BOOL bRet = FALSE;
1060 bRet = pWidgetHandler->OnKeyDown(pAnnot->GetXFAWidget(), nKeyCode,
1061 GetFWLFlags(nFlag));
1062
1063 return bRet;
1064 }
1065
1066 FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
1067 int nKeyCode,
1068 int nFlag) {
1069 if (!pAnnot)
1070 return FALSE;
1071
1072 IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
1073 ASSERT(pWidgetHandler != NULL);
1074
1075 FX_BOOL bRet = FALSE;
1076 bRet = pWidgetHandler->OnKeyUp(pAnnot->GetXFAWidget(), nKeyCode,
1077 GetFWLFlags(nFlag));
1078
1079 return bRet;
1080 }
1081
1082 FX_BOOL CPDFSDK_XFAAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot,
1083 FX_DWORD nFlag) {
1084 return TRUE;
1085 }
1086
1087 FX_BOOL CPDFSDK_XFAAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot,
1088 FX_DWORD nFlag) {
1089 return TRUE;
1090 }
1091
1092 FX_BOOL CPDFSDK_XFAAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot,
1093 CPDFSDK_Annot* pNewAnnot) {
1094 IXFA_WidgetHandler* pWidgetHandler = NULL;
1095
1096 if (pOldAnnot)
1097 pWidgetHandler = GetXFAWidgetHandler(pOldAnnot);
1098 else if (pNewAnnot)
1099 pWidgetHandler = GetXFAWidgetHandler(pNewAnnot);
1100
1101 if (pWidgetHandler) {
1102 FX_BOOL bRet = TRUE;
1103 IXFA_Widget* hWidget = pNewAnnot ? pNewAnnot->GetXFAWidget() : NULL;
1104 if (hWidget) {
1105 IXFA_PageView* pXFAPageView = pWidgetHandler->GetPageView(hWidget);
1106 if (pXFAPageView) {
1107 bRet = pXFAPageView->GetDocView()->SetFocus(hWidget);
1108 if (pXFAPageView->GetDocView()->GetFocusWidget() == hWidget)
1109 bRet = TRUE;
1110 }
1111 }
1112 return bRet;
1113 }
1114
1115 return TRUE;
1116 }
1117
1118 IXFA_WidgetHandler* CPDFSDK_XFAAnnotHandler::GetXFAWidgetHandler(
1119 CPDFSDK_Annot* pAnnot) {
1120 if (!pAnnot)
1121 return NULL;
1122
1123 CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
1124 if (!pPageView)
1125 return NULL;
1126
1127 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
1128 if (!pSDKDoc)
1129 return NULL;
1130
1131 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
1132 if (!pDoc)
1133 return NULL;
1134
1135 IXFA_DocView* pDocView = pDoc->GetXFADocView();
1136 if (!pDocView)
1137 return NULL;
1138
1139 return pDocView->GetWidgetHandler();
1140 }
1141
1142 #define FWL_KEYFLAG_Ctrl (1 << 0)
1143 #define FWL_KEYFLAG_Alt (1 << 1)
1144 #define FWL_KEYFLAG_Shift (1 << 2)
1145 #define FWL_KEYFLAG_LButton (1 << 3)
1146 #define FWL_KEYFLAG_RButton (1 << 4)
1147 #define FWL_KEYFLAG_MButton (1 << 5)
1148
1149 FX_DWORD CPDFSDK_XFAAnnotHandler::GetFWLFlags(FX_DWORD dwFlag) {
1150 FX_DWORD dwFWLFlag = 0;
1151
1152 if (dwFlag & FWL_EVENTFLAG_ControlKey)
1153 dwFWLFlag |= FWL_KEYFLAG_Ctrl;
1154 if (dwFlag & FWL_EVENTFLAG_LeftButtonDown)
1155 dwFWLFlag |= FWL_KEYFLAG_LButton;
1156 if (dwFlag & FWL_EVENTFLAG_MiddleButtonDown)
1157 dwFWLFlag |= FWL_KEYFLAG_MButton;
1158 if (dwFlag & FWL_EVENTFLAG_RightButtonDown)
1159 dwFWLFlag |= FWL_KEYFLAG_RButton;
1160 if (dwFlag & FWL_EVENTFLAG_ShiftKey)
1161 dwFWLFlag |= FWL_KEYFLAG_Shift;
1162 if (dwFlag & FWL_EVENTFLAG_AltKey)
1163 dwFWLFlag |= FWL_KEYFLAG_Alt;
1164
1165 return dwFWLFlag;
1166 }
1167
1168 #endif
651 CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView, 1169 CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView,
652 bool bReverse) 1170 bool bReverse)
653 : m_bReverse(bReverse), m_pos(0) { 1171 : m_bReverse(bReverse), m_pos(0) {
654 const std::vector<CPDFSDK_Annot*>& annots = pPageView->GetAnnotList(); 1172 const std::vector<CPDFSDK_Annot*>& annots = pPageView->GetAnnotList();
655 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), annots.rbegin(), 1173 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), annots.rbegin(),
656 annots.rend()); 1174 annots.rend());
657 std::stable_sort(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(), 1175 std::stable_sort(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(),
658 [](CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) { 1176 [](CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) {
659 return p1->GetLayoutOrder() < p2->GetLayoutOrder(); 1177 return p1->GetLayoutOrder() < p2->GetLayoutOrder();
660 }); 1178 });
(...skipping 22 matching lines...) Expand all
683 1201
684 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot() { 1202 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot() {
685 if (m_pos < m_iteratorAnnotList.size()) 1203 if (m_pos < m_iteratorAnnotList.size())
686 return m_iteratorAnnotList[m_iteratorAnnotList.size() - ++m_pos]; 1204 return m_iteratorAnnotList[m_iteratorAnnotList.size() - ++m_pos];
687 return nullptr; 1205 return nullptr;
688 } 1206 }
689 1207
690 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next() { 1208 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next() {
691 return m_bReverse ? PrevAnnot() : NextAnnot(); 1209 return m_bReverse ? PrevAnnot() : NextAnnot();
692 } 1210 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fsdk_actionhandler.cpp ('k') | fpdfsdk/src/fsdk_baseannot.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698