Cleanup: Remove dead formfiller code.
[pdfium.git] / fpdfsdk / src / formfiller / FFL_FormFiller.cpp
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
8 #include "../../include/formfiller/FFL_FormFiller.h"
9 #include "../../include/formfiller/FFL_Notify.h"
10 #include "../../include/formfiller/FFL_CBA_Fontmap.h"
11
12 #define GetRed(rgb)                     ((uint8_t)(rgb))
13 #define GetGreen(rgb)           ((uint8_t)(((FX_WORD)(rgb)) >> 8))
14 #define GetBlue(rgb)            ((uint8_t)((rgb)>>16))
15
16 #define FFL_HINT_ELAPSE         800
17
18 /* ------------------------- CFFL_FormFiller ------------------------- */
19
20 CFFL_FormFiller::CFFL_FormFiller(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot)
21         :m_pApp(pApp),
22         m_pAnnot(pAnnot),
23         m_bValid(FALSE),
24         m_ptOldPos(0,0)
25 {
26         m_pWidget = (CPDFSDK_Widget*) pAnnot;
27 }
28
29 CFFL_FormFiller::~CFFL_FormFiller()
30 {
31     for (auto& it : m_Maps) {
32         CPWL_Wnd* pWnd = it.second;
33         CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData();
34         pWnd->Destroy();
35         delete pWnd;
36         delete pData;
37     }
38     m_Maps.clear();
39 }
40
41 void CFFL_FormFiller::SetWindowRect(CPDFSDK_PageView* pPageView, const CPDF_Rect& rcWindow)
42 {
43         if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE))
44         {
45                 pWnd->Move(CPDF_Rect(rcWindow), TRUE, FALSE);
46         }
47 }
48
49 CPDF_Rect CFFL_FormFiller::GetWindowRect(CPDFSDK_PageView* pPageView)
50 {
51         if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE))
52         {
53                 return pWnd->GetWindowRect();
54         }
55
56         return CPDF_Rect(0,0,0,0);
57 }
58
59 FX_RECT CFFL_FormFiller::GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
60 {
61         ASSERT(pPageView != NULL);
62         ASSERT(pAnnot != NULL);
63
64         CPDF_Rect rcAnnot = m_pWidget->GetRect();
65
66         if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE))
67         {
68                 CPDF_Rect rcWindow = pWnd->GetWindowRect();
69                 rcAnnot = PWLtoFFL(rcWindow);
70         }
71
72         CPDF_Rect rcWin = rcAnnot;
73
74         CPDF_Rect rcFocus = GetFocusBox(pPageView);
75         if (!rcFocus.IsEmpty())
76                 rcWin.Union(rcFocus);
77
78         CPDF_Rect rect = CPWL_Utils::InflateRect(rcWin,1);
79
80         return rect.GetOutterRect();
81 }
82
83 void CFFL_FormFiller::OnDraw(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot,
84                                                 CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
85                                                 /*const CRect& rcWindow,*/ FX_DWORD dwFlags)
86 {
87         ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
88
89         if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
90         {
91                 CPDF_Matrix mt = GetCurMatrix();
92                 mt.Concat(*pUser2Device);
93                 pWnd->DrawAppearance(pDevice,&mt);
94         }
95         else
96         {
97                 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
98                 if (CFFL_IFormFiller::IsVisible(pWidget))
99                         pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
100         }
101 }
102
103 void CFFL_FormFiller::OnDrawDeactive(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot,
104                                                 CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
105                                                 /*const CRect& rcWindow,*/ FX_DWORD dwFlags)
106 {
107         ASSERT(pAnnot != NULL);
108
109         CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
110
111         pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
112 }
113
114
115 void CFFL_FormFiller::OnCreate(CPDFSDK_Annot* pAnnot)
116 {
117 }
118
119 void CFFL_FormFiller::OnLoad(CPDFSDK_Annot* pAnnot)
120 {
121 }
122
123 void CFFL_FormFiller::OnDelete(CPDFSDK_Annot* pAnnot)
124 {
125 }
126
127 void CFFL_FormFiller::OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
128 {
129 }
130
131 void CFFL_FormFiller::OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
132 {
133         EndTimer();
134         ASSERT(m_pWidget != NULL);
135 }
136
137 FX_BOOL CFFL_FormFiller::OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
138 {
139         if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, TRUE))
140         {
141                 m_bValid = TRUE;
142                 FX_RECT rect = GetViewBBox(pPageView,pAnnot);
143                 InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
144
145                 if(!rect.Contains((int)point.x, (int)point.y))
146                         return FALSE;
147
148                 return pWnd->OnLButtonDown(WndtoPWL(pPageView, point),nFlags);
149         }
150
151         return FALSE;
152 }
153
154 FX_BOOL CFFL_FormFiller::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
155 {
156         if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
157         {
158                 FX_RECT rcFFL = GetViewBBox(pPageView, pAnnot);
159                 InvalidateRect(rcFFL.left, rcFFL.top, rcFFL.right, rcFFL.bottom);
160                 pWnd->OnLButtonUp(WndtoPWL(pPageView, point),nFlags);
161                 return TRUE;
162         }
163
164         return FALSE;
165 }
166
167 FX_BOOL CFFL_FormFiller::OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
168 {
169         if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
170         {
171                 pWnd->OnLButtonDblClk(WndtoPWL(pPageView, point),nFlags);
172                 return TRUE;
173         }
174
175         return FALSE;
176 }
177
178 FX_BOOL CFFL_FormFiller::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
179 {
180         if ((m_ptOldPos.x != point.x) || (m_ptOldPos.y != point.y))
181         {
182                 m_ptOldPos = point;
183         }
184
185         if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
186         {
187                 pWnd->OnMouseMove(WndtoPWL(pPageView, point),nFlags);
188                 return TRUE;
189         }
190
191         return FALSE;
192 }
193
194 FX_BOOL CFFL_FormFiller::OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, short zDelta, const CPDF_Point& point)
195 {
196         if (!IsValid()) return FALSE;
197
198         if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, TRUE))
199         {
200                 return pWnd->OnMouseWheel(zDelta, WndtoPWL(pPageView, point),nFlags);
201         }
202
203         return FALSE;
204 }
205
206 FX_BOOL CFFL_FormFiller::OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
207 {
208         if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, TRUE))
209         {
210                 pWnd->OnRButtonDown(WndtoPWL(pPageView, point),nFlags);
211                 return TRUE;
212         }
213
214         return FALSE;
215 }
216
217 FX_BOOL CFFL_FormFiller::OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
218 {
219         if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
220         {
221                 pWnd->OnRButtonUp(WndtoPWL(pPageView, point),nFlags);
222                 return TRUE;
223         }
224
225         return FALSE;
226 }
227
228 FX_BOOL CFFL_FormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot, FX_UINT nKeyCode, FX_UINT nFlags)
229 {
230         if (IsValid())
231         {
232                 CPDFSDK_PageView* pPageView = GetCurPageView();
233                 ASSERT(pPageView != NULL);
234
235                 if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
236                 {
237                         return pWnd->OnKeyDown(nKeyCode,nFlags);
238                 }
239         }
240
241         return FALSE;
242 }
243
244 FX_BOOL CFFL_FormFiller::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
245 {
246         if (IsValid())
247         {
248                 CPDFSDK_PageView* pPageView = GetCurPageView();
249                 ASSERT(pPageView != NULL);
250
251                 if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
252                 {
253                         return pWnd->OnChar(nChar,nFlags);
254                 }
255         }
256
257         return FALSE;
258 }
259
260 FX_BOOL CFFL_FormFiller::OnSetFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag)
261 {
262         CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
263
264         CPDF_Page * pPage = pWidget->GetPDFPage();
265         CPDFSDK_Document * pDoc = m_pApp->GetCurrentDoc();
266         CPDFSDK_PageView* pPageView = pDoc->GetPageView(pPage);
267         ASSERT(pPageView != NULL);
268
269         CPWL_Wnd * pWnd = NULL;
270         if ( (pWnd = GetPDFWindow(pPageView, TRUE)))
271         {
272                 pWnd->SetFocus();
273         }
274
275         m_bValid = TRUE;
276         FX_RECT rcRect = GetViewBBox(pPageView,pAnnot);
277         InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom);
278
279         return TRUE;
280 }
281
282 FX_BOOL CFFL_FormFiller::OnKillFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag)
283 {
284         if (IsValid())
285         {
286                 CPDFSDK_PageView* pPageView = GetCurPageView();
287                 ASSERT(pPageView != NULL);
288
289                 CommitData(pPageView, nFlag);
290
291                 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE))
292                 {
293                         pWnd->KillFocus();
294                 }
295
296                 switch (m_pWidget->GetFieldType())
297                 {
298                 case FIELDTYPE_PUSHBUTTON:
299                 case FIELDTYPE_CHECKBOX:
300                 case FIELDTYPE_RADIOBUTTON:
301                         EscapeFiller(pPageView, TRUE);
302                         break;
303                 default:
304                         EscapeFiller(pPageView, FALSE);
305                         break;
306                 }
307         }
308
309         return TRUE;
310 }
311
312 FX_BOOL CFFL_FormFiller::IsValid() const
313 {
314         return m_bValid;
315 }
316
317 PWL_CREATEPARAM CFFL_FormFiller::GetCreateParam()
318 {
319         ASSERT(m_pApp != NULL);
320
321         PWL_CREATEPARAM cp;
322
323         cp.pParentWnd = NULL;
324         cp.pProvider = this;
325         cp.rcRectWnd = GetPDFWindowRect();
326
327         FX_DWORD dwCreateFlags = PWS_BORDER | PWS_BACKGROUND | PWS_VISIBLE;
328
329         ASSERT(m_pWidget != NULL);
330
331
332         FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags();
333
334         if (dwFieldFlag & FIELDFLAG_READONLY)
335         {
336                 dwCreateFlags |= PWS_READONLY;
337         }
338
339         FX_COLORREF color;
340         if (m_pWidget->GetFillColor(color))
341         {
342                 cp.sBackgroundColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color));
343         }
344
345         if (m_pWidget->GetBorderColor(color))
346         {
347                 cp.sBorderColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color));
348         }
349
350         cp.sTextColor = CPWL_Color(COLORTYPE_GRAY,0);
351
352         if (m_pWidget->GetTextColor(color))
353         {
354                 cp.sTextColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color));
355         }
356
357         cp.fFontSize = m_pWidget->GetFontSize();
358         cp.dwBorderWidth = m_pWidget->GetBorderWidth();
359
360         int nBorderStyle = m_pWidget->GetBorderStyle();
361
362         switch (nBorderStyle)
363         {
364         case BBS_SOLID:
365                 cp.nBorderStyle = PBS_SOLID;
366                 break;
367         case BBS_DASH:
368                 cp.nBorderStyle = PBS_DASH;
369                 cp.sDash = CPWL_Dash(3,3,0);
370                 break;
371         case BBS_BEVELED:
372                 cp.nBorderStyle = PBS_BEVELED;
373                 cp.dwBorderWidth *= 2;
374                 break;
375         case BBS_INSET:
376                 cp.nBorderStyle = PBS_INSET;
377                 cp.dwBorderWidth *= 2;
378                 break;
379         case BBS_UNDERLINE:
380                 cp.nBorderStyle = PBS_UNDERLINED;
381                 break;
382         }
383
384         if (cp.fFontSize <= 0)
385         {
386                 dwCreateFlags |= PWS_AUTOFONTSIZE;
387         }
388
389         cp.dwFlags = dwCreateFlags;
390         cp.pSystemHandler = m_pApp->GetSysHandler();
391         return cp;
392 }
393
394 CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bNew)
395 {
396     ASSERT(pPageView);
397
398     auto it = m_Maps.find(pPageView);
399     const bool found = it != m_Maps.end();
400     CPWL_Wnd* pWnd = found ? it->second : nullptr;
401     if (!bNew)
402         return pWnd;
403
404     if (found) {
405         CFFL_PrivateData* pPrivateData =
406             (CFFL_PrivateData*)pWnd->GetAttachedData();
407         if (pPrivateData->nWidgetAge != m_pWidget->GetAppearanceAge()) {
408             return ResetPDFWindow(
409                 pPageView, m_pWidget->GetValueAge() == pPrivateData->nValueAge);
410       }
411     } else {
412       PWL_CREATEPARAM cp = GetCreateParam();
413       cp.hAttachedWnd = (FX_HWND)m_pWidget;
414
415       CFFL_PrivateData* pPrivateData = new CFFL_PrivateData;
416       pPrivateData->pWidget = m_pWidget;
417       pPrivateData->pPageView = pPageView;
418       pPrivateData->nWidgetAge = m_pWidget->GetAppearanceAge();
419       pPrivateData->nValueAge = 0;
420
421       cp.pAttachedData = pPrivateData;
422
423       pWnd = NewPDFWindow(cp, pPageView);
424       m_Maps[pPageView] = pWnd;
425     }
426
427     return pWnd;
428 }
429
430 void CFFL_FormFiller::DestroyPDFWindow(CPDFSDK_PageView* pPageView)
431 {
432     auto it = m_Maps.find(pPageView);
433     if (it == m_Maps.end())
434         return;
435
436     CPWL_Wnd* pWnd = it->second;
437     CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData();
438     pWnd->Destroy();
439     delete pWnd;
440     delete pData;
441
442     m_Maps.erase(it);
443 }
444
445 CPDF_Matrix     CFFL_FormFiller::GetWindowMatrix(void* pAttachedData)
446 {
447         if (CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pAttachedData)
448         {
449                 if (pPrivateData->pPageView)
450                 {
451                         CPDF_Matrix mtPageView;
452                         pPrivateData->pPageView->GetCurrentMatrix(mtPageView);
453                         CPDF_Matrix mt = GetCurMatrix();
454                         mt.Concat(mtPageView);
455
456                         return mt;
457                 }
458         }
459         return CPDF_Matrix(1,0,0,1,0,0);
460 }
461
462 CPDF_Matrix     CFFL_FormFiller::GetCurMatrix()
463 {
464         CPDF_Matrix mt;
465
466         ASSERT(m_pWidget != NULL);
467
468         CPDF_Rect rcDA ;
469         m_pWidget->GetPDFAnnot()->GetRect(rcDA);
470
471
472         switch (m_pWidget->GetRotate())
473         {
474         default:
475         case 0:
476                 mt = CPDF_Matrix(1,0,0,1,0,0);
477                 break;
478         case 90:
479                 mt = CPDF_Matrix(0,1,-1,0,rcDA.right - rcDA.left,0);
480                 break;
481         case 180:
482                 mt = CPDF_Matrix(-1,0,0,-1,rcDA.right - rcDA.left,rcDA.top - rcDA.bottom);
483                 break;
484         case 270:
485                 mt = CPDF_Matrix(0,-1,1,0,0,rcDA.top - rcDA.bottom);
486                 break;
487         }
488         mt.e += rcDA.left;
489         mt.f += rcDA.bottom;
490
491         return mt;
492 }
493
494 CFX_WideString CFFL_FormFiller::LoadPopupMenuString(int nIndex)
495 {
496         ASSERT(m_pApp != NULL);
497
498         return L"";
499 }
500
501 CPDF_Rect CFFL_FormFiller::GetPDFWindowRect() const
502 {
503         ASSERT(m_pWidget != NULL);
504
505         CPDF_Rect rectAnnot;
506         m_pWidget->GetPDFAnnot()->GetRect(rectAnnot);
507
508         FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left;
509         FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom;
510
511
512         if ((m_pWidget->GetRotate() / 90) & 0x01)
513                 return CPDF_Rect(0,0,fHeight,fWidth);
514         else
515                 return CPDF_Rect(0,0,fWidth,fHeight);
516 }
517
518 CPDFSDK_PageView* CFFL_FormFiller::GetCurPageView()
519 {
520
521         CPDF_Page* pPage = m_pAnnot->GetPDFPage();
522         CPDFSDK_Document* pSDKDoc = m_pApp->GetCurrentDoc();
523         if(pSDKDoc)
524         {
525                 return pSDKDoc->GetPageView(pPage);
526         }
527         return NULL;
528 }
529
530 CPDF_Rect CFFL_FormFiller::GetFocusBox(CPDFSDK_PageView* pPageView)
531 {
532         if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
533         {
534                 CPDF_Rect rcFocus =  FFLtoWnd(pPageView, PWLtoFFL(pWnd->GetFocusRect()));
535                 ASSERT(pPageView);
536                 CPDF_Rect rcPage = pPageView->GetPDFPage()->GetPageBBox();
537                 if(rcPage.Contains(rcFocus))
538                         return rcFocus;
539                 else
540                         return CPDF_Rect(0,0,0,0);
541         }
542         return CPDF_Rect(0,0,0,0);
543 }
544
545 CPDF_Rect CFFL_FormFiller::FFLtoPWL(const CPDF_Rect& rect)
546 {
547         CPDF_Matrix mt;
548         mt.SetReverse(GetCurMatrix());
549
550         CPDF_Rect temp = rect;
551         mt.TransformRect(temp);
552
553         return temp;
554 }
555
556 CPDF_Rect CFFL_FormFiller::PWLtoFFL(const CPDF_Rect& rect)
557 {
558         CPDF_Matrix mt = GetCurMatrix();
559
560         CPDF_Rect temp = rect;
561         mt.TransformRect(temp);
562
563         return temp;
564 }
565
566 CPDF_Point CFFL_FormFiller::FFLtoPWL(const CPDF_Point& point)
567 {
568         CPDF_Matrix mt;
569         mt.SetReverse(GetCurMatrix());
570
571         CPDF_Point pt = point;
572         mt.Transform(pt.x,pt.y);
573
574         return pt;
575 }
576
577 CPDF_Point CFFL_FormFiller::PWLtoFFL(const CPDF_Point & point)
578 {
579         CPDF_Matrix mt = GetCurMatrix();
580
581         CPDF_Point pt = point;
582         mt.Transform(pt.x,pt.y);
583
584         return pt;
585 }
586
587 CPDF_Point CFFL_FormFiller::WndtoPWL(CPDFSDK_PageView* pPageView, const CPDF_Point& pt)
588 {
589 //      ASSERT(pPageView != NULL);
590 //
591 //      CPDF_Point point(0.0f, 0.0f);
592 //      pPageView->WindowToDoc(pt.x, pt.y, point.x, point.y);
593 //
594         return FFLtoPWL(pt);
595 //      return CPDF_Point(0, 0);
596 }
597
598 CPDF_Rect CFFL_FormFiller::FFLtoWnd(CPDFSDK_PageView* pPageView, const CPDF_Rect & rect)
599 {
600 //      FX_RECT rcRet(0,0,0,0);
601 //
602 //      ASSERT(pPageView != NULL);
603 //      pPageView->DocToWindow(rect, rcRet);
604 //
605         return rect;
606
607 }
608
609 void CFFL_FormFiller::FFL_FreeData(void* pData)
610 {
611         ASSERT(pData != NULL);
612
613         delete (CFFL_PrivateData*)pData;
614 }
615
616 FX_BOOL CFFL_FormFiller::CommitData(CPDFSDK_PageView* pPageView, FX_UINT nFlag)
617 {
618         if (IsDataChanged(pPageView))
619         {
620                 //CFFL_IFormFiller* pIFormFiller = CFFL_Module::GetFormFiller(m_pApp);
621                 CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();//NULL;
622                 ASSERT(pIFormFiller != NULL);
623
624                 FX_BOOL bRC = TRUE;
625                 FX_BOOL bExit = FALSE;
626
627                 pIFormFiller->OnKeyStrokeCommit(m_pWidget, pPageView, bRC, bExit, nFlag);
628                 if (bExit) return TRUE;
629                 if (!bRC)
630                 {
631                         ResetPDFWindow(pPageView, FALSE);
632                         return TRUE;
633                 }
634
635                 pIFormFiller->OnValidate(m_pWidget, pPageView, bRC, bExit, nFlag);
636                 if (bExit) return TRUE;
637                 if (!bRC)
638                 {
639                         ResetPDFWindow(pPageView, FALSE);
640                         return TRUE;
641                 }
642
643                 SaveData(pPageView);
644
645                 pIFormFiller->OnCalculate(m_pWidget, pPageView, bExit,nFlag);
646                 if (bExit) return TRUE;
647
648                 pIFormFiller->OnFormat(m_pWidget, pPageView, bExit,nFlag);
649         }
650
651         return TRUE;
652 }
653
654 FX_BOOL CFFL_FormFiller::IsDataChanged(CPDFSDK_PageView* pPageView)
655 {
656         return FALSE;
657 }
658
659 void CFFL_FormFiller::SaveData(CPDFSDK_PageView* pPageView)
660 {
661 }
662
663 void CFFL_FormFiller::GetKeyStrokeData(CPDFSDK_PageView* pPageView, FFL_KeyStrokeData& data)
664 {
665 }
666
667 void CFFL_FormFiller::SetChangeMark()
668 {
669         m_pApp->FFI_OnChange();
670 }
671
672 void CFFL_FormFiller::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
673                                                         PDFSDK_FieldAction& fa)
674 {
675         fa.sValue = m_pWidget->GetValue();
676 }
677
678 void CFFL_FormFiller::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
679                                                                         const PDFSDK_FieldAction& fa)
680 {
681 }
682
683 FX_BOOL CFFL_FormFiller::IsActionDataChanged(CPDF_AAction::AActionType type, const PDFSDK_FieldAction& faOld,
684                                                                         const PDFSDK_FieldAction& faNew)
685 {
686         return FALSE;
687 }
688
689 void CFFL_FormFiller::SaveState(CPDFSDK_PageView* pPageView)
690 {
691 }
692
693 void CFFL_FormFiller::RestoreState(CPDFSDK_PageView* pPageView)
694 {
695 }
696
697 CPWL_Wnd*  CFFL_FormFiller::ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bRestoreValue)
698 {
699         return GetPDFWindow(pPageView, FALSE);
700 }
701
702 void CFFL_FormFiller::TimerProc()
703 {
704
705 }
706
707 IFX_SystemHandler* CFFL_FormFiller::GetSystemHandler() const
708 {
709         return m_pApp->GetSysHandler();
710 //      return NULL;
711 }
712
713 void CFFL_FormFiller::OnKeyStroke(FX_BOOL bKeyDown)
714 {
715 }
716
717 void CFFL_FormFiller::EscapeFiller(CPDFSDK_PageView* pPageView, FX_BOOL bDestroyPDFWindow)
718 {
719         m_bValid = FALSE;
720
721         FX_RECT rcRect = GetViewBBox(pPageView, m_pWidget);
722         InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom);
723
724         if(bDestroyPDFWindow)
725                 DestroyPDFWindow(pPageView);
726 }
727
728 FX_BOOL CFFL_FormFiller::CanCopy(CPDFSDK_Document* pDocument)
729 {
730         return FALSE;
731 }
732
733 FX_BOOL CFFL_FormFiller::CanCut(CPDFSDK_Document* pDocument)
734 {
735         return FALSE;
736 }
737
738 FX_BOOL CFFL_FormFiller::CanPaste(CPDFSDK_Document* pDocument)
739 {
740         return FALSE;
741 }
742
743 void CFFL_FormFiller::DoCopy(CPDFSDK_Document* pDocument)
744 {
745 }
746
747 void CFFL_FormFiller::DoCut(CPDFSDK_Document* pDocument)
748 {
749 }
750
751 void CFFL_FormFiller::DoPaste(CPDFSDK_Document* pDocument)
752 {
753 }
754
755 void CFFL_FormFiller::InvalidateRect(double left, double top, double right, double bottom)
756 {
757         CPDF_Page * pPage = m_pWidget->GetPDFPage();
758         m_pApp->FFI_Invalidate(pPage, left, top, right, bottom);
759 }
760
761 /* ------------------------- CFFL_Button ------------------------- */
762
763 CFFL_Button::CFFL_Button(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) :
764         CFFL_FormFiller(pApp, pWidget),
765         m_bMouseIn(FALSE),
766         m_bMouseDown(FALSE)
767 {
768 }
769
770 CFFL_Button::~CFFL_Button()
771 {
772 }
773
774 void CFFL_Button::OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
775 {
776         m_bMouseIn = TRUE;
777         FX_RECT rect = GetViewBBox(pPageView,pAnnot);
778         InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
779 }
780
781 void CFFL_Button::OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
782 {
783         m_bMouseIn = FALSE;
784
785         FX_RECT rect = GetViewBBox(pPageView,pAnnot);
786         InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
787         EndTimer();
788         ASSERT(m_pWidget != NULL);
789 }
790
791 FX_BOOL CFFL_Button::OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
792 {
793         CPDF_Rect rcAnnot = pAnnot->GetRect();
794         if(!rcAnnot.Contains(point.x, point.y))
795                 return FALSE;
796
797         m_bMouseDown = TRUE;
798         m_bValid = TRUE;
799         FX_RECT rect = GetViewBBox(pPageView, pAnnot);
800         InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
801         return TRUE;
802 }
803
804 FX_BOOL CFFL_Button::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
805 {
806         CPDF_Rect rcAnnot = pAnnot->GetRect();
807         if(!rcAnnot.Contains(point.x, point.y))
808                 return FALSE;
809
810         m_bMouseDown = FALSE;
811         m_pWidget->GetPDFPage();
812
813
814         FX_RECT rect = GetViewBBox(pPageView, pAnnot);
815         InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
816         return TRUE;
817 }
818
819 FX_BOOL CFFL_Button::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
820 {
821         ASSERT(m_pApp != NULL);
822
823         return TRUE;
824 }
825
826 void CFFL_Button::OnDraw(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot,
827                                                         CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
828                                                         /*const CRect& rcWindow,*/ FX_DWORD dwFlags)
829 {
830         ASSERT(pPageView != NULL);
831         ASSERT(pAnnot != NULL);
832
833         CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
834
835         CPDF_FormControl* pCtrl = pWidget->GetFormControl();
836         ASSERT(pCtrl != NULL);
837
838         CPDF_FormControl::HighlightingMode eHM = pCtrl->GetHighlightingMode();
839
840         if (eHM == CPDF_FormControl::Push)
841         {
842                 if (m_bMouseDown)
843                 {
844                         if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Down))
845                                 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Down, NULL);
846                         else
847                                 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
848                 }
849                 else if (m_bMouseIn)
850                 {
851                         if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Rollover))
852                                 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Rollover, NULL);
853                         else
854                                 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
855                 }
856                 else
857                 {
858                         pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
859                 }
860         }
861         else
862                 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
863 }
864
865
866 void CFFL_Button::OnDrawDeactive(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot,
867                                                                  CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
868                                                                  /*const CRect& rcWindow, */FX_DWORD dwFlags)
869 {
870         OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
871 }