Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: fpdfsdk/src/formfiller/FFL_IFormFiller.cpp

Issue 1799773002: Move fpdfsdk/src up to fpdfsdk/. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/formfiller/FFL_FormFiller.cpp ('k') | fpdfsdk/src/formfiller/FFL_ListBox.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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/formfiller/FFL_IFormFiller.h"
8
9 #include "core/include/fpdfapi/cpdf_document.h"
10 #include "fpdfsdk/include/formfiller/FFL_CheckBox.h"
11 #include "fpdfsdk/include/formfiller/FFL_ComboBox.h"
12 #include "fpdfsdk/include/formfiller/FFL_FormFiller.h"
13 #include "fpdfsdk/include/formfiller/FFL_ListBox.h"
14 #include "fpdfsdk/include/formfiller/FFL_PushButton.h"
15 #include "fpdfsdk/include/formfiller/FFL_RadioButton.h"
16 #include "fpdfsdk/include/formfiller/FFL_TextField.h"
17 #include "fpdfsdk/include/fsdk_mgr.h"
18 #include "fpdfsdk/include/pdfwindow/PWL_Utils.h"
19
20 #define FFL_MAXLISTBOXHEIGHT 140.0f
21
22 CFFL_IFormFiller::CFFL_IFormFiller(CPDFDoc_Environment* pApp)
23 : m_pApp(pApp), m_bNotifying(FALSE) {}
24
25 CFFL_IFormFiller::~CFFL_IFormFiller() {
26 for (auto& it : m_Maps)
27 delete it.second;
28 m_Maps.clear();
29 }
30
31 FX_BOOL CFFL_IFormFiller::Annot_HitTest(CPDFSDK_PageView* pPageView,
32 CPDFSDK_Annot* pAnnot,
33 CFX_FloatPoint point) {
34 CFX_FloatRect rc = pAnnot->GetRect();
35 if (rc.Contains(point.x, point.y))
36 return TRUE;
37 return FALSE;
38 }
39
40 FX_RECT CFFL_IFormFiller::GetViewBBox(CPDFSDK_PageView* pPageView,
41 CPDFSDK_Annot* pAnnot) {
42 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
43 return pFormFiller->GetViewBBox(pPageView, pAnnot);
44
45 ASSERT(pPageView);
46
47 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
48 CFX_FloatRect rcAnnot;
49 pPDFAnnot->GetRect(rcAnnot);
50
51 CFX_FloatRect rcWin = CPWL_Utils::InflateRect(rcAnnot, 1);
52 return rcWin.GetOutterRect();
53 }
54
55 void CFFL_IFormFiller::OnDraw(CPDFSDK_PageView* pPageView,
56 CPDFSDK_Annot* pAnnot,
57 CFX_RenderDevice* pDevice,
58 CFX_Matrix* pUser2Device,
59 FX_DWORD dwFlags) {
60 ASSERT(pPageView);
61 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
62
63 if (IsVisible(pWidget)) {
64 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) {
65 if (pFormFiller->IsValid()) {
66 pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
67 pAnnot->GetPDFPage();
68
69 CPDFSDK_Document* pDocument = m_pApp->GetSDKDocument();
70 if (pDocument->GetFocusAnnot() == pAnnot) {
71 CFX_FloatRect rcFocus = pFormFiller->GetFocusBox(pPageView);
72 if (!rcFocus.IsEmpty()) {
73 CFX_PathData path;
74 path.SetPointCount(5);
75 path.SetPoint(0, rcFocus.left, rcFocus.top, FXPT_MOVETO);
76 path.SetPoint(1, rcFocus.left, rcFocus.bottom, FXPT_LINETO);
77 path.SetPoint(2, rcFocus.right, rcFocus.bottom, FXPT_LINETO);
78 path.SetPoint(3, rcFocus.right, rcFocus.top, FXPT_LINETO);
79 path.SetPoint(4, rcFocus.left, rcFocus.top, FXPT_LINETO);
80
81 CFX_GraphStateData gsd;
82 gsd.SetDashCount(1);
83 gsd.m_DashArray[0] = 1.0f;
84 gsd.m_DashPhase = 0;
85 gsd.m_LineWidth = 1.0f;
86 pDevice->DrawPath(&path, pUser2Device, &gsd, 0,
87 ArgbEncode(255, 0, 0, 0), FXFILL_ALTERNATE);
88 }
89 }
90 return;
91 }
92 }
93
94 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
95 pFormFiller->OnDrawDeactive(pPageView, pAnnot, pDevice, pUser2Device,
96 dwFlags);
97 else
98 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
99
100 if (!IsReadOnly(pWidget) && IsFillingAllowed(pWidget))
101 pWidget->DrawShadow(pDevice, pPageView);
102 }
103 }
104
105 void CFFL_IFormFiller::OnCreate(CPDFSDK_Annot* pAnnot) {
106 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) {
107 pFormFiller->OnCreate(pAnnot);
108 }
109 }
110
111 void CFFL_IFormFiller::OnLoad(CPDFSDK_Annot* pAnnot) {
112 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) {
113 pFormFiller->OnLoad(pAnnot);
114 }
115 }
116
117 void CFFL_IFormFiller::OnDelete(CPDFSDK_Annot* pAnnot) {
118 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) {
119 pFormFiller->OnDelete(pAnnot);
120 }
121
122 UnRegisterFormFiller(pAnnot);
123 }
124
125 void CFFL_IFormFiller::OnMouseEnter(CPDFSDK_PageView* pPageView,
126 CPDFSDK_Annot* pAnnot,
127 FX_UINT nFlag) {
128 ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
129
130 if (!m_bNotifying) {
131 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
132 if (pWidget->GetAAction(CPDF_AAction::CursorEnter).GetDict()) {
133 m_bNotifying = TRUE;
134
135 int nValueAge = pWidget->GetValueAge();
136
137 pWidget->ClearAppModified();
138
139 ASSERT(pPageView);
140
141 PDFSDK_FieldAction fa;
142 fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
143 fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
144 pWidget->OnAAction(CPDF_AAction::CursorEnter, fa, pPageView);
145 m_bNotifying = FALSE;
146
147 if (pWidget->IsAppModified()) {
148 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) {
149 pFormFiller->ResetPDFWindow(pPageView,
150 pWidget->GetValueAge() == nValueAge);
151 }
152 }
153 }
154 }
155
156 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, TRUE)) {
157 pFormFiller->OnMouseEnter(pPageView, pAnnot);
158 }
159 }
160
161 void CFFL_IFormFiller::OnMouseExit(CPDFSDK_PageView* pPageView,
162 CPDFSDK_Annot* pAnnot,
163 FX_UINT nFlag) {
164 ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
165
166 if (!m_bNotifying) {
167 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
168 if (pWidget->GetAAction(CPDF_AAction::CursorExit).GetDict()) {
169 m_bNotifying = TRUE;
170 pWidget->GetAppearanceAge();
171 int nValueAge = pWidget->GetValueAge();
172 pWidget->ClearAppModified();
173
174 ASSERT(pPageView);
175
176 PDFSDK_FieldAction fa;
177 fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
178 fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
179
180 pWidget->OnAAction(CPDF_AAction::CursorExit, fa, pPageView);
181 m_bNotifying = FALSE;
182
183 if (pWidget->IsAppModified()) {
184 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) {
185 pFormFiller->ResetPDFWindow(pPageView,
186 nValueAge == pWidget->GetValueAge());
187 }
188 }
189 }
190 }
191
192 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) {
193 pFormFiller->OnMouseExit(pPageView, pAnnot);
194 }
195 }
196
197 FX_BOOL CFFL_IFormFiller::OnLButtonDown(CPDFSDK_PageView* pPageView,
198 CPDFSDK_Annot* pAnnot,
199 FX_UINT nFlags,
200 const CFX_FloatPoint& point) {
201 ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
202
203 if (!m_bNotifying) {
204 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
205 if (Annot_HitTest(pPageView, pAnnot, point) &&
206 pWidget->GetAAction(CPDF_AAction::ButtonDown).GetDict()) {
207 m_bNotifying = TRUE;
208 pWidget->GetAppearanceAge();
209 int nValueAge = pWidget->GetValueAge();
210 pWidget->ClearAppModified();
211
212 ASSERT(pPageView);
213
214 PDFSDK_FieldAction fa;
215 fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlags);
216 fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlags);
217 pWidget->OnAAction(CPDF_AAction::ButtonDown, fa, pPageView);
218 m_bNotifying = FALSE;
219
220 if (!IsValidAnnot(pPageView, pAnnot))
221 return TRUE;
222
223 if (pWidget->IsAppModified()) {
224 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) {
225 pFormFiller->ResetPDFWindow(pPageView,
226 nValueAge == pWidget->GetValueAge());
227 }
228 }
229 }
230 }
231
232 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) {
233 return pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point);
234 }
235
236 return FALSE;
237 }
238
239 FX_BOOL CFFL_IFormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView,
240 CPDFSDK_Annot* pAnnot,
241 FX_UINT nFlags,
242 const CFX_FloatPoint& point) {
243 ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
244 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
245 CPDFSDK_Document* pDocument = m_pApp->GetSDKDocument();
246
247 switch (pWidget->GetFieldType()) {
248 case FIELDTYPE_PUSHBUTTON:
249 case FIELDTYPE_CHECKBOX:
250 case FIELDTYPE_RADIOBUTTON:
251 if (GetViewBBox(pPageView, pAnnot).Contains((int)point.x, (int)point.y))
252 pDocument->SetFocusAnnot(pAnnot);
253 break;
254 default:
255 pDocument->SetFocusAnnot(pAnnot);
256 break;
257 }
258
259 FX_BOOL bRet = FALSE;
260
261 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) {
262 bRet = pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point);
263 }
264
265 if (pDocument->GetFocusAnnot() == pAnnot) {
266 FX_BOOL bExit = FALSE;
267 FX_BOOL bReset = FALSE;
268 OnButtonUp(pWidget, pPageView, bReset, bExit, nFlags);
269 if (bExit)
270 return TRUE;
271 #ifdef PDF_ENABLE_XFA
272 OnClick(pWidget, pPageView, bReset, bExit, nFlags);
273 if (bExit)
274 return TRUE;
275 #endif // PDF_ENABLE_XFA
276 }
277 return bRet;
278 }
279
280 void CFFL_IFormFiller::OnButtonUp(CPDFSDK_Widget* pWidget,
281 CPDFSDK_PageView* pPageView,
282 FX_BOOL& bReset,
283 FX_BOOL& bExit,
284 FX_UINT nFlag) {
285 ASSERT(pWidget);
286
287 if (!m_bNotifying) {
288 if (pWidget->GetAAction(CPDF_AAction::ButtonUp).GetDict()) {
289 m_bNotifying = TRUE;
290 int nAge = pWidget->GetAppearanceAge();
291 int nValueAge = pWidget->GetValueAge();
292
293 ASSERT(pPageView);
294
295 PDFSDK_FieldAction fa;
296 fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
297 fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
298
299 pWidget->OnAAction(CPDF_AAction::ButtonUp, fa, pPageView);
300 m_bNotifying = FALSE;
301
302 if (!IsValidAnnot(pPageView, pWidget)) {
303 bExit = TRUE;
304 return;
305 }
306
307 if (nAge != pWidget->GetAppearanceAge()) {
308 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) {
309 pFormFiller->ResetPDFWindow(pPageView,
310 nValueAge == pWidget->GetValueAge());
311 }
312
313 bReset = TRUE;
314 }
315 }
316 }
317 }
318
319 FX_BOOL CFFL_IFormFiller::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
320 CPDFSDK_Annot* pAnnot,
321 FX_UINT nFlags,
322 const CFX_FloatPoint& point) {
323 ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
324
325 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) {
326 return pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
327 }
328
329 return FALSE;
330 }
331
332 FX_BOOL CFFL_IFormFiller::OnMouseMove(CPDFSDK_PageView* pPageView,
333 CPDFSDK_Annot* pAnnot,
334 FX_UINT nFlags,
335 const CFX_FloatPoint& point) {
336 ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
337
338 // change cursor
339 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, TRUE)) {
340 return pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point);
341 }
342
343 return FALSE;
344 }
345
346 FX_BOOL CFFL_IFormFiller::OnMouseWheel(CPDFSDK_PageView* pPageView,
347 CPDFSDK_Annot* pAnnot,
348 FX_UINT nFlags,
349 short zDelta,
350 const CFX_FloatPoint& point) {
351 ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
352
353 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) {
354 return pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, point);
355 }
356
357 return FALSE;
358 }
359
360 FX_BOOL CFFL_IFormFiller::OnRButtonDown(CPDFSDK_PageView* pPageView,
361 CPDFSDK_Annot* pAnnot,
362 FX_UINT nFlags,
363 const CFX_FloatPoint& point) {
364 ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
365
366 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) {
367 return pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point);
368 }
369
370 return FALSE;
371 }
372
373 FX_BOOL CFFL_IFormFiller::OnRButtonUp(CPDFSDK_PageView* pPageView,
374 CPDFSDK_Annot* pAnnot,
375 FX_UINT nFlags,
376 const CFX_FloatPoint& point) {
377 ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
378
379 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) {
380 return pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point);
381 }
382
383 return FALSE;
384 }
385
386 FX_BOOL CFFL_IFormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot,
387 FX_UINT nKeyCode,
388 FX_UINT nFlags) {
389 ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
390
391 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) {
392 return pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlags);
393 }
394
395 return FALSE;
396 }
397
398 FX_BOOL CFFL_IFormFiller::OnChar(CPDFSDK_Annot* pAnnot,
399 FX_UINT nChar,
400 FX_UINT nFlags) {
401 ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
402 if (nChar == FWL_VKEY_Tab)
403 return TRUE;
404
405 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
406 return pFormFiller->OnChar(pAnnot, nChar, nFlags);
407
408 return FALSE;
409 }
410
411 FX_BOOL CFFL_IFormFiller::OnSetFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) {
412 if (!pAnnot)
413 return FALSE;
414
415 ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
416
417 if (!m_bNotifying) {
418 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
419 if (pWidget->GetAAction(CPDF_AAction::GetFocus).GetDict()) {
420 m_bNotifying = TRUE;
421 pWidget->GetAppearanceAge();
422
423 int nValueAge = pWidget->GetValueAge();
424 pWidget->ClearAppModified();
425
426 CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
427 ASSERT(pPageView);
428
429 PDFSDK_FieldAction fa;
430 fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
431 fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
432
433 CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, TRUE);
434 if (!pFormFiller)
435 return FALSE;
436 pFormFiller->GetActionData(pPageView, CPDF_AAction::GetFocus, fa);
437 pWidget->OnAAction(CPDF_AAction::GetFocus, fa, pPageView);
438 m_bNotifying = FALSE;
439
440 if (pWidget->IsAppModified()) {
441 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) {
442 pFormFiller->ResetPDFWindow(pPageView,
443 nValueAge == pWidget->GetValueAge());
444 }
445 }
446 }
447 }
448
449 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, TRUE))
450 pFormFiller->SetFocusForAnnot(pAnnot, nFlag);
451
452 return TRUE;
453 }
454
455 FX_BOOL CFFL_IFormFiller::OnKillFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) {
456 if (!pAnnot)
457 return FALSE;
458 ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
459
460 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE)) {
461 pFormFiller->KillFocusForAnnot(pAnnot, nFlag);
462
463 if (!m_bNotifying) {
464 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
465 if (pWidget->GetAAction(CPDF_AAction::LoseFocus).GetDict()) {
466 m_bNotifying = TRUE;
467 pWidget->ClearAppModified();
468
469 CPDFSDK_PageView* pPageView = pWidget->GetPageView();
470 ASSERT(pPageView);
471
472 PDFSDK_FieldAction fa;
473 fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
474 fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
475
476 pFormFiller->GetActionData(pPageView, CPDF_AAction::LoseFocus, fa);
477
478 pWidget->OnAAction(CPDF_AAction::LoseFocus, fa, pPageView);
479 m_bNotifying = FALSE;
480 }
481 }
482 }
483
484 return TRUE;
485 }
486
487 FX_BOOL CFFL_IFormFiller::IsVisible(CPDFSDK_Widget* pWidget) {
488 return pWidget->IsVisible();
489 }
490
491 FX_BOOL CFFL_IFormFiller::IsReadOnly(CPDFSDK_Widget* pWidget) {
492 int nFieldFlags = pWidget->GetFieldFlags();
493 return (nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY;
494 }
495
496 FX_BOOL CFFL_IFormFiller::IsFillingAllowed(CPDFSDK_Widget* pWidget) {
497 if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON)
498 return TRUE;
499
500 CPDF_Page* pPage = pWidget->GetPDFPage();
501 CPDF_Document* pDocument = pPage->m_pDocument;
502 FX_DWORD dwPermissions = pDocument->GetUserPermissions();
503 return (dwPermissions & FPDFPERM_FILL_FORM) ||
504 (dwPermissions & FPDFPERM_ANNOT_FORM) ||
505 (dwPermissions & FPDFPERM_MODIFY);
506 }
507
508 CFFL_FormFiller* CFFL_IFormFiller::GetFormFiller(CPDFSDK_Annot* pAnnot,
509 FX_BOOL bRegister) {
510 auto it = m_Maps.find(pAnnot);
511 if (it != m_Maps.end())
512 return it->second;
513
514 if (!bRegister)
515 return nullptr;
516
517 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
518 int nFieldType = pWidget->GetFieldType();
519 CFFL_FormFiller* pFormFiller;
520 switch (nFieldType) {
521 case FIELDTYPE_PUSHBUTTON:
522 pFormFiller = new CFFL_PushButton(m_pApp, pWidget);
523 break;
524 case FIELDTYPE_CHECKBOX:
525 pFormFiller = new CFFL_CheckBox(m_pApp, pWidget);
526 break;
527 case FIELDTYPE_RADIOBUTTON:
528 pFormFiller = new CFFL_RadioButton(m_pApp, pWidget);
529 break;
530 case FIELDTYPE_TEXTFIELD:
531 pFormFiller = new CFFL_TextField(m_pApp, pWidget);
532 break;
533 case FIELDTYPE_LISTBOX:
534 pFormFiller = new CFFL_ListBox(m_pApp, pWidget);
535 break;
536 case FIELDTYPE_COMBOBOX:
537 pFormFiller = new CFFL_ComboBox(m_pApp, pWidget);
538 break;
539 case FIELDTYPE_UNKNOWN:
540 default:
541 pFormFiller = nullptr;
542 break;
543 }
544
545 if (!pFormFiller)
546 return nullptr;
547
548 m_Maps[pAnnot] = pFormFiller;
549 return pFormFiller;
550 }
551
552 void CFFL_IFormFiller::RemoveFormFiller(CPDFSDK_Annot* pAnnot) {
553 if (pAnnot) {
554 UnRegisterFormFiller(pAnnot);
555 }
556 }
557
558 void CFFL_IFormFiller::UnRegisterFormFiller(CPDFSDK_Annot* pAnnot) {
559 auto it = m_Maps.find(pAnnot);
560 if (it == m_Maps.end())
561 return;
562
563 delete it->second;
564 m_Maps.erase(it);
565 }
566
567 void CFFL_IFormFiller::QueryWherePopup(void* pPrivateData,
568 FX_FLOAT fPopupMin,
569 FX_FLOAT fPopupMax,
570 int32_t& nRet,
571 FX_FLOAT& fPopupRet) {
572 CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;
573
574 CFX_FloatRect rcPageView(0, 0, 0, 0);
575 rcPageView.right = pData->pWidget->GetPDFPage()->GetPageWidth();
576 rcPageView.bottom = pData->pWidget->GetPDFPage()->GetPageHeight();
577 rcPageView.Normalize();
578
579 CFX_FloatRect rcAnnot = pData->pWidget->GetRect();
580
581 FX_FLOAT fTop = 0.0f;
582 FX_FLOAT fBottom = 0.0f;
583
584 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pData->pWidget;
585 switch (pWidget->GetRotate() / 90) {
586 default:
587 case 0:
588 fTop = rcPageView.top - rcAnnot.top;
589 fBottom = rcAnnot.bottom - rcPageView.bottom;
590 break;
591 case 1:
592 fTop = rcAnnot.left - rcPageView.left;
593 fBottom = rcPageView.right - rcAnnot.right;
594 break;
595 case 2:
596 fTop = rcAnnot.bottom - rcPageView.bottom;
597 fBottom = rcPageView.top - rcAnnot.top;
598 break;
599 case 3:
600 fTop = rcPageView.right - rcAnnot.right;
601 fBottom = rcAnnot.left - rcPageView.left;
602 break;
603 }
604
605 FX_FLOAT fFactHeight = 0;
606 FX_BOOL bBottom = TRUE;
607 FX_FLOAT fMaxListBoxHeight = 0;
608 if (fPopupMax > FFL_MAXLISTBOXHEIGHT) {
609 if (fPopupMin > FFL_MAXLISTBOXHEIGHT) {
610 fMaxListBoxHeight = fPopupMin;
611 } else {
612 fMaxListBoxHeight = FFL_MAXLISTBOXHEIGHT;
613 }
614 } else {
615 fMaxListBoxHeight = fPopupMax;
616 }
617
618 if (fBottom > fMaxListBoxHeight) {
619 fFactHeight = fMaxListBoxHeight;
620 bBottom = TRUE;
621 } else {
622 if (fTop > fMaxListBoxHeight) {
623 fFactHeight = fMaxListBoxHeight;
624 bBottom = FALSE;
625 } else {
626 if (fTop > fBottom) {
627 fFactHeight = fTop;
628 bBottom = FALSE;
629 } else {
630 fFactHeight = fBottom;
631 bBottom = TRUE;
632 }
633 }
634 }
635
636 nRet = bBottom ? 0 : 1;
637 fPopupRet = fFactHeight;
638 }
639
640 void CFFL_IFormFiller::OnKeyStrokeCommit(CPDFSDK_Widget* pWidget,
641 CPDFSDK_PageView* pPageView,
642 FX_BOOL& bRC,
643 FX_BOOL& bExit,
644 FX_DWORD nFlag) {
645 if (!m_bNotifying) {
646 if (pWidget->GetAAction(CPDF_AAction::KeyStroke).GetDict()) {
647 m_bNotifying = TRUE;
648 pWidget->ClearAppModified();
649
650 ASSERT(pPageView);
651
652 PDFSDK_FieldAction fa;
653 fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
654 fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
655 fa.bWillCommit = TRUE;
656 fa.bKeyDown = TRUE;
657 fa.bRC = TRUE;
658
659 CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE);
660 pFormFiller->GetActionData(pPageView, CPDF_AAction::KeyStroke, fa);
661 pFormFiller->SaveState(pPageView);
662
663 PDFSDK_FieldAction faOld = fa;
664 pWidget->OnAAction(CPDF_AAction::KeyStroke, fa, pPageView);
665
666 bRC = fa.bRC;
667 m_bNotifying = FALSE;
668 }
669 }
670 }
671
672 void CFFL_IFormFiller::OnValidate(CPDFSDK_Widget* pWidget,
673 CPDFSDK_PageView* pPageView,
674 FX_BOOL& bRC,
675 FX_BOOL& bExit,
676 FX_DWORD nFlag) {
677 if (!m_bNotifying) {
678 if (pWidget->GetAAction(CPDF_AAction::Validate).GetDict()) {
679 m_bNotifying = TRUE;
680 pWidget->ClearAppModified();
681
682 ASSERT(pPageView);
683
684 PDFSDK_FieldAction fa;
685 fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
686 fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
687 fa.bKeyDown = TRUE;
688 fa.bRC = TRUE;
689
690 CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE);
691 pFormFiller->GetActionData(pPageView, CPDF_AAction::Validate, fa);
692 pFormFiller->SaveState(pPageView);
693
694 PDFSDK_FieldAction faOld = fa;
695 pWidget->OnAAction(CPDF_AAction::Validate, fa, pPageView);
696
697 bRC = fa.bRC;
698 m_bNotifying = FALSE;
699 }
700 }
701 }
702
703 void CFFL_IFormFiller::OnCalculate(CPDFSDK_Widget* pWidget,
704 CPDFSDK_PageView* pPageView,
705 FX_BOOL& bExit,
706 FX_DWORD nFlag) {
707 if (!m_bNotifying) {
708 ASSERT(pWidget);
709 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
710 CPDFSDK_InterForm* pInterForm =
711 (CPDFSDK_InterForm*)pDocument->GetInterForm();
712 pInterForm->OnCalculate(pWidget->GetFormField());
713
714 m_bNotifying = FALSE;
715 }
716 }
717
718 void CFFL_IFormFiller::OnFormat(CPDFSDK_Widget* pWidget,
719 CPDFSDK_PageView* pPageView,
720 FX_BOOL& bExit,
721 FX_DWORD nFlag) {
722 if (!m_bNotifying) {
723 ASSERT(pWidget);
724 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
725 CPDFSDK_InterForm* pInterForm =
726 (CPDFSDK_InterForm*)pDocument->GetInterForm();
727
728 FX_BOOL bFormated = FALSE;
729 CFX_WideString sValue =
730 pInterForm->OnFormat(pWidget->GetFormField(), bFormated);
731
732 if (bExit)
733 return;
734
735 if (bFormated) {
736 pInterForm->ResetFieldAppearance(pWidget->GetFormField(), sValue.c_str(),
737 TRUE);
738 pInterForm->UpdateField(pWidget->GetFormField());
739 }
740
741 m_bNotifying = FALSE;
742 }
743 }
744
745 #ifdef PDF_ENABLE_XFA
746 void CFFL_IFormFiller::OnClick(CPDFSDK_Widget* pWidget,
747 CPDFSDK_PageView* pPageView,
748 FX_BOOL& bReset,
749 FX_BOOL& bExit,
750 FX_UINT nFlag) {
751 if (!m_bNotifying) {
752 if (pWidget->HasXFAAAction(PDFSDK_XFA_Click)) {
753 m_bNotifying = TRUE;
754 int nAge = pWidget->GetAppearanceAge();
755 int nValueAge = pWidget->GetValueAge();
756
757 PDFSDK_FieldAction fa;
758 fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
759 fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
760
761 pWidget->OnXFAAAction(PDFSDK_XFA_Click, fa, pPageView);
762 m_bNotifying = FALSE;
763
764 if (!IsValidAnnot(pPageView, pWidget)) {
765 bExit = TRUE;
766 return;
767 }
768
769 if (nAge != pWidget->GetAppearanceAge()) {
770 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) {
771 pFormFiller->ResetPDFWindow(pPageView,
772 nValueAge == pWidget->GetValueAge());
773 }
774
775 bReset = TRUE;
776 }
777 }
778 }
779 }
780
781 void CFFL_IFormFiller::OnFull(CPDFSDK_Widget* pWidget,
782 CPDFSDK_PageView* pPageView,
783 FX_BOOL& bReset,
784 FX_BOOL& bExit,
785 FX_UINT nFlag) {
786 if (!m_bNotifying) {
787 if (pWidget->HasXFAAAction(PDFSDK_XFA_Full)) {
788 m_bNotifying = TRUE;
789 int nAge = pWidget->GetAppearanceAge();
790 int nValueAge = pWidget->GetValueAge();
791
792 PDFSDK_FieldAction fa;
793 fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
794 fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
795
796 pWidget->OnXFAAAction(PDFSDK_XFA_Full, fa, pPageView);
797 m_bNotifying = FALSE;
798
799 if (!IsValidAnnot(pPageView, pWidget)) {
800 bExit = TRUE;
801 return;
802 }
803
804 if (nAge != pWidget->GetAppearanceAge()) {
805 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) {
806 pFormFiller->ResetPDFWindow(pPageView,
807 nValueAge == pWidget->GetValueAge());
808 }
809
810 bReset = TRUE;
811 }
812 }
813 }
814 }
815
816 void CFFL_IFormFiller::OnPopupPreOpen(void* pPrivateData,
817 FX_BOOL& bExit,
818 FX_DWORD nFlag) {
819 CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;
820 ASSERT(pData);
821 ASSERT(pData->pWidget);
822
823 FX_BOOL bTempReset = FALSE;
824 FX_BOOL bTempExit = FALSE;
825 OnPreOpen(pData->pWidget, pData->pPageView, bTempReset, bTempExit, nFlag);
826
827 if (bTempReset || bTempExit) {
828 bExit = TRUE;
829 }
830 }
831
832 void CFFL_IFormFiller::OnPopupPostOpen(void* pPrivateData,
833 FX_BOOL& bExit,
834 FX_DWORD nFlag) {
835 CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;
836 ASSERT(pData);
837 ASSERT(pData->pWidget);
838
839 FX_BOOL bTempReset = FALSE;
840 FX_BOOL bTempExit = FALSE;
841 OnPostOpen(pData->pWidget, pData->pPageView, bTempReset, bTempExit, nFlag);
842
843 if (bTempReset || bTempExit) {
844 bExit = TRUE;
845 }
846 }
847
848 void CFFL_IFormFiller::OnPreOpen(CPDFSDK_Widget* pWidget,
849 CPDFSDK_PageView* pPageView,
850 FX_BOOL& bReset,
851 FX_BOOL& bExit,
852 FX_UINT nFlag) {
853 if (!m_bNotifying) {
854 if (pWidget->HasXFAAAction(PDFSDK_XFA_PreOpen)) {
855 m_bNotifying = TRUE;
856 int nAge = pWidget->GetAppearanceAge();
857 int nValueAge = pWidget->GetValueAge();
858
859 PDFSDK_FieldAction fa;
860 fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
861 fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
862
863 pWidget->OnXFAAAction(PDFSDK_XFA_PreOpen, fa, pPageView);
864 m_bNotifying = FALSE;
865
866 if (!IsValidAnnot(pPageView, pWidget)) {
867 bExit = TRUE;
868 return;
869 }
870
871 if (nAge != pWidget->GetAppearanceAge()) {
872 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) {
873 pFormFiller->ResetPDFWindow(pPageView,
874 nValueAge == pWidget->GetValueAge());
875 }
876
877 bReset = TRUE;
878 }
879 }
880 }
881 }
882
883 void CFFL_IFormFiller::OnPostOpen(CPDFSDK_Widget* pWidget,
884 CPDFSDK_PageView* pPageView,
885 FX_BOOL& bReset,
886 FX_BOOL& bExit,
887 FX_UINT nFlag) {
888 if (!m_bNotifying) {
889 if (pWidget->HasXFAAAction(PDFSDK_XFA_PostOpen)) {
890 m_bNotifying = TRUE;
891 int nAge = pWidget->GetAppearanceAge();
892 int nValueAge = pWidget->GetValueAge();
893
894 PDFSDK_FieldAction fa;
895 fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
896 fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
897
898 pWidget->OnXFAAAction(PDFSDK_XFA_PostOpen, fa, pPageView);
899 m_bNotifying = FALSE;
900
901 if (!IsValidAnnot(pPageView, pWidget)) {
902 bExit = TRUE;
903 return;
904 }
905
906 if (nAge != pWidget->GetAppearanceAge()) {
907 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE)) {
908 pFormFiller->ResetPDFWindow(pPageView,
909 nValueAge == pWidget->GetValueAge());
910 }
911
912 bReset = TRUE;
913 }
914 }
915 }
916 }
917 #endif // PDF_ENABLE_XFA
918
919 FX_BOOL CFFL_IFormFiller::IsValidAnnot(CPDFSDK_PageView* pPageView,
920 CPDFSDK_Annot* pAnnot) {
921 if (pPageView)
922 return pPageView->IsValidAnnot(pAnnot->GetPDFAnnot());
923
924 return FALSE;
925 }
926
927 void CFFL_IFormFiller::OnBeforeKeyStroke(void* pPrivateData,
928 CFX_WideString& strChange,
929 const CFX_WideString& strChangeEx,
930 int nSelStart,
931 int nSelEnd,
932 FX_BOOL bKeyDown,
933 FX_BOOL& bRC,
934 FX_BOOL& bExit,
935 FX_DWORD nFlag) {
936 CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;
937 ASSERT(pData->pWidget);
938
939 CFFL_FormFiller* pFormFiller = GetFormFiller(pData->pWidget, FALSE);
940
941 #ifdef PDF_ENABLE_XFA
942 if (pFormFiller->IsFieldFull(pData->pPageView)) {
943 FX_BOOL bFullExit = FALSE;
944 FX_BOOL bFullReset = FALSE;
945 OnFull(pData->pWidget, pData->pPageView, bFullReset, bFullExit, nFlag);
946
947 if (bFullReset || bFullExit) {
948 bExit = TRUE;
949 return;
950 }
951 }
952 #endif // PDF_ENABLE_XFA
953
954 if (!m_bNotifying) {
955 if (pData->pWidget->GetAAction(CPDF_AAction::KeyStroke).GetDict()) {
956 m_bNotifying = TRUE;
957 int nAge = pData->pWidget->GetAppearanceAge();
958 int nValueAge = pData->pWidget->GetValueAge();
959
960 CPDFSDK_Document* pDocument = pData->pPageView->GetSDKDocument();
961
962 PDFSDK_FieldAction fa;
963 fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
964 fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
965 fa.sChange = strChange;
966 fa.sChangeEx = strChangeEx;
967 fa.bKeyDown = bKeyDown;
968 fa.bWillCommit = FALSE;
969 fa.bRC = TRUE;
970 fa.nSelStart = nSelStart;
971 fa.nSelEnd = nSelEnd;
972
973 pFormFiller->GetActionData(pData->pPageView, CPDF_AAction::KeyStroke, fa);
974 pFormFiller->SaveState(pData->pPageView);
975
976 if (pData->pWidget->OnAAction(CPDF_AAction::KeyStroke, fa,
977 pData->pPageView)) {
978 if (!IsValidAnnot(pData->pPageView, pData->pWidget)) {
979 bExit = TRUE;
980 m_bNotifying = FALSE;
981 return;
982 }
983
984 if (nAge != pData->pWidget->GetAppearanceAge()) {
985 CPWL_Wnd* pWnd = pFormFiller->ResetPDFWindow(
986 pData->pPageView, nValueAge == pData->pWidget->GetValueAge());
987 pData = (CFFL_PrivateData*)pWnd->GetAttachedData();
988 bExit = TRUE;
989 }
990
991 if (fa.bRC) {
992 pFormFiller->SetActionData(pData->pPageView, CPDF_AAction::KeyStroke,
993 fa);
994 bRC = FALSE;
995 } else {
996 pFormFiller->RestoreState(pData->pPageView);
997 bRC = FALSE;
998 }
999
1000 if (pDocument->GetFocusAnnot() != pData->pWidget) {
1001 pFormFiller->CommitData(pData->pPageView, nFlag);
1002 bExit = TRUE;
1003 }
1004 } else {
1005 if (!IsValidAnnot(pData->pPageView, pData->pWidget)) {
1006 bExit = TRUE;
1007 m_bNotifying = FALSE;
1008 return;
1009 }
1010 }
1011
1012 m_bNotifying = FALSE;
1013 }
1014 }
1015 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/formfiller/FFL_FormFiller.cpp ('k') | fpdfsdk/src/formfiller/FFL_ListBox.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698