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

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

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

Powered by Google App Engine
This is Rietveld 408576698