Initial commit.
[pdfium.git] / fpdfsdk / src / fsdk_baseform.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4  \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "../include/fsdk_define.h"\r
8 #include "../include/fsdk_mgr.h"\r
9 #include "../include/fsdk_baseannot.h"\r
10 #include "../include/fsdk_baseform.h"\r
11 #include "../include/formfiller/FFL_FormFiller.h"\r
12 #include "../include/fsdk_actionhandler.h"\r
13 \r
14 #include "../include/javascript/IJavaScript.h"\r
15 \r
16 //------------------------------------------------------------------------------------\r
17 //*                                                                             CPDFSDK_Widget \r
18 //------------------------------------------------------------------------------------\r
19 \r
20 #define IsFloatZero(f)                                          ((f) < 0.01 && (f) > -0.01)\r
21 #define IsFloatBigger(fa,fb)                            ((fa) > (fb) && !IsFloatZero((fa) - (fb)))\r
22 #define IsFloatSmaller(fa,fb)                           ((fa) < (fb) && !IsFloatZero((fa) - (fb)))\r
23 #define IsFloatEqual(fa,fb)                                     IsFloatZero((fa)-(fb))\r
24 \r
25 CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView, CPDFSDK_InterForm* pInterForm) :\r
26                                         CPDFSDK_Annot(pAnnot, pPageView),\r
27                                         m_pInterForm(pInterForm),\r
28                                         m_nAppAge(0),\r
29                                         m_nValueAge(0)\r
30 {\r
31         ASSERT(m_pInterForm != NULL);\r
32 }\r
33 \r
34 CPDFSDK_Widget::~CPDFSDK_Widget()\r
35 {\r
36 \r
37 }\r
38 \r
39 FX_BOOL         CPDFSDK_Widget::IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode)\r
40 {\r
41         ASSERT(m_pAnnot != NULL);\r
42         ASSERT(m_pAnnot->m_pAnnotDict != NULL);\r
43         \r
44         CPDF_Dictionary* pAP = m_pAnnot->m_pAnnotDict->GetDict("AP");\r
45         if (pAP == NULL) return FALSE;\r
46         \r
47         // Choose the right sub-ap\r
48         const FX_CHAR* ap_entry = "N";\r
49         if (mode == CPDF_Annot::Down)\r
50                 ap_entry = "D";\r
51         else if (mode == CPDF_Annot::Rollover)\r
52                 ap_entry = "R";\r
53         if (!pAP->KeyExist(ap_entry))\r
54                 ap_entry = "N";\r
55         \r
56         // Get the AP stream or subdirectory\r
57         CPDF_Object* psub = pAP->GetElementValue(ap_entry);\r
58         if (psub == NULL) return FALSE;\r
59         \r
60         int nFieldType = GetFieldType();\r
61         switch (nFieldType)\r
62         {\r
63         case FIELDTYPE_PUSHBUTTON:\r
64         case FIELDTYPE_COMBOBOX:\r
65         case FIELDTYPE_LISTBOX:\r
66         case FIELDTYPE_TEXTFIELD:\r
67         case FIELDTYPE_SIGNATURE:\r
68                 return psub->GetType() == PDFOBJ_STREAM;\r
69         case FIELDTYPE_CHECKBOX:\r
70         case FIELDTYPE_RADIOBUTTON:\r
71                 if (psub->GetType() == PDFOBJ_DICTIONARY) \r
72                 {\r
73                         CPDF_Dictionary* pSubDict = (CPDF_Dictionary*)psub;\r
74                         \r
75                         return pSubDict->GetStream(this->GetAppState()) != NULL;\r
76                 }\r
77                 else\r
78                         return FALSE;\r
79                 break;\r
80         }\r
81         \r
82         return TRUE;\r
83 }\r
84 \r
85 int     CPDFSDK_Widget::GetFieldType() const\r
86 {\r
87         CPDF_FormField* pField = GetFormField();\r
88         ASSERT(pField != NULL);\r
89         \r
90         return pField->GetFieldType();\r
91 }\r
92 \r
93 int CPDFSDK_Widget::GetFieldFlags() const\r
94 {\r
95         CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();\r
96         ASSERT(pPDFInterForm != NULL);\r
97 \r
98         CPDF_FormControl* pFormControl = pPDFInterForm->GetControlByDict(m_pAnnot->m_pAnnotDict);\r
99         CPDF_FormField* pFormField = pFormControl->GetField();\r
100         return pFormField->GetFieldFlags();\r
101 }\r
102 \r
103 CFX_ByteString CPDFSDK_Widget::GetSubType() const\r
104 {\r
105         int nType = GetFieldType();\r
106         \r
107         if (nType == FIELDTYPE_SIGNATURE)\r
108                 return BFFT_SIGNATURE;\r
109         return CPDFSDK_Annot::GetSubType();\r
110 }\r
111 \r
112 CPDF_FormField* CPDFSDK_Widget::GetFormField() const\r
113 {\r
114         ASSERT(m_pInterForm != NULL);\r
115         \r
116         CPDF_FormControl* pCtrl = GetFormControl();     \r
117         ASSERT(pCtrl != NULL);\r
118         \r
119         return pCtrl->GetField();\r
120 }\r
121 \r
122 CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const\r
123 {\r
124         ASSERT(m_pInterForm != NULL);\r
125         \r
126         CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();\r
127         ASSERT(pPDFInterForm != NULL);\r
128         \r
129         return pPDFInterForm->GetControlByDict(GetAnnotDict());\r
130 }\r
131 static CPDF_Dictionary* BF_GetField(CPDF_Dictionary* pFieldDict, const FX_CHAR* name)\r
132 {\r
133         if (pFieldDict == NULL) return NULL;\r
134         // First check the dictionary itself\r
135         CPDF_Object* pAttr = pFieldDict->GetElementValue(name);\r
136         if (pAttr) return pFieldDict;\r
137         \r
138         // Now we need to search from parents\r
139         CPDF_Dictionary* pParent = pFieldDict->GetDict("Parent");\r
140         if (pParent == NULL) return NULL;\r
141         \r
142         return BF_GetField(pParent, name);\r
143 }\r
144 \r
145 CPDF_FormControl* CPDFSDK_Widget::GetFormControl(CPDF_InterForm* pInterForm, CPDF_Dictionary* pAnnotDict)\r
146 {\r
147         ASSERT(pInterForm != NULL);\r
148         ASSERT(pAnnotDict != NULL);\r
149         \r
150         CPDF_FormControl* pControl = pInterForm->GetControlByDict(pAnnotDict);\r
151         \r
152         return pControl;\r
153 }\r
154 \r
155 int CPDFSDK_Widget::GetRotate() const\r
156 {\r
157         CPDF_FormControl* pCtrl = this->GetFormControl();\r
158         ASSERT(pCtrl != NULL);\r
159         \r
160         return pCtrl->GetRotation() % 360;\r
161 }\r
162 \r
163 FX_BOOL CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const\r
164 {\r
165         CPDF_FormControl* pFormCtrl = GetFormControl();\r
166         ASSERT(pFormCtrl != NULL);\r
167         \r
168         int iColorType = 0;     \r
169         color = FX_ARGBTOCOLORREF(pFormCtrl->GetBackgroundColor(iColorType));\r
170         \r
171         return iColorType != COLORTYPE_TRANSPARENT;\r
172 }\r
173 \r
174 FX_BOOL CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const\r
175 {\r
176         CPDF_FormControl* pFormCtrl = GetFormControl();\r
177         ASSERT(pFormCtrl != NULL);\r
178         \r
179         int iColorType = 0;     \r
180         color = FX_ARGBTOCOLORREF(pFormCtrl->GetBorderColor(iColorType));\r
181         \r
182         return iColorType != COLORTYPE_TRANSPARENT;\r
183 }\r
184 \r
185 FX_BOOL CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const\r
186 {\r
187         CPDF_FormControl* pFormCtrl = GetFormControl();\r
188         ASSERT(pFormCtrl != NULL);\r
189         \r
190         CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();\r
191         if (da.HasColor())\r
192         {\r
193                 FX_ARGB argb;\r
194                 int iColorType = COLORTYPE_TRANSPARENT; \r
195                 da.GetColor(argb, iColorType);\r
196                 color = FX_ARGBTOCOLORREF(argb);\r
197                 \r
198                 return iColorType != COLORTYPE_TRANSPARENT;\r
199         }\r
200         \r
201         return FALSE;\r
202 }\r
203 \r
204 FX_FLOAT CPDFSDK_Widget::GetFontSize() const\r
205 {\r
206         CPDF_FormControl* pFormCtrl = GetFormControl();\r
207         ASSERT(pFormCtrl != NULL);\r
208         \r
209         CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance();\r
210         CFX_ByteString csFont = "";\r
211         FX_FLOAT fFontSize = 0.0f;\r
212         pDa.GetFont(csFont, fFontSize);\r
213         \r
214         return fFontSize;\r
215 }\r
216 \r
217 int     CPDFSDK_Widget::GetSelectedIndex(int nIndex) const\r
218 {\r
219         CPDF_FormField* pFormField = GetFormField();\r
220         ASSERT(pFormField != NULL);\r
221         \r
222         return pFormField->GetSelectedIndex(nIndex);\r
223 }\r
224 \r
225 CFX_WideString CPDFSDK_Widget::GetValue() const\r
226 {\r
227         CPDF_FormField* pFormField = GetFormField();\r
228         ASSERT(pFormField != NULL);\r
229         \r
230         return pFormField->GetValue();\r
231 }\r
232 \r
233 CFX_WideString CPDFSDK_Widget::GetDefaultValue() const\r
234 {\r
235         CPDF_FormField* pFormField = GetFormField();\r
236         ASSERT(pFormField != NULL);\r
237         \r
238         return pFormField->GetDefaultValue();\r
239 }\r
240 \r
241 CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const\r
242 {\r
243         CPDF_FormField* pFormField = GetFormField();\r
244         ASSERT(pFormField != NULL);\r
245         \r
246         return pFormField->GetOptionLabel(nIndex);\r
247 }\r
248 \r
249 int     CPDFSDK_Widget::CountOptions() const\r
250 {\r
251         CPDF_FormField* pFormField = GetFormField();\r
252         ASSERT(pFormField != NULL);\r
253         \r
254         return pFormField->CountOptions();\r
255 }\r
256 \r
257 FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const\r
258 {\r
259         CPDF_FormField* pFormField = GetFormField();\r
260         ASSERT(pFormField != NULL);\r
261         \r
262         return pFormField->IsItemSelected(nIndex);\r
263 }\r
264 \r
265 int     CPDFSDK_Widget::GetTopVisibleIndex() const\r
266 {\r
267         CPDF_FormField* pFormField = GetFormField();\r
268         ASSERT(pFormField != NULL);\r
269         \r
270         return pFormField->GetTopVisibleIndex();\r
271 }\r
272 \r
273 FX_BOOL CPDFSDK_Widget::IsChecked() const\r
274 {\r
275         CPDF_FormControl* pFormCtrl = GetFormControl();\r
276         ASSERT(pFormCtrl != NULL);\r
277         \r
278         return pFormCtrl->IsChecked();\r
279 }\r
280 \r
281 int     CPDFSDK_Widget::GetAlignment() const\r
282 {\r
283         CPDF_FormControl* pFormCtrl = GetFormControl();\r
284         ASSERT(pFormCtrl != NULL);\r
285         \r
286         return pFormCtrl->GetControlAlignment();\r
287 }\r
288 \r
289 int     CPDFSDK_Widget::GetMaxLen() const\r
290 {\r
291         CPDF_FormField* pFormField = GetFormField();\r
292         ASSERT(pFormField != NULL);\r
293         \r
294         return pFormField->GetMaxLen();\r
295 }\r
296 \r
297 void CPDFSDK_Widget::SetCheck(FX_BOOL bChecked, FX_BOOL bNotify)\r
298 {\r
299         CPDF_FormControl* pFormCtrl = GetFormControl();\r
300         ASSERT(pFormCtrl != NULL);\r
301         \r
302         CPDF_FormField* pFormField = pFormCtrl->GetField();\r
303         ASSERT(pFormField != NULL);\r
304         \r
305         pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked, bNotify);\r
306 }\r
307 \r
308 void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify)\r
309 {\r
310         CPDF_FormField* pFormField = GetFormField();\r
311         ASSERT(pFormField != NULL);\r
312         \r
313         pFormField->SetValue(sValue, bNotify);\r
314 }\r
315 \r
316 void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue)\r
317 {\r
318 }\r
319 void CPDFSDK_Widget::SetOptionSelection(int index, FX_BOOL bSelected, FX_BOOL bNotify)\r
320 {\r
321         CPDF_FormField* pFormField = GetFormField();\r
322         ASSERT(pFormField != NULL);\r
323         \r
324         pFormField->SetItemSelection(index, bSelected, bNotify);\r
325 }\r
326 \r
327 void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify)\r
328 {\r
329         CPDF_FormField* pFormField = GetFormField();\r
330         ASSERT(pFormField != NULL);\r
331         \r
332         pFormField->ClearSelection(bNotify);\r
333 }\r
334 \r
335 void CPDFSDK_Widget::SetTopVisibleIndex(int index)\r
336 {\r
337 }\r
338 \r
339 void CPDFSDK_Widget::SetAppModified()\r
340 {\r
341         m_bAppModified = TRUE;\r
342 }\r
343 \r
344 void CPDFSDK_Widget::ClearAppModified()\r
345 {\r
346         m_bAppModified = FALSE;\r
347 }\r
348 \r
349 FX_BOOL CPDFSDK_Widget::IsAppModified() const\r
350 {\r
351         return m_bAppModified;\r
352 }\r
353 \r
354 void CPDFSDK_Widget::ResetAppearance(FX_LPCWSTR sValue, FX_BOOL bValueChanged)\r
355 {\r
356         SetAppModified();\r
357 \r
358         m_nAppAge++;\r
359         if (m_nAppAge > 999999)\r
360                 m_nAppAge = 0;\r
361         if (bValueChanged)\r
362                 m_nValueAge++;\r
363 \r
364         int nFieldType = GetFieldType();\r
365         \r
366         switch (nFieldType)\r
367         {\r
368         case FIELDTYPE_PUSHBUTTON:\r
369                 ResetAppearance_PushButton();\r
370                 break;\r
371         case FIELDTYPE_CHECKBOX:\r
372                 ResetAppearance_CheckBox();\r
373                 break;\r
374         case FIELDTYPE_RADIOBUTTON:\r
375                 ResetAppearance_RadioButton();\r
376                 break;\r
377         case FIELDTYPE_COMBOBOX:\r
378                 ResetAppearance_ComboBox(sValue);\r
379                 break;\r
380         case FIELDTYPE_LISTBOX:\r
381                 ResetAppearance_ListBox();\r
382                 break;\r
383         case FIELDTYPE_TEXTFIELD:\r
384                 ResetAppearance_TextField(sValue);\r
385                 break;\r
386         }\r
387         \r
388         ASSERT(m_pAnnot != NULL);\r
389         m_pAnnot->ClearCachedAP();\r
390 }\r
391 \r
392 CFX_WideString CPDFSDK_Widget::OnFormat(int nCommitKey, FX_BOOL& bFormated)\r
393 {\r
394         CPDF_FormField* pFormField = GetFormField();\r
395         ASSERT(pFormField != NULL);\r
396         \r
397         ASSERT(m_pInterForm != NULL);\r
398         \r
399         return m_pInterForm->OnFormat(pFormField, nCommitKey, bFormated);\r
400 \r
401 }\r
402 \r
403 void CPDFSDK_Widget::ResetFieldAppearance(FX_BOOL bValueChanged)\r
404 {\r
405         CPDF_FormField* pFormField = GetFormField();\r
406         ASSERT(pFormField != NULL);\r
407         \r
408         ASSERT(m_pInterForm != NULL);\r
409 \r
410         m_pInterForm->ResetFieldAppearance(pFormField, NULL, bValueChanged);\r
411 }\r
412 \r
413 void    CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,\r
414                 CPDF_Annot::AppearanceMode mode, const CPDF_RenderOptions* pOptions)\r
415 {\r
416         int nFieldType = GetFieldType();\r
417         \r
418         if ((nFieldType == FIELDTYPE_CHECKBOX || nFieldType == FIELDTYPE_RADIOBUTTON) &&\r
419                 mode == CPDF_Annot::Normal && \r
420                 !this->IsWidgetAppearanceValid(CPDF_Annot::Normal))\r
421         {\r
422                 CFX_PathData pathData;\r
423                 \r
424                 CPDF_Rect rcAnnot = this->GetRect();\r
425                 \r
426                 pathData.AppendRect(rcAnnot.left, rcAnnot.bottom,\r
427                         rcAnnot.right, rcAnnot.top);\r
428                 \r
429                 CFX_GraphStateData gsd;\r
430                 gsd.m_LineWidth = 0.0f;\r
431                 \r
432                 pDevice->DrawPath(&pathData, pUser2Device, &gsd, 0, 0xFFAAAAAA, FXFILL_ALTERNATE);\r
433         }\r
434         else\r
435         {\r
436                 CPDFSDK_Annot::DrawAppearance(pDevice, pUser2Device, mode, pOptions);\r
437         }\r
438 }\r
439 \r
440 void CPDFSDK_Widget::UpdateField()\r
441 {\r
442         CPDF_FormField* pFormField = GetFormField();\r
443         ASSERT(pFormField != NULL);\r
444         \r
445         ASSERT(m_pInterForm != NULL);\r
446         m_pInterForm->UpdateField(pFormField);\r
447 }\r
448 \r
449 void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice, CPDFSDK_PageView* pPageView)\r
450 {\r
451         ASSERT(m_pInterForm != NULL);\r
452  \r
453         int nFieldType = GetFieldType();\r
454         if (m_pInterForm->IsNeedHighLight(nFieldType))\r
455         {\r
456  \r
457 //              if (nFieldType != FIELDTYPE_PUSHBUTTON)\r
458 //              {\r
459                         CPDF_Rect rc  = GetRect();\r
460                         FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType);\r
461                         FX_BYTE alpha = m_pInterForm->GetHighlightAlpha();\r
462 \r
463                         CFX_FloatRect rcDevice;\r
464                         ASSERT(m_pInterForm->GetDocument());\r
465                         CPDFDoc_Environment* pEnv = m_pInterForm->GetDocument()->GetEnv();\r
466                         if(!pEnv)\r
467                                 return;\r
468                         CFX_AffineMatrix page2device;\r
469                         pPageView->GetCurrentMatrix(page2device);\r
470                         page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom), rcDevice.left, rcDevice.bottom);\r
471 //                      pEnv->FFI_PageToDevice(m_pPageView->GetPDFPage(), rc.left, rc.bottom, &rcDevice.left, &rcDevice.bottom);\r
472 //                      pEnv->FFI_PageToDevice(m_pPageView->GetPDFPage(), rc.right, rc.top, &rcDevice.right, &rcDevice.top);\r
473                         page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top), rcDevice.right, rcDevice.top);\r
474 \r
475                         rcDevice.Normalize();\r
476 \r
477                         FX_ARGB argb = ArgbEncode((int)alpha, color);\r
478                         FX_RECT rcDev((int)rcDevice.left,(int)rcDevice.top,(int)rcDevice.right,(int)rcDevice.bottom);\r
479                         pDevice->FillRect(&rcDev, argb);        \r
480                         /*              }*/\r
481         }\r
482 }\r
483 \r
484 void CPDFSDK_Widget::ResetAppearance_PushButton()\r
485 {\r
486         CPDF_FormControl* pControl = GetFormControl();\r
487         ASSERT(pControl != NULL);\r
488 \r
489 \r
490         \r
491         CPDF_Rect rcWindow = GetRotatedRect();  \r
492 \r
493         FX_INT32 nLayout = 0;\r
494 \r
495         switch (pControl->GetTextPosition())\r
496         {\r
497         case TEXTPOS_ICON:\r
498                 nLayout = PPBL_ICON;\r
499                 break;\r
500         case TEXTPOS_BELOW:\r
501                 nLayout = PPBL_ICONTOPLABELBOTTOM;\r
502                 break;\r
503         case TEXTPOS_ABOVE:\r
504                 nLayout = PPBL_LABELTOPICONBOTTOM;\r
505                 break;\r
506         case TEXTPOS_RIGHT:\r
507                 nLayout = PPBL_ICONLEFTLABELRIGHT;\r
508                 break;\r
509         case TEXTPOS_LEFT:\r
510                 nLayout = PPBL_LABELLEFTICONRIGHT;\r
511                 break;\r
512         case TEXTPOS_OVERLAID:\r
513                 nLayout = PPBL_LABELOVERICON;\r
514                 break;\r
515         default:\r
516                 nLayout = PPBL_LABEL;\r
517                 break;\r
518         }\r
519 \r
520         CPWL_Color crBackground, crBorder;\r
521 \r
522         int iColorType;\r
523         FX_FLOAT fc[4];\r
524 \r
525         pControl->GetOriginalBackgroundColor(iColorType, fc);\r
526         if (iColorType > 0)\r
527                 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
528 \r
529         pControl->GetOriginalBorderColor(iColorType, fc);\r
530         if (iColorType > 0)\r
531                 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
532 \r
533         FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();\r
534         FX_INT32 nBorderStyle = 0;\r
535         CPWL_Dash dsBorder(3,0,0);\r
536         CPWL_Color crLeftTop,crRightBottom;\r
537 \r
538         switch (GetBorderStyle())\r
539         {\r
540         case BBS_DASH:\r
541                 nBorderStyle = PBS_DASH;\r
542                 dsBorder = CPWL_Dash(3, 3, 0);\r
543                 break;\r
544         case BBS_BEVELED:\r
545                 nBorderStyle = PBS_BEVELED;\r
546                 fBorderWidth *= 2;\r
547                 crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);\r
548                 crRightBottom = CPWL_Utils::DevideColor(crBackground,2);\r
549                 break;\r
550         case BBS_INSET:\r
551                 nBorderStyle = PBS_INSET;\r
552                 fBorderWidth *= 2;\r
553                 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);\r
554                 crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);\r
555                 break;\r
556         case BBS_UNDERLINE:\r
557                 nBorderStyle = PBS_UNDERLINED;\r
558                 break;\r
559         default: \r
560                 nBorderStyle = PBS_SOLID;\r
561                 break;\r
562         }\r
563 \r
564         CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow,fBorderWidth);    \r
565 \r
566         CPWL_Color crText(COLORTYPE_GRAY,0);\r
567 \r
568         FX_FLOAT fFontSize = 12.0f;\r
569         CFX_ByteString csNameTag;\r
570 \r
571         CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();\r
572         if (da.HasColor())\r
573         {\r
574                 da.GetColor(iColorType, fc);\r
575                 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
576         }\r
577 \r
578         if (da.HasFont()) \r
579                 da.GetFont(csNameTag, fFontSize);\r
580 \r
581         CFX_WideString csWCaption;\r
582         CFX_WideString csNormalCaption, csRolloverCaption, csDownCaption;\r
583 \r
584         if (pControl->HasMKEntry("CA"))\r
585         {\r
586                 csNormalCaption = pControl->GetNormalCaption();\r
587         }\r
588         if (pControl->HasMKEntry("RC"))\r
589         {\r
590                 csRolloverCaption = pControl->GetRolloverCaption();\r
591         }\r
592         if (pControl->HasMKEntry("AC"))\r
593         {\r
594                 csDownCaption = pControl->GetDownCaption();\r
595         }\r
596 \r
597         CPDF_Stream* pNormalIcon = NULL;\r
598         CPDF_Stream* pRolloverIcon = NULL;\r
599         CPDF_Stream* pDownIcon = NULL;\r
600 \r
601         if (pControl->HasMKEntry("I"))\r
602         {\r
603                 pNormalIcon = pControl->GetNormalIcon();\r
604         }\r
605         if (pControl->HasMKEntry("RI"))\r
606         {\r
607                 pRolloverIcon = pControl->GetRolloverIcon();\r
608         }\r
609         if (pControl->HasMKEntry("IX"))\r
610         {\r
611                 pDownIcon = pControl->GetDownIcon();\r
612         }\r
613 \r
614         if (pNormalIcon)\r
615         {\r
616                 if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict())\r
617                 {\r
618                         if (pImageDict->GetString("Name").IsEmpty())\r
619                                 pImageDict->SetAtString("Name", "ImgA");\r
620                 }\r
621         }\r
622 \r
623         if (pRolloverIcon)\r
624         {\r
625                 if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict())\r
626                 {\r
627                         if (pImageDict->GetString("Name").IsEmpty())\r
628                                 pImageDict->SetAtString("Name", "ImgB");\r
629                 }\r
630         }\r
631 \r
632         if (pDownIcon)\r
633         {\r
634                 if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict())\r
635                 {\r
636                         if (pImageDict->GetString("Name").IsEmpty())\r
637                                 pImageDict->SetAtString("Name", "ImgC");\r
638                 }\r
639         }\r
640 \r
641         CPDF_IconFit iconFit = pControl->GetIconFit();\r
642 \r
643 //      ASSERT(this->m_pBaseForm != NULL);\r
644         ASSERT(this->m_pInterForm != NULL);\r
645         CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();\r
646         ASSERT(pDoc != NULL);\r
647         CPDFDoc_Environment* pEnv = pDoc->GetEnv();\r
648 \r
649         CBA_FontMap FontMap(this,pEnv->GetSysHandler());//, ISystemHandle::GetSystemHandler(m_pBaseForm->GetEnv()));\r
650         FontMap.Initial();\r
651 \r
652         FontMap.SetAPType("N");\r
653 \r
654         CFX_ByteString csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + \r
655                 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, dsBorder) +\r
656                 CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout);\r
657 \r
658         WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP);\r
659         if (pNormalIcon)\r
660                 AddImageToAppearance("N", pNormalIcon);\r
661 \r
662         CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode();\r
663         if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle)\r
664         {\r
665                 if (csRolloverCaption.IsEmpty() && !pRolloverIcon)                      \r
666                 {\r
667                         csRolloverCaption = csNormalCaption;\r
668                         pRolloverIcon = pNormalIcon;\r
669                 }\r
670 \r
671                 FontMap.SetAPType("R");\r
672 \r
673                 csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + \r
674                                 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, dsBorder) +\r
675                                 CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize, nLayout);\r
676 \r
677                 WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP);\r
678                 if (pRolloverIcon)\r
679                         AddImageToAppearance("R", pRolloverIcon);\r
680 \r
681                 if (csDownCaption.IsEmpty() && !pDownIcon)\r
682                 {\r
683                         csDownCaption = csNormalCaption;\r
684                         pDownIcon = pNormalIcon;\r
685                 }\r
686 \r
687                 switch (nBorderStyle)\r
688                 {\r
689                 case PBS_BEVELED:\r
690                         {\r
691                                 CPWL_Color crTemp = crLeftTop;\r
692                                 crLeftTop = crRightBottom;\r
693                                 crRightBottom = crTemp;\r
694                         }\r
695                         break;\r
696                 case PBS_INSET:\r
697                         crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);\r
698                         crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);\r
699                         break;\r
700                 }\r
701                 \r
702                 FontMap.SetAPType("D");\r
703 \r
704                 csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, CPWL_Utils::SubstractColor(crBackground,0.25f)) + \r
705                         CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, dsBorder) + \r
706                         CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout);\r
707 \r
708                 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP);\r
709                 if (pDownIcon)\r
710                         AddImageToAppearance("D", pDownIcon);\r
711         }\r
712         else\r
713         {\r
714                 RemoveAppearance("D");\r
715                 RemoveAppearance("R");\r
716         }\r
717 }\r
718 \r
719 void CPDFSDK_Widget::ResetAppearance_CheckBox()\r
720 {\r
721         CPDF_FormControl* pControl = GetFormControl();\r
722         ASSERT(pControl != NULL);\r
723 \r
724 \r
725 \r
726         CPWL_Color crBackground, crBorder, crText;\r
727         \r
728         int iColorType;\r
729         FX_FLOAT fc[4];\r
730 \r
731         pControl->GetOriginalBackgroundColor(iColorType, fc);\r
732         if (iColorType > 0)\r
733                 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
734 \r
735         pControl->GetOriginalBorderColor(iColorType, fc);\r
736         if (iColorType > 0)\r
737                 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
738 \r
739         FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();\r
740         FX_INT32 nBorderStyle = 0;\r
741         CPWL_Dash dsBorder(3,0,0);\r
742         CPWL_Color crLeftTop,crRightBottom;\r
743 \r
744         switch (GetBorderStyle())\r
745         {\r
746         case BBS_DASH:\r
747                 nBorderStyle = PBS_DASH;\r
748                 dsBorder = CPWL_Dash(3, 3, 0);\r
749                 break;\r
750         case BBS_BEVELED:\r
751                 nBorderStyle = PBS_BEVELED;\r
752                 fBorderWidth *= 2;\r
753                 crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);\r
754                 crRightBottom = CPWL_Utils::DevideColor(crBackground,2);\r
755                 break;\r
756         case BBS_INSET:\r
757                 nBorderStyle = PBS_INSET;\r
758                 fBorderWidth *= 2;\r
759                 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);\r
760                 crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);\r
761                 break;\r
762         case BBS_UNDERLINE:\r
763                 nBorderStyle = PBS_UNDERLINED;\r
764                 break;\r
765         default: \r
766                 nBorderStyle = PBS_SOLID;\r
767                 break;\r
768         }\r
769 \r
770         CPDF_Rect rcWindow = GetRotatedRect();\r
771         CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow,fBorderWidth);\r
772 \r
773         CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();\r
774         if (da.HasColor())\r
775         {\r
776                 da.GetColor(iColorType, fc);\r
777                 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
778         }\r
779 \r
780         FX_INT32 nStyle = 0;\r
781 \r
782         CFX_WideString csWCaption = pControl->GetNormalCaption();\r
783         if (csWCaption.GetLength() > 0)\r
784         {\r
785                 switch (csWCaption[0])\r
786                 {\r
787                 case L'l':\r
788                         nStyle = PCS_CIRCLE;                    \r
789                         break;\r
790                 case L'8':\r
791                         nStyle = PCS_CROSS;\r
792                         break;\r
793                 case L'u':\r
794                         nStyle = PCS_DIAMOND;\r
795                         break;\r
796                 case L'n':\r
797                         nStyle = PCS_SQUARE;\r
798                         break;\r
799                 case L'H':\r
800                         nStyle = PCS_STAR;\r
801                         break;\r
802                 default: //L'4'\r
803                         nStyle = PCS_CHECK;\r
804                         break;\r
805                 }\r
806         }\r
807         else\r
808         {\r
809                 nStyle = PCS_CHECK;\r
810         }\r
811 \r
812         CFX_ByteString csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,crBackground) +\r
813                 CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);\r
814 \r
815         CFX_ByteString csAP_N_OFF = csAP_N_ON;\r
816 \r
817         switch (nBorderStyle)\r
818         {\r
819         case PBS_BEVELED:\r
820                 {\r
821                         CPWL_Color crTemp = crLeftTop;\r
822                         crLeftTop = crRightBottom;\r
823                         crRightBottom = crTemp;\r
824                 }\r
825                 break;\r
826         case PBS_INSET:\r
827                 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);\r
828                 crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);\r
829                 break;\r
830         }\r
831 \r
832         CFX_ByteString csAP_D_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,CPWL_Utils::SubstractColor(crBackground,0.25f)) + \r
833                 CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);\r
834 \r
835         CFX_ByteString csAP_D_OFF = csAP_D_ON;\r
836 \r
837         csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient,nStyle,crText);\r
838         csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient,nStyle,crText);\r
839 \r
840         WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, pControl->GetCheckedAPState());\r
841         WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");\r
842 \r
843         WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, pControl->GetCheckedAPState());\r
844         WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");\r
845 \r
846         CFX_ByteString csAS = GetAppState();\r
847         if (csAS.IsEmpty())\r
848                 SetAppState("Off");\r
849 }\r
850 \r
851 void CPDFSDK_Widget::ResetAppearance_RadioButton()\r
852 {\r
853         CPDF_FormControl* pControl = GetFormControl();\r
854         ASSERT(pControl != NULL);\r
855         \r
856 \r
857 \r
858         CPWL_Color crBackground, crBorder, crText;\r
859         \r
860         int iColorType;\r
861         FX_FLOAT fc[4];\r
862 \r
863         pControl->GetOriginalBackgroundColor(iColorType, fc);\r
864         if (iColorType > 0)\r
865                 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
866 \r
867         pControl->GetOriginalBorderColor(iColorType, fc);\r
868         if (iColorType > 0)\r
869                 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
870 \r
871         FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();\r
872         FX_INT32 nBorderStyle = 0;\r
873         CPWL_Dash dsBorder(3,0,0);\r
874         CPWL_Color crLeftTop,crRightBottom;\r
875 \r
876         switch (GetBorderStyle())\r
877         {\r
878         case BBS_DASH:\r
879                 nBorderStyle = PBS_DASH;\r
880                 dsBorder = CPWL_Dash(3, 3, 0);\r
881                 break;\r
882         case BBS_BEVELED:\r
883                 nBorderStyle = PBS_BEVELED;\r
884                 fBorderWidth *= 2;\r
885                 crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);\r
886                 crRightBottom = CPWL_Utils::DevideColor(crBackground,2);\r
887                 break;\r
888         case BBS_INSET:\r
889                 nBorderStyle = PBS_INSET;\r
890                 fBorderWidth *= 2;\r
891                 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);\r
892                 crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);\r
893                 break;\r
894         case BBS_UNDERLINE:\r
895                 nBorderStyle = PBS_UNDERLINED;\r
896                 break;\r
897         default: \r
898                 nBorderStyle = PBS_SOLID;\r
899                 break;\r
900         }\r
901 \r
902         CPDF_Rect rcWindow = GetRotatedRect();\r
903         CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);\r
904 \r
905         CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();\r
906         if (da.HasColor())\r
907         {\r
908                 da.GetColor(iColorType, fc);\r
909                 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
910         }\r
911 \r
912         FX_INT32 nStyle = 0;\r
913 \r
914         CFX_WideString csWCaption = pControl->GetNormalCaption();\r
915         if (csWCaption.GetLength() > 0)\r
916         {\r
917                 switch (csWCaption[0])\r
918                 {\r
919                 default: //L'l':\r
920                         nStyle = PCS_CIRCLE;                    \r
921                         break;\r
922                 case L'8':\r
923                         nStyle = PCS_CROSS;\r
924                         break;\r
925                 case L'u':\r
926                         nStyle = PCS_DIAMOND;\r
927                         break;\r
928                 case L'n':\r
929                         nStyle = PCS_SQUARE;\r
930                         break;\r
931                 case L'H':\r
932                         nStyle = PCS_STAR;\r
933                         break;\r
934                 case L'4':\r
935                         nStyle = PCS_CHECK;\r
936                         break;\r
937                 }\r
938         }\r
939         else\r
940         {\r
941                 nStyle = PCS_CIRCLE;\r
942         }\r
943 \r
944         CFX_ByteString csAP_N_ON;\r
945 \r
946         CPDF_Rect rcCenter = CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f);\r
947         \r
948         if (nStyle == PCS_CIRCLE)\r
949         {\r
950                 if (nBorderStyle == PBS_BEVELED)\r
951                 {\r
952                         crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);\r
953                         crRightBottom = CPWL_Utils::SubstractColor(crBackground,0.25f);\r
954                 }\r
955                 else if (nBorderStyle == PBS_INSET)\r
956                 {\r
957                         crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5f);\r
958                         crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75f);\r
959                 }\r
960 \r
961                 csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter,crBackground) + \r
962                         CPWL_Utils::GetCircleBorderAppStream(rcCenter,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);\r
963         }\r
964         else\r
965         {\r
966                 csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,crBackground) + \r
967                         CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);\r
968         }\r
969 \r
970         CFX_ByteString csAP_N_OFF = csAP_N_ON;\r
971 \r
972         switch (nBorderStyle)\r
973         {\r
974         case PBS_BEVELED:\r
975                 {\r
976                         CPWL_Color crTemp = crLeftTop;\r
977                         crLeftTop = crRightBottom;\r
978                         crRightBottom = crTemp;\r
979                 }\r
980                 break;\r
981         case PBS_INSET:\r
982                 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);\r
983                 crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);\r
984                 break;\r
985         }\r
986 \r
987         CFX_ByteString csAP_D_ON;\r
988 \r
989         if (nStyle == PCS_CIRCLE)\r
990         {\r
991                 CPWL_Color crBK = CPWL_Utils::SubstractColor(crBackground,0.25f);\r
992                 if (nBorderStyle == PBS_BEVELED)\r
993                 {\r
994                         crLeftTop = CPWL_Utils::SubstractColor(crBackground,0.25f);\r
995                         crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);\r
996                         crBK = crBackground;\r
997                 }\r
998                 else if (nBorderStyle == PBS_INSET)\r
999                 {\r
1000                         crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);\r
1001                         crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);\r
1002                 }\r
1003 \r
1004                 csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter,crBK)\r
1005                         + CPWL_Utils::GetCircleBorderAppStream(rcCenter,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);\r
1006         }\r
1007         else\r
1008         {\r
1009                 csAP_D_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,CPWL_Utils::SubstractColor(crBackground,0.25f)) + \r
1010                         CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);           \r
1011         }\r
1012 \r
1013         CFX_ByteString csAP_D_OFF = csAP_D_ON;\r
1014 \r
1015         csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient,nStyle,crText);\r
1016         csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient,nStyle,crText);\r
1017 \r
1018         WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, pControl->GetCheckedAPState());\r
1019         WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");\r
1020 \r
1021         WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, pControl->GetCheckedAPState());\r
1022         WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");\r
1023 \r
1024         CFX_ByteString csAS = GetAppState();\r
1025         if (csAS.IsEmpty())\r
1026                 SetAppState("Off");\r
1027 }\r
1028 \r
1029 void CPDFSDK_Widget::ResetAppearance_ComboBox(FX_LPCWSTR sValue)\r
1030 {\r
1031         CPDF_FormControl* pControl = GetFormControl();\r
1032         ASSERT(pControl != NULL);\r
1033         CPDF_FormField* pField = pControl->GetField();\r
1034         ASSERT(pField != NULL);\r
1035 \r
1036         CFX_ByteTextBuf sBody, sLines;\r
1037 \r
1038         CPDF_Rect rcClient = GetClientRect();\r
1039         CPDF_Rect rcButton = rcClient;\r
1040         rcButton.left = rcButton.right - 13;\r
1041         rcButton.Normalize();\r
1042 \r
1043         if (IFX_Edit * pEdit = IFX_Edit::NewEdit())\r
1044         {\r
1045                 pEdit->EnableRefresh(FALSE);\r
1046 \r
1047                 ASSERT(this->m_pInterForm != NULL);\r
1048                 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();\r
1049                 ASSERT(pDoc != NULL);\r
1050                 CPDFDoc_Environment* pEnv = pDoc->GetEnv();\r
1051                 CBA_FontMap FontMap(this,pEnv->GetSysHandler());\r
1052                 FontMap.Initial();\r
1053                 pEdit->SetFontMap(&FontMap);\r
1054 \r
1055                 CPDF_Rect rcEdit = rcClient;\r
1056                 rcEdit.right = rcButton.left;\r
1057                 rcEdit.Normalize();\r
1058                 \r
1059                 pEdit->SetPlateRect(rcEdit);\r
1060                 pEdit->SetAlignmentV(1);\r
1061 \r
1062                 FX_FLOAT fFontSize = this->GetFontSize();\r
1063                 if (IsFloatZero(fFontSize))\r
1064                         pEdit->SetAutoFontSize(TRUE);\r
1065                 else\r
1066                         pEdit->SetFontSize(fFontSize);\r
1067                 \r
1068                 pEdit->Initialize();\r
1069                 \r
1070                 if (sValue)\r
1071                         pEdit->SetText(sValue);\r
1072                 else\r
1073                 {\r
1074                         FX_INT32 nCurSel = pField->GetSelectedIndex(0);\r
1075 \r
1076                         if (nCurSel < 0)\r
1077                                 pEdit->SetText((FX_LPCWSTR)pField->GetValue());\r
1078                         else\r
1079                                 pEdit->SetText((FX_LPCWSTR)pField->GetOptionLabel(nCurSel));\r
1080                 }\r
1081 \r
1082                 CPDF_Rect rcContent = pEdit->GetContentRect();\r
1083 \r
1084                 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,0.0f));\r
1085                 if (sEdit.GetLength() > 0)\r
1086                 {\r
1087                         sBody << "/Tx BMC\n" << "q\n";\r
1088                         if (rcContent.Width() > rcEdit.Width() ||\r
1089                                 rcContent.Height() > rcEdit.Height())\r
1090                         {\r
1091                                 sBody << rcEdit.left << " " << rcEdit.bottom << " " \r
1092                                         << rcEdit.Width() << " " << rcEdit.Height() << " re\nW\nn\n";\r
1093                         }\r
1094 \r
1095                         CPWL_Color crText = GetTextPWLColor();  \r
1096                         sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" << "Q\nEMC\n";\r
1097                 }\r
1098 \r
1099                 IFX_Edit::DelEdit(pEdit);\r
1100         }\r
1101 \r
1102         sBody << CPWL_Utils::GetDropButtonAppStream(rcButton);\r
1103 \r
1104         CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.GetByteString() + sBody.GetByteString();\r
1105 \r
1106         WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);\r
1107 }\r
1108 \r
1109 void CPDFSDK_Widget::ResetAppearance_ListBox()\r
1110 {\r
1111         CPDF_FormControl* pControl = GetFormControl();\r
1112         ASSERT(pControl != NULL);\r
1113         CPDF_FormField* pField = pControl->GetField();\r
1114         ASSERT(pField != NULL);\r
1115 \r
1116         CPDF_Rect rcClient = GetClientRect();\r
1117 \r
1118         CFX_ByteTextBuf sBody, sLines;\r
1119 \r
1120         if (IFX_Edit * pEdit = IFX_Edit::NewEdit())\r
1121         {\r
1122                 pEdit->EnableRefresh(FALSE);\r
1123 \r
1124 //              ASSERT(this->m_pBaseForm != NULL);\r
1125                 ASSERT(this->m_pInterForm != NULL);\r
1126                 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();\r
1127                 ASSERT(pDoc != NULL);\r
1128                 CPDFDoc_Environment* pEnv = pDoc->GetEnv();\r
1129 \r
1130                 CBA_FontMap FontMap(this,pEnv->GetSysHandler());\r
1131                 FontMap.Initial();\r
1132                 pEdit->SetFontMap(&FontMap);\r
1133 \r
1134                 pEdit->SetPlateRect(CPDF_Rect(rcClient.left,0.0f,rcClient.right,0.0f)); \r
1135                 \r
1136                 FX_FLOAT fFontSize = GetFontSize();\r
1137 \r
1138                 if (IsFloatZero(fFontSize))\r
1139                         pEdit->SetFontSize(12.0f);\r
1140                 else\r
1141                         pEdit->SetFontSize(fFontSize);\r
1142                 \r
1143                 pEdit->Initialize();\r
1144 \r
1145                 CFX_ByteTextBuf sList;\r
1146                 FX_FLOAT fy = rcClient.top;\r
1147 \r
1148                 FX_INT32 nTop = pField->GetTopVisibleIndex();\r
1149                 FX_INT32 nCount = pField->CountOptions();\r
1150                 FX_INT32 nSelCount = pField->CountSelectedItems();\r
1151 \r
1152                 for (FX_INT32 i=nTop; i<nCount; i++)\r
1153                 {\r
1154                         FX_BOOL bSelected = FALSE;                              \r
1155                         for (FX_INT32 j=0; j<nSelCount; j++)\r
1156                         {\r
1157                                 if (pField->GetSelectedIndex(j) == i)\r
1158                                 {\r
1159                                         bSelected = TRUE;\r
1160                                         break;\r
1161                                 }\r
1162                         }\r
1163 \r
1164                         pEdit->SetText((FX_LPCWSTR)pField->GetOptionLabel(i));\r
1165 \r
1166                         CPDF_Rect rcContent = pEdit->GetContentRect();\r
1167                         FX_FLOAT fItemHeight = rcContent.Height();\r
1168 \r
1169                         if (bSelected)\r
1170                         {\r
1171                                 CPDF_Rect rcItem = CPDF_Rect(rcClient.left,fy-fItemHeight,rcClient.right,fy);\r
1172                                 sList << "q\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_RGB,0,51.0f/255.0f,113.0f/255.0f),TRUE)\r
1173                                         << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() << " " << rcItem.Height() << " re f\n" << "Q\n";\r
1174 \r
1175                                 sList << "BT\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY,1),TRUE) << \r
1176                                         CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,fy)) << "ET\n";\r
1177                         }\r
1178                         else\r
1179                         {\r
1180                                 CPWL_Color crText = GetTextPWLColor();\r
1181                                 sList << "BT\n" << CPWL_Utils::GetColorAppStream(crText,TRUE) << \r
1182                                 CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,fy)) << "ET\n";\r
1183                         }\r
1184 \r
1185                         fy -= fItemHeight;\r
1186                 }\r
1187                                         \r
1188                 if (sList.GetSize() > 0)\r
1189                 {\r
1190                         sBody << "/Tx BMC\n" << "q\n" << rcClient.left << " " << rcClient.bottom << " " \r
1191                                         << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";\r
1192                         sBody << sList << "Q\nEMC\n";\r
1193                 }\r
1194 \r
1195                 IFX_Edit::DelEdit(pEdit);\r
1196         }\r
1197 \r
1198         CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.GetByteString() + sBody.GetByteString();\r
1199 \r
1200         WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);\r
1201 }\r
1202 \r
1203 void CPDFSDK_Widget::ResetAppearance_TextField(FX_LPCWSTR sValue)\r
1204 {\r
1205         CPDF_FormControl* pControl = GetFormControl();\r
1206         ASSERT(pControl != NULL);\r
1207         CPDF_FormField* pField = pControl->GetField();\r
1208         ASSERT(pField != NULL);\r
1209 \r
1210         CFX_ByteTextBuf sBody, sLines;\r
1211         \r
1212         if (IFX_Edit * pEdit = IFX_Edit::NewEdit())\r
1213         {\r
1214                 pEdit->EnableRefresh(FALSE);\r
1215 \r
1216 //              ASSERT(this->m_pBaseForm != NULL);\r
1217                 ASSERT(this->m_pInterForm != NULL);\r
1218                 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();\r
1219                 ASSERT(pDoc != NULL);\r
1220                 CPDFDoc_Environment* pEnv = pDoc->GetEnv();\r
1221 \r
1222                 CBA_FontMap FontMap(this,pEnv->GetSysHandler());//, ISystemHandle::GetSystemHandler(m_pBaseForm->GetEnv()));\r
1223                 FontMap.Initial();\r
1224                 pEdit->SetFontMap(&FontMap);\r
1225 \r
1226                 CPDF_Rect rcClient = GetClientRect();\r
1227                 pEdit->SetPlateRect(rcClient);\r
1228                 pEdit->SetAlignmentH(pControl->GetControlAlignment());\r
1229                 \r
1230                 FX_DWORD dwFieldFlags = pField->GetFieldFlags();\r
1231                 FX_BOOL bMultiLine = (dwFieldFlags >> 12) & 1;\r
1232 \r
1233                 if (bMultiLine)\r
1234                 {\r
1235                         pEdit->SetMultiLine(TRUE);\r
1236                         pEdit->SetAutoReturn(TRUE);\r
1237                 }\r
1238                 else\r
1239                 {\r
1240                         pEdit->SetAlignmentV(1);\r
1241                 }\r
1242 \r
1243                 FX_WORD subWord = 0;\r
1244                 if ((dwFieldFlags >> 13) & 1)\r
1245                 {\r
1246                         subWord = '*';\r
1247                         pEdit->SetPasswordChar(subWord);\r
1248                 }\r
1249 \r
1250                 int nMaxLen = pField->GetMaxLen();\r
1251                 FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1;\r
1252                 FX_FLOAT fFontSize = GetFontSize();     \r
1253 \r
1254                 if (nMaxLen > 0)\r
1255                 {\r
1256                         if (bCharArray)\r
1257                         {\r
1258                                 pEdit->SetCharArray(nMaxLen);\r
1259 \r
1260                                 if (IsFloatZero(fFontSize))\r
1261                                 {\r
1262                                         fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(FontMap.GetPDFFont(0),rcClient,nMaxLen);\r
1263                                 }\r
1264                         }\r
1265                         else\r
1266                         {\r
1267                                 if (sValue)\r
1268                                         nMaxLen = wcslen((const wchar_t*)sValue); \r
1269                                 pEdit->SetLimitChar(nMaxLen);\r
1270                         }\r
1271                 }\r
1272 \r
1273                 if (IsFloatZero(fFontSize))\r
1274                         pEdit->SetAutoFontSize(TRUE);\r
1275                 else\r
1276                         pEdit->SetFontSize(fFontSize);\r
1277 \r
1278                 pEdit->Initialize();\r
1279                 \r
1280                 if (sValue)\r
1281                         pEdit->SetText(sValue);\r
1282                 else\r
1283                         pEdit->SetText((FX_LPCWSTR)pField->GetValue());\r
1284 \r
1285                 CPDF_Rect rcContent = pEdit->GetContentRect();\r
1286 \r
1287                 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,0.0f),\r
1288                                                                                                                                         NULL,!bCharArray,subWord);\r
1289 \r
1290                 if (sEdit.GetLength() > 0)\r
1291                 {\r
1292                         sBody << "/Tx BMC\n" << "q\n";\r
1293                         if (rcContent.Width() > rcClient.Width() ||\r
1294                                 rcContent.Height() > rcClient.Height())\r
1295                         {\r
1296                                 sBody << rcClient.left << " " << rcClient.bottom << " " \r
1297                                         << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";\r
1298                         }\r
1299                         CPWL_Color crText = GetTextPWLColor();  \r
1300                         sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" << "Q\nEMC\n";\r
1301                 }\r
1302 \r
1303                 if (bCharArray)\r
1304                 {\r
1305                         switch (GetBorderStyle())\r
1306                         {\r
1307                         case BBS_SOLID:\r
1308                                 {\r
1309                                         CFX_ByteString sColor = CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE);\r
1310                                         if (sColor.GetLength() > 0)\r
1311                                         {\r
1312                                                 sLines << "q\n" << GetBorderWidth() << " w\n" \r
1313                                                         << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE) << " 2 J 0 j\n";                                    \r
1314 \r
1315                                                 for (FX_INT32 i=1;i<nMaxLen;i++)\r
1316                                                 {\r
1317                                                         sLines << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "\r
1318                                                                 << rcClient.bottom << " m\n"\r
1319                                                                 << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "\r
1320                                                                 << rcClient.top << " l S\n";                                            \r
1321                                                 }\r
1322 \r
1323                                                 sLines << "Q\n";                \r
1324                                         }\r
1325                                 }\r
1326                                 break;\r
1327                         case BBS_DASH:\r
1328                                 {\r
1329                                         CFX_ByteString sColor = CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE);\r
1330                                         if (sColor.GetLength() > 0)\r
1331                                         {\r
1332                                                 CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0);\r
1333 \r
1334                                                 sLines << "q\n" << GetBorderWidth() << " w\n" \r
1335                                                         << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE)\r
1336                                                         << "[" << dsBorder.nDash << " " \r
1337                                                         << dsBorder.nGap << "] " \r
1338                                                         << dsBorder.nPhase << " d\n";\r
1339 \r
1340                                                 for (FX_INT32 i=1;i<nMaxLen;i++)                                        \r
1341                                                 {\r
1342                                                         sLines << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "\r
1343                                                                 << rcClient.bottom << " m\n"\r
1344                                                                 << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "\r
1345                                                                 << rcClient.top << " l S\n";    \r
1346                                                 }\r
1347 \r
1348                                                 sLines << "Q\n";\r
1349                                         }\r
1350                                 }\r
1351                                 break;\r
1352                         }\r
1353                 }\r
1354 \r
1355                 IFX_Edit::DelEdit(pEdit);\r
1356         }\r
1357 \r
1358         CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.GetByteString() + sBody.GetByteString();\r
1359         WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);\r
1360 }\r
1361 \r
1362 CPDF_Rect CPDFSDK_Widget::GetClientRect() const\r
1363 {\r
1364         CPDF_Rect rcWindow = GetRotatedRect();\r
1365         FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();\r
1366         switch (GetBorderStyle())\r
1367         {\r
1368         case BBS_BEVELED:\r
1369         case BBS_INSET:\r
1370                 fBorderWidth *= 2.0f;\r
1371                 break;\r
1372         }\r
1373 \r
1374         return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);\r
1375 }\r
1376 \r
1377 CPDF_Rect CPDFSDK_Widget::GetRotatedRect() const\r
1378 {\r
1379         CPDF_Rect rectAnnot = GetRect();\r
1380         FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left;\r
1381         FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom;\r
1382 \r
1383         CPDF_FormControl* pControl = GetFormControl();\r
1384         ASSERT(pControl != NULL);\r
1385 \r
1386         CPDF_Rect rcPDFWindow;\r
1387         switch(abs(pControl->GetRotation() % 360))\r
1388         {\r
1389                 case 0:\r
1390                 case 180:\r
1391                 default:\r
1392                         rcPDFWindow = CPDF_Rect(0, 0, fWidth, fHeight); \r
1393                         break;\r
1394                 case 90:\r
1395                 case 270:\r
1396                         rcPDFWindow = CPDF_Rect(0, 0, fHeight, fWidth);\r
1397                         break;\r
1398         }\r
1399 \r
1400         return rcPDFWindow;\r
1401 }\r
1402 \r
1403 CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const\r
1404 {\r
1405         CPWL_Color crBackground = GetFillPWLColor();\r
1406         if (crBackground.nColorType != COLORTYPE_TRANSPARENT)\r
1407                 return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground);\r
1408         else\r
1409                 return "";\r
1410 }\r
1411 \r
1412 CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const\r
1413 {\r
1414         CPDF_Rect rcWindow = GetRotatedRect();\r
1415         CPWL_Color crBorder = GetBorderPWLColor();\r
1416         CPWL_Color crBackground = GetFillPWLColor();\r
1417         CPWL_Color crLeftTop, crRightBottom;\r
1418 \r
1419         FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();\r
1420         FX_INT32 nBorderStyle = 0;\r
1421         CPWL_Dash dsBorder(3,0,0);\r
1422 \r
1423         switch (GetBorderStyle())\r
1424         {\r
1425         case BBS_DASH:\r
1426                 nBorderStyle = PBS_DASH;\r
1427                 dsBorder = CPWL_Dash(3, 3, 0);\r
1428                 break;\r
1429         case BBS_BEVELED:\r
1430                 nBorderStyle = PBS_BEVELED;\r
1431                 fBorderWidth *= 2;\r
1432                 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);\r
1433                 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);\r
1434                 break;\r
1435         case BBS_INSET:\r
1436                 nBorderStyle = PBS_INSET;\r
1437                 fBorderWidth *= 2;\r
1438                 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);\r
1439                 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);\r
1440                 break;\r
1441         case BBS_UNDERLINE:\r
1442                 nBorderStyle = PBS_UNDERLINED;\r
1443                 break;\r
1444         default: \r
1445                 nBorderStyle = PBS_SOLID;\r
1446                 break;\r
1447         }\r
1448 \r
1449         return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, \r
1450                 crRightBottom, nBorderStyle, dsBorder);\r
1451 }\r
1452 \r
1453 CPDF_Matrix CPDFSDK_Widget::GetMatrix() const\r
1454 {\r
1455         CPDF_Matrix mt;\r
1456         CPDF_FormControl* pControl = GetFormControl();\r
1457         ASSERT(pControl != NULL);\r
1458 \r
1459         CPDF_Rect rcAnnot = GetRect();\r
1460         FX_FLOAT fWidth = rcAnnot.right - rcAnnot.left;\r
1461         FX_FLOAT fHeight = rcAnnot.top - rcAnnot.bottom;\r
1462         \r
1463 \r
1464 \r
1465         switch (abs(pControl->GetRotation() % 360))\r
1466         {\r
1467                 case 0:\r
1468                 default:\r
1469                         mt = CPDF_Matrix(1, 0, 0, 1, 0, 0);\r
1470                         break;\r
1471                 case 90:\r
1472                         mt = CPDF_Matrix(0, 1, -1, 0, fWidth, 0);\r
1473                         break;\r
1474                 case 180:\r
1475                         mt = CPDF_Matrix(-1, 0, 0, -1, fWidth, fHeight);\r
1476                         break;\r
1477                 case 270:\r
1478                         mt = CPDF_Matrix(0, -1, 1, 0, 0, fHeight);\r
1479                         break;\r
1480         }\r
1481 \r
1482         return mt;\r
1483 }\r
1484 \r
1485 CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const\r
1486 {\r
1487         CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0);\r
1488 \r
1489         CPDF_FormControl* pFormCtrl = GetFormControl();\r
1490         ASSERT(pFormCtrl != NULL);\r
1491 \r
1492         CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();\r
1493         if (da.HasColor())\r
1494         {\r
1495                 FX_INT32 iColorType;\r
1496                 FX_FLOAT fc[4];\r
1497                 da.GetColor(iColorType, fc);\r
1498                 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
1499         }\r
1500 \r
1501         return crText;\r
1502 }\r
1503 \r
1504 CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const\r
1505 {\r
1506         CPWL_Color crBorder;\r
1507 \r
1508         CPDF_FormControl* pFormCtrl = GetFormControl();\r
1509         ASSERT(pFormCtrl != NULL);\r
1510 \r
1511         FX_INT32 iColorType;\r
1512         FX_FLOAT fc[4];\r
1513         pFormCtrl->GetOriginalBorderColor(iColorType, fc);\r
1514         if (iColorType > 0)\r
1515                 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
1516 \r
1517         return crBorder;\r
1518 }\r
1519 \r
1520 CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const\r
1521 {\r
1522         CPWL_Color crFill;\r
1523 \r
1524         CPDF_FormControl* pFormCtrl = GetFormControl();\r
1525         ASSERT(pFormCtrl != NULL);\r
1526 \r
1527         FX_INT32 iColorType;\r
1528         FX_FLOAT fc[4];\r
1529         pFormCtrl->GetOriginalBackgroundColor(iColorType, fc);\r
1530         if (iColorType > 0)\r
1531                 crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);\r
1532 \r
1533         return crFill;\r
1534 }\r
1535 \r
1536 void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType, CPDF_Stream* pImage)\r
1537 {\r
1538         ASSERT(pImage != NULL);\r
1539 \r
1540         ASSERT(m_pAnnot != NULL);\r
1541         ASSERT(m_pAnnot->m_pAnnotDict != NULL);\r
1542 \r
1543         CPDF_Document* pDoc = m_pPageView->GetPDFDocument();//pDocument->GetDocument();\r
1544         ASSERT(pDoc != NULL);\r
1545 \r
1546         CPDF_Dictionary* pAPDict = m_pAnnot->m_pAnnotDict->GetDict("AP");\r
1547         ASSERT(pAPDict != NULL);\r
1548 \r
1549         CPDF_Stream* pStream = pAPDict->GetStream(sAPType);\r
1550         ASSERT(pStream != NULL);\r
1551 \r
1552         CPDF_Dictionary* pStreamDict = pStream->GetDict();\r
1553         ASSERT(pStreamDict != NULL);\r
1554 \r
1555         CFX_ByteString sImageAlias = "IMG";\r
1556 \r
1557         if (CPDF_Dictionary* pImageDict = pImage->GetDict())\r
1558         {\r
1559                 sImageAlias = pImageDict->GetString("Name");\r
1560                 if (sImageAlias.IsEmpty())\r
1561                         sImageAlias = "IMG";\r
1562         }       \r
1563 \r
1564         CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources");\r
1565         if (!pStreamResList)\r
1566         {\r
1567                 pStreamResList = FX_NEW CPDF_Dictionary();\r
1568                 pStreamDict->SetAt("Resources", pStreamResList);\r
1569         }\r
1570 \r
1571         if (pStreamResList) \r
1572         {\r
1573                 CPDF_Dictionary* pXObject = FX_NEW CPDF_Dictionary;                     \r
1574                 pXObject->SetAtReference(sImageAlias, pDoc, pImage);\r
1575                 pStreamResList->SetAt("XObject", pXObject);\r
1576         }\r
1577 }\r
1578 \r
1579 void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType)\r
1580 {\r
1581         ASSERT(m_pAnnot != NULL);\r
1582         ASSERT(m_pAnnot->m_pAnnotDict != NULL);\r
1583 \r
1584         if (CPDF_Dictionary* pAPDict = m_pAnnot->m_pAnnotDict->GetDict("AP"))\r
1585         {\r
1586                 pAPDict->RemoveAt(sAPType);\r
1587         }\r
1588 }\r
1589 \r
1590 FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, PDFSDK_FieldAction& data, CPDFSDK_PageView* pPageView)\r
1591 {\r
1592         CPDF_Action action = GetAAction(type);\r
1593 \r
1594         if (action && action.GetType() != CPDF_Action::Unknown)\r
1595         {\r
1596                 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();\r
1597                 ASSERT(pDocument != NULL);\r
1598  \r
1599                 CPDFDoc_Environment* pEnv = pDocument->GetEnv();\r
1600                 ASSERT(pEnv != NULL);\r
1601 \r
1602                 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();/*(CPDFSDK_ActionHandler*)pApp->GetActionHandler();*/\r
1603                 ASSERT(pActionHandler != NULL);\r
1604  \r
1605                 return pActionHandler->DoAction_Field(action, type, pDocument, GetFormField(), data);\r
1606         }\r
1607 \r
1608         return FALSE;\r
1609 }\r
1610 \r
1611 CPDF_Action     CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT)\r
1612 {\r
1613         switch (eAAT)\r
1614         {\r
1615         case CPDF_AAction::CursorEnter:\r
1616         case CPDF_AAction::CursorExit:\r
1617         case CPDF_AAction::ButtonDown:\r
1618         case CPDF_AAction::ButtonUp:\r
1619         case CPDF_AAction::GetFocus:\r
1620         case CPDF_AAction::LoseFocus:\r
1621         case CPDF_AAction::PageOpen:\r
1622         case CPDF_AAction::PageClose:\r
1623         case CPDF_AAction::PageVisible:\r
1624         case CPDF_AAction::PageInvisible:\r
1625                 return CPDFSDK_Annot::GetAAction(eAAT);\r
1626         case CPDF_AAction::KeyStroke:\r
1627         case CPDF_AAction::Format:\r
1628         case CPDF_AAction::Validate:\r
1629         case CPDF_AAction::Calculate:\r
1630                 {\r
1631                         CPDF_FormField* pField = this->GetFormField();\r
1632                         ASSERT(pField != NULL);\r
1633 \r
1634                         if (CPDF_AAction aa = pField->GetAdditionalAction())\r
1635                                 return aa.GetAction(eAAT);\r
1636                         else \r
1637                                 return CPDFSDK_Annot::GetAAction(eAAT);\r
1638                 }\r
1639         default:\r
1640                 return NULL;\r
1641         }\r
1642 \r
1643         return NULL;\r
1644 }\r
1645 \r
1646 \r
1647 CFX_WideString CPDFSDK_Widget::GetAlternateName() const\r
1648 {\r
1649         CPDF_FormField* pFormField = GetFormField();\r
1650         ASSERT(pFormField != NULL);\r
1651 \r
1652         return pFormField->GetAlternateName();\r
1653 }\r
1654 \r
1655 FX_INT32        CPDFSDK_Widget::GetAppearanceAge() const\r
1656 {\r
1657         return m_nAppAge;\r
1658 }\r
1659 \r
1660 FX_INT32 CPDFSDK_Widget::GetValueAge() const\r
1661 {\r
1662         return m_nValueAge;\r
1663 }\r
1664 \r
1665 \r
1666 FX_BOOL CPDFSDK_Widget::HitTest(FX_FLOAT pageX, FX_FLOAT pageY)\r
1667 {\r
1668         CPDF_Annot* pAnnot = GetPDFAnnot();\r
1669         CFX_FloatRect annotRect;\r
1670         pAnnot->GetRect(annotRect);\r
1671         if(annotRect.Contains(pageX, pageY))\r
1672         {\r
1673                 if (!IsVisible()) return FALSE;\r
1674                 \r
1675                 int nFieldFlags = GetFieldFlags();\r
1676                 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) \r
1677                         return FALSE;\r
1678                 \r
1679                 return TRUE;\r
1680         }\r
1681         return FALSE;\r
1682 }\r
1683 \r
1684 CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument)\r
1685         :m_pDocument(pDocument),\r
1686         m_pInterForm(NULL),\r
1687         m_bCalculate(TRUE),\r
1688         m_bBusy(FALSE)\r
1689 {\r
1690         ASSERT(m_pDocument != NULL);\r
1691         m_pInterForm = new CPDF_InterForm(m_pDocument->GetDocument(), FALSE);\r
1692         ASSERT(m_pInterForm != NULL);\r
1693         m_pInterForm->SetFormNotify(this);\r
1694 \r
1695         for(int i=0; i<6; i++)\r
1696                 m_bNeedHightlight[i] = FALSE;\r
1697         m_iHighlightAlpha = 0;\r
1698 }\r
1699 \r
1700 CPDFSDK_InterForm::~CPDFSDK_InterForm()\r
1701 {\r
1702         ASSERT(m_pInterForm != NULL);\r
1703         delete m_pInterForm;\r
1704         m_pInterForm = NULL;\r
1705 \r
1706         m_Map.RemoveAll();\r
1707 }\r
1708 \r
1709 void CPDFSDK_InterForm::Destroy()\r
1710 {\r
1711         delete this;\r
1712 }\r
1713 \r
1714 CPDF_InterForm* CPDFSDK_InterForm::GetInterForm()\r
1715 {\r
1716         return m_pInterForm;\r
1717 }\r
1718 \r
1719 CPDFSDK_Document* CPDFSDK_InterForm::GetDocument()\r
1720 {\r
1721         return m_pDocument;\r
1722 }\r
1723 \r
1724 FX_BOOL CPDFSDK_InterForm::HighlightWidgets()\r
1725 {\r
1726         return FALSE;\r
1727 }\r
1728 \r
1729 CPDFSDK_Widget* CPDFSDK_InterForm::GetSibling(CPDFSDK_Widget* pWidget, FX_BOOL bNext) const\r
1730 {\r
1731         ASSERT(pWidget != NULL);\r
1732 \r
1733         CBA_AnnotIterator* pIterator = new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", "");\r
1734         ASSERT(pIterator != NULL);\r
1735 \r
1736         CPDFSDK_Widget* pRet = NULL;\r
1737 \r
1738         if (bNext)\r
1739                 pRet = (CPDFSDK_Widget*)pIterator->GetNextAnnot(pWidget);\r
1740         else\r
1741                 pRet = (CPDFSDK_Widget*)pIterator->GetPrevAnnot(pWidget);\r
1742 \r
1743         pIterator->Release();\r
1744         \r
1745         return pRet;\r
1746 \r
1747 }\r
1748 \r
1749 CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const\r
1750 {\r
1751         if(!pControl || !m_pInterForm) return NULL;\r
1752         \r
1753         CPDFSDK_Widget* pWidget = NULL;\r
1754         m_Map.Lookup(pControl, pWidget);\r
1755 \r
1756         if (pWidget) return pWidget;\r
1757 \r
1758         CPDF_Dictionary* pControlDict = pControl->GetWidget();\r
1759         ASSERT(pControlDict != NULL);\r
1760 \r
1761         ASSERT(m_pDocument != NULL);\r
1762         CPDF_Document* pDocument = m_pDocument->GetDocument();\r
1763 \r
1764         CPDFSDK_PageView* pPage = NULL;\r
1765 \r
1766         if (CPDF_Dictionary* pPageDict = pControlDict->GetDict("P"))\r
1767         {\r
1768                 int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum());\r
1769                 if (nPageIndex >= 0)\r
1770                 {\r
1771                         pPage = m_pDocument->GetPageView(nPageIndex);\r
1772                 }\r
1773         }\r
1774 \r
1775         if (!pPage) \r
1776         {\r
1777                 int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict);\r
1778                 if (nPageIndex >= 0)\r
1779                 {\r
1780                         pPage = m_pDocument->GetPageView(nPageIndex);\r
1781                 }\r
1782         }\r
1783 \r
1784         if (pPage)\r
1785                 return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict);\r
1786 \r
1787         return NULL;\r
1788 }\r
1789 \r
1790 void CPDFSDK_InterForm::GetWidgets(const CFX_WideString& sFieldName, CFX_PtrArray& widgets)\r
1791 {\r
1792         ASSERT(m_pInterForm != NULL);\r
1793 \r
1794         for (int i=0,sz=m_pInterForm->CountFields(sFieldName); i<sz; i++)\r
1795         {\r
1796                 CPDF_FormField* pFormField = m_pInterForm->GetField(i, sFieldName);\r
1797                 ASSERT(pFormField != NULL);\r
1798 \r
1799                 GetWidgets(pFormField, widgets);        \r
1800         }\r
1801 }\r
1802 \r
1803 void CPDFSDK_InterForm::GetWidgets(CPDF_FormField* pField, CFX_PtrArray& widgets)\r
1804 {\r
1805         ASSERT(pField != NULL);\r
1806 \r
1807         for (int i=0,isz=pField->CountControls(); i<isz; i++)\r
1808         {\r
1809                 CPDF_FormControl* pFormCtrl = pField->GetControl(i);\r
1810                 ASSERT(pFormCtrl != NULL);\r
1811 \r
1812                 CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl);\r
1813 \r
1814                 if (pWidget)\r
1815                         widgets.Add(pWidget);\r
1816         }\r
1817 }\r
1818 \r
1819 int CPDFSDK_InterForm::GetPageIndexByAnnotDict(CPDF_Document* pDocument, CPDF_Dictionary* pAnnotDict) const\r
1820 {\r
1821         ASSERT(pDocument != NULL);\r
1822         ASSERT(pAnnotDict != NULL);\r
1823 \r
1824         for (int i=0,sz=pDocument->GetPageCount(); i<sz; i++)\r
1825         {\r
1826                 if (CPDF_Dictionary* pPageDict = pDocument->GetPage(i))\r
1827                 {                       \r
1828                         if (CPDF_Array* pAnnots = pPageDict->GetArray("Annots"))\r
1829                         {\r
1830                                 for (int j=0,jsz=pAnnots->GetCount(); j<jsz; j++)\r
1831                                 {\r
1832                                         CPDF_Object* pDict = pAnnots->GetElementValue(j);\r
1833                                         if (pAnnotDict == pDict)\r
1834                                         {\r
1835                                                 return i;\r
1836                                         }\r
1837                                 }\r
1838                         }\r
1839                 }\r
1840         }\r
1841 \r
1842         return -1;\r
1843 }\r
1844 \r
1845 void CPDFSDK_InterForm::AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget)\r
1846 {\r
1847         m_Map.SetAt(pControl, pWidget);\r
1848 }\r
1849 \r
1850 void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl)\r
1851 {\r
1852         m_Map.RemoveKey(pControl);\r
1853 }\r
1854 \r
1855 void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled)\r
1856 {\r
1857         m_bCalculate = bEnabled;\r
1858 }\r
1859 \r
1860 FX_BOOL CPDFSDK_InterForm::IsCalculateEnabled() const\r
1861 {\r
1862         return m_bCalculate;\r
1863 }\r
1864 \r
1865 #ifdef _WIN32\r
1866 CPDF_Stream* CPDFSDK_InterForm::LoadImageFromFile(const CFX_WideString& sFile)\r
1867 {\r
1868         ASSERT(m_pDocument != NULL);\r
1869         CPDF_Document* pDocument = m_pDocument->GetDocument();\r
1870         ASSERT(pDocument != NULL);\r
1871 \r
1872         CPDF_Stream* pRetStream = NULL;\r
1873 \r
1874         if (CFX_DIBitmap* pBmp = CFX_WindowsDIB::LoadFromFile(sFile))\r
1875         {\r
1876                 int nWidth = pBmp->GetWidth();\r
1877                 int nHeight = pBmp->GetHeight();\r
1878 \r
1879                 CPDF_Image Image(pDocument);\r
1880                 Image.SetImage(pBmp, FALSE);\r
1881                 CPDF_Stream* pImageStream = Image.GetStream();\r
1882                 if (pImageStream)\r
1883                 {\r
1884                         if (pImageStream->GetObjNum() == 0)\r
1885                                 pDocument->AddIndirectObject(pImageStream);\r
1886 \r
1887                         CPDF_Dictionary* pStreamDict = new CPDF_Dictionary();\r
1888                         pStreamDict->SetAtName("Subtype", "Form");\r
1889                         pStreamDict->SetAtName("Name", "IMG");\r
1890                         CPDF_Array* pMatrix = new CPDF_Array();\r
1891                         pStreamDict->SetAt("Matrix", pMatrix);\r
1892                         pMatrix->AddInteger(1);\r
1893                         pMatrix->AddInteger(0);\r
1894                         pMatrix->AddInteger(0);\r
1895                         pMatrix->AddInteger(1);\r
1896                         pMatrix->AddInteger(-nWidth / 2);\r
1897                         pMatrix->AddInteger(-nHeight / 2);\r
1898                         CPDF_Dictionary* pResource = new CPDF_Dictionary();\r
1899                         pStreamDict->SetAt("Resources", pResource);\r
1900                         CPDF_Dictionary* pXObject = new CPDF_Dictionary();\r
1901                         pResource->SetAt("XObject", pXObject);\r
1902                         pXObject->SetAtReference("Img", pDocument, pImageStream);\r
1903                         CPDF_Array* pProcSet = new CPDF_Array();\r
1904                         pResource->SetAt("ProcSet", pProcSet);\r
1905                         pProcSet->AddName("PDF");\r
1906                         pProcSet->AddName("ImageC");\r
1907                         pStreamDict->SetAtName("Type", "XObject");\r
1908                         CPDF_Array* pBBox = new CPDF_Array();\r
1909                         pStreamDict->SetAt("BBox", pBBox);\r
1910                         pBBox->AddInteger(0);\r
1911                         pBBox->AddInteger(0);\r
1912                         pBBox->AddInteger(nWidth);\r
1913                         pBBox->AddInteger(nHeight);\r
1914                         pStreamDict->SetAtInteger("FormType", 1);\r
1915 \r
1916                         pRetStream = new CPDF_Stream(NULL, 0, NULL);\r
1917                         CFX_ByteString csStream;\r
1918                         csStream.Format("q\n%d 0 0 %d 0 0 cm\n/Img Do\nQ", nWidth, nHeight);\r
1919                         pRetStream->InitStream((FX_BYTE*)(FX_LPCSTR)csStream, csStream.GetLength(), pStreamDict);\r
1920                         pDocument->AddIndirectObject(pRetStream);\r
1921                 }\r
1922 \r
1923                 delete pBmp;\r
1924         }\r
1925 \r
1926         return pRetStream;\r
1927 }\r
1928 #endif\r
1929 \r
1930 void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField)\r
1931 {\r
1932         ASSERT(m_pDocument != NULL);\r
1933         CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
1934         ASSERT(pEnv);\r
1935         if(!pEnv->IsJSInitiated())\r
1936                 return;\r
1937 \r
1938         if (m_bBusy) return;\r
1939 \r
1940         m_bBusy = TRUE;\r
1941 \r
1942         if (this->IsCalculateEnabled())\r
1943         {\r
1944                 IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();\r
1945                 ASSERT(pRuntime != NULL);\r
1946 \r
1947                 pRuntime->SetReaderDocument(m_pDocument);\r
1948 \r
1949                 int nSize = m_pInterForm->CountFieldsInCalculationOrder();\r
1950                 for (int i=0; i<nSize; i++)\r
1951                 {\r
1952                         if(CPDF_FormField* pField = m_pInterForm->GetFieldInCalculationOrder(i))\r
1953                         {\r
1954 //                      ASSERT(pField != NULL);\r
1955                                 int nType = pField->GetFieldType();\r
1956                                 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)\r
1957                                 {\r
1958                                         CPDF_AAction aAction = pField->GetAdditionalAction();\r
1959                                         if (aAction && aAction.ActionExist(CPDF_AAction::Calculate))\r
1960                                         {\r
1961                                                 CPDF_Action action = aAction.GetAction(CPDF_AAction::Calculate);\r
1962                                                 if (action)\r
1963                                                 {\r
1964                                                         CFX_WideString csJS = action.GetJavaScript();\r
1965                                                         if (!csJS.IsEmpty())\r
1966                                                         {\r
1967                                                                 IFXJS_Context* pContext = pRuntime->NewContext();\r
1968                                                                 ASSERT(pContext != NULL);\r
1969                                                                 \r
1970                                                                 CFX_WideString sOldValue = pField->GetValue();\r
1971                                                                 CFX_WideString sValue = sOldValue;\r
1972                                                                 FX_BOOL bRC = TRUE;\r
1973                                                                 pContext->OnField_Calculate(pFormField, pField, sValue, bRC);\r
1974                                                                 \r
1975                                                                 CFX_WideString sInfo;\r
1976                                                                 FX_BOOL bRet = pContext->RunScript(csJS, sInfo);\r
1977                                                                 pRuntime->ReleaseContext(pContext);\r
1978                                                                 \r
1979                                                                 if (bRet)\r
1980                                                                 {\r
1981                                                                         if (bRC)\r
1982                                                                         {\r
1983                                                                                 if (sValue.Compare(sOldValue) != 0)\r
1984                                                                                         pField->SetValue(sValue, TRUE);\r
1985                                                                         }\r
1986                                                                 }\r
1987                                                         }\r
1988                                                 }\r
1989                                         }\r
1990                                 }\r
1991                         }\r
1992                 }\r
1993 \r
1994                 \r
1995         }\r
1996 \r
1997         m_bBusy = FALSE;\r
1998 }\r
1999 \r
2000 CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField, int nCommitKey, FX_BOOL& bFormated)\r
2001 {\r
2002         ASSERT(m_pDocument != NULL);\r
2003         ASSERT(pFormField != NULL);\r
2004 \r
2005         CFX_WideString sValue = pFormField->GetValue();\r
2006         CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
2007         ASSERT(pEnv);\r
2008         if(!pEnv->IsJSInitiated())\r
2009         {\r
2010                 bFormated = FALSE;\r
2011                 return sValue;\r
2012         } \r
2013 \r
2014         IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();\r
2015         ASSERT(pRuntime != NULL);\r
2016         \r
2017         pRuntime->SetReaderDocument(m_pDocument);\r
2018 \r
2019         if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)\r
2020         {\r
2021                 if (pFormField->CountSelectedItems() > 0)\r
2022                 {\r
2023                         int index = pFormField->GetSelectedIndex(0);\r
2024                         if (index >= 0)\r
2025                                 sValue = pFormField->GetOptionLabel(index);\r
2026                 }\r
2027         }\r
2028 \r
2029         bFormated = FALSE;\r
2030 \r
2031         CPDF_AAction aAction = pFormField->GetAdditionalAction();\r
2032         if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Format)) \r
2033         {\r
2034                 CPDF_Action action = aAction.GetAction(CPDF_AAction::Format);\r
2035                 if (action)\r
2036                 {                       \r
2037                         CFX_WideString script = action.GetJavaScript();\r
2038                         if (!script.IsEmpty())\r
2039                         {\r
2040                                 CFX_WideString Value = sValue;\r
2041 \r
2042                                 IFXJS_Context* pContext = pRuntime->NewContext();\r
2043                                 ASSERT(pContext != NULL);\r
2044 \r
2045                                 pContext->OnField_Format(nCommitKey, pFormField, Value, TRUE);\r
2046                         \r
2047                                 CFX_WideString sInfo;\r
2048                                 FX_BOOL bRet = pContext->RunScript(script, sInfo);\r
2049                                 pRuntime->ReleaseContext(pContext);\r
2050 \r
2051                                 if (bRet)\r
2052                                 {\r
2053                                         sValue = Value;\r
2054                                         bFormated = TRUE;\r
2055                                 }\r
2056                         }\r
2057                 }\r
2058         }\r
2059 \r
2060         return sValue;\r
2061 }\r
2062 \r
2063 void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField, FX_LPCWSTR sValue, FX_BOOL bValueChanged)\r
2064 {\r
2065         ASSERT(pFormField != NULL);\r
2066 \r
2067         for (int i=0,sz=pFormField->CountControls(); i<sz; i++)\r
2068         {\r
2069                 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);\r
2070                 ASSERT(pFormCtrl != NULL);\r
2071 \r
2072                 ASSERT(m_pInterForm != NULL);\r
2073                 if(CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))\r
2074                         pWidget->ResetAppearance(sValue, bValueChanged);\r
2075         }\r
2076 }\r
2077 \r
2078 void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField)\r
2079 {\r
2080         ASSERT(pFormField != NULL);\r
2081 \r
2082         for (int i=0,sz=pFormField->CountControls(); i<sz; i++)\r
2083         {\r
2084                 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);\r
2085                 ASSERT(pFormCtrl != NULL);\r
2086 \r
2087                 if(CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))\r
2088                 {\r
2089                         CPDFDoc_Environment * pEnv = m_pDocument->GetEnv();\r
2090                         CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller();\r
2091                         \r
2092                         CPDF_Page * pPage = pWidget->GetPDFPage();\r
2093                         CPDFSDK_PageView * pPageView = m_pDocument->GetPageView(pPage,FALSE);\r
2094 \r
2095                         FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget);\r
2096 \r
2097                         pEnv->FFI_Invalidate(pPage,rcBBox.left, rcBBox.top, rcBBox.right, rcBBox.bottom);\r
2098                 }\r
2099         }\r
2100 }\r
2101 \r
2102 void CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, CFX_WideString& csValue, FX_BOOL& bRC)\r
2103 {\r
2104         ASSERT(pFormField != NULL);\r
2105 \r
2106         CPDF_AAction aAction = pFormField->GetAdditionalAction();\r
2107         if (aAction != NULL && aAction.ActionExist(CPDF_AAction::KeyStroke)) \r
2108         {\r
2109                 CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke);\r
2110                 if (action)\r
2111                 {                        \r
2112                         ASSERT(m_pDocument != NULL);\r
2113                         CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
2114                         ASSERT(pEnv != NULL);\r
2115 \r
2116                         CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();\r
2117                         ASSERT(pActionHandler != NULL);\r
2118         \r
2119                         PDFSDK_FieldAction fa;\r
2120                         fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0);\r
2121                         fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0);\r
2122                         fa.sValue = csValue;\r
2123 \r
2124                         pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke, \r
2125                                 m_pDocument, pFormField, fa);\r
2126                         bRC = fa.bRC;\r
2127                 }\r
2128         }\r
2129 }\r
2130 \r
2131 void CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, CFX_WideString& csValue, FX_BOOL& bRC)\r
2132 {\r
2133         ASSERT(pFormField != NULL);\r
2134 \r
2135         CPDF_AAction aAction = pFormField->GetAdditionalAction();\r
2136         if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Validate)) \r
2137         {\r
2138                 CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate);\r
2139                 if (action)\r
2140                 {               \r
2141                         ASSERT(m_pDocument != NULL);\r
2142                         CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
2143                         ASSERT(pEnv != NULL);\r
2144                         \r
2145                         CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();\r
2146                         ASSERT(pActionHandler != NULL);\r
2147 \r
2148                         PDFSDK_FieldAction fa;\r
2149                         fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0);\r
2150                         fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0);\r
2151                         fa.sValue = csValue;\r
2152 \r
2153                         pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate, m_pDocument, pFormField, fa);\r
2154                         bRC = fa.bRC;\r
2155          \r
2156                 }\r
2157         }\r
2158 }\r
2159 \r
2160 /* ----------------------------- action ----------------------------- */\r
2161 \r
2162 FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action)\r
2163 {\r
2164         ASSERT(action != NULL);\r
2165 \r
2166         CPDF_ActionFields af = action.GetWidgets();\r
2167         CFX_PtrArray fieldObjects;\r
2168         af.GetAllFields(fieldObjects);\r
2169         CFX_PtrArray widgetArray;\r
2170         CFX_PtrArray fields;\r
2171         GetFieldFromObjects(fieldObjects, fields);\r
2172 \r
2173         FX_BOOL bHide = action.GetHideStatus();\r
2174 \r
2175         FX_BOOL bChanged = FALSE;\r
2176         \r
2177         for (int i=0, sz=fields.GetSize(); i<sz; i++)\r
2178         {\r
2179                 CPDF_FormField* pField = (CPDF_FormField*)fields[i];\r
2180                 ASSERT(pField != NULL);\r
2181 \r
2182         \r
2183                 for (int j=0,jsz=pField->CountControls(); j<jsz; j++)\r
2184                 {\r
2185                         CPDF_FormControl* pControl = pField->GetControl(j);\r
2186                         ASSERT(pControl != NULL);\r
2187 \r
2188                         if (CPDFSDK_Widget* pWidget = GetWidget(pControl))\r
2189                         {\r
2190                                 int nFlags = pWidget->GetFlags();\r
2191                                 if (bHide)\r
2192                                 {\r
2193                                         nFlags &= (~ANNOTFLAG_INVISIBLE);\r
2194                                         nFlags &= (~ANNOTFLAG_NOVIEW);\r
2195                                         nFlags |= (ANNOTFLAG_HIDDEN);\r
2196                                 }\r
2197                                 else\r
2198                                 {\r
2199                                         nFlags &= (~ANNOTFLAG_INVISIBLE);\r
2200                                         nFlags &= (~ANNOTFLAG_HIDDEN);\r
2201                                         nFlags &= (~ANNOTFLAG_NOVIEW);\r
2202                                 }\r
2203                                 pWidget->SetFlags(nFlags);\r
2204 \r
2205                                 CPDFSDK_PageView* pPageView = pWidget->GetPageView();\r
2206                                 ASSERT(pPageView != NULL);\r
2207  \r
2208                                 pPageView->UpdateView(pWidget);\r
2209 \r
2210                                 bChanged = TRUE;\r
2211                         }\r
2212                 }\r
2213         }\r
2214 \r
2215         return bChanged;\r
2216 }\r
2217 \r
2218 FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action)\r
2219 {\r
2220         ASSERT(action != NULL);\r
2221         ASSERT(m_pInterForm != NULL);\r
2222 \r
2223         CFX_WideString sDestination = action.GetFilePath();\r
2224         if (sDestination.IsEmpty()) return FALSE;\r
2225 \r
2226         CPDF_Dictionary* pActionDict = action;\r
2227         if (pActionDict->KeyExist("Fields"))\r
2228         {\r
2229                 CPDF_ActionFields af = action.GetWidgets();\r
2230                 FX_DWORD dwFlags = action.GetFlags();\r
2231                 \r
2232                 CFX_PtrArray fieldObjects;\r
2233                 af.GetAllFields(fieldObjects);\r
2234                 CFX_PtrArray fields;\r
2235                 GetFieldFromObjects(fieldObjects, fields);\r
2236                 \r
2237                 if (fields.GetSize() != 0)\r
2238                 {\r
2239                         FX_BOOL bIncludeOrExclude = !(dwFlags & 0x01);\r
2240                         if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude))\r
2241                         {\r
2242                                 return FALSE;\r
2243                         }\r
2244                         return SubmitFields(sDestination, fields, bIncludeOrExclude, FALSE);\r
2245                 }\r
2246                 else\r
2247                 {\r
2248                         if ( m_pInterForm->CheckRequiredFields())\r
2249                         {\r
2250                                 return FALSE;\r
2251                         }\r
2252 \r
2253                         return SubmitForm(sDestination, FALSE);\r
2254                 }\r
2255         }\r
2256         else\r
2257         {\r
2258                 if ( m_pInterForm->CheckRequiredFields())\r
2259                 {\r
2260                         return FALSE;\r
2261                 }\r
2262 \r
2263                 return SubmitForm(sDestination, FALSE);\r
2264         }\r
2265 }\r
2266 \r
2267 FX_BOOL CPDFSDK_InterForm::SubmitFields(const CFX_WideString& csDestination, const CFX_PtrArray& fields,\r
2268                                                                         FX_BOOL bIncludeOrExclude, FX_BOOL bUrlEncoded)\r
2269 {\r
2270         CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
2271         ASSERT(pEnv != NULL);\r
2272 \r
2273         CFX_ByteTextBuf textBuf;\r
2274         ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf);\r
2275 \r
2276         FX_LPBYTE pBuffer = textBuf.GetBuffer();\r
2277         FX_STRSIZE nBufSize = textBuf.GetLength();\r
2278         \r
2279         if (bUrlEncoded)\r
2280         {\r
2281                 if(!FDFToURLEncodedData(pBuffer, nBufSize))\r
2282                         return FALSE;\r
2283         }\r
2284 \r
2285         pEnv->JS_docSubmitForm(pBuffer, nBufSize, (FX_LPCWSTR)csDestination);\r
2286         \r
2287         if (bUrlEncoded && pBuffer)\r
2288         {\r
2289                 FX_Free(pBuffer);\r
2290                 pBuffer = NULL; \r
2291         }\r
2292 \r
2293         return TRUE;\r
2294 }\r
2295 \r
2296 void CPDFSDK_InterForm::DoFDFBuffer(CFX_ByteString sBuffer)\r
2297 {\r
2298         ASSERT(m_pDocument != NULL);\r
2299 \r
2300         if (CFDF_Document *pFDFDocument = CFDF_Document::ParseMemory((const unsigned char *)sBuffer.GetBuffer(sBuffer.GetLength()), sBuffer.GetLength()))\r
2301         {                                               \r
2302                 CPDF_Dictionary* pRootDic = pFDFDocument->GetRoot();\r
2303                 if(pRootDic)\r
2304                 {\r
2305                         CPDF_Dictionary * pFDFDict=pRootDic->GetDict("FDF");\r
2306                         if(pFDFDict)\r
2307                         {               \r
2308                                 CPDF_Dictionary * pJSDict = pFDFDict->GetDict("JavaScript");\r
2309                                 if(pJSDict)\r
2310                                 {\r
2311                                         CFX_WideString csJS;\r
2312                                 \r
2313                                         CPDF_Object* pJS = pJSDict->GetElementValue("Before");\r
2314                                         if (pJS != NULL)\r
2315                                         {\r
2316                                                 int iType = pJS->GetType();\r
2317                                                 if (iType == PDFOBJ_STRING)\r
2318                                                         csJS = pJSDict->GetUnicodeText("Before");\r
2319                                                 else if (iType == PDFOBJ_STREAM)\r
2320                                                         csJS = pJS->GetUnicodeText();\r
2321                                         }\r
2322                                         \r
2323                                 }\r
2324                         }\r
2325                 }\r
2326                 delete pFDFDocument;\r
2327         }\r
2328 \r
2329         sBuffer.ReleaseBuffer();\r
2330 }\r
2331 \r
2332 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, CFX_WideString csTxtFile)\r
2333 {\r
2334         return TRUE;\r
2335 }\r
2336 \r
2337 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(FX_LPBYTE& pBuf, FX_STRSIZE& nBufSize)\r
2338 {\r
2339         CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize);\r
2340         if (pFDF)\r
2341         {\r
2342                 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF");\r
2343                 if (pMainDict == NULL) return FALSE;\r
2344                 \r
2345                 // Get fields\r
2346                 CPDF_Array* pFields = pMainDict->GetArray("Fields");\r
2347                 if (pFields == NULL) return FALSE;\r
2348                 \r
2349                 CFX_ByteTextBuf fdfEncodedData;\r
2350 \r
2351                 for (FX_DWORD i = 0; i < pFields->GetCount(); i ++) \r
2352                 {\r
2353                         CPDF_Dictionary* pField = pFields->GetDict(i);\r
2354                         if (pField == NULL) continue;\r
2355                         CFX_WideString name;\r
2356                         name = pField->GetUnicodeText("T");\r
2357                         CFX_ByteString name_b = CFX_ByteString::FromUnicode(name);\r
2358                         CFX_ByteString csBValue = pField->GetString("V");\r
2359                         CFX_WideString csWValue = PDF_DecodeText(csBValue);\r
2360                         CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue);\r
2361 \r
2362                         fdfEncodedData = fdfEncodedData<<name_b.GetBuffer(name_b.GetLength());\r
2363                         name_b.ReleaseBuffer();\r
2364                         fdfEncodedData = fdfEncodedData<<"=";\r
2365                         fdfEncodedData = fdfEncodedData<<csValue_b.GetBuffer(csValue_b.GetLength());\r
2366                         csValue_b.ReleaseBuffer();\r
2367                         if(i != pFields->GetCount()-1)\r
2368                                 fdfEncodedData = fdfEncodedData<<"&";\r
2369                 }\r
2370                 \r
2371                 nBufSize = fdfEncodedData.GetLength();\r
2372                 pBuf = FX_Alloc(FX_BYTE, nBufSize);\r
2373                 if(!pBuf)\r
2374                         return FALSE;\r
2375                 FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize);\r
2376                 \r
2377         }\r
2378         return TRUE;\r
2379 }\r
2380 \r
2381 FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFFile(const CFX_WideString& sFDFFileName, \r
2382                                                                                                  const CFX_PtrArray& fields, FX_BOOL bIncludeOrExclude)\r
2383 {\r
2384         if (sFDFFileName.IsEmpty()) return FALSE;\r
2385         ASSERT(m_pDocument != NULL);\r
2386         ASSERT(m_pInterForm != NULL);\r
2387 \r
2388         CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath(),(CFX_PtrArray&)fields, bIncludeOrExclude);\r
2389         if (!pFDF) return FALSE;\r
2390         FX_BOOL bRet = pFDF->WriteFile(sFDFFileName.UTF8Encode()); // = FALSE;//\r
2391         delete pFDF;\r
2392 \r
2393         return bRet;\r
2394 }\r
2395 FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(const CFX_PtrArray& fields,FX_BOOL bIncludeOrExclude, CFX_ByteTextBuf& textBuf)\r
2396 {\r
2397         ASSERT(m_pDocument != NULL);\r
2398         ASSERT(m_pInterForm != NULL);\r
2399         \r
2400         CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath(),(CFX_PtrArray&)fields, bIncludeOrExclude);\r
2401         if (!pFDF) return FALSE;\r
2402         FX_BOOL bRet = pFDF->WriteBuf(textBuf); // = FALSE;//\r
2403         delete pFDF;\r
2404         \r
2405         return bRet;\r
2406 }\r
2407 \r
2408 CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName(const CFX_WideString& sFileExt)\r
2409 {\r
2410         CFX_WideString sFileName;\r
2411         return L"";\r
2412 }\r
2413 \r
2414 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, FX_BOOL bUrlEncoded)\r
2415 {\r
2416         if (sDestination.IsEmpty()) return FALSE;\r
2417 \r
2418         CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
2419         ASSERT(pEnv != NULL);\r
2420 \r
2421         if(NULL == m_pDocument) return FALSE;\r
2422         CFX_WideString wsPDFFilePath = m_pDocument->GetPath();\r
2423         \r
2424         if(NULL == m_pInterForm) return FALSE;\r
2425         CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath);\r
2426         if (NULL == pFDFDoc) return FALSE;\r
2427 \r
2428         CFX_ByteTextBuf FdfBuffer;\r
2429         FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer);\r
2430         delete pFDFDoc;\r
2431         if (!bRet) return FALSE;\r
2432 \r
2433         FX_LPBYTE pBuffer = FdfBuffer.GetBuffer();\r
2434         FX_STRSIZE nBufSize = FdfBuffer.GetLength();\r
2435         \r
2436         if (bUrlEncoded)\r
2437         {\r
2438                 if(!FDFToURLEncodedData(pBuffer, nBufSize))\r
2439                         return FALSE;\r
2440         }\r
2441 \r
2442         pEnv->JS_docSubmitForm(pBuffer, nBufSize, (FX_LPCWSTR)sDestination);\r
2443         \r
2444         if (bUrlEncoded && pBuffer)\r
2445         {\r
2446                 FX_Free(pBuffer);\r
2447                 pBuffer = NULL; \r
2448         }\r
2449 \r
2450         return TRUE;\r
2451 }\r
2452 \r
2453 FX_BOOL CPDFSDK_InterForm::ExportFormToFDFFile(const CFX_WideString& sFDFFileName)\r
2454 {\r
2455         if (sFDFFileName.IsEmpty()) return FALSE;\r
2456 \r
2457         ASSERT(m_pInterForm != NULL);\r
2458         ASSERT(m_pDocument != NULL);\r
2459 \r
2460         CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath());\r
2461         if (!pFDF) return FALSE;\r
2462 \r
2463         FX_BOOL bRet = pFDF->WriteFile(sFDFFileName.UTF8Encode());\r
2464         delete pFDF;\r
2465 \r
2466         return bRet;\r
2467 }\r
2468 \r
2469 FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf)\r
2470 {\r
2471 \r
2472         ASSERT(m_pInterForm != NULL);\r
2473         ASSERT(m_pDocument != NULL);\r
2474         \r
2475         CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath());\r
2476         if (!pFDF) return FALSE;\r
2477         \r
2478         FX_BOOL bRet = pFDF->WriteBuf(textBuf);\r
2479         delete pFDF;\r
2480         \r
2481         return bRet;\r
2482 }\r
2483 \r
2484 FX_BOOL CPDFSDK_InterForm::ExportFormToTxtFile(const CFX_WideString& sTxtFileName)\r
2485 {\r
2486         ASSERT(m_pInterForm != NULL);\r
2487 \r
2488         CFX_WideString sFieldNames;\r
2489         CFX_WideString sFieldValues;\r
2490 \r
2491         int nSize = m_pInterForm->CountFields();\r
2492 \r
2493         if (nSize > 0)\r
2494         {\r
2495                 for (int i=0; i<nSize; i++)\r
2496                 {\r
2497                         CPDF_FormField* pField = m_pInterForm->GetField(i);\r
2498                         ASSERT(pField != NULL);\r
2499 \r
2500                         if (i != 0)\r
2501                         {\r
2502                                 sFieldNames += L"\t";\r
2503                                 sFieldValues += L"\t";\r
2504                         }\r
2505                         sFieldNames += pField->GetFullName();\r
2506                         sFieldValues += pField->GetValue();\r
2507                 }\r
2508 \r
2509                 return TRUE;\r
2510         }\r
2511 \r
2512         return FALSE;\r
2513 }\r
2514 \r
2515 FX_BOOL CPDFSDK_InterForm::ImportFormFromTxtFile(const CFX_WideString& sTxtFileName)\r
2516 {\r
2517         ASSERT(m_pInterForm != NULL);\r
2518 \r
2519         return TRUE;\r
2520 }\r
2521 \r
2522 FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action)\r
2523 {\r
2524         ASSERT(action != NULL);\r
2525 \r
2526         CPDF_Dictionary* pActionDict = action;\r
2527 \r
2528         if (pActionDict->KeyExist("Fields"))\r
2529         {\r
2530                 CPDF_ActionFields af = action.GetWidgets();\r
2531                 FX_DWORD dwFlags = action.GetFlags();\r
2532                 \r
2533                 CFX_PtrArray fieldObjects;\r
2534                 af.GetAllFields(fieldObjects);\r
2535                 CFX_PtrArray fields;\r
2536                 GetFieldFromObjects(fieldObjects, fields);\r
2537                 \r
2538                 ASSERT(m_pInterForm != NULL);\r
2539 \r
2540                 return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), TRUE);\r
2541         }\r
2542         else\r
2543         {\r
2544                 ASSERT(m_pInterForm != NULL);\r
2545                 return m_pInterForm->ResetForm(TRUE);\r
2546         }\r
2547 }\r
2548 \r
2549 FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action)\r
2550 {\r
2551         ASSERT(action != NULL);\r
2552 \r
2553         CFX_WideString sFilePath = action.GetFilePath();\r
2554         if (sFilePath.IsEmpty())\r
2555                 return FALSE;\r
2556 \r
2557         if (!ImportFormFromFDFFile(sFilePath, TRUE))\r
2558         {\r
2559                 return FALSE;\r
2560         }\r
2561 \r
2562         return TRUE;\r
2563 }\r
2564 \r
2565 FX_BOOL CPDFSDK_InterForm::ImportFormFromFDFFile(const CFX_WideString& csFDFFileName,\r
2566                                                                                                  FX_BOOL bNotify)\r
2567 {\r
2568         return FALSE;\r
2569 }\r
2570 \r
2571 void CPDFSDK_InterForm::GetFieldFromObjects(const CFX_PtrArray& objects, CFX_PtrArray& fields)\r
2572 {\r
2573         ASSERT(m_pInterForm != NULL);\r
2574 \r
2575         int iCount = objects.GetSize();\r
2576         for (int i = 0; i < iCount; i ++)\r
2577         {\r
2578                 CPDF_Object* pObject = (CPDF_Object*)objects[i];\r
2579                 if (pObject == NULL) continue;\r
2580                 \r
2581                 int iType = pObject->GetType();\r
2582                 if (iType == PDFOBJ_STRING)\r
2583                 {\r
2584                         CFX_WideString csName = pObject->GetUnicodeText();\r
2585                         CPDF_FormField* pField = m_pInterForm->GetField(0, csName);\r
2586                         if (pField != NULL)\r
2587                                 fields.Add(pField);\r
2588                 }\r
2589                 else if (iType == PDFOBJ_DICTIONARY)\r
2590                 {\r
2591                         if (m_pInterForm->IsValidFormField(pObject))\r
2592                                 fields.Add(pObject);\r
2593                 }\r
2594         }\r
2595 }\r
2596 \r
2597 /* ----------------------------- CPDF_FormNotify ----------------------------- */\r
2598 \r
2599 int     CPDFSDK_InterForm::BeforeValueChange(const CPDF_FormField* pField, CFX_WideString& csValue)\r
2600 {\r
2601         ASSERT(pField != NULL);\r
2602 \r
2603         CPDF_FormField* pFormField = (CPDF_FormField*)pField;\r
2604 \r
2605         int nType = pFormField->GetFieldType();\r
2606         if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)\r
2607         {\r
2608                 FX_BOOL bRC = TRUE;\r
2609                 OnKeyStrokeCommit(pFormField, csValue, bRC);\r
2610                 if (bRC) \r
2611                 {\r
2612                         OnValidate(pFormField, csValue, bRC);\r
2613                         if (bRC)\r
2614                                 return 1;\r
2615                         else\r
2616                                 return -1;\r
2617                 }\r
2618                 else\r
2619                         return -1;\r
2620         }\r
2621         else\r
2622                 return 0;\r
2623 }\r
2624 \r
2625 int     CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField)\r
2626 {\r
2627         ASSERT(pField != NULL);\r
2628 \r
2629         CPDF_FormField* pFormField = (CPDF_FormField*)pField;\r
2630         int nType = pFormField->GetFieldType();\r
2631 \r
2632         if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)\r
2633         {\r
2634                 this->OnCalculate(pFormField);\r
2635                 FX_BOOL bFormated = FALSE;\r
2636                 CFX_WideString sValue = this->OnFormat(pFormField, 0, bFormated);\r
2637                 if (bFormated)\r
2638                         this->ResetFieldAppearance(pFormField, sValue, TRUE);\r
2639                 else\r
2640                         this->ResetFieldAppearance(pFormField, NULL, TRUE);\r
2641                 this->UpdateField(pFormField);\r
2642         }\r
2643 \r
2644         return 0;\r
2645 }\r
2646 \r
2647 int     CPDFSDK_InterForm::BeforeSelectionChange(const CPDF_FormField* pField, CFX_WideString& csValue)\r
2648 {\r
2649         ASSERT(pField != NULL);\r
2650 \r
2651         CPDF_FormField* pFormField = (CPDF_FormField*)pField;\r
2652 \r
2653         int nType = pFormField->GetFieldType();\r
2654         if (nType == FIELDTYPE_LISTBOX)\r
2655         {\r
2656                 FX_BOOL bRC = TRUE;\r
2657                 OnKeyStrokeCommit(pFormField, csValue, bRC);\r
2658                 if (bRC) \r
2659                 {\r
2660                         OnValidate(pFormField, csValue, bRC);\r
2661                         if (bRC)\r
2662                                 return 1;\r
2663                         else\r
2664                                 return -1;\r
2665                 }\r
2666                 else\r
2667                         return -1;\r
2668         }\r
2669         else\r
2670                 return 0;\r
2671 }\r
2672 \r
2673 int     CPDFSDK_InterForm::AfterSelectionChange(const CPDF_FormField* pField)\r
2674 {\r
2675         ASSERT(pField != NULL);\r
2676 \r
2677         CPDF_FormField* pFormField = (CPDF_FormField*)pField;\r
2678         int nType = pFormField->GetFieldType();\r
2679 \r
2680         if (nType == FIELDTYPE_LISTBOX)\r
2681         {\r
2682                 this->OnCalculate(pFormField);\r
2683                 this->ResetFieldAppearance(pFormField, NULL, TRUE);\r
2684                 this->UpdateField(pFormField);\r
2685         }\r
2686 \r
2687         return 0;\r
2688 }\r
2689 \r
2690 int     CPDFSDK_InterForm::AfterCheckedStatusChange(const CPDF_FormField* pField, const CFX_ByteArray& statusArray)\r
2691 {\r
2692         ASSERT(pField != NULL);\r
2693 \r
2694         CPDF_FormField* pFormField = (CPDF_FormField*)pField;\r
2695         int nType = pFormField->GetFieldType();\r
2696 \r
2697         if (nType == FIELDTYPE_CHECKBOX || nType == FIELDTYPE_RADIOBUTTON)\r
2698         {\r
2699                 this->OnCalculate(pFormField);\r
2700                 //this->ResetFieldAppearance(pFormField, NULL);\r
2701                 this->UpdateField(pFormField);\r
2702         }\r
2703 \r
2704         return 0;\r
2705 }\r
2706 \r
2707 int     CPDFSDK_InterForm::BeforeFormReset(const CPDF_InterForm* pForm)\r
2708 {\r
2709         return 0;\r
2710 }\r
2711 \r
2712 int     CPDFSDK_InterForm::AfterFormReset(const CPDF_InterForm* pForm)\r
2713 {\r
2714         this->OnCalculate(NULL);\r
2715 \r
2716         return 0;\r
2717 }\r
2718 \r
2719 int     CPDFSDK_InterForm::BeforeFormImportData(const CPDF_InterForm* pForm)\r
2720 {\r
2721         return 0;\r
2722 }\r
2723 \r
2724 int     CPDFSDK_InterForm::AfterFormImportData(const CPDF_InterForm* pForm)\r
2725 {\r
2726         this->OnCalculate(NULL);\r
2727 \r
2728         return 0;\r
2729 }\r
2730 \r
2731 FX_BOOL CPDFSDK_InterForm::IsNeedHighLight(int nFieldType)\r
2732 {\r
2733         if(nFieldType <1 || nFieldType > 6)\r
2734                 return FALSE;\r
2735         return m_bNeedHightlight[nFieldType-1];\r
2736 }\r
2737 \r
2738 void CPDFSDK_InterForm::RemoveAllHighLight()\r
2739 {\r
2740         memset((void*)m_bNeedHightlight, 0, 6*sizeof(FX_BOOL));\r
2741 }\r
2742 void   CPDFSDK_InterForm::SetHighlightColor(FX_COLORREF clr, int nFieldType)\r
2743 {\r
2744         if(nFieldType <0 || nFieldType > 6) return;\r
2745         switch(nFieldType)\r
2746         {\r
2747         case 0:\r
2748                 {\r
2749                         for(int i=0; i<6; i++)\r
2750                         {\r
2751                                 m_aHighlightColor[i] = clr;\r
2752                                 m_bNeedHightlight[i] = TRUE;\r
2753                         }\r
2754                         break;\r
2755                 }\r
2756         default:\r
2757                 {\r
2758                         m_aHighlightColor[nFieldType-1] = clr;\r
2759                         m_bNeedHightlight[nFieldType-1] = TRUE;\r
2760                         break;\r
2761                 }\r
2762         }\r
2763         \r
2764 }\r
2765 \r
2766 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType)\r
2767 {\r
2768         if(nFieldType <0 || nFieldType >6) return FXSYS_RGB(255,255,255);\r
2769         if(nFieldType == 0)\r
2770                 return m_aHighlightColor[0];\r
2771         else\r
2772                 return m_aHighlightColor[nFieldType-1];\r
2773 }\r
2774 \r
2775 /* ------------------------- CBA_AnnotIterator ------------------------- */\r
2776 \r
2777 CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView, const CFX_ByteString& sType, const CFX_ByteString& sSubType)\r
2778         :m_pPageView(pPageView),\r
2779         m_sType(sType),\r
2780         m_sSubType(sSubType),\r
2781         m_nTabs(BAI_STRUCTURE)\r
2782 {\r
2783         ASSERT(m_pPageView != NULL);\r
2784 \r
2785         CPDF_Page* pPDFPage = m_pPageView->GetPDFPage();\r
2786         ASSERT(pPDFPage != NULL);\r
2787         ASSERT(pPDFPage->m_pFormDict != NULL);\r
2788 \r
2789         CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetString("Tabs");\r
2790 \r
2791         if (sTabs == "R")\r
2792         {\r
2793                 m_nTabs = BAI_ROW;\r
2794         }\r
2795         else if (sTabs == "C")\r
2796         {\r
2797                 m_nTabs = BAI_COLUMN;\r
2798         }\r
2799         else\r
2800         {\r
2801                 m_nTabs = BAI_STRUCTURE;\r
2802         }\r
2803 \r
2804         GenerateResults();\r
2805 }\r
2806 \r
2807 CBA_AnnotIterator::~CBA_AnnotIterator()\r
2808 {\r
2809         m_Annots.RemoveAll();\r
2810 }\r
2811 \r
2812 CPDFSDK_Annot* CBA_AnnotIterator::GetFirstAnnot()\r
2813 {\r
2814         if (m_Annots.GetSize() > 0)\r
2815                 return m_Annots[0];\r
2816         \r
2817         return NULL;\r
2818 }\r
2819 \r
2820 CPDFSDK_Annot* CBA_AnnotIterator::GetLastAnnot()\r
2821 {\r
2822         if (m_Annots.GetSize() > 0)\r
2823                 return m_Annots[m_Annots.GetSize() - 1];\r
2824 \r
2825         return NULL;\r
2826 }\r
2827 \r
2828 CPDFSDK_Annot* CBA_AnnotIterator::GetNextAnnot(CPDFSDK_Annot* pAnnot)\r
2829 {\r
2830         for (int i=0,sz=m_Annots.GetSize(); i<sz; i++)\r
2831         {\r
2832                 if (m_Annots[i] == pAnnot)\r
2833                 {\r
2834                         if (i+1 < sz)\r
2835                                 return m_Annots[i+1];\r
2836                         else\r
2837                                 return m_Annots[0];\r
2838                 }\r
2839         }\r
2840 \r
2841         return NULL;\r
2842 }\r
2843 \r
2844 CPDFSDK_Annot* CBA_AnnotIterator::GetPrevAnnot(CPDFSDK_Annot* pAnnot)\r
2845 {\r
2846         for (int i=0,sz=m_Annots.GetSize(); i<sz; i++)\r
2847         {\r
2848                 if (m_Annots[i] == pAnnot)\r
2849                 {\r
2850                         if (i-1 >= 0)\r
2851                                 return m_Annots[i-1];\r
2852                         else\r
2853                                 return m_Annots[sz-1];\r
2854                 }\r
2855         }\r
2856 \r
2857         return NULL;\r
2858 }\r
2859 \r
2860 int CBA_AnnotIterator::CompareByLeft(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)\r
2861 {\r
2862         ASSERT(p1 != NULL);\r
2863         ASSERT(p2 != NULL);\r
2864 \r
2865         CPDF_Rect rcAnnot1 = GetAnnotRect(p1);\r
2866         CPDF_Rect rcAnnot2 = GetAnnotRect(p2);\r
2867 \r
2868         if (rcAnnot1.left < rcAnnot2.left)\r
2869                 return -1;\r
2870         if (rcAnnot1.left > rcAnnot2.left)\r
2871                 return 1;\r
2872         return 0;\r
2873 }\r
2874 \r
2875 \r
2876 int CBA_AnnotIterator::CompareByTop(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)\r
2877 {\r
2878         ASSERT(p1 != NULL);\r
2879         ASSERT(p2 != NULL);\r
2880 \r
2881         CPDF_Rect rcAnnot1 = GetAnnotRect(p1);\r
2882         CPDF_Rect rcAnnot2 = GetAnnotRect(p2);\r
2883 \r
2884         if (rcAnnot1.top < rcAnnot2.top)\r
2885                 return -1;\r
2886         if (rcAnnot1.top > rcAnnot2.top)\r
2887                 return 1;\r
2888         return 0;\r
2889 }\r
2890 \r
2891 void CBA_AnnotIterator::GenerateResults()\r
2892 {\r
2893         ASSERT(m_pPageView != NULL);\r
2894 \r
2895         switch (m_nTabs)\r
2896         {\r
2897         case BAI_STRUCTURE:\r
2898                 {\r
2899                         for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)\r
2900                         {\r
2901                                 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);\r
2902                                 ASSERT(pAnnot != NULL);\r
2903 \r
2904                                 if (pAnnot->GetType() == m_sType \r
2905                                         && pAnnot->GetSubType() == m_sSubType)\r
2906                                         m_Annots.Add(pAnnot);\r
2907                         }\r
2908                 }\r
2909                 break;\r
2910         case BAI_ROW:\r
2911                 {\r
2912                         CPDFSDK_SortAnnots sa;\r
2913 \r
2914                         {\r
2915                                 \r
2916                                 for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)\r
2917                                 {\r
2918                                         CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);\r
2919                                         ASSERT(pAnnot != NULL);\r
2920 \r
2921                                         if (pAnnot->GetType() == m_sType \r
2922                                                 && pAnnot->GetSubType() == m_sSubType)\r
2923                                                 sa.Add(pAnnot);\r
2924                                 }\r
2925                         }\r
2926 \r
2927                         if (sa.GetSize() > 0)\r
2928                         {\r
2929                                 sa.Sort(CBA_AnnotIterator::CompareByLeft);\r
2930                         }\r
2931 \r
2932                         while (sa.GetSize() > 0)\r
2933                         {\r
2934                                 int nLeftTopIndex = -1;\r
2935 \r
2936                                 {\r
2937                                         FX_FLOAT fTop = 0.0f;\r
2938 \r
2939                                         for (int i=sa.GetSize()-1; i>=0; i--)\r
2940                                         {\r
2941                                                 CPDFSDK_Annot* pAnnot = sa.GetAt(i);\r
2942                                                 ASSERT(pAnnot != NULL);\r
2943 \r
2944                                                 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);\r
2945 \r
2946                                                 if (rcAnnot.top > fTop)\r
2947                                                 {\r
2948                                                         nLeftTopIndex = i;\r
2949                                                         fTop = rcAnnot.top;\r
2950                                                 }\r
2951                                         }\r
2952                                 }\r
2953 \r
2954                                 if (nLeftTopIndex >= 0)\r
2955                                 {\r
2956                                         CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex);\r
2957                                         ASSERT(pLeftTopAnnot != NULL);\r
2958 \r
2959                                         CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot);\r
2960                                         \r
2961                                         m_Annots.Add(pLeftTopAnnot);\r
2962                                         sa.RemoveAt(nLeftTopIndex);\r
2963 \r
2964                                         CFX_ArrayTemplate<int> aSelect;\r
2965 \r
2966                                         {\r
2967                                                 for (int i=0,sz=sa.GetSize(); i<sz; i++)\r
2968                                                 {\r
2969                                                         CPDFSDK_Annot* pAnnot = sa.GetAt(i);\r
2970                                                         ASSERT(pAnnot != NULL);\r
2971 \r
2972                                                         CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);\r
2973 \r
2974                                                         FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f;\r
2975 \r
2976                                                         if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top)\r
2977                                                                 aSelect.Add(i);\r
2978                                                 }\r
2979                                         }\r
2980 \r
2981                                         {\r
2982                                                 for (int i=0,sz=aSelect.GetSize(); i<sz; i++)\r
2983                                                 {\r
2984                                                         m_Annots.Add(sa[aSelect[i]]);\r
2985                                                 }\r
2986                                         }\r
2987 \r
2988                                         {\r
2989                                                 for (int i=aSelect.GetSize()-1; i>=0; i--)\r
2990                                                 {\r
2991                                                         sa.RemoveAt(aSelect[i]);\r
2992                                                 }\r
2993                                         }\r
2994 \r
2995                                         aSelect.RemoveAll();\r
2996                                 }\r
2997                         }\r
2998                         sa.RemoveAll();\r
2999                 }\r
3000                 break;\r
3001         case BAI_COLUMN:\r
3002                 {\r
3003                         CPDFSDK_SortAnnots sa;\r
3004 \r
3005                         {\r
3006                                 for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)\r
3007                                 {\r
3008                                         CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);\r
3009                                         ASSERT(pAnnot != NULL);\r
3010 \r
3011                                         if (pAnnot->GetType() == m_sType \r
3012                                                 && pAnnot->GetSubType() == m_sSubType)\r
3013                                                 sa.Add(pAnnot);\r
3014                                 }\r
3015                         }\r
3016 \r
3017                         if (sa.GetSize() > 0)\r
3018                         {\r
3019                                 sa.Sort(CBA_AnnotIterator::CompareByTop, FALSE);\r
3020                         }\r
3021 \r
3022                         while (sa.GetSize() > 0)\r
3023                         {\r
3024                                 int nLeftTopIndex = -1;\r
3025 \r
3026                                 {\r
3027                                         FX_FLOAT fLeft = -1.0f;\r
3028 \r
3029                                         for (int i=sa.GetSize()-1; i>=0; i--)\r
3030                                         {\r
3031                                                 CPDFSDK_Annot* pAnnot = sa.GetAt(i);\r
3032                                                 ASSERT(pAnnot != NULL);\r
3033 \r
3034                                                 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);\r
3035 \r
3036                                                 if (fLeft < 0)\r
3037                                                 {\r
3038                                                         nLeftTopIndex = 0;\r
3039                                                         fLeft = rcAnnot.left;\r
3040                                                 }\r
3041                                                 else if (rcAnnot.left < fLeft)\r
3042                                                 {\r
3043                                                         nLeftTopIndex = i;\r
3044                                                         fLeft = rcAnnot.left;\r
3045                                                 }\r
3046                                         }\r
3047                                 }\r
3048 \r
3049                                 if (nLeftTopIndex >= 0)\r
3050                                 {\r
3051                                         CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex);\r
3052                                         ASSERT(pLeftTopAnnot != NULL);\r
3053 \r
3054                                         CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot);\r
3055                                         \r
3056                                         m_Annots.Add(pLeftTopAnnot);\r
3057                                         sa.RemoveAt(nLeftTopIndex);\r
3058 \r
3059                                         CFX_ArrayTemplate<int> aSelect;\r
3060 \r
3061                                         {\r
3062                                                 for (int i=0,sz=sa.GetSize(); i<sz; i++)\r
3063                                                 {\r
3064                                                         CPDFSDK_Annot* pAnnot = sa.GetAt(i);\r
3065                                                         ASSERT(pAnnot != NULL);\r
3066 \r
3067                                                         CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);\r
3068 \r
3069                                                         FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f;\r
3070 \r
3071                                                         if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right)\r
3072                                                                 aSelect.Add(i);\r
3073                                                 }\r
3074                                         }\r
3075 \r
3076                                         {\r
3077                                                 for (int i=0,sz=aSelect.GetSize(); i<sz; i++)\r
3078                                                 {\r
3079                                                         m_Annots.Add(sa[aSelect[i]]);\r
3080                                                 }\r
3081                                         }\r
3082 \r
3083                                         {\r
3084                                                 for (int i=aSelect.GetSize()-1; i>=0; i--)\r
3085                                                 {\r
3086                                                         sa.RemoveAt(aSelect[i]);\r
3087                                                 }\r
3088                                         }\r
3089 \r
3090                                         aSelect.RemoveAll();\r
3091                                 }\r
3092                         }\r
3093                         sa.RemoveAll();\r
3094                 }\r
3095                 break;\r
3096         }\r
3097 }\r
3098 \r
3099 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot)\r
3100 {\r
3101         ASSERT(pAnnot != NULL);\r
3102 \r
3103         CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();\r
3104         ASSERT(pPDFAnnot != NULL);\r
3105 \r
3106         CPDF_Rect rcAnnot;\r
3107         pPDFAnnot->GetRect(rcAnnot);\r
3108 \r
3109         return rcAnnot;\r
3110 }\r
3111 \r