OLD | NEW |
| (Empty) |
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 | |
7 #include "fpdfsdk/include/cpdfsdk_xfaannothandler.h" | |
8 | |
9 #include "core/fpdfdoc/include/cpdf_interform.h" | |
10 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" | |
11 #include "fpdfsdk/include/cpdfsdk_annot.h" | |
12 #include "fpdfsdk/include/cpdfsdk_interform.h" | |
13 #include "fpdfsdk/include/cpdfsdk_xfawidget.h" | |
14 #include "fpdfsdk/include/fsdk_mgr.h" | |
15 #include "xfa/fxfa/include/fxfa_basic.h" | |
16 #include "xfa/fxfa/include/xfa_ffdocview.h" | |
17 #include "xfa/fxfa/include/xfa_ffpageview.h" | |
18 #include "xfa/fxfa/include/xfa_ffwidget.h" | |
19 #include "xfa/fxfa/include/xfa_ffwidgethandler.h" | |
20 #include "xfa/fxgraphics/include/cfx_graphics.h" | |
21 #include "xfa/fwl/core/include/fwl_widgethit.h" | |
22 | |
23 CPDFSDK_XFAAnnotHandler::CPDFSDK_XFAAnnotHandler(CPDFDoc_Environment* pApp) | |
24 : m_pApp(pApp) {} | |
25 | |
26 CPDFSDK_XFAAnnotHandler::~CPDFSDK_XFAAnnotHandler() {} | |
27 | |
28 CFX_ByteString CPDFSDK_XFAAnnotHandler::GetType() { | |
29 return FSDK_XFAWIDGET_TYPENAME; | |
30 } | |
31 | |
32 FX_BOOL CPDFSDK_XFAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { | |
33 return !!pAnnot->GetXFAWidget(); | |
34 } | |
35 | |
36 CPDFSDK_Annot* CPDFSDK_XFAAnnotHandler::NewAnnot(CPDF_Annot* pAnnot, | |
37 CPDFSDK_PageView* pPage) { | |
38 return nullptr; | |
39 } | |
40 | |
41 CPDFSDK_Annot* CPDFSDK_XFAAnnotHandler::NewAnnot(CXFA_FFWidget* pAnnot, | |
42 CPDFSDK_PageView* pPage) { | |
43 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument(); | |
44 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); | |
45 CPDFSDK_XFAWidget* pWidget = new CPDFSDK_XFAWidget(pAnnot, pPage, pInterForm); | |
46 pInterForm->AddXFAMap(pAnnot, pWidget); | |
47 return pWidget; | |
48 } | |
49 | |
50 void CPDFSDK_XFAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView, | |
51 CPDFSDK_Annot* pAnnot, | |
52 CFX_RenderDevice* pDevice, | |
53 CFX_Matrix* pUser2Device, | |
54 uint32_t dwFlags) { | |
55 ASSERT(pPageView); | |
56 ASSERT(pAnnot); | |
57 | |
58 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); | |
59 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
60 | |
61 CFX_Graphics gs; | |
62 gs.Create(pDevice); | |
63 | |
64 CFX_Matrix mt; | |
65 mt = *pUser2Device; | |
66 | |
67 FX_BOOL bIsHighlight = FALSE; | |
68 if (pSDKDoc->GetFocusAnnot() != pAnnot) | |
69 bIsHighlight = TRUE; | |
70 | |
71 pWidgetHandler->RenderWidget(pAnnot->GetXFAWidget(), &gs, &mt, bIsHighlight); | |
72 | |
73 // to do highlight and shadow | |
74 } | |
75 | |
76 void CPDFSDK_XFAAnnotHandler::OnDrawSleep(CPDFSDK_PageView* pPageView, | |
77 CPDFSDK_Annot* pAnnot, | |
78 CFX_RenderDevice* pDevice, | |
79 CFX_Matrix* pUser2Device, | |
80 const CFX_FloatRect& rcWindow, | |
81 uint32_t dwFlags) {} | |
82 | |
83 void CPDFSDK_XFAAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) {} | |
84 | |
85 void CPDFSDK_XFAAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {} | |
86 | |
87 void CPDFSDK_XFAAnnotHandler::OnDelete(CPDFSDK_Annot* pAnnot) {} | |
88 | |
89 void CPDFSDK_XFAAnnotHandler::OnRelease(CPDFSDK_Annot* pAnnot) {} | |
90 | |
91 void CPDFSDK_XFAAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { | |
92 CPDFSDK_XFAWidget* pWidget = reinterpret_cast<CPDFSDK_XFAWidget*>(pAnnot); | |
93 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); | |
94 pInterForm->RemoveXFAMap(pWidget->GetXFAWidget()); | |
95 | |
96 delete pWidget; | |
97 } | |
98 | |
99 void CPDFSDK_XFAAnnotHandler::DeleteAnnot(CPDFSDK_Annot* pAnnot) {} | |
100 | |
101 CFX_FloatRect CPDFSDK_XFAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView, | |
102 CPDFSDK_Annot* pAnnot) { | |
103 ASSERT(pAnnot); | |
104 | |
105 CFX_RectF rcBBox; | |
106 XFA_Element eType = pAnnot->GetXFAWidget()->GetDataAcc()->GetUIType(); | |
107 if (eType == XFA_Element::Signature) | |
108 pAnnot->GetXFAWidget()->GetBBox(rcBBox, XFA_WidgetStatus_Visible, TRUE); | |
109 else | |
110 pAnnot->GetXFAWidget()->GetBBox(rcBBox, XFA_WidgetStatus_None); | |
111 | |
112 CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, | |
113 rcBBox.top + rcBBox.height); | |
114 rcWidget.left -= 1.0f; | |
115 rcWidget.right += 1.0f; | |
116 rcWidget.bottom -= 1.0f; | |
117 rcWidget.top += 1.0f; | |
118 | |
119 return rcWidget; | |
120 } | |
121 | |
122 FX_BOOL CPDFSDK_XFAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, | |
123 CPDFSDK_Annot* pAnnot, | |
124 const CFX_FloatPoint& point) { | |
125 if (!pPageView || !pAnnot) | |
126 return FALSE; | |
127 | |
128 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); | |
129 if (!pSDKDoc) | |
130 return FALSE; | |
131 | |
132 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); | |
133 if (!pDoc) | |
134 return FALSE; | |
135 | |
136 CXFA_FFDocView* pDocView = pDoc->GetXFADocView(); | |
137 if (!pDocView) | |
138 return FALSE; | |
139 | |
140 CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler(); | |
141 if (!pWidgetHandler) | |
142 return FALSE; | |
143 | |
144 FWL_WidgetHit dwHitTest = | |
145 pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point.x, point.y); | |
146 return dwHitTest != FWL_WidgetHit::Unknown; | |
147 } | |
148 | |
149 void CPDFSDK_XFAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView, | |
150 CPDFSDK_Annot* pAnnot, | |
151 uint32_t nFlag) { | |
152 if (!pPageView || !pAnnot) | |
153 return; | |
154 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
155 pWidgetHandler->OnMouseEnter(pAnnot->GetXFAWidget()); | |
156 } | |
157 | |
158 void CPDFSDK_XFAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView, | |
159 CPDFSDK_Annot* pAnnot, | |
160 uint32_t nFlag) { | |
161 if (!pPageView || !pAnnot) | |
162 return; | |
163 | |
164 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
165 pWidgetHandler->OnMouseExit(pAnnot->GetXFAWidget()); | |
166 } | |
167 | |
168 FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView, | |
169 CPDFSDK_Annot* pAnnot, | |
170 uint32_t nFlags, | |
171 const CFX_FloatPoint& point) { | |
172 if (!pPageView || !pAnnot) | |
173 return FALSE; | |
174 | |
175 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
176 return pWidgetHandler->OnLButtonDown(pAnnot->GetXFAWidget(), | |
177 GetFWLFlags(nFlags), point.x, point.y); | |
178 } | |
179 | |
180 FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView, | |
181 CPDFSDK_Annot* pAnnot, | |
182 uint32_t nFlags, | |
183 const CFX_FloatPoint& point) { | |
184 if (!pPageView || !pAnnot) | |
185 return FALSE; | |
186 | |
187 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
188 return pWidgetHandler->OnLButtonUp(pAnnot->GetXFAWidget(), | |
189 GetFWLFlags(nFlags), point.x, point.y); | |
190 } | |
191 | |
192 FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView, | |
193 CPDFSDK_Annot* pAnnot, | |
194 uint32_t nFlags, | |
195 const CFX_FloatPoint& point) { | |
196 if (!pPageView || !pAnnot) | |
197 return FALSE; | |
198 | |
199 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
200 return pWidgetHandler->OnLButtonDblClk(pAnnot->GetXFAWidget(), | |
201 GetFWLFlags(nFlags), point.x, point.y); | |
202 } | |
203 | |
204 FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView, | |
205 CPDFSDK_Annot* pAnnot, | |
206 uint32_t nFlags, | |
207 const CFX_FloatPoint& point) { | |
208 if (!pPageView || !pAnnot) | |
209 return FALSE; | |
210 | |
211 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
212 return pWidgetHandler->OnMouseMove(pAnnot->GetXFAWidget(), | |
213 GetFWLFlags(nFlags), point.x, point.y); | |
214 } | |
215 | |
216 FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView, | |
217 CPDFSDK_Annot* pAnnot, | |
218 uint32_t nFlags, | |
219 short zDelta, | |
220 const CFX_FloatPoint& point) { | |
221 if (!pPageView || !pAnnot) | |
222 return FALSE; | |
223 | |
224 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
225 return pWidgetHandler->OnMouseWheel( | |
226 pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), zDelta, point.x, point.y); | |
227 } | |
228 | |
229 FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView, | |
230 CPDFSDK_Annot* pAnnot, | |
231 uint32_t nFlags, | |
232 const CFX_FloatPoint& point) { | |
233 if (!pPageView || !pAnnot) | |
234 return FALSE; | |
235 | |
236 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
237 return pWidgetHandler->OnRButtonDown(pAnnot->GetXFAWidget(), | |
238 GetFWLFlags(nFlags), point.x, point.y); | |
239 } | |
240 | |
241 FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView, | |
242 CPDFSDK_Annot* pAnnot, | |
243 uint32_t nFlags, | |
244 const CFX_FloatPoint& point) { | |
245 if (!pPageView || !pAnnot) | |
246 return FALSE; | |
247 | |
248 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
249 return pWidgetHandler->OnRButtonUp(pAnnot->GetXFAWidget(), | |
250 GetFWLFlags(nFlags), point.x, point.y); | |
251 } | |
252 | |
253 FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView, | |
254 CPDFSDK_Annot* pAnnot, | |
255 uint32_t nFlags, | |
256 const CFX_FloatPoint& point) { | |
257 if (!pPageView || !pAnnot) | |
258 return FALSE; | |
259 | |
260 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
261 return pWidgetHandler->OnRButtonDblClk(pAnnot->GetXFAWidget(), | |
262 GetFWLFlags(nFlags), point.x, point.y); | |
263 } | |
264 | |
265 FX_BOOL CPDFSDK_XFAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot, | |
266 uint32_t nChar, | |
267 uint32_t nFlags) { | |
268 if (!pAnnot) | |
269 return FALSE; | |
270 | |
271 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
272 return pWidgetHandler->OnChar(pAnnot->GetXFAWidget(), nChar, | |
273 GetFWLFlags(nFlags)); | |
274 } | |
275 | |
276 FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, | |
277 int nKeyCode, | |
278 int nFlag) { | |
279 if (!pAnnot) | |
280 return FALSE; | |
281 | |
282 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
283 return pWidgetHandler->OnKeyDown(pAnnot->GetXFAWidget(), nKeyCode, | |
284 GetFWLFlags(nFlag)); | |
285 } | |
286 | |
287 FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, | |
288 int nKeyCode, | |
289 int nFlag) { | |
290 if (!pAnnot) | |
291 return FALSE; | |
292 | |
293 CXFA_FFWidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); | |
294 return pWidgetHandler->OnKeyUp(pAnnot->GetXFAWidget(), nKeyCode, | |
295 GetFWLFlags(nFlag)); | |
296 } | |
297 | |
298 void CPDFSDK_XFAAnnotHandler::OnDeSelected(CPDFSDK_Annot* pAnnot) {} | |
299 | |
300 void CPDFSDK_XFAAnnotHandler::OnSelected(CPDFSDK_Annot* pAnnot) {} | |
301 | |
302 FX_BOOL CPDFSDK_XFAAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, | |
303 uint32_t nFlag) { | |
304 return TRUE; | |
305 } | |
306 | |
307 FX_BOOL CPDFSDK_XFAAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot, | |
308 uint32_t nFlag) { | |
309 return TRUE; | |
310 } | |
311 | |
312 FX_BOOL CPDFSDK_XFAAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot, | |
313 CPDFSDK_Annot* pNewAnnot) { | |
314 CXFA_FFWidgetHandler* pWidgetHandler = nullptr; | |
315 | |
316 if (pOldAnnot) | |
317 pWidgetHandler = GetXFAWidgetHandler(pOldAnnot); | |
318 else if (pNewAnnot) | |
319 pWidgetHandler = GetXFAWidgetHandler(pNewAnnot); | |
320 | |
321 if (pWidgetHandler) { | |
322 FX_BOOL bRet = TRUE; | |
323 CXFA_FFWidget* hWidget = pNewAnnot ? pNewAnnot->GetXFAWidget() : nullptr; | |
324 if (hWidget) { | |
325 CXFA_FFPageView* pXFAPageView = hWidget->GetPageView(); | |
326 if (pXFAPageView) { | |
327 bRet = pXFAPageView->GetDocView()->SetFocus(hWidget); | |
328 if (pXFAPageView->GetDocView()->GetFocusWidget() == hWidget) | |
329 bRet = TRUE; | |
330 } | |
331 } | |
332 return bRet; | |
333 } | |
334 | |
335 return TRUE; | |
336 } | |
337 | |
338 CXFA_FFWidgetHandler* CPDFSDK_XFAAnnotHandler::GetXFAWidgetHandler( | |
339 CPDFSDK_Annot* pAnnot) { | |
340 if (!pAnnot) | |
341 return nullptr; | |
342 | |
343 CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); | |
344 if (!pPageView) | |
345 return nullptr; | |
346 | |
347 CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); | |
348 if (!pSDKDoc) | |
349 return nullptr; | |
350 | |
351 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); | |
352 if (!pDoc) | |
353 return nullptr; | |
354 | |
355 CXFA_FFDocView* pDocView = pDoc->GetXFADocView(); | |
356 if (!pDocView) | |
357 return nullptr; | |
358 | |
359 return pDocView->GetWidgetHandler(); | |
360 } | |
361 | |
362 const uint32_t FWL_KEYFLAG_Ctrl = (1 << 0); | |
363 const uint32_t FWL_KEYFLAG_Alt = (1 << 1); | |
364 const uint32_t FWL_KEYFLAG_Shift = (1 << 2); | |
365 const uint32_t FWL_KEYFLAG_LButton = (1 << 3); | |
366 const uint32_t FWL_KEYFLAG_RButton = (1 << 4); | |
367 const uint32_t FWL_KEYFLAG_MButton = (1 << 5); | |
368 | |
369 uint32_t CPDFSDK_XFAAnnotHandler::GetFWLFlags(uint32_t dwFlag) { | |
370 uint32_t dwFWLFlag = 0; | |
371 | |
372 if (dwFlag & FWL_EVENTFLAG_ControlKey) | |
373 dwFWLFlag |= FWL_KEYFLAG_Ctrl; | |
374 if (dwFlag & FWL_EVENTFLAG_LeftButtonDown) | |
375 dwFWLFlag |= FWL_KEYFLAG_LButton; | |
376 if (dwFlag & FWL_EVENTFLAG_MiddleButtonDown) | |
377 dwFWLFlag |= FWL_KEYFLAG_MButton; | |
378 if (dwFlag & FWL_EVENTFLAG_RightButtonDown) | |
379 dwFWLFlag |= FWL_KEYFLAG_RButton; | |
380 if (dwFlag & FWL_EVENTFLAG_ShiftKey) | |
381 dwFWLFlag |= FWL_KEYFLAG_Shift; | |
382 if (dwFlag & FWL_EVENTFLAG_AltKey) | |
383 dwFWLFlag |= FWL_KEYFLAG_Alt; | |
384 | |
385 return dwFWLFlag; | |
386 } | |
OLD | NEW |