Initial commit.
[pdfium.git] / fpdfsdk / src / formfiller / FFL_IFormFiller.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4  \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "../../include/formfiller/FFL_FormFiller.h"\r
8 #include "../../include/formfiller/FFL_IFormFiller.h"\r
9 #include "../../include/formfiller/FFL_CheckBox.h"\r
10 #include "../../include/formfiller/FFL_ComboBox.h"\r
11 #include "../../include/formfiller/FFL_ListBox.h"\r
12 #include "../../include/formfiller/FFL_PushButton.h"\r
13 #include "../../include/formfiller/FFL_RadioButton.h"\r
14 #include "../../include/formfiller/FFL_TextField.h"\r
15 \r
16 #define FFL_MAXLISTBOXHEIGHT            140.0f\r
17 \r
18 // HHOOK CFFL_IFormFiller::m_hookSheet = NULL;\r
19 // MSG CFFL_IFormFiller::g_Msg;\r
20 \r
21 /* ----------------------------- CFFL_IFormFiller ----------------------------- */\r
22 \r
23 CFFL_IFormFiller::CFFL_IFormFiller(CPDFDoc_Environment* pApp) : \r
24         m_pApp(pApp),\r
25         m_bNotifying(FALSE)\r
26 {\r
27 }\r
28 \r
29 CFFL_IFormFiller::~CFFL_IFormFiller()\r
30 {\r
31         FX_POSITION pos = m_Maps.GetStartPosition();\r
32         while (pos)\r
33         {\r
34                 CPDFSDK_Annot * pAnnot = NULL;\r
35                 CFFL_FormFiller * pFormFiller = NULL;\r
36                 m_Maps.GetNextAssoc(pos,pAnnot,pFormFiller);\r
37                 delete pFormFiller;\r
38         }\r
39         m_Maps.RemoveAll();\r
40 }\r
41 \r
42 FX_BOOL CFFL_IFormFiller::Annot_HitTest(CPDFSDK_PageView* pPageView,CPDFSDK_Annot* pAnnot, CPDF_Point point)\r
43 {\r
44         CPDF_Rect rc = pAnnot->GetRect();\r
45         if(rc.Contains(point.x, point.y))\r
46                 return TRUE;\r
47         return FALSE;\r
48 }\r
49 \r
50 FX_RECT CFFL_IFormFiller::GetViewBBox(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot)\r
51 {\r
52         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))\r
53         {\r
54                 return pFormFiller->GetViewBBox(pPageView, pAnnot);\r
55         }\r
56         else\r
57         {\r
58                 ASSERT(pPageView != NULL);\r
59                 ASSERT(pAnnot != NULL);\r
60 \r
61                 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();\r
62                 ASSERT(pPDFAnnot != NULL);\r
63 \r
64                 CPDF_Rect rcAnnot;\r
65                 pPDFAnnot->GetRect(rcAnnot);\r
66 \r
67 //              CRect rcWin;\r
68 //              pPageView->DocToWindow(rcAnnot, rcWin);\r
69                 CPDF_Rect rcWin = CPWL_Utils::InflateRect(rcAnnot,1);\r
70 //              rcWin.InflateRect(1, 1);\r
71 \r
72                 return rcWin.GetOutterRect();\r
73         }\r
74 }\r
75 \r
76 void CFFL_IFormFiller::OnDraw(CPDFSDK_PageView* pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot, \r
77                                                 CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,\r
78                                                 /*const CRect& rcWindow,*/ FX_DWORD dwFlags)\r
79 {\r
80         ASSERT(pPageView != NULL);\r
81         CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;\r
82 \r
83         if (IsVisible(pWidget))\r
84         {\r
85                 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))\r
86                 {\r
87                         if (pFormFiller->IsValid())\r
88                         {\r
89                                 pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);\r
90                                 \r
91                                 pAnnot->GetPDFPage();\r
92                                 \r
93 \r
94                                 CPDFSDK_Document* pDocument = m_pApp->GetCurrentDoc();\r
95                                 ASSERT(pDocument != NULL);\r
96 \r
97                                 if (pDocument->GetFocusAnnot() == pAnnot)\r
98                                 {\r
99                                         CPDF_Rect rcFocus = pFormFiller->GetFocusBox(pPageView);\r
100                                         if (!rcFocus.IsEmpty())\r
101                                         {\r
102                                                 CFX_PathData path;\r
103                                                 \r
104                                                 path.SetPointCount(5);\r
105                                                 path.SetPoint(0, rcFocus.left,  rcFocus.top, FXPT_MOVETO);\r
106                                                 path.SetPoint(1, rcFocus.left,  rcFocus.bottom, FXPT_LINETO);\r
107                                                 path.SetPoint(2, rcFocus.right,  rcFocus.bottom, FXPT_LINETO);\r
108                                                 path.SetPoint(3, rcFocus.right,  rcFocus.top, FXPT_LINETO);\r
109                                                 path.SetPoint(4, rcFocus.left,  rcFocus.top, FXPT_LINETO);\r
110                                                 \r
111                                                 CFX_GraphStateData gsd;\r
112                                                 gsd.SetDashCount(1);                            \r
113                                                 gsd.m_DashArray[0] = 1.0f;\r
114                                                 gsd.m_DashPhase = 0;    \r
115                                                 \r
116                                                 gsd.m_LineWidth = 1.0f;\r
117                                                 pDevice->DrawPath(&path, pUser2Device, &gsd, 0, ArgbEncode(255,0,0,0), FXFILL_ALTERNATE);\r
118 \r
119                                         //      ::DrawFocusRect(hDC, &rcFocus); \r
120                                         }\r
121                                 }\r
122 \r
123                                 return;\r
124                         }\r
125                 }\r
126 \r
127                 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))\r
128                         pFormFiller->OnDrawDeactive(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);\r
129                 else\r
130                         pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);\r
131 \r
132                 if (!IsReadOnly(pWidget) && IsFillingAllowed(pWidget))\r
133                 {\r
134                         pWidget->DrawShadow(pDevice, pPageView);\r
135                 }\r
136         \r
137         }\r
138 }\r
139 \r
140 void CFFL_IFormFiller::OnCreate(CPDFSDK_Annot* pAnnot)\r
141 {\r
142         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))\r
143         {\r
144                 pFormFiller->OnCreate(pAnnot);\r
145         }\r
146 }\r
147 \r
148 void CFFL_IFormFiller::OnLoad(CPDFSDK_Annot* pAnnot)\r
149 {\r
150         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))\r
151         {\r
152                 pFormFiller->OnLoad(pAnnot);\r
153         }\r
154 }\r
155 \r
156 void CFFL_IFormFiller::OnDelete(CPDFSDK_Annot* pAnnot)\r
157 {\r
158         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))\r
159         {\r
160                 pFormFiller->OnDelete(pAnnot);\r
161         }\r
162 \r
163         UnRegisterFormFiller(pAnnot);\r
164 }\r
165 \r
166 void CFFL_IFormFiller::OnMouseEnter(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlag)\r
167 {\r
168         ASSERT(pAnnot != NULL);\r
169         ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");\r
170         \r
171         if (!m_bNotifying)\r
172         {\r
173                 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;\r
174                 if (pWidget->GetAAction(CPDF_AAction::CursorEnter))\r
175                 {\r
176                         m_bNotifying = TRUE;\r
177                         \r
178                         int nValueAge = pWidget->GetValueAge();\r
179 \r
180                         pWidget->ClearAppModified();\r
181                         \r
182                         ASSERT(pPageView != NULL);\r
183                         \r
184                         \r
185                         \r
186                         PDFSDK_FieldAction fa;\r
187                         fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);\r
188                         fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);\r
189                         pWidget->OnAAction(CPDF_AAction::CursorEnter, fa, pPageView );\r
190                         m_bNotifying = FALSE;\r
191                         \r
192                         //if ( !IsValidAnnot(pPageView, pAnnot) ) return;\r
193                         \r
194                         if (pWidget->IsAppModified())\r
195                         {\r
196                                 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE))\r
197                                 {\r
198                                         pFormFiller->ResetPDFWindow(pPageView, pWidget->GetValueAge() == nValueAge);\r
199                                 }\r
200                         }\r
201                 }\r
202         }\r
203         \r
204         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, TRUE))\r
205         {\r
206                 pFormFiller->OnMouseEnter(pPageView, pAnnot);\r
207         }\r
208 }\r
209 \r
210 void CFFL_IFormFiller::OnMouseExit(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlag)\r
211 {\r
212         ASSERT(pAnnot != NULL);\r
213         ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");\r
214         \r
215         if (!m_bNotifying)\r
216         {\r
217                 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;\r
218                 if (pWidget->GetAAction(CPDF_AAction::CursorExit))\r
219                 {\r
220                         m_bNotifying = TRUE;\r
221                         pWidget->GetAppearanceAge();\r
222                         int nValueAge = pWidget->GetValueAge();\r
223                         pWidget->ClearAppModified();\r
224                         \r
225                         ASSERT(pPageView != NULL);\r
226                         \r
227                         \r
228                         \r
229                         PDFSDK_FieldAction fa;\r
230                         fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);\r
231                         fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);\r
232                         \r
233                         pWidget->OnAAction(CPDF_AAction::CursorExit, fa, pPageView);\r
234                         m_bNotifying = FALSE;\r
235                         \r
236                         //if (!IsValidAnnot(pPageView, pAnnot)) return;\r
237                         \r
238                         if (pWidget->IsAppModified())\r
239                         {\r
240                                 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE))\r
241                                 {\r
242                                         pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());\r
243                                 }\r
244                         }\r
245                 }\r
246         }\r
247         \r
248         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))\r
249         {\r
250                 pFormFiller->OnMouseExit(pPageView, pAnnot);\r
251         }\r
252 }\r
253 \r
254 FX_BOOL CFFL_IFormFiller::OnLButtonDown(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)\r
255 {\r
256         ASSERT(pAnnot != NULL);\r
257         ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");\r
258         \r
259         if (!m_bNotifying)\r
260         {\r
261                 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;\r
262                 if (Annot_HitTest(pPageView, pAnnot, point) && pWidget->GetAAction(CPDF_AAction::ButtonDown))\r
263                 {\r
264                         m_bNotifying = TRUE;\r
265                         pWidget->GetAppearanceAge();\r
266                         int nValueAge = pWidget->GetValueAge();\r
267                         pWidget->ClearAppModified();\r
268                         \r
269                         ASSERT(pPageView != NULL);\r
270                         \r
271                         \r
272                         \r
273                         PDFSDK_FieldAction fa;\r
274                         fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlags);\r
275                         fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlags);\r
276                         pWidget->OnAAction(CPDF_AAction::ButtonDown, fa, pPageView);\r
277                         m_bNotifying = FALSE;\r
278                         \r
279                         if (!IsValidAnnot(pPageView, pAnnot)) return TRUE;\r
280                         \r
281                         if (pWidget->IsAppModified())\r
282                         {\r
283                                 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE))\r
284                                 {\r
285                                         pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());\r
286                                 }\r
287                         }\r
288                 }\r
289         }\r
290         \r
291         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))\r
292         {\r
293                 return pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point);\r
294         }\r
295         \r
296         return FALSE;\r
297 }\r
298 \r
299 FX_BOOL CFFL_IFormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)\r
300 {\r
301         ASSERT(pAnnot != NULL);\r
302         ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");\r
303         \r
304         CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;\r
305         //      CReader_Page* pPage = pAnnot->GetPage();\r
306         //      ASSERT(pPage != NULL);\r
307         CPDFSDK_Document* pDocument = m_pApp->GetCurrentDoc();\r
308         ASSERT(pDocument != NULL);              \r
309         \r
310         switch (pWidget->GetFieldType())\r
311         {\r
312         case FIELDTYPE_PUSHBUTTON:\r
313         case FIELDTYPE_CHECKBOX:\r
314         case FIELDTYPE_RADIOBUTTON:\r
315                 if (GetViewBBox(pPageView, pAnnot).Contains((int)point.x, (int)point.y))\r
316                 {\r
317                         pDocument->SetFocusAnnot(pAnnot);\r
318                 }\r
319                 break;\r
320         default:\r
321                 pDocument->SetFocusAnnot(pAnnot);\r
322                 break;\r
323         }\r
324         \r
325         FX_BOOL bRet = FALSE;\r
326         \r
327         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))\r
328         {\r
329                 bRet = pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point);\r
330         }\r
331 \r
332         if (pDocument->GetFocusAnnot() == pAnnot)\r
333         {\r
334                 FX_BOOL bExit = FALSE;\r
335                 FX_BOOL bReset = FALSE;\r
336                 OnButtonUp(pWidget, pPageView, bReset, bExit,nFlags);\r
337                 if (bExit) return TRUE;\r
338         }\r
339         return bRet;\r
340 }\r
341 \r
342 void CFFL_IFormFiller::OnButtonUp(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bReset, FX_BOOL& bExit,FX_UINT nFlag)\r
343 {\r
344         ASSERT(pWidget != NULL);\r
345         \r
346         if (!m_bNotifying)\r
347         {\r
348                 if (pWidget->GetAAction(CPDF_AAction::ButtonUp))\r
349                 {\r
350                         m_bNotifying = TRUE;\r
351                         int nAge = pWidget->GetAppearanceAge();\r
352                         int nValueAge = pWidget->GetValueAge();\r
353                         \r
354                         ASSERT(pPageView != NULL);\r
355 //                      CReader_DocView* pDocView = pPageView->GetDocView();\r
356 //                      ASSERT(pDocView != NULL);\r
357                         \r
358                         \r
359                         \r
360                         PDFSDK_FieldAction fa;\r
361                         fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);\r
362                         fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);\r
363 \r
364                         pWidget->OnAAction(CPDF_AAction::ButtonUp, fa, pPageView);\r
365                         m_bNotifying = FALSE;\r
366                         \r
367                         if (!IsValidAnnot(pPageView, pWidget))\r
368                         {\r
369                                 bExit = TRUE;\r
370                                 return;\r
371                         }\r
372                         \r
373                         if (nAge != pWidget->GetAppearanceAge())\r
374                         {\r
375                                 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE))\r
376                                 {\r
377                                         pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());\r
378                                 }\r
379                                 \r
380                                 bReset = TRUE;\r
381                         }\r
382                 }\r
383         }\r
384 }\r
385 \r
386 FX_BOOL CFFL_IFormFiller::OnLButtonDblClk(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)\r
387 {\r
388         ASSERT(pAnnot != NULL);\r
389         ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");\r
390 \r
391         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))\r
392         {\r
393                 return pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);\r
394         }\r
395 \r
396         return FALSE;\r
397 }\r
398 \r
399 FX_BOOL CFFL_IFormFiller::OnMouseMove(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)\r
400 {\r
401         ASSERT(pAnnot != NULL);\r
402         ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");\r
403 \r
404         //change cursor\r
405         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, TRUE))\r
406         {\r
407                 return pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point);\r
408         }\r
409 \r
410         return FALSE;\r
411 }\r
412 \r
413 FX_BOOL CFFL_IFormFiller::OnMouseWheel(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, short zDelta, const CPDF_Point& point)\r
414 {\r
415         ASSERT(pAnnot != NULL);\r
416         ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");\r
417 \r
418         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))\r
419         {\r
420                 return pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, point);\r
421         }\r
422 \r
423         return FALSE;\r
424 }\r
425 \r
426 FX_BOOL CFFL_IFormFiller::OnRButtonDown(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)\r
427 {\r
428         ASSERT(pAnnot != NULL);\r
429         ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");\r
430 \r
431         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))\r
432         {\r
433                 return pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point);\r
434         }\r
435 \r
436         return FALSE;\r
437 }\r
438 \r
439 FX_BOOL CFFL_IFormFiller::OnRButtonUp(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)\r
440 {\r
441         ASSERT(pAnnot != NULL);\r
442         ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");\r
443 \r
444         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))\r
445         {\r
446                 return pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point);\r
447         }\r
448 \r
449         return FALSE;\r
450 }\r
451 \r
452 FX_BOOL CFFL_IFormFiller::OnRButtonDblClk(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)\r
453 {\r
454         ASSERT(pAnnot != NULL);\r
455         ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");\r
456 \r
457         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))\r
458         {\r
459                 return pFormFiller->OnRButtonDblClk(pPageView, pAnnot, nFlags, point);\r
460         }\r
461 \r
462         return FALSE;\r
463 }\r
464 \r
465 FX_BOOL CFFL_IFormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot, FX_UINT nKeyCode, FX_UINT nFlags)\r
466 {\r
467         ASSERT(pAnnot != NULL);\r
468         ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");\r
469 \r
470         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))\r
471         {\r
472                 return pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlags);        \r
473         }\r
474 \r
475         return FALSE;\r
476 }\r
477 \r
478 FX_BOOL CFFL_IFormFiller::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)\r
479 {\r
480         ASSERT(pAnnot != NULL);\r
481         ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");\r
482 \r
483         if (nChar == FWL_VKEY_Tab) return TRUE;\r
484 \r
485         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))\r
486         {\r
487                 return pFormFiller->OnChar(pAnnot, nChar, nFlags);\r
488         }\r
489 \r
490         return FALSE;\r
491 }\r
492 \r
493 void CFFL_IFormFiller::OnDeSelected(CPDFSDK_Annot* pAnnot)\r
494 {\r
495         ASSERT(pAnnot != NULL);\r
496         ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");\r
497 \r
498         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))\r
499         {\r
500                 pFormFiller->OnDeSelected(pAnnot);\r
501         }\r
502 }\r
503 \r
504 void CFFL_IFormFiller::OnSelected(CPDFSDK_Annot* pAnnot)\r
505 {\r
506         ASSERT(pAnnot != NULL);\r
507         ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");\r
508 \r
509         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))\r
510         {\r
511                 pFormFiller->OnSelected(pAnnot);\r
512         }\r
513 }\r
514 \r
515 FX_BOOL CFFL_IFormFiller::OnSetFocus(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)\r
516 {\r
517         if(!pAnnot) return FALSE;\r
518         ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");\r
519 \r
520         if (!m_bNotifying)\r
521         {\r
522                 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;\r
523                 if (pWidget->GetAAction(CPDF_AAction::GetFocus))\r
524                 {\r
525                         m_bNotifying = TRUE;\r
526                         pWidget->GetAppearanceAge();\r
527                         int nValueAge = pWidget->GetValueAge();\r
528                         pWidget->ClearAppModified();\r
529  \r
530  \r
531                         CPDFSDK_PageView* pPageView = pAnnot->GetPageView();\r
532                         ASSERT(pPageView != NULL);\r
533                         \r
534                         PDFSDK_FieldAction fa;\r
535                         fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);\r
536                         fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);\r
537 \r
538  \r
539                         CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, TRUE);\r
540                         if(!pFormFiller) return FALSE;\r
541                         pFormFiller->GetActionData(pPageView, CPDF_AAction::GetFocus, fa);\r
542  \r
543                         pWidget->OnAAction(CPDF_AAction::GetFocus, fa, pPageView);\r
544                         m_bNotifying = FALSE;\r
545                         \r
546  //                     if (!IsValidAnnot(m_pApp, pDocument, pDocView, pPageView, pAnnot)) return FALSE;\r
547  \r
548                         if (pWidget->IsAppModified())\r
549                         {\r
550                                 if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE))\r
551                                 {\r
552                                         pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());\r
553                                 }\r
554                         }\r
555                 }\r
556         }\r
557         \r
558         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, TRUE))\r
559         {\r
560                 if (pFormFiller->OnSetFocus(pAnnot, nFlag))\r
561                 {\r
562                         return TRUE;\r
563                 }\r
564                 else\r
565                         return FALSE;\r
566         }\r
567 \r
568         return TRUE;\r
569 }\r
570 \r
571 FX_BOOL CFFL_IFormFiller::OnKillFocus(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)\r
572 {\r
573         if(!pAnnot) return FALSE;\r
574         ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");\r
575 \r
576         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))\r
577         {\r
578                 if (pFormFiller->OnKillFocus(pAnnot, nFlag))\r
579                 {\r
580                         if (!m_bNotifying)\r
581                         {\r
582                                 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;\r
583                                 if (pWidget->GetAAction(CPDF_AAction::LoseFocus))\r
584                                 {\r
585                                         m_bNotifying = TRUE;\r
586                                         pWidget->ClearAppModified();\r
587  \r
588                                         CPDFSDK_PageView* pPageView = pWidget->GetPageView();\r
589                                         ASSERT(pPageView != NULL);\r
590  \r
591                                         PDFSDK_FieldAction fa;\r
592                                         fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);\r
593                                         fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);\r
594  \r
595                                         pFormFiller->GetActionData(pPageView, CPDF_AAction::LoseFocus, fa);\r
596  \r
597                                         pWidget->OnAAction(CPDF_AAction::LoseFocus, fa, pPageView);\r
598                                         m_bNotifying = FALSE;\r
599  \r
600                                 }\r
601                         }\r
602                 }\r
603                 else\r
604                         return FALSE;\r
605         }\r
606 \r
607         return TRUE;\r
608 }\r
609 \r
610 FX_BOOL CFFL_IFormFiller::IsVisible(CPDFSDK_Widget* pWidget)\r
611 {\r
612         return pWidget->IsVisible();\r
613 }\r
614 \r
615 FX_BOOL CFFL_IFormFiller::IsReadOnly(CPDFSDK_Widget* pWidget)\r
616 {\r
617         ASSERT(pWidget != NULL);\r
618 \r
619         int nFieldFlags = pWidget->GetFieldFlags();\r
620 \r
621         return (nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY;\r
622 }\r
623 \r
624 FX_BOOL CFFL_IFormFiller::IsFillingAllowed(CPDFSDK_Widget* pWidget)\r
625 {\r
626         ASSERT(pWidget != NULL);\r
627 \r
628         if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON)\r
629                 return TRUE;\r
630         else\r
631         {\r
632                 CPDF_Page* pPage = pWidget->GetPDFPage();\r
633                 ASSERT(pPage != NULL);\r
634  \r
635                 CPDF_Document* pDocument = pPage->m_pDocument;\r
636                 ASSERT(pDocument != NULL);\r
637  \r
638                 FX_DWORD dwPermissions = pDocument->GetUserPermissions();\r
639                 return (dwPermissions&FPDFPERM_FILL_FORM) || \r
640                                 (dwPermissions&FPDFPERM_ANNOT_FORM) || \r
641                         (dwPermissions&FPDFPERM_MODIFY);\r
642         }\r
643         return TRUE;    \r
644 }\r
645 \r
646 CFFL_FormFiller* CFFL_IFormFiller::GetFormFiller(CPDFSDK_Annot* pAnnot, FX_BOOL bRegister)\r
647 {\r
648 //      ASSERT(pAnnot != NULL);\r
649 //      ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");\r
650 \r
651         CFFL_FormFiller * pFormFiller = NULL;\r
652         m_Maps.Lookup(pAnnot, pFormFiller);\r
653 \r
654         if (pFormFiller)\r
655                 return pFormFiller;\r
656 \r
657         if (bRegister)\r
658         {\r
659                 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;              \r
660 \r
661                 int nFieldType = pWidget->GetFieldType();\r
662                 switch(nFieldType)\r
663                 {\r
664                 case FIELDTYPE_PUSHBUTTON:\r
665                         pFormFiller = new CFFL_PushButton(m_pApp, pWidget);\r
666                         break;\r
667                 case FIELDTYPE_CHECKBOX:\r
668                         pFormFiller = new CFFL_CheckBox(m_pApp, pWidget);\r
669                         break;\r
670                 case FIELDTYPE_RADIOBUTTON:\r
671                         pFormFiller = new CFFL_RadioButton(m_pApp, pWidget);\r
672                         break;\r
673                 case FIELDTYPE_TEXTFIELD:\r
674                         pFormFiller = new CFFL_TextField(m_pApp, pWidget);\r
675                         break;\r
676                 case FIELDTYPE_LISTBOX:\r
677                         pFormFiller = new CFFL_ListBox(m_pApp, pWidget);\r
678                         break;\r
679                 case FIELDTYPE_COMBOBOX:\r
680                         pFormFiller = new CFFL_ComboBox(m_pApp, pWidget);\r
681                         break;\r
682                 case FIELDTYPE_UNKNOWN:\r
683                 default:\r
684                         pFormFiller = NULL;\r
685                         break;\r
686                 }\r
687 \r
688                 if (pFormFiller)\r
689                 {\r
690                         m_Maps.SetAt(pAnnot, pFormFiller);\r
691                 }\r
692         }\r
693 \r
694         return pFormFiller;\r
695 }\r
696 \r
697 void CFFL_IFormFiller::RemoveFormFiller(CPDFSDK_Annot* pAnnot)\r
698 {\r
699         if ( pAnnot != NULL )\r
700         {\r
701                 UnRegisterFormFiller( pAnnot );\r
702         }\r
703 }\r
704 \r
705 void CFFL_IFormFiller::UnRegisterFormFiller(CPDFSDK_Annot* pAnnot)\r
706 {\r
707         CFFL_FormFiller * pFormFiller = NULL;\r
708 \r
709         if (m_Maps.Lookup(pAnnot,pFormFiller))\r
710         {\r
711                 if (pFormFiller)\r
712                         delete pFormFiller;\r
713                 m_Maps.RemoveKey(pAnnot);\r
714         }\r
715 }\r
716 \r
717 void CFFL_IFormFiller::SetFocusAnnotTab(CPDFSDK_Annot* pWidget, FX_BOOL bSameField, FX_BOOL bNext)\r
718 {\r
719 \r
720 }\r
721 \r
722 void CFFL_IFormFiller::QueryWherePopup(void* pPrivateData, FX_FLOAT fPopupMin,FX_FLOAT fPopupMax, FX_INT32 & nRet, FX_FLOAT & fPopupRet)\r
723 {\r
724         ASSERT(pPrivateData != NULL);\r
725 \r
726         CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;\r
727 \r
728         \r
729 \r
730 \r
731         CPDF_Rect rcPageView(0,0,0,0);\r
732         rcPageView.right = pData->pWidget->GetPDFPage()->GetPageWidth();\r
733         rcPageView.bottom = pData->pWidget->GetPDFPage()->GetPageHeight();\r
734         rcPageView.Normalize();\r
735 \r
736 \r
737         ASSERT(pData->pWidget != NULL);\r
738         CPDF_Rect rcAnnot = pData->pWidget->GetRect();\r
739 \r
740         FX_FLOAT fTop = 0.0f;\r
741         FX_FLOAT fBottom = 0.0f;\r
742 \r
743         CPDFSDK_Widget * pWidget = (CPDFSDK_Widget*)pData->pWidget;\r
744         switch (pWidget->GetRotate() / 90)\r
745         {\r
746         default:\r
747         case 0:\r
748                 fTop = rcPageView.top - rcAnnot.top;\r
749                 fBottom = rcAnnot.bottom - rcPageView.bottom;\r
750                 break;\r
751         case 1:\r
752                 fTop = rcAnnot.left - rcPageView.left;\r
753                 fBottom = rcPageView.right - rcAnnot.right;\r
754                 break;\r
755         case 2:\r
756                 fTop = rcAnnot.bottom - rcPageView.bottom;\r
757                 fBottom = rcPageView.top - rcAnnot.top;\r
758                 break;\r
759         case 3:\r
760                 fTop = rcPageView.right - rcAnnot.right;\r
761                 fBottom = rcAnnot.left - rcPageView.left;\r
762                 break;\r
763         }\r
764 \r
765         FX_FLOAT fFactHeight = 0;\r
766         FX_BOOL bBottom = TRUE;\r
767         FX_FLOAT fMaxListBoxHeight = 0;\r
768         if (fPopupMax > FFL_MAXLISTBOXHEIGHT)\r
769         {\r
770                 if (fPopupMin > FFL_MAXLISTBOXHEIGHT)\r
771                 {\r
772                         fMaxListBoxHeight = fPopupMin;\r
773                 }\r
774                 else\r
775                 {\r
776                         fMaxListBoxHeight = FFL_MAXLISTBOXHEIGHT;\r
777                 }\r
778         }\r
779         else\r
780                 fMaxListBoxHeight = fPopupMax;\r
781 \r
782         if (fBottom > fMaxListBoxHeight)\r
783         {\r
784                 fFactHeight = fMaxListBoxHeight;\r
785                 bBottom = TRUE;\r
786         }\r
787         else\r
788         {\r
789                 if (fTop > fMaxListBoxHeight)\r
790                 {\r
791                         fFactHeight = fMaxListBoxHeight;\r
792                         bBottom = FALSE;\r
793                 }\r
794                 else\r
795                 {\r
796                         if (fTop > fBottom)\r
797                         {\r
798                                 fFactHeight = fTop;\r
799                                 bBottom = FALSE;\r
800                         }\r
801                         else\r
802                         {\r
803                                 fFactHeight = fBottom;\r
804                                 bBottom = TRUE;\r
805                         }\r
806                 }\r
807         }\r
808 \r
809         nRet = bBottom ? 0 : 1;\r
810         fPopupRet = fFactHeight;\r
811 }\r
812 \r
813 void CFFL_IFormFiller::OnSetWindowRect(void* pPrivateData, const CPDF_Rect & rcWindow)\r
814 {\r
815         ASSERT(pPrivateData != NULL);\r
816 \r
817         CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;\r
818 \r
819         if (CFFL_FormFiller* pFormFiller = GetFormFiller(pData->pWidget, TRUE))\r
820         {\r
821 \r
822                 CPDF_Rect rcOld = pFormFiller->PWLtoFFL(pFormFiller->GetWindowRect(pData->pPageView));\r
823                 CPDF_Rect rcNew = pFormFiller->PWLtoFFL(rcWindow);\r
824                 pFormFiller->SetWindowRect(pData->pPageView, rcWindow);\r
825 \r
826                 CPDF_Rect unRect = rcOld;\r
827                 unRect.Union(rcNew);\r
828                 //FX_RECT rcRect = unRect.GetOutterRect();\r
829                 unRect.left = (FX_FLOAT)(unRect.left - 0.5);\r
830                 unRect.right = (FX_FLOAT)(unRect.right + 0.5);\r
831                 unRect.top = (FX_FLOAT)(unRect.top + 0.5);\r
832                 unRect.bottom = (FX_FLOAT)(unRect.bottom -0.5);\r
833                 m_pApp->FFI_Invalidate(pData->pWidget->GetPDFPage(), unRect.left, unRect.top, unRect.right, unRect.bottom);\r
834         }\r
835 }\r
836 \r
837 void CFFL_IFormFiller::OnKeyStroke(FX_BOOL bEditOrList, void* pPrivateData, FX_INT32 nKeyCode, CFX_WideString& strChange, \r
838                                                                    const CFX_WideString& strChangeEx, FX_BOOL bKeyDown, \r
839                                                                    FX_BOOL & bRC, FX_BOOL & bExit)\r
840 {\r
841         ASSERT(pPrivateData != NULL);\r
842         CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;\r
843         ASSERT(pData->pWidget != NULL);\r
844 \r
845         CFFL_FormFiller* pFormFiller = GetFormFiller(pData->pWidget, FALSE);\r
846         ASSERT(pFormFiller != NULL);\r
847 \r
848         pFormFiller->OnKeyStroke(bKeyDown);\r
849 }\r
850 \r
851 void CFFL_IFormFiller::OnKeyStrokeCommit(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bRC, FX_BOOL& bExit, FX_DWORD nFlag)\r
852 {\r
853         if (!m_bNotifying)\r
854         {\r
855                 ASSERT(pWidget != NULL);\r
856                 if (pWidget->GetAAction(CPDF_AAction::KeyStroke))\r
857                 {\r
858                         m_bNotifying = TRUE;\r
859                         pWidget->ClearAppModified();\r
860 \r
861                         ASSERT(pPageView != NULL);\r
862 //                      CReader_DocView* pDocView = pPageView->GetDocView();\r
863 //                      ASSERT(pDocView != NULL);\r
864                         \r
865                 \r
866 \r
867                         PDFSDK_FieldAction fa;\r
868                         fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);\r
869                         fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);\r
870                         fa.bWillCommit = TRUE;\r
871                         fa.nCommitKey = GetCommitKey();\r
872                         fa.bKeyDown = GetKeyDown();\r
873                         fa.bRC = TRUE;\r
874 \r
875                         CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE);\r
876                         ASSERT(pFormFiller != NULL);\r
877 \r
878                         pFormFiller->GetActionData(pPageView, CPDF_AAction::KeyStroke, fa);\r
879                         pFormFiller->SaveState(pPageView);\r
880 \r
881                         PDFSDK_FieldAction faOld = fa;\r
882                         pWidget->OnAAction(CPDF_AAction::KeyStroke, fa, pPageView);\r
883 \r
884                         bRC = fa.bRC;\r
885 //                      bExit = !IsValidAnnot(m_pApp, pDocument, pDocView, pPageView, pWidget);\r
886 \r
887                         m_bNotifying = FALSE;\r
888                 }\r
889         }\r
890 }\r
891 \r
892 void CFFL_IFormFiller::OnValidate(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bRC, FX_BOOL& bExit, FX_DWORD nFlag)\r
893 {\r
894         if (!m_bNotifying)\r
895         {\r
896                 ASSERT(pWidget != NULL);\r
897                 if (pWidget->GetAAction(CPDF_AAction::Validate))\r
898                 {\r
899                         m_bNotifying = TRUE;\r
900                         pWidget->ClearAppModified();\r
901 \r
902                         ASSERT(pPageView != NULL);\r
903 //                      CReader_DocView* pDocView = pPageView->GetDocView();\r
904 //                      ASSERT(pDocView != NULL);\r
905                         \r
906                         \r
907 \r
908                         PDFSDK_FieldAction fa;\r
909                         fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);\r
910                         fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);\r
911                         fa.bKeyDown = GetKeyDown();\r
912                         fa.bRC = TRUE;\r
913 \r
914                         CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE);\r
915                         ASSERT(pFormFiller != NULL);\r
916 \r
917                         pFormFiller->GetActionData(pPageView, CPDF_AAction::Validate, fa);\r
918                         pFormFiller->SaveState(pPageView);\r
919 \r
920                         PDFSDK_FieldAction faOld = fa;\r
921                         pWidget->OnAAction(CPDF_AAction::Validate, fa, pPageView);\r
922 \r
923                         bRC = fa.bRC;\r
924 //                      bExit = !IsValidAnnot(m_pApp, pDocument, pDocView, pPageView, pWidget);\r
925 \r
926                         m_bNotifying = FALSE;\r
927                 }\r
928         }\r
929 }\r
930 \r
931 void CFFL_IFormFiller::OnCalculate(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bExit, FX_DWORD nFlag)\r
932 {\r
933         if (!m_bNotifying)\r
934         {\r
935                 ASSERT(pWidget != NULL);\r
936                 ASSERT(pPageView != NULL);\r
937 //              CReader_DocView* pDocView = pPageView->GetDocView();\r
938 //              ASSERT(pDocView != NULL);\r
939                 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();\r
940                 ASSERT(pDocument != NULL);\r
941 \r
942                 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();\r
943                 ASSERT(pInterForm != NULL);\r
944 \r
945                 pInterForm->OnCalculate(pWidget->GetFormField());\r
946 \r
947 //              bExit = !IsValidAnnot(m_pApp, pDocument, pDocView, pPageView, pWidget);\r
948 \r
949                 m_bNotifying = FALSE;\r
950         }\r
951 }\r
952 \r
953 void CFFL_IFormFiller::OnFormat(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bExit, FX_DWORD nFlag)\r
954 {\r
955         if (!m_bNotifying)\r
956         {\r
957                 ASSERT(pWidget != NULL);\r
958                 ASSERT(pPageView != NULL);\r
959 //              CReader_DocView* pDocView = pPageView->GetDocView();\r
960 //              ASSERT(pDocView != NULL);\r
961                 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();\r
962                 ASSERT(pDocument != NULL);\r
963 \r
964                 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();\r
965                 ASSERT(pInterForm != NULL);\r
966 \r
967                 FX_BOOL bFormated = FALSE;\r
968                 CFX_WideString sValue = pInterForm->OnFormat(pWidget->GetFormField(), GetCommitKey(), bFormated);\r
969 \r
970 //              bExit = !IsValidAnnot(m_pApp, pDocument, pDocView, pPageView, pWidget);\r
971 \r
972                 if (bExit) return;\r
973 \r
974                 if (bFormated)\r
975                 {\r
976                         pInterForm->ResetFieldAppearance(pWidget->GetFormField(), sValue, TRUE);\r
977                         pInterForm->UpdateField(pWidget->GetFormField());\r
978                 }\r
979 \r
980                 m_bNotifying = FALSE;\r
981         }\r
982 }\r
983 \r
984 // LRESULT CALLBACK CFFL_IFormFiller::FFL_WndProc(\r
985 //                                                                        int code,       // hook code\r
986 //                                                                        WPARAM wParam,  // virtual-key code\r
987 //                                                                        LPARAM lParam   // keystroke-message information\r
988 //                                                                              )\r
989 // {\r
990 //      if (code != HC_ACTION)\r
991 //      {\r
992 //              return CallNextHookEx (m_hookSheet, code, wParam, lParam);\r
993 //      }\r
994 // \r
995 //      FXSYS_memcpy(&g_Msg, (void*)lParam, sizeof(MSG));       \r
996 // \r
997 //      return 0;\r
998 // }\r
999 \r
1000 // MSG  CFFL_IFormFiller::GetLastMessage()\r
1001 // {\r
1002 //      return g_Msg;\r
1003 // }\r
1004 \r
1005 int CFFL_IFormFiller::GetCommitKey()\r
1006 {\r
1007 //      MSG msg = CFFL_IFormFiller::GetLastMessage();\r
1008 \r
1009         int nCommitKey = 0;\r
1010 //      switch (msg.message)\r
1011 //      {\r
1012 //      case WM_LBUTTONDOWN:\r
1013 //      case WM_LBUTTONUP:\r
1014 //              nCommitKey = 1;\r
1015 //              break;\r
1016 //      case WM_KEYDOWN:\r
1017 //              switch (msg.wParam)\r
1018 //              {\r
1019 //              case VK_RETURN:\r
1020 //                      nCommitKey = 2;\r
1021 //                      break;\r
1022 //              case VK_TAB:\r
1023 //                      nCommitKey = 3;\r
1024 //                      break;\r
1025 //              }\r
1026 //              break;\r
1027 //      }\r
1028 \r
1029         return nCommitKey;\r
1030 }\r
1031 \r
1032 FX_BOOL CFFL_IFormFiller::GetKeyDown()\r
1033 {\r
1034         return TRUE;\r
1035 //      MSG msg = CFFL_IFormFiller::GetLastMessage();\r
1036 // \r
1037 //      return msg.message == WM_KEYDOWN || msg.message == WM_CHAR;\r
1038 }\r
1039 \r
1040 FX_BOOL CFFL_IFormFiller::IsValidAnnot(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot)\r
1041 {\r
1042 \r
1043         ASSERT(pPageView != NULL);\r
1044         ASSERT(pAnnot != NULL);\r
1045 \r
1046         if(pPageView)\r
1047                 return pPageView->IsValidAnnot(pAnnot->GetPDFAnnot());\r
1048         else\r
1049                 return FALSE;\r
1050 }\r
1051 \r
1052 void CFFL_IFormFiller::BeforeUndo(CPDFSDK_Document* pDocument)\r
1053 {\r
1054 \r
1055 }\r
1056 \r
1057 void CFFL_IFormFiller::BeforeRedo(CPDFSDK_Document* pDocument)\r
1058 {\r
1059         BeforeUndo(pDocument);\r
1060 }\r
1061 \r
1062 void CFFL_IFormFiller::AfterUndo(CPDFSDK_Document* pDocument)\r
1063 {\r
1064 }\r
1065 \r
1066 void CFFL_IFormFiller::AfterRedo(CPDFSDK_Document* pDocument)\r
1067 {\r
1068 }\r
1069 \r
1070 FX_BOOL CFFL_IFormFiller::CanCopy(CPDFSDK_Document* pDocument)\r
1071 {\r
1072 \r
1073         return FALSE;\r
1074 }\r
1075 \r
1076 FX_BOOL CFFL_IFormFiller::CanCut(CPDFSDK_Document* pDocument)\r
1077 {\r
1078 \r
1079         return FALSE;\r
1080 }\r
1081 \r
1082 FX_BOOL CFFL_IFormFiller::CanPaste(CPDFSDK_Document* pDocument)\r
1083 {\r
1084 \r
1085         return FALSE;\r
1086 }\r
1087 \r
1088 void CFFL_IFormFiller::DoCopy(CPDFSDK_Document* pDocument)\r
1089 {\r
1090 }\r
1091 \r
1092 void CFFL_IFormFiller::DoCut(CPDFSDK_Document* pDocument)\r
1093 {\r
1094 }\r
1095 \r
1096 void CFFL_IFormFiller::DoPaste(CPDFSDK_Document* pDocument)\r
1097 {\r
1098 \r
1099 }\r
1100 void CFFL_IFormFiller::OnBeforeKeyStroke(FX_BOOL bEditOrList, void* pPrivateData, FX_INT32 nKeyCode,\r
1101                                                                                           CFX_WideString & strChange, const CFX_WideString& strChangeEx, \r
1102                                                                                           int nSelStart, int nSelEnd,\r
1103                                                                                 FX_BOOL bKeyDown, FX_BOOL & bRC, FX_BOOL & bExit, FX_DWORD nFlag)\r
1104 {\r
1105         ASSERT(pPrivateData != NULL);\r
1106         CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;\r
1107         ASSERT(pData->pWidget != NULL);\r
1108         \r
1109         CFFL_FormFiller* pFormFiller = GetFormFiller(pData->pWidget, FALSE);\r
1110         ASSERT(pFormFiller != NULL);\r
1111         \r
1112         if (!m_bNotifying)\r
1113         {\r
1114                 if (pData->pWidget->GetAAction(CPDF_AAction::KeyStroke))\r
1115                 {\r
1116                         m_bNotifying = TRUE;\r
1117                         int nAge = pData->pWidget->GetAppearanceAge();\r
1118                         int nValueAge = pData->pWidget->GetValueAge();\r
1119 \r
1120                         ASSERT(pData->pPageView != NULL);\r
1121                         CPDFSDK_Document* pDocument  = pData->pPageView->GetSDKDocument();\r
1122                         \r
1123                         PDFSDK_FieldAction fa;\r
1124                         fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);\r
1125                         fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);\r
1126                         fa.sChange = strChange;\r
1127                         fa.sChangeEx = strChangeEx;\r
1128                         fa.bKeyDown = bKeyDown;\r
1129                         fa.bWillCommit = FALSE;\r
1130                         fa.bRC = TRUE;\r
1131                         fa.nSelStart = nSelStart;\r
1132                         fa.nSelEnd = nSelEnd;\r
1133 \r
1134 \r
1135                         pFormFiller->GetActionData(pData->pPageView, CPDF_AAction::KeyStroke, fa);\r
1136                         pFormFiller->SaveState(pData->pPageView);\r
1137                         \r
1138                         if (pData->pWidget->OnAAction(CPDF_AAction::KeyStroke, fa, pData->pPageView))\r
1139                         {\r
1140                                 if (!IsValidAnnot(pData->pPageView, pData->pWidget))\r
1141                                 {\r
1142                                         bExit = TRUE;\r
1143                                         m_bNotifying = FALSE;\r
1144                                         return;\r
1145                                 }\r
1146                                 \r
1147                                 if (nAge != pData->pWidget->GetAppearanceAge())\r
1148                                 {\r
1149                                         CPWL_Wnd* pWnd = pFormFiller->ResetPDFWindow(pData->pPageView, nValueAge == pData->pWidget->GetValueAge());\r
1150                                         pData = (CFFL_PrivateData*)pWnd->GetAttachedData();\r
1151                                         bExit = TRUE;\r
1152                                 }\r
1153                                 \r
1154                                 if (fa.bRC)\r
1155                                 {\r
1156                                         pFormFiller->SetActionData(pData->pPageView, CPDF_AAction::KeyStroke, fa);\r
1157                                         bRC = FALSE;\r
1158                                 }\r
1159                                 else\r
1160                                 {\r
1161                                         pFormFiller->RestoreState(pData->pPageView);\r
1162                                         bRC = FALSE;\r
1163                                 }\r
1164                                 \r
1165                                 if (pDocument->GetFocusAnnot() != pData->pWidget)\r
1166                                 {\r
1167                                         pFormFiller->CommitData(pData->pPageView,nFlag);\r
1168                                         bExit = TRUE;\r
1169                                 }\r
1170                         }\r
1171                         else\r
1172                         {                       \r
1173                                 if (!IsValidAnnot(pData->pPageView, pData->pWidget))\r
1174                                 {\r
1175                                         bExit = TRUE;\r
1176                                         m_bNotifying = FALSE;\r
1177                                         return;\r
1178                                 }\r
1179                         }\r
1180                         \r
1181                         m_bNotifying = FALSE;\r
1182                 }\r
1183         }\r
1184 }\r
1185 \r
1186 void    CFFL_IFormFiller::OnAfterKeyStroke(FX_BOOL bEditOrList, void* pPrivateData, FX_BOOL & bExit,FX_DWORD nFlag) \r
1187 {\r
1188         ASSERT(pPrivateData != NULL);\r
1189         CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;\r
1190         ASSERT(pData->pWidget != NULL);\r
1191         \r
1192         CFFL_FormFiller* pFormFiller = GetFormFiller(pData->pWidget, FALSE);\r
1193         ASSERT(pFormFiller != NULL);\r
1194         \r
1195         if (!bEditOrList)\r
1196                 pFormFiller->OnKeyStroke(bExit);\r
1197 }\r