blob: c1ef2bdb23dee01aa3edfc710a593b7761dc432e [file] [log] [blame]
jaepark98e10192016-08-15 10:51:11 -07001// 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
dsinclair114e46a2016-09-29 17:18:21 -07007#include "fpdfsdk/cpdfsdk_xfawidgethandler.h"
jaepark98e10192016-08-15 10:51:11 -07008
dsinclair1727aee2016-09-29 13:12:56 -07009#include "core/fpdfdoc/cpdf_interform.h"
dsinclair114e46a2016-09-29 17:18:21 -070010#include "fpdfsdk/cpdfsdk_annot.h"
dsinclair735606d2016-10-05 15:47:02 -070011#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
dsinclair114e46a2016-09-29 17:18:21 -070012#include "fpdfsdk/cpdfsdk_interform.h"
13#include "fpdfsdk/cpdfsdk_pageview.h"
14#include "fpdfsdk/cpdfsdk_xfawidget.h"
dsinclair521b7502016-11-02 13:02:28 -070015#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
dsinclair447b1f32016-12-08 10:06:32 -080016#include "xfa/fwl/cfwl_app.h"
17#include "xfa/fwl/fwl_widgethit.h"
Dan Sinclair80c48782017-03-23 12:11:20 -040018#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"
dsinclair5b493092016-09-29 20:20:24 -070022#include "xfa/fxfa/fxfa_basic.h"
Dan Sinclair2b918c82017-07-13 14:47:10 -040023#include "xfa/fxgraphics/cxfa_graphics.h"
jaepark98e10192016-08-15 10:51:11 -070024
dsinclair735606d2016-10-05 15:47:02 -070025CPDFSDK_XFAWidgetHandler::CPDFSDK_XFAWidgetHandler(
dsinclair8779fa82016-10-12 12:05:44 -070026 CPDFSDK_FormFillEnvironment* pFormFillEnv)
27 : m_pFormFillEnv(pFormFillEnv) {}
jaepark98e10192016-08-15 10:51:11 -070028
jaepark8c541822016-08-30 13:43:05 -070029CPDFSDK_XFAWidgetHandler::~CPDFSDK_XFAWidgetHandler() {}
jaepark98e10192016-08-15 10:51:11 -070030
tsepez4cf55152016-11-02 14:37:54 -070031bool CPDFSDK_XFAWidgetHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
jaepark98e10192016-08-15 10:51:11 -070032 return !!pAnnot->GetXFAWidget();
33}
34
jaepark8c541822016-08-30 13:43:05 -070035CPDFSDK_Annot* CPDFSDK_XFAWidgetHandler::NewAnnot(CPDF_Annot* pAnnot,
36 CPDFSDK_PageView* pPage) {
jaepark98e10192016-08-15 10:51:11 -070037 return nullptr;
38}
39
jaepark8c541822016-08-30 13:43:05 -070040CPDFSDK_Annot* CPDFSDK_XFAWidgetHandler::NewAnnot(CXFA_FFWidget* pAnnot,
41 CPDFSDK_PageView* pPage) {
dsinclair8779fa82016-10-12 12:05:44 -070042 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
jaepark98e10192016-08-15 10:51:11 -070043 CPDFSDK_XFAWidget* pWidget = new CPDFSDK_XFAWidget(pAnnot, pPage, pInterForm);
44 pInterForm->AddXFAMap(pAnnot, pWidget);
45 return pWidget;
46}
47
jaepark8c541822016-08-30 13:43:05 -070048void CPDFSDK_XFAWidgetHandler::OnDraw(CPDFSDK_PageView* pPageView,
49 CPDFSDK_Annot* pAnnot,
50 CFX_RenderDevice* pDevice,
jaepark75f84a52016-09-09 15:39:09 -070051 CFX_Matrix* pUser2Device,
52 bool bDrawAnnots) {
jaepark98e10192016-08-15 10:51:11 -070053 ASSERT(pPageView);
54 ASSERT(pAnnot);
55
Dan Sinclair2b918c82017-07-13 14:47:10 -040056 CXFA_Graphics gs(pDevice);
jaepark98e10192016-08-15 10:51:11 -070057
Dan Sinclairbba2a7c2017-02-07 16:36:39 -050058 CFX_Matrix mt = *pUser2Device;
tsepez4cf55152016-11-02 14:37:54 -070059 bool bIsHighlight = false;
dsinclair7cbe68e2016-10-12 11:56:23 -070060 if (pPageView->GetFormFillEnv()->GetFocusAnnot() != pAnnot)
tsepez4cf55152016-11-02 14:37:54 -070061 bIsHighlight = true;
jaepark98e10192016-08-15 10:51:11 -070062
Lei Zhang7c9d4c22017-08-17 13:53:52 -070063 GetXFAWidgetHandler(pAnnot)->RenderWidget(pAnnot->GetXFAWidget(), &gs, mt,
dsinclairb402b172016-10-11 09:26:32 -070064 bIsHighlight);
jaepark98e10192016-08-15 10:51:11 -070065
66 // to do highlight and shadow
67}
68
jaepark8c541822016-08-30 13:43:05 -070069void CPDFSDK_XFAWidgetHandler::OnLoad(CPDFSDK_Annot* pAnnot) {}
jaepark98e10192016-08-15 10:51:11 -070070
jaepark8c541822016-08-30 13:43:05 -070071void CPDFSDK_XFAWidgetHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
jaepark98e10192016-08-15 10:51:11 -070072 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
jaepark8c541822016-08-30 13:43:05 -070079CFX_FloatRect CPDFSDK_XFAWidgetHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
80 CPDFSDK_Annot* pAnnot) {
jaepark98e10192016-08-15 10:51:11 -070081 ASSERT(pAnnot);
82
83 CFX_RectF rcBBox;
84 XFA_Element eType = pAnnot->GetXFAWidget()->GetDataAcc()->GetUIType();
85 if (eType == XFA_Element::Signature)
Dan Sinclair1b08df12017-02-09 09:17:20 -050086 rcBBox = pAnnot->GetXFAWidget()->GetBBox(XFA_WidgetStatus_Visible, true);
jaepark98e10192016-08-15 10:51:11 -070087 else
Dan Sinclair1b08df12017-02-09 09:17:20 -050088 rcBBox = pAnnot->GetXFAWidget()->GetBBox(XFA_WidgetStatus_None);
jaepark98e10192016-08-15 10:51:11 -070089
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
Ryan Harrison275e2602017-09-18 14:23:18 -0400100WideString CPDFSDK_XFAWidgetHandler::GetSelectedText(CPDFSDK_Annot* pAnnot) {
Dan Sinclairb8777a22017-09-20 16:21:31 -0400101 if (!pAnnot)
102 return WideString();
103
104 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
105 return pWidgetHandler->GetSelectedText(pAnnot->GetXFAWidget());
Diana Gagedce2d722017-06-20 11:17:11 -0700106}
107
Diana Gageab390972017-07-28 17:07:39 -0700108void CPDFSDK_XFAWidgetHandler::ReplaceSelection(CPDFSDK_Annot* pAnnot,
Dan Sinclairb8777a22017-09-20 16:21:31 -0400109 const WideString& text) {
110 if (!pAnnot)
111 return;
112
113 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
114 return pWidgetHandler->PasteText(pAnnot->GetXFAWidget(), text);
115}
Diana Gage1c7f1422017-07-24 11:19:52 -0700116
tsepez4cf55152016-11-02 14:37:54 -0700117bool CPDFSDK_XFAWidgetHandler::HitTest(CPDFSDK_PageView* pPageView,
118 CPDFSDK_Annot* pAnnot,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500119 const CFX_PointF& point) {
jaepark98e10192016-08-15 10:51:11 -0700120 if (!pPageView || !pAnnot)
tsepez4cf55152016-11-02 14:37:54 -0700121 return false;
jaepark98e10192016-08-15 10:51:11 -0700122
dsinclairb402b172016-10-11 09:26:32 -0700123 CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv();
dsinclair7cbe68e2016-10-12 11:56:23 -0700124 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700125 return false;
jaepark98e10192016-08-15 10:51:11 -0700126
dsinclair521b7502016-11-02 13:02:28 -0700127 CPDFXFA_Context* pContext = pFormFillEnv->GetXFAContext();
128 if (!pContext)
tsepez4cf55152016-11-02 14:37:54 -0700129 return false;
jaepark98e10192016-08-15 10:51:11 -0700130
dsinclair521b7502016-11-02 13:02:28 -0700131 CXFA_FFDocView* pDocView = pContext->GetXFADocView();
jaepark98e10192016-08-15 10:51:11 -0700132 if (!pDocView)
tsepez4cf55152016-11-02 14:37:54 -0700133 return false;
jaepark98e10192016-08-15 10:51:11 -0700134
135 CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
136 if (!pWidgetHandler)
tsepez4cf55152016-11-02 14:37:54 -0700137 return false;
jaepark98e10192016-08-15 10:51:11 -0700138
139 FWL_WidgetHit dwHitTest =
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500140 pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point);
jaepark98e10192016-08-15 10:51:11 -0700141 return dwHitTest != FWL_WidgetHit::Unknown;
142}
143
jaepark8c541822016-08-30 13:43:05 -0700144void CPDFSDK_XFAWidgetHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700145 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark8c541822016-08-30 13:43:05 -0700146 uint32_t nFlag) {
tsepezf8074ce2016-09-27 14:29:57 -0700147 if (!pPageView || !(*pAnnot))
jaepark98e10192016-08-15 10:51:11 -0700148 return;
tsepezf8074ce2016-09-27 14:29:57 -0700149 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
150 pWidgetHandler->OnMouseEnter((*pAnnot)->GetXFAWidget());
jaepark98e10192016-08-15 10:51:11 -0700151}
152
jaepark8c541822016-08-30 13:43:05 -0700153void CPDFSDK_XFAWidgetHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700154 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark8c541822016-08-30 13:43:05 -0700155 uint32_t nFlag) {
tsepezf8074ce2016-09-27 14:29:57 -0700156 if (!pPageView || !(*pAnnot))
jaepark98e10192016-08-15 10:51:11 -0700157 return;
158
tsepezf8074ce2016-09-27 14:29:57 -0700159 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
160 pWidgetHandler->OnMouseExit((*pAnnot)->GetXFAWidget());
jaepark98e10192016-08-15 10:51:11 -0700161}
162
tsepez4cf55152016-11-02 14:37:54 -0700163bool CPDFSDK_XFAWidgetHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
164 CPDFSDK_Annot::ObservedPtr* pAnnot,
165 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500166 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700167 if (!pPageView || !(*pAnnot))
tsepez4cf55152016-11-02 14:37:54 -0700168 return false;
jaepark98e10192016-08-15 10:51:11 -0700169
tsepezf8074ce2016-09-27 14:29:57 -0700170 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
171 return pWidgetHandler->OnLButtonDown((*pAnnot)->GetXFAWidget(),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500172 GetFWLFlags(nFlags), point);
jaepark98e10192016-08-15 10:51:11 -0700173}
174
tsepez4cf55152016-11-02 14:37:54 -0700175bool CPDFSDK_XFAWidgetHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
176 CPDFSDK_Annot::ObservedPtr* pAnnot,
177 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500178 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700179 if (!pPageView || !(*pAnnot))
tsepez4cf55152016-11-02 14:37:54 -0700180 return false;
jaepark98e10192016-08-15 10:51:11 -0700181
tsepezf8074ce2016-09-27 14:29:57 -0700182 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
183 return pWidgetHandler->OnLButtonUp((*pAnnot)->GetXFAWidget(),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500184 GetFWLFlags(nFlags), point);
jaepark98e10192016-08-15 10:51:11 -0700185}
186
tsepez4cf55152016-11-02 14:37:54 -0700187bool CPDFSDK_XFAWidgetHandler::OnLButtonDblClk(
tsepezf8074ce2016-09-27 14:29:57 -0700188 CPDFSDK_PageView* pPageView,
189 CPDFSDK_Annot::ObservedPtr* pAnnot,
190 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500191 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700192 if (!pPageView || !(*pAnnot))
tsepez4cf55152016-11-02 14:37:54 -0700193 return false;
jaepark98e10192016-08-15 10:51:11 -0700194
tsepezf8074ce2016-09-27 14:29:57 -0700195 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
196 return pWidgetHandler->OnLButtonDblClk((*pAnnot)->GetXFAWidget(),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500197 GetFWLFlags(nFlags), point);
jaepark98e10192016-08-15 10:51:11 -0700198}
199
tsepez4cf55152016-11-02 14:37:54 -0700200bool CPDFSDK_XFAWidgetHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
201 CPDFSDK_Annot::ObservedPtr* pAnnot,
202 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500203 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700204 if (!pPageView || !(*pAnnot))
tsepez4cf55152016-11-02 14:37:54 -0700205 return false;
jaepark98e10192016-08-15 10:51:11 -0700206
tsepezf8074ce2016-09-27 14:29:57 -0700207 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
208 return pWidgetHandler->OnMouseMove((*pAnnot)->GetXFAWidget(),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500209 GetFWLFlags(nFlags), point);
jaepark98e10192016-08-15 10:51:11 -0700210}
211
tsepez4cf55152016-11-02 14:37:54 -0700212bool CPDFSDK_XFAWidgetHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
213 CPDFSDK_Annot::ObservedPtr* pAnnot,
214 uint32_t nFlags,
215 short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500216 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700217 if (!pPageView || !(*pAnnot))
tsepez4cf55152016-11-02 14:37:54 -0700218 return false;
jaepark98e10192016-08-15 10:51:11 -0700219
tsepezf8074ce2016-09-27 14:29:57 -0700220 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500221 return pWidgetHandler->OnMouseWheel((*pAnnot)->GetXFAWidget(),
222 GetFWLFlags(nFlags), zDelta, point);
jaepark98e10192016-08-15 10:51:11 -0700223}
224
tsepez4cf55152016-11-02 14:37:54 -0700225bool CPDFSDK_XFAWidgetHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
226 CPDFSDK_Annot::ObservedPtr* pAnnot,
227 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500228 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700229 if (!pPageView || !(*pAnnot))
tsepez4cf55152016-11-02 14:37:54 -0700230 return false;
jaepark98e10192016-08-15 10:51:11 -0700231
tsepezf8074ce2016-09-27 14:29:57 -0700232 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
233 return pWidgetHandler->OnRButtonDown((*pAnnot)->GetXFAWidget(),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500234 GetFWLFlags(nFlags), point);
jaepark98e10192016-08-15 10:51:11 -0700235}
236
tsepez4cf55152016-11-02 14:37:54 -0700237bool CPDFSDK_XFAWidgetHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
238 CPDFSDK_Annot::ObservedPtr* pAnnot,
239 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500240 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700241 if (!pPageView || !(*pAnnot))
tsepez4cf55152016-11-02 14:37:54 -0700242 return false;
jaepark98e10192016-08-15 10:51:11 -0700243
tsepezf8074ce2016-09-27 14:29:57 -0700244 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
245 return pWidgetHandler->OnRButtonUp((*pAnnot)->GetXFAWidget(),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500246 GetFWLFlags(nFlags), point);
jaepark98e10192016-08-15 10:51:11 -0700247}
248
tsepez4cf55152016-11-02 14:37:54 -0700249bool CPDFSDK_XFAWidgetHandler::OnRButtonDblClk(
tsepezf8074ce2016-09-27 14:29:57 -0700250 CPDFSDK_PageView* pPageView,
251 CPDFSDK_Annot::ObservedPtr* pAnnot,
252 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500253 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700254 if (!pPageView || !(*pAnnot))
tsepez4cf55152016-11-02 14:37:54 -0700255 return false;
jaepark98e10192016-08-15 10:51:11 -0700256
tsepezf8074ce2016-09-27 14:29:57 -0700257 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
258 return pWidgetHandler->OnRButtonDblClk((*pAnnot)->GetXFAWidget(),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500259 GetFWLFlags(nFlags), point);
jaepark98e10192016-08-15 10:51:11 -0700260}
261
tsepez4cf55152016-11-02 14:37:54 -0700262bool CPDFSDK_XFAWidgetHandler::OnChar(CPDFSDK_Annot* pAnnot,
263 uint32_t nChar,
264 uint32_t nFlags) {
jaepark98e10192016-08-15 10:51:11 -0700265 if (!pAnnot)
tsepez4cf55152016-11-02 14:37:54 -0700266 return false;
jaepark98e10192016-08-15 10:51:11 -0700267
268 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
269 return pWidgetHandler->OnChar(pAnnot->GetXFAWidget(), nChar,
270 GetFWLFlags(nFlags));
271}
272
tsepez4cf55152016-11-02 14:37:54 -0700273bool CPDFSDK_XFAWidgetHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
274 int nKeyCode,
275 int nFlag) {
jaepark98e10192016-08-15 10:51:11 -0700276 if (!pAnnot)
tsepez4cf55152016-11-02 14:37:54 -0700277 return false;
jaepark98e10192016-08-15 10:51:11 -0700278
279 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
280 return pWidgetHandler->OnKeyDown(pAnnot->GetXFAWidget(), nKeyCode,
281 GetFWLFlags(nFlag));
282}
283
tsepez4cf55152016-11-02 14:37:54 -0700284bool CPDFSDK_XFAWidgetHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
285 int nKeyCode,
286 int nFlag) {
jaepark98e10192016-08-15 10:51:11 -0700287 if (!pAnnot)
tsepez4cf55152016-11-02 14:37:54 -0700288 return false;
jaepark98e10192016-08-15 10:51:11 -0700289
290 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
291 return pWidgetHandler->OnKeyUp(pAnnot->GetXFAWidget(), nKeyCode,
292 GetFWLFlags(nFlag));
293}
294
tsepez4cf55152016-11-02 14:37:54 -0700295bool CPDFSDK_XFAWidgetHandler::OnSetFocus(CPDFSDK_Annot::ObservedPtr* pAnnot,
296 uint32_t nFlag) {
297 return true;
jaepark98e10192016-08-15 10:51:11 -0700298}
299
tsepez4cf55152016-11-02 14:37:54 -0700300bool CPDFSDK_XFAWidgetHandler::OnKillFocus(CPDFSDK_Annot::ObservedPtr* pAnnot,
301 uint32_t nFlag) {
302 return true;
jaepark8c541822016-08-30 13:43:05 -0700303}
304
tsepez4cf55152016-11-02 14:37:54 -0700305bool CPDFSDK_XFAWidgetHandler::OnXFAChangedFocus(
tsepezf8074ce2016-09-27 14:29:57 -0700306 CPDFSDK_Annot::ObservedPtr* pOldAnnot,
307 CPDFSDK_Annot::ObservedPtr* pNewAnnot) {
jaepark98e10192016-08-15 10:51:11 -0700308 CXFA_FFWidgetHandler* pWidgetHandler = nullptr;
tsepezf8074ce2016-09-27 14:29:57 -0700309 if (*pOldAnnot)
310 pWidgetHandler = GetXFAWidgetHandler(pOldAnnot->Get());
311 else if (*pNewAnnot)
312 pWidgetHandler = GetXFAWidgetHandler(pNewAnnot->Get());
jaepark98e10192016-08-15 10:51:11 -0700313
tsepezf8074ce2016-09-27 14:29:57 -0700314 if (!pWidgetHandler)
tsepez4cf55152016-11-02 14:37:54 -0700315 return true;
jaepark98e10192016-08-15 10:51:11 -0700316
tsepezf8074ce2016-09-27 14:29:57 -0700317 CXFA_FFWidget* hWidget = *pNewAnnot ? (*pNewAnnot)->GetXFAWidget() : nullptr;
318 if (!hWidget)
tsepez4cf55152016-11-02 14:37:54 -0700319 return true;
jaepark98e10192016-08-15 10:51:11 -0700320
tsepezf8074ce2016-09-27 14:29:57 -0700321 CXFA_FFPageView* pXFAPageView = hWidget->GetPageView();
322 if (!pXFAPageView)
tsepez4cf55152016-11-02 14:37:54 -0700323 return true;
tsepezf8074ce2016-09-27 14:29:57 -0700324
tsepez4cf55152016-11-02 14:37:54 -0700325 bool bRet = pXFAPageView->GetDocView()->SetFocus(hWidget);
tsepezf8074ce2016-09-27 14:29:57 -0700326 if (pXFAPageView->GetDocView()->GetFocusWidget() == hWidget)
tsepez4cf55152016-11-02 14:37:54 -0700327 bRet = true;
tsepezf8074ce2016-09-27 14:29:57 -0700328
329 return bRet;
jaepark98e10192016-08-15 10:51:11 -0700330}
331
jaepark8c541822016-08-30 13:43:05 -0700332CXFA_FFWidgetHandler* CPDFSDK_XFAWidgetHandler::GetXFAWidgetHandler(
jaepark98e10192016-08-15 10:51:11 -0700333 CPDFSDK_Annot* pAnnot) {
334 if (!pAnnot)
335 return nullptr;
336
337 CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
338 if (!pPageView)
339 return nullptr;
340
dsinclairb402b172016-10-11 09:26:32 -0700341 CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv();
dsinclair7cbe68e2016-10-12 11:56:23 -0700342 if (!pFormFillEnv)
jaepark98e10192016-08-15 10:51:11 -0700343 return nullptr;
344
dsinclair521b7502016-11-02 13:02:28 -0700345 CPDFXFA_Context* pDoc = pFormFillEnv->GetXFAContext();
jaepark98e10192016-08-15 10:51:11 -0700346 if (!pDoc)
347 return nullptr;
348
349 CXFA_FFDocView* pDocView = pDoc->GetXFADocView();
350 if (!pDocView)
351 return nullptr;
352
353 return pDocView->GetWidgetHandler();
354}
355
jaepark8c541822016-08-30 13:43:05 -0700356uint32_t CPDFSDK_XFAWidgetHandler::GetFWLFlags(uint32_t dwFlag) {
jaepark98e10192016-08-15 10:51:11 -0700357 uint32_t dwFWLFlag = 0;
358
359 if (dwFlag & FWL_EVENTFLAG_ControlKey)
360 dwFWLFlag |= FWL_KEYFLAG_Ctrl;
361 if (dwFlag & FWL_EVENTFLAG_LeftButtonDown)
362 dwFWLFlag |= FWL_KEYFLAG_LButton;
363 if (dwFlag & FWL_EVENTFLAG_MiddleButtonDown)
364 dwFWLFlag |= FWL_KEYFLAG_MButton;
365 if (dwFlag & FWL_EVENTFLAG_RightButtonDown)
366 dwFWLFlag |= FWL_KEYFLAG_RButton;
367 if (dwFlag & FWL_EVENTFLAG_ShiftKey)
368 dwFWLFlag |= FWL_KEYFLAG_Shift;
369 if (dwFlag & FWL_EVENTFLAG_AltKey)
370 dwFWLFlag |= FWL_KEYFLAG_Alt;
371
372 return dwFWLFlag;
373}