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