Replace CFX_MapPtrTemplate with std::map.
[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::OnRButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
229 {
230         if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
231         {
232                 pWnd->OnRButtonDblClk(WndtoPWL(pPageView, point),nFlags);
233                 return TRUE;
234         }
235
236         return FALSE;
237 }
238
239 FX_BOOL CFFL_FormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot, FX_UINT nKeyCode, FX_UINT nFlags)
240 {
241         if (IsValid())
242         {
243                 CPDFSDK_PageView* pPageView = GetCurPageView();
244                 ASSERT(pPageView != NULL);
245
246                 if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
247                 {
248                         return pWnd->OnKeyDown(nKeyCode,nFlags);
249                 }
250         }
251
252         return FALSE;
253 }
254
255 FX_BOOL CFFL_FormFiller::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
256 {
257         if (IsValid())
258         {
259                 CPDFSDK_PageView* pPageView = GetCurPageView();
260                 ASSERT(pPageView != NULL);
261
262                 if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
263                 {
264                         return pWnd->OnChar(nChar,nFlags);
265                 }
266         }
267
268         return FALSE;
269 }
270
271 void CFFL_FormFiller::OnDeSelected(CPDFSDK_Annot* pAnnot)
272 {
273         ASSERT(FALSE);
274 }
275
276 void CFFL_FormFiller::OnSelected(CPDFSDK_Annot* pAnnot)
277 {
278         ASSERT(FALSE);
279 }
280
281 FX_BOOL CFFL_FormFiller::OnSetFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag)
282 {
283         CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
284
285         CPDF_Page * pPage = pWidget->GetPDFPage();
286         CPDFSDK_Document * pDoc = m_pApp->GetCurrentDoc();
287         CPDFSDK_PageView* pPageView = pDoc->GetPageView(pPage);
288         ASSERT(pPageView != NULL);
289
290
291
292         CPWL_Wnd * pWnd = NULL;
293         if ( (pWnd = GetPDFWindow(pPageView, TRUE)))
294         {
295                 pWnd->SetFocus();
296         }
297
298         m_bValid = TRUE;
299
300
301
302
303         m_bValid = TRUE;
304         FX_RECT rcRect = GetViewBBox(pPageView,pAnnot);
305         InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom);
306
307         return TRUE;
308 }
309
310 FX_BOOL CFFL_FormFiller::OnKillFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag)
311 {
312         if (IsValid())
313         {
314                 CPDFSDK_PageView* pPageView = GetCurPageView();
315                 ASSERT(pPageView != NULL);
316
317                 CommitData(pPageView, nFlag);
318
319                 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE))
320                 {
321                         pWnd->KillFocus();
322                 }
323
324                 switch (m_pWidget->GetFieldType())
325                 {
326                 case FIELDTYPE_PUSHBUTTON:
327                 case FIELDTYPE_CHECKBOX:
328                 case FIELDTYPE_RADIOBUTTON:
329                         EscapeFiller(pPageView, TRUE);
330                         break;
331                 default:
332                         EscapeFiller(pPageView, FALSE);
333                         break;
334                 }
335         }
336
337         return TRUE;
338 }
339
340 FX_BOOL CFFL_FormFiller::IsValid() const
341 {
342         return m_bValid;
343 }
344
345 PWL_CREATEPARAM CFFL_FormFiller::GetCreateParam()
346 {
347         ASSERT(m_pApp != NULL);
348
349         PWL_CREATEPARAM cp;
350
351         cp.pParentWnd = NULL;
352         cp.pProvider = this;
353         cp.rcRectWnd = GetPDFWindowRect();
354
355         FX_DWORD dwCreateFlags = PWS_BORDER | PWS_BACKGROUND | PWS_VISIBLE;
356
357         ASSERT(m_pWidget != NULL);
358
359
360         FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags();
361
362         if (dwFieldFlag & FIELDFLAG_READONLY)
363         {
364                 dwCreateFlags |= PWS_READONLY;
365         }
366
367         FX_COLORREF color;
368         if (m_pWidget->GetFillColor(color))
369         {
370                 cp.sBackgroundColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color));
371         }
372
373         if (m_pWidget->GetBorderColor(color))
374         {
375                 cp.sBorderColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color));
376         }
377
378         cp.sTextColor = CPWL_Color(COLORTYPE_GRAY,0);
379
380         if (m_pWidget->GetTextColor(color))
381         {
382                 cp.sTextColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color));
383         }
384
385         cp.fFontSize = m_pWidget->GetFontSize();
386         cp.dwBorderWidth = m_pWidget->GetBorderWidth();
387
388         int nBorderStyle = m_pWidget->GetBorderStyle();
389
390         switch (nBorderStyle)
391         {
392         case BBS_SOLID:
393                 cp.nBorderStyle = PBS_SOLID;
394                 break;
395         case BBS_DASH:
396                 cp.nBorderStyle = PBS_DASH;
397                 cp.sDash = CPWL_Dash(3,3,0);
398                 break;
399         case BBS_BEVELED:
400                 cp.nBorderStyle = PBS_BEVELED;
401                 cp.dwBorderWidth *= 2;
402                 break;
403         case BBS_INSET:
404                 cp.nBorderStyle = PBS_INSET;
405                 cp.dwBorderWidth *= 2;
406                 break;
407         case BBS_UNDERLINE:
408                 cp.nBorderStyle = PBS_UNDERLINED;
409                 break;
410         }
411
412         if (cp.fFontSize <= 0)
413         {
414                 dwCreateFlags |= PWS_AUTOFONTSIZE;
415         }
416
417         cp.dwFlags = dwCreateFlags;
418         cp.pSystemHandler = m_pApp->GetSysHandler();
419         return cp;
420 }
421
422 CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bNew)
423 {
424     ASSERT(pPageView);
425
426     auto it = m_Maps.find(pPageView);
427     const bool found = it != m_Maps.end();
428     CPWL_Wnd* pWnd = found ? it->second : nullptr;
429     if (!bNew)
430         return pWnd;
431
432     if (found) {
433         CFFL_PrivateData* pPrivateData =
434             (CFFL_PrivateData*)pWnd->GetAttachedData();
435         if (pPrivateData->nWidgetAge != m_pWidget->GetAppearanceAge()) {
436             return ResetPDFWindow(
437                 pPageView, m_pWidget->GetValueAge() == pPrivateData->nValueAge);
438       }
439     } else {
440       PWL_CREATEPARAM cp = GetCreateParam();
441       cp.hAttachedWnd = (FX_HWND)m_pWidget;
442
443       CFFL_PrivateData* pPrivateData = new CFFL_PrivateData;
444       pPrivateData->pWidget = m_pWidget;
445       pPrivateData->pPageView = pPageView;
446       pPrivateData->nWidgetAge = m_pWidget->GetAppearanceAge();
447       pPrivateData->nValueAge = 0;
448
449       cp.pAttachedData = pPrivateData;
450
451       pWnd = NewPDFWindow(cp, pPageView);
452       m_Maps[pPageView] = pWnd;
453     }
454
455     return pWnd;
456 }
457
458 void CFFL_FormFiller::DestroyPDFWindow(CPDFSDK_PageView* pPageView)
459 {
460     auto it = m_Maps.find(pPageView);
461     if (it == m_Maps.end())
462         return;
463
464     CPWL_Wnd* pWnd = it->second;
465     CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData();
466     pWnd->Destroy();
467     delete pWnd;
468     delete pData;
469
470     m_Maps.erase(it);
471 }
472
473 CPDF_Matrix     CFFL_FormFiller::GetWindowMatrix(void* pAttachedData)
474 {
475         if (CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pAttachedData)
476         {
477                 if (pPrivateData->pPageView)
478                 {
479                         CPDF_Matrix mtPageView;
480                         pPrivateData->pPageView->GetCurrentMatrix(mtPageView);
481                         CPDF_Matrix mt = GetCurMatrix();
482                         mt.Concat(mtPageView);
483
484                         return mt;
485                 }
486         }
487         return CPDF_Matrix(1,0,0,1,0,0);
488 }
489
490 CPDF_Matrix     CFFL_FormFiller::GetCurMatrix()
491 {
492         CPDF_Matrix mt;
493
494         ASSERT(m_pWidget != NULL);
495
496         CPDF_Rect rcDA ;
497         m_pWidget->GetPDFAnnot()->GetRect(rcDA);
498
499
500         switch (m_pWidget->GetRotate())
501         {
502         default:
503         case 0:
504                 mt = CPDF_Matrix(1,0,0,1,0,0);
505                 break;
506         case 90:
507                 mt = CPDF_Matrix(0,1,-1,0,rcDA.right - rcDA.left,0);
508                 break;
509         case 180:
510                 mt = CPDF_Matrix(-1,0,0,-1,rcDA.right - rcDA.left,rcDA.top - rcDA.bottom);
511                 break;
512         case 270:
513                 mt = CPDF_Matrix(0,-1,1,0,0,rcDA.top - rcDA.bottom);
514                 break;
515         }
516         mt.e += rcDA.left;
517         mt.f += rcDA.bottom;
518
519         return mt;
520 }
521
522 CFX_WideString CFFL_FormFiller::LoadPopupMenuString(int nIndex)
523 {
524         ASSERT(m_pApp != NULL);
525
526         return L"";
527 }
528
529 CPDF_Rect CFFL_FormFiller::GetPDFWindowRect() const
530 {
531         ASSERT(m_pWidget != NULL);
532
533         CPDF_Rect rectAnnot;
534         m_pWidget->GetPDFAnnot()->GetRect(rectAnnot);
535
536         FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left;
537         FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom;
538
539
540         if ((m_pWidget->GetRotate() / 90) & 0x01)
541                 return CPDF_Rect(0,0,fHeight,fWidth);
542         else
543                 return CPDF_Rect(0,0,fWidth,fHeight);
544 }
545
546 CPDFSDK_PageView* CFFL_FormFiller::GetCurPageView()
547 {
548
549         CPDF_Page* pPage = m_pAnnot->GetPDFPage();
550         CPDFSDK_Document* pSDKDoc = m_pApp->GetCurrentDoc();
551         if(pSDKDoc)
552         {
553                 return pSDKDoc->GetPageView(pPage);
554         }
555         return NULL;
556 }
557
558 CPDF_Rect CFFL_FormFiller::GetFocusBox(CPDFSDK_PageView* pPageView)
559 {
560         if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE))
561         {
562                 CPDF_Rect rcFocus =  FFLtoWnd(pPageView, PWLtoFFL(pWnd->GetFocusRect()));
563                 ASSERT(pPageView);
564                 CPDF_Rect rcPage = pPageView->GetPDFPage()->GetPageBBox();
565                 if(rcPage.Contains(rcFocus))
566                         return rcFocus;
567                 else
568                         return CPDF_Rect(0,0,0,0);
569         }
570         return CPDF_Rect(0,0,0,0);
571 }
572
573 CPDF_Rect CFFL_FormFiller::FFLtoPWL(const CPDF_Rect& rect)
574 {
575         CPDF_Matrix mt;
576         mt.SetReverse(GetCurMatrix());
577
578         CPDF_Rect temp = rect;
579         mt.TransformRect(temp);
580
581         return temp;
582 }
583
584 CPDF_Rect CFFL_FormFiller::PWLtoFFL(const CPDF_Rect& rect)
585 {
586         CPDF_Matrix mt = GetCurMatrix();
587
588         CPDF_Rect temp = rect;
589         mt.TransformRect(temp);
590
591         return temp;
592 }
593
594 CPDF_Point CFFL_FormFiller::FFLtoPWL(const CPDF_Point& point)
595 {
596         CPDF_Matrix mt;
597         mt.SetReverse(GetCurMatrix());
598
599         CPDF_Point pt = point;
600         mt.Transform(pt.x,pt.y);
601
602         return pt;
603 }
604
605 CPDF_Point CFFL_FormFiller::PWLtoFFL(const CPDF_Point & point)
606 {
607         CPDF_Matrix mt = GetCurMatrix();
608
609         CPDF_Point pt = point;
610         mt.Transform(pt.x,pt.y);
611
612         return pt;
613 }
614
615 CPDF_Point CFFL_FormFiller::WndtoPWL(CPDFSDK_PageView* pPageView, const CPDF_Point& pt)
616 {
617 //      ASSERT(pPageView != NULL);
618 //
619 //      CPDF_Point point(0.0f, 0.0f);
620 //      pPageView->WindowToDoc(pt.x, pt.y, point.x, point.y);
621 //
622         return FFLtoPWL(pt);
623 //      return CPDF_Point(0, 0);
624 }
625
626 CPDF_Rect CFFL_FormFiller::FFLtoWnd(CPDFSDK_PageView* pPageView, const CPDF_Rect & rect)
627 {
628 //      FX_RECT rcRet(0,0,0,0);
629 //
630 //      ASSERT(pPageView != NULL);
631 //      pPageView->DocToWindow(rect, rcRet);
632 //
633         return rect;
634
635 }
636
637 void CFFL_FormFiller::FFL_FreeData(void* pData)
638 {
639         ASSERT(pData != NULL);
640
641         delete (CFFL_PrivateData*)pData;
642 }
643
644 FX_BOOL CFFL_FormFiller::CommitData(CPDFSDK_PageView* pPageView, FX_UINT nFlag)
645 {
646         if (IsDataChanged(pPageView))
647         {
648                 //CFFL_IFormFiller* pIFormFiller = CFFL_Module::GetFormFiller(m_pApp);
649                 CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();//NULL;
650                 ASSERT(pIFormFiller != NULL);
651
652                 FX_BOOL bRC = TRUE;
653                 FX_BOOL bExit = FALSE;
654
655                 pIFormFiller->OnKeyStrokeCommit(m_pWidget, pPageView, bRC, bExit, nFlag);
656                 if (bExit) return TRUE;
657                 if (!bRC)
658                 {
659                         ResetPDFWindow(pPageView, FALSE);
660                         return TRUE;
661                 }
662
663                 pIFormFiller->OnValidate(m_pWidget, pPageView, bRC, bExit, nFlag);
664                 if (bExit) return TRUE;
665                 if (!bRC)
666                 {
667                         ResetPDFWindow(pPageView, FALSE);
668                         return TRUE;
669                 }
670
671                 SaveData(pPageView);
672
673                 pIFormFiller->OnCalculate(m_pWidget, pPageView, bExit,nFlag);
674                 if (bExit) return TRUE;
675
676                 pIFormFiller->OnFormat(m_pWidget, pPageView, bExit,nFlag);
677         }
678
679         return TRUE;
680 }
681
682 FX_BOOL CFFL_FormFiller::IsDataChanged(CPDFSDK_PageView* pPageView)
683 {
684         return FALSE;
685 }
686
687 void CFFL_FormFiller::SaveData(CPDFSDK_PageView* pPageView)
688 {
689 }
690
691 void CFFL_FormFiller::GetKeyStrokeData(CPDFSDK_PageView* pPageView, FFL_KeyStrokeData& data)
692 {
693 }
694
695 void CFFL_FormFiller::SetChangeMark()
696 {
697         m_pApp->FFI_OnChange();
698 }
699
700 void CFFL_FormFiller::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
701                                                         PDFSDK_FieldAction& fa)
702 {
703         fa.sValue = m_pWidget->GetValue();
704 }
705
706 void CFFL_FormFiller::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
707                                                                         const PDFSDK_FieldAction& fa)
708 {
709 }
710
711 FX_BOOL CFFL_FormFiller::IsActionDataChanged(CPDF_AAction::AActionType type, const PDFSDK_FieldAction& faOld,
712                                                                         const PDFSDK_FieldAction& faNew)
713 {
714         return FALSE;
715 }
716
717 void CFFL_FormFiller::SaveState(CPDFSDK_PageView* pPageView)
718 {
719 }
720
721 void CFFL_FormFiller::RestoreState(CPDFSDK_PageView* pPageView)
722 {
723 }
724
725 CPWL_Wnd*  CFFL_FormFiller::ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bRestoreValue)
726 {
727         return GetPDFWindow(pPageView, FALSE);
728 }
729
730 void CFFL_FormFiller::TimerProc()
731 {
732
733 }
734
735 IFX_SystemHandler* CFFL_FormFiller::GetSystemHandler() const
736 {
737         return m_pApp->GetSysHandler();
738 //      return NULL;
739 }
740
741 void CFFL_FormFiller::OnKeyStroke(FX_BOOL bKeyDown)
742 {
743 }
744
745 void CFFL_FormFiller::EscapeFiller(CPDFSDK_PageView* pPageView, FX_BOOL bDestroyPDFWindow)
746 {
747         m_bValid = FALSE;
748
749         FX_RECT rcRect = GetViewBBox(pPageView, m_pWidget);
750         InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom);
751
752         if(bDestroyPDFWindow)
753                 DestroyPDFWindow(pPageView);
754 }
755
756 FX_BOOL CFFL_FormFiller::CanCopy(CPDFSDK_Document* pDocument)
757 {
758         return FALSE;
759 }
760
761 FX_BOOL CFFL_FormFiller::CanCut(CPDFSDK_Document* pDocument)
762 {
763         return FALSE;
764 }
765
766 FX_BOOL CFFL_FormFiller::CanPaste(CPDFSDK_Document* pDocument)
767 {
768         return FALSE;
769 }
770
771 void CFFL_FormFiller::DoCopy(CPDFSDK_Document* pDocument)
772 {
773 }
774
775 void CFFL_FormFiller::DoCut(CPDFSDK_Document* pDocument)
776 {
777 }
778
779 void CFFL_FormFiller::DoPaste(CPDFSDK_Document* pDocument)
780 {
781 }
782
783 void CFFL_FormFiller::InvalidateRect(double left, double top, double right, double bottom)
784 {
785         CPDF_Page * pPage = m_pWidget->GetPDFPage();
786         m_pApp->FFI_Invalidate(pPage, left, top, right, bottom);
787 }
788
789 /* ------------------------- CFFL_Button ------------------------- */
790
791 CFFL_Button::CFFL_Button(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) :
792         CFFL_FormFiller(pApp, pWidget),
793         m_bMouseIn(FALSE),
794         m_bMouseDown(FALSE)
795 {
796 }
797
798 CFFL_Button::~CFFL_Button()
799 {
800 }
801
802 void CFFL_Button::OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
803 {
804         m_bMouseIn = TRUE;
805         FX_RECT rect = GetViewBBox(pPageView,pAnnot);
806         InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
807 }
808
809 void CFFL_Button::OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
810 {
811         m_bMouseIn = FALSE;
812
813         FX_RECT rect = GetViewBBox(pPageView,pAnnot);
814         InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
815         EndTimer();
816         ASSERT(m_pWidget != NULL);
817 }
818
819 FX_BOOL CFFL_Button::OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
820 {
821         CPDF_Rect rcAnnot = pAnnot->GetRect();
822         if(!rcAnnot.Contains(point.x, point.y))
823                 return FALSE;
824
825         m_bMouseDown = TRUE;
826         m_bValid = TRUE;
827         FX_RECT rect = GetViewBBox(pPageView, pAnnot);
828         InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
829         return TRUE;
830 }
831
832 FX_BOOL CFFL_Button::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
833 {
834         CPDF_Rect rcAnnot = pAnnot->GetRect();
835         if(!rcAnnot.Contains(point.x, point.y))
836                 return FALSE;
837
838         m_bMouseDown = FALSE;
839         m_pWidget->GetPDFPage();
840
841
842         FX_RECT rect = GetViewBBox(pPageView, pAnnot);
843         InvalidateRect(rect.left, rect.top, rect.right, rect.bottom);
844         return TRUE;
845 }
846
847 FX_BOOL CFFL_Button::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
848 {
849         ASSERT(m_pApp != NULL);
850
851         return TRUE;
852 }
853
854 void CFFL_Button::OnDraw(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot,
855                                                         CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
856                                                         /*const CRect& rcWindow,*/ FX_DWORD dwFlags)
857 {
858         ASSERT(pPageView != NULL);
859         ASSERT(pAnnot != NULL);
860
861         CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
862
863         CPDF_FormControl* pCtrl = pWidget->GetFormControl();
864         ASSERT(pCtrl != NULL);
865
866         CPDF_FormControl::HighlightingMode eHM = pCtrl->GetHighlightingMode();
867
868         if (eHM == CPDF_FormControl::Push)
869         {
870                 if (m_bMouseDown)
871                 {
872                         if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Down))
873                                 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Down, NULL);
874                         else
875                                 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
876                 }
877                 else if (m_bMouseIn)
878                 {
879                         if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Rollover))
880                                 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Rollover, NULL);
881                         else
882                                 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
883                 }
884                 else
885                 {
886                         pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
887                 }
888         }
889         else
890                 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
891 }
892
893
894 void CFFL_Button::OnDrawDeactive(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot,
895                                                                  CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,
896                                                                  /*const CRect& rcWindow, */FX_DWORD dwFlags)
897 {
898         OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
899 }