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" |
dsinclair | 5b49309 | 2016-09-29 20:20:24 -0700 | [diff] [blame] | 18 | #include "xfa/fxfa/fxfa_basic.h" |
| 19 | #include "xfa/fxfa/xfa_ffdocview.h" |
| 20 | #include "xfa/fxfa/xfa_ffpageview.h" |
| 21 | #include "xfa/fxfa/xfa_ffwidget.h" |
| 22 | #include "xfa/fxfa/xfa_ffwidgethandler.h" |
dsinclair | 202ad72 | 2016-09-29 17:41:42 -0700 | [diff] [blame] | 23 | #include "xfa/fxgraphics/cfx_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 | |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 56 | CFX_Graphics gs; |
| 57 | gs.Create(pDevice); |
| 58 | |
| 59 | CFX_Matrix mt; |
| 60 | mt = *pUser2Device; |
| 61 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 62 | bool bIsHighlight = false; |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 63 | if (pPageView->GetFormFillEnv()->GetFocusAnnot() != pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 64 | bIsHighlight = true; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 65 | |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 66 | GetXFAWidgetHandler(pAnnot)->RenderWidget(pAnnot->GetXFAWidget(), &gs, &mt, |
| 67 | bIsHighlight); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 68 | |
| 69 | // to do highlight and shadow |
| 70 | } |
| 71 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 72 | void CPDFSDK_XFAWidgetHandler::OnLoad(CPDFSDK_Annot* pAnnot) {} |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 73 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 74 | void CPDFSDK_XFAWidgetHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 75 | CPDFSDK_XFAWidget* pWidget = reinterpret_cast<CPDFSDK_XFAWidget*>(pAnnot); |
| 76 | CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); |
| 77 | pInterForm->RemoveXFAMap(pWidget->GetXFAWidget()); |
| 78 | |
| 79 | delete pWidget; |
| 80 | } |
| 81 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 82 | CFX_FloatRect CPDFSDK_XFAWidgetHandler::GetViewBBox(CPDFSDK_PageView* pPageView, |
| 83 | CPDFSDK_Annot* pAnnot) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 84 | ASSERT(pAnnot); |
| 85 | |
| 86 | CFX_RectF rcBBox; |
| 87 | XFA_Element eType = pAnnot->GetXFAWidget()->GetDataAcc()->GetUIType(); |
| 88 | if (eType == XFA_Element::Signature) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 89 | pAnnot->GetXFAWidget()->GetBBox(rcBBox, XFA_WidgetStatus_Visible, true); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 90 | else |
| 91 | pAnnot->GetXFAWidget()->GetBBox(rcBBox, XFA_WidgetStatus_None); |
| 92 | |
| 93 | CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, |
| 94 | rcBBox.top + rcBBox.height); |
| 95 | rcWidget.left -= 1.0f; |
| 96 | rcWidget.right += 1.0f; |
| 97 | rcWidget.bottom -= 1.0f; |
| 98 | rcWidget.top += 1.0f; |
| 99 | |
| 100 | return rcWidget; |
| 101 | } |
| 102 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 103 | bool CPDFSDK_XFAWidgetHandler::HitTest(CPDFSDK_PageView* pPageView, |
| 104 | CPDFSDK_Annot* pAnnot, |
| 105 | const CFX_FloatPoint& point) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 106 | if (!pPageView || !pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 107 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 108 | |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 109 | CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv(); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 110 | if (!pFormFillEnv) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 111 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 112 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 113 | CPDFXFA_Context* pContext = pFormFillEnv->GetXFAContext(); |
| 114 | if (!pContext) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 115 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 116 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 117 | CXFA_FFDocView* pDocView = pContext->GetXFADocView(); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 118 | if (!pDocView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 119 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 120 | |
| 121 | CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler(); |
| 122 | if (!pWidgetHandler) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 123 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 124 | |
| 125 | FWL_WidgetHit dwHitTest = |
| 126 | pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point.x, point.y); |
| 127 | return dwHitTest != FWL_WidgetHit::Unknown; |
| 128 | } |
| 129 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 130 | void CPDFSDK_XFAWidgetHandler::OnMouseEnter(CPDFSDK_PageView* pPageView, |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 131 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 132 | uint32_t nFlag) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 133 | if (!pPageView || !(*pAnnot)) |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 134 | return; |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 135 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
| 136 | pWidgetHandler->OnMouseEnter((*pAnnot)->GetXFAWidget()); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 137 | } |
| 138 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 139 | void CPDFSDK_XFAWidgetHandler::OnMouseExit(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; |
| 144 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 145 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
| 146 | pWidgetHandler->OnMouseExit((*pAnnot)->GetXFAWidget()); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 147 | } |
| 148 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 149 | bool CPDFSDK_XFAWidgetHandler::OnLButtonDown(CPDFSDK_PageView* pPageView, |
| 150 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 151 | uint32_t nFlags, |
| 152 | const CFX_FloatPoint& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 153 | if (!pPageView || !(*pAnnot)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 154 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 155 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 156 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
| 157 | return pWidgetHandler->OnLButtonDown((*pAnnot)->GetXFAWidget(), |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 158 | GetFWLFlags(nFlags), point.x, point.y); |
| 159 | } |
| 160 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 161 | bool CPDFSDK_XFAWidgetHandler::OnLButtonUp(CPDFSDK_PageView* pPageView, |
| 162 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 163 | uint32_t nFlags, |
| 164 | const CFX_FloatPoint& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 165 | if (!pPageView || !(*pAnnot)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 166 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 167 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 168 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
| 169 | return pWidgetHandler->OnLButtonUp((*pAnnot)->GetXFAWidget(), |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 170 | GetFWLFlags(nFlags), point.x, point.y); |
| 171 | } |
| 172 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 173 | bool CPDFSDK_XFAWidgetHandler::OnLButtonDblClk( |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 174 | CPDFSDK_PageView* pPageView, |
| 175 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 176 | uint32_t nFlags, |
| 177 | const CFX_FloatPoint& point) { |
| 178 | if (!pPageView || !(*pAnnot)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 179 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 180 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 181 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
| 182 | return pWidgetHandler->OnLButtonDblClk((*pAnnot)->GetXFAWidget(), |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 183 | GetFWLFlags(nFlags), point.x, point.y); |
| 184 | } |
| 185 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 186 | bool CPDFSDK_XFAWidgetHandler::OnMouseMove(CPDFSDK_PageView* pPageView, |
| 187 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 188 | uint32_t nFlags, |
| 189 | const CFX_FloatPoint& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 190 | if (!pPageView || !(*pAnnot)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 191 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 192 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 193 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
| 194 | return pWidgetHandler->OnMouseMove((*pAnnot)->GetXFAWidget(), |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 195 | GetFWLFlags(nFlags), point.x, point.y); |
| 196 | } |
| 197 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 198 | bool CPDFSDK_XFAWidgetHandler::OnMouseWheel(CPDFSDK_PageView* pPageView, |
| 199 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 200 | uint32_t nFlags, |
| 201 | short zDelta, |
| 202 | const CFX_FloatPoint& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 203 | if (!pPageView || !(*pAnnot)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 204 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 205 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 206 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 207 | return pWidgetHandler->OnMouseWheel( |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 208 | (*pAnnot)->GetXFAWidget(), GetFWLFlags(nFlags), zDelta, point.x, point.y); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 209 | } |
| 210 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 211 | bool CPDFSDK_XFAWidgetHandler::OnRButtonDown(CPDFSDK_PageView* pPageView, |
| 212 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 213 | uint32_t nFlags, |
| 214 | const CFX_FloatPoint& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 215 | if (!pPageView || !(*pAnnot)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 216 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 217 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 218 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
| 219 | return pWidgetHandler->OnRButtonDown((*pAnnot)->GetXFAWidget(), |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 220 | GetFWLFlags(nFlags), point.x, point.y); |
| 221 | } |
| 222 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 223 | bool CPDFSDK_XFAWidgetHandler::OnRButtonUp(CPDFSDK_PageView* pPageView, |
| 224 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 225 | uint32_t nFlags, |
| 226 | const CFX_FloatPoint& point) { |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 227 | if (!pPageView || !(*pAnnot)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 228 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 229 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 230 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
| 231 | return pWidgetHandler->OnRButtonUp((*pAnnot)->GetXFAWidget(), |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 232 | GetFWLFlags(nFlags), point.x, point.y); |
| 233 | } |
| 234 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 235 | bool CPDFSDK_XFAWidgetHandler::OnRButtonDblClk( |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 236 | CPDFSDK_PageView* pPageView, |
| 237 | CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 238 | uint32_t nFlags, |
| 239 | const CFX_FloatPoint& point) { |
| 240 | if (!pPageView || !(*pAnnot)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 241 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 242 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 243 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get()); |
| 244 | return pWidgetHandler->OnRButtonDblClk((*pAnnot)->GetXFAWidget(), |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 245 | GetFWLFlags(nFlags), point.x, point.y); |
| 246 | } |
| 247 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 248 | bool CPDFSDK_XFAWidgetHandler::OnChar(CPDFSDK_Annot* pAnnot, |
| 249 | uint32_t nChar, |
| 250 | uint32_t nFlags) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 251 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 252 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 253 | |
| 254 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 255 | return pWidgetHandler->OnChar(pAnnot->GetXFAWidget(), nChar, |
| 256 | GetFWLFlags(nFlags)); |
| 257 | } |
| 258 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 259 | bool CPDFSDK_XFAWidgetHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, |
| 260 | int nKeyCode, |
| 261 | int nFlag) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 262 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 263 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 264 | |
| 265 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 266 | return pWidgetHandler->OnKeyDown(pAnnot->GetXFAWidget(), nKeyCode, |
| 267 | GetFWLFlags(nFlag)); |
| 268 | } |
| 269 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 270 | bool CPDFSDK_XFAWidgetHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, |
| 271 | int nKeyCode, |
| 272 | int nFlag) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 273 | if (!pAnnot) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 274 | return false; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 275 | |
| 276 | CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 277 | return pWidgetHandler->OnKeyUp(pAnnot->GetXFAWidget(), nKeyCode, |
| 278 | GetFWLFlags(nFlag)); |
| 279 | } |
| 280 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 281 | bool CPDFSDK_XFAWidgetHandler::OnSetFocus(CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 282 | uint32_t nFlag) { |
| 283 | return true; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 284 | } |
| 285 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 286 | bool CPDFSDK_XFAWidgetHandler::OnKillFocus(CPDFSDK_Annot::ObservedPtr* pAnnot, |
| 287 | uint32_t nFlag) { |
| 288 | return true; |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 289 | } |
| 290 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 291 | bool CPDFSDK_XFAWidgetHandler::OnXFAChangedFocus( |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 292 | CPDFSDK_Annot::ObservedPtr* pOldAnnot, |
| 293 | CPDFSDK_Annot::ObservedPtr* pNewAnnot) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 294 | CXFA_FFWidgetHandler* pWidgetHandler = nullptr; |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 295 | if (*pOldAnnot) |
| 296 | pWidgetHandler = GetXFAWidgetHandler(pOldAnnot->Get()); |
| 297 | else if (*pNewAnnot) |
| 298 | pWidgetHandler = GetXFAWidgetHandler(pNewAnnot->Get()); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 299 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 300 | if (!pWidgetHandler) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 301 | return true; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 302 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 303 | CXFA_FFWidget* hWidget = *pNewAnnot ? (*pNewAnnot)->GetXFAWidget() : nullptr; |
| 304 | if (!hWidget) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 305 | return true; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 306 | |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 307 | CXFA_FFPageView* pXFAPageView = hWidget->GetPageView(); |
| 308 | if (!pXFAPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 309 | return true; |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 310 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 311 | bool bRet = pXFAPageView->GetDocView()->SetFocus(hWidget); |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 312 | if (pXFAPageView->GetDocView()->GetFocusWidget() == hWidget) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 313 | bRet = true; |
tsepez | f8074ce | 2016-09-27 14:29:57 -0700 | [diff] [blame] | 314 | |
| 315 | return bRet; |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 316 | } |
| 317 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 318 | CXFA_FFWidgetHandler* CPDFSDK_XFAWidgetHandler::GetXFAWidgetHandler( |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 319 | CPDFSDK_Annot* pAnnot) { |
| 320 | if (!pAnnot) |
| 321 | return nullptr; |
| 322 | |
| 323 | CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); |
| 324 | if (!pPageView) |
| 325 | return nullptr; |
| 326 | |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 327 | CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv(); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 328 | if (!pFormFillEnv) |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 329 | return nullptr; |
| 330 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 331 | CPDFXFA_Context* pDoc = pFormFillEnv->GetXFAContext(); |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 332 | if (!pDoc) |
| 333 | return nullptr; |
| 334 | |
| 335 | CXFA_FFDocView* pDocView = pDoc->GetXFADocView(); |
| 336 | if (!pDocView) |
| 337 | return nullptr; |
| 338 | |
| 339 | return pDocView->GetWidgetHandler(); |
| 340 | } |
| 341 | |
jaepark | 8c54182 | 2016-08-30 13:43:05 -0700 | [diff] [blame] | 342 | uint32_t CPDFSDK_XFAWidgetHandler::GetFWLFlags(uint32_t dwFlag) { |
jaepark | 98e1019 | 2016-08-15 10:51:11 -0700 | [diff] [blame] | 343 | uint32_t dwFWLFlag = 0; |
| 344 | |
| 345 | if (dwFlag & FWL_EVENTFLAG_ControlKey) |
| 346 | dwFWLFlag |= FWL_KEYFLAG_Ctrl; |
| 347 | if (dwFlag & FWL_EVENTFLAG_LeftButtonDown) |
| 348 | dwFWLFlag |= FWL_KEYFLAG_LButton; |
| 349 | if (dwFlag & FWL_EVENTFLAG_MiddleButtonDown) |
| 350 | dwFWLFlag |= FWL_KEYFLAG_MButton; |
| 351 | if (dwFlag & FWL_EVENTFLAG_RightButtonDown) |
| 352 | dwFWLFlag |= FWL_KEYFLAG_RButton; |
| 353 | if (dwFlag & FWL_EVENTFLAG_ShiftKey) |
| 354 | dwFWLFlag |= FWL_KEYFLAG_Shift; |
| 355 | if (dwFlag & FWL_EVENTFLAG_AltKey) |
| 356 | dwFWLFlag |= FWL_KEYFLAG_Alt; |
| 357 | |
| 358 | return dwFWLFlag; |
| 359 | } |