jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 1 | // Copyright 2016 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 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 7 | #include "fpdfsdk/cpdfsdk_xfawidgethandler.h" |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 8 | |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 9 | #include "core/fpdfdoc/cpdf_interform.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 10 | #include "fpdfsdk/cpdfsdk_annot.h" |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 11 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 12 | #include "fpdfsdk/cpdfsdk_interform.h" |
| 13 | #include "fpdfsdk/cpdfsdk_pageview.h" |
| 14 | #include "fpdfsdk/cpdfsdk_xfawidget.h" |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 15 | #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 16 | #include "xfa/fwl/cfwl_app.h" |
| 17 | #include "xfa/fwl/fwl_widgethit.h" |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 18 | #include "xfa/fxfa/cxfa_ffdocview.h" |
| 19 | #include "xfa/fxfa/cxfa_ffpageview.h" |
| 20 | #include "xfa/fxfa/cxfa_ffwidget.h" |
| 21 | #include "xfa/fxfa/cxfa_ffwidgethandler.h" |
dsinclair | 5b49309 | 2016-09-29 20:20:24 -0700 | [diff] [blame] | 22 | #include "xfa/fxfa/fxfa_basic.h" |
Dan Sinclair | 2b918c8 | 2017-07-13 14:47:10 -0400 | [diff] [blame] | 23 | #include "xfa/fxgraphics/cxfa_graphics.h" |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 24 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 25 | CPDFSDK_XFAWidgetHandler::CPDFSDK_XFAWidgetHandler( |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 26 | CPDFSDK_FormFillEnvironment* pFormFillEnv) |
| 27 | : m_pFormFillEnv(pFormFillEnv) {} |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 28 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 29 | CPDFSDK_XFAWidgetHandler::~CPDFSDK_XFAWidgetHandler() {} |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 30 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 31 | bool CPDFSDK_XFAWidgetHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 32 | return !!pAnnot->GetXFAWidget(); |
| 33 | } |
| 34 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 35 | CPDFSDK_Annot* CPDFSDK_XFAWidgetHandler::NewAnnot(CPDF_Annot* pAnnot, |
| 36 | CPDFSDK_PageView* pPage) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 37 | return nullptr; |
| 38 | } |
| 39 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 40 | CPDFSDK_Annot* CPDFSDK_XFAWidgetHandler::NewAnnot(CXFA_FFWidget* pAnnot, |
| 41 | CPDFSDK_PageView* pPage) { |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 42 | CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 43 | CPDFSDK_XFAWidget* pWidget = new CPDFSDK_XFAWidget(pAnnot, pPage, pInterForm); |
| 44 | pInterForm->AddXFAMap(pAnnot, pWidget); |
| 45 | return pWidget; |
| 46 | } |
| 47 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 48 | void CPDFSDK_XFAWidgetHandler::OnDraw(CPDFSDK_PageView* pPageView, |
| 49 | CPDFSDK_Annot* pAnnot, |
| 50 | CFX_RenderDevice* pDevice, |
jaepark | 75f84a5 | 2016-09-09 15:39:09 -0700 | [diff] [blame] | 51 | CFX_Matrix* pUser2Device, |
| 52 | bool bDrawAnnots) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 53 | ASSERT(pPageView); |
| 54 | ASSERT(pAnnot); |
| 55 | |
Dan Sinclair | 2b918c8 | 2017-07-13 14:47:10 -0400 | [diff] [blame] | 56 | CXFA_Graphics gs(pDevice); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 57 | |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 58 | CFX_Matrix mt = *pUser2Device; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 59 | bool bIsHighlight = false; |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 60 | if (pPageView->GetFormFillEnv()->GetFocusAnnot() != pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 61 | bIsHighlight = true; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 62 | |
Lei Zhang | 7c9d4c2 | 2017-08-17 13:53:52 -0700 | [diff] [blame^] | 63 | GetXFAWidgetHandler(pAnnot)->RenderWidget(pAnnot->GetXFAWidget(), &gs, mt, |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 64 | bIsHighlight); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 65 | |
| 66 | // to do highlight and shadow |
| 67 | } |
| 68 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 69 | void CPDFSDK_XFAWidgetHandler::OnLoad(CPDFSDK_Annot* pAnnot) {} |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 70 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 71 | void CPDFSDK_XFAWidgetHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 72 | CPDFSDK_XFAWidget* pWidget = reinterpret_cast<CPDFSDK_XFAWidget*>(pAnnot); |
| 73 | CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); |
| 74 | pInterForm->RemoveXFAMap(pWidget->GetXFAWidget()); |
| 75 | |
| 76 | delete pWidget; |
| 77 | } |
| 78 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 79 | CFX_FloatRect CPDFSDK_XFAWidgetHandler::GetViewBBox(CPDFSDK_PageView* pPageView, |
| 80 | CPDFSDK_Annot* pAnnot) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 81 | ASSERT(pAnnot); |
| 82 | |
| 83 | CFX_RectF rcBBox; |
| 84 | XFA_Element eType = pAnnot->GetXFAWidget()->GetDataAcc()->GetUIType(); |
| 85 | if (eType == XFA_Element::Signature) |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 86 | rcBBox = pAnnot->GetXFAWidget()->GetBBox(XFA_WidgetStatus_Visible, true); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 87 | else |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 88 | rcBBox = pAnnot->GetXFAWidget()->GetBBox(XFA_WidgetStatus_None); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 89 | |
| 90 | CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, |
| 91 | rcBBox.top + rcBBox.height); |
| 92 | rcWidget.left -= 1.0f; |
| 93 | rcWidget.right += 1.0f; |
| 94 | rcWidget.bottom -= 1.0f; |
| 95 | rcWidget.top += 1.0f; |
| 96 | |
| 97 | return rcWidget; |
| 98 | } |
| 99 | |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 100 | // TODO(bug 840): Implement so selected text can be obtained from XFA |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 101 | // fields. |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 102 | CFX_WideString CPDFSDK_XFAWidgetHandler::GetSelectedText( |
| 103 | CPDFSDK_Annot* pAnnot) { |
| 104 | return CFX_WideString(); |
| 105 | } |
| 106 | |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 107 | // TODO(bug 840): Implement so text can be inserted into and deleted from XFA |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 108 | // fields. |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 109 | void CPDFSDK_XFAWidgetHandler::ReplaceSelection(CPDFSDK_Annot* pAnnot, |
| 110 | const CFX_WideString& text) {} |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 111 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 112 | bool CPDFSDK_XFAWidgetHandler::HitTest(CPDFSDK_PageView* pPageView, |
| 113 | CPDFSDK_Annot* pAnnot, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 114 | const CFX_PointF& point) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 115 | if (!pPageView || !pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 116 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 117 | |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 118 | CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv(); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 119 | if (!pFormFillEnv) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 120 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 121 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 122 | CPDFXFA_Context* pContext = pFormFillEnv->GetXFAContext(); |
| 123 | if (!pContext) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 124 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 125 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 126 | CXFA_FFDocView* pDocView = pContext->GetXFADocView(); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 127 | if (!pDocView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 128 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 129 | |
| 130 | CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler(); |
| 131 | if (!pWidgetHandler) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 132 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 133 | |
| 134 | FWL_WidgetHit dwHitTest = |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 135 | pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 136 | return dwHitTest != FWL_WidgetHit::Unknown; |
| 137 | } |
| 138 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 139 | void CPDFSDK_XFAWidgetHandler::OnMouseEnter(CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 140 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 141 | uint32_t nFlag) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 142 | if (!pPageView || !(*pAnnot)) |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 143 | return; |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 144 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
| 145 | pWidgetHandler->OnMouseEnter((*pAnnot)->GetXFAWidget()); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 146 | } |
| 147 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 148 | void CPDFSDK_XFAWidgetHandler::OnMouseExit(CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 149 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 150 | uint32_t nFlag) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 151 | if (!pPageView || !(*pAnnot)) |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 152 | return; |
| 153 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 154 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
| 155 | pWidgetHandler->OnMouseExit((*pAnnot)->GetXFAWidget()); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 156 | } |
| 157 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 158 | bool CPDFSDK_XFAWidgetHandler::OnLButtonDown(CPDFSDK_PageView* pPageView, |
| 159 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 160 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 161 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 162 | if (!pPageView || !(*pAnnot)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 163 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 164 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 165 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
| 166 | return pWidgetHandler->OnLButtonDown((*pAnnot)->GetXFAWidget(), |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 167 | GetFWLFlags(nFlags), point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 168 | } |
| 169 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 170 | bool CPDFSDK_XFAWidgetHandler::OnLButtonUp(CPDFSDK_PageView* pPageView, |
| 171 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 172 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 173 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 174 | if (!pPageView || !(*pAnnot)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 175 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 176 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 177 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
| 178 | return pWidgetHandler->OnLButtonUp((*pAnnot)->GetXFAWidget(), |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 179 | GetFWLFlags(nFlags), point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 180 | } |
| 181 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 182 | bool CPDFSDK_XFAWidgetHandler::OnLButtonDblClk( |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 183 | CPDFSDK_PageView* pPageView, |
| 184 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 185 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 186 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 187 | if (!pPageView || !(*pAnnot)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 188 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 189 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 190 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
| 191 | return pWidgetHandler->OnLButtonDblClk((*pAnnot)->GetXFAWidget(), |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 192 | GetFWLFlags(nFlags), point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 193 | } |
| 194 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 195 | bool CPDFSDK_XFAWidgetHandler::OnMouseMove(CPDFSDK_PageView* pPageView, |
| 196 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 197 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 198 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 199 | if (!pPageView || !(*pAnnot)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 200 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 201 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 202 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
| 203 | return pWidgetHandler->OnMouseMove((*pAnnot)->GetXFAWidget(), |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 204 | GetFWLFlags(nFlags), point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 205 | } |
| 206 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 207 | bool CPDFSDK_XFAWidgetHandler::OnMouseWheel(CPDFSDK_PageView* pPageView, |
| 208 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 209 | uint32_t nFlags, |
| 210 | short zDelta, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 211 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 212 | if (!pPageView || !(*pAnnot)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 213 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 214 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 215 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 216 | return pWidgetHandler->OnMouseWheel((*pAnnot)->GetXFAWidget(), |
| 217 | GetFWLFlags(nFlags), zDelta, point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 218 | } |
| 219 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 220 | bool CPDFSDK_XFAWidgetHandler::OnRButtonDown(CPDFSDK_PageView* pPageView, |
| 221 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 222 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 223 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 224 | if (!pPageView || !(*pAnnot)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 225 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 226 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 227 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
| 228 | return pWidgetHandler->OnRButtonDown((*pAnnot)->GetXFAWidget(), |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 229 | GetFWLFlags(nFlags), point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 230 | } |
| 231 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 232 | bool CPDFSDK_XFAWidgetHandler::OnRButtonUp(CPDFSDK_PageView* pPageView, |
| 233 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 234 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 235 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 236 | if (!pPageView || !(*pAnnot)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 237 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 238 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 239 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
| 240 | return pWidgetHandler->OnRButtonUp((*pAnnot)->GetXFAWidget(), |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 241 | GetFWLFlags(nFlags), point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 242 | } |
| 243 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 244 | bool CPDFSDK_XFAWidgetHandler::OnRButtonDblClk( |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 245 | CPDFSDK_PageView* pPageView, |
| 246 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 247 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 248 | const CFX_PointF& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 249 | if (!pPageView || !(*pAnnot)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 250 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 251 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 252 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
| 253 | return pWidgetHandler->OnRButtonDblClk((*pAnnot)->GetXFAWidget(), |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 254 | GetFWLFlags(nFlags), point); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 255 | } |
| 256 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 257 | bool CPDFSDK_XFAWidgetHandler::OnChar(CPDFSDK_Annot* pAnnot, |
| 258 | uint32_t nChar, |
| 259 | uint32_t nFlags) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 260 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 261 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 262 | |
| 263 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 264 | return pWidgetHandler->OnChar(pAnnot->GetXFAWidget(), nChar, |
| 265 | GetFWLFlags(nFlags)); |
| 266 | } |
| 267 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 268 | bool CPDFSDK_XFAWidgetHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, |
| 269 | int nKeyCode, |
| 270 | int nFlag) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 271 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 272 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 273 | |
| 274 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 275 | return pWidgetHandler->OnKeyDown(pAnnot->GetXFAWidget(), nKeyCode, |
| 276 | GetFWLFlags(nFlag)); |
| 277 | } |
| 278 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 279 | bool CPDFSDK_XFAWidgetHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, |
| 280 | int nKeyCode, |
| 281 | int nFlag) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 282 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 283 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 284 | |
| 285 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 286 | return pWidgetHandler->OnKeyUp(pAnnot->GetXFAWidget(), nKeyCode, |
| 287 | GetFWLFlags(nFlag)); |
| 288 | } |
| 289 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 290 | bool CPDFSDK_XFAWidgetHandler::OnSetFocus(CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 291 | uint32_t nFlag) { |
| 292 | return true; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 293 | } |
| 294 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 295 | bool CPDFSDK_XFAWidgetHandler::OnKillFocus(CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 296 | uint32_t nFlag) { |
| 297 | return true; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 298 | } |
| 299 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 300 | bool CPDFSDK_XFAWidgetHandler::OnXFAChangedFocus( |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 301 | CPDFSDK_Annot::ObservedPtr* pOldAnnot, |
| 302 | CPDFSDK_Annot::ObservedPtr* pNewAnnot) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 303 | CXFA_FFWidgetHandler* pWidgetHandler = nullptr; |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 304 | if (*pOldAnnot) |
| 305 | pWidgetHandler = GetXFAWidgetHandler(pOldAnnot->Get()); |
| 306 | else if (*pNewAnnot) |
| 307 | pWidgetHandler = GetXFAWidgetHandler(pNewAnnot->Get()); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 308 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 309 | if (!pWidgetHandler) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 310 | return true; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 311 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 312 | CXFA_FFWidget* hWidget = *pNewAnnot ? (*pNewAnnot)->GetXFAWidget() : nullptr; |
| 313 | if (!hWidget) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 314 | return true; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 315 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 316 | CXFA_FFPageView* pXFAPageView = hWidget->GetPageView(); |
| 317 | if (!pXFAPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 318 | return true; |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 319 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 320 | bool bRet = pXFAPageView->GetDocView()->SetFocus(hWidget); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 321 | if (pXFAPageView->GetDocView()->GetFocusWidget() == hWidget) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 322 | bRet = true; |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 323 | |
| 324 | return bRet; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 325 | } |
| 326 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 327 | CXFA_FFWidgetHandler* CPDFSDK_XFAWidgetHandler::GetXFAWidgetHandler( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 328 | CPDFSDK_Annot* pAnnot) { |
| 329 | if (!pAnnot) |
| 330 | return nullptr; |
| 331 | |
| 332 | CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); |
| 333 | if (!pPageView) |
| 334 | return nullptr; |
| 335 | |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 336 | CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv(); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 337 | if (!pFormFillEnv) |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 338 | return nullptr; |
| 339 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 340 | CPDFXFA_Context* pDoc = pFormFillEnv->GetXFAContext(); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 341 | if (!pDoc) |
| 342 | return nullptr; |
| 343 | |
| 344 | CXFA_FFDocView* pDocView = pDoc->GetXFADocView(); |
| 345 | if (!pDocView) |
| 346 | return nullptr; |
| 347 | |
| 348 | return pDocView->GetWidgetHandler(); |
| 349 | } |
| 350 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 351 | uint32_t CPDFSDK_XFAWidgetHandler::GetFWLFlags(uint32_t dwFlag) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 352 | uint32_t dwFWLFlag = 0; |
| 353 | |
| 354 | if (dwFlag & FWL_EVENTFLAG_ControlKey) |
| 355 | dwFWLFlag |= FWL_KEYFLAG_Ctrl; |
| 356 | if (dwFlag & FWL_EVENTFLAG_LeftButtonDown) |
| 357 | dwFWLFlag |= FWL_KEYFLAG_LButton; |
| 358 | if (dwFlag & FWL_EVENTFLAG_MiddleButtonDown) |
| 359 | dwFWLFlag |= FWL_KEYFLAG_MButton; |
| 360 | if (dwFlag & FWL_EVENTFLAG_RightButtonDown) |
| 361 | dwFWLFlag |= FWL_KEYFLAG_RButton; |
| 362 | if (dwFlag & FWL_EVENTFLAG_ShiftKey) |
| 363 | dwFWLFlag |= FWL_KEYFLAG_Shift; |
| 364 | if (dwFlag & FWL_EVENTFLAG_AltKey) |
| 365 | dwFWLFlag |= FWL_KEYFLAG_Alt; |
| 366 | |
| 367 | return dwFWLFlag; |
| 368 | } |