Revert "Kill operator LPCWSTR from CFX_WideString()."
[pdfium.git] / fpdfsdk / src / javascript / Field.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4  
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "../../include/javascript/JavaScript.h"
8 #include "../../include/javascript/IJavaScript.h"
9 #include "../../include/javascript/JS_Define.h"
10 #include "../../include/javascript/JS_Object.h"
11 #include "../../include/javascript/JS_Value.h"
12 #include "../../include/javascript/Field.h"
13 #include "../../include/javascript/JS_EventHandler.h"
14 //#include "../include/JS_ResMgr.h"
15 #include "../../include/javascript/JS_Context.h"
16 #include "../../include/javascript/JS_Runtime.h"
17 #include "../../include/javascript/Document.h"
18 #include "../../include/javascript/color.h"
19 #include "../../include/javascript/PublicMethods.h"
20 #include "../../include/javascript/Icon.h"
21
22
23 /* ---------------------- Field ---------------------- */
24
25 BEGIN_JS_STATIC_CONST(CJS_Field)
26 END_JS_STATIC_CONST()
27
28 BEGIN_JS_STATIC_PROP(CJS_Field)
29         JS_STATIC_PROP_ENTRY(alignment)
30         JS_STATIC_PROP_ENTRY(borderStyle)
31         JS_STATIC_PROP_ENTRY(buttonAlignX)
32         JS_STATIC_PROP_ENTRY(buttonAlignY)
33         JS_STATIC_PROP_ENTRY(buttonFitBounds)
34         JS_STATIC_PROP_ENTRY(buttonPosition)
35         JS_STATIC_PROP_ENTRY(buttonScaleHow)
36         JS_STATIC_PROP_ENTRY(buttonScaleWhen)
37         JS_STATIC_PROP_ENTRY(calcOrderIndex)
38         JS_STATIC_PROP_ENTRY(charLimit)
39         JS_STATIC_PROP_ENTRY(comb)
40         JS_STATIC_PROP_ENTRY(commitOnSelChange)
41         JS_STATIC_PROP_ENTRY(currentValueIndices)
42         JS_STATIC_PROP_ENTRY(defaultStyle)
43         JS_STATIC_PROP_ENTRY(defaultValue)
44         JS_STATIC_PROP_ENTRY(doNotScroll)
45         JS_STATIC_PROP_ENTRY(doNotSpellCheck)
46         JS_STATIC_PROP_ENTRY(delay)
47         JS_STATIC_PROP_ENTRY(display)
48         JS_STATIC_PROP_ENTRY(doc)
49         JS_STATIC_PROP_ENTRY(editable)
50         JS_STATIC_PROP_ENTRY(exportValues)
51         JS_STATIC_PROP_ENTRY(hidden)
52         JS_STATIC_PROP_ENTRY(fileSelect)
53         JS_STATIC_PROP_ENTRY(fillColor)
54         JS_STATIC_PROP_ENTRY(lineWidth)
55         JS_STATIC_PROP_ENTRY(highlight)
56         JS_STATIC_PROP_ENTRY(multiline)
57         JS_STATIC_PROP_ENTRY(multipleSelection)
58         JS_STATIC_PROP_ENTRY(name)
59         JS_STATIC_PROP_ENTRY(numItems)
60         JS_STATIC_PROP_ENTRY(page)
61         JS_STATIC_PROP_ENTRY(password)
62         JS_STATIC_PROP_ENTRY(print)
63         JS_STATIC_PROP_ENTRY(radiosInUnison)
64         JS_STATIC_PROP_ENTRY(readonly)
65         JS_STATIC_PROP_ENTRY(rect)
66         JS_STATIC_PROP_ENTRY(required)
67         JS_STATIC_PROP_ENTRY(richText)
68         JS_STATIC_PROP_ENTRY(richValue)
69         JS_STATIC_PROP_ENTRY(rotation)
70         JS_STATIC_PROP_ENTRY(strokeColor)
71         JS_STATIC_PROP_ENTRY(style)
72         JS_STATIC_PROP_ENTRY(submitName)
73         JS_STATIC_PROP_ENTRY(textColor)
74         JS_STATIC_PROP_ENTRY(textFont)
75         JS_STATIC_PROP_ENTRY(textSize)
76         JS_STATIC_PROP_ENTRY(type)
77         JS_STATIC_PROP_ENTRY(userName)
78         JS_STATIC_PROP_ENTRY(value)
79         JS_STATIC_PROP_ENTRY(valueAsString)
80         JS_STATIC_PROP_ENTRY(source)
81 END_JS_STATIC_PROP()
82
83 BEGIN_JS_STATIC_METHOD(CJS_Field)
84         JS_STATIC_METHOD_ENTRY(browseForFileToSubmit)
85         JS_STATIC_METHOD_ENTRY(buttonGetCaption)
86         JS_STATIC_METHOD_ENTRY(buttonGetIcon)
87         JS_STATIC_METHOD_ENTRY(buttonImportIcon)
88         JS_STATIC_METHOD_ENTRY(buttonSetCaption)
89         JS_STATIC_METHOD_ENTRY(buttonSetIcon)
90         JS_STATIC_METHOD_ENTRY(checkThisBox)
91         JS_STATIC_METHOD_ENTRY(clearItems)
92         JS_STATIC_METHOD_ENTRY(defaultIsChecked)
93         JS_STATIC_METHOD_ENTRY(deleteItemAt)
94         JS_STATIC_METHOD_ENTRY(getArray )
95         JS_STATIC_METHOD_ENTRY(getItemAt)
96         JS_STATIC_METHOD_ENTRY(getLock)
97         JS_STATIC_METHOD_ENTRY(insertItemAt)
98         JS_STATIC_METHOD_ENTRY(isBoxChecked)
99         JS_STATIC_METHOD_ENTRY(isDefaultChecked)
100         JS_STATIC_METHOD_ENTRY(setAction)
101         JS_STATIC_METHOD_ENTRY(setFocus)
102         JS_STATIC_METHOD_ENTRY(setItems)
103         JS_STATIC_METHOD_ENTRY(setLock)
104         JS_STATIC_METHOD_ENTRY(signatureGetModifications)
105         JS_STATIC_METHOD_ENTRY(signatureGetSeedValue)
106         JS_STATIC_METHOD_ENTRY(signatureInfo)
107         JS_STATIC_METHOD_ENTRY(signatureSetSeedValue)
108         JS_STATIC_METHOD_ENTRY(signatureSign)
109         JS_STATIC_METHOD_ENTRY(signatureValidate)
110 END_JS_STATIC_METHOD()
111
112 IMPLEMENT_JS_CLASS(CJS_Field, Field)
113
114 FX_BOOL CJS_Field::InitInstance(IFXJS_Context* cc)
115 {
116         CJS_Context* pContext = (CJS_Context*)cc;
117         ASSERT(pContext != NULL);
118
119         Field* pField = (Field*)GetEmbedObject();
120         ASSERT(pField != NULL);
121
122         pField->SetIsolate(pContext->GetJSRuntime()->GetIsolate());
123
124         return TRUE;
125 };
126
127 Field::Field(CJS_Object* pJSObject): CJS_EmbedObj(pJSObject),
128         m_pJSDoc(NULL),
129         m_pDocument(NULL),
130         m_nFormControlIndex(-1),
131         m_bCanSet(FALSE),
132         m_bDelay(FALSE),
133         m_isolate(NULL)
134 {
135 }
136
137 Field::~Field()
138 {
139 }
140
141 //note: iControlNo = -1, means not a widget.
142 void Field::ParseFieldName(const std::wstring &strFieldNameParsed,std::wstring &strFieldName,int & iControlNo)
143 {
144         int iStart = strFieldNameParsed.find_last_of(L'.');
145         if (iStart == -1)
146         {
147                 strFieldName = strFieldNameParsed;
148                 iControlNo = -1;
149                 return;
150         }
151         std::wstring suffixal = strFieldNameParsed.substr(iStart+1);
152         iControlNo = FXSYS_wtoi(suffixal.c_str());
153         if (iControlNo == 0)
154         {
155                 int iStart;
156                 while((iStart = suffixal.find_last_of(L" ")) != -1)
157                 {
158                         suffixal.erase(iStart,1);
159                 }
160
161                 if (suffixal.compare(L"0") != 0)
162                 {
163                         strFieldName = strFieldNameParsed;
164                         iControlNo = -1;
165                         return;
166                 }
167
168         }
169         strFieldName = strFieldNameParsed.substr(0,iStart);    
170 }
171
172 FX_BOOL Field::AttachField(Document* pDocument, const CFX_WideString& csFieldName)
173 {
174         ASSERT(pDocument != NULL);
175         m_pJSDoc = pDocument;
176
177         m_pDocument = pDocument->GetReaderDoc();
178         ASSERT(m_pDocument != NULL);
179
180         m_bCanSet = m_pDocument->GetPermissions(FPDFPERM_FILL_FORM) || 
181                 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || 
182                 m_pDocument->GetPermissions(FPDFPERM_MODIFY);
183
184         CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
185         ASSERT(pRDInterForm != NULL);
186
187         CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
188         ASSERT(pInterForm != NULL);
189
190         CFX_WideString swFieldNameTemp = csFieldName;
191         swFieldNameTemp.Replace(L"..", L".");
192
193         if (pInterForm->CountFields(swFieldNameTemp) <= 0)
194         {
195                 std::wstring strFieldName;
196                 int iControlNo = -1;
197                 ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo);
198                 if (iControlNo == -1) return FALSE;
199                 
200                 m_FieldName = strFieldName.c_str();
201                 m_nFormControlIndex = iControlNo;
202                 return TRUE;
203         }
204
205         m_FieldName = swFieldNameTemp;
206         m_nFormControlIndex = -1;
207
208         return TRUE;
209 }
210
211 void Field::GetFormFields(CPDFSDK_Document* pDocument, const CFX_WideString& csFieldName, CFX_PtrArray& FieldArray)
212 {
213         ASSERT(pDocument != NULL);
214
215         CPDFSDK_InterForm* pReaderInterForm = pDocument->GetInterForm();
216         ASSERT(pReaderInterForm != NULL);
217
218         CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
219         ASSERT(pInterForm != NULL);
220
221         ASSERT(FieldArray.GetSize() == 0);
222
223         for (int i=0,sz=pInterForm->CountFields(csFieldName); i<sz; i++)
224         {
225                 if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
226                         FieldArray.Add((void*)pFormField);
227         }
228 }
229
230 void Field::GetFormFields(const CFX_WideString& csFieldName, CFX_PtrArray& FieldArray)
231 {
232         ASSERT(m_pDocument != NULL);
233
234         Field::GetFormFields(m_pDocument, csFieldName, FieldArray);
235 }
236
237 void Field::UpdateFormField(CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, 
238                                                         FX_BOOL bChangeMark, FX_BOOL bResetAP, FX_BOOL bRefresh)
239 {
240         ASSERT(pDocument != NULL);
241         ASSERT(pFormField != NULL);
242
243         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
244         ASSERT(pInterForm != NULL);
245
246         CFX_PtrArray widgets;
247         pInterForm->GetWidgets(pFormField, widgets);
248
249         if (bResetAP)
250         {
251                 int nFieldType = pFormField->GetFieldType();
252                 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD)
253                 {
254                         for (int i=0,sz=widgets.GetSize(); i<sz; i++)
255                         {
256                                 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i);
257                                 ASSERT(pWidget != NULL);
258
259                                 FX_BOOL bFormated = FALSE;
260                                 CFX_WideString sValue = pWidget->OnFormat(0, bFormated);
261                                 if (bFormated)
262                                         pWidget->ResetAppearance(sValue, FALSE);
263                                 else
264                                         pWidget->ResetAppearance(NULL, FALSE);
265                         }
266                 }
267                 else
268                 {
269                         for (int i=0,sz=widgets.GetSize(); i<sz; i++)
270                         {
271                                 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i);
272                                 ASSERT(pWidget != NULL);
273
274                                 pWidget->ResetAppearance(NULL, FALSE);
275                         }
276                 }
277         }
278
279         if (bRefresh)
280         {
281                 for (int i=0,sz=widgets.GetSize(); i<sz; i++)
282                 {
283                         CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i);
284                         ASSERT(pWidget != NULL);
285                         
286                         CPDFSDK_InterForm * pInterForm = pWidget->GetInterForm();
287                         CPDFSDK_Document* pDoc = pInterForm->GetDocument();
288 //                      CReader_Page* pPage = pWidget->GetPage();
289                         ASSERT(pDoc != NULL);
290                         pDoc->UpdateAllViews(NULL, pWidget);
291                 }
292         }               
293         
294         if (bChangeMark)
295                 pDocument->SetChangeMark();
296 }
297
298 void Field::UpdateFormControl(CPDFSDK_Document* pDocument, CPDF_FormControl* pFormControl, 
299                                                         FX_BOOL bChangeMark, FX_BOOL bResetAP, FX_BOOL bRefresh)
300 {
301         ASSERT(pDocument != NULL);
302         ASSERT(pFormControl != NULL);
303
304         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
305         ASSERT(pInterForm != NULL);
306
307         CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
308         
309         if (pWidget)
310         {
311                 if (bResetAP)
312                 {
313                         int nFieldType = pWidget->GetFieldType();
314                         if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD)
315                         {
316                                 FX_BOOL bFormated = FALSE;
317                                 CFX_WideString sValue = pWidget->OnFormat(0, bFormated);
318                                 if (bFormated)
319                                         pWidget->ResetAppearance(sValue, FALSE);
320                                 else
321                                         pWidget->ResetAppearance(NULL, FALSE);
322                         }
323                         else
324                         {
325                                 pWidget->ResetAppearance(NULL, FALSE);
326                         }
327                 }
328
329                 if (bRefresh)
330                 {
331                         CPDFSDK_InterForm * pInterForm = pWidget->GetInterForm();
332                         CPDFSDK_Document* pDoc = pInterForm->GetDocument();
333                         ASSERT(pDoc != NULL);
334                         pDoc->UpdateAllViews(NULL, pWidget);
335                 }
336
337         }
338
339         if (bChangeMark)
340                 pDocument->SetChangeMark();
341 }
342
343 CPDFSDK_Widget* Field::GetWidget(CPDFSDK_Document* pDocument, CPDF_FormControl* pFormControl)
344 {
345         ASSERT(pDocument != NULL);
346         ASSERT(pFormControl != NULL);
347
348         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
349         ASSERT(pInterForm != NULL);
350
351         return pInterForm->GetWidget(pFormControl);
352 }
353
354 FX_BOOL Field::ValueIsOccur(CPDF_FormField* pFormField, CFX_WideString csOptLabel)
355 {
356         ASSERT(pFormField != NULL);
357
358         for (int i=0,sz = pFormField->CountOptions(); i < sz; i++)
359         {
360                 if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
361                         return TRUE;
362         }
363
364         return FALSE;
365 }
366
367 CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField)
368 {
369         ASSERT(pFormField != NULL);
370         if(!pFormField->CountControls() || m_nFormControlIndex>=pFormField->CountControls()) return NULL;
371
372         if (m_nFormControlIndex<0)
373                 return pFormField->GetControl(0);
374         else
375                 return pFormField->GetControl(m_nFormControlIndex);
376 }
377
378 /* ---------------------------------------- property ---------------------------------------- */
379
380 FX_BOOL Field::alignment(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
381 {
382         ASSERT(m_pDocument != NULL);
383
384         if (vp.IsSetting())
385         {
386                 if (!m_bCanSet) return FALSE;
387
388                 CFX_ByteString alignStr;
389                 vp >> alignStr;
390
391                 if (m_bDelay)
392                 {
393                         AddDelay_String(FP_ALIGNMENT, alignStr);
394                 }
395                 else
396                 {
397                         Field::SetAlignment(m_pDocument, m_FieldName, m_nFormControlIndex, alignStr);
398                 }
399         }
400         else
401         {
402                 CFX_PtrArray FieldArray;
403                 GetFormFields(m_FieldName, FieldArray);
404                 if (FieldArray.GetSize() <= 0) return FALSE;
405
406                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
407                 ASSERT(pFormField != NULL);
408
409                 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
410                         return FALSE;
411
412                 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
413                 if (!pFormControl)return FALSE;
414
415                 switch (pFormControl->GetControlAlignment())
416                 {
417                         case 1:
418                                 vp << L"center";
419                                 break;
420                         case 0:
421                                 vp << L"left";
422                                 break;
423                         case 2:
424                                 vp << L"right";
425                                 break;
426                         default:
427                                 vp << L"";
428                 }
429         }
430
431         return TRUE;
432 }
433
434 void Field::SetAlignment(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, 
435                                                  const CFX_ByteString& string)
436 {
437         //Not supported.
438 }
439
440 FX_BOOL Field::borderStyle(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
441 {       
442         ASSERT(m_pDocument != NULL);
443
444         if (vp.IsSetting())
445         {
446                 if (!m_bCanSet) return FALSE;
447
448                 CFX_ByteString strType = "";
449                 vp >> strType;
450
451                 if (m_bDelay)
452                 {
453                         AddDelay_String(FP_BORDERSTYLE, strType);
454                 }
455                 else
456                 {
457                         Field::SetBorderStyle(m_pDocument, m_FieldName, m_nFormControlIndex, strType);
458                 }
459         }
460         else
461         {
462                 CFX_PtrArray FieldArray;
463                 GetFormFields(m_FieldName, FieldArray);
464                 if (FieldArray.GetSize() <= 0) return FALSE;
465
466                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
467                 if (!pFormField) return FALSE;
468
469                 CPDFSDK_Widget* pWidget = GetWidget(m_pDocument, GetSmartFieldControl(pFormField));
470                 if (!pWidget) return FALSE;
471
472                 int nBorderstyle = pWidget->GetBorderStyle();
473
474                 switch (nBorderstyle)
475                 {
476                         case BBS_SOLID:
477                                 vp << L"solid";
478                                 break;
479                         case BBS_DASH:
480                                 vp << L"dashed";
481                                 break;
482                         case BBS_BEVELED:
483                                 vp << L"beveled";
484                                 break;
485                         case BBS_INSET:
486                                 vp << L"inset";
487                                 break;
488                         case BBS_UNDERLINE:
489                                 vp << L"underline";
490                                 break;
491                         default:
492                                 vp << L"";
493                                 break;
494                 }
495         }
496
497         return TRUE;
498 }
499
500 void Field::SetBorderStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, 
501                                                    const CFX_ByteString& string)
502 {
503         ASSERT(pDocument != NULL);
504
505         int nBorderStyle = 0;
506
507         if (string == "solid")
508                 nBorderStyle = BBS_SOLID;
509         else if (string == "beveled")
510                 nBorderStyle = BBS_BEVELED;
511         else if (string == "dashed")
512                 nBorderStyle = BBS_DASH;
513         else if (string == "inset")
514                 nBorderStyle = BBS_INSET;
515         else if (string == "underline")
516                 nBorderStyle = BBS_UNDERLINE;
517         else return;
518
519         CFX_PtrArray FieldArray;
520         GetFormFields(pDocument, swFieldName, FieldArray);
521
522         for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
523         {
524                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
525                 ASSERT(pFormField != NULL);
526
527                 if (nControlIndex < 0)
528                 {
529                         FX_BOOL bSet = FALSE;
530                         for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
531                         {
532                                 if (CPDFSDK_Widget* pWidget = GetWidget(pDocument, pFormField->GetControl(j)))
533                                 {
534                                         if (pWidget->GetBorderStyle() != nBorderStyle)
535                                         {
536                                                 pWidget->SetBorderStyle(nBorderStyle);
537                                                 bSet = TRUE;
538                                         }
539                                 }
540                         }
541                         if (bSet) UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
542                 }
543                 else
544                 {
545                         if(nControlIndex >= pFormField->CountControls()) return;
546                         if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
547                         {
548                                 if (CPDFSDK_Widget* pWidget = GetWidget(pDocument, pFormControl))
549                                 {
550                                         if (pWidget->GetBorderStyle() != nBorderStyle)
551                                         {
552                                                 pWidget->SetBorderStyle(nBorderStyle);
553                                                 UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
554                                         }
555                                 }
556                         }
557                 }
558         }
559 }
560
561 FX_BOOL Field::buttonAlignX(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
562 {
563         ASSERT(m_pDocument != NULL);
564
565         if (vp.IsSetting())
566         {
567                 if (!m_bCanSet) return FALSE;
568
569                 int nVP;
570                 vp >> nVP;
571
572                 if (m_bDelay)
573                 {
574                         AddDelay_Int(FP_BUTTONALIGNX, nVP);
575                 }
576                 else
577                 {
578                         Field::SetButtonAlignX(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
579                 }
580         }
581         else
582         {               
583                 CFX_PtrArray FieldArray;
584                 GetFormFields(m_FieldName,FieldArray);
585                 if (FieldArray.GetSize() <= 0) return FALSE;
586
587                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
588                 ASSERT(pFormField != NULL);
589
590                 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
591                         return FALSE;
592
593                 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
594                 if (!pFormControl)return FALSE;
595
596                 CPDF_IconFit IconFit = pFormControl->GetIconFit();
597
598                 FX_FLOAT fLeft,fBottom;
599                 IconFit.GetIconPosition(fLeft,fBottom);
600
601                 vp << (FX_INT32)fLeft;
602         }
603
604         return TRUE;
605 }
606
607 void Field::SetButtonAlignX(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
608 {
609         //Not supported.
610 }
611
612 FX_BOOL Field::buttonAlignY(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
613 {
614         ASSERT(m_pDocument != NULL);
615
616         if (vp.IsSetting())
617         {
618                 if (!m_bCanSet) return FALSE;
619
620                 int nVP;
621                 vp >> nVP;
622
623                 if (m_bDelay)
624                 {
625                         AddDelay_Int(FP_BUTTONALIGNY, nVP);
626                 }
627                 else
628                 {
629                         Field::SetButtonAlignY(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
630                 }
631         }
632         else
633         {
634                 CFX_PtrArray FieldArray;
635                 GetFormFields(m_FieldName,FieldArray);
636                 if (FieldArray.GetSize() <= 0) return FALSE;
637
638                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
639                 ASSERT(pFormField != NULL);
640
641                 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
642                         return FALSE;
643
644                 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
645                 if (!pFormControl)return FALSE;
646
647                 CPDF_IconFit IconFit = pFormControl->GetIconFit();
648
649                 FX_FLOAT fLeft,fBottom;
650                 IconFit.GetIconPosition(fLeft,fBottom);
651
652                 vp <<  (FX_INT32)fBottom;
653         }
654
655         return TRUE;
656 }
657
658 void Field::SetButtonAlignY(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
659 {
660         //Not supported.
661 }
662
663 FX_BOOL Field::buttonFitBounds(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
664 {
665         ASSERT(m_pDocument != NULL);
666
667         if (vp.IsSetting())
668         {
669                 if (!m_bCanSet) return FALSE;
670
671                 bool bVP;
672                 vp >> bVP;
673
674                 if (m_bDelay)
675                 {
676                         AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP);
677                 }
678                 else
679                 {
680                         Field::SetButtonFitBounds(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
681                 }
682         }
683         else
684         {
685                 CFX_PtrArray FieldArray;
686                 GetFormFields(m_FieldName,FieldArray);
687                 if (FieldArray.GetSize() <= 0) return FALSE;
688
689                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
690                 ASSERT(pFormField != NULL);
691
692                 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
693                         return FALSE;
694
695                 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
696                 if (!pFormControl)return FALSE;
697
698                 CPDF_IconFit IconFit = pFormControl->GetIconFit();
699                 vp << IconFit.GetFittingBounds();               
700         }
701
702         return TRUE;
703 }
704
705 void Field::SetButtonFitBounds(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
706 {
707         //Not supported.
708 }
709
710 FX_BOOL Field::buttonPosition(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
711 {
712         ASSERT(m_pDocument != NULL);
713
714         if (vp.IsSetting())
715         {
716                 if (!m_bCanSet) return FALSE;
717
718                 int nVP;
719                 vp >> nVP;
720
721                 if (m_bDelay)
722                 {
723                         AddDelay_Int(FP_BUTTONPOSITION, nVP);
724                 }
725                 else
726                 {
727                         Field::SetButtonPosition(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
728                 }
729         }
730         else
731         {
732                 CFX_PtrArray FieldArray;
733                 GetFormFields(m_FieldName,FieldArray);
734                 if (FieldArray.GetSize() <= 0) return FALSE;
735
736                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
737                 ASSERT(pFormField != NULL);
738
739                 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
740                         return FALSE;
741
742                 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
743                 if (!pFormControl)return FALSE;
744
745                 vp <<  pFormControl->GetTextPosition();
746         }
747         return TRUE;
748 }
749
750 void Field::SetButtonPosition(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
751 {
752         //Not supported.
753 }
754
755 FX_BOOL Field::buttonScaleHow(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
756 {
757         ASSERT(m_pDocument != NULL);
758
759         if (vp.IsSetting())
760         {
761                 if (!m_bCanSet) return FALSE;
762
763                 int nVP;
764                 vp >> nVP;
765
766                 if (m_bDelay)
767                 {
768                         AddDelay_Int(FP_BUTTONSCALEHOW, nVP);
769                 }
770                 else
771                 {
772                         Field::SetButtonScaleHow(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
773                 }
774         }
775         else
776         {
777                 CFX_PtrArray FieldArray;
778                 GetFormFields(m_FieldName, FieldArray);
779                 if (FieldArray.GetSize() <= 0) return FALSE;
780
781                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
782                 ASSERT(pFormField != NULL);
783
784                 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
785                         return FALSE;
786
787                 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
788                 if (!pFormControl)return FALSE;
789
790                 CPDF_IconFit IconFit = pFormControl->GetIconFit();
791                 if (IconFit.IsProportionalScale())
792                         vp << (FX_INT32)0;
793                 else
794                         vp << (FX_INT32)1;
795         }
796
797         return TRUE;
798 }
799
800 void Field::SetButtonScaleHow(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
801 {
802         //Not supported.
803 }
804
805 FX_BOOL Field::buttonScaleWhen(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
806 {
807         ASSERT(m_pDocument != NULL);
808
809         if (vp.IsSetting())
810         {
811                 if (!m_bCanSet) return FALSE;
812
813                 int nVP;
814                 vp >> nVP;
815
816                 if (m_bDelay)
817                 {
818                         AddDelay_Int(FP_BUTTONSCALEWHEN, nVP);
819                 }
820                 else
821                 {
822                         Field::SetButtonScaleWhen(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
823                 }
824         }
825         else
826         {
827                 CFX_PtrArray FieldArray;
828                 GetFormFields(m_FieldName,FieldArray);
829                 if (FieldArray.GetSize() <= 0) return FALSE;
830
831                 CPDF_FormField* pFormField = (CPDF_FormField*) FieldArray.ElementAt(0);
832                 ASSERT(pFormField != NULL);
833
834                 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
835                         return FALSE;
836
837                 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
838                 if (!pFormControl) return FALSE;
839
840                 CPDF_IconFit IconFit = pFormControl->GetIconFit();
841                 int ScaleM = IconFit.GetScaleMethod();
842                 switch (ScaleM)
843                 {
844                         case CPDF_IconFit::Always :
845                                 vp <<  (FX_INT32) CPDF_IconFit::Always;
846                                 break;
847                         case CPDF_IconFit::Bigger :
848                                 vp <<  (FX_INT32) CPDF_IconFit::Bigger;
849                                 break;
850                         case CPDF_IconFit::Never :
851                                 vp <<  (FX_INT32) CPDF_IconFit::Never;
852                                 break;
853                         case CPDF_IconFit::Smaller :
854                                 vp <<  (FX_INT32) CPDF_IconFit::Smaller;
855                                 break;
856                 }
857         }
858
859         return TRUE;
860 }
861
862 void Field::SetButtonScaleWhen(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
863 {
864         //Not supported.
865 }
866
867 FX_BOOL Field::calcOrderIndex(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
868 {
869         ASSERT(m_pDocument != NULL);
870
871         if (vp.IsSetting())
872         {       
873                 if (!m_bCanSet) return FALSE;
874
875                 int nVP;
876                 vp >> nVP;
877
878                 if (m_bDelay)
879                 {
880                         AddDelay_Int(FP_CALCORDERINDEX, nVP);
881                 }
882                 else
883                 {
884                         Field::SetCalcOrderIndex(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
885                 }
886         }
887         else
888         {
889                 CFX_PtrArray FieldArray;
890                 GetFormFields(m_FieldName, FieldArray);
891                 if (FieldArray.GetSize() <= 0) return FALSE;
892
893                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
894                 ASSERT(pFormField != NULL);
895
896                 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
897                         return FALSE;
898
899                 CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
900                 ASSERT(pRDInterForm != NULL);
901
902                 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
903                 ASSERT(pInterForm != NULL);
904
905                 vp << (FX_INT32)pInterForm->FindFieldInCalculationOrder(pFormField);
906         }
907
908         return TRUE;
909 }
910
911 void Field::SetCalcOrderIndex(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
912 {
913         //Not supported.
914 }
915
916 FX_BOOL Field::charLimit(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
917 {
918         ASSERT(m_pDocument != NULL);
919
920         if (vp.IsSetting())
921         {
922                 if (!m_bCanSet) return FALSE;
923
924                 int nVP;
925                 vp >> nVP;
926
927                 if (m_bDelay)
928                 {
929                         AddDelay_Int(FP_CHARLIMIT, nVP);
930                 }
931                 else
932                 {
933                         Field::SetCharLimit(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
934                 }
935         }
936         else
937         {
938                 CFX_PtrArray FieldArray;
939                 GetFormFields(m_FieldName, FieldArray);
940                 if (FieldArray.GetSize() <= 0) return FALSE;
941
942                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
943                 ASSERT(pFormField != NULL);
944
945                 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
946                         return FALSE;
947
948                 vp << (FX_INT32)pFormField->GetMaxLen();
949         }
950         return TRUE;
951 }
952
953 void Field::SetCharLimit(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
954 {
955         //Not supported.
956 }
957
958 FX_BOOL Field::comb(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
959 {
960         ASSERT(m_pDocument != NULL);
961
962         if (vp.IsSetting())
963         {
964                 if (!m_bCanSet) return FALSE;
965
966                 bool bVP;
967                 vp >> bVP;
968
969                 if (m_bDelay)
970                 {
971                         AddDelay_Bool(FP_COMB, bVP);
972                 }
973                 else
974                 {
975                         Field::SetComb(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
976                 }
977         }
978         else
979         {       
980                 CFX_PtrArray FieldArray;
981                 GetFormFields(m_FieldName,FieldArray);
982                 if (FieldArray.GetSize() <= 0) return FALSE;
983
984                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
985                 ASSERT(pFormField != NULL);
986
987                 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
988                         return FALSE;
989
990                 if (pFormField->GetFieldFlags() & FIELDFLAG_COMB)
991                         vp << true;
992                 else
993                         vp << false;
994         }
995
996         return TRUE;
997 }
998
999 void Field::SetComb(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
1000 {
1001         //Not supported.
1002 }
1003
1004 FX_BOOL Field::commitOnSelChange(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1005 {
1006         ASSERT(m_pDocument != NULL);
1007
1008         if (vp.IsSetting())
1009         {
1010                 if (!m_bCanSet) return FALSE;
1011
1012                 bool bVP;
1013                 vp >> bVP;
1014
1015                 if (m_bDelay)
1016                 {
1017                         AddDelay_Bool(FP_COMMITONSELCHANGE, bVP);
1018                 }
1019                 else
1020                 {
1021                         Field::SetCommitOnSelChange(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1022                 }
1023         }
1024         else
1025         {
1026                 CFX_PtrArray FieldArray;
1027                 GetFormFields(m_FieldName,FieldArray);
1028                 if (FieldArray.GetSize() <= 0) return FALSE;
1029
1030                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
1031                 ASSERT(pFormField != NULL);
1032
1033                 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
1034                         return FALSE;
1035
1036                 if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)
1037                         vp << true;
1038                 else
1039                         vp << false;
1040         }
1041
1042         return TRUE;
1043 }
1044
1045 void Field::SetCommitOnSelChange(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
1046 {
1047         //Not supported.
1048 }
1049
1050 FX_BOOL Field::currentValueIndices(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1051 {
1052         ASSERT(m_pDocument != NULL);
1053
1054         if (vp.IsSetting())
1055         {
1056                 if (!m_bCanSet) return FALSE;
1057
1058                 CFX_DWordArray array;
1059
1060                 if (vp.GetType() == VT_number)
1061                 {
1062                         int iSelecting = 0;
1063                         vp >> iSelecting;
1064                         array.Add(iSelecting);
1065                 }
1066                 else if (vp.IsArrayObject())
1067                 {
1068                         CJS_Array SelArray(m_isolate);
1069                         CJS_Value SelValue(m_isolate);
1070                         int iSelecting;
1071                         vp >> SelArray;
1072                         for (int i=0,sz=SelArray.GetLength(); i<sz; i++)
1073                         {
1074                                 SelArray.GetElement(i,SelValue);
1075                                 iSelecting = SelValue.ToInt();
1076                                 array.Add(iSelecting);
1077                         }
1078                 }
1079                 
1080                 if (m_bDelay)
1081                 {
1082                         AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
1083                 }
1084                 else
1085                 {
1086                         Field::SetCurrentValueIndices(m_pDocument, m_FieldName, m_nFormControlIndex, array);
1087                 }
1088         }
1089         else
1090         {
1091                 CFX_PtrArray FieldArray;
1092                 GetFormFields(m_FieldName,FieldArray);
1093                 if (FieldArray.GetSize() <= 0) return FALSE;
1094
1095                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
1096                 ASSERT(pFormField != NULL);
1097
1098                 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
1099                         return FALSE;
1100
1101                 if (pFormField->CountSelectedItems() == 1)
1102                         vp << pFormField->GetSelectedIndex(0);
1103                 else if (pFormField->CountSelectedItems() > 1)
1104                 {
1105                         CJS_Array SelArray(m_isolate);
1106                         for (int i=0,sz=pFormField->CountSelectedItems(); i<sz; i++)
1107                         {
1108                                 SelArray.SetElement(i, CJS_Value(m_isolate,pFormField->GetSelectedIndex(i)));
1109                         }
1110                         vp << SelArray;
1111                 }
1112                 else
1113                         vp << -1;
1114         }
1115
1116         return TRUE;
1117 }
1118
1119 void Field::SetCurrentValueIndices(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, 
1120                                                                    const CFX_DWordArray& array)
1121 {
1122         ASSERT(pDocument != NULL);
1123
1124         CFX_PtrArray FieldArray;
1125         GetFormFields(pDocument, swFieldName, FieldArray);
1126
1127         for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
1128         {
1129                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
1130                 ASSERT(pFormField != NULL);
1131
1132                 int nFieldType = pFormField->GetFieldType();
1133                 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX)
1134                 {
1135                         FX_DWORD dwFieldFlags = pFormField->GetFieldFlags();
1136                         pFormField->ClearSelection(TRUE);
1137
1138                         for (int i=0,sz=array.GetSize(); i<sz; i++)
1139                         {
1140                                 if (i>0 && !(dwFieldFlags & (1<<21)))
1141                                 {
1142                                         break;
1143                                 }
1144
1145                                 int iSelecting = (FX_INT32)array.GetAt(i);
1146                                 if (iSelecting < pFormField->CountOptions() && !pFormField->IsItemSelected(iSelecting))
1147                                         pFormField->SetItemSelection(iSelecting, TRUE);
1148
1149                         }
1150                         UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
1151                 }
1152         }
1153 }
1154
1155 FX_BOOL Field::defaultStyle(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1156 {
1157         // MQG sError = JSGetStringFromID(IDS_STRING_NOTSUPPORT);
1158         return FALSE;
1159
1160         if (vp.IsSetting())
1161         {
1162                 if (!m_bCanSet) return FALSE;
1163
1164                 ;               
1165         }
1166         else
1167         {
1168                 ;
1169         }
1170         return TRUE;
1171 }
1172
1173 void Field::SetDefaultStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex)
1174 {
1175         //Not supported.
1176 }
1177
1178 FX_BOOL Field::defaultValue(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1179 {
1180         ASSERT(m_pDocument != NULL);
1181
1182         if (vp.IsSetting())
1183         {
1184                 if (!m_bCanSet) return FALSE;
1185
1186                 CFX_WideString WideStr;
1187                 vp >> WideStr; 
1188
1189                 if (m_bDelay)
1190                 {
1191                         AddDelay_WideString(FP_DEFAULTVALUE, WideStr);
1192                 }
1193                 else
1194                 {
1195                         Field::SetDefaultValue(m_pDocument, m_FieldName, m_nFormControlIndex, WideStr);
1196                 }
1197         }
1198         else
1199         {
1200                 CFX_PtrArray FieldArray;
1201                 GetFormFields(m_FieldName,FieldArray);
1202                 if (FieldArray.GetSize() <= 0) return FALSE;
1203
1204                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
1205                 ASSERT(pFormField != NULL);
1206
1207                 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON || 
1208                         pFormField->GetFieldType() == FIELDTYPE_SIGNATURE)
1209                         return FALSE;
1210
1211                 vp << pFormField->GetDefaultValue();
1212         }
1213         return TRUE;
1214 }
1215
1216 void Field::SetDefaultValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
1217                                                         const CFX_WideString& string)
1218 {
1219         //Not supported.
1220 }
1221
1222 FX_BOOL Field::doNotScroll(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1223 {
1224         ASSERT(m_pDocument != NULL);
1225
1226         if (vp.IsSetting())
1227         {
1228                 if (!m_bCanSet) return FALSE;
1229
1230                 bool bVP;
1231                 vp >> bVP;
1232
1233                 if (m_bDelay)
1234                 {
1235                         AddDelay_Bool(FP_DONOTSCROLL, bVP);
1236                 }
1237                 else
1238                 {
1239                         Field::SetDoNotScroll(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1240                 }
1241         }
1242         else
1243         {
1244                 CFX_PtrArray FieldArray;
1245                 GetFormFields(m_FieldName,FieldArray);
1246                 if (FieldArray.GetSize() <= 0) return FALSE;
1247
1248                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
1249                 ASSERT(pFormField != NULL);
1250
1251                 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1252                         return FALSE;
1253
1254                 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
1255                         vp << true;
1256                 else
1257                         vp << false;
1258         }
1259
1260         return TRUE;
1261 }
1262
1263 void Field::SetDoNotScroll(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
1264 {
1265         //Not supported.
1266 }
1267
1268 FX_BOOL Field::doNotSpellCheck(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1269 {
1270         ASSERT(m_pDocument != NULL);
1271
1272         if (vp.IsSetting())
1273         {
1274                 if (!m_bCanSet) return FALSE;
1275
1276                 bool bVP;
1277                 vp >> bVP;
1278         }
1279         else
1280         {
1281                 CFX_PtrArray FieldArray;
1282                 GetFormFields(m_FieldName,FieldArray);
1283                 if (FieldArray.GetSize() <= 0) return FALSE;
1284
1285                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
1286                 ASSERT(pFormField != NULL);
1287
1288                 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD && 
1289                         pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
1290                         return FALSE;
1291
1292                 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
1293                         vp << true;
1294                 else
1295                         vp << false;
1296         }
1297
1298         return TRUE;
1299 }
1300
1301 void Field::SetDelay(FX_BOOL bDelay)
1302 {
1303         m_bDelay = bDelay;
1304
1305         if (!m_bDelay)
1306         {
1307                 if (m_pJSDoc)
1308                         m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
1309         }
1310 }
1311
1312 FX_BOOL Field::delay(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1313 {
1314         if (vp.IsSetting())
1315         {
1316                 if (!m_bCanSet) return FALSE;
1317                 
1318                 bool bVP;
1319                 vp >> bVP;
1320
1321                 SetDelay(bVP);
1322         }
1323         else
1324         {
1325                 vp << m_bDelay;
1326         }
1327         return TRUE;
1328 }
1329
1330 FX_BOOL Field::display(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1331 {
1332         ASSERT(m_pDocument != NULL);
1333
1334         if (vp.IsSetting())
1335         {
1336                 if (!m_bCanSet) return FALSE;
1337
1338                 int nVP;
1339                 vp >> nVP;      
1340
1341                 if (m_bDelay)
1342                 {
1343                         AddDelay_Int(FP_DISPLAY, nVP);
1344                 }
1345                 else
1346                 {
1347                         Field::SetDisplay(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
1348                 }
1349         }
1350         else
1351         {
1352                 CFX_PtrArray FieldArray;
1353                 GetFormFields(m_FieldName,FieldArray);
1354                 if (FieldArray.GetSize() <= 0) return FALSE;
1355
1356                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
1357                 ASSERT(pFormField != NULL);
1358
1359                 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
1360                 ASSERT(pInterForm != NULL);
1361
1362                 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1363                 if (!pWidget)return FALSE;
1364
1365                 FX_DWORD dwFlag = pWidget->GetFlags();
1366
1367                 if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) 
1368                 {
1369                         vp << (FX_INT32)1;
1370                 }
1371                 else 
1372                 {
1373                         if (ANNOTFLAG_PRINT & dwFlag)
1374                         {
1375                                 if (ANNOTFLAG_NOVIEW & dwFlag)
1376                                 {
1377                                         vp << (FX_INT32)3;
1378                                 }
1379                                 else
1380                                 {
1381                                         vp << (FX_INT32)0;
1382                                 }
1383                         }
1384                         else
1385                         {
1386                                 vp << (FX_INT32)2;
1387                         }                               
1388                 }
1389         }
1390
1391         return TRUE;
1392 }
1393
1394 void Field::SetDisplay(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
1395 {
1396         ASSERT(pDocument != NULL);
1397
1398         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
1399         ASSERT(pInterForm != NULL);
1400
1401         CFX_PtrArray FieldArray;
1402         GetFormFields(pDocument, swFieldName, FieldArray);
1403
1404         for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
1405         {
1406                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
1407                 ASSERT(pFormField != NULL);
1408
1409                 if (nControlIndex < 0)
1410                 {
1411                         FX_BOOL bSet = FALSE;
1412                         for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
1413                         {
1414                                 CPDF_FormControl* pFormControl = pFormField->GetControl(j);
1415                                 ASSERT(pFormControl != NULL);
1416
1417                                 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
1418                                 {
1419                                         FX_DWORD dwFlag = pWidget->GetFlags();
1420                                         switch (number)
1421                                         {
1422                                         case 0:
1423                                                 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1424                                                 dwFlag &= (~ANNOTFLAG_HIDDEN);
1425                                                 dwFlag &= (~ANNOTFLAG_NOVIEW);
1426                                                 dwFlag |= ANNOTFLAG_PRINT;                                                      
1427                                                 break;
1428                                         case 1:
1429                                                 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1430                                                 dwFlag &= (~ANNOTFLAG_NOVIEW);
1431                                                 dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1432                                                 break;
1433                                         case 2:
1434                                                 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1435                                                 dwFlag &= (~ANNOTFLAG_PRINT);
1436                                                 dwFlag &= (~ANNOTFLAG_HIDDEN);
1437                                                 dwFlag &= (~ANNOTFLAG_NOVIEW);
1438                                                 break;
1439                                         case 3:
1440                                                 dwFlag |= ANNOTFLAG_NOVIEW;
1441                                                 dwFlag |= ANNOTFLAG_PRINT;
1442                                                 dwFlag &= (~ANNOTFLAG_HIDDEN);
1443                                                 break;
1444                                         }       
1445
1446                                         if (dwFlag != pWidget->GetFlags())
1447                                         {
1448                                                 pWidget->SetFlags(dwFlag);
1449                                                 bSet = TRUE;
1450                                         }
1451                                 }
1452                         }               
1453                         
1454                         if (bSet) UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
1455                 }
1456                 else
1457                 {
1458                         if(nControlIndex >= pFormField->CountControls()) return;
1459                         if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
1460                         {
1461                                 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
1462                                 {
1463
1464                                         FX_DWORD dwFlag = pWidget->GetFlags();
1465                                         switch (number)
1466                                         {
1467                                         case 0:
1468                                                 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1469                                                 dwFlag &= (~ANNOTFLAG_HIDDEN);
1470                                                 dwFlag &= (~ANNOTFLAG_NOVIEW);
1471                                                 dwFlag |= ANNOTFLAG_PRINT;                                                      
1472                                                 break;
1473                                         case 1:
1474                                                 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1475                                                 dwFlag &= (~ANNOTFLAG_NOVIEW);
1476                                                 dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1477                                                 break;
1478                                         case 2:
1479                                                 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1480                                                 dwFlag &= (~ANNOTFLAG_PRINT);
1481                                                 dwFlag &= (~ANNOTFLAG_HIDDEN);
1482                                                 dwFlag &= (~ANNOTFLAG_NOVIEW);
1483                                                 break;
1484                                         case 3:
1485                                                 dwFlag |= ANNOTFLAG_NOVIEW;
1486                                                 dwFlag |= ANNOTFLAG_PRINT;
1487                                                 dwFlag &= (~ANNOTFLAG_HIDDEN);
1488                                                 break;
1489                                         }       
1490                                         if (dwFlag != pWidget->GetFlags())
1491                                         {
1492                                                 pWidget->SetFlags(dwFlag);
1493                                                 UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
1494                                         }
1495                                 }
1496                         }
1497                 }
1498         }
1499 }
1500
1501 FX_BOOL Field::doc(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1502 {
1503         if (!vp.IsGetting()) {
1504                 return FALSE;
1505         }
1506         vp << m_pJSDoc->GetCJSDoc();
1507         return TRUE;
1508 }
1509
1510 FX_BOOL Field::editable(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1511 {
1512         ASSERT(m_pDocument != NULL);
1513         if (vp.IsSetting())
1514         {
1515                 if (!m_bCanSet) return FALSE;
1516
1517                 bool bVP;
1518                 vp >> bVP;
1519         }
1520         else
1521         {
1522                 CFX_PtrArray FieldArray;
1523                 GetFormFields(m_FieldName, FieldArray);
1524                 if (FieldArray.GetSize() <= 0) return FALSE;
1525
1526                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
1527                 ASSERT(pFormField != NULL);
1528
1529                 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
1530                         return FALSE;
1531
1532                 if (pFormField->GetFieldFlags() & FIELDFLAG_EDIT)
1533                         vp << true;
1534                 else
1535                         vp << false;
1536         }
1537
1538         return TRUE;
1539 }
1540
1541 FX_BOOL Field::exportValues(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1542 {
1543         ASSERT(m_pDocument != NULL);
1544
1545         CFX_PtrArray FieldArray;
1546         GetFormFields(m_FieldName,FieldArray);
1547         if (FieldArray.GetSize() <= 0) return FALSE;
1548
1549         CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
1550         ASSERT(pFormField != NULL);
1551
1552         if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX && 
1553                 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
1554                 return FALSE;
1555
1556         if (vp.IsSetting())
1557         {       
1558                 if (!m_bCanSet) return FALSE;
1559                 if (!vp.IsArrayObject())return FALSE;
1560         }
1561         else
1562         {
1563                 CJS_Array ExportValusArray(m_isolate);
1564
1565                 if (m_nFormControlIndex < 0)
1566                 {
1567                         for (int i=0,sz=pFormField->CountControls(); i<sz; i++)
1568                         {
1569                                 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
1570                                 ASSERT(pFormControl != NULL);
1571
1572                                 ExportValusArray.SetElement(i, CJS_Value(m_isolate,pFormControl->GetExportValue().c_str()));
1573                         }
1574                 }
1575                 else
1576                 {
1577                         if(m_nFormControlIndex >= pFormField->CountControls()) return FALSE;
1578                         CPDF_FormControl* pFormControl = pFormField->GetControl(m_nFormControlIndex);
1579                         if (!pFormControl) return FALSE;
1580
1581                         ExportValusArray.SetElement(0, CJS_Value(m_isolate,pFormControl->GetExportValue().c_str()));
1582                 }
1583
1584                 vp << ExportValusArray;
1585         }
1586
1587         return TRUE;
1588 }
1589
1590 FX_BOOL Field::fileSelect(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1591 {
1592         ASSERT(m_pDocument != NULL);
1593
1594         CFX_PtrArray FieldArray;
1595         GetFormFields(m_FieldName, FieldArray);
1596         if (FieldArray.GetSize() <= 0) return FALSE;
1597
1598         CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
1599         ASSERT(pFormField != NULL);
1600
1601         if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1602                 return FALSE;
1603
1604         if (vp.IsSetting())
1605         {
1606                 if (!m_bCanSet) return FALSE;
1607
1608                 bool bVP;
1609                 vp >> bVP;
1610
1611         }
1612         else
1613         {
1614                 if (pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT)
1615                         vp << true;
1616                 else
1617                         vp << false;
1618         }
1619
1620         return TRUE;
1621 }
1622
1623 FX_BOOL Field::fillColor(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1624 {
1625         ASSERT(m_pDocument != NULL);
1626
1627         CJS_Array crArray(m_isolate);
1628
1629         CFX_PtrArray FieldArray;
1630         GetFormFields(m_FieldName,FieldArray);
1631         if (FieldArray.GetSize() <= 0) return FALSE;
1632
1633         if (vp.IsSetting())
1634         {
1635                 if (!m_bCanSet) return FALSE;
1636                 if (!vp.IsArrayObject()) return FALSE;
1637
1638                 vp >> crArray;
1639
1640                 CPWL_Color color;
1641                 color::ConvertArrayToPWLColor(crArray, color);
1642
1643                 if (m_bDelay)
1644                 {
1645                         AddDelay_Color(FP_FILLCOLOR, color);
1646                 }
1647                 else
1648                 {
1649                         Field::SetFillColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
1650                 }
1651         }
1652         else
1653         {
1654                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
1655                 ASSERT(pFormField != NULL);
1656
1657                 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1658                 if (!pFormControl)return FALSE;
1659
1660                 int iColorType;
1661                 pFormControl->GetBackgroundColor(iColorType);
1662
1663                 CPWL_Color color;
1664
1665                 if (iColorType == COLORTYPE_TRANSPARENT)
1666                 {
1667                         color = CPWL_Color(COLORTYPE_TRANSPARENT);
1668                 }
1669                 else if (iColorType == COLORTYPE_GRAY)
1670                 {
1671                         color = CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBackgroundColor(0));
1672                 }
1673                 else if (iColorType == COLORTYPE_RGB)
1674                 {
1675                         color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0),
1676                                 pFormControl->GetOriginalBackgroundColor(1),
1677                                 pFormControl->GetOriginalBackgroundColor(2));
1678                 }
1679                 else if (iColorType == COLORTYPE_CMYK)
1680                 {
1681                         color = CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBackgroundColor(0),
1682                                 pFormControl->GetOriginalBackgroundColor(1),
1683                                 pFormControl->GetOriginalBackgroundColor(2),
1684                                 pFormControl->GetOriginalBackgroundColor(3));
1685                 }
1686                 else
1687                         return FALSE;
1688
1689                 color::ConvertPWLColorToArray(color, crArray);
1690         vp  <<  crArray;
1691         }
1692
1693         return TRUE;
1694 }
1695
1696 void Field::SetFillColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
1697 {
1698         //Not supported.
1699 }
1700
1701 FX_BOOL Field::hidden(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1702 {
1703         ASSERT(m_pDocument != NULL);
1704
1705         if (vp.IsSetting())
1706         {
1707                 if (!m_bCanSet) return FALSE;
1708
1709                 bool bVP;
1710                 vp >> bVP;
1711
1712                 if (m_bDelay)
1713                 {
1714                         AddDelay_Bool(FP_HIDDEN, bVP);
1715                 }
1716                 else
1717                 {
1718                         Field::SetHidden(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1719                 }
1720         }
1721         else
1722         {
1723                 CFX_PtrArray FieldArray;
1724                 GetFormFields(m_FieldName,FieldArray);
1725                 if (FieldArray.GetSize() <= 0) return FALSE;
1726
1727                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
1728                 ASSERT(pFormField != NULL);
1729
1730                 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
1731                 ASSERT(pInterForm != NULL);
1732
1733                 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1734                 if (!pWidget) return FALSE;
1735
1736                 FX_DWORD dwFlags = pWidget->GetFlags();
1737
1738                 if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags) 
1739                 {
1740                         vp << true;
1741                 }
1742                 else 
1743                         vp << false;
1744         }
1745
1746         return TRUE;
1747 }
1748
1749 void Field::SetHidden(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
1750 {
1751         ASSERT(pDocument != NULL);
1752
1753         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
1754         ASSERT(pInterForm != NULL);
1755
1756         CFX_PtrArray FieldArray;
1757         GetFormFields(pDocument, swFieldName, FieldArray);
1758
1759         for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
1760         {
1761                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
1762                 ASSERT(pFormField != NULL);
1763
1764                 if (nControlIndex < 0)
1765                 {
1766                         FX_BOOL bSet = FALSE;
1767                         for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
1768                         {
1769                                 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(j)))
1770                                 {                                       
1771                                         FX_DWORD dwFlags = pWidget->GetFlags();
1772                                         
1773                                         if (b)
1774                                         {
1775                                                 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1776                                                 dwFlags &= (~ANNOTFLAG_NOVIEW);
1777                                                 dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1778                                         }
1779                                         else
1780                                         {
1781                                                 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1782                                                 dwFlags &= (~ANNOTFLAG_HIDDEN);
1783                                                 dwFlags &= (~ANNOTFLAG_NOVIEW);
1784                                                 dwFlags |= ANNOTFLAG_PRINT;     
1785                                         }
1786
1787                                         if (dwFlags != pWidget->GetFlags())
1788                                         {
1789                                                 pWidget->SetFlags(dwFlags);     
1790                                                 bSet = TRUE;
1791                                         }
1792                                 }
1793                         }
1794
1795                         if (bSet)
1796                                 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);      
1797                 }
1798                 else
1799                 {
1800                         if(nControlIndex >= pFormField->CountControls()) return;
1801                         if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
1802                         {
1803                                 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
1804                                 {
1805                                         FX_DWORD dwFlags = pWidget->GetFlags();
1806                                         
1807                                         if (b)
1808                                         {
1809                                                 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1810                                                 dwFlags &= (~ANNOTFLAG_NOVIEW);
1811                                                 dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1812                                         }
1813                                         else
1814                                         {
1815                                                 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1816                                                 dwFlags &= (~ANNOTFLAG_HIDDEN);
1817                                                 dwFlags &= (~ANNOTFLAG_NOVIEW);
1818                                                 dwFlags |= ANNOTFLAG_PRINT;     
1819                                         }
1820
1821                                         if (dwFlags != pWidget->GetFlags())
1822                                         {
1823                                                 pWidget->SetFlags(dwFlags);     
1824                                                 UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);  
1825                                         }
1826                                 }
1827                         }
1828                 }
1829         }
1830 }
1831
1832 FX_BOOL Field::highlight(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1833 {
1834         ASSERT(m_pDocument != NULL);
1835
1836         if (vp.IsSetting())
1837         {
1838                 if (!m_bCanSet) return FALSE;
1839
1840                 CFX_ByteString strMode;
1841                 vp >> strMode;
1842
1843                 if (m_bDelay)
1844                 {
1845                         AddDelay_String(FP_HIGHLIGHT, strMode);
1846                 }
1847                 else
1848                 {
1849                         Field::SetHighlight(m_pDocument, m_FieldName, m_nFormControlIndex, strMode);
1850                 }
1851         }
1852         else
1853         {
1854                 CFX_PtrArray FieldArray;
1855                 GetFormFields(m_FieldName,FieldArray);
1856                 if (FieldArray.GetSize() <= 0) return FALSE;
1857
1858                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
1859                 ASSERT(pFormField != NULL);
1860
1861                 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
1862                         return FALSE;
1863
1864                 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1865                 if (!pFormControl) return FALSE;
1866
1867                 int eHM = pFormControl->GetHighlightingMode();
1868                 switch (eHM)
1869                 {
1870                 case CPDF_FormControl::None:
1871                         vp  <<  L"none";
1872                         break;
1873                 case CPDF_FormControl::Push:
1874                         vp  <<  L"push";
1875                         break;
1876                 case CPDF_FormControl::Invert:
1877                         vp  <<  L"invert";
1878                         break;
1879                 case CPDF_FormControl::Outline:
1880                         vp  <<  L"outline";
1881                         break;
1882                 case CPDF_FormControl::Toggle:
1883                          vp  <<  L"toggle";
1884                          break;
1885                 }
1886         }
1887
1888         return TRUE;
1889 }
1890
1891 void Field::SetHighlight(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string)
1892 {
1893         //Not supported.
1894 }
1895
1896 FX_BOOL Field::lineWidth(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1897 {
1898         ASSERT(m_pDocument != NULL);
1899
1900         if (vp.IsSetting())
1901         {
1902                 if (!m_bCanSet) return FALSE;
1903
1904                 int iWidth;
1905                 vp >> iWidth;
1906
1907                 if (m_bDelay)
1908                 {
1909                         AddDelay_Int(FP_LINEWIDTH, iWidth);
1910                 }
1911                 else
1912                 {
1913                         Field::SetLineWidth(m_pDocument, m_FieldName, m_nFormControlIndex, iWidth);
1914                 }
1915         }
1916         else
1917         {
1918                 CFX_PtrArray FieldArray;
1919                 GetFormFields(m_FieldName,FieldArray);
1920                 if (FieldArray.GetSize() <= 0) return FALSE;
1921
1922                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
1923                 ASSERT(pFormField != NULL);
1924
1925                 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1926                 if (!pFormControl) return FALSE;
1927
1928                 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
1929                 ASSERT(pInterForm != NULL);
1930
1931                 if(!pFormField->CountControls()) return FALSE;
1932
1933                 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
1934                 if (!pWidget) return FALSE;
1935
1936                 vp << (FX_INT32)pWidget->GetBorderWidth();
1937         }
1938
1939         return TRUE;
1940 }
1941
1942 void Field::SetLineWidth(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
1943 {
1944         ASSERT(pDocument != NULL);
1945
1946         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
1947         ASSERT(pInterForm != NULL);
1948
1949         CFX_PtrArray FieldArray;
1950         GetFormFields(pDocument, swFieldName, FieldArray);
1951
1952         for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
1953         {
1954                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
1955                 ASSERT(pFormField != NULL);
1956
1957                 if (nControlIndex < 0)
1958                 {
1959                         FX_BOOL bSet = FALSE;
1960                         for (int j=0,jsz=pFormField->CountControls(); j<jsz; j++)
1961                         {
1962                                 CPDF_FormControl* pFormControl = pFormField->GetControl(j);
1963                                 ASSERT(pFormControl != NULL);
1964                                 
1965                                 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
1966                                 {
1967                                         if (number != pWidget->GetBorderWidth())
1968                                         {
1969                                                 pWidget->SetBorderWidth(number);
1970                                                 bSet = TRUE;
1971                                         }
1972                                 }
1973                         }
1974                         if (bSet) UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
1975                 }
1976                 else
1977                 {
1978                         if(nControlIndex >= pFormField->CountControls()) return;
1979                         if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
1980                         {
1981                                 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
1982                                 {
1983                                         if (number != pWidget->GetBorderWidth())
1984                                         {
1985                                                 pWidget->SetBorderWidth(number);
1986                                                 UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
1987                                         }
1988                                 }
1989                         }
1990                 }
1991         }
1992 }
1993
1994 FX_BOOL Field::multiline(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1995 {
1996         ASSERT(m_pDocument != NULL);
1997
1998         if (vp.IsSetting())
1999         {
2000                 if (!m_bCanSet) return FALSE;
2001
2002                 bool bVP;
2003                 vp >> bVP;
2004
2005                 if (m_bDelay)
2006                 {
2007                         AddDelay_Bool(FP_MULTILINE, bVP);
2008                 }
2009                 else
2010                 {
2011                         Field::SetMultiline(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
2012                 }
2013         }
2014         else
2015         {
2016                 CFX_PtrArray FieldArray;
2017                 GetFormFields(m_FieldName, FieldArray);
2018                 if (FieldArray.GetSize() <= 0) return FALSE;
2019
2020                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
2021                 ASSERT(pFormField != NULL);
2022
2023                 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
2024                         return FALSE;
2025
2026                 if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
2027                         vp << true;
2028                 else
2029                         vp << false;
2030         }
2031
2032         return TRUE;
2033 }
2034
2035 void Field::SetMultiline(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
2036 {
2037         //Not supported.
2038 }
2039
2040 FX_BOOL Field::multipleSelection(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2041 {
2042         ASSERT(m_pDocument != NULL);
2043
2044         if (vp.IsSetting())
2045         {
2046                 if (!m_bCanSet) return FALSE;
2047
2048                 bool bVP;
2049                 vp >> bVP;
2050
2051                 if (m_bDelay)
2052                 {
2053                         AddDelay_Bool(FP_MULTIPLESELECTION, bVP);
2054                 }
2055                 else
2056                 {
2057                         Field::SetMultipleSelection(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
2058                 }
2059         }
2060         else
2061         {
2062                 CFX_PtrArray FieldArray;
2063                 GetFormFields(m_FieldName,FieldArray);
2064                 if (FieldArray.GetSize() <= 0) return FALSE;
2065
2066                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
2067                 ASSERT(pFormField != NULL);
2068
2069                 if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
2070                         return FALSE;
2071
2072                 if (pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)
2073                         vp << true;
2074                 else
2075                         vp << false;
2076         }
2077
2078         return TRUE;
2079 }
2080
2081 void Field::SetMultipleSelection(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
2082 {
2083         //Not supported.
2084 }
2085
2086 FX_BOOL Field::name(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2087 {
2088         if (!vp.IsGetting()) return FALSE;
2089
2090         CFX_PtrArray FieldArray;
2091         GetFormFields(m_FieldName, FieldArray);
2092         if (FieldArray.GetSize() <= 0) return FALSE;
2093
2094         vp << m_FieldName;
2095
2096         return TRUE;
2097 }
2098
2099 FX_BOOL Field::numItems(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2100 {       
2101         CFX_PtrArray FieldArray;
2102         GetFormFields(m_FieldName, FieldArray);
2103         if (FieldArray.GetSize() <= 0) return FALSE;
2104
2105         CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
2106         ASSERT(pFormField != NULL);
2107
2108         if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
2109                 pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
2110                 return FALSE;
2111
2112         if (!vp.IsGetting()) return FALSE;
2113
2114         vp << (FX_INT32)pFormField->CountOptions();
2115
2116         return TRUE;
2117 }
2118
2119 FX_BOOL Field::page(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2120 {
2121         if (!vp.IsGetting()) return FALSE;
2122
2123         CFX_PtrArray FieldArray;
2124         GetFormFields(m_FieldName, FieldArray);
2125         if (FieldArray.GetSize() <= 0) return FALSE;
2126
2127         CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
2128         if (!pFormField) return FALSE;
2129
2130         ASSERT(m_pDocument != NULL);
2131
2132         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
2133         ASSERT(pInterForm != NULL);
2134
2135         CFX_PtrArray widgetArray;
2136         pInterForm->GetWidgets(pFormField, widgetArray);
2137
2138         if (widgetArray.GetSize() > 0)
2139         {
2140                 CJS_Array PageArray(m_isolate);
2141
2142                 for (int i=0,sz=widgetArray.GetSize(); i<sz; i++)
2143                 {
2144                         CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgetArray.GetAt(i);
2145                         ASSERT(pWidget != NULL);
2146
2147                         CPDFSDK_PageView* pPageView = pWidget->GetPageView();
2148                         if(!pPageView)
2149                                 return FALSE;
2150
2151                         PageArray.SetElement(i, CJS_Value(m_isolate,(FX_INT32)pPageView->GetPageIndex()));
2152                 }
2153
2154                 vp << PageArray;
2155         }
2156         else
2157         {
2158                 vp << (FX_INT32) -1;
2159         }
2160
2161         return TRUE;
2162 }
2163
2164 FX_BOOL Field::password(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2165 {
2166         ASSERT(m_pDocument != NULL);
2167
2168         if (vp.IsSetting())
2169         {
2170                 if (!m_bCanSet) return FALSE;
2171
2172                 bool bVP;
2173                 vp >> bVP;
2174
2175                 if (m_bDelay)
2176                 {
2177                         AddDelay_Bool(FP_PASSWORD, bVP);
2178                 }
2179                 else
2180                 {
2181                         Field::SetPassword(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
2182                 }       
2183         }
2184         else
2185         {
2186                 CFX_PtrArray FieldArray;
2187                 GetFormFields(m_FieldName,FieldArray);
2188                 if (FieldArray.GetSize() <= 0) return FALSE;
2189
2190                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
2191                 ASSERT(pFormField != NULL);
2192
2193                 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
2194                         return FALSE;
2195
2196                 if (pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)
2197                         vp << true;
2198                 else
2199                         vp << false;
2200         }
2201
2202         return TRUE;
2203 }
2204
2205 void Field::SetPassword(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
2206 {
2207         //Not supported.
2208 }
2209
2210 FX_BOOL Field::print(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2211 {
2212         ASSERT(m_pDocument != NULL);
2213
2214         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
2215         ASSERT(pInterForm != NULL);
2216
2217         CFX_PtrArray FieldArray;
2218         GetFormFields(m_FieldName, FieldArray);
2219         if (FieldArray.GetSize() <= 0) return FALSE;
2220
2221         if (vp.IsSetting())
2222         {
2223                 if (!m_bCanSet) return FALSE;
2224
2225                 bool bVP;
2226                 vp >> bVP;
2227
2228                 for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
2229                 {
2230                         CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
2231                         ASSERT(pFormField != NULL);
2232
2233                         if (m_nFormControlIndex < 0)
2234                         {
2235                                 FX_BOOL bSet = FALSE;
2236                                 for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
2237                                 {
2238                                         if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(j)))
2239                                         {
2240                                                 FX_DWORD dwFlags = pWidget->GetFlags();
2241                                                 if (bVP)
2242                                                         dwFlags |= ANNOTFLAG_PRINT;
2243                                                 else
2244                                                         dwFlags &= ~ANNOTFLAG_PRINT;
2245
2246                                                 if (dwFlags != pWidget->GetFlags())
2247                                                 {
2248                                                         pWidget->SetFlags(dwFlags);
2249                                                         bSet = TRUE;
2250                                                 }
2251                                         }
2252                                 }
2253
2254                                 if (bSet)
2255                                         UpdateFormField(m_pDocument, pFormField, TRUE, FALSE, TRUE);
2256                         }
2257                         else
2258                         {
2259                                 if(m_nFormControlIndex >= pFormField->CountControls()) return FALSE;
2260                                 if (CPDF_FormControl* pFormControl = pFormField->GetControl(m_nFormControlIndex))
2261                                 {
2262                                         if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
2263                                         {
2264                                                 FX_DWORD dwFlags = pWidget->GetFlags();
2265                                                 if (bVP)
2266                                                         dwFlags |= ANNOTFLAG_PRINT;
2267                                                 else
2268                                                         dwFlags &= ~ANNOTFLAG_PRINT;
2269
2270                                                 if (dwFlags != pWidget->GetFlags())
2271                                                 {
2272                                                         pWidget->SetFlags(dwFlags);
2273                                                         UpdateFormControl(m_pDocument, pFormField->GetControl(m_nFormControlIndex), TRUE, FALSE, TRUE);
2274                                                 }
2275                                         }
2276                                 }
2277                         }
2278                 }
2279         }
2280         else
2281         {
2282                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
2283                 ASSERT(pFormField != NULL);
2284                 
2285                 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
2286                 if (!pWidget) return FALSE;
2287
2288                 if (pWidget->GetFlags() & ANNOTFLAG_PRINT)
2289                         vp << true;
2290                 else
2291                         vp << false;
2292         }
2293
2294         return TRUE;
2295 }
2296
2297 FX_BOOL Field::radiosInUnison(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2298 {
2299         ASSERT(m_pDocument != NULL);
2300
2301         CFX_PtrArray FieldArray;
2302         GetFormFields(m_FieldName,FieldArray);
2303         if (FieldArray.GetSize() <= 0) return FALSE;
2304
2305         if (vp.IsSetting())
2306         {
2307                 if (!m_bCanSet) return FALSE;
2308
2309                 bool bVP;
2310                 vp >> bVP;
2311
2312         }
2313         else
2314         {
2315                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
2316                 ASSERT(pFormField != NULL);
2317
2318                 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
2319                         return FALSE;
2320
2321                 if (pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)
2322                         vp << true;
2323                 else
2324                         vp << false;
2325         }
2326
2327         return TRUE;
2328 }
2329
2330 FX_BOOL Field::readonly(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2331 {
2332         ASSERT(m_pDocument != NULL);
2333
2334         CFX_PtrArray FieldArray;
2335         GetFormFields(m_FieldName,FieldArray);
2336         if (FieldArray.GetSize() <= 0) return FALSE;
2337
2338         if (vp.IsSetting())
2339         {
2340                 if (!m_bCanSet) return FALSE;
2341
2342                 bool bVP;
2343                 vp >> bVP;
2344
2345         }
2346         else
2347         {
2348                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
2349                 ASSERT(pFormField != NULL);
2350
2351                 if (pFormField->GetFieldFlags() & FIELDFLAG_READONLY)
2352                         vp << true;
2353                 else
2354                         vp << false;
2355         }
2356
2357         return TRUE;
2358 }
2359
2360 FX_BOOL Field::rect(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2361 {
2362         ASSERT(m_pDocument != NULL);
2363
2364         if (vp.IsSetting())
2365         {
2366                 if (!m_bCanSet) return FALSE;
2367                 if (!vp.IsArrayObject())return FALSE;
2368
2369                 CJS_Array rcArray(m_isolate);
2370                 vp >> rcArray;
2371                 CJS_Value Upper_Leftx(m_isolate), Upper_Lefty(m_isolate), Lower_Rightx(m_isolate), Lower_Righty(m_isolate);
2372                 rcArray.GetElement(0, Upper_Leftx);
2373                 rcArray.GetElement(1, Upper_Lefty);
2374                 rcArray.GetElement(2, Lower_Rightx);
2375                 rcArray.GetElement(3, Lower_Righty);
2376
2377                 FX_FLOAT pArray[4] = {0.0f,0.0f,0.0f,0.0f};
2378                 pArray[0] = (FX_FLOAT)Upper_Leftx.ToInt();
2379                 pArray[1] = (FX_FLOAT)Lower_Righty.ToInt();
2380                 pArray[2] = (FX_FLOAT)Lower_Rightx.ToInt();
2381                 pArray[3] = (FX_FLOAT)Upper_Lefty.ToInt();
2382
2383                 CPDF_Rect crRect(pArray);
2384
2385                 if (m_bDelay)
2386                 {
2387                         AddDelay_Rect(FP_RECT, crRect);
2388                 }
2389                 else
2390                 {
2391                         Field::SetRect(m_pDocument, m_FieldName, m_nFormControlIndex, crRect);
2392                 }       
2393         }
2394         else
2395         {
2396                 CFX_PtrArray FieldArray;
2397                 GetFormFields(m_FieldName,FieldArray);
2398                 if (FieldArray.GetSize() <= 0) return FALSE;
2399
2400                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
2401                 ASSERT(pFormField != NULL);
2402
2403                 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
2404                 ASSERT(pInterForm != NULL);
2405
2406                 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
2407                 if (!pWidget) return FALSE;
2408
2409                 CFX_FloatRect crRect = pWidget->GetRect();
2410                 CJS_Value Upper_Leftx(m_isolate),Upper_Lefty(m_isolate),Lower_Rightx(m_isolate),Lower_Righty(m_isolate);
2411                 Upper_Leftx = (FX_INT32)crRect.left;
2412                 Upper_Lefty = (FX_INT32)crRect.top;
2413                 Lower_Rightx = (FX_INT32)crRect.right;
2414                 Lower_Righty = (FX_INT32)crRect.bottom;
2415
2416                 CJS_Array rcArray(m_isolate);
2417                 rcArray.SetElement(0,Upper_Leftx);
2418                 rcArray.SetElement(1,Upper_Lefty);
2419                 rcArray.SetElement(2,Lower_Rightx);
2420                 rcArray.SetElement(3,Lower_Righty);
2421
2422                 vp  <<  rcArray;                        
2423         }
2424
2425         return TRUE;
2426 }
2427
2428 void Field::SetRect(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPDF_Rect& rect)
2429 {
2430         ASSERT(pDocument != NULL);
2431
2432         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
2433         ASSERT(pInterForm != NULL);
2434
2435         CFX_PtrArray FieldArray;
2436         GetFormFields(pDocument, swFieldName, FieldArray);
2437
2438         for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
2439         {
2440                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
2441                 ASSERT(pFormField != NULL);
2442
2443                 if (nControlIndex < 0)
2444                 {
2445                         FX_BOOL bSet = FALSE;
2446                         for (int i=0, sz=pFormField->CountControls(); i<sz; i++)
2447                         {
2448                                 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
2449                                 ASSERT(pFormControl != NULL);
2450
2451                                 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
2452                                 {
2453                                         CPDF_Rect crRect = rect;
2454
2455                                         CPDF_Page* pPDFPage = pWidget->GetPDFPage();
2456                                         ASSERT(pPDFPage != NULL);
2457
2458 //                                      CPDF_Page* pPDFPage = pPage->GetPage();
2459 //                                      ASSERT(pPDFPage != NULL);
2460
2461                                         crRect.Intersect(pPDFPage->GetPageBBox());
2462
2463                                         if (!crRect.IsEmpty())
2464                                         {
2465                                                 CPDF_Rect rcOld = pWidget->GetRect();
2466                                                 if (crRect.left != rcOld.left ||
2467                                                         crRect.right != rcOld.right ||
2468                                                         crRect.top != rcOld.top ||
2469                                                         crRect.bottom != rcOld.bottom)
2470                                                 {
2471                                                         pWidget->SetRect(crRect);
2472                                                         bSet = TRUE;
2473                                                 }
2474                                         }
2475                                 }
2476                         }
2477
2478                         if (bSet) UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
2479                 }
2480                 else
2481                 {
2482                         if(nControlIndex >= pFormField->CountControls()) return;
2483                         if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
2484                         {
2485                                 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
2486                                 {
2487                                         CPDF_Rect crRect = rect;
2488                                         
2489                                         CPDF_Page* pPDFPage = pWidget->GetPDFPage();
2490                                         ASSERT(pPDFPage != NULL);
2491
2492 //                                      CPDF_Page* pPDFPage = pPage->GetPage();
2493 //                                      ASSERT(pPDFPage != NULL);
2494
2495                                         crRect.Intersect(pPDFPage->GetPageBBox());
2496
2497                                         if (!crRect.IsEmpty())
2498                                         {
2499                                                 CPDF_Rect rcOld = pWidget->GetRect();
2500                                                 if (crRect.left != rcOld.left ||
2501                                                         crRect.right != rcOld.right ||
2502                                                         crRect.top != rcOld.top ||
2503                                                         crRect.bottom != rcOld.bottom)
2504                                                 {
2505                                                         pWidget->SetRect(crRect);
2506                                                         UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
2507                                                 }
2508                                         }
2509                                 }
2510                         }
2511                 }
2512         }
2513 }
2514
2515 FX_BOOL Field::required(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2516 {
2517         ASSERT(m_pDocument != NULL);
2518
2519         CFX_PtrArray FieldArray;
2520         GetFormFields(m_FieldName,FieldArray);
2521         if (FieldArray.GetSize() <= 0) return FALSE;
2522
2523         if (vp.IsSetting())
2524         {
2525                 if (!m_bCanSet) return FALSE;
2526
2527
2528                 bool bVP;
2529                 vp >> bVP;
2530
2531         }
2532         else
2533         {
2534                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
2535                 ASSERT(pFormField != NULL);
2536
2537                 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
2538                         return FALSE;
2539
2540                 if (pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)
2541                         vp << true;
2542                 else
2543                         vp << false;
2544         }
2545
2546         return TRUE;
2547 }
2548
2549 FX_BOOL Field::richText(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2550 {
2551         ASSERT(m_pDocument != NULL);
2552
2553         if (vp.IsSetting())
2554         {
2555                 if (!m_bCanSet) return FALSE;
2556
2557                 bool bVP;
2558                 vp >> bVP;
2559
2560                 if (m_bDelay)
2561                 {
2562                         AddDelay_Bool(FP_RICHTEXT, bVP);
2563                 }
2564                 else
2565                 {
2566                         Field::SetRichText(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
2567                 }       
2568         }
2569         else
2570         {
2571                 CFX_PtrArray FieldArray;
2572                 GetFormFields(m_FieldName,FieldArray);
2573                 if (FieldArray.GetSize() <= 0) return FALSE;
2574
2575                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
2576                 ASSERT(pFormField != NULL);
2577
2578                 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
2579                         return FALSE;
2580
2581                 if (pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)
2582                         vp << true;
2583                 else
2584                         vp << false;
2585         }
2586
2587         return TRUE;
2588 }
2589
2590 void Field::SetRichText(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
2591 {
2592         //Not supported.
2593 }
2594
2595 FX_BOOL Field::richValue(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2596 {
2597         return TRUE;
2598         if (vp.IsSetting())
2599         {
2600                 if (!m_bCanSet) return FALSE;
2601                 ;
2602         }
2603         else
2604         {
2605                 ;
2606         }
2607         return TRUE;
2608 }
2609
2610 void Field::SetRichValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex)
2611 {
2612         //Not supported.
2613 }
2614
2615 FX_BOOL Field::rotation(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2616 {
2617         ASSERT(m_pDocument != NULL);
2618
2619         if (vp.IsSetting())
2620         {
2621                 if (!m_bCanSet) return FALSE;
2622
2623                 int nVP;
2624                 vp >> nVP;
2625
2626                 if (m_bDelay)
2627                 {
2628                         AddDelay_Int(FP_ROTATION, nVP);
2629                 }
2630                 else
2631                 {
2632                         Field::SetRotation(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
2633                 }       
2634         }
2635         else
2636         {
2637                 CFX_PtrArray FieldArray;
2638                 GetFormFields(m_FieldName,FieldArray);
2639                 if (FieldArray.GetSize() <= 0) return FALSE;
2640
2641                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
2642                 ASSERT(pFormField != NULL);
2643
2644                 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2645                 if (!pFormControl)return FALSE;
2646
2647                 vp << (FX_INT32)pFormControl->GetRotation();
2648         }
2649
2650         return TRUE;
2651 }
2652
2653 void Field::SetRotation(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
2654 {
2655         //Not supported.
2656 }
2657
2658 FX_BOOL Field::strokeColor(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2659 {
2660         ASSERT(m_pDocument != NULL);
2661
2662         if (vp.IsSetting())
2663         {
2664                 if (!m_bCanSet) return FALSE;
2665
2666                 if (!vp.IsArrayObject())return FALSE;
2667
2668                 CJS_Array crArray(m_isolate);
2669                 vp >> crArray;
2670
2671                 CPWL_Color color;
2672                 color::ConvertArrayToPWLColor(crArray, color);
2673
2674                 if (m_bDelay)
2675                 {
2676                         AddDelay_Color(FP_STROKECOLOR, color);
2677                 }
2678                 else
2679                 {
2680                         Field::SetStrokeColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
2681                 }       
2682         }
2683         else
2684         {
2685                 CFX_PtrArray FieldArray;
2686                 GetFormFields(m_FieldName,FieldArray);
2687                 if (FieldArray.GetSize() <= 0) return FALSE;
2688
2689                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
2690                 ASSERT(pFormField != NULL);
2691
2692                 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2693                 if (!pFormControl)return FALSE;
2694
2695                 int iColorType;
2696                 pFormControl->GetBorderColor(iColorType);
2697
2698                 CPWL_Color color;
2699
2700                 if (iColorType == COLORTYPE_TRANSPARENT)
2701                 {
2702                         color = CPWL_Color(COLORTYPE_TRANSPARENT);
2703                 }
2704                 else if (iColorType == COLORTYPE_GRAY)
2705                 {
2706                         color = CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0));
2707                 }
2708                 else if (iColorType == COLORTYPE_RGB)
2709                 {
2710                         color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0),
2711                                 pFormControl->GetOriginalBorderColor(1),
2712                                 pFormControl->GetOriginalBorderColor(2));
2713                 }
2714                 else if (iColorType == COLORTYPE_CMYK)
2715                 {
2716                         color = CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0),
2717                                 pFormControl->GetOriginalBorderColor(1),
2718                                 pFormControl->GetOriginalBorderColor(2),
2719                                 pFormControl->GetOriginalBorderColor(3));
2720                 }
2721                 else
2722                         return FALSE;
2723
2724                 CJS_Array crArray(m_isolate);
2725                 color::ConvertPWLColorToArray(color, crArray);
2726         vp  <<  crArray;
2727         }
2728
2729         return TRUE;
2730 }
2731
2732 void Field::SetStrokeColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
2733 {
2734         //Not supported.
2735 }
2736
2737 FX_BOOL Field::style(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2738 {
2739         ASSERT(m_pDocument != NULL);
2740
2741         if (vp.IsSetting())
2742         {
2743                 if (!m_bCanSet) return FALSE;
2744
2745                 CFX_ByteString csBCaption;
2746                 vp >> csBCaption;
2747
2748                 if (m_bDelay)
2749                 {
2750                         AddDelay_String(FP_STYLE, csBCaption);
2751                 }
2752                 else
2753                 {
2754                         Field::SetStyle(m_pDocument, m_FieldName, m_nFormControlIndex, csBCaption);
2755                 }       
2756         }
2757         else
2758         {
2759                 CFX_PtrArray FieldArray;
2760                 GetFormFields(m_FieldName,FieldArray);
2761                 if (FieldArray.GetSize() <= 0) return FALSE;
2762
2763                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
2764                 ASSERT(pFormField != NULL);
2765
2766                 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON && 
2767                         pFormField->GetFieldType() != FIELDTYPE_CHECKBOX)
2768                         return FALSE;
2769
2770                 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2771                 if (!pFormControl) return FALSE;
2772
2773                 CFX_WideString csWCaption = pFormControl->GetNormalCaption();
2774                 CFX_ByteString csBCaption;
2775
2776                 switch (csWCaption[0])
2777                 {
2778                         case L'l':
2779                                 csBCaption = "circle";
2780                                 break;
2781                         case L'8':
2782                                 csBCaption = "cross";
2783                                 break;
2784                         case L'u':
2785                                 csBCaption = "diamond";
2786                                 break;
2787                         case L'n':
2788                                 csBCaption = "square";
2789                                 break;
2790                         case L'H':
2791                                 csBCaption = "star";
2792                                 break;
2793                         default: //L'4'
2794                                 csBCaption = "check";
2795                                 break;
2796                 }
2797                 vp << csBCaption;
2798         }
2799
2800         return TRUE;
2801 }
2802
2803 void Field::SetStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, 
2804                                          const CFX_ByteString& string)
2805 {
2806         //Not supported.
2807 }
2808
2809 FX_BOOL Field::submitName(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2810 {
2811         return TRUE;
2812 }
2813
2814 FX_BOOL Field::textColor(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2815 {
2816         ASSERT(m_pDocument != NULL);
2817
2818         if (vp.IsSetting())
2819         {
2820                 if (!m_bCanSet) return FALSE;
2821
2822                 CJS_Array crArray(m_isolate);
2823                 if (!vp.IsArrayObject())return FALSE;
2824                 vp >> crArray;
2825
2826                 CPWL_Color color;
2827                 color::ConvertArrayToPWLColor(crArray, color);
2828
2829                 if (m_bDelay)
2830                 {
2831                         AddDelay_Color(FP_TEXTCOLOR, color);
2832                 }
2833                 else
2834                 {
2835                         Field::SetTextColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
2836                 }       
2837         }
2838         else
2839         {
2840                 CFX_PtrArray FieldArray;
2841                 GetFormFields(m_FieldName,FieldArray);
2842                 if (FieldArray.GetSize() <= 0) return FALSE;
2843
2844                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
2845                 ASSERT(pFormField != NULL);
2846
2847                 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2848                 if (!pFormControl)return FALSE;
2849                 
2850                 int iColorType;
2851                 FX_ARGB color;
2852                 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2853                 FieldAppearance.GetColor(color, iColorType);
2854                 FX_INT32 a,r,g,b;
2855                 ArgbDecode(color, a, r, g, b);
2856
2857                 CPWL_Color crRet = CPWL_Color(COLORTYPE_RGB, r / 255.0f,
2858                                 g / 255.0f,
2859                                 b / 255.0f);
2860
2861                 if (iColorType == COLORTYPE_TRANSPARENT)
2862                         crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
2863
2864                 CJS_Array crArray(m_isolate);
2865                 color::ConvertPWLColorToArray(crRet, crArray);
2866         vp  <<  crArray;                
2867         }
2868
2869         return TRUE;
2870 }
2871
2872 void Field::SetTextColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
2873 {
2874         //Not supported.
2875 }
2876
2877 FX_BOOL Field::textFont(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2878 {
2879         ASSERT(m_pDocument != NULL);
2880
2881         if (vp.IsSetting())
2882         {
2883                 if (!m_bCanSet) return FALSE;
2884
2885                 CFX_ByteString csFontName;
2886                 vp >> csFontName;
2887                 if (csFontName.IsEmpty()) return FALSE;
2888
2889                 if (m_bDelay)
2890                 {
2891                         AddDelay_String(FP_TEXTFONT, csFontName);
2892                 }
2893                 else
2894                 {
2895                         Field::SetTextFont(m_pDocument, m_FieldName, m_nFormControlIndex, csFontName);
2896                 }       
2897         }
2898         else
2899         {
2900                 CFX_PtrArray FieldArray;
2901                 GetFormFields(m_FieldName,FieldArray);
2902                 if (FieldArray.GetSize() <= 0) return FALSE;
2903
2904                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
2905                 ASSERT(pFormField != NULL);
2906
2907                 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2908                 if (!pFormControl)return FALSE;
2909
2910                 int nFieldType = pFormField->GetFieldType();
2911
2912                 if (nFieldType == FIELDTYPE_PUSHBUTTON || 
2913                         nFieldType == FIELDTYPE_COMBOBOX || 
2914                         nFieldType == FIELDTYPE_LISTBOX ||
2915                         nFieldType == FIELDTYPE_TEXTFIELD)
2916                 {
2917                         CPDF_Font * pFont = pFormControl->GetDefaultControlFont();
2918                         if (!pFont) return FALSE;
2919
2920                         vp << pFont->GetBaseFont();
2921                 }
2922                 else
2923                         return FALSE;
2924         }
2925
2926         return TRUE;
2927 }
2928
2929 void Field::SetTextFont(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string)
2930 {
2931         //Not supported.
2932 }
2933
2934 FX_BOOL Field::textSize(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2935 {
2936         ASSERT(m_pDocument != NULL);
2937
2938         if (vp.IsSetting())
2939         {
2940                 if (!m_bCanSet) return FALSE;
2941
2942                 int nVP;
2943                 vp >> nVP;
2944
2945                 if (m_bDelay)
2946                 {
2947                         AddDelay_Int(FP_TEXTSIZE, nVP);
2948                 }
2949                 else
2950                 {
2951                         Field::SetTextSize(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
2952                 }       
2953         }
2954         else
2955         {
2956                 CFX_PtrArray FieldArray;
2957                 GetFormFields(m_FieldName,FieldArray);
2958                 if (FieldArray.GetSize() <= 0) return FALSE;
2959
2960                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
2961                 ASSERT(pFormField != NULL);
2962
2963                 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2964                 if (!pFormControl)return FALSE;
2965
2966                 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2967
2968                 CFX_ByteString csFontNameTag;
2969                 FX_FLOAT fFontSize;
2970                 FieldAppearance.GetFont(csFontNameTag,fFontSize);
2971
2972                 vp << (int)fFontSize;
2973         }
2974
2975         return TRUE;
2976 }
2977
2978 void Field::SetTextSize(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
2979 {
2980         //Not supported.
2981 }
2982
2983 FX_BOOL Field::type(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
2984 {
2985         ASSERT(m_pDocument != NULL);
2986
2987         if (!vp.IsGetting()) return FALSE;
2988
2989         CFX_PtrArray FieldArray;
2990         GetFormFields(m_FieldName,FieldArray);
2991         if (FieldArray.GetSize() <= 0) return FALSE;
2992
2993         CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
2994         ASSERT(pFormField != NULL);
2995
2996         switch (pFormField->GetFieldType())
2997         {
2998                 case FIELDTYPE_UNKNOWN:
2999                         vp << L"unknown";
3000                         break;
3001                 case FIELDTYPE_PUSHBUTTON:
3002                         vp << L"button";
3003                         break;
3004                 case FIELDTYPE_CHECKBOX:
3005                         vp << L"checkbox";
3006                         break;
3007                 case FIELDTYPE_RADIOBUTTON:
3008                         vp << L"radiobutton";
3009                         break;
3010                 case FIELDTYPE_COMBOBOX:
3011                         vp << L"combobox";
3012                         break;
3013                 case FIELDTYPE_LISTBOX:
3014                         vp << L"listbox";
3015                         break;
3016                 case FIELDTYPE_TEXTFIELD:
3017                         vp << L"text";
3018                         break;
3019                 case FIELDTYPE_SIGNATURE:
3020                         vp << L"signature";
3021                         break;
3022                 default :
3023                         vp << L"unknown";
3024                         break;
3025         }
3026
3027         return TRUE;
3028 }
3029
3030 FX_BOOL Field::userName(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
3031 {
3032         ASSERT(m_pDocument != NULL);
3033
3034         if (vp.IsSetting())
3035         {
3036                 if (!m_bCanSet) return FALSE;
3037
3038                 CFX_WideString swName;
3039                 vp >> swName;
3040
3041                 if (m_bDelay)
3042                 {
3043                         AddDelay_WideString(FP_USERNAME, swName);
3044                 }
3045                 else
3046                 {
3047                         Field::SetUserName(m_pDocument, m_FieldName, m_nFormControlIndex, swName);
3048                 }       
3049         }
3050         else
3051         {
3052                 CFX_PtrArray FieldArray;
3053                 GetFormFields(m_FieldName,FieldArray);
3054                 if (FieldArray.GetSize() <= 0) return FALSE;
3055
3056                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
3057                 ASSERT(pFormField != NULL);
3058
3059                 vp << (CFX_WideString)pFormField->GetAlternateName();
3060         }
3061
3062         return TRUE;
3063 }
3064
3065 void Field::SetUserName(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_WideString& string)
3066 {
3067         //Not supported.
3068 }
3069
3070 FX_BOOL Field::value(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
3071 {
3072         ASSERT(m_pDocument != NULL);
3073
3074         if (vp.IsSetting())
3075         {               
3076                 if (!m_bCanSet) return FALSE;
3077
3078                 CJS_WideStringArray strArray;
3079
3080                 if (vp.IsArrayObject())
3081                 {
3082                         CJS_Array ValueArray(m_isolate);
3083                         vp.ConvertToArray(ValueArray);
3084                         for (int i = 0,sz = ValueArray.GetLength(); i < sz; i++)
3085                         {
3086                                 CJS_Value ElementValue(m_isolate);
3087                                 ValueArray.GetElement(i, ElementValue);
3088                                 strArray.Add(ElementValue.ToCFXWideString());
3089                         }
3090                 }
3091                 else
3092                 {
3093                         CFX_WideString swValue;
3094                         vp >> swValue;
3095
3096                         strArray.Add(swValue);
3097                 }
3098
3099                 if (m_bDelay)
3100                 {
3101                         AddDelay_WideStringArray(FP_VALUE, strArray);
3102                 }
3103                 else
3104                 {
3105                         Field::SetValue(m_pDocument, m_FieldName, m_nFormControlIndex, strArray);
3106                 }
3107         }
3108         else
3109         {
3110                 CFX_PtrArray FieldArray;
3111                 GetFormFields(m_FieldName,FieldArray);
3112                 if (FieldArray.GetSize() <= 0) return FALSE;
3113
3114                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
3115                 ASSERT(pFormField != NULL);
3116
3117
3118
3119                 switch (pFormField->GetFieldType())
3120                 {
3121                 case FIELDTYPE_PUSHBUTTON:
3122                         return FALSE;
3123                 case FIELDTYPE_COMBOBOX:
3124                 case FIELDTYPE_TEXTFIELD:
3125                         {
3126                                 CFX_WideString swValue = pFormField->GetValue();
3127
3128                                 double dRet;
3129                                 FX_BOOL bDot;
3130                                 if (CJS_PublicMethods::ConvertStringToNumber(swValue,dRet,bDot))
3131                                 {
3132                                         if (bDot)
3133                                                 vp << dRet;
3134                                         else
3135                                                 vp << dRet;
3136                                 }
3137                                 else
3138                                         vp << swValue;
3139                         }
3140                         break;
3141                 case FIELDTYPE_LISTBOX:
3142                         {
3143                                 if (pFormField->CountSelectedItems() > 1)
3144                                 {
3145                                         CJS_Array ValueArray(m_isolate);
3146                                         CJS_Value ElementValue(m_isolate);
3147                                         int iIndex;
3148                                         for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++)
3149                                         {
3150                                                 iIndex = pFormField->GetSelectedIndex(i);
3151                                                 ElementValue = pFormField->GetOptionValue(iIndex);
3152                                                 if (FXSYS_wcslen(ElementValue.ToCFXWideString().c_str()) == 0)
3153                                                         ElementValue = pFormField->GetOptionLabel(iIndex);
3154                                                 ValueArray.SetElement(i, ElementValue);
3155                                         }
3156                                         vp << ValueArray;
3157                                 }
3158                                 else
3159                                 {
3160                                         CFX_WideString swValue = pFormField->GetValue();
3161                                 
3162                                         double dRet;
3163                                         FX_BOOL bDot;
3164                                         if (CJS_PublicMethods::ConvertStringToNumber(swValue,dRet,bDot))
3165                                         {
3166                                                 if (bDot)
3167                                                         vp << dRet;
3168                                                 else
3169                                                         vp << dRet;
3170                                         }
3171                                         else
3172                                                 vp << swValue;  
3173                                 }
3174                         }
3175                         break;
3176                 case FIELDTYPE_CHECKBOX:
3177                 case FIELDTYPE_RADIOBUTTON:
3178                         {
3179                                 FX_BOOL bFind = FALSE;
3180                                 for (int i = 0 , sz = pFormField->CountControls(); i < sz; i++)
3181                                 {
3182                                         if (pFormField->GetControl(i)->IsChecked())
3183                                         {
3184                                                 CFX_WideString swValue = pFormField->GetControl(i)->GetExportValue();
3185                                                 
3186                                                 double dRet;
3187                                                 FX_BOOL bDot;
3188                                                 if (CJS_PublicMethods::ConvertStringToNumber(swValue,dRet,bDot))
3189                                                 {
3190                                                         if (bDot)
3191                                                                 vp << dRet;
3192                                                         else
3193                                                                 vp << dRet;
3194                                                 }
3195                                                 else
3196                                                         vp << swValue;
3197
3198                                                 bFind = TRUE;
3199                                                 break;
3200                                         }
3201                                         else
3202                                                 continue;
3203                                 }
3204                                 if (!bFind)
3205                                         vp << L"Off";                                   
3206                         }
3207                         break;
3208                 default:
3209                         vp << pFormField->GetValue();
3210                         break;
3211                 }
3212         }
3213
3214         return TRUE;
3215 }
3216
3217 void Field::SetValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, 
3218                                          int nControlIndex, const CJS_WideStringArray& strArray)
3219 {
3220         ASSERT(pDocument != NULL);
3221
3222         if (strArray.GetSize() < 1) return;
3223
3224         CFX_PtrArray FieldArray;
3225         GetFormFields(pDocument, swFieldName, FieldArray);
3226
3227         for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
3228         {
3229                 CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
3230                 ASSERT(pFormField != NULL);
3231
3232                 if (pFormField->GetFullName().Compare(swFieldName) != 0)
3233                         continue;
3234
3235                 switch (pFormField->GetFieldType())
3236                 {
3237                 case FIELDTYPE_TEXTFIELD:
3238                 case FIELDTYPE_COMBOBOX:
3239                         if (pFormField->GetValue() != strArray.GetAt(0))
3240                         {
3241                                 CFX_WideString WideString = strArray.GetAt(0);
3242                                 pFormField->SetValue(strArray.GetAt(0), TRUE);  
3243                                 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
3244                         }
3245                         break;
3246                 case FIELDTYPE_CHECKBOX: //mantis: 0004493
3247                 case FIELDTYPE_RADIOBUTTON:
3248                         {
3249                                 if (pFormField->GetValue() != strArray.GetAt(0))
3250                                 {
3251                                         pFormField->SetValue(strArray.GetAt(0), TRUE);  
3252                                         UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
3253                                 }
3254                         }
3255                         break;
3256                 case FIELDTYPE_LISTBOX:
3257                         {
3258                                 FX_BOOL bModified = FALSE;
3259
3260                                 for (int i=0,sz=strArray.GetSize(); i<sz; i++)
3261                                 {
3262                                         int iIndex = pFormField->FindOption(strArray.GetAt(i));
3263
3264                                         if (!pFormField->IsItemSelected(iIndex))
3265                                         {
3266                                                 bModified = TRUE;
3267                                                 break;
3268                                         }
3269                                 }
3270
3271                                 if (bModified)
3272                                 {
3273                                         pFormField->ClearSelection(TRUE);
3274                                         for (int i=0,sz=strArray.GetSize(); i<sz; i++)
3275                                         {
3276                                                 int iIndex = pFormField->FindOption(strArray.GetAt(i));
3277                                                 pFormField->SetItemSelection(iIndex, TRUE, TRUE);
3278                                         }
3279
3280                                         UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
3281                                 }
3282                         }
3283                         break;
3284                 default:                                
3285                         break;
3286                 }
3287         }
3288 }
3289
3290 FX_BOOL Field::valueAsString(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
3291 {
3292         ASSERT(m_pDocument != NULL);
3293
3294         if (!vp.IsGetting()) return FALSE;
3295
3296         CFX_PtrArray FieldArray;
3297         GetFormFields(m_FieldName,FieldArray);
3298         if (FieldArray.GetSize() <= 0) return FALSE;
3299
3300         CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
3301         ASSERT(pFormField != NULL);
3302
3303         if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
3304                 return FALSE;
3305
3306         if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
3307         {
3308                 if(!pFormField->CountControls()) return FALSE;
3309
3310                 if (pFormField->GetControl(0)->IsChecked())
3311                         vp << L"Yes";
3312                 else
3313                         vp << L"Off";
3314         }
3315         else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON && !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON))
3316         {
3317                 for (int i=0, sz=pFormField->CountControls(); i<sz; i++)
3318                 {
3319                         if (pFormField->GetControl(i)->IsChecked())
3320                         {
3321                                 vp << pFormField->GetControl(i)->GetExportValue().c_str();
3322                                 break;
3323                         }
3324                         else
3325                                 vp << L"Off";
3326                 }
3327         }
3328         else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX && (pFormField->CountSelectedItems() > 1))
3329         {
3330                 vp << L"";
3331         }
3332         else
3333                 vp << pFormField->GetValue().c_str();
3334
3335         return TRUE;
3336 }
3337
3338 /* --------------------------------- methods --------------------------------- */
3339
3340 FX_BOOL Field::browseForFileToSubmit(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
3341 {
3342         ASSERT(m_pDocument != NULL);
3343
3344         CFX_PtrArray FieldArray;
3345         GetFormFields(m_FieldName, FieldArray);
3346         if (FieldArray.GetSize() <= 0) return FALSE;
3347
3348         CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
3349         ASSERT(pFormField != NULL);
3350
3351         CPDFDoc_Environment* pApp = m_pDocument->GetEnv();
3352         ASSERT(pApp != NULL);
3353
3354         if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) && 
3355                 (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD))
3356         {               
3357                 CFX_WideString wsFileName = pApp->JS_fieldBrowse();
3358                 if(!wsFileName.IsEmpty())
3359                 {
3360                         pFormField->SetValue(wsFileName);
3361                         UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
3362          }
3363         }
3364         else 
3365                 return FALSE;
3366
3367         return TRUE;
3368 }
3369
3370
3371 FX_BOOL Field::buttonGetCaption(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
3372 {
3373         ASSERT(m_pDocument != NULL);
3374
3375         int nface = 0;
3376         int iSize = params.size();
3377         if (iSize >= 1)
3378                 nface = params[0].ToInt();
3379
3380         CFX_PtrArray FieldArray;
3381         GetFormFields(m_FieldName,FieldArray);
3382         if (FieldArray.GetSize() <= 0) return FALSE;
3383
3384         CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
3385         ASSERT(pFormField != NULL);
3386         
3387         if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
3388                 return FALSE;
3389
3390         CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
3391         if (!pFormControl)return FALSE;
3392         
3393         if (nface == 0)
3394                 vRet = pFormControl->GetNormalCaption();
3395         else if (nface == 1)
3396                 vRet = pFormControl->GetDownCaption();
3397         else if (nface == 2)
3398                 vRet = pFormControl->GetRolloverCaption();
3399         else
3400                 return FALSE;
3401
3402         return TRUE;
3403 }
3404
3405 //#pragma warning(disable: 4800)
3406
3407 FX_BOOL Field::buttonGetIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
3408 {
3409         ASSERT(m_pDocument != NULL);
3410
3411         int nface = 0;
3412         int iSize = params.size();
3413         if (iSize >= 1)
3414                 nface = params[0].ToInt();
3415         
3416         CFX_PtrArray FieldArray;
3417         GetFormFields(m_FieldName,FieldArray);
3418         if (FieldArray.GetSize() <= 0) return FALSE;
3419
3420         CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
3421         ASSERT(pFormField != NULL);
3422         
3423         if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
3424                 return FALSE;
3425
3426         CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
3427         if (!pFormControl)return FALSE;
3428
3429         CJS_Context* pContext = (CJS_Context*)cc;
3430         ASSERT(pContext != NULL);
3431
3432         CJS_Runtime* pRuntime = pContext->GetJSRuntime();
3433         ASSERT(pRuntime != NULL);
3434         
3435         JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon"));
3436         ASSERT(pObj.IsEmpty() == FALSE);
3437         
3438         CJS_Icon* pJS_Icon = (CJS_Icon*)JS_GetPrivate(pObj);
3439         ASSERT(pJS_Icon != NULL);
3440
3441         Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
3442         ASSERT(pIcon != NULL);
3443
3444         CPDF_Stream* pIconStream = NULL;
3445         if (nface == 0)
3446                 pIconStream = pFormControl->GetNormalIcon();
3447         else if (nface == 1)
3448                 pIconStream = pFormControl->GetDownIcon();
3449         else if (nface == 2)
3450                 pIconStream = pFormControl->GetRolloverIcon();
3451         else
3452                 return FALSE;
3453
3454         pIcon->SetStream(pIconStream);
3455         vRet = pJS_Icon;
3456
3457         return TRUE;
3458 }
3459
3460 //#pragma warning(default: 4800)
3461
3462 FX_BOOL Field::buttonImportIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
3463 {
3464 #if 0  
3465         ASSERT(m_pDocument != NULL);
3466
3467         CFX_PtrArray FieldArray;
3468         GetFormFields(m_FieldName,FieldArray);
3469         if (FieldArray.GetSize() <= 0) return FALSE;
3470
3471         CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
3472         if (!pFormField)return FALSE;
3473
3474         CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
3475         ASSERT(pEnv);
3476
3477         CFX_WideString sIconFileName = pEnv->JS_fieldBrowse();
3478         if (sIconFileName.IsEmpty()) 
3479         {
3480                 vRet = 1;
3481                 return TRUE;
3482         }
3483
3484         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
3485         ASSERT(pInterForm != NULL);
3486
3487         CPDF_Stream* pStream = pInterForm->LoadImageFromFile(sIconFileName);
3488         if (!pStream) 
3489         {
3490                 vRet = -1;
3491                 return TRUE;
3492         }
3493
3494         CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
3495         if (!pFormControl)return FALSE;
3496
3497         pFormControl->SetNormalIcon(pStream);
3498         UpdateFormControl(m_pDocument, pFormControl, TRUE, TRUE, TRUE);
3499
3500         vRet = 0;
3501 #endif // 0
3502         return TRUE;
3503 }
3504
3505 FX_BOOL Field::buttonSetCaption(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
3506 {
3507         return FALSE;
3508 }
3509
3510 FX_BOOL Field::buttonSetIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
3511 {
3512         return FALSE;
3513 }
3514
3515 FX_BOOL Field::checkThisBox(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
3516 {
3517         ASSERT(m_pDocument != NULL);
3518
3519         if (!m_bCanSet) return FALSE;
3520
3521         int iSize = params.size();
3522         if (iSize < 1)
3523                 return FALSE;
3524
3525         int nWidget = params[0].ToInt();
3526
3527         FX_BOOL bCheckit = TRUE;
3528         if (iSize >= 2)
3529                 bCheckit = params[1].ToBool();
3530
3531         CFX_PtrArray FieldArray;
3532         GetFormFields(m_FieldName,FieldArray);
3533         if (FieldArray.GetSize() <= 0) return FALSE;
3534
3535         CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
3536         ASSERT(pFormField != NULL);
3537
3538         if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX && pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
3539                 return FALSE;
3540         if(nWidget <0 || nWidget >= pFormField->CountControls())
3541                 return FALSE;
3542         if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
3543                 pFormField->CheckControl(nWidget, bCheckit, TRUE);
3544         else
3545                 pFormField->CheckControl(nWidget, bCheckit, TRUE);
3546
3547         UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
3548         return TRUE;
3549 }
3550
3551 FX_BOOL Field::clearItems(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
3552 {
3553         return TRUE;
3554 }
3555
3556 FX_BOOL Field::defaultIsChecked(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
3557 {
3558         ASSERT(m_pDocument != NULL);
3559
3560         if (!m_bCanSet) return FALSE;
3561
3562         int iSize = params.size();
3563         if (iSize < 1)
3564                 return FALSE;
3565
3566         int nWidget = params[0].ToInt();
3567
3568         CFX_PtrArray FieldArray;
3569         GetFormFields(m_FieldName,FieldArray);
3570         if (FieldArray.GetSize() <= 0) return FALSE;
3571
3572         CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
3573         ASSERT(pFormField != NULL);
3574
3575         if(nWidget <0 || nWidget >= pFormField->CountControls())
3576         {
3577                 vRet = FALSE;
3578                 return FALSE;
3579         }
3580         if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
3581                 || (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON))
3582         {
3583
3584                 vRet = TRUE;
3585         }
3586         else
3587                 vRet = FALSE;
3588
3589         return TRUE;
3590 }
3591
3592 FX_BOOL Field::deleteItemAt(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
3593 {
3594         return TRUE;
3595 }
3596
3597 int JS_COMPARESTRING(CFX_WideString* ps1, CFX_WideString* ps2)
3598 {
3599         ASSERT(ps1 != NULL);
3600         ASSERT(ps2 != NULL);
3601
3602         return ps1->Compare(*ps2);
3603 }
3604
3605
3606 FX_BOOL Field::getArray(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
3607 {
3608         ASSERT(m_pDocument != NULL);
3609
3610         CFX_PtrArray FieldArray;
3611         GetFormFields(m_FieldName,FieldArray);
3612         if (FieldArray.GetSize() <= 0) return FALSE;
3613
3614         CGW_ArrayTemplate<CFX_WideString*> swSort;
3615
3616         for (int i=0,sz=FieldArray.GetSize(); i<sz; i++)
3617