blob: 41c21e0bd870192e60564d9408449435b03ef28c [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"
dsinclair5b493092016-09-29 20:20:24 -070018#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"
dsinclair202ad722016-09-29 17:41:42 -070023#include "xfa/fxgraphics/cfx_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
jaepark98e10192016-08-15 10:51:11 -070056 CFX_Graphics gs;
57 gs.Create(pDevice);
58
Dan Sinclairbba2a7c2017-02-07 16:36:39 -050059 CFX_Matrix mt = *pUser2Device;
tsepez4cf55152016-11-02 14:37:54 -070060 bool bIsHighlight = false;
dsinclair7cbe68e2016-10-12 11:56:23 -070061 if (pPageView->GetFormFillEnv()->GetFocusAnnot() != pAnnot)
tsepez4cf55152016-11-02 14:37:54 -070062 bIsHighlight = true;
jaepark98e10192016-08-15 10:51:11 -070063
dsinclairb402b172016-10-11 09:26:32 -070064 GetXFAWidgetHandler(pAnnot)->RenderWidget(pAnnot->GetXFAWidget(), &gs, &mt,
65 bIsHighlight);
jaepark98e10192016-08-15 10:51:11 -070066
67 // to do highlight and shadow
68}
69
jaepark8c541822016-08-30 13:43:05 -070070void CPDFSDK_XFAWidgetHandler::OnLoad(CPDFSDK_Annot* pAnnot) {}
jaepark98e10192016-08-15 10:51:11 -070071
jaepark8c541822016-08-30 13:43:05 -070072void CPDFSDK_XFAWidgetHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
jaepark98e10192016-08-15 10:51:11 -070073 CPDFSDK_XFAWidget* pWidget = reinterpret_cast<CPDFSDK_XFAWidget*>(pAnnot);
74 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
75 pInterForm->RemoveXFAMap(pWidget->GetXFAWidget());
76
77 delete pWidget;
78}
79
jaepark8c541822016-08-30 13:43:05 -070080CFX_FloatRect CPDFSDK_XFAWidgetHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
81 CPDFSDK_Annot* pAnnot) {
jaepark98e10192016-08-15 10:51:11 -070082 ASSERT(pAnnot);
83
84 CFX_RectF rcBBox;
85 XFA_Element eType = pAnnot->GetXFAWidget()->GetDataAcc()->GetUIType();
86 if (eType == XFA_Element::Signature)
Dan Sinclair1b08df12017-02-09 09:17:20 -050087 rcBBox = pAnnot->GetXFAWidget()->GetBBox(XFA_WidgetStatus_Visible, true);
jaepark98e10192016-08-15 10:51:11 -070088 else
Dan Sinclair1b08df12017-02-09 09:17:20 -050089 rcBBox = pAnnot->GetXFAWidget()->GetBBox(XFA_WidgetStatus_None);
jaepark98e10192016-08-15 10:51:11 -070090
91 CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
92 rcBBox.top + rcBBox.height);
93 rcWidget.left -= 1.0f;
94 rcWidget.right += 1.0f;
95 rcWidget.bottom -= 1.0f;
96 rcWidget.top += 1.0f;
97
98 return rcWidget;
99}
100
tsepez4cf55152016-11-02 14:37:54 -0700101bool CPDFSDK_XFAWidgetHandler::HitTest(CPDFSDK_PageView* pPageView,
102 CPDFSDK_Annot* pAnnot,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500103 const CFX_PointF& point) {
jaepark98e10192016-08-15 10:51:11 -0700104 if (!pPageView || !pAnnot)
tsepez4cf55152016-11-02 14:37:54 -0700105 return false;
jaepark98e10192016-08-15 10:51:11 -0700106
dsinclairb402b172016-10-11 09:26:32 -0700107 CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv();
dsinclair7cbe68e2016-10-12 11:56:23 -0700108 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700109 return false;
jaepark98e10192016-08-15 10:51:11 -0700110
dsinclair521b7502016-11-02 13:02:28 -0700111 CPDFXFA_Context* pContext = pFormFillEnv->GetXFAContext();
112 if (!pContext)
tsepez4cf55152016-11-02 14:37:54 -0700113 return false;
jaepark98e10192016-08-15 10:51:11 -0700114
dsinclair521b7502016-11-02 13:02:28 -0700115 CXFA_FFDocView* pDocView = pContext->GetXFADocView();
jaepark98e10192016-08-15 10:51:11 -0700116 if (!pDocView)
tsepez4cf55152016-11-02 14:37:54 -0700117 return false;
jaepark98e10192016-08-15 10:51:11 -0700118
119 CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
120 if (!pWidgetHandler)
tsepez4cf55152016-11-02 14:37:54 -0700121 return false;
jaepark98e10192016-08-15 10:51:11 -0700122
123 FWL_WidgetHit dwHitTest =
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500124 pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point);
jaepark98e10192016-08-15 10:51:11 -0700125 return dwHitTest != FWL_WidgetHit::Unknown;
126}
127
jaepark8c541822016-08-30 13:43:05 -0700128void CPDFSDK_XFAWidgetHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700129 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark8c541822016-08-30 13:43:05 -0700130 uint32_t nFlag) {
tsepezf8074ce2016-09-27 14:29:57 -0700131 if (!pPageView || !(*pAnnot))
jaepark98e10192016-08-15 10:51:11 -0700132 return;
tsepezf8074ce2016-09-27 14:29:57 -0700133 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
134 pWidgetHandler->OnMouseEnter((*pAnnot)->GetXFAWidget());
jaepark98e10192016-08-15 10:51:11 -0700135}
136
jaepark8c541822016-08-30 13:43:05 -0700137void CPDFSDK_XFAWidgetHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
tsepezf8074ce2016-09-27 14:29:57 -0700138 CPDFSDK_Annot::ObservedPtr* pAnnot,
jaepark8c541822016-08-30 13:43:05 -0700139 uint32_t nFlag) {
tsepezf8074ce2016-09-27 14:29:57 -0700140 if (!pPageView || !(*pAnnot))
jaepark98e10192016-08-15 10:51:11 -0700141 return;
142
tsepezf8074ce2016-09-27 14:29:57 -0700143 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
144 pWidgetHandler->OnMouseExit((*pAnnot)->GetXFAWidget());
jaepark98e10192016-08-15 10:51:11 -0700145}
146
tsepez4cf55152016-11-02 14:37:54 -0700147bool CPDFSDK_XFAWidgetHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
148 CPDFSDK_Annot::ObservedPtr* pAnnot,
149 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500150 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700151 if (!pPageView || !(*pAnnot))
tsepez4cf55152016-11-02 14:37:54 -0700152 return false;
jaepark98e10192016-08-15 10:51:11 -0700153
tsepezf8074ce2016-09-27 14:29:57 -0700154 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
155 return pWidgetHandler->OnLButtonDown((*pAnnot)->GetXFAWidget(),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500156 GetFWLFlags(nFlags), point);
jaepark98e10192016-08-15 10:51:11 -0700157}
158
tsepez4cf55152016-11-02 14:37:54 -0700159bool CPDFSDK_XFAWidgetHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
160 CPDFSDK_Annot::ObservedPtr* pAnnot,
161 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500162 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700163 if (!pPageView || !(*pAnnot))
tsepez4cf55152016-11-02 14:37:54 -0700164 return false;
jaepark98e10192016-08-15 10:51:11 -0700165
tsepezf8074ce2016-09-27 14:29:57 -0700166 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
167 return pWidgetHandler->OnLButtonUp((*pAnnot)->GetXFAWidget(),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500168 GetFWLFlags(nFlags), point);
jaepark98e10192016-08-15 10:51:11 -0700169}
170
tsepez4cf55152016-11-02 14:37:54 -0700171bool CPDFSDK_XFAWidgetHandler::OnLButtonDblClk(
tsepezf8074ce2016-09-27 14:29:57 -0700172 CPDFSDK_PageView* pPageView,
173 CPDFSDK_Annot::ObservedPtr* pAnnot,
174 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500175 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700176 if (!pPageView || !(*pAnnot))
tsepez4cf55152016-11-02 14:37:54 -0700177 return false;
jaepark98e10192016-08-15 10:51:11 -0700178
tsepezf8074ce2016-09-27 14:29:57 -0700179 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
180 return pWidgetHandler->OnLButtonDblClk((*pAnnot)->GetXFAWidget(),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500181 GetFWLFlags(nFlags), point);
jaepark98e10192016-08-15 10:51:11 -0700182}
183
tsepez4cf55152016-11-02 14:37:54 -0700184bool CPDFSDK_XFAWidgetHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
185 CPDFSDK_Annot::ObservedPtr* pAnnot,
186 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500187 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700188 if (!pPageView || !(*pAnnot))
tsepez4cf55152016-11-02 14:37:54 -0700189 return false;
jaepark98e10192016-08-15 10:51:11 -0700190
tsepezf8074ce2016-09-27 14:29:57 -0700191 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
192 return pWidgetHandler->OnMouseMove((*pAnnot)->GetXFAWidget(),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500193 GetFWLFlags(nFlags), point);
jaepark98e10192016-08-15 10:51:11 -0700194}
195
tsepez4cf55152016-11-02 14:37:54 -0700196bool CPDFSDK_XFAWidgetHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
197 CPDFSDK_Annot::ObservedPtr* pAnnot,
198 uint32_t nFlags,
199 short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500200 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700201 if (!pPageView || !(*pAnnot))
tsepez4cf55152016-11-02 14:37:54 -0700202 return false;
jaepark98e10192016-08-15 10:51:11 -0700203
tsepezf8074ce2016-09-27 14:29:57 -0700204 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500205 return pWidgetHandler->OnMouseWheel((*pAnnot)->GetXFAWidget(),
206 GetFWLFlags(nFlags), zDelta, point);
jaepark98e10192016-08-15 10:51:11 -0700207}
208
tsepez4cf55152016-11-02 14:37:54 -0700209bool CPDFSDK_XFAWidgetHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
210 CPDFSDK_Annot::ObservedPtr* pAnnot,
211 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500212 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700213 if (!pPageView || !(*pAnnot))
tsepez4cf55152016-11-02 14:37:54 -0700214 return false;
jaepark98e10192016-08-15 10:51:11 -0700215
tsepezf8074ce2016-09-27 14:29:57 -0700216 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
217 return pWidgetHandler->OnRButtonDown((*pAnnot)->GetXFAWidget(),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500218 GetFWLFlags(nFlags), point);
jaepark98e10192016-08-15 10:51:11 -0700219}
220
tsepez4cf55152016-11-02 14:37:54 -0700221bool CPDFSDK_XFAWidgetHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
222 CPDFSDK_Annot::ObservedPtr* pAnnot,
223 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500224 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700225 if (!pPageView || !(*pAnnot))
tsepez4cf55152016-11-02 14:37:54 -0700226 return false;
jaepark98e10192016-08-15 10:51:11 -0700227
tsepezf8074ce2016-09-27 14:29:57 -0700228 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
229 return pWidgetHandler->OnRButtonUp((*pAnnot)->GetXFAWidget(),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500230 GetFWLFlags(nFlags), point);
jaepark98e10192016-08-15 10:51:11 -0700231}
232
tsepez4cf55152016-11-02 14:37:54 -0700233bool CPDFSDK_XFAWidgetHandler::OnRButtonDblClk(
tsepezf8074ce2016-09-27 14:29:57 -0700234 CPDFSDK_PageView* pPageView,
235 CPDFSDK_Annot::ObservedPtr* pAnnot,
236 uint32_t nFlags,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500237 const CFX_PointF& point) {
tsepezf8074ce2016-09-27 14:29:57 -0700238 if (!pPageView || !(*pAnnot))
tsepez4cf55152016-11-02 14:37:54 -0700239 return false;
jaepark98e10192016-08-15 10:51:11 -0700240
tsepezf8074ce2016-09-27 14:29:57 -0700241 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot->Get());
242 return pWidgetHandler->OnRButtonDblClk((*pAnnot)->GetXFAWidget(),
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500243 GetFWLFlags(nFlags), point);
jaepark98e10192016-08-15 10:51:11 -0700244}
245
tsepez4cf55152016-11-02 14:37:54 -0700246bool CPDFSDK_XFAWidgetHandler::OnChar(CPDFSDK_Annot* pAnnot,
247 uint32_t nChar,
248 uint32_t nFlags) {
jaepark98e10192016-08-15 10:51:11 -0700249 if (!pAnnot)
tsepez4cf55152016-11-02 14:37:54 -0700250 return false;
jaepark98e10192016-08-15 10:51:11 -0700251
252 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
253 return pWidgetHandler->OnChar(pAnnot->GetXFAWidget(), nChar,
254 GetFWLFlags(nFlags));
255}
256
tsepez4cf55152016-11-02 14:37:54 -0700257bool CPDFSDK_XFAWidgetHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
258 int nKeyCode,
259 int nFlag) {
jaepark98e10192016-08-15 10:51:11 -0700260 if (!pAnnot)
tsepez4cf55152016-11-02 14:37:54 -0700261 return false;
jaepark98e10192016-08-15 10:51:11 -0700262
263 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
264 return pWidgetHandler->OnKeyDown(pAnnot->GetXFAWidget(), nKeyCode,
265 GetFWLFlags(nFlag));
266}
267
tsepez4cf55152016-11-02 14:37:54 -0700268bool CPDFSDK_XFAWidgetHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
269 int nKeyCode,
270 int nFlag) {
jaepark98e10192016-08-15 10:51:11 -0700271 if (!pAnnot)
tsepez4cf55152016-11-02 14:37:54 -0700272 return false;
jaepark98e10192016-08-15 10:51:11 -0700273
274 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
275 return pWidgetHandler->OnKeyUp(pAnnot->GetXFAWidget(), nKeyCode,
276 GetFWLFlags(nFlag));
277}
278
tsepez4cf55152016-11-02 14:37:54 -0700279bool CPDFSDK_XFAWidgetHandler::OnSetFocus(CPDFSDK_Annot::ObservedPtr* pAnnot,
280 uint32_t nFlag) {
281 return true;
jaepark98e10192016-08-15 10:51:11 -0700282}
283
tsepez4cf55152016-11-02 14:37:54 -0700284bool CPDFSDK_XFAWidgetHandler::OnKillFocus(CPDFSDK_Annot::ObservedPtr* pAnnot,
285 uint32_t nFlag) {
286 return true;
jaepark8c541822016-08-30 13:43:05 -0700287}
288
tsepez4cf55152016-11-02 14:37:54 -0700289bool CPDFSDK_XFAWidgetHandler::OnXFAChangedFocus(
tsepezf8074ce2016-09-27 14:29:57 -0700290 CPDFSDK_Annot::ObservedPtr* pOldAnnot,
291 CPDFSDK_Annot::ObservedPtr* pNewAnnot) {
jaepark98e10192016-08-15 10:51:11 -0700292 CXFA_FFWidgetHandler* pWidgetHandler = nullptr;
tsepezf8074ce2016-09-27 14:29:57 -0700293 if (*pOldAnnot)
294 pWidgetHandler = GetXFAWidgetHandler(pOldAnnot->Get());
295 else if (*pNewAnnot)
296 pWidgetHandler = GetXFAWidgetHandler(pNewAnnot->Get());
jaepark98e10192016-08-15 10:51:11 -0700297
tsepezf8074ce2016-09-27 14:29:57 -0700298 if (!pWidgetHandler)
tsepez4cf55152016-11-02 14:37:54 -0700299 return true;
jaepark98e10192016-08-15 10:51:11 -0700300
tsepezf8074ce2016-09-27 14:29:57 -0700301 CXFA_FFWidget* hWidget = *pNewAnnot ? (*pNewAnnot)->GetXFAWidget() : nullptr;
302 if (!hWidget)
tsepez4cf55152016-11-02 14:37:54 -0700303 return true;
jaepark98e10192016-08-15 10:51:11 -0700304
tsepezf8074ce2016-09-27 14:29:57 -0700305 CXFA_FFPageView* pXFAPageView = hWidget->GetPageView();
306 if (!pXFAPageView)
tsepez4cf55152016-11-02 14:37:54 -0700307 return true;
tsepezf8074ce2016-09-27 14:29:57 -0700308
tsepez4cf55152016-11-02 14:37:54 -0700309 bool bRet = pXFAPageView->GetDocView()->SetFocus(hWidget);
tsepezf8074ce2016-09-27 14:29:57 -0700310 if (pXFAPageView->GetDocView()->GetFocusWidget() == hWidget)
tsepez4cf55152016-11-02 14:37:54 -0700311 bRet = true;
tsepezf8074ce2016-09-27 14:29:57 -0700312
313 return bRet;
jaepark98e10192016-08-15 10:51:11 -0700314}
315
jaepark8c541822016-08-30 13:43:05 -0700316CXFA_FFWidgetHandler* CPDFSDK_XFAWidgetHandler::GetXFAWidgetHandler(
jaepark98e10192016-08-15 10:51:11 -0700317 CPDFSDK_Annot* pAnnot) {
318 if (!pAnnot)
319 return nullptr;
320
321 CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
322 if (!pPageView)
323 return nullptr;
324
dsinclairb402b172016-10-11 09:26:32 -0700325 CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv();
dsinclair7cbe68e2016-10-12 11:56:23 -0700326 if (!pFormFillEnv)
jaepark98e10192016-08-15 10:51:11 -0700327 return nullptr;
328
dsinclair521b7502016-11-02 13:02:28 -0700329 CPDFXFA_Context* pDoc = pFormFillEnv->GetXFAContext();
jaepark98e10192016-08-15 10:51:11 -0700330 if (!pDoc)
331 return nullptr;
332
333 CXFA_FFDocView* pDocView = pDoc->GetXFADocView();
334 if (!pDocView)
335 return nullptr;
336
337 return pDocView->GetWidgetHandler();
338}
339
jaepark8c541822016-08-30 13:43:05 -0700340uint32_t CPDFSDK_XFAWidgetHandler::GetFWLFlags(uint32_t dwFlag) {
jaepark98e10192016-08-15 10:51:11 -0700341 uint32_t dwFWLFlag = 0;
342
343 if (dwFlag & FWL_EVENTFLAG_ControlKey)
344 dwFWLFlag |= FWL_KEYFLAG_Ctrl;
345 if (dwFlag & FWL_EVENTFLAG_LeftButtonDown)
346 dwFWLFlag |= FWL_KEYFLAG_LButton;
347 if (dwFlag & FWL_EVENTFLAG_MiddleButtonDown)
348 dwFWLFlag |= FWL_KEYFLAG_MButton;
349 if (dwFlag & FWL_EVENTFLAG_RightButtonDown)
350 dwFWLFlag |= FWL_KEYFLAG_RButton;
351 if (dwFlag & FWL_EVENTFLAG_ShiftKey)
352 dwFWLFlag |= FWL_KEYFLAG_Shift;
353 if (dwFlag & FWL_EVENTFLAG_AltKey)
354 dwFWLFlag |= FWL_KEYFLAG_Alt;
355
356 return dwFWLFlag;
357}