blob: 44a744f1d19ae94b48fd073af9470b7547d95f79 [file] [log] [blame]
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../include/javascript/JavaScript.h"
#include "../../include/javascript/IJavaScript.h"
#include "../../include/javascript/JS_Define.h"
#include "../../include/javascript/JS_Object.h"
#include "../../include/javascript/JS_Value.h"
#include "../../include/javascript/Field.h"
#include "../../include/javascript/JS_EventHandler.h"
//#include "../include/JS_ResMgr.h"
#include "../../include/javascript/JS_Context.h"
#include "../../include/javascript/JS_Runtime.h"
#include "../../include/javascript/Document.h"
#include "../../include/javascript/color.h"
#include "../../include/javascript/PublicMethods.h"
#include "../../include/javascript/Icon.h"
/* ---------------------- Field ---------------------- */
BEGIN_JS_STATIC_CONST(CJS_Field)
END_JS_STATIC_CONST()
BEGIN_JS_STATIC_PROP(CJS_Field)
JS_STATIC_PROP_ENTRY(alignment)
JS_STATIC_PROP_ENTRY(borderStyle)
JS_STATIC_PROP_ENTRY(buttonAlignX)
JS_STATIC_PROP_ENTRY(buttonAlignY)
JS_STATIC_PROP_ENTRY(buttonFitBounds)
JS_STATIC_PROP_ENTRY(buttonPosition)
JS_STATIC_PROP_ENTRY(buttonScaleHow)
JS_STATIC_PROP_ENTRY(buttonScaleWhen)
JS_STATIC_PROP_ENTRY(calcOrderIndex)
JS_STATIC_PROP_ENTRY(charLimit)
JS_STATIC_PROP_ENTRY(comb)
JS_STATIC_PROP_ENTRY(commitOnSelChange)
JS_STATIC_PROP_ENTRY(currentValueIndices)
JS_STATIC_PROP_ENTRY(defaultStyle)
JS_STATIC_PROP_ENTRY(defaultValue)
JS_STATIC_PROP_ENTRY(doNotScroll)
JS_STATIC_PROP_ENTRY(doNotSpellCheck)
JS_STATIC_PROP_ENTRY(delay)
JS_STATIC_PROP_ENTRY(display)
JS_STATIC_PROP_ENTRY(doc)
JS_STATIC_PROP_ENTRY(editable)
JS_STATIC_PROP_ENTRY(exportValues)
JS_STATIC_PROP_ENTRY(hidden)
JS_STATIC_PROP_ENTRY(fileSelect)
JS_STATIC_PROP_ENTRY(fillColor)
JS_STATIC_PROP_ENTRY(lineWidth)
JS_STATIC_PROP_ENTRY(highlight)
JS_STATIC_PROP_ENTRY(multiline)
JS_STATIC_PROP_ENTRY(multipleSelection)
JS_STATIC_PROP_ENTRY(name)
JS_STATIC_PROP_ENTRY(numItems)
JS_STATIC_PROP_ENTRY(page)
JS_STATIC_PROP_ENTRY(password)
JS_STATIC_PROP_ENTRY(print)
JS_STATIC_PROP_ENTRY(radiosInUnison)
JS_STATIC_PROP_ENTRY(readonly)
JS_STATIC_PROP_ENTRY(rect)
JS_STATIC_PROP_ENTRY(required)
JS_STATIC_PROP_ENTRY(richText)
JS_STATIC_PROP_ENTRY(richValue)
JS_STATIC_PROP_ENTRY(rotation)
JS_STATIC_PROP_ENTRY(strokeColor)
JS_STATIC_PROP_ENTRY(style)
JS_STATIC_PROP_ENTRY(submitName)
JS_STATIC_PROP_ENTRY(textColor)
JS_STATIC_PROP_ENTRY(textFont)
JS_STATIC_PROP_ENTRY(textSize)
JS_STATIC_PROP_ENTRY(type)
JS_STATIC_PROP_ENTRY(userName)
JS_STATIC_PROP_ENTRY(value)
JS_STATIC_PROP_ENTRY(valueAsString)
JS_STATIC_PROP_ENTRY(source)
END_JS_STATIC_PROP()
BEGIN_JS_STATIC_METHOD(CJS_Field)
JS_STATIC_METHOD_ENTRY(browseForFileToSubmit, 0)
JS_STATIC_METHOD_ENTRY(buttonGetCaption, 1)
JS_STATIC_METHOD_ENTRY(buttonGetIcon, 1)
JS_STATIC_METHOD_ENTRY(buttonImportIcon, 0)
JS_STATIC_METHOD_ENTRY(buttonSetCaption, 2)
JS_STATIC_METHOD_ENTRY(buttonSetIcon, 2)
JS_STATIC_METHOD_ENTRY(checkThisBox, 2)
JS_STATIC_METHOD_ENTRY(clearItems, 0)
JS_STATIC_METHOD_ENTRY(defaultIsChecked, 2)
JS_STATIC_METHOD_ENTRY(deleteItemAt, 1)
JS_STATIC_METHOD_ENTRY(getArray , 0)
JS_STATIC_METHOD_ENTRY(getItemAt, 0)
JS_STATIC_METHOD_ENTRY(getLock, 0)
JS_STATIC_METHOD_ENTRY(insertItemAt, 0)
JS_STATIC_METHOD_ENTRY(isBoxChecked, 1)
JS_STATIC_METHOD_ENTRY(isDefaultChecked, 1)
JS_STATIC_METHOD_ENTRY(setAction, 2)
JS_STATIC_METHOD_ENTRY(setFocus, 0)
JS_STATIC_METHOD_ENTRY(setItems, 1)
JS_STATIC_METHOD_ENTRY(setLock, 0)
JS_STATIC_METHOD_ENTRY(signatureGetModifications, 0)
JS_STATIC_METHOD_ENTRY(signatureGetSeedValue, 0)
JS_STATIC_METHOD_ENTRY(signatureInfo, 0)
JS_STATIC_METHOD_ENTRY(signatureSetSeedValue, 0)
JS_STATIC_METHOD_ENTRY(signatureSign, 0)
JS_STATIC_METHOD_ENTRY(signatureValidate, 0)
END_JS_STATIC_METHOD()
IMPLEMENT_JS_CLASS(CJS_Field, Field)
FX_BOOL CJS_Field::InitInstance(IFXJS_Context* cc)
{
CJS_Context* pContext = (CJS_Context*)cc;
ASSERT(pContext != NULL);
Field* pField = (Field*)GetEmbedObject();
ASSERT(pField != NULL);
pField->SetIsolate(pContext->GetJSRuntime()->GetIsolate());
return TRUE;
};
Field::Field(CJS_Object* pJSObject): CJS_EmbedObj(pJSObject),
m_pJSDoc(NULL),
m_pDocument(NULL),
m_nFormControlIndex(-1),
m_bCanSet(FALSE),
m_bDelay(FALSE),
m_isolate(NULL)
{
}
Field::~Field()
{
}
//note: iControlNo = -1, means not a widget.
void Field::ParseFieldName(const std::wstring &strFieldNameParsed,std::wstring &strFieldName,int & iControlNo)
{
int iStart = strFieldNameParsed.find_last_of(L'.');
if (iStart == -1)
{
strFieldName = strFieldNameParsed;
iControlNo = -1;
return;
}
std::wstring suffixal = strFieldNameParsed.substr(iStart+1);
iControlNo = FXSYS_wtoi((FX_LPCWSTR)suffixal.c_str());
if (iControlNo == 0)
{
int iStart;
while((iStart = suffixal.find_last_of(L" ")) != -1)
{
suffixal.erase(iStart,1);
}
if (suffixal.compare(L"0") != 0)
{
strFieldName = strFieldNameParsed;
iControlNo = -1;
return;
}
}
strFieldName = strFieldNameParsed.substr(0,iStart);
}
FX_BOOL Field::AttachField(Document* pDocument, const CFX_WideString& csFieldName)
{
ASSERT(pDocument != NULL);
m_pJSDoc = pDocument;
m_pDocument = pDocument->GetReaderDoc();
ASSERT(m_pDocument != NULL);
m_bCanSet = m_pDocument->GetPermissions(FPDFPERM_FILL_FORM) ||
m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
m_pDocument->GetPermissions(FPDFPERM_MODIFY);
CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
ASSERT(pRDInterForm != NULL);
CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
ASSERT(pInterForm != NULL);
CFX_WideString swFieldNameTemp = csFieldName;
swFieldNameTemp.Replace((FX_LPCWSTR)L"..", (FX_LPCWSTR)L".");
if (pInterForm->CountFields(swFieldNameTemp) <= 0)
{
std::wstring strFieldName;
int iControlNo = -1;
ParseFieldName((wchar_t*)(FX_LPCWSTR)swFieldNameTemp, strFieldName, iControlNo);
if (iControlNo == -1) return FALSE;
m_FieldName = strFieldName.c_str();
m_nFormControlIndex = iControlNo;
return TRUE;
}
m_FieldName = swFieldNameTemp;
m_nFormControlIndex = -1;
return TRUE;
}
void Field::GetFormFields(CPDFSDK_Document* pDocument, const CFX_WideString& csFieldName, CFX_PtrArray& FieldArray)
{
ASSERT(pDocument != NULL);
CPDFSDK_InterForm* pReaderInterForm = pDocument->GetInterForm();
ASSERT(pReaderInterForm != NULL);
CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
ASSERT(pInterForm != NULL);
ASSERT(FieldArray.GetSize() == 0);
for (int i=0,sz=pInterForm->CountFields(csFieldName); i<sz; i++)
{
if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
FieldArray.Add((void*)pFormField);
}
}
void Field::GetFormFields(const CFX_WideString& csFieldName, CFX_PtrArray& FieldArray)
{
ASSERT(m_pDocument != NULL);
Field::GetFormFields(m_pDocument, csFieldName, FieldArray);
}
void Field::UpdateFormField(CPDFSDK_Document* pDocument, CPDF_FormField* pFormField,
FX_BOOL bChangeMark, FX_BOOL bResetAP, FX_BOOL bRefresh)
{
ASSERT(pDocument != NULL);
ASSERT(pFormField != NULL);
CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
ASSERT(pInterForm != NULL);
CFX_PtrArray widgets;
pInterForm->GetWidgets(pFormField, widgets);
if (bResetAP)
{
int nFieldType = pFormField->GetFieldType();
if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD)
{
for (int i=0,sz=widgets.GetSize(); i<sz; i++)
{
CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i);
ASSERT(pWidget != NULL);
FX_BOOL bFormated = FALSE;
CFX_WideString sValue = pWidget->OnFormat(0, bFormated);
if (bFormated)
pWidget->ResetAppearance(sValue, FALSE);
else
pWidget->ResetAppearance(NULL, FALSE);
}
}
else
{
for (int i=0,sz=widgets.GetSize(); i<sz; i++)
{
CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i);
ASSERT(pWidget != NULL);
pWidget->ResetAppearance(NULL, FALSE);
}
}
}
if (bRefresh)
{
for (int i=0,sz=widgets.GetSize(); i<sz; i++)
{
CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i);
ASSERT(pWidget != NULL);
CPDFSDK_InterForm * pInterForm = pWidget->GetInterForm();
CPDFSDK_Document* pDoc = pInterForm->GetDocument();
// CReader_Page* pPage = pWidget->GetPage();
ASSERT(pDoc != NULL);
pDoc->UpdateAllViews(NULL, pWidget);
}
}
if (bChangeMark)
pDocument->SetChangeMark();
}
void Field::UpdateFormControl(CPDFSDK_Document* pDocument, CPDF_FormControl* pFormControl,
FX_BOOL bChangeMark, FX_BOOL bResetAP, FX_BOOL bRefresh)
{
ASSERT(pDocument != NULL);
ASSERT(pFormControl != NULL);
CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
ASSERT(pInterForm != NULL);
CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
if (pWidget)
{
if (bResetAP)
{
int nFieldType = pWidget->GetFieldType();
if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD)
{
FX_BOOL bFormated = FALSE;
CFX_WideString sValue = pWidget->OnFormat(0, bFormated);
if (bFormated)
pWidget->ResetAppearance(sValue, FALSE);
else
pWidget->ResetAppearance(NULL, FALSE);
}
else
{
pWidget->ResetAppearance(NULL, FALSE);
}
}
if (bRefresh)
{
CPDFSDK_InterForm * pInterForm = pWidget->GetInterForm();
CPDFSDK_Document* pDoc = pInterForm->GetDocument();
ASSERT(pDoc != NULL);
pDoc->UpdateAllViews(NULL, pWidget);
}
}
if (bChangeMark)
pDocument->SetChangeMark();
}
CPDFSDK_Widget* Field::GetWidget(CPDFSDK_Document* pDocument, CPDF_FormControl* pFormControl)
{
ASSERT(pDocument != NULL);
ASSERT(pFormControl != NULL);
CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
ASSERT(pInterForm != NULL);
return pInterForm->GetWidget(pFormControl);
}
FX_BOOL Field::ValueIsOccur(CPDF_FormField* pFormField, CFX_WideString csOptLabel)
{
ASSERT(pFormField != NULL);
for (int i=0,sz = pFormField->CountOptions(); i < sz; i++)
{
if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
return TRUE;
}
return FALSE;
}
CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField)
{
ASSERT(pFormField != NULL);
if(!pFormField->CountControls() || m_nFormControlIndex>=pFormField->CountControls()) return NULL;
if (m_nFormControlIndex<0)
return pFormField->GetControl(0);
else
return pFormField->GetControl(m_nFormControlIndex);
}
/* ---------------------------------------- property ---------------------------------------- */
FX_BOOL Field::alignment(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
CFX_ByteString alignStr;
vp >> alignStr;
if (m_bDelay)
{
AddDelay_String(FP_ALIGNMENT, alignStr);
}
else
{
Field::SetAlignment(m_pDocument, m_FieldName, m_nFormControlIndex, alignStr);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName, FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
return FALSE;
CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
if (!pFormControl)return FALSE;
switch (pFormControl->GetControlAlignment())
{
case 1:
vp << (FX_LPCWSTR)L"center";
break;
case 0:
vp << (FX_LPCWSTR)L"left";
break;
case 2:
vp << (FX_LPCWSTR)L"right";
break;
default:
vp << (FX_LPCWSTR)L"";
}
}
return TRUE;
}
void Field::SetAlignment(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
const CFX_ByteString& string)
{
//Not supported.
}
FX_BOOL Field::borderStyle(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
CFX_ByteString strType = "";
vp >> strType;
if (m_bDelay)
{
AddDelay_String(FP_BORDERSTYLE, strType);
}
else
{
Field::SetBorderStyle(m_pDocument, m_FieldName, m_nFormControlIndex, strType);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName, FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
if (!pFormField) return FALSE;
CPDFSDK_Widget* pWidget = GetWidget(m_pDocument, GetSmartFieldControl(pFormField));
if (!pWidget) return FALSE;
int nBorderstyle = pWidget->GetBorderStyle();
switch (nBorderstyle)
{
case BBS_SOLID:
vp << (FX_LPCWSTR)L"solid";
break;
case BBS_DASH:
vp << (FX_LPCWSTR)L"dashed";
break;
case BBS_BEVELED:
vp << (FX_LPCWSTR)L"beveled";
break;
case BBS_INSET:
vp << (FX_LPCWSTR)L"inset";
break;
case BBS_UNDERLINE:
vp << (FX_LPCWSTR)L"underline";
break;
default:
vp << (FX_LPCWSTR)L"";
break;
}
}
return TRUE;
}
void Field::SetBorderStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
const CFX_ByteString& string)
{
ASSERT(pDocument != NULL);
int nBorderStyle = 0;
if (string == "solid")
nBorderStyle = BBS_SOLID;
else if (string == "beveled")
nBorderStyle = BBS_BEVELED;
else if (string == "dashed")
nBorderStyle = BBS_DASH;
else if (string == "inset")
nBorderStyle = BBS_INSET;
else if (string == "underline")
nBorderStyle = BBS_UNDERLINE;
else return;
CFX_PtrArray FieldArray;
GetFormFields(pDocument, swFieldName, FieldArray);
for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
{
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
ASSERT(pFormField != NULL);
if (nControlIndex < 0)
{
FX_BOOL bSet = FALSE;
for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
{
if (CPDFSDK_Widget* pWidget = GetWidget(pDocument, pFormField->GetControl(j)))
{
if (pWidget->GetBorderStyle() != nBorderStyle)
{
pWidget->SetBorderStyle(nBorderStyle);
bSet = TRUE;
}
}
}
if (bSet) UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
}
else
{
if(nControlIndex >= pFormField->CountControls()) return;
if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
{
if (CPDFSDK_Widget* pWidget = GetWidget(pDocument, pFormControl))
{
if (pWidget->GetBorderStyle() != nBorderStyle)
{
pWidget->SetBorderStyle(nBorderStyle);
UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
}
}
}
}
}
}
FX_BOOL Field::buttonAlignX(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
int nVP;
vp >> nVP;
if (m_bDelay)
{
AddDelay_Int(FP_BUTTONALIGNX, nVP);
}
else
{
Field::SetButtonAlignX(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
return FALSE;
CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
if (!pFormControl)return FALSE;
CPDF_IconFit IconFit = pFormControl->GetIconFit();
FX_FLOAT fLeft,fBottom;
IconFit.GetIconPosition(fLeft,fBottom);
vp << (FX_INT32)fLeft;
}
return TRUE;
}
void Field::SetButtonAlignX(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
{
//Not supported.
}
FX_BOOL Field::buttonAlignY(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
int nVP;
vp >> nVP;
if (m_bDelay)
{
AddDelay_Int(FP_BUTTONALIGNY, nVP);
}
else
{
Field::SetButtonAlignY(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
return FALSE;
CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
if (!pFormControl)return FALSE;
CPDF_IconFit IconFit = pFormControl->GetIconFit();
FX_FLOAT fLeft,fBottom;
IconFit.GetIconPosition(fLeft,fBottom);
vp << (FX_INT32)fBottom;
}
return TRUE;
}
void Field::SetButtonAlignY(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
{
//Not supported.
}
FX_BOOL Field::buttonFitBounds(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
bool bVP;
vp >> bVP;
if (m_bDelay)
{
AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP);
}
else
{
Field::SetButtonFitBounds(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
return FALSE;
CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
if (!pFormControl)return FALSE;
CPDF_IconFit IconFit = pFormControl->GetIconFit();
vp << IconFit.GetFittingBounds();
}
return TRUE;
}
void Field::SetButtonFitBounds(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
{
//Not supported.
}
FX_BOOL Field::buttonPosition(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
int nVP;
vp >> nVP;
if (m_bDelay)
{
AddDelay_Int(FP_BUTTONPOSITION, nVP);
}
else
{
Field::SetButtonPosition(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
return FALSE;
CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
if (!pFormControl)return FALSE;
vp << pFormControl->GetTextPosition();
}
return TRUE;
}
void Field::SetButtonPosition(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
{
//Not supported.
}
FX_BOOL Field::buttonScaleHow(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
int nVP;
vp >> nVP;
if (m_bDelay)
{
AddDelay_Int(FP_BUTTONSCALEHOW, nVP);
}
else
{
Field::SetButtonScaleHow(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName, FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
return FALSE;
CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
if (!pFormControl)return FALSE;
CPDF_IconFit IconFit = pFormControl->GetIconFit();
if (IconFit.IsProportionalScale())
vp << (FX_INT32)0;
else
vp << (FX_INT32)1;
}
return TRUE;
}
void Field::SetButtonScaleHow(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
{
//Not supported.
}
FX_BOOL Field::buttonScaleWhen(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
int nVP;
vp >> nVP;
if (m_bDelay)
{
AddDelay_Int(FP_BUTTONSCALEWHEN, nVP);
}
else
{
Field::SetButtonScaleWhen(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*) FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
return FALSE;
CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
if (!pFormControl) return FALSE;
CPDF_IconFit IconFit = pFormControl->GetIconFit();
int ScaleM = IconFit.GetScaleMethod();
switch (ScaleM)
{
case CPDF_IconFit::Always :
vp << (FX_INT32) CPDF_IconFit::Always;
break;
case CPDF_IconFit::Bigger :
vp << (FX_INT32) CPDF_IconFit::Bigger;
break;
case CPDF_IconFit::Never :
vp << (FX_INT32) CPDF_IconFit::Never;
break;
case CPDF_IconFit::Smaller :
vp << (FX_INT32) CPDF_IconFit::Smaller;
break;
}
}
return TRUE;
}
void Field::SetButtonScaleWhen(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
{
//Not supported.
}
FX_BOOL Field::calcOrderIndex(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
int nVP;
vp >> nVP;
if (m_bDelay)
{
AddDelay_Int(FP_CALCORDERINDEX, nVP);
}
else
{
Field::SetCalcOrderIndex(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName, FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
return FALSE;
CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
ASSERT(pRDInterForm != NULL);
CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
ASSERT(pInterForm != NULL);
vp << (FX_INT32)pInterForm->FindFieldInCalculationOrder(pFormField);
}
return TRUE;
}
void Field::SetCalcOrderIndex(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
{
//Not supported.
}
FX_BOOL Field::charLimit(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
int nVP;
vp >> nVP;
if (m_bDelay)
{
AddDelay_Int(FP_CHARLIMIT, nVP);
}
else
{
Field::SetCharLimit(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName, FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
return FALSE;
vp << (FX_INT32)pFormField->GetMaxLen();
}
return TRUE;
}
void Field::SetCharLimit(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
{
//Not supported.
}
FX_BOOL Field::comb(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
bool bVP;
vp >> bVP;
if (m_bDelay)
{
AddDelay_Bool(FP_COMB, bVP);
}
else
{
Field::SetComb(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
return FALSE;
if (pFormField->GetFieldFlags() & FIELDFLAG_COMB)
vp << true;
else
vp << false;
}
return TRUE;
}
void Field::SetComb(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
{
//Not supported.
}
FX_BOOL Field::commitOnSelChange(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
bool bVP;
vp >> bVP;
if (m_bDelay)
{
AddDelay_Bool(FP_COMMITONSELCHANGE, bVP);
}
else
{
Field::SetCommitOnSelChange(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
return FALSE;
if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)
vp << true;
else
vp << false;
}
return TRUE;
}
void Field::SetCommitOnSelChange(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
{
//Not supported.
}
FX_BOOL Field::currentValueIndices(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
CFX_DWordArray array;
if (vp.GetType() == VT_number)
{
int iSelecting = 0;
vp >> iSelecting;
array.Add(iSelecting);
}
else if (vp.IsArrayObject())
{
CJS_Array SelArray(m_isolate);
CJS_Value SelValue(m_isolate);
int iSelecting;
vp >> SelArray;
for (int i=0,sz=SelArray.GetLength(); i<sz; i++)
{
SelArray.GetElement(i,SelValue);
iSelecting = (FX_INT32)SelValue;
array.Add(iSelecting);
}
}
if (m_bDelay)
{
AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
}
else
{
Field::SetCurrentValueIndices(m_pDocument, m_FieldName, m_nFormControlIndex, array);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
return FALSE;
if (pFormField->CountSelectedItems() == 1)
vp << pFormField->GetSelectedIndex(0);
else if (pFormField->CountSelectedItems() > 1)
{
CJS_Array SelArray(m_isolate);
for (int i=0,sz=pFormField->CountSelectedItems(); i<sz; i++)
{
SelArray.SetElement(i, CJS_Value(m_isolate,pFormField->GetSelectedIndex(i)));
}
vp << SelArray;
}
else
vp << -1;
}
return TRUE;
}
void Field::SetCurrentValueIndices(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
const CFX_DWordArray& array)
{
ASSERT(pDocument != NULL);
CFX_PtrArray FieldArray;
GetFormFields(pDocument, swFieldName, FieldArray);
for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
{
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
ASSERT(pFormField != NULL);
int nFieldType = pFormField->GetFieldType();
if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX)
{
FX_DWORD dwFieldFlags = pFormField->GetFieldFlags();
pFormField->ClearSelection(TRUE);
for (int i=0,sz=array.GetSize(); i<sz; i++)
{
if (i>0 && !(dwFieldFlags & (1<<21)))
{
break;
}
int iSelecting = (FX_INT32)array.GetAt(i);
if (iSelecting < pFormField->CountOptions() && !pFormField->IsItemSelected(iSelecting))
pFormField->SetItemSelection(iSelecting, TRUE);
}
UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
}
}
}
FX_BOOL Field::defaultStyle(OBJ_PROP_PARAMS)
{
// MQG sError = JSGetStringFromID(IDS_STRING_NOTSUPPORT);
return FALSE;
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
;
}
else
{
;
}
return TRUE;
}
void Field::SetDefaultStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex)
{
//Not supported.
}
FX_BOOL Field::defaultValue(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
CFX_WideString WideStr;
vp >> WideStr;
if (m_bDelay)
{
AddDelay_WideString(FP_DEFAULTVALUE, WideStr);
}
else
{
Field::SetDefaultValue(m_pDocument, m_FieldName, m_nFormControlIndex, WideStr);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
pFormField->GetFieldType() == FIELDTYPE_SIGNATURE)
return FALSE;
vp << pFormField->GetDefaultValue();
}
return TRUE;
}
void Field::SetDefaultValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
const CFX_WideString& string)
{
//Not supported.
}
FX_BOOL Field::doNotScroll(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
bool bVP;
vp >> bVP;
if (m_bDelay)
{
AddDelay_Bool(FP_DONOTSCROLL, bVP);
}
else
{
Field::SetDoNotScroll(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
return FALSE;
if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
vp << true;
else
vp << false;
}
return TRUE;
}
void Field::SetDoNotScroll(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
{
//Not supported.
}
FX_BOOL Field::doNotSpellCheck(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
bool bVP;
vp >> bVP;
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
return FALSE;
if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
vp << true;
else
vp << false;
}
return TRUE;
}
void Field::SetDelay(FX_BOOL bDelay)
{
m_bDelay = bDelay;
if (!m_bDelay)
{
if (m_pJSDoc)
m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
}
}
FX_BOOL Field::delay(OBJ_PROP_PARAMS)
{
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
bool bVP;
vp >> bVP;
SetDelay(bVP);
}
else
{
vp << m_bDelay;
}
return TRUE;
}
FX_BOOL Field::display(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
int nVP;
vp >> nVP;
if (m_bDelay)
{
AddDelay_Int(FP_DISPLAY, nVP);
}
else
{
Field::SetDisplay(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
ASSERT(pInterForm != NULL);
CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
if (!pWidget)return FALSE;
FX_DWORD dwFlag = pWidget->GetFlags();
if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag)
{
vp << (FX_INT32)1;
}
else
{
if (ANNOTFLAG_PRINT & dwFlag)
{
if (ANNOTFLAG_NOVIEW & dwFlag)
{
vp << (FX_INT32)3;
}
else
{
vp << (FX_INT32)0;
}
}
else
{
vp << (FX_INT32)2;
}
}
}
return TRUE;
}
void Field::SetDisplay(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
{
ASSERT(pDocument != NULL);
CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
ASSERT(pInterForm != NULL);
CFX_PtrArray FieldArray;
GetFormFields(pDocument, swFieldName, FieldArray);
for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
{
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
ASSERT(pFormField != NULL);
if (nControlIndex < 0)
{
FX_BOOL bSet = FALSE;
for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
{
CPDF_FormControl* pFormControl = pFormField->GetControl(j);
ASSERT(pFormControl != NULL);
if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
{
FX_DWORD dwFlag = pWidget->GetFlags();
switch (number)
{
case 0:
dwFlag &= (~ANNOTFLAG_INVISIBLE);
dwFlag &= (~ANNOTFLAG_HIDDEN);
dwFlag &= (~ANNOTFLAG_NOVIEW);
dwFlag |= ANNOTFLAG_PRINT;
break;
case 1:
dwFlag &= (~ANNOTFLAG_INVISIBLE);
dwFlag &= (~ANNOTFLAG_NOVIEW);
dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
break;
case 2:
dwFlag &= (~ANNOTFLAG_INVISIBLE);
dwFlag &= (~ANNOTFLAG_PRINT);
dwFlag &= (~ANNOTFLAG_HIDDEN);
dwFlag &= (~ANNOTFLAG_NOVIEW);
break;
case 3:
dwFlag |= ANNOTFLAG_NOVIEW;
dwFlag |= ANNOTFLAG_PRINT;
dwFlag &= (~ANNOTFLAG_HIDDEN);
break;
}
if (dwFlag != pWidget->GetFlags())
{
pWidget->SetFlags(dwFlag);
bSet = TRUE;
}
}
}
if (bSet) UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
}
else
{
if(nControlIndex >= pFormField->CountControls()) return;
if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
{
if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
{
FX_DWORD dwFlag = pWidget->GetFlags();
switch (number)
{
case 0:
dwFlag &= (~ANNOTFLAG_INVISIBLE);
dwFlag &= (~ANNOTFLAG_HIDDEN);
dwFlag &= (~ANNOTFLAG_NOVIEW);
dwFlag |= ANNOTFLAG_PRINT;
break;
case 1:
dwFlag &= (~ANNOTFLAG_INVISIBLE);
dwFlag &= (~ANNOTFLAG_NOVIEW);
dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
break;
case 2:
dwFlag &= (~ANNOTFLAG_INVISIBLE);
dwFlag &= (~ANNOTFLAG_PRINT);
dwFlag &= (~ANNOTFLAG_HIDDEN);
dwFlag &= (~ANNOTFLAG_NOVIEW);
break;
case 3:
dwFlag |= ANNOTFLAG_NOVIEW;
dwFlag |= ANNOTFLAG_PRINT;
dwFlag &= (~ANNOTFLAG_HIDDEN);
break;
}
if (dwFlag != pWidget->GetFlags())
{
pWidget->SetFlags(dwFlag);
UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
}
}
}
}
}
}
FX_BOOL Field::doc(OBJ_PROP_PARAMS)
{
ASSERT(m_pJSDoc != NULL);
if (!vp.IsGetting())return FALSE;
vp << (CJS_Object*)(*m_pJSDoc);
return TRUE;
}
FX_BOOL Field::editable(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
bool bVP;
vp >> bVP;
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName, FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
return FALSE;
if (pFormField->GetFieldFlags() & FIELDFLAG_EDIT)
vp << true;
else
vp << false;
}
return TRUE;
}
FX_BOOL Field::exportValues(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
return FALSE;
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
if (!vp.IsArrayObject())return FALSE;
}
else
{
CJS_Array ExportValusArray(m_isolate);
if (m_nFormControlIndex < 0)
{
for (int i=0,sz=pFormField->CountControls(); i<sz; i++)
{
CPDF_FormControl* pFormControl = pFormField->GetControl(i);
ASSERT(pFormControl != NULL);
ExportValusArray.SetElement(i, CJS_Value(m_isolate,(FX_LPCWSTR)pFormControl->GetExportValue()));
}
}
else
{
if(m_nFormControlIndex >= pFormField->CountControls()) return FALSE;
CPDF_FormControl* pFormControl = pFormField->GetControl(m_nFormControlIndex);
if (!pFormControl) return FALSE;
ExportValusArray.SetElement(0, CJS_Value(m_isolate,(FX_LPCWSTR)pFormControl->GetExportValue()));
}
vp << ExportValusArray;
}
return TRUE;
}
FX_BOOL Field::fileSelect(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName, FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
return FALSE;
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
bool bVP;
vp >> bVP;
}
else
{
if (pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT)
vp << true;
else
vp << false;
}
return TRUE;
}
FX_BOOL Field::fillColor(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
CJS_Array crArray(m_isolate);
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
if (!vp.IsArrayObject()) return FALSE;
vp >> crArray;
CPWL_Color color;
color::ConvertArrayToPWLColor(crArray, color);
if (m_bDelay)
{
AddDelay_Color(FP_FILLCOLOR, color);
}
else
{
Field::SetFillColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
}
}
else
{
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
if (!pFormControl)return FALSE;
int iColorType;
pFormControl->GetBackgroundColor(iColorType);
CPWL_Color color;
if (iColorType == COLORTYPE_TRANSPARENT)
{
color = CPWL_Color(COLORTYPE_TRANSPARENT);
}
else if (iColorType == COLORTYPE_GRAY)
{
color = CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBackgroundColor(0));
}
else if (iColorType == COLORTYPE_RGB)
{
color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0),
pFormControl->GetOriginalBackgroundColor(1),
pFormControl->GetOriginalBackgroundColor(2));
}
else if (iColorType == COLORTYPE_CMYK)
{
color = CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBackgroundColor(0),
pFormControl->GetOriginalBackgroundColor(1),
pFormControl->GetOriginalBackgroundColor(2),
pFormControl->GetOriginalBackgroundColor(3));
}
else
return FALSE;
color::ConvertPWLColorToArray(color, crArray);
vp << crArray;
}
return TRUE;
}
void Field::SetFillColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
{
//Not supported.
}
FX_BOOL Field::hidden(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
bool bVP;
vp >> bVP;
if (m_bDelay)
{
AddDelay_Bool(FP_HIDDEN, bVP);
}
else
{
Field::SetHidden(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
ASSERT(pInterForm != NULL);
CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
if (!pWidget) return FALSE;
FX_DWORD dwFlags = pWidget->GetFlags();
if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)
{
vp << true;
}
else
vp << false;
}
return TRUE;
}
void Field::SetHidden(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
{
ASSERT(pDocument != NULL);
CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
ASSERT(pInterForm != NULL);
CFX_PtrArray FieldArray;
GetFormFields(pDocument, swFieldName, FieldArray);
for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
{
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
ASSERT(pFormField != NULL);
if (nControlIndex < 0)
{
FX_BOOL bSet = FALSE;
for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
{
if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(j)))
{
FX_DWORD dwFlags = pWidget->GetFlags();
if (b)
{
dwFlags &= (~ANNOTFLAG_INVISIBLE);
dwFlags &= (~ANNOTFLAG_NOVIEW);
dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
}
else
{
dwFlags &= (~ANNOTFLAG_INVISIBLE);
dwFlags &= (~ANNOTFLAG_HIDDEN);
dwFlags &= (~ANNOTFLAG_NOVIEW);
dwFlags |= ANNOTFLAG_PRINT;
}
if (dwFlags != pWidget->GetFlags())
{
pWidget->SetFlags(dwFlags);
bSet = TRUE;
}
}
}
if (bSet)
UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
}
else
{
if(nControlIndex >= pFormField->CountControls()) return;
if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
{
if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
{
FX_DWORD dwFlags = pWidget->GetFlags();
if (b)
{
dwFlags &= (~ANNOTFLAG_INVISIBLE);
dwFlags &= (~ANNOTFLAG_NOVIEW);
dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
}
else
{
dwFlags &= (~ANNOTFLAG_INVISIBLE);
dwFlags &= (~ANNOTFLAG_HIDDEN);
dwFlags &= (~ANNOTFLAG_NOVIEW);
dwFlags |= ANNOTFLAG_PRINT;
}
if (dwFlags != pWidget->GetFlags())
{
pWidget->SetFlags(dwFlags);
UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
}
}
}
}
}
}
FX_BOOL Field::highlight(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
CFX_ByteString strMode;
vp >> strMode;
if (m_bDelay)
{
AddDelay_String(FP_HIGHLIGHT, strMode);
}
else
{
Field::SetHighlight(m_pDocument, m_FieldName, m_nFormControlIndex, strMode);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
return FALSE;
CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
if (!pFormControl) return FALSE;
int eHM = pFormControl->GetHighlightingMode();
switch (eHM)
{
case CPDF_FormControl::None:
vp << (FX_LPCWSTR)L"none";
break;
case CPDF_FormControl::Push:
vp << (FX_LPCWSTR)L"push";
break;
case CPDF_FormControl::Invert:
vp << (FX_LPCWSTR)L"invert";
break;
case CPDF_FormControl::Outline:
vp << (FX_LPCWSTR)L"outline";
break;
case CPDF_FormControl::Toggle:
vp << (FX_LPCWSTR)L"toggle";
break;
}
}
return TRUE;
}
void Field::SetHighlight(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string)
{
//Not supported.
}
FX_BOOL Field::lineWidth(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
int iWidth;
vp >> iWidth;
if (m_bDelay)
{
AddDelay_Int(FP_LINEWIDTH, iWidth);
}
else
{
Field::SetLineWidth(m_pDocument, m_FieldName, m_nFormControlIndex, iWidth);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
if (!pFormControl) return FALSE;
CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
ASSERT(pInterForm != NULL);
if(!pFormField->CountControls()) return FALSE;
CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
if (!pWidget) return FALSE;
vp << (FX_INT32)pWidget->GetBorderWidth();
}
return TRUE;
}
void Field::SetLineWidth(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
{
ASSERT(pDocument != NULL);
CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
ASSERT(pInterForm != NULL);
CFX_PtrArray FieldArray;
GetFormFields(pDocument, swFieldName, FieldArray);
for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
{
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
ASSERT(pFormField != NULL);
if (nControlIndex < 0)
{
FX_BOOL bSet = FALSE;
for (int j=0,jsz=pFormField->CountControls(); j<jsz; j++)
{
CPDF_FormControl* pFormControl = pFormField->GetControl(j);
ASSERT(pFormControl != NULL);
if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
{
if (number != pWidget->GetBorderWidth())
{
pWidget->SetBorderWidth(number);
bSet = TRUE;
}
}
}
if (bSet) UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
}
else
{
if(nControlIndex >= pFormField->CountControls()) return;
if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
{
if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
{
if (number != pWidget->GetBorderWidth())
{
pWidget->SetBorderWidth(number);
UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
}
}
}
}
}
}
FX_BOOL Field::multiline(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
bool bVP;
vp >> bVP;
if (m_bDelay)
{
AddDelay_Bool(FP_MULTILINE, bVP);
}
else
{
Field::SetMultiline(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName, FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
return FALSE;
if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
vp << true;
else
vp << false;
}
return TRUE;
}
void Field::SetMultiline(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
{
//Not supported.
}
FX_BOOL Field::multipleSelection(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
bool bVP;
vp >> bVP;
if (m_bDelay)
{
AddDelay_Bool(FP_MULTIPLESELECTION, bVP);
}
else
{
Field::SetMultipleSelection(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
return FALSE;
if (pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)
vp << true;
else
vp << false;
}
return TRUE;
}
void Field::SetMultipleSelection(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
{
//Not supported.
}
FX_BOOL Field::name(OBJ_PROP_PARAMS)
{
if (!vp.IsGetting()) return FALSE;
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName, FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
vp << m_FieldName;
return TRUE;
}
FX_BOOL Field::numItems(OBJ_PROP_PARAMS)
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName, FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
return FALSE;
if (!vp.IsGetting()) return FALSE;
vp << (FX_INT32)pFormField->CountOptions();
return TRUE;
}
FX_BOOL Field::page(OBJ_PROP_PARAMS)
{
if (!vp.IsGetting()) return FALSE;
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName, FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
if (!pFormField) return FALSE;
ASSERT(m_pDocument != NULL);
CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
ASSERT(pInterForm != NULL);
CFX_PtrArray widgetArray;
pInterForm->GetWidgets(pFormField, widgetArray);
if (widgetArray.GetSize() > 0)
{
CJS_Array PageArray(m_isolate);
for (int i=0,sz=widgetArray.GetSize(); i<sz; i++)
{
CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgetArray.GetAt(i);
ASSERT(pWidget != NULL);
CPDFSDK_PageView* pPageView = pWidget->GetPageView();
if(!pPageView)
return FALSE;
PageArray.SetElement(i, CJS_Value(m_isolate,(FX_INT32)pPageView->GetPageIndex()));
}
vp << PageArray;
}
else
{
vp << (FX_INT32) -1;
}
return TRUE;
}
FX_BOOL Field::password(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
bool bVP;
vp >> bVP;
if (m_bDelay)
{
AddDelay_Bool(FP_PASSWORD, bVP);
}
else
{
Field::SetPassword(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
return FALSE;
if (pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)
vp << true;
else
vp << false;
}
return TRUE;
}
void Field::SetPassword(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
{
//Not supported.
}
FX_BOOL Field::print(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
ASSERT(pInterForm != NULL);
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName, FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
bool bVP;
vp >> bVP;
for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
{
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
ASSERT(pFormField != NULL);
if (m_nFormControlIndex < 0)
{
FX_BOOL bSet = FALSE;
for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
{
if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(j)))
{
FX_DWORD dwFlags = pWidget->GetFlags();
if (bVP)
dwFlags |= ANNOTFLAG_PRINT;
else
dwFlags &= ~ANNOTFLAG_PRINT;
if (dwFlags != pWidget->GetFlags())
{
pWidget->SetFlags(dwFlags);
bSet = TRUE;
}
}
}
if (bSet)
UpdateFormField(m_pDocument, pFormField, TRUE, FALSE, TRUE);
}
else
{
if(m_nFormControlIndex >= pFormField->CountControls()) return FALSE;
if (CPDF_FormControl* pFormControl = pFormField->GetControl(m_nFormControlIndex))
{
if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
{
FX_DWORD dwFlags = pWidget->GetFlags();
if (bVP)
dwFlags |= ANNOTFLAG_PRINT;
else
dwFlags &= ~ANNOTFLAG_PRINT;
if (dwFlags != pWidget->GetFlags())
{
pWidget->SetFlags(dwFlags);
UpdateFormControl(m_pDocument, pFormField->GetControl(m_nFormControlIndex), TRUE, FALSE, TRUE);
}
}
}
}
}
}
else
{
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
if (!pWidget) return FALSE;
if (pWidget->GetFlags() & ANNOTFLAG_PRINT)
vp << true;
else
vp << false;
}
return TRUE;
}
FX_BOOL Field::radiosInUnison(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
bool bVP;
vp >> bVP;
}
else
{
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
return FALSE;
if (pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)
vp << true;
else
vp << false;
}
return TRUE;
}
FX_BOOL Field::readonly(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
bool bVP;
vp >> bVP;
}
else
{
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldFlags() & FIELDFLAG_READONLY)
vp << true;
else
vp << false;
}
return TRUE;
}
FX_BOOL Field::rect(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
if (!vp.IsArrayObject())return FALSE;
CJS_Array rcArray(m_isolate);
vp >> rcArray;
CJS_Value Upper_Leftx(m_isolate), Upper_Lefty(m_isolate), Lower_Rightx(m_isolate), Lower_Righty(m_isolate);
rcArray.GetElement(0, Upper_Leftx);
rcArray.GetElement(1, Upper_Lefty);
rcArray.GetElement(2, Lower_Rightx);
rcArray.GetElement(3, Lower_Righty);
FX_FLOAT pArray[4] = {0.0f,0.0f,0.0f,0.0f};
pArray[0] = (FX_FLOAT)(FX_INT32)Upper_Leftx;
pArray[1] = (FX_FLOAT)(FX_INT32)Lower_Righty;
pArray[2] = (FX_FLOAT)(FX_INT32)Lower_Rightx;
pArray[3] = (FX_FLOAT)(FX_INT32)Upper_Lefty;
CPDF_Rect crRect(pArray);
if (m_bDelay)
{
AddDelay_Rect(FP_RECT, crRect);
}
else
{
Field::SetRect(m_pDocument, m_FieldName, m_nFormControlIndex, crRect);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
ASSERT(pInterForm != NULL);
CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
if (!pWidget) return FALSE;
CFX_FloatRect crRect = pWidget->GetRect();
CJS_Value Upper_Leftx(m_isolate),Upper_Lefty(m_isolate),Lower_Rightx(m_isolate),Lower_Righty(m_isolate);
Upper_Leftx = (FX_INT32)crRect.left;
Upper_Lefty = (FX_INT32)crRect.top;
Lower_Rightx = (FX_INT32)crRect.right;
Lower_Righty = (FX_INT32)crRect.bottom;
CJS_Array rcArray(m_isolate);
rcArray.SetElement(0,Upper_Leftx);
rcArray.SetElement(1,Upper_Lefty);
rcArray.SetElement(2,Lower_Rightx);
rcArray.SetElement(3,Lower_Righty);
vp << rcArray;
}
return TRUE;
}
void Field::SetRect(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPDF_Rect& rect)
{
ASSERT(pDocument != NULL);
CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
ASSERT(pInterForm != NULL);
CFX_PtrArray FieldArray;
GetFormFields(pDocument, swFieldName, FieldArray);
for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
{
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
ASSERT(pFormField != NULL);
if (nControlIndex < 0)
{
FX_BOOL bSet = FALSE;
for (int i=0, sz=pFormField->CountControls(); i<sz; i++)
{
CPDF_FormControl* pFormControl = pFormField->GetControl(i);
ASSERT(pFormControl != NULL);
if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
{
CPDF_Rect crRect = rect;
CPDF_Page* pPDFPage = pWidget->GetPDFPage();
ASSERT(pPDFPage != NULL);
// CPDF_Page* pPDFPage = pPage->GetPage();
// ASSERT(pPDFPage != NULL);
crRect.Intersect(pPDFPage->GetPageBBox());
if (!crRect.IsEmpty())
{
CPDF_Rect rcOld = pWidget->GetRect();
if (crRect.left != rcOld.left ||
crRect.right != rcOld.right ||
crRect.top != rcOld.top ||
crRect.bottom != rcOld.bottom)
{
pWidget->SetRect(crRect);
bSet = TRUE;
}
}
}
}
if (bSet) UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
}
else
{
if(nControlIndex >= pFormField->CountControls()) return;
if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
{
if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
{
CPDF_Rect crRect = rect;
CPDF_Page* pPDFPage = pWidget->GetPDFPage();
ASSERT(pPDFPage != NULL);
// CPDF_Page* pPDFPage = pPage->GetPage();
// ASSERT(pPDFPage != NULL);
crRect.Intersect(pPDFPage->GetPageBBox());
if (!crRect.IsEmpty())
{
CPDF_Rect rcOld = pWidget->GetRect();
if (crRect.left != rcOld.left ||
crRect.right != rcOld.right ||
crRect.top != rcOld.top ||
crRect.bottom != rcOld.bottom)
{
pWidget->SetRect(crRect);
UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
}
}
}
}
}
}
}
FX_BOOL Field::required(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
bool bVP;
vp >> bVP;
}
else
{
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
return FALSE;
if (pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)
vp << true;
else
vp << false;
}
return TRUE;
}
FX_BOOL Field::richText(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
bool bVP;
vp >> bVP;
if (m_bDelay)
{
AddDelay_Bool(FP_RICHTEXT, bVP);
}
else
{
Field::SetRichText(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
return FALSE;
if (pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)
vp << true;
else
vp << false;
}
return TRUE;
}
void Field::SetRichText(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
{
//Not supported.
}
FX_BOOL Field::richValue(OBJ_PROP_PARAMS)
{
return TRUE;
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
;
}
else
{
;
}
return TRUE;
}
void Field::SetRichValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex)
{
//Not supported.
}
FX_BOOL Field::rotation(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
int nVP;
vp >> nVP;
if (m_bDelay)
{
AddDelay_Int(FP_ROTATION, nVP);
}
else
{
Field::SetRotation(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
if (!pFormControl)return FALSE;
vp << (FX_INT32)pFormControl->GetRotation();
}
return TRUE;
}
void Field::SetRotation(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
{
//Not supported.
}
FX_BOOL Field::strokeColor(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
if (!vp.IsArrayObject())return FALSE;
CJS_Array crArray(m_isolate);
vp >> crArray;
CPWL_Color color;
color::ConvertArrayToPWLColor(crArray, color);
if (m_bDelay)
{
AddDelay_Color(FP_STROKECOLOR, color);
}
else
{
Field::SetStrokeColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
if (!pFormControl)return FALSE;
int iColorType;
pFormControl->GetBorderColor(iColorType);
CPWL_Color color;
if (iColorType == COLORTYPE_TRANSPARENT)
{
color = CPWL_Color(COLORTYPE_TRANSPARENT);
}
else if (iColorType == COLORTYPE_GRAY)
{
color = CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0));
}
else if (iColorType == COLORTYPE_RGB)
{
color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0),
pFormControl->GetOriginalBorderColor(1),
pFormControl->GetOriginalBorderColor(2));
}
else if (iColorType == COLORTYPE_CMYK)
{
color = CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0),
pFormControl->GetOriginalBorderColor(1),
pFormControl->GetOriginalBorderColor(2),
pFormControl->GetOriginalBorderColor(3));
}
else
return FALSE;
CJS_Array crArray(m_isolate);
color::ConvertPWLColorToArray(color, crArray);
vp << crArray;
}
return TRUE;
}
void Field::SetStrokeColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
{
//Not supported.
}
FX_BOOL Field::style(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
CFX_ByteString csBCaption;
vp >> csBCaption;
if (m_bDelay)
{
AddDelay_String(FP_STYLE, csBCaption);
}
else
{
Field::SetStyle(m_pDocument, m_FieldName, m_nFormControlIndex, csBCaption);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
pFormField->GetFieldType() != FIELDTYPE_CHECKBOX)
return FALSE;
CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
if (!pFormControl) return FALSE;
CFX_WideString csWCaption = pFormControl->GetNormalCaption();
CFX_ByteString csBCaption;
switch (csWCaption[0])
{
case L'l':
csBCaption = "circle";
break;
case L'8':
csBCaption = "cross";
break;
case L'u':
csBCaption = "diamond";
break;
case L'n':
csBCaption = "square";
break;
case L'H':
csBCaption = "star";
break;
default: //L'4'
csBCaption = "check";
break;
}
vp << csBCaption;
}
return TRUE;
}
void Field::SetStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
const CFX_ByteString& string)
{
//Not supported.
}
FX_BOOL Field::submitName(OBJ_PROP_PARAMS)
{
return TRUE;
}
FX_BOOL Field::textColor(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
CJS_Array crArray(m_isolate);
if (!vp.IsArrayObject())return FALSE;
vp >> crArray;
CPWL_Color color;
color::ConvertArrayToPWLColor(crArray, color);
if (m_bDelay)
{
AddDelay_Color(FP_TEXTCOLOR, color);
}
else
{
Field::SetTextColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
if (!pFormControl)return FALSE;
int iColorType;
FX_ARGB color;
CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
FieldAppearance.GetColor(color, iColorType);
FX_INT32 a,r,g,b;
ArgbDecode(color, a, r, g, b);
CPWL_Color crRet = CPWL_Color(COLORTYPE_RGB, r / 255.0f,
g / 255.0f,
b / 255.0f);
if (iColorType == COLORTYPE_TRANSPARENT)
crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
CJS_Array crArray(m_isolate);
color::ConvertPWLColorToArray(crRet, crArray);
vp << crArray;
}
return TRUE;
}
void Field::SetTextColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
{
//Not supported.
}
FX_BOOL Field::textFont(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
if (vp.IsSetting())
{
if (!m_bCanSet) return FALSE;
CFX_ByteString csFontName;
vp >> csFontName;
if (csFontName.IsEmpty()) return FALSE;
if (m_bDelay)
{
AddDelay_String(FP_TEXTFONT, csFontName);
}
else
{
Field::SetTextFont(m_pDocument, m_FieldName, m_nFormControlIndex, csFontName);
}
}
else
{
CFX_PtrArray FieldArray;
GetFormFields(m_FieldName,FieldArray);
if (FieldArray.GetSize() <= 0) return FALSE;
CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
ASSERT(pFormField != NULL);
CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
if (!pFormControl)return FALSE;
int nFieldType = pFormField->GetFieldType();
if (nFieldType == FIELDTYPE_PUSHBUTTON ||
nFieldType == FIELDTYPE_COMBOBOX ||
nFieldType == FIELDTYPE_LISTBOX ||
nFieldType == FIELDTYPE_TEXTFIELD)
{
CPDF_Font * pFont = pFormControl->GetDefaultControlFont();
if (!pFont) return FALSE;
vp << pFont->GetBaseFont();
}
else
return FALSE;
}