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