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